Results 1 to 15 of 24
Page 1 of 2
FirstFirst 1 2 ... LastLast

Thread: [Release] Change Vote Ability

  1. #1
    Member Flare is on a distinguished road Flare's Avatar
    Join Date
    Feb 2001
    Posts
    77

    [Release] Change Vote Ability

    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
     

  2. #2
    Senior Member conan is on a distinguished road
    Join Date
    Sep 2000
    Posts
    389
    I apologize if I misundestood the meaning of the hack, but if I understood correctly, there is already a feature to allow users to change their vote
     

  3. #3
    Senior Member tubedogg has disabled reputation tubedogg's Avatar
    Join Date
    Feb 2001
    Location
    Medina, OH
    Age
    28
    Posts
    13,647
    There's a way to allow users to change their thread ratings, not votes on polls.
     

  4. #4
    Senior Member doron is on a distinguished road
    Join Date
    Apr 2000
    Location
    Austin, TX
    Age
    29
    Posts
    670
    that code is somewhat unclean (select *).
     

  5. #5
    Senior Member conan is on a distinguished road
    Join Date
    Sep 2000
    Posts
    389
    Oh I see my bad
    Thanks for clearing that up tuebdogg

    Originally posted by tubedogg
    There's a way to allow users to change their thread ratings, not votes on polls.
     

  6. #6
    Member Flare is on a distinguished road Flare's Avatar
    Join Date
    Feb 2001
    Posts
    77
    Jeez... thought this was something a bunch of people wanted Instead... I'm... *sob* ... unclean!

    I'll go back in my corner now and eat paint chips
     

  7. #7
    Senior Member jojo85 is on a distinguished road
    Join Date
    Jan 2001
    Location
    FRANCE
    Age
    24
    Posts
    916
    Nice one thx youuu
    Best Regards,
    Geoffrey 'G3oW0RK' BALDET.
     

  8. #8
    Senior Member Aunt Jemima is on a distinguished road
    Join Date
    Mar 2001
    Location
    Phoenix, AZ
    Age
    26
    Posts
    188
    I get a Parse Error
     

  9. #9
    Member Jpp is on a distinguished road
    Join Date
    May 2001
    Location
    asdfasdfa
    Posts
    37
    Originally posted by Aunt Jemima
    I get a Parse Error
    Me to
     

  10. #10
    Member Flare is on a distinguished road Flare's Avatar
    Join Date
    Feb 2001
    Posts
    77
    Where is this error generated? Can you show me a on your system?
     

  11. #11
    Member Jpp is on a distinguished road
    Join Date
    May 2001
    Location
    asdfasdfa
    Posts
    37
    Originally posted by Flare
    Where is this error generated? Can you show me a on your system?
    Parse error when woting, and view result
    Parse error: parse error in C:\HTTPD\upload\poll.php on line 532
     

  12. #12
    Member Flare is on a distinguished road Flare's Avatar
    Join Date
    Feb 2001
    Posts
    77
    Can you send me your poll.php?

    My email is: flare@cohort.cc

    I haven't tried this with the latest VB, I'm running 2.0.0 ... but I can't imagine anything has changed in poll.php between the two versions.

    Only other thing I can think of off the top of my head is that you are running it on a windows box compared to my linux box... but I don't think that would affect it either.
     

  13. #13
    Member Jpp is on a distinguished road
    Join Date
    May 2001
    Location
    asdfasdfa
    Posts
    37
    Originally posted by Flare
    Can you send me your poll.php?

    My email is: flare@cohort.cc

    I haven't tried this with the latest VB, I'm running 2.0.0 ... but I can't imagine anything has changed in poll.php between the two versions.

    Only other thing I can think of off the top of my head is that you are running it on a windows box compared to my linux box... but I don't think that would affect it either.
    I dont know much about this but shouldn't the new templates be mentioned in the $templatesused at the top of poll.php?? Did try that but no good,
     

  14. #14
    Member Flare is on a distinguished road Flare's Avatar
    Join Date
    Feb 2001
    Posts
    77
    No, that $templatesused variable isn't referenced anywhere else in poll.php. To be honest, I'm not even sure why it's there.

    I tried installing this hack on a clean copy of poll.php and it worked fine. I have no clue what your issues could be, if you send me a copy of your poll.php, I'll run a compare against mine and see what's different.
     

  15. #15
    Member Jpp is on a distinguished road
    Join Date
    May 2001
    Location
    asdfasdfa
    Posts
    37
    OK here it comes
     

Page 1 of 2
FirstFirst 1 2 ... LastLast

Similar Threads

  1. It would be nice to be able to change your vote in a poll
    By Andy in forum vBulletin Suggestions and Feedback
    Replies: 16
    Last Post: Tue 26th Aug '08, 4:38am
  2. would like to see ability to change rep icons based on post count..
    By jilly in forum vBulletin Suggestions and Feedback
    Replies: 0
    Last Post: Thu 12th Feb '04, 8:20pm
  3. Can I give a mod the ability to change style colors?
    By jilly in forum vBulletin 3.0 How Do I and Troubleshooting Forum
    Replies: 1
    Last Post: Mon 5th Jan '04, 1:32pm
  4. Change Vote
    By Goldfinger in forum vBulletin 2 Suggestions and Feedback
    Replies: 5
    Last Post: Mon 17th Dec '01, 7:00am

Bookmarks

Posting Permissions

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