| 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 . 'db.inc.php' ); |
|---|
| 23 | require_once( BX_DIRECTORY_PATH_INC . 'languages.inc.php' ); |
|---|
| 24 | |
|---|
| 25 | $member['ID'] = (int)$_COOKIE['memberID']; |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | if ( 'vote' == $_GET['action'] ) { |
|---|
| 29 | if ( '' != $_GET['ID'] ) { |
|---|
| 30 | if ( '' != $_GET['param'] ) { |
|---|
| 31 | $query = "SELECT poll_results FROM ProfilesPolls WHERE id_poll='" . (int)$_GET['ID'] . "'"; |
|---|
| 32 | $res_arr = db_arr( $query ); |
|---|
| 33 | |
|---|
| 34 | $results = explode( ';', $res_arr['poll_results'] ); |
|---|
| 35 | $results[$_GET['param']]++; |
|---|
| 36 | $poll_total_votes = array_sum($results); |
|---|
| 37 | $results = implode(';', $results); |
|---|
| 38 | |
|---|
| 39 | $iPollID = (int)$_GET['ID']; |
|---|
| 40 | if ( $_COOKIE["profile_polls_question_{$iPollID}"] > 0 ) { |
|---|
| 41 | //print 'Dublicate'; |
|---|
| 42 | } else { |
|---|
| 43 | $query = "UPDATE ProfilesPolls SET poll_results = '{$results}', poll_total_votes = '{$poll_total_votes}' WHERE id_poll='{$iPollID}'"; |
|---|
| 44 | $vProfPollRes = db_res( $query ); |
|---|
| 45 | if ( $vProfPollRes ) setcookie("profile_polls_question_{$iPollID}", 1 , time() + ( 10000 * 3600 ), '/' ); |
|---|
| 46 | } |
|---|
| 47 | } |
|---|
| 48 | } |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | |
|---|
| 52 | header('Content-Type: application/xml'); |
|---|
| 53 | echo '<?xml version="1.0" encoding="UTF-8"?>'; |
|---|
| 54 | |
|---|
| 55 | // ===================================================================== |
|---|
| 56 | // TODO : protect from malicious calls !!!!!! |
|---|
| 57 | // ===================================================================== |
|---|
| 58 | // DELETE action ------------------------------------------------------- |
|---|
| 59 | if ( 'delete' == $_GET['action'] ) |
|---|
| 60 | { |
|---|
| 61 | if ( '' != $_GET['ID'] ) |
|---|
| 62 | { |
|---|
| 63 | $query = "DELETE FROM ProfilesPolls WHERE id_poll = '" . (int)$_GET['ID'] . "' AND id_profile = '{$member['ID']}' LIMIT 1"; |
|---|
| 64 | if ( db_res( $query ) ) |
|---|
| 65 | echo '<answer>no results</answer>'; |
|---|
| 66 | } |
|---|
| 67 | } |
|---|
| 68 | // CHANGE STATUS action ------------------------------------------------ |
|---|
| 69 | elseif ( 'status' == $_GET['action'] ) |
|---|
| 70 | { |
|---|
| 71 | if ( '' != $_GET['ID'] && $_GET['param'] ) |
|---|
| 72 | { |
|---|
| 73 | $query = "UPDATE ProfilesPolls SET `poll_status` = '{$_GET['param']}' WHERE id_poll = '" . (int)$_GET['ID'] . "' AND id_profile = '{$member['ID']}' LIMIT 1"; |
|---|
| 74 | if ( db_res( $query ) ) |
|---|
| 75 | echo '<answer>no results</answer>'; |
|---|
| 76 | } |
|---|
| 77 | } |
|---|
| 78 | // VOTE action -------------------------------------------------------- |
|---|
| 79 | elseif ( 'vote' == $_GET['action'] ) |
|---|
| 80 | { |
|---|
| 81 | |
|---|
| 82 | if ( '' != $_GET['ID'] ) |
|---|
| 83 | { |
|---|
| 84 | /* if ( '' != $_GET['param'] ) |
|---|
| 85 | { |
|---|
| 86 | $query = "SELECT poll_results FROM ProfilesPolls WHERE id_poll='" . (int)$_GET['ID'] . "'"; |
|---|
| 87 | $res_arr = db_arr( $query ); |
|---|
| 88 | |
|---|
| 89 | $results = explode( ';', $res_arr['poll_results'] ); |
|---|
| 90 | $results[$_GET['param']]++; |
|---|
| 91 | $poll_total_votes = array_sum($results); |
|---|
| 92 | $results = implode(';', $results); |
|---|
| 93 | |
|---|
| 94 | $iPollID = (int)$_GET['ID']; |
|---|
| 95 | if ( $_COOKIE["profile_polls_question_{$iPollID}"] > 0 ) { |
|---|
| 96 | //print 'Dublicate'; |
|---|
| 97 | } else { |
|---|
| 98 | $query = "UPDATE ProfilesPolls SET poll_results = '{$results}', poll_total_votes = '{$poll_total_votes}' WHERE id_poll='{$iPollID}'"; |
|---|
| 99 | $vProfPollRes = db_res( $query ); |
|---|
| 100 | if ( $vProfPollRes ) setcookie("profile_polls_question_{$iPollID}", 1 , time() + ( 10000 * 3600 ), '/' ); |
|---|
| 101 | } |
|---|
| 102 | }*/ |
|---|
| 103 | |
|---|
| 104 | $query = "SELECT * FROM ProfilesPolls WHERE id_poll='" . (int)$_GET['ID'] . "'"; |
|---|
| 105 | $res_arr = db_arr( $query ); |
|---|
| 106 | |
|---|
| 107 | $answers_points = explode(';', $res_arr['poll_results'] ); |
|---|
| 108 | |
|---|
| 109 | $answers_names = explode('<delim>', $res_arr['poll_answers'] ); |
|---|
| 110 | |
|---|
| 111 | echo '<results>'; |
|---|
| 112 | |
|---|
| 113 | $poll_total_votes = $res_arr['poll_total_votes']; |
|---|
| 114 | |
|---|
| 115 | foreach ($answers_points as $value) |
|---|
| 116 | { |
|---|
| 117 | if ( '' != $value ) |
|---|
| 118 | { |
|---|
| 119 | echo '<answer_point>'; |
|---|
| 120 | echo round( (0 != $poll_total_votes ? (( $value / $poll_total_votes ) * 100) : 0), 1); |
|---|
| 121 | echo '</answer_point>'; |
|---|
| 122 | |
|---|
| 123 | echo '<answer_num>'; |
|---|
| 124 | echo htmlspecialchars ( $value ); |
|---|
| 125 | echo '</answer_num>'; |
|---|
| 126 | } |
|---|
| 127 | } |
|---|
| 128 | |
|---|
| 129 | |
|---|
| 130 | foreach ($answers_names as $value) |
|---|
| 131 | { |
|---|
| 132 | if ( '' != $value ) |
|---|
| 133 | { |
|---|
| 134 | echo '<answer_name>'; |
|---|
| 135 | echo htmlspecialchars ( $value ); |
|---|
| 136 | echo '</answer_name>'; |
|---|
| 137 | } |
|---|
| 138 | } |
|---|
| 139 | |
|---|
| 140 | echo '</results>'; |
|---|
| 141 | |
|---|
| 142 | } |
|---|
| 143 | |
|---|
| 144 | } |
|---|
| 145 | else if ( 'questions' == $_GET[action] && $_GET[ID] ) |
|---|
| 146 | { |
|---|
| 147 | $query = "SELECT * FROM ProfilesPolls WHERE id_poll = '" . (int)$_GET[ID] . "'"; |
|---|
| 148 | |
|---|
| 149 | $res_arr = db_arr( $query ); |
|---|
| 150 | |
|---|
| 151 | echo '<poll>'; |
|---|
| 152 | |
|---|
| 153 | echo '<question>'; |
|---|
| 154 | echo htmlspecialchars ( $res_arr['poll_question'] ); |
|---|
| 155 | echo '</question>'; |
|---|
| 156 | |
|---|
| 157 | $questions = explode( '<delim>', $res_arr['poll_answers']); |
|---|
| 158 | |
|---|
| 159 | foreach ($questions as $value) |
|---|
| 160 | { |
|---|
| 161 | if ( '' != $value ) |
|---|
| 162 | { |
|---|
| 163 | echo '<answer>'; |
|---|
| 164 | echo htmlspecialchars ( $value ); |
|---|
| 165 | echo '</answer>'; |
|---|
| 166 | } |
|---|
| 167 | |
|---|
| 168 | } |
|---|
| 169 | |
|---|
| 170 | echo '</poll>'; |
|---|
| 171 | } |
|---|
| 172 | else |
|---|
| 173 | { |
|---|
| 174 | echo '<answer>no results</answer>'; |
|---|
| 175 | } |
|---|
| 176 | ?> |
|---|