Author Topic: [MOD] Votes saved in DB  (Read 244237 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
Re: [MOD] Votes saved in DB
« Reply #60 on: January 18, 2006, 11:56:20 PM »
You can use this query:
Code: [Select]
$sql = "SELECT COUNT(vote) AS num
        FROM ".VOTED_TABLE."
        WHERE user_id = ".$user_id;
$result = $site_db->query_firstrow($sql);
echo $result['num'];
(Asuming variable $user_id conteins the user id ;))
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 TIMT

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
Re: [MOD] Votes saved in DB
« Reply #61 on: February 03, 2006, 10:53:45 PM »
Hi,

I installed Version A of this fantastic MOD.

Now it would be great, if the dropdownlist with the scale 1-5  is only shown, when the user still has not voted. As soon as her has voted, instead of the dropdown list a text like "already voted" should be displayed.

How ca I do that?

Thanks!

Offline ch€ri{Bi}˛

  • Sr. Member
  • ****
  • Posts: 315
  • A PRoBLeM wIthOUt SoLuTioN Is NoT rEAllY a PRoBLeM
    • View Profile
    • Pat's Gallery
Re: [MOD] Votes saved in DB
« Reply #62 on: February 04, 2006, 10:35:23 AM »
it seems you need this mod : [Mod] Rating Button Disabled After Vote
 :wink:
ch€ri{Bi}˛


Offline TIMT

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
Re: [MOD] Votes saved in DB
« Reply #63 on: February 04, 2006, 10:57:42 AM »
upps... haven't seen this MOD    :oops:
Thanks cheribibi for the hint!  :)

Offline Stoleti

  • Hero Member
  • *****
  • Posts: 574
    • View Profile
Re: [MOD] Votes saved in DB
« Reply #64 on: February 09, 2006, 05:10:42 PM »
I'm using the Version A , and i would like know how make only possible see "who Voted" for Admin's ? For Another Users make show "You've No Permission"  :mrgreen:


 :wink:

Offline TIMT

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
Re: [MOD] Votes saved in DB
« Reply #65 on: February 09, 2006, 05:18:51 PM »
Hi cheribibi

The MOD you proposed works with Cookies. The votes are stored in the DB, but are not anymore interpreted for a second "vote-try". When I delete the Cookies, I can vote again and I get a second entry in the database.

Now I'm asking, if it is possible to check the database and disabled the dropdownlist with the scale (1-5) when the picture was already voted by a user.

Thanks!!!

Offline ch€ri{Bi}˛

  • Sr. Member
  • ****
  • Posts: 315
  • A PRoBLeM wIthOUt SoLuTioN Is NoT rEAllY a PRoBLeM
    • View Profile
    • Pat's Gallery
Re: [MOD] Votes saved in DB
« Reply #66 on: February 09, 2006, 07:56:23 PM »
I'm asking, if it is possible to check the database and disabled the dropdownlist with the scale (1-5) when the picture was already voted by a user.
you're right   :arrow: here is the modification:

