Hits : 3542

Poll Example:

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


Unknown action "Poll"




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

3542

Action: Poll

Current version: R4.2 and 4.3 svn
Credits: Evaggelos Balaskas
{{Poll q="Do you like WackoWiki?" a="Yes:No"}}

/actions/poll.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($fpsubstr($data0, -1));
  
fclose($fp);
}

if ( !empty( 
$_POST["answer"] ) ) {

$poll file($filename);
$results explode(":",$poll[0]);

for ( 
$i $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 $i count $sum ) ; $i++ ) {
  
$chart_values .= round( ($sum[$i][1]*100)/$summary) . "," ;
  
$chart_data .= $sum[$i][0] . "("round( ($sum[$i][1]*100)/$summary) . "%)|" ;
}

?>

<p><strong><?php echo $q?></strong></p>
<p>Poll Results:</p>
<img src="http://chart.apis.google.com/chart?
chs=375x100
&amp;chd=t:<?php echo substr($chart_values0, -1); ?>
&amp;cht=p3
&amp;chl=<?php echo substr($chart_data0, -1); ?>
&amp;chtt=Total+Votes:+<?php echo $summary?>
"
alt="<?php echo $q?>" />
<p>&nbsp;</p>
<?php
  $fp 
fopen($filename'w');
  
fwrite($fpsubstr($data0, -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 $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

There are no referring pages