Viewing file: poll.php (3.35 KB) -rwxr-xr-x Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
if(isset($isinc_poll)) return;
$isinc_poll = TRUE;
class Poll {
var $pid, $ident, $question, $tstamp, $status, $options, $nextcid;
var $voted, $votes, $tvotes, $highpct, $votepcts;
function Poll($lpid) {
########################
## -1 = random poll ##
## -2 = latest poll ##
## -3 = nonexistant ##
########################
global $s_dbid, $REMOTE_ADDR, $s_blength, $s_iplog;
symp_connect();
if($lpid == -1) {
$q1 = "SELECT pid FROM sympoll_list WHERE(status!=0)";
$r1 = mysql_query($q1, $s_dbid);
$rows = mysql_numrows($r1);
srand((double) microtime() * 1000000);
$pollnum = (rand() / getrandmax()) * $rows;
$lpid = mysql_result($r1, $pollnum, 'pid');
} elseif($lpid == -2) {
$q2 = "SELECT pid FROM sympoll_list WHERE(status!=0) ORDER BY timeStamp DESC LIMIT 1";
$r2 = mysql_query($q2, $s_dbid);
$a2 = mysql_fetch_array($r2);
$lpid = $a2['pid'];
}
$q3 = "SELECT * FROM sympoll_list,sympoll_data ";
$q3 .= "WHERE(sympoll_list.pid='$lpid' AND sympoll_data.pid='$lpid') ORDER BY cid";
$r3 = mysql_query($q3, $s_dbid);
if(mysql_numrows($r3) <= 0) {
$this->pid = -3;
} else {
$a3 = mysql_fetch_array($r3);
$this->pid = $lpid;
$this->ident = htmlspecialchars(stripslashes($a3['identifier']));
$this->nextcid = $a3['nextcid'];
$this->question = htmlspecialchars(stripslashes($a3['question']));
$this->tstamp = $a3['timeStamp'];
$this->status = $a3['status'];
$this->tvotes = 0;
do {
$cid = $a3['cid'];
$this->options[$cid] = htmlspecialchars(stripslashes($a3['choice']));
$this->votes[$cid] = $a3['votes'];
$this->tvotes += $a3['votes'];
} while($a3 = mysql_fetch_array($r3));
$this->voted = 0;
if($s_iplog != "0") {
$q4 = "SELECT voted FROM sympoll_iplog WHERE(ip='$REMOTE_ADDR' AND pid='$this->pid')";
$r4 = mysql_query($q4, $s_dbid);
if(mysql_numrows($r4) > 0) {
$now = time();
$a4 = mysql_fetch_array($r4);
if($now > ($a4['voted'] + ($s_blength * 86400)) ) {
$q5 = "DELETE FROM sympoll_iplog WHERE(ip='$REMOTE_ADDR' AND pid='$this->pid')";
$r5 = mysql_query($q5, $s_dbid);
} else {
$this->voted = $a4['voted'];
}
}
}
}
symp_disconnect();
}
function inc_vote($cid) {
global $s_dbid, $s_iplog, $REMOTE_ADDR;
symp_connect();
if($s_iplog != "0") {
$now = time();
$q1 = "INSERT INTO sympoll_iplog (ip,pid,voted) VALUES('$REMOTE_ADDR','$this->pid','$now')";
$r1 = mysql_query($q1, $s_dbid);
}
$q2 = "UPDATE sympoll_data SET votes=votes+1 WHERE(pid='$this->pid' AND cid='$cid')";
$r2 = mysql_query($q2, $s_dbid);
symp_disconnect();
}
function calc_pcts() {
$this->highpct = -1;
while(is_array($this->votes) && list($k,$v) = each($this->votes)) {
if($this->tvotes > 0) {
$this->votepcts[$k] = round(($v / $this->tvotes) * 100);
} else {
$this->votepcts[$k] = 0;
}
if($this->votepcts[$k] > $this->highpct)
{ $this->highpct = $this->votepcts[$k]; }
}
if(is_array($this->votes))
{ reset($this->votes); }
}
}
?>
|