======= MultiPoll Plugin ====== ---- plugin ---- description: Lets you add slightly extended polls to a wiki page # (from poll plugin by Gina Häußge, Michael Klier and previously Esther Brunner) author : Etienne MELEARD email : etienne.meleard@free.fr type : syntax lastupdate : 2010-04-12 compatible : Detritus, Greebo, !Hogfather depends : conflicts : similar : poll, userpoll tags : extended poll, poll, !experimental downloadurl: https://trello.com/1/cards/5afdce92c41a16189740888e/attachments/5afdcec570defdb9b490bfcb/download/multipoll.zip bugtracker : sourcerepo : donationurl: screenshot_img: ---- > :!: This plugin is the result of an attempt of mine to make the original poll plugin meet my requirements, I heavily hacked into its code, thus it looks very similar... I do not attempt to "steal" the original work, but the code I ended with was too much different to just propose a patch... If the authors of the poll plugin are interested in a merge, they are welcome! :!: **Animated** version, adopted from [[http://cssdeck.com/labs/animated-progress-bar|cssdeck.com]] can be downloaded [[http://comicslate.org/_media/wiki/dokuplug/multipoll1.tgz|here]] **(MD5 sum 392d7a5075aaf36c6f49feecdb67bd15)** :!: Animated version with **conf[width of poll bars]** can be downloaded [[http://comicslate.org/_media/wiki/dokuplug/multipoll2.tgz|here]] **(MD5 sum 4cbf093a456e6414cb9960e626f06f70)** :!: Universal bug (at least in Binky) - __nonregistered users can press F5 for reload page and automatically adding votes for first answers in all questions__. That crush all. ===== Syntax ===== Use this plugin to add a poll to a wiki page. The syntax looks like this: [question 1] * [option] * [option] * ... [question 2] * [option] * [option] [multivaluated question] + [option] + [option] + [option] + ... ^[hideresults] | hides the results of the poll to users who don't have write access on the page, displays a "You already voted" message instead | optional | ^[hideifvoted] | completly hides the poll once the user voted, only users with write access on the page can see the results | optional | ^[showresultsto] | comma separated list of users or @groups which can see the results without the need to vote or to have editing rights | optional | ^[id] | the ID of the poll; must be unique((If it is not, metadata of the polls with the same id gets mixed up, i.e. users with IPs who have voted for a previous poll with that id can't vote again.)); appears as title ^ required | ^[question] | the question you'd like to ask | optional | ^[option] | a possible answer to the immediately above question ^ required | The poll title is converted to a md5sum. This is used as the filename in data/meta: md5sum.multipoll - so all polls in the whole wiki must be unique. As a result you can move your poll around and the poll data is accessible. If you remove the poll you must remove the poll data with "rm". ===== Installation Notes ===== When the [[blog]] plugin is also installed, you need to turn ''$conf['plugin']['blog']['useifmodifiedsince']'' off. I will try to eliminate this incompatibility. ===== Discussion ===== Following patch provides: * Fix - poll results percentage indicators are accurate even in case when user votes for some questions while not choosing any radio-button for other questions * Feature - IP can vote again after one hour time limit expires * Feature - After vote, return user to $ID.'#anketa', that means his browser is pointed to poll results * Feature - More space is added between two questions so they can be easily distinguished --- syntax.orig.php 2010-04-12 18:08:48.000000000 +0200 +++ syntax.php 2010-06-06 21:48:50.000000000 +0200 @@ -151,6 +151,8 @@ if($save) { $poll['votes']++; $poll['ips'][] = $ip; + // CHANGE + $poll['time'] = time(); if($_SERVER['REMOTE_USER']) $poll['users'][] = $_SERVER['REMOTE_USER']; if($fh = fopen($pfile, 'w')) { fwrite($fh, serialize($poll)); @@ -158,7 +160,7 @@ } $voted = true; } - }elseif(in_array($ip, $poll['ips']) || ($_SERVER['REMOTE_USER'] && in_array($_SERVER['REMOTE_USER'], $poll['users']))) { + }elseif( (in_array($ip, $poll['ips']) /*CHANGE - one hour limit*/ && time()-$poll['time'] <= 60*60) || ($_SERVER['REMOTE_USER'] && in_array($_SERVER['REMOTE_USER'], $poll['users']))) { $voted = true; } @@ -188,11 +190,20 @@ foreach($questions as $question) { $ret .= '
'.$renderer->_xmlEntities($question['q']).'
'."\n"; $ret .= ' '."\n"; + // CHANGE - Find total number of votes for this question; note this might be different from $poll['votes'], + // since user might vote only for some questions and not for others + $total = 0; + foreach($question['a'] as $a) { + $s = isset($poll['results'][$q]) ? (isset($poll['results'][$q][$a]) ? $poll['results'][$q][$a] : 0) : 0; + $total += $s; + } foreach($question['a'] as $a) { $ret .= ' '."\n"; $a = $renderer->_xmlEntities($a); $s = isset($poll['results'][$q]) ? (isset($poll['results'][$q][$a]) ? $poll['results'][$q][$a] : 0) : 0; - $pct = sprintf('%3.1f', 100 * $s / $poll['votes']); + // CHANGE + // $pct = sprintf('%3.1f', 100 * $s / $poll['votes']); + $pct = sprintf('%3.1f', 100 * $s / $total); $ret .= ' '."\n"; $ret .= ' '."\n"; $ret .= ' '."\n"; @@ -209,7 +220,9 @@ global $lang; global $ID; - $ret = ''."\n"; + // CHANGE + // $ret = ''."\n"; + $ret = ''."\n"; $ret .= '
'."\n"; $ret .= ' '."\n"; $ret .= ' '."\n"; @@ -225,7 +238,8 @@ $ret .= ' '.$a.'
'."\n"; }else $ret .= ' '.$a.'
'."\n"; } - $ret .= '
'."\n"; + // CHANGE + $ret .= '


'."\n"; $q++; } $ret .= ' '."\n";
'.$a.'
'.($s ? '
 
' : '').'
'.$pct.'% ('.$s.')