function canvote() { if (isset($_GET["vote"]) && is_numeric($_GET["vote"])) { if ($GLOBALS['ok'] == FALSE) // is not an admin { /* * check if the ip has already voted */ $ip = $_SERVER["REMOTE_ADDR"]; $vfn = $GLOBALS['voters']; // file containing IP's that has already voted if (file_exists($vfn)) { $vlist = explode("\n",trim(file_get_contents($vfn))); foreach($vlist as $vip) { if ($vip == $ip) { return(FALSE); } } } @file_put_contents($vfn,$ip."\n",FILE_APPEND); } $GLOBALS['castvote'] = intval($_GET["vote"]); } return(TRUE); } // nothing printed yet, make array (read from file) of vote topics $index = explode("\n",trim(file_get_contents("votelist"))); $voteindex = array(); foreach($index as $v) if ($v) { list($nr,$filename,$topic) = explode(";",$v,3); $voteindex[$nr] = array("filename" => $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 = "
" ."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 .= "