4 This mpi allows for polls/surveys, whose results are stored into
8 <?plugin Survey data=PollOneData
9 answer1="I vote for this!"
10 second="another option"
11 3="no meaning on that issue."
14 Except for the data= setting, the named parameters are free-form and
15 only associate the text to an internal (named hash) entry.
17 If you later want to make a poll read-only, you could use:
18 <?plugin-show Survey data="data/var/poll1.dat" ... ?> (this is just
19 a pagename, that __looks__ like a filename).
23 define("EWIKI_UP_SURVEY", "_voting4");
26 $ewiki_plugins["mpi"]["survey"] = "ewiki_mpi_survey";
27 $ewiki_plugins["view_stat"][] = "ewiki_show_survey";
29 function ewiki_mpi_survey($action, &$args, &$iii, &$s)
31 global $ewiki_id, $ewiki_plugins;
35 if (! ($df = $args["data"])) {
41 $data = ewiki_db::GET($df);
42 if (!$data["version"]) {
43 $data = ewiki_new_data($df, EWIKI_DB_F_BINARY);
46 if ($data["flags"] != EWIKI_DB_F_BINARY) {
49 $survey = unserialize($data["content"]);
52 $vote = @$_REQUEST[EWIKI_UP_SURVEY];
62 . '<form action="'.$_SERVER["REQUEST_URI"].'" method="POST" enctype="multipart/form-data">'
63 . '<input type="hidden" name="id" value="'.htmlentities($ewiki_id).'">'
65 foreach ($args as $name=>$text) {
66 if (!$name || !$text || ($name=="data")) { continue; }
67 $o .= '<input type="radio" name="'.EWIKI_UP_SURVEY.'" value="'
68 . htmlentities($name) . '"> ' . $text . "<br />\n";
70 $o .= '<input type="submit" value="vote">';
71 $o .= "\n</form>\n<br /><br />\n";
72 $o .= '<a href="'.ewiki_script("",$ewiki_id,array(EWIKI_UP_SURVEY=>"$")).'">show results</a><br />';
78 $data["content"] = serialize($survey);
80 $data["lastmodified"] = time();
81 $data["author"] = ewiki_author();
82 ewiki_db::WRITE($data);
91 $o .= $ewiki_plugins["view_stat"][0]($survey, $args);
97 function ewiki_show_survey($count, $text) {
100 $char = "*"; // char for result bars (<img> alt text or <div> content)
101 $clen = 60; // max len of above
102 $px = 6; // pixel size of each $char, for CSS
104 "#ff8888", "#88ee88", "#9999ff", "#ffbb33", "#eeee66",
105 "#dd99dd", "#555555", "#dddddd",
106 // "poll1.png", "poll2.png", "poll3.png", "poll4.png", "poll5.png",
111 foreach ($text as $name=>$uu) {
112 $all += $count[$name];
113 $max = max($max, $count[$name]);
119 foreach ($text as $name=>$title) {
122 $n = 0 + $count[$name]; // number of votes
123 $n_percent = ((int) (1000*$n/$all))/10;
124 $bar_chars = (int)($clen * ($n/$max)); // num of chars in bar
125 $bar_width = $n_c * $px; // pixel width of bar
126 $bar_str = "[" . str_repeat($char, $bar_chars) . "]";
129 $color = $colors[$i];
130 if ($color{0} == "#") {
131 $bar = "<div style=\"color:$color; background:$color; width:$bar_width; height: 5px; border: 1px solid #333333;\">" . $bar_str . "</div>\n";
134 $bar = "<div><img src=\"$color\" height=\"6\" width=\"$bar_width\" alt=\"$bar_str\" /></div>";
137 $i %= count($colors);
140 $o .= "$title<br />\n";
141 $o .= "<b>$n</b> votes, $n_percent%<br />\n";