vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 2.x Full Releases (https://vborg.vbsupport.ru/forumdisplay.php?f=4)
-   -   Change Vote Ability (https://vborg.vbsupport.ru/showthread.php?t=15709)

Flare 04-30-2001 09:00 PM

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

conan 05-01-2001 05:23 PM

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

tubedogg 05-01-2001 05:50 PM

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

doron 05-01-2001 06:07 PM

that code is somewhat unclean (select *).

conan 05-01-2001 09:13 PM

Oh I see my bad :)
Thanks for clearing that up tuebdogg

Quote:

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

Flare 05-02-2001 03:11 PM

Jeez... thought this was something a bunch of people wanted :D Instead... I'm... *sob* ... unclean!

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

jojo85 05-03-2001 08:48 AM

Nice one thx youuu

Aunt Jemima 06-22-2001 06:45 AM

I get a Parse Error

Jpp 06-22-2001 07:48 AM

Quote:

Originally posted by Aunt Jemima
I get a Parse Error
Me to

Flare 06-22-2001 04:29 PM

Where is this error generated? Can you show me a on your system?

Jpp 06-22-2001 05:44 PM

Quote:

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

Flare 06-22-2001 08:09 PM

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.

Jpp 06-22-2001 08:17 PM

Quote:

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,

Flare 06-22-2001 08:48 PM

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.

Jpp 06-22-2001 09:09 PM

OK here it comes

Flare 06-23-2001 03:53 AM

PHP Code:

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

Code:

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

// redirect
eval("standardredirect(\"".gettemplate("redirect_p ollchange")."\",\"showthread.php?s=$session[sessionhash]&threadid=$threadinfo[threadid]\");");
}

Flare 06-23-2001 03:59 AM

Ok... well, I found your problem. Which is exposing a problem with vBulletin itself. Very strange.

I'm on a dialup so I can't debug it very easily right now.. perhaps the VB programmers can take a look at this.

If you look at my original post, you'll see this line:

PHP Code:

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

at the bottom of the [ PHP ] tag.

If you'll look closely, the slash is missing from that line when viewed.

If you go edit that message, that quote shows up in the edit box.

You'll see above that the slash exists in the above [ php ] block. The code was cut and pasted from the edit box of the first message, it is identical to the first PHP block in the first message...

Currently, I have no explanation for this. I'll try to look at it more on Monday, but no guarentees. If the vB programmers can take a look at it and see what is causing the parse error, it'd be greatly appreciated.

To solve Jbb and AJ's problem, however, is simple. Just pull the code out of the edit box, not directly from the post page. You are missing an escaping slash (and possibly more), which is generating your parse error. When I tried installing it on a fresh poll.php, I used the copy from the edit box, which is why it worked for me, and not for you two.

Jpp 06-23-2001 06:01 AM

Ok It works now, That is to bad that you have been trubbled with such a tiny error, sorry!! But I could never have found it myself,
One little slash....... and the empire shakes. Btw It is a very nice featuer to have in the poll's. Good job ;)

Aunt Jemima 06-23-2001 09:27 AM

I don't understand what to fix right now. Can you post the fix here?

Thanks,
Aunt

Jpp 06-23-2001 09:59 AM

OK sroll down to the end of your poll.php, at the end of the last line you will see that there is a slash missing,

// redirect
eval("standardredirect(\"".gettemplate("redirect_p ollchange")."\",\"showthread.p hp?s=$session[sessionhash]&threadid=$threadinfo[threadid]\");");
}

Aunt Jemima 06-25-2001 08:04 AM

Thanks - problem fixed :D

Nocturnal 06-25-2001 12:32 PM

Worked a dream thanks for that

maverick1236 08-04-2001 10:47 PM

it installed fine-but where is option to change vote?

Admin 08-05-2001 10:16 AM

Awesome hack, great job! :D

kyrnel 11-21-2001 11:57 PM

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

kyrnel 11-22-2001 12:44 AM

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...

Syphin 11-22-2001 02:03 AM

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

But it works great now.. ^^

-Syphin

Meta 04-14-2002 01:46 PM

Nice hack ... works fine.

Thank you, Flare!

josh929 06-05-2002 01:12 AM

GREAT hack Flare!!

Stud_Muffin 03-26-2003 09:25 PM

Installed in vb 2.3.0 ok. :eek:


All times are GMT. The time now is 10:58 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.01787 seconds
  • Memory Usage 1,827KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (4)bbcode_code_printable
  • (4)bbcode_php_printable
  • (4)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (30)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete