get( "usergroup" );
if( ! $user_group ) {$user_group = array ();
$db->query( "SELECT * FROM " . USERPREFIX . "_usergroups ORDER BY id ASC" );
while ( $row = $db->get_row() ) {$user_group[$row['id']] = array ();
foreach ( $row as $key => $value ) {$user_group[$row['id']][$key] = stripslashes($value);}
}
$cache->set( "usergroup", $user_group );
$db->free();
}
require_once SYSTEM_DIR . '/modules/sitelogin.php';
function votes($all, $ansid) {
$data = array ();
$alldata = array ();
if( $all != "" ) {
$all = explode( "|", $all );
foreach ( $all as $vote ) {
list ( $answerid, $answervalue ) = explode( ":", $vote );
$data[$answerid] = intval( $answervalue );
}
}
foreach ( $ansid as $id ) {
$data[$id] ++;
}
foreach ( $data as $key => $value ) {
$alldata[] = intval( $key ) . ":" . intval( $value );
}
$alldata = implode( "|", $alldata );
return $alldata;
}
function get_votes($all) {
$data = array ();
if( $all != "" ) {
$all = explode( "|", $all );
foreach ( $all as $vote ) {
list ( $answerid, $answervalue ) = explode( ":", $vote );
$data[$answerid] = intval( $answervalue );
}
}
return $data;
}
$news_id = intval( $_REQUEST['news_id'] );
$answers = explode( " ", trim( $_REQUEST['answer'] ) );
$buffer = "";
$vote_skin = trim(totranslit( $_REQUEST['vote_skin'], false, false));
$_IP = $db->safesql( $_SERVER['REMOTE_ADDR'] );
if( $is_logged ) $log_id = intval( $member_id['user_id'] );
else $log_id = $_IP;
$poll = $db->super_query( "SELECT * FROM " . PREFIX . "_poll WHERE news_id = '{$news_id}'" );
$log = $db->super_query( "SELECT COUNT(*) as count FROM " . PREFIX . "_poll_log WHERE news_id = '{$news_id}' AND member ='{$log_id}'" );
if( $log['count'] and $_REQUEST['action'] != "list" ) $_REQUEST['action'] = "results";
if($_REQUEST['action'] != "list" AND !$user_group[$member_id['user_group']]['allow_poll']) $_REQUEST['action'] = "results";
$votes = "";
if( $_REQUEST['action'] == "vote" ) {
$votes = votes( $poll['answer'], $answers );
$db->query( "UPDATE " . PREFIX . "_poll set answer='$votes', votes=votes+" . count( $answers ) . " WHERE news_id = '{$news_id}'" );
$db->query( "INSERT INTO " . PREFIX . "_poll_log (news_id, member) VALUES('{$news_id}', '$log_id')" );
$_REQUEST['action'] = "results";
}
if( $_REQUEST['action'] == "results" ) {
if( $votes == "" ) {
$votes = $poll['answer'];
$allcount = $poll['votes'];
} else {
$allcount = count( $answers ) + $poll['votes'];
}
$answer = get_votes( $votes );
$body = explode( "
", stripslashes( $poll['body'] ) );
$pn = 0;
for($i = 0; $i < sizeof( $body ); $i ++) {
$num = $answer[$i];
if( ! $num ) $num = 0;
++ $pn;
if( $pn > 5 ) $pn = 1;
if( $allcount != 0 ) $proc = (100 * $num) / $allcount;
else $proc = 0;
$proc = round( $proc, 2 );
$buffer .= <<