$filename,"topic" => $topic); } unset($index,$nr,$filename); // nothing printed yet, get id for specific vote to show/vote for $topic = ""; if (isset($_GET["id"]) && is_numeric($_GET["id"])) { $x = intval($_GET["id"]); if ($x > 0 && $x < 99999 && isset($voteindex[$x])) { $nr = $x; $arr = $voteindex[$nr]; $filename = $arr["filename"]; $topic = ": ".($htopic = $arr["topic"]); $voters = $filename.".voters"; $votenum = $filename.".vote"; } } // nothing printed yet, check for cookie, user might be known and logged in $ok = FALSE; if (isset($_COOKIE["ee"])) { list($eeuser,$eepass) = explode("_",$_COOKIE["ee"],2); $eepass = base64_decode($eepass."=="); $fn = "forum/users/".strtolower($eeuser); if (file_exists($fn)) { $pass = $admin = ""; $x = trim(file_get_contents($fn)); $x = explode("\n",$x); foreach($x as $line) { if (strpos($line,"pass ") === 0) $pass = substr($line,5); if (strpos($line,"admin ") === 0) $admin = substr($line,6); } unset($x,$line); if ($pass && $pass == $eepass && $admin == "yes") { $ok = TRUE; $user = $eeuser; } } unset($pass,$admin,$eepass,$eeuser); } $box = ""; if ($ok) { $box = "
".$user ."

" ."Log
\n"; if (isset($_GET["add"])) $add = ""; } if (isset($nr)) include "users/vote/votenr.html"; else include "users/vote/votelist.html"; if (isset($filename)) { $x = trim(file_get_contents($filename)); $x = explode("<:message:>",$x,2); $body = array_pop($x); unset($x); } /* * display a single vote topic */ if (isset($body) && strpos($body,"[vote option ") !== FALSE) { $ip = $_SERVER["REMOTE_ADDR"]; if (isset($htopic)) { echo "

".$htopic."

\n"; } if (canvote() == TRUE && !isset($castvote)) { echo "

" ."Click the option of your choice to cast your vote.

\n"; } if (isset($_SERVER["HTTP_USER_AGENT"]) && strpos($_SERVER["HTTP_USER_AGENT"],'Yahoo! Slurp') !== FALSE) { // _SERVER["HTTP_USER_AGENT"] = Yahoo! Slurp //file_put_contents("log","[".gmdate("g:ia D M j Y")."] " // .$ip." ignored Yahoo Slurp {vote.php}\n",FILE_APPEND); unset($castvote); } $vote = array(); $sum = $max = 0; if (file_exists($votenum)) { $x = explode("\n",trim(file_get_contents($votenum))); foreach($x as $v) if ($v) { list($id,$n) = explode(" ",$v,2); $n = intval($n); $id = intval($id); $vote[$id] = $n; if ($n > $max) $max = $n; $sum += $n; } unset($x,$v,$n,$id); } if (isset($castvote)) { $vote[$castvote] = (isset($vote[$castvote])) ? ($vote[$castvote] + 1) : 1; $x = $vote[$castvote]; if ($x > $max) $max = $x; $sum += 1; $save = ""; foreach($vote as $id => $n) { $save .= $id." ".$n."\n"; } $m1 = "--"; $m2 = $nr; if (isset($voteindex[$nr])) { $m1 = $voteindex[$nr]["topic"]; $m2 = array_pop(explode("/",$voteindex[$nr]["filename"],2)); } $x = ($ok) ? " ($user)" : ""; file_put_contents($votenum,$save); file_put_contents("log","[".gmdate("g:ia D M j Y")."] " .$ip.$x." user vote opt $castvote ($m2 $m1) {vote.php}\n",FILE_APPEND); unset($save,$castvote,$x,$m1,$m2); } $x = explode("\n",str_replace("\r","",$body)); $body = ""; foreach($x as $v) { if (preg_match("#^\[vote option (\d+) (.+)\]$#",$v,$m) == 1) { $id = intval($m[1]); $vo = trim($m[2]); $ct = (isset($vote[$id])) ? $vote[$id] : 0; $wi = (isset($vote[$id])) ? 200*($ct/$max) : 0; $pc = (isset($vote[$id])) ? 100*($ct/$sum) : 0; $pc = number_format($pc,1,'.',','); $c = "vote?id=$nr&vote=$id"; $u = "".$vo.""; if ($wi > 0) { $body .= "".$u."" ."$ct" ."$pc%" ."" ."\"*\"\n"; } else { $body .= "".$u."" ."-" ."-" ."\n"; } } else $body .= $v."\n"; } list($null,$fid,$mytid) = explode("/",$filename,3); echo "".$body."
\n"; $vword = ($sum == 1) ? "vote" : "votes"; echo "
Total: $sum $vword." ."
(forum discussion (add comments))
\n"; } /* * display a list of vote topics */ if (!isset($nr)) { // separating line $body = "

\n"; $templist = array(); $tempnum = array(); $i = 0; foreach($voteindex as $nr => $arr) { $filename = $arr["filename"]; $topic = $arr["topic"]; $x = trim(file_get_contents($filename.".vote")); $x = explode("\n",$x); $sum = 0; foreach($x as $v) if ($v) { list($id,$n) = explode(" ",$v,2); $n = intval($n); $sum += $n; } $vword = ($sum == 1) ? "vote" : "votes"; $templist[] = array($sum,"".$topic."$sum $vword\n"); $i++; } rsort($templist); foreach($templist as $v) { $body .= array_pop($v); } // separating line $body .= "

\n"; echo "
".$body."
\n"; } ?>