Rye Voting

Summary: Voting with several option and graph bars
Version: 0.7 (2007-07-14)
Prerequisites: pmwiki-2b44
Last-tested-with: 2.1.27
Status: stable
Maintainer:
Categories: Voting Forms
Votes:

Goal

This cookbook alows voting with:

  • several options (vote items) with the possibility to allow
    • one answer per questions (radio buttons)
    • or multiple answer per questions (checkboxes)
  • drawing of the votings as graph
  • allow people to vote only once (by setting a cookie and logging the IP)
  • voting on edit protected pages

You can test the script out here.

For Users

Installation

  • download ryevote.phpΔ and put it into the cookbook folder
  • include the script in your config.php:
    include_once("$FarmD/cookbook/ryevote.php");

Administrative Tasks/Options

Out of the box the script only needs read privileges to vote. If you want to restrict this set in your config.php:

 $HandleAuth['ryevote'] = 'edit';

Activate (1) / deactivate (0) the IP/Cookie Check, (default: 1):

 $RyeVoteRestrictions = 0;

Hide vote after voting (works only with $RyeVoteRestrictions = 1; (default: 1)

 $RyeVoteHideAfterVote = 0;

Standard DB Page (default: Site.RyeVoteDB):

 $RyeVoteDBPName = Page.Name;

Message after vote (instead of vote form, default: "Thank you for your opinion! You have already voted."):

 $RyeVoteAfterVoteMsg = "Sorry, no second chance.";

Color of bars customizable (default: "siver"):

 $RyeVoteBarColor = "#00ab00";

Bar width in output customizable (default: "4"):

 $RyeVoteSizeFactor, "1");

Usage

The Input Form

The script uses the PmWiki Forms features. A vote looks like this:

 (:input form "{$PageUrl}?action=ryevote" :) 

 (:input radio vote-a somevalue:) Some Label 
 (:input radio vote-a someothervalue:) Some other Label 
 (:input hidden vote-a-name "!!!Question A":)

 (:input radio vote-b somevalue:) Some Label 
 (:input radio vote-b someothervalue:) Some other Label 
 (:input hidden vote-b-name "!!!Question B":)

 (:input checkbox vote-c[] somevalue:) Some Label 
 (:input checkbox vote-c[] someothervalue:) Some other Label 
 (:input hidden vote-c-name "!!!Question C":)

 (:input hidden redirect Page.Name:)
 (:input hidden db Page.Name:)

 (:input submit value="Vote":) 
 (:input hidden votename thevotename:) 
 (:input end:)
 
Some Label Some other Label Some Label Some other Label Some Label Some other Label
(:input form "{$PageUrl}?action=ryevote" :)
We call the ryevote script. Leave this line unchanged.
(:input radio vote-a somevalue:) Label Some Value
Every vote item needs some unique value somevalue. The text itself is completly with no meanings and can be random. If you want to use several radio buttons set in the same form you have to use a unique name for each button set. In this example: "vote-a" and "vote-b".
(:input hidden vote-a-name "!!!Question A":)
Optional. Sets an header for the output. Usefull if you use several votes in the same form. It has to be button set name followed by "-name". So for the button set "vote-a" it is "vote-a-name".
(:input checkbox vote-c[] somevalue:) Some Label
If you want to give the possibility to check more than one item per question use "checkbox" instead of "radio". Please notice, in this case you have to use square bracket after the unique name, in this case "vote-c[]".
(:input hidden redirect Page.Name:)
Optional. Redirects to Page.Name after the vote. Usefull to jump to a result or "thanks for voting" page.
(:input hidden db Page.Name:)
Optional. Use a data page different to the default. There is no space allowed between "Page.Name" and ":)"!
(:input submit value="Vote":)
You can set the text of the submit button to any value you want.
(:input hidden votename thevotename:)
A unique identifier for the vote form.
(:input end:)
Ends the input form. Leave this line unchanged.

Show output

(:ryevote db=Page.Name votename=thevotename:)
votename
The unique form identifier.
db
Optional. The data page if different from the default value.

Notes and Hints

Other elements in the form

Your can use other elements in the input form. To show text for example:

(:input form "{$PageUrl}?action=complexvote" :) 
Vote here, its important!\\
(:input radio vote somevalue:) Some Label 
...
(:input end:)

Vote here, its important!
Some Label ...

See Forms for further examples.

No edit after first voting

As soon as the first person voted you can't add one more question in the form or another item. If you want to do this, you have to edit the data page (default: Site.RyeVoteDB), too. or you have to delete all voting data collected so far. Be carefull, on the data page could bo the data from more than one voting!

Comments

Bugs

Bug, Division by zero

