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 AJust 3 files to edit:
/includes/page_header.php
/includes/functions.php
/includes/constants.php------ Installation ------
Step 1Open
/includes/page_header.phpFind:
$rating = intval($HTTP_POST_VARS['rating']);
Add after:
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.2Find:
if (!in_array($id, $split_list) && !in_array($id, $cookie_rated)) {
Replace with:
if (!in_array($id, $split_list) && !in_array($id, $cookie_rated) && !$rated) {
Step 2Open
/includes/functions.phpFind:
function update_image_rating($image_id, $rating) {
global $site_db;
Replace with:
function update_image_rating($image_id, $rating) {
global $site_db, $user_info;
Step 2.2Find next:
$sql = "UPDATE ".IMAGES_TABLE."
SET image_votes = ($old_votes + 1), image_rating = '$new_rating'
Add before:
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 3Open
/includes/constants.phpAdd just before closing
?>define('VOTED_TABLE', $table_prefix.'voted');
Step 4Download
this installer.
Unpack it and upload to your 4images root.
Start it
http://yoursite/4images/voted_b_install.phpVersion BJust 3 files to edit:
/includes/page_header.php
/includes/functions.php
/includes/db_field_definitions.php------ Installation ------
Step 1Open
/includes/page_header.phpFind:
$rating = intval($HTTP_POST_VARS['rating']);
Add after:
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.2Find:
if (!in_array($id, $split_list) && !in_array($id, $cookie_rated)) {
Replace with:
if (!in_array($id, $split_list) && !in_array($id, $cookie_rated) && !$rated) {
Step 2Open
/includes/functions.phpFind:
function update_image_rating($image_id, $rating) {
global $site_db;
Replace with:
function update_image_rating($image_id, $rating) {
global $site_db, $user_info;
Step 2.2Find next:
$sql = "UPDATE ".IMAGES_TABLE."
SET image_votes = ($old_votes + 1), image_rating = '$new_rating'
Add before:
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 3Open
/includes/db_field_definitions.phpAdd just before closing
?>$additional_user_fields['user_voted'] = array("User votes", "text", 0);
Step 4Download
this installer.
Unpack it and upload to your 4images root.
Start it
http://yoursite/4images/voted_b_install.php
Version history