{{Poll q="Do you like WackoWiki?" a="Yes:No"}}Action: PollCurrent version: R4.2 and 4.3 svnCredits: Evaggelos Balaskas |
{{Poll q="Do you like WackoWiki?" a="Yes:No"}}
<!-- Action Poll -->
<?php
// WackoWiki Poll, Delimeter is ":"
// eg. {{Poll q="Do you like WackoWiki?" a="Yes:No"}}
$answers = explode(":",$a);
$filename = "files/polls_".$this->tag."_".md5($q);
if (!file_exists($filename)) {
$fp = fopen($filename, 'w');
foreach($answers as $ans)
$data .= $ans . "=0:";
fwrite($fp, substr($data, 0, -1));
fclose($fp);
}
if ( !empty( $_POST["answer"] ) ) {
$poll = file($filename);
$results = explode(":",$poll[0]);
for ( $i = 0 ; $i < count($results) ; $i++ ) {
$res = explode("=",$results[$i]);
if ( $res[0] == $_POST["answer"] ) $res[1]++;
$data .= $res[0] . "=" . $res[1] . ":";
$sum[$i][0] = $res[0];
$sum[$i][1] = $res[1];
$summary += $res[1];
}
for ( $i = 0 ; $i < count ( $sum ) ; $i++ ) {
$chart_values .= round( ($sum[$i][1]*100)/$summary, 2 ) . "," ;
$chart_data .= $sum[$i][0] . "(". round( ($sum[$i][1]*100)/$summary, 2 ) . "%)|" ;
}
?>
<p><strong><?php echo $q; ?></strong></p>
<p>Poll Results:</p>
<img src="http://chart.apis.google.com/chart?
chs=375x100
&chd=t:<?php echo substr($chart_values, 0, -1); ?>
&cht=p3
&chl=<?php echo substr($chart_data, 0, -1); ?>
&chtt=Total+Votes:+<?php echo $summary; ?>
"
alt="<?php echo $q; ?>" />
<p> </p>
<?php
$fp = fopen($filename, 'w');
fwrite($fp, substr($data, 0, -1));
fclose($fp);
$url = $this->GetConfigValue("base_url").$this->tag;
echo "<a href=\"".$url."\">Return</a>\n";
} else {
?>
<FORM method="POST">
<table border="0" cellpadding="3" cellspacing="0">
<TR>
<TD colspan="2"><strong><?php echo $q; ?></strong></TD>
</TR>
<?php
for ( $i = 0 ; $i < count($answers) ; $i++ ) {
?>
<tr>
<TD><?php echo $answers[$i]; ?></td>
<td><INPUT name="answer" value="<?php echo $answers[$i]; ?>" type="radio" <?php if ( $i == 0) echo "checked=\"true\""; ?>></TD>
</tr>
<?php
}
?>
<tr>
<TD colspan="2"><INPUT type="submit" value="Count me In"></TD>
</tr>
</table>
</FORM>
<?php
}
?>
<!-- Action Poll -->
//hacks "YourPhrase" => "your translation here",