I got this error: Warning: Division by zero in /cdcv2/www/droenologie/html/floxwiki/cookbook/ryevote.php on line 137

Flo (29th Jan 2006)

Right after the install, after the first vote, occasionaly?
I got it right after I wrote the poll, before the first vote.

Bug, Grey Bars

I have this working in my wiki but I only seem to get two grey bars of the same size for the graphical output. I have tried this on your site and get the same thing too. Is this correct as I was expecting the bar length to represent the number of votes cast Dav Bacci, 23rd Jan 2006

It is a problem of IE, Firefox hasn't it.

flox, Jan 2006

I changed the script a little bit and uploaded a new version 0.4.2. There also was a glitch with Opera and I hope it will fix the IE problem too (can not test it here). - Schlaefer January 23, 2006, at 03:18 PM
Tried the version, but same problem as before: Sometimes if someone vote, it is destroyed. I have to use the History.... Flo, January 26, 2006
I tested with IE6, but could not reproduce the problem. If the corruption occurs, please post the destroyed code here. - Schlaefer January 27, 2006, at 03:23 AM
(:input form "http://droenologie.cybton.com/drdoswiki/pmwiki.php/Main/
HomePage?action=ryevoteRyeVotesDiagramDividerotheros
(:table:) (:tableend:)
But only at my first Wiki. Other hasn't this problem. I will reinstall it, maybe it helps. Flo Feb 11, 2006
I think I have figure out the reason why it's not working in IE. The problem is the _wiki formatting_ in It works with
the HTML output is
>>> this works _not_ >>>\\ <p><br/><br/>\\ </p><h1>Sometext<span style='display: block; background-color: \\ silver; color: silver;'></span></h1>\\ <table ><tr> ...
I think there is no reason for <span style='display: block; background-color: silver; color: silver;'></span>. Does somebody know how to fix this in ryevote.php?
cg, 2006-08-05

More Bars Issues

I'm having the same issue where the bars are the same size. For some reason, it appears that the width request is not being translated by the PmWiki engine.

The line:

    $out .= "(:cellnr:)".$names[$k]."\n(:cell:)%ryevotebox width=".$upbound."px% = \n";

Is interpreted as:

    <table ><tr><td  valign='top'> Yes
    </td><td  valign='top'><span  style='display: block; background-color: silver; color: silver;'>.</span>
    </td><td style="color:gray;"  valign='top'> (2/100%)
    </td></tr><tr><td  valign='top'> No
    </td><td  valign='top'><span  style='display: block; background-color: silver; color: silver;'>.</span>
    </td><td style="color:gray;"  valign='top'> (0/0%)
    </td></tr></table>

Kurt Devlin February 21, 2007, at 04:17 PM

Squelch multiple votes from one user

As far as I tested the script I could not see suppression of multiple votes made by one user. A fool can easily manipulate the votes by clicking multiple times same button. It should be possible to suppress ist either by use of cookies and/or user-IP storage. If I find some time, I'll try to add it. -Armin
I've to correct me. The test page provide by Schlaefer does not suppress multiple votes by one user. But when I installed the script in my Wiki, I could not make multiple votes: Thank you for your opinion! You have already voted.
The vote expires time is set in the script to a default value of 1 month by SDV($RyeVoteExpires, $Now +60 * 60 * 24 * 30); -Armin
It's the "and/or" feature of IP logging and cookies which is missing. I'd like to activate control via cookies, but not over IPs (as many users vote over the same proxy) -this seems to be impossible right now - mfeldt

Autovoting possible?

I am interested to learn about the possibility of including two different voting opptions in every page or section (splitsection) when they are created without the user to insert one of the kind. Is such an automation possible? New to PMwiki, so be explicit. Thanks! Sichendra

Look if edit templates fit your needs. - Schlaefer January 23, 2006, at 03:38 PM

Local Anchors

When there are multiple votes on a page, each vote returns you back to the top of the page, which gets annoying. It can be solved by adding local anchors to the form as follows.

 [[#somevotename]]
 (:input form "{$PageUrl}?action=ryevote#somevotename" :) 
 (:input radio vote somevalue:) One Vote
 (:input radio vote someothervalue:) Another Vote
 (:input submit value="Vote":) 
 (:input hidden votename somevotename:) 
 (:input end:)
 
 
One Vote Another Vote

Twiki PollPlugin+PeerPlugin Equivalent?

Is there anything like the twiki.org's PollPlugin and PeerPlugin equivalent in PMwiki? Or could the existing voting scripts could be improvised to that (twiki.org's voting scripts) standards? Sichendra

For Developers

There is a easy way to hook in your own output drawing code in the script.

Releases

See inside the script file. :

Saving to database?

is there a possibility to have the return result be save to mysql database?

User notes? : If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.