| 1 | <? |
|---|
| 2 | |
|---|
| 3 | /***************************************************************************
|
|---|
| 4 | * Dolphin Smart Community Builder
|
|---|
| 5 | * -----------------
|
|---|
| 6 | * begin : Mon Mar 23 2006
|
|---|
| 7 | * copyright : (C) 2006 BoonEx Group
|
|---|
| 8 | * website : http://www.boonex.com/
|
|---|
| 9 | * This file is part of Dolphin - Smart Community Builder
|
|---|
| 10 | *
|
|---|
| 11 | * Dolphin is free software. This work is licensed under a Creative Commons Attribution 3.0 License.
|
|---|
| 12 | * http://creativecommons.org/licenses/by/3.0/
|
|---|
| 13 | *
|
|---|
| 14 | * Dolphin is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|---|
| 15 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|---|
| 16 | * See the Creative Commons Attribution 3.0 License for more details.
|
|---|
| 17 | * You should have received a copy of the Creative Commons Attribution 3.0 License along with Dolphin,
|
|---|
| 18 | * see license.txt file; if not, write to marketing@boonex.com
|
|---|
| 19 | ***************************************************************************/
|
|---|
| 20 | |
|---|
| 21 | require_once( 'inc/header.inc.php' ); |
|---|
| 22 | require_once( BX_DIRECTORY_PATH_INC . 'design.inc.php' ); |
|---|
| 23 | require_once( BX_DIRECTORY_PATH_INC . 'utils.inc.php' ); |
|---|
| 24 | |
|---|
| 25 | // --------------- page variables / login |
|---|
| 26 | |
|---|
| 27 | $_page['name_index'] = 39; |
|---|
| 28 | $_page['css_name'] = 'poll.css'; |
|---|
| 29 | |
|---|
| 30 | if ( !( $logged['admin'] = member_auth( 1, false ) ) )
|
|---|
| 31 | if ( !( $logged['member'] = member_auth( 0, false ) ) )
|
|---|
| 32 | if ( !( $logged['aff'] = member_auth( 2, false ) ) )
|
|---|
| 33 | $logged['moderator'] = member_auth( 3, false );
|
|---|
| 34 | |
|---|
| 35 | $_page['header'] = _t( "_Site Poll" ); |
|---|
| 36 | $_page['header_text'] = _t( "_Site Poll" ); |
|---|
| 37 | |
|---|
| 38 | $ID = (int)$_REQUEST['ID']; |
|---|
| 39 | |
|---|
| 40 | if ( $_POST['vote'] ) |
|---|
| 41 | { |
|---|
| 42 | if ( PollsVoteAdd() ) |
|---|
| 43 | $actionText = _t_action("_Vote accepted"); |
|---|
| 44 | else |
|---|
| 45 | $actionText = _t_err("_You already voted"); |
|---|
| 46 | } |
|---|
| 47 | else |
|---|
| 48 | $actionText = ''; |
|---|
| 49 | |
|---|
| 50 | // --------------- page components |
|---|
| 51 | |
|---|
| 52 | $_ni = $_page['name_index']; |
|---|
| 53 | $_page_cont[$_ni]['page_main_code'] = $actionText . MemberPrintPoll( $ID ); |
|---|
| 54 | |
|---|
| 55 | // --------------- [END] page components |
|---|
| 56 | |
|---|
| 57 | PageCode(); |
|---|
| 58 | |
|---|
| 59 | // --------------- page components functions |
|---|
| 60 | |
|---|
| 61 | /** |
|---|
| 62 | * page code function |
|---|
| 63 | */ |
|---|
| 64 | function PageCompPageMainCode() |
|---|
| 65 | { |
|---|
| 66 | global $ID; |
|---|
| 67 | |
|---|
| 68 | } |
|---|
| 69 | |
|---|
| 70 | /** |
|---|
| 71 | * Add vote |
|---|
| 72 | */ |
|---|
| 73 | function PollsVoteAdd ( ) |
|---|
| 74 | { |
|---|
| 75 | global $ID; |
|---|
| 76 | |
|---|
| 77 | if ( $_COOKIE["polls_question_{$ID}"] > 0 ) |
|---|
| 78 | return 0; |
|---|
| 79 | |
|---|
| 80 | if ( !(int)$_POST['vote'] ) |
|---|
| 81 | return 0; |
|---|
| 82 | |
|---|
| 83 | $res = db_res("UPDATE `polls_a` SET `Votes` = `Votes` + 1 WHERE `IDanswer` = ". (int)$_POST['vote']); |
|---|
| 84 | |
|---|
| 85 | if ( $res ) |
|---|
| 86 | setcookie("polls_question_{$ID}", 1 , time() + ( 10000 * 3600 ), '/' ); |
|---|
| 87 | |
|---|
| 88 | return $res; |
|---|
| 89 | } |
|---|
| 90 | |
|---|
| 91 | |
|---|
| 92 | |
|---|
| 93 | /** |
|---|
| 94 | * Print a poll |
|---|
| 95 | */ |
|---|
| 96 | function MemberPrintPoll( $ID ) |
|---|
| 97 | { |
|---|
| 98 | |
|---|
| 99 | $queryQuestion = "SELECT `Question` FROM `polls_q` WHERE `Active` = 'on' AND `ID` = $ID"; |
|---|
| 100 | $queryAnswers = "SELECT `IDanswer`, `Answer`, `Votes` FROM `polls_a` WHERE `ID` = $ID"; |
|---|
| 101 | |
|---|
| 102 | $aQuestion = db_arr( $queryQuestion ); |
|---|
| 103 | $rAnswers = db_res( $queryAnswers ); |
|---|
| 104 | |
|---|
| 105 | if ( !$aQuestion or !mysql_num_rows($rAnswers) ) |
|---|
| 106 | return _t_err("_Poll not available"); |
|---|
| 107 | |
|---|
| 108 | $aVotes = db_arr( "SELECT SUM(`Votes`) FROM `polls_a` WHERE `ID` = $ID" ); |
|---|
| 109 | $iTotalVotes = (int)$aVotes[0]; |
|---|
| 110 | |
|---|
| 111 | ob_start(); |
|---|
| 112 | ?> |
|---|
| 113 | <form method="post" name="FormVote" action="<?=$_SERVER['PHP_SELF']?>"> |
|---|
| 114 | <input type="hidden" name="ID" value="<?=$ID?>" /> |
|---|
| 115 | <table class="tableVote"> |
|---|
| 116 | <tr><th colspan="2"><?=process_line_output( $aQuestion['Question'] )?></th> |
|---|
| 117 | </tr> |
|---|
| 118 | <? |
|---|
| 119 | |
|---|
| 120 | $j = 1; |
|---|
| 121 | while ( $aAnswer = mysql_fetch_array($rAnswers) ) |
|---|
| 122 | { |
|---|
| 123 | if( ($j%2) == 0) |
|---|
| 124 | $add = '2'; |
|---|
| 125 | else |
|---|
| 126 | $add = '1'; |
|---|
| 127 | |
|---|
| 128 | ?> |
|---|
| 129 | <tr> |
|---|
| 130 | <td> |
|---|
| 131 | <input type="radio" onclick="javascript: this.form.submit()" name="vote" |
|---|
| 132 | value="<?=$aAnswer['IDanswer']?>" ID="l<?=$aAnswer['IDanswer']?>" /> |
|---|
| 133 | <label for="l<?=$aAnswer['IDanswer']?>"><?=process_line_output( $aAnswer['Answer'] )?></label> |
|---|
| 134 | </td> |
|---|
| 135 | <td><?=DesignProgressPos( _t("_votes").": ".$aAnswer['Votes'], 100, $iTotalVotes, $aAnswer['Votes'], $add )?></td> |
|---|
| 136 | </tr> |
|---|
| 137 | <? |
|---|
| 138 | $j++; |
|---|
| 139 | } |
|---|
| 140 | |
|---|
| 141 | ?> |
|---|
| 142 | </table> |
|---|
| 143 | </form> |
|---|
| 144 | <? |
|---|
| 145 | |
|---|
| 146 | return ob_get_clean(); |
|---|
| 147 | } |
|---|
| 148 | |
|---|
| 149 | ?> |
|---|