Kód: Vybrať všetko
<?php
class Poll {
var $pid, $ident, $question, $tstamp, $status, $options, $nextcid;
function Poll($lpid, $dbid=0) {
global $be_sympoll_list,$be_sympoll_data;
////////////////////////
// -1 = random poll //
// -2 = latest poll //
// -3 = nonexistant //
// >0 = that poll id //
////////////////////////
if($dbid == 0) {
GLOBAL $dbhost, $dbuser, $dbpass, $dbname;
// Please let [email protected] know if you get errors on these two lines (and what was happening at the time)
MYSQL_CONNECT($dbhost,$dbuser,$dbpass) OR DIE("Unable to connect.");
MYSQL_SELECT_DB("$dbname") OR DIE("Unable to select database");
}
// random poll
if($lpid == -1) {
$query = "SELECT pid from $be_sympoll_list WHERE(status!=0)";
$result = MYSQL_QUERY($query);
$rows = MYSQL_NUMROWS($result);
srand((double) microtime() * 1000000);
$pollnum = (rand() / getrandmax()) * $rows;
$lpid = MYSQL_RESULT($result,$pollnum,"pid");
}
// latest poll
elseif($lpid == -2) {
$query = "SELECT pid from $be_sympoll_list WHERE(status!=0) ORDER BY timeStamp DESC LIMIT 1";
$result = MYSQL_QUERY($query);
$lpid = MYSQL_RESULT($result,0,"pid");
}
$query = "SELECT * from $be_sympoll_list WHERE pid='$lpid'";
$result_l = MYSQL_QUERY($query);
$query = "SELECT cid,choice from $be_sympoll_data WHERE pid='$lpid' ORDER BY cid";
$result_d = MYSQL_QUERY($query);
if($dbid==0)
{MYSQL_CLOSE();}
if (!empty($result_l)) if(MYSQL_NUMROWS($result_l) <= 0) { $this->pid = -3; }
else {
$this->pid = $lpid;
$this->ident = htmlspecialchars(stripslashes(MYSQL_RESULT($result_l,0,"identifier")));
$this->nextcid = MYSQL_RESULT($result_l,0,"nextcid");
$this->question = htmlspecialchars(stripslashes(MYSQL_RESULT($result_l,0,"question")));
$this->tstamp = MYSQL_RESULT($result_l,0,"timeStamp");
$this->status = MYSQL_RESULT($result_l,0,"status");
$rows = MYSQL_NUMROWS($result_d);
for($i = 0; $i < $rows; $i++) {
$cid = MYSQL_RESULT($result_d,$i,"cid");
$this->options[$cid] = htmlspecialchars(stripslashes(MYSQL_RESULT($result_d,$i,"choice")));
} //for
} //else
} //constructor
} //end class Poll
?>