86 if(sizeof($l) < 1) return 'No polls created yet'; |
86 if(sizeof($l) < 1) return 'No polls created yet'; |
87 $ques = array_rand($l); |
87 $ques = array_rand($l); |
88 $poll_id = $l[$ques]['pid']; |
88 $poll_id = $l[$ques]['pid']; |
89 unset($l[$ques]['pid']); |
89 unset($l[$ques]['pid']); |
90 if(!$poll_id) die_semicritical('Surveyor plugin error', 'Invalid poll ID: '.$poll_id); |
90 if(!$poll_id) die_semicritical('Surveyor plugin error', 'Invalid poll ID: '.$poll_id); |
91 $q = $db->sql_query('SELECT * FROM '.table_prefix.'poll_results WHERE poll_id='.$poll_id.' AND ( ip_addr=\''.mysql_real_escape_string(ip2hex($_SERVER['REMOTE_ADDR'])).'\' OR user_id='.$session->user_id.' );'); |
91 $uidbit = $session->user_logged_in ? 'OR user_id='.$session->user_id : ''; |
|
92 $q = $db->sql_query('SELECT * FROM '.table_prefix.'poll_results WHERE poll_id='.$poll_id.' AND ( ip_addr=\''.$db->escape($_SERVER['REMOTE_ADDR']).'\' ' . $uidbit . ' );'); |
92 if(!$q) $db->_die('Error obtaining vote result information'); |
93 if(!$q) $db->_die('Error obtaining vote result information'); |
93 if($db->numrows() > 0) |
94 if($db->numrows() > 0) |
94 { |
95 { |
95 if(!isset($_GET['results'])) $_GET['results'] = ''; |
96 if(!isset($_GET['results'])) $_GET['results'] = ''; |
96 $_REQUEST['poll_id'] = $poll_id.''; |
97 $_REQUEST['poll_id'] = $poll_id.''; |
187 function __enanoVoteAjaxhandler($allow_vote = true) |
188 function __enanoVoteAjaxhandler($allow_vote = true) |
188 { |
189 { |
189 global $db, $session, $paths, $template, $plugins; // Common objects |
190 global $db, $session, $paths, $template, $plugins; // Common objects |
190 $ret = ''; |
191 $ret = ''; |
191 if(!isset($_REQUEST['poll_id'])) { die_semicritical('Critical error in plugin', '$_REQUEST[\'poll_id\'] is not set'); $paths->main_page(); exit; } |
192 if(!isset($_REQUEST['poll_id'])) { die_semicritical('Critical error in plugin', '$_REQUEST[\'poll_id\'] is not set'); $paths->main_page(); exit; } |
192 if(!preg_match('/^([0-9]+)$/', $_REQUEST['poll_id'])) die('Hacking attempt'); // Prevents SQL injection from the URL |
193 if(isset($_GET['poll_id']) && !preg_match('/^([0-9]+)$/', $_GET['poll_id'])) die('Hacking attempt'); // Prevents SQL injection from the URL |
|
194 if(isset($_POST['poll_id']) && !preg_match('/^([0-9]+)$/', $_POST['poll_id'])) die('Hacking attempt'); // Prevents SQL injection from the URL |
193 if(isset($_GET['results'])) |
195 if(isset($_GET['results'])) |
194 { |
196 { |
195 $q = $db->sql_query('SELECT p.poll_id AS pid,o.item_id AS oid,p.poll_question AS q,o.option_value AS v FROM '.table_prefix.'polls p, '.table_prefix.'poll_options o WHERE p.poll_id=o.poll_id AND p.poll_id=\''.$_GET['poll_id'].'\';'); |
197 $q = $db->sql_query('SELECT p.poll_id AS pid,o.item_id AS oid,p.poll_question AS q,o.option_value AS v FROM '.table_prefix.'polls p, '.table_prefix.'poll_options o WHERE p.poll_id=o.poll_id AND p.poll_id=\''.$_GET['poll_id'].'\';'); |
196 $l = Array(); |
198 $l = Array(); |
197 while($row = $db->fetchrow()) |
199 while($row = $db->fetchrow()) |
260 } else { |
262 } else { |
261 if(!isset($_POST['item_id']) || (isset($_POST['item_id']) && !preg_match('/^([0-9]+)$/', $_POST['item_id']))) die('Hacking attempt'); // Once again, ensure that only numbers are passed on the URL |
263 if(!isset($_POST['item_id']) || (isset($_POST['item_id']) && !preg_match('/^([0-9]+)$/', $_POST['item_id']))) die('Hacking attempt'); // Once again, ensure that only numbers are passed on the URL |
262 if(isset($_GET['redirect']) && $_GET['redirect'] == 'no') |
264 if(isset($_GET['redirect']) && $_GET['redirect'] == 'no') |
263 { |
265 { |
264 header('Content-type: text/plain'); |
266 header('Content-type: text/plain'); |
265 $q = $db->sql_query('SELECT * FROM '.table_prefix.'poll_results WHERE poll_id='.$_POST['poll_id'].' AND ( ip_addr=\''.mysql_real_escape_string(ip2hex($_SERVER['REMOTE_ADDR'])).'\' OR user_id='.$session->user_id.' );'); |
267 $uidbit = $session->user_logged_in ? 'OR user_id='.$session->user_id : ''; |
|
268 $q = $db->sql_query('SELECT * FROM '.table_prefix.'poll_results WHERE poll_id='.$_POST['poll_id'].' AND ( ip_addr=\''.$db->escape($_SERVER['REMOTE_ADDR']).'\' ' . $uidbit . ' );'); |
266 if(!$q) $db->_die('Error obtaining vote result information'); |
269 if(!$q) $db->_die('Error obtaining vote result information'); |
267 if($db->numrows() > 0) |
270 if($db->numrows() > 0) |
268 { |
271 { |
269 die('Looks like you already voted in this poll.'); |
272 die('Looks like you already voted in this poll.'); |
270 } |
273 } |
271 $q = $db->sql_query('INSERT INTO '.table_prefix.'poll_results(poll_id,item_id,ip_addr,user_id) VALUES('.$_POST['poll_id'].', '.$_POST['item_id'].', \''.ip2hex($_SERVER['REMOTE_ADDR']).'\', '.$session->user_id.');'); |
274 $q = $db->sql_query('INSERT INTO '.table_prefix.'poll_results(poll_id,item_id,ip_addr,user_id) VALUES('.$_POST['poll_id'].', '.$_POST['item_id'].', \''.$db->escape($_SERVER['REMOTE_ADDR']).'\', '.$session->user_id.');'); |
272 if(!$q) $db->_die('Your vote could not be inserted into the results table.'); |
275 if(!$q) $db->_die('Your vote could not be inserted into the results table.'); |
273 $ret .= 'Your vote has been cast.'; |
276 $ret .= 'Your vote has been cast.'; |
274 } else { |
277 } else { |
275 $paths->main_page(); |
278 $paths->main_page(); |
276 } |
279 } |