Saturday, August 8, 2009

Poll Write-In & Change Vote Hack

About this hack:
I developed this hack for my board after several polls were made by members that were short on options, especially since the poll creators are sometimes biased with the poll options. I am sure you have seen the same on your boards.

This hack allows the poll creator to allow "Write-In Votes" to a poll (single or multiple). I also added the feature to change your vote if the poll is a "write-in vote" poll, you can also allow vote changes on all polls through an admin option (ver 1.2+). This will allow a user to change their vote if they discover a better poll option written in by another user, or if they want to add one or more write-in votes to a multiple choice poll.

An admin/moderator/etc. who has permission to edit a poll can change a poll to make it a write-in poll or not. (ver 1.3+)

The cancel/change vote feature works with single and multiple choice polls.

This is my first hack but please don't let that scare you away, this is a very basic hack.

Permission Overview:


There are very few permission checks with my hack;

* If you can create a poll, you can make it a write-in vote poll.
* If you can vote on the poll, you can add a write-in vote to a write-in poll.
* If the poll is closed you cannot change your vote or add a write-in vote of course.
* You cannot add a write-in vote to a non write-in vote poll.
* If you can Edit a Poll you can remove a write-in choice.

Permission Settings:


Located in vBulletin Options "Poll and Thread Rating Options" section.

* Allow users to change their votes in ANY poll. (Default NO)
* Show the username after a write-in vote. (Default Yes)
* If NO a log entry is written to the moderator log as per a request, see pic below
* Since version 3.6.8 vBulletin has had the ability to filter by product in the moderator log so you can filter the write-in votes if you chose not to have the username displayed.

Install Info:

* Files edited: 0
* Templates edited: 3
* Files to install: 1
* Time to install: 5 minutes max

Install Procedure:

1. Install the Product (Download the XML file)

2. Edit Template polloptions_table

FIND

PHP Code - SELECT ALL
<input type="submit" class="button" value="$vbphrase[vote_now]" />
ADD ABOVE

PHP Code - SELECT ALL
condition="$pollinfo[writein]"><span style="float:$stylevar[right]"><a href="poll.php?$session[sessionurl]do=addwritein&pollid=$pollinfo[pollid]">$vbphrase[add_writein_vote]a>&nbsp;&nbsp;span>
3. Edit Template pollresults_table

FIND

PHP Code - SELECT ALL
<td class="tfoot" colspan="4" align="center"><span class="smallfont">condition="$show['multiple']">$vbphrase[multiple_choice_poll] $vbphrase[voters]: <strong>$pollinfo[numbervotes]strong>. $pollstatusspan>td>
REPLACE WITH

PHP Code - SELECT ALL
<td class="tfoot" colspan="4" align="center"><span class="smallfont">condition="$show['multiple']">$vbphrase[multiple_choice_poll] $vbphrase[voters]: <strong>$pollinfo[numbervotes]strong>. $pollstatuscondition="$vbulletin->options['allchangevote'] OR $pollinfo[writein]">condition="$uservoted AND $pollinfo[active]">&nbsp;&nbsp;<a href="poll.php?$session[sessionurl]do=changevote&pollid=$pollinfo[pollid]">$vbphrase[change_vote]a>span>td>
4. Edit Template editpoll

FIND

PHP Code - SELECT ALL
condition="$show['makeprivate']">
<
fieldset class="fieldset">
<
legend>$vbphrase[poll_options]legend>
<
table cellpadding="0" cellspacing="$stylevar[formspacer]" border="0">
<
tr>
<
td><label for="cb_public"><input type="checkbox" name="public" value="1" id="cb_public" tabindex="1" $pollinfo[public] />$vbphrase[make_votes_public]label>td>
tr>
table>
fieldset>

REPLACE WITH

PHP Code - SELECT ALL
<fieldset class="fieldset"><legend>$vbphrase[poll_options]legend><table cellpadding="0" cellspacing="$stylevar[formspacer]" border="0">$addwriteincondition="$show['makeprivate']"><tr> <td><label for="cb_public"><input type="checkbox" name="public" value="1" id="cb_public" tabindex="1" $pollinfo[public] />$vbphrase[make_votes_public]label>td>tr>table>fieldset>
5. Enjoy!


Attached Files
File Type: xml product-poll_write_in_vote_3.7.xml‎


No comments: