• [Mod] Rating Button Disabled After Vote 5 0 5 1
Currently:  

Author Topic: [Mod] Rating Button Disabled After Vote  (Read 64262 times)

0 Members and 1 Guest are viewing this topic.

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
[Mod] Rating Button Disabled After Vote
« on: May 24, 2003, 06:10:27 PM »
Many people asked me post the code that will disable "rate form" after visitor voted. (no more error message "Sorry, u have voted ones recently") u can try it youself here
what it does:
1. could be anable/disable to show what was your vote for each picture. (it will show your vote number in the dropdown, but it will be disabled and u wont be able vote again for that image)
2. could be anabled/disabled ability vote for one image by different members who share one computer. (right now, if u and your brother use the same computer, and u visit 4images sites with different login names, after vote either of u, cookies set that nobody else can vote for the same image from same computer)
3. rate form generates automaticaly based on MAX_RATING set in /includes/constants.php

Open /includes/page_header.php
Find:
Code: [Select]
//-----------------------------------------------------
//--- Save Rating -------------------------------------
//-----------------------------------------------------
if ($action == "rateimage" && $id) {
  $rating = intval($HTTP_POST_VARS['rating']);
  $cookie_name = (defined("COOKIE_NAME")) ? COOKIE_NAME : "4images_";
  $cookie_rated = isset($HTTP_COOKIE_VARS[$cookie_name.'rated']) ? unserialize(stripslashes($HTTP_COOKIE_VARS[$cookie_name.'rated'])) : array();
  if ($rating && $rating <= MAX_RATING && $id) {
    if (!isset($session_info['rated_imgs'])) {
      $session_info['rated_imgs'] = $site_sess->get_session_var("rated_imgs");
    }   
    $split_list = array();
    if (!empty($session_info['rated_imgs'])) {
      $split_list = explode(" ", $session_info['rated_imgs']);
    }
    if (!in_array($id, $split_list) && !in_array($id, $cookie_rated)) {
      $session_info['rated_imgs'] .= " ".$id;
      $session_info['rated_imgs'] = trim($session_info['rated_imgs']);
      $site_sess->set_session_var("rated_imgs", $session_info['rated_imgs']);
      $cookie_rated[] = $id;
      $cookie_expire = time() + 60 * 60 * 24 * 4;
      setcookie($cookie_name.'rated', serialize($cookie_rated), $cookie_expire, COOKIE_PATH, COOKIE_DOMAIN, COOKIE_SECURE);
      update_image_rating($id, $rating);
      $msg = $lang['voting_success'];
    }
    else {
      $msg = $lang['already_voted'];
    }
  }
  else {
    $msg = $lang['voting_error'];
  }
}

//-----------------------------------------------------
//--- Parse Header & Footer ---------------------------
//-----------------------------------------------------
Replace with:
Code: [Select]
//-----------------------------------------------------
//--- Save Rating -------------------------------------
//-----------------------------------------------------

//----- Settings ------------

//change to $rate_suffix = ""; if u dont want remmber votes for different users on same computer
$rate_suffix = "_".$user_info['user_id'];

//--- End Settings ----------

if ($action == "rateimage" && $id) {
  $rating = intval($HTTP_POST_VARS['rating']);
  $cookie_name = (defined("COOKIE_NAME")) ? COOKIE_NAME : "4images_";
  $cookie_rated_array = isset($HTTP_COOKIE_VARS[$cookie_name.'rated'.$rate_suffix]) ? unserialize(stripslashes($HTTP_COOKIE_VARS[$cookie_name.'rated'.$rate_suffix])) : array();
  if ($rating && $rating <= MAX_RATING && $id) {
    if (!isset($session_info['rated_imgs'.$rate_suffix])) {
      $session_info['rated_imgs'.$rate_suffix] = $site_sess->get_session_var("rated_imgs".$rate_suffix);
    }
    $split_list_array = array();
    if (!empty($session_info['rated_imgs'.$rate_suffix])) {
      $split_list_array = explode(" ", $session_info['rated_imgs'.$rate_suffix]);
    }
    $split_list = array();
    foreach ($split_list_array as $key) {
      $key = explode(",", $key);
      $split_list[] = $key[0];
    }
    $cookie_rated = array();
    foreach ($cookie_rated_array as $key) {
      $key = explode(",", $key);
      $cookie_rated[] = $key[0];
    }
    if (!in_array($id, $split_list) && !in_array($id, $cookie_rated)) {
      $session_info['rated_imgs'.$rate_suffix] .= " ".$id.",".$rating;
      $session_info['rated_imgs'.$rate_suffix] = trim($session_info['rated_imgs'.$rate_suffix]);
      $site_sess->set_session_var("rated_imgs".$rate_suffix, $session_info['rated_imgs'.$rate_suffix]);
      $cookie_rated_array[] = $id.",".$rating;
      $cookie_expire = time() + 60 * 60 * 24 * 4;
      setcookie($cookie_name.'rated'.$rate_suffix, serialize($cookie_rated_array), $cookie_expire, COOKIE_PATH, COOKIE_DOMAIN, COOKIE_SECURE);
      update_image_rating($id, $rating);
      $msg = $lang['voting_success'];
    }
    else {
      $msg = $lang['already_voted'];
    }
  }
  else {
    $msg = $lang['voting_error'];
  }
}

//-----------------------------------------------------
//--- Parse Header & Footer ---------------------------
//-----------------------------------------------------


Open /includes/functions.php
Find:
Code: [Select]
    $site_template->register_vars("rate", $lang['rate']);
    $rate_form = $site_template->parse_template("rate_form");
  }
  $site_template->register_vars("rate_form", $rate_form);
  return true;
}
Replace with:
Code: [Select]
    $rate_form = rate_form($image_row['image_id'], $rate_suffix, $rating);
  }
  $site_template->register_vars("rate_form", $rate_form);

  return true;
}

function rate_form($id, $rate_suffix = "", $rating = ""){
 global $site_template, $session_info, $lang, $site_sess, $HTTP_COOKIE_VARS, $rate_suffix;

  //----- Settings ------------

  //change to $rate_show = 0; if u dont want to show what was your vote for an image
  $rate_show = 1;

  //--- End Settings ----------

  $cookie_name = (defined("COOKIE_NAME")) ? COOKIE_NAME : "4images_";
  $cookie_rated_array = isset($HTTP_COOKIE_VARS[$cookie_name.'rated'.$rate_suffix]) ? unserialize(stripslashes($HTTP_COOKIE_VARS[$cookie_name.'rated'.$rate_suffix])) : array();
  $split_list_array = array();
  if (!empty($session_info['rated_imgs'.$rate_suffix])) {
    $split_list_array = explode(" ", $session_info['rated_imgs'.$rate_suffix]);
  }
  $cookie_rated = array();
  foreach ($cookie_rated_array as $key) {
    $split = explode(",", $key);
    $cookie_rated[] = $split[0];
    if ($id == $split[0]) {
      $rating = $split[1];
    }
  }
  $split_list = array();
  foreach ($split_list_array as $key) {
    $split = explode(",", $key);
    $split_list[] = $split[0];
    if ($id == $split[0]) {
      $rating = $split[1];
    }
  }
  $no_rateform = (in_array($id, $split_list) || in_array($id, $cookie_rated)) ? "disabled" : 0;
  $rate_options = "<option value=\"\">--</option>\n";
  for ($i = MAX_RATING; $i; $i--){
    $rate_options .= "<option value=\"".$i."\"".(($i == $rating && $rate_show) ? "selected" : "").">".$i."</option>\n";
  }
  $site_template->register_vars(array(
          "rate" => ($no_rateform && !(check_permission("auth_vote", $image_row['cat_id']) && $no_rateform)) ?  "rated" : $lang['rate'],
          "rate_options" => $rate_options,
          "rate_button" => ($no_rateform) ? $no_rateform : ""

    ));
  $rate_form = $site_template->parse_template("rate_form");
  return $rate_form;
}

*In each changed parts u'll find //----- Settings ---------


Open /templates/<yourtemplate>/rate_form.html
replace the code with this:
Code: [Select]
<table border="0" cellspacing="0" cellpadding="1">
  <form method="post" action="{self}">
    <tr>
      <td class="head1">
        <table border="0" cellspacing="0" cellpadding="3" class="row1">
          <tr>
            <td valign="bottom">
              <select name="rating" class="select" {rate_button}>
                {rate_options}
              </select>
            </td>
            <td>
              <input type="hidden" name="action" value="rateimage" />
              <input type="hidden" name="id" value="{image_id}" />
              <input type="submit" value="{rate}" class="button" name="submit" {rate_button} />
            </td>
          </tr>
        </table>
      </td>
    </tr>
  </form>
</table>
« Last Edit: October 10, 2005, 04:14:47 AM by V@no »
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline Xwall

  • Full Member
  • ***
  • Posts: 100
    • View Profile
    • http://www.xwall.tk
[Mod] Rating Button Disabled After Vote
« Reply #1 on: June 01, 2003, 11:24:27 AM »
Works well  :wink:

Only one thing, not all people speak english.  :?
Rated -> Calificación

/includes/functions.php

Code: [Select]
"rate" => ($no_rateform && !(check_permission("auth_vote", $image_row['cat_id']) && $no_rateform)) ?  "Calificación" : $lang['rate'],

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
[Mod] Rating Button Disabled After Vote
« Reply #2 on: June 01, 2003, 04:35:33 PM »
Quote from: Xwall
Only one thing, not all people speak english.  :?
Rated -> Calificación

/includes/functions.php

Code: [Select]
"rate" => ($no_rateform && !(check_permission("auth_vote", $image_row['cat_id']) && $no_rateform)) ?  "Calificación" : $lang['rate'],

yes, u are right, I just wasnt feel like I want add multilanguage support here...;)
u can replace "Calificación" with $lang['rated'] and then add
$lang['rated'] = "Calificación"; in your /lang/<yourlanguage>/main.php
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline universal

  • Full Member
  • ***
  • Posts: 213
    • View Profile
    • http://www.funny.lt
Re: [Mod] Rating Button Disabled After Vote
« Reply #3 on: April 23, 2005, 06:50:25 PM »
Uch, I tought, that to modify it will be easyer, but look at my rate_form.html
I just want to hide the form after vote...

Code: [Select]
<form action="{self}" method="post" name="RateMe" id="RateMe">
  <table cellspacing="0" cellpadding="1" border="0" style="border-color:#999999; border-style:solid; border-width:1px; ">
    <tr>
      <td> <table cellspacing="0" cellpadding="3" border="0">
          <tr>
            <td width="0" valign="middle"><strong>Ávertink:</strong></td>
            <td width="1" valign="middle"><input onClick="document.RateMe.submit()" type="radio" value="1" name="rating" /></td>
            <td width="1" valign="middle">1</td>
            <td width="1" valign="middle"><input onClick="document.RateMe.submit()" type="radio" value="2" name="rating" /></td>
            <td width="1" valign="middle">2</td>
            <td width="1" valign="middle"><input onClick="document.RateMe.submit()" type="radio" value="3" name="rating" /></td>
            <td width="1" valign="middle">3</td>
            <td width="1" valign="middle"><input onClick="document.RateMe.submit()" type="radio" value="4" name="rating" /></td>
            <td width="1" valign="middle">4</td>
            <td width="1" valign="middle"><input onClick="document.RateMe.submit()" type="radio" value="5" name="rating" /></td>
            <td width="1" valign="middle">5</td>
            <td rowspan="2"> <input type="hidden" name="action" value="rateimage" />
              <input type="hidden" name="id" value="{image_id}" /> </td>
          </tr>
        </table></td>
    </tr>
  </table>
</form>
Again this addres?!
http://www.funny.lt

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: [Mod] Rating Button Disabled After Vote
« Reply #4 on: April 23, 2005, 06:57:42 PM »
either install "{ifno ..} {endifno ..}" mod and use {ifno rate_button} and {endifno rate_button} around your form, or in includes/functions.php find:
Code: [Select]
         "rate_options" => $rate_options,insert below:
Code: [Select]
          "show_rate_form" => ($no_rateform) ? 0 : 1,then in your rate_form.html use {if show_rate_form} and {endif show_rate_form} tags ;)
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline universal

  • Full Member
  • ***
  • Posts: 213
    • View Profile
    • http://www.funny.lt
Re: [Mod] Rating Button Disabled After Vote
« Reply #5 on: April 23, 2005, 10:06:43 PM »
great! :) thanks again... ;)
Again this addres?!
http://www.funny.lt

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: [Mod] Rating Button Disabled After Vote
« Reply #6 on: April 23, 2005, 10:12:26 PM »
I've told u its easier modify already existing mod then start from scratch ;)
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline graficalicus

  • Full Member
  • ***
  • Posts: 235
    • View Profile
Re: [Mod] Rating Button Disabled After Vote
« Reply #7 on: May 05, 2005, 07:49:52 PM »
V@no - this seems to "expire" after cookies are deleted - seems like there was another "disable rating after vote" thing I used before that just posted a message "Sorry, but you've already voted..."

here's my code from page_header.php:
Code: [Select]
/* //-----------------------------------------------------
//--- Save Rating -------------------------------------
//-----------------------------------------------------
if ($action == "rateimage" && $id) {
  $rating = intval($HTTP_POST_VARS['rating']);
if ($user_info['user_level'] != GUEST) {
$voted_array = array();
if (!empty($user_info['user_voted'])) {
$voted_array = explode(" ", $user_info['user_voted']);
}
$list_rated = array();
foreach ($voted_array as $key) {
$split = explode(",", $key);
$list_rated[] = $split[0];
if ($id == $split[0]) {
$rating = $split[1];
}
}
$rated = in_array($id, $list_rated);
}else{
$rated = FALSE;
}
  $cookie_name = (defined("COOKIE_NAME")) ? COOKIE_NAME : "4images_";
  $cookie_rated = isset($HTTP_COOKIE_VARS[$cookie_name.'rated']) ? unserialize(stripslashes($HTTP_COOKIE_VARS[$cookie_name.'rated'])) : array();
  if ($rating && $rating <= MAX_RATING && $id) {
    if (!isset($session_info['rated_imgs'])) {
      $session_info['rated_imgs'] = $site_sess->get_session_var("rated_imgs");
    }   
    $split_list = array();
    if (!empty($session_info['rated_imgs'])) {
      $split_list = explode(" ", $session_info['rated_imgs']);
    }
    if (!in_array($id, $split_list) && !in_array($id, $cookie_rated) && !$rated) {

      $session_info['rated_imgs'] .= " ".$id;
      $session_info['rated_imgs'] = trim($session_info['rated_imgs']);
      $site_sess->set_session_var("rated_imgs", $session_info['rated_imgs']);
      $cookie_rated[] = $id;
      $cookie_expire = time() + 60 * 60 * 24 * 4;
      setcookie($cookie_name.'rated', serialize($cookie_rated), $cookie_expire, COOKIE_PATH, COOKIE_DOMAIN, COOKIE_SECURE);
      update_image_rating($id, $rating);
      $msg = $lang['voting_success'];
    }
    else {
      $msg = $lang['already_voted'];
    }
  }
  else {
    $msg = $lang['voting_error'];
  }
}  */
//-----------------------------------------------------
//--- Save Rating -------------------------------------
//-----------------------------------------------------

//----- Settings ------------

//change to $rate_suffix = ""; if u dont want remmber votes for different users on same computer
$rate_suffix = "_".$user_info['user_id'];

//--- End Settings ----------

if ($action == "rateimage" && $id) {
  $rating = intval($HTTP_POST_VARS['rating']);
  $cookie_name = (defined("COOKIE_NAME")) ? COOKIE_NAME : "4images_";
  $cookie_rated_array = isset($HTTP_COOKIE_VARS[$cookie_name.'rated'.$rate_suffix]) ? unserialize(stripslashes($HTTP_COOKIE_VARS[$cookie_name.'rated'.$rate_suffix])) : array();
  if ($rating && $rating <= MAX_RATING && $id) {
    if (!isset($session_info['rated_imgs'.$rate_suffix])) {
      $session_info['rated_imgs'.$rate_suffix] = $site_sess->get_session_var("rated_imgs".$rate_suffix);
    }
    $split_list_array = array();
    if (!empty($session_info['rated_imgs'.$rate_suffix])) {
      $split_list_array = explode(" ", $session_info['rated_imgs'.$rate_suffix]);
    }
    $split_list = array();
    foreach ($split_list_array as $key) {
      $key = explode(",", $key);
      $split_list[] = $key[0];
    }
    $cookie_rated = array();
    foreach ($cookie_rated_array as $key) {
      $key = explode(",", $key);
      $cookie_rated[] = $key[0];
    }
    if (!in_array($id, $split_list) && !in_array($id, $cookie_rated)) {
      $session_info['rated_imgs'.$rate_suffix] .= " ".$id.",".$rating;
      $session_info['rated_imgs'.$rate_suffix] = trim($session_info['rated_imgs'.$rate_suffix]);
      $site_sess->set_session_var("rated_imgs".$rate_suffix, $session_info['rated_imgs'.$rate_suffix]);
      $cookie_rated_array[] = $id.",".$rating;
      $cookie_expire = time() + 60 * 60 * 24 * 4;
      setcookie($cookie_name.'rated'.$rate_suffix, serialize($cookie_rated_array), $cookie_expire, COOKIE_PATH, COOKIE_DOMAIN, COOKIE_SECURE);
      update_image_rating($id, $rating);
      $msg = $lang['voting_success'];
    }
    else {
      $msg = $lang['already_voted'];
    }
  }
  else {
    $msg = $lang['voting_error'];
  }
}

//-----------------------------------------------------
//--- Parse Header & Footer ---------------------------
//-----------------------------------------------------

I simply commented out what was already there and added this new code - - but users can still vote again the next day - - is this one based on cookies?

thx -

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: [Mod] Rating Button Disabled After Vote
« Reply #8 on: May 05, 2005, 08:26:11 PM »
are u saing that if u delete the cookies, u can again vote? - well, yes, what do u expect ;)
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline graficalicus

  • Full Member
  • ***
  • Posts: 235
    • View Profile
Re: [Mod] Rating Button Disabled After Vote
« Reply #9 on: May 05, 2005, 08:52:06 PM »
Quote
if u delete the cookies, u can again vote

but the earlier one stored in the DB, so if a user votes, he can't vote again, ever.  not sure what was different between these two MODS....   :?

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: [Mod] Rating Button Disabled After Vote
« Reply #10 on: May 05, 2005, 09:05:07 PM »
these are completly different mods ;)
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline graficalicus

  • Full Member
  • ***
  • Posts: 235
    • View Profile
Re: [Mod] Rating Button Disabled After Vote
« Reply #11 on: May 06, 2005, 01:44:29 AM »
 :lol:   but, as usual, I want to combine 2 MODS   :!:

I like the idea of the rating box showing a user's last rating, but the cookie never expiring so they can't vote again   8)

(nothing's ever good enough for me, as my mom often told me....  :|  )

Offline marius26

  • Newbie
  • *
  • Posts: 21
    • View Profile
    • http://www.steves-network.net
Re: [Mod] Rating Button Disabled After Vote
« Reply #12 on: November 06, 2005, 11:56:34 PM »
and i want one like is on V@no site  :twisted:

Offline Lucifix

  • Hero Member
  • *****
  • Posts: 710
    • View Profile
    • http://www.slo-foto.net
Re: [Mod] Rating Button Disabled After Vote
« Reply #13 on: December 01, 2005, 06:56:20 PM »
@veno: remember my problem?  :roll:

This is how my rate_form.html looks like:

Code: [Select]
<table border="0" cellspacing="0" cellpadding="3" class="row1">
                      <tr>
                        <td> <input type="radio" name="rating" value="0">
                          0 - {lang_rate_zero}<br>
<input type="radio" name="rating" value="1.0">
                          1 - {lang_rate_one}<br>
                          <input type="radio" name="rating" value="2.0">
                          2 - {lang_rate_two}<br>
  <input type="radio" name="rating" value="3.0">
                          3 - {lang_rate_three}<br>
                          <input type="radio" name="rating" value="4.0">
                          4 - {lang_rate_four}<br>
                          <input type="radio" name="rating" value="5.0">
                          5 - {lang_rate_five}
</td>
                      </tr>
                    </table>

Can anyone help me solve this problem?

Offline Acidgod

  • 4images Moderator
  • 4images Guru
  • *****
  • Posts: 2.421
  • It's me?
    • View Profile
    • Flash-Webdesign
Re: [Mod] Rating Button Disabled After Vote
« Reply #14 on: December 01, 2005, 07:45:47 PM »
this is the first time you post in this thread, so we don´t now your Problem... (o: