View source for Poll

{{anchor href="top"}}
Hits :  **{{hits}}**

Poll Example:

%%
{{Poll q="Do you like WackoWiki?" a="Yes:No"}}
%%

{{Poll q="Do you like WackoWiki?" a="Yes:No"}}


----

Original Page: http://wackowiki.org/Dev/PatchesHacks/Poll

{{hits}}

#||
||==Action: ~Poll== 
Current version: !!(green)**R4.2**!! and !!(red)**4.3 svn**!!
Credits: //Evaggelos Balaskas//
|{{toc numerate="1"}} ||
||#
##~{{Poll q="Do you like ~WackoWiki?" a="Yes:No"}}##

**~/actions/poll.php**
%%(php)

<!-- 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 -->

%%

====Documentation==
The code isnt perfect - i am still working on this.
I've just add http://chart.apis.google.com 

**ATTENTION** You must not change the answers!
I am working to find a good solution on this.

the result is something like this:
file:wacko_poll.jpg

====How to==

for users available for copy and paste

=====Localization (optional)==
put this at the end of your language file 

**/lang/wakka.xyz.php**
%%
//hacks
"YourPhrase" => "your translation here",
%%

pls. notice that this entry will not survive an Wacko upgrade, so you have to redo this

**[xyz] proposed translations**
[de] ...
[fr]
[ru]

====To Do==
  * Fix php code
  * Translate (if necessary)
  
{{backlinks}}