in this mod STEP 2 (modifying functions.php), in the new function :
Quote
function rate_form($id, $rate_suffix = "", $rating = ""){

find :
Quote
global $site_template, $session_info, $lang, $site_sess, $HTTP_COOKIE_VARS, $rate_suffix;
and replace by:
Code: [Select]
global $site_template, $session_info, $lang, $site_sess, $HTTP_COOKIE_VARS, $rate_suffix;
global $user_info, $site_db; //-----[ [ MOD ] : check user rating in DB

and find : 
Quote
$no_rateform = (in_array($id, $split_list) || in_array($id, $cookie_rated)) ? "disabled" : 0;
and replace by:
Code: [Select]
//-----[ [ MOD ] : check user rating in DB
  $image_rated_by_user = "";
  $sql30 = "SELECT vote
            FROM ".VOTED_TABLE."
            WHERE image_id =".$id." AND user_id =".$user_info['user_id'];

  $row = $site_db->query_firstrow($sql30); 
 
  $image_rated_by_user = (isset($row['vote']))? 1 : 0 ;
  $rating = (isset($row['vote']))? $row['vote'] : 0 ;
 
  // $no_rateform = (in_array($id, $split_list) || in_array($id, $cookie_rated)) ? "disabled" : 0; // original code
  $no_rateform = (in_array($id, $split_list) || in_array($id, $cookie_rated) || $image_rated_by_user) ? "disabled" : 0;
//-----[/[ MOD ] : check user rating in DB ]

here is the work  :wink:
« Last Edit: February 11, 2006, 06:26:33 PM by V@no »
ch€ri{Bi}˛


Offline trez

  • Hero Member
  • *****
  • Posts: 613
    • View Profile
    • blog / photography
Re: [MOD] Votes saved in DB
« Reply #67 on: February 10, 2006, 12:01:40 AM »
sure but you can very easy manipulate the vote.

- login with first username
- vote for picture
- logout
- delete cookies
- login with second username
- vote again for the same picture

Ive tried something like this (snippet)
Code: [Select]
if ($action == "rateimage" && $id) {
  $rating = intval($HTTP_POST_VARS['rating']);
 if ($user_info['user_level'] != GUEST) {
$sql = "SELECT user_id, image_id, vote
FROM ".VOTED_TABLE."
WHERE image_id = ".$id." AND user_id = ".$user_info['user_id'];
$rated = $site_db->query_firstrow($sql);
$rating = ($rated['vote']) ? $rated['vote'] : $rating;
$hisIp=$_SERVER['REMOTE_ADDR'];
$opsa="SELECT imID, ipAdd FROM ip_vote WHERE imID = ".$id." AND ipAdd = '".$hisIp."'";
if ($site_db->query_firstrow($opsa)) { $rated = TRUE ;}
}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");
    }


and added a new field for the IP, but i have to make some more bugfixes...
It is possible to make the voting check also the IP, so V@no suggestions?

Offline ch€ri{Bi}˛

  • Sr. Member
  • ****
  • Posts: 315
  • A PRoBLeM wIthOUt SoLuTioN Is NoT rEAllY a PRoBLeM
    • View Profile
    • Pat's Gallery
Re: [MOD] Votes saved in DB
« Reply #68 on: February 10, 2006, 12:30:15 AM »
and added a new field for the IP, but i have to make some more bugfixes...
It is possible to make the voting check also the IP

by keeping your reasoning, even if you records the ip addresses, someone who knows how to use proxies to hide its real IP will still be able to vote again and again  :wink:
ch€ri{Bi}˛


Offline trez

  • Hero Member
  • *****
  • Posts: 613
    • View Profile
    • blog / photography
Re: [MOD] Votes saved in DB
« Reply #69 on: February 10, 2006, 12:57:57 AM »
and added a new field for the IP, but i have to make some more bugfixes...
It is possible to make the voting check also the IP

by keeping your reasoning, even if you records the ip addresses, someone who knows how to use proxies to hide its real IP will still be able to vote again and again  :wink:

sure, but at least it is some more protection ;)

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] Votes saved in DB
« Reply #70 on: February 10, 2006, 01:18:45 AM »
Ok, since cheribibi did most of the job, its quiet easy to add IP check.
Note, the following will only work with version A of this mod!

Step 1
Execute this MySQL query (you can use phpmyadmin or something simular)
[qcode]ALTER TABLE 4images_voted ADD vote_ip VARCHAR( 15 ) NOT NULL[/qcode](make sure the table prefix is the same as its in your config.php. 4images_ is the default prefix.)

Step 2
Follow the cheribibi's tutorial above
then replace
Code: [Select]
  $sql30 = "SELECT vote
            FROM ".VOTED_TABLE."
            WHERE image_id =".$id." AND user_id =".$user_info['user_id'];
with:
Code: [Select]
  $sql30 = "SELECT vote
            FROM ".VOTED_TABLE."
            WHERE image_id =".$id." AND (user_id =".$user_info['user_id']." OR vote_ip = '".$site_sess->user_ip."')";

Step 3.
in includes/functions.php find:
Code: [Select]
$sql = "INSERT INTO ".VOTED_TABLE."
        (user_id, image_id, vote)
        VALUES
        (".$user_info['user_id'].", ".$image_id.", ".$rating.")";

Replace with:
Code: [Select]
global $site_sess;
$sql = "INSERT INTO ".VOTED_TABLE."
        (user_id, image_id, vote, vote_ip)
        VALUES
        (".$user_info['user_id'].", ".$image_id.", ".$rating.", '".$site_sess->user_ip."')";

I didnt tested this, but theoreticaly it should work ;)
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 trez

  • Hero Member
  • *****
  • Posts: 613
    • View Profile
    • blog / photography
Re: [MOD] Votes saved in DB
« Reply #71 on: February 10, 2006, 10:50:55 AM »
V@no, so this IP-check will not allow users from the same IP vote two times for the same picture? Just to get it right, if yes i will test it and post my results.
But, is there any way to do this without the "rate form disable after vote", because if i installthat mod, it will totally change my design (hot or not)?

Offline trez

  • Hero Member
  • *****
  • Posts: 613
    • View Profile
    • blog / photography
Re: [MOD] Votes saved in DB
« Reply #72 on: February 10, 2006, 10:30:12 PM »
v@no i have a further question related to your MOD. How can i delete all votes from a specific user ?

Offline Stoleti

  • Hero Member
  • *****
  • Posts: 574
    • View Profile
Re: [MOD] Votes saved in DB
« Reply #73 on: February 10, 2006, 11:03:41 PM »
On myphpadmin i think you can do that  :roll: , search and after after set again to 0 ...


Offline trez

  • Hero Member
  • *****
  • Posts: 613
    • View Profile
    • blog / photography
Re: [MOD] Votes saved in DB
« Reply #74 on: February 10, 2006, 11:41:50 PM »
On myphpadmin i think you can do that  :roll: , search and after after set again to 0 ...



really? but in whitch table? Iam not good at phpAdmin :)