Author Topic: [MOD] Votes saved in DB  (Read 244222 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] Votes saved in DB
« on: June 08, 2003, 06:19:12 PM »
This mod will save each members vote in the database. That means, that members now can only vote ONCE for the same image, even if they clear cookies.
I made two versions of this mod:

A - will uses new table in the database "4images_voted", that will stores new entry for each vote for each image and user. That would allow with some extra code display how many members voted for an image, who and what was the vote. And backwards: how many images the user voted, witch images and what was the vote. The disadvantage of this version is that database will grew as fast as many votes members do. :(

B - will uses existing users table "4images_users" with new field and store image ids and vote rating as simple text. Disadvantage of this version - statistics other then which images a member voted for would not be avalable (almost not possible).
------------------------------


Version A

Just 3 files to edit:
/includes/page_header.php
/includes/functions.php
/includes/constants.php


------ Installation ------

Step 1
Open /includes/page_header.php
Find:
Code: [Select]
  $rating = intval($HTTP_POST_VARS['rating']);Add after:
Code: [Select]
  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;
  }else{
    $rated = FALSE;
  }

Step 1.2
Find:
Code: [Select]
if (!in_array($id, $split_list) && !in_array($id, $cookie_rated)) {Replace with:
Code: [Select]
if (!in_array($id, $split_list) && !in_array($id, $cookie_rated) && !$rated) {

Step 2
Open /includes/functions.php
Find:
Code: [Select]
function update_image_rating($image_id, $rating) {
  global $site_db;
Replace with:
Code: [Select]
function update_image_rating($image_id, $rating) {
  global $site_db, $user_info;

Step 2.2
Find next:
Code: [Select]
$sql = "UPDATE ".IMAGES_TABLE."
            SET image_votes = ($old_votes + 1), image_rating = '$new_rating'
Add before:
Code: [Select]
   if ($user_info['user_id'] != GUEST) {
        $sql = "INSERT INTO ".VOTED_TABLE."
                (user_id, image_id, vote)
                VALUES
                (".$user_info['user_id'].", ".$image_id.", ".$rating.")";
        $site_db->query($sql);
    }


Step 3
Open /includes/constants.php
Add just before closing ?>
Code: [Select]
define('VOTED_TABLE', $table_prefix.'voted');

Step 4
Download this installer.
Unpack it and upload to your 4images root.
Start it http://yoursite/4images/voted_b_install.php



Version B

Just 3 files to edit:
/includes/page_header.php
/includes/functions.php
/includes/db_field_definitions.php


------ Installation ------

Step 1
Open /includes/page_header.php
Find:
Code: [Select]
  $rating = intval($HTTP_POST_VARS['rating']);Add after:
Code: [Select]
  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;
  }

Step 1.2
Find:
Code: [Select]
if (!in_array($id, $split_list) && !in_array($id, $cookie_rated)) {Replace with:
Code: [Select]
if (!in_array($id, $split_list) && !in_array($id, $cookie_rated) && !$rated) {

Step 2
Open /includes/functions.php
Find:
Code: [Select]
function update_image_rating($image_id, $rating) {
  global $site_db;
Replace with:
Code: [Select]
function update_image_rating($image_id, $rating) {
  global $site_db, $user_info;

Step 2.2
Find next:
Code: [Select]
    $sql = "UPDATE ".IMAGES_TABLE."
            SET image_votes = ($old_votes + 1), image_rating = '$new_rating'
Add before:
Code: [Select]
   if ($user_info['user_id'] != GUEST) {
        $user_info['user_voted'] = $user_info['user_voted']." ".$image_id.",".$rating;
        $sql = "UPDATE ".USERS_TABLE."
                SET user_voted = '".trim($user_info['user_voted'])."'
                WHERE user_id = ".$user_info['user_id'];
        $site_db->query($sql);
    }

Step 3
Open /includes/db_field_definitions.php
Add just before closing ?>
Code: [Select]
$additional_user_fields['user_voted'] = array("User votes", "text", 0);
Step 4
Download this installer.
Unpack it and upload to your 4images root.
Start it http://yoursite/4images/voted_b_install.php



Version history

1.0- Original release
« Last Edit: January 14, 2009, 04:33:25 PM 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 salem

  • Pre-Newbie
  • Posts: 7
    • View Profile
[MOD] Votes saved in DB
« Reply #1 on: June 09, 2003, 01:05:30 AM »
Thank you

But how can I see what did they vots? :(

Offline Lucifix

  • Hero Member
  • *****
  • Posts: 710
    • View Profile
    • http://www.slo-foto.net
[MOD] Votes saved in DB
« Reply #2 on: June 10, 2003, 07:11:11 PM »
Can we see any demo?

I would like to know if the votes can be see next to comments?

Offline Lionel

  • Pre-Newbie
  • Posts: 3
    • View Profile
[MOD] Votes saved in DB
« Reply #3 on: June 10, 2003, 09:21:52 PM »
Thank you V@no, it work perfectly ;)

Offline www.girls-on-bikes.com

  • Full Member
  • ***
  • Posts: 145
    • View Profile
    • http://www.girls-on-bikes.com/
[MOD] Votes saved in DB
« Reply #4 on: June 11, 2003, 12:33:21 AM »
Yes, can I see a demo of this
(V@no, was this the mod I requested?)

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] Votes saved in DB
« Reply #5 on: June 11, 2003, 12:43:00 AM »
I dont know, guys, what kind of demo do u need? :?
all I can show u is url to my site, registr/login and vote for something, close your browser, clear cookies, come back, and u'll see that u cant vote agian for same image.
what else I can show u? ;)

[EDITED]
ok, here is a little example of what u can do with version A:
http://www.come.no-ip.com/details.php?image_id=9741
look at the side, under category info.
With just one change it can also display what was their votes. (I dont want to show it, because I belive voting should be private)
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 www.girls-on-bikes.com

  • Full Member
  • ***
  • Posts: 145
    • View Profile
    • http://www.girls-on-bikes.com/
[MOD] Votes saved in DB
« Reply #6 on: June 11, 2003, 01:02:30 AM »
What I'm wondering is can this somehow be included in the Admin control panel so that we can look up a particular user, and see which images he/she voted on, and what rating they gave them?

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] Votes saved in DB
« Reply #7 on: June 11, 2003, 01:03:29 AM »
What I'm wondering is can this somehow be included in the Admin control panel so that we can look up a particular user, and see which images he/she voted on, and what rating they gave them?

yes, u can, with either of version.
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 www.girls-on-bikes.com

  • Full Member
  • ***
  • Posts: 145
    • View Profile
    • http://www.girls-on-bikes.com/
[MOD] Votes saved in DB
« Reply #8 on: June 11, 2003, 01:38:14 AM »
I'm currently in the middle of installing this, and ran into a problem.
On step 2.2, I have to instances of:
Quote
$sql = "UPDATE ".IMAGES_TABLE."


One inside this:
Quote
function update_comment_count($image_id = 0, $user_id = 0) {


The other is inside this:
Quote
function update_image_rating($image_id, $rating) {


Which one should I replace, or both?

Offline www.girls-on-bikes.com

  • Full Member
  • ***
  • Posts: 145
    • View Profile
    • http://www.girls-on-bikes.com/
[MOD] Votes saved in DB
« Reply #9 on: June 11, 2003, 01:41:47 AM »
And another problem.  Upon downloading voted_a_install.zip, I get the following error from WinZip:
Quote
Cannot open file: it does not appear to be a valid archice.
If you downloaded this file, try downloading the file again.


Anybody else have a problem with installer A?

Thanks

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] Votes saved in DB
« Reply #10 on: June 11, 2003, 02:14:41 AM »

On step 2.2, I have to instances of:
Quote
$sql = "UPDATE ".IMAGES_TABLE."


Which one should I replace, or both?

no, in function update_image_rating

by default u shouldnt have more then one "UPDATE"
ok, I have updated my post.

about the download thing, try to clear your internet cache and download again. I was upgrading my Apache to Apache2 and PHP 4.3.3, so u might caught that time...(also, registered users can receive by email any files ;))
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 www.girls-on-bikes.com

  • Full Member
  • ***
  • Posts: 145
    • View Profile
    • http://www.girls-on-bikes.com/
[MOD] Votes saved in DB
« Reply #11 on: June 11, 2003, 02:26:29 AM »
I have cleared my cache, still no go on the download.

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] Votes saved in DB
« Reply #12 on: June 11, 2003, 02:35:25 AM »
I have cleared my cache, still no go on the download.

I dont know what to say...nobody has reported this...
maybe try to reboot?
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 www.girls-on-bikes.com

  • Full Member
  • ***
  • Posts: 145
    • View Profile
    • http://www.girls-on-bikes.com/
[MOD] Votes saved in DB
« Reply #13 on: June 11, 2003, 02:36:15 AM »
Can you PM me the source or somethin?
I'd appreciate it.

Offline www.girls-on-bikes.com

  • Full Member
  • ***
  • Posts: 145
    • View Profile
    • http://www.girls-on-bikes.com/
[MOD] Votes saved in DB
« Reply #14 on: June 11, 2003, 03:33:24 AM »
Kewl, I got it all to work! :)
Now who wants to code v1.1?

[Request] What I would want is a place in the control panel to check out all of these stats, like give a list of users, which image they voted on, and what they gave that image.

Thanks!