Go Back   vb.org Archive > vBulletin Modifications > Archive > vB.org Archives > vBulletin 2.x > vBulletin 2.x Full Releases

Reply
 
Thread Tools
Details »»

Version: , by Flare Flare is offline
Developer Last Online: Mar 2016 Show Printable Version Email this Page

Version: 2.2.x Rating:
Released: 04-30-2001 Last Update: Never Installs: 3
 
No support by the author.

As promised a few weeks ago, I finally found some time to make the much needed addition to allow users to change their votes in a poll. After examining the code a bit, I ended up reusing some of the vB code for this ... I hope this isn't a violation of the hacks rules. I read through them, and I think the code re-use is so small and specialized that it will be ok for redistribution via this forum. If it's not, please feel free to edit/lock this thread, I just ask that a moderator let me know what parts are unacceptable.

Here is the hack, it's fairly simple:

Open up poll.php:

At the bottom of the file, find ?>

Just above this, insert this code:

PHP Code:
// #################################### Change Vote ##########################################

if ($action=="changevote"

{

  
// other permissions?
  
$permissions=getpermissions($forumid);
  if (!
$permissions[canview] or !$permissions[canvote]) {
    
show_nopermission();
  }

  
$pollid=verifyid("poll",$pollid);
  
$pollinfo=$DB_site->query_first("SELECT * FROM poll WHERE pollid='$pollid'");
  
$voteinfo=$DB_site->query_first("SELECT * FROM pollvote WHERE userid='$bbuserinfo[userid]' AND pollid='$pollid'");

  
$threadinfo=$DB_site->query_first("SELECT * FROM thread WHERE pollid='$pollid' AND open<>10");
  
$threadcache[$threadinfo[threadid]]=$threadinfo;
  
  
//check if poll is closed
  
if (!$pollinfo[active] or !$threadinfo[open] or ($pollinfo[dateline]+($pollinfo[timeout]*86400)<time() and $pollinfo[timeout]!=0)){ //poll closed
     
eval("standarderror(\"".gettemplate("error_pollclosed")."\");");
     exit;
  }

    
//check if a user has already voted - abuse management
    
if (!$uservoteinfo=$DB_site->query_first("SELECT userid FROM pollvote WHERE userid=$bbuserinfo[userid] AND pollid='$pollid'"))
    {
      
//the user has not voted yet
      
eval("standarderror(\"".gettemplate("error_userhasnotvoted")."\");");
      exit;
    }

    
//Error checking complete, lets get the options
    
$timenow time();
    
$DB_site->query("DELETE FROM pollvote WHERE pollid='$pollid' AND userid='$bbuserinfo[userid]' LIMIT 1");

    
$splitvotes=explode("|||",$pollinfo[votes]);
    
$splitvotes[$voteinfo[voteoption]-1]--;

    
$counter=0;
    while (
$counter<$pollinfo[numberoptions]) {
      
$votesstring.="|||".intval($splitvotes[$counter]);
      
$counter++;
    }
    if (
substr($votesstring,0,3)=="|||") {
      
$votesstring=substr($votesstring,3);
    }

    
$DB_site->query("UPDATE poll SET votes='".addslashes($votesstring)."' WHERE pollid='$pollid'");

    
//make last reply date == last vote date
    
if ($updatelastpost){ //option selected in CP
      
$DB_site->query("UPDATE thread SET lastpost=$timenow WHERE threadid=$threadinfo[threadid]");
    }

    
// redirect
    
eval("standardredirect(\"".gettemplate("redirect_pollchange")."\",\"showthread.php?s=$session[sessionhash]&threadid=$threadinfo[threadid]\");");
  } 
Save poll.php and upload it.

In your templates, you will need to add two templates and modify 1 existing one.

First:

Code:
Add template " error_userhasnotvoted "

The text of the template should be: 

You have not voted on this thread, so you can not change your vote.
Second:

Code:
Add template " redirect_pollchange "

The text of the template should be:

You have deleted your vote.  You will be taken to the poll, where you will be allowed to revote.
Lastly:

Code:
Edit your "showthread_pollresults_voted" template.

Change the text to:

You have already voted on this poll!
<BR>If you wish to change your vote, click <a href="poll.php?action=changevote&pollid=$pollinfo[pollid]">here</a>.
That's it...

Now your users will have the option to erase thier vote and revote. Not <i>quite</i> as elegant as allowing them to actually revote, but it will suffice for now ... at least for me. Someone feel free to expand on this if they want something a bit more robust.

Thanks, and good luck!

-Flare

Show Your Support

  • This modification may not be copied, reproduced or published elsewhere without author's permission.

Comments
  #22  
Old 06-25-2001, 09:04 AM
Aunt Jemima
Guest
 
Posts: n/a
Default

Thanks - problem fixed
Reply With Quote
  #23  
Old 06-25-2001, 01:32 PM
Nocturnal
Guest
 
Posts: n/a
Default

Worked a dream thanks for that
Reply With Quote
  #24  
Old 08-04-2001, 11:47 PM
maverick1236 maverick1236 is offline
 
Join Date: Oct 2001
Location: NY
Posts: 183
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

it installed fine-but where is option to change vote?
Reply With Quote
  #25  
Old 08-05-2001, 11:16 AM
Admin's Avatar
Admin Admin is offline
Coder
 
Join Date: Oct 2023
Location: Server
Posts: 1
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Awesome hack, great job!
Reply With Quote
  #26  
Old 11-21-2001, 11:57 PM
kyrnel's Avatar
kyrnel kyrnel is offline
 
Join Date: Nov 2001
Location: Houston, TX
Posts: 87
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Im getting a parse error at line 536 which (for me) is this line
PHP Code:
&#123; 
That the 3rd line of your added code.

Dont know why it is causing a parse error, I checked the last line of code for the missing slash, it is ok.

Im using 2.2.0 if that makes a difference.

any ideas? thanks
Reply With Quote
  #27  
Old 11-22-2001, 12:44 AM
kyrnel's Avatar
kyrnel kyrnel is offline
 
Join Date: Nov 2001
Location: Houston, TX
Posts: 87
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I quoted your original message to see if there are differences and the "{" (open round brackets) is showing up as "& #123" (without a space)
I dont know if that affects everyone or not, but you would think that the [ PHP ] tag would display php code as it really is.. hmm

well i copied the code from the edit window and it works fine now..thanks for the hack...
Reply With Quote
  #28  
Old 11-22-2001, 02:03 AM
Syphin Syphin is offline
 
Join Date: Oct 2001
Posts: 115
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Great hack... =) And only way i could get it to work, was from the edit box also... =/

But it works great now.. ^^

-Syphin
Reply With Quote
  #29  
Old 04-14-2002, 02:46 PM
Meta's Avatar
Meta Meta is offline
 
Join Date: Nov 2001
Location: Germany (north)
Posts: 65
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Nice hack ... works fine.

Thank you, Flare!
Reply With Quote
  #30  
Old 06-05-2002, 02:12 AM
josh929's Avatar
josh929 josh929 is offline
 
Join Date: Mar 2002
Posts: 33
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

GREAT hack Flare!!
Reply With Quote
  #31  
Old 03-26-2003, 09:25 PM
Stud_Muffin Stud_Muffin is offline
 
Join Date: Sep 2002
Location: UK
Posts: 16
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Installed in vb 2.3.0 ok.
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 07:06 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04668 seconds
  • Memory Usage 2,320KB
  • Queries Executed 27 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (3)bbcode_code
  • (2)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_post
  • (1)navbar
  • (6)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (11)post_thanks_box
  • (11)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (11)post_thanks_postbit_info
  • (10)postbit
  • (9)postbit_onlinestatus
  • (11)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete