Location: PHPKode > projects > ZompLog > plugins/poll/poll.inc.php
<?php

class wmpoll {
function wmpoll($bezoeker) {
$this->bezoeker = $bezoeker;
}

function htmlparse($string){
return htmlentities(trim($string), ENT_QUOTES);
}

function stem($vote) {
GLOBAL $prefix;
if(is_numeric($vote) && $vote >= 1 && $vote <= 10) {
$id = $this->list['id'];
$gestemd = $this->list['gestemd']."(".$this->bezoeker.",".$vote.")";
$sql = @mysql_query("UPDATE $prefix"."_poll SET antwoord".$vote."=antwoord".$vote."+1, gestemd='".$gestemd."' WHERE id='$id'");
if($sql) {
$this->list["antwoord".$vote]++;
}
}
}

function archief($aantal=0) {
GLOBAL $HTTP_SERVER_VARS, $prefix;
if($aantal != 0) {
$limit = " LIMIT ".$aantal;
} else {
$limit = "";
}
$sql = @mysql_query("SELECT id, vraag FROM $prefix"."_poll ORDER BY id DESC".$limit);
echo "<select name=\"pollarchief\" onChange=\"window.location=('".$HTTP_SERVER_VARS['PHP_SELF']."?pollid='+this.options[this.selectedIndex].value)\">\n<option value=\"\">Archief</option>/n";
while($list = @mysql_fetch_assoc($sql)) {
echo "<option value=\"".$list['id']."\">".$this->htmlparse($list['vraag'])."</option>\n";
}
echo "</select>\n";
}

function toon($id=0, $magstemmen=1, $balkje=200, $kleur1="#A9A9A9", $kleur2="#FF9900") {
GLOBAL $HTTP_POST_VARS, $HTTP_SERVER_VARS, $prefix;
if($id == 0) {
$sql = @mysql_query("SELECT * FROM $prefix"."_poll WHERE actief='1' ORDER BY id DESC LIMIT 1");
} else {
$id = addslashes($id);
$sql = @mysql_query("SELECT * FROM $prefix"."_poll WHERE id='$id'");
}

// bestaat poll?
$bestaat = @mysql_num_rows($sql);
if($bestaat == 0 && $id == 0) {
echo "Error: there is currently no active poll!\n";
} elseif($bestaat == 0) {
echo "Error: the requested poll doesn't exist!\n";
} else {

$this->list = @mysql_fetch_assoc($sql);

// mag de bezoeker stemmen?
if($magstemmen == 0 || preg_match("/\(".$this->bezoeker.",/", $this->list['gestemd'])) {
$magstemmen = 0;
} else {
$magstemmen = 1;
}

// poll type
if($this->list['actief'] == 1) {
$type = "Actief";
} else {
$type = "Archief";
$magstemmen = 0;
}

// stem opslaan
if($magstemmen == 1 && isset($HTTP_POST_VARS['pollvote']) && isset($HTTP_POST_VARS['pollid']) && $HTTP_POST_VARS['pollid'] == $this->list['id']) {
$this->stem($HTTP_POST_VARS['pollvote']);
$magstemmen = 0;
}

// totaal aantal stemmen
$totaal = 0;
for($x=1; $x<=10; $x++) {
$totaal = $totaal + $this->list["antwoord".$x];
}

// poll weergeven
if($magstemmen == 1) {
echo "<form action=\"".$HTTP_SERVER_VARS['REQUEST_URI']."\" method=\"POST\">\n<input type=\"hidden\" name=\"pollid\" value=\"".$this->list['id']."\">\n";
}
echo "<b>".$this->htmlparse($this->list['vraag'])."</b><br>\nStemmen: ".$totaal."<br><br>\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n";

for($x=1; $x<=10; $x++) {
if(!empty($this->list["keuze".$x])) {
// resultaten berekenen
if($totaal != 0) {
$procent = round(($this->list["antwoord".$x]/$totaal)*100);
$balk = ($this->list["antwoord".$x]/$totaal)*$balkje;
} else {
$procent = 0;
$balk = 0;
}

echo "<tr>";
if($magstemmen == 1) {
echo "<td><input type=\"radio\" name=\"pollvote\" value=\"".$x."\"></td>";
}
echo "<td><b>".$this->htmlparse($this->list["keuze".$x])."</b></td><td align=\"right\">".$procent." %</td>
<table width=\"".$balkje."\" height=\"10\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"border: 1px solid ".$kleur1.";\">
<tr><td width=\"".$balk."\" bgcolor=\"".$kleur2."\"></td><td width=\"".($balkje-$balk)."\"></td></tr>
</table>
</td></tr>";
}
}

echo "</table>\n";

if($magstemmen == 1) {
echo "<br><input type=\"submit\" name=\"submit\" id=\"inputveld\" value=\"Stem\">\n</form>\n";
}
}
}
}
?>
Return current item: ZompLog