4images Forum & Community

4images Modifications / Modifikationen => Mods & Plugins (Releases & Support) => Topic started by: V@no on June 08, 2003, 06:19:12 PM

Title: [MOD] Votes saved in DB
Post by: V@no 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 (http://www.4homepages.de/forum/index.php?topic=6123.msg37763#msg37763). 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 (http://gallery.vano.org/file31dl) 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 (http://gallery.vano.org/file32dl) installer.
Unpack it and upload to your 4images root.
Start it http://yoursite/4images/voted_b_install.php



Version history

1.0- Original release
Title: [MOD] Votes saved in DB
Post by: salem on June 09, 2003, 01:05:30 AM
Thank you

But how can I see what did they vots? :(
Title: [MOD] Votes saved in DB
Post by: Lucifix 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?
Title: [MOD] Votes saved in DB
Post by: Lionel on June 10, 2003, 09:21:52 PM
Thank you V@no, it work perfectly ;)
Title: [MOD] Votes saved in DB
Post by: www.girls-on-bikes.com on June 11, 2003, 12:33:21 AM
Yes, can I see a demo of this
(V@no, was this the mod I requested?)
Title: [MOD] Votes saved in DB
Post by: V@no 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)
Title: [MOD] Votes saved in DB
Post by: www.girls-on-bikes.com 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?
Title: [MOD] Votes saved in DB
Post by: V@no on June 11, 2003, 01:03:29 AM
Quote from: www.girls-on-bikes.com
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.
Title: [MOD] Votes saved in DB
Post by: www.girls-on-bikes.com 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?
Title: [MOD] Votes saved in DB
Post by: www.girls-on-bikes.com 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
Title: [MOD] Votes saved in DB
Post by: V@no on June 11, 2003, 02:14:41 AM
Quote from: www.girls-on-bikes.com

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 ;))
Title: [MOD] Votes saved in DB
Post by: www.girls-on-bikes.com on June 11, 2003, 02:26:29 AM
I have cleared my cache, still no go on the download.
Title: [MOD] Votes saved in DB
Post by: V@no on June 11, 2003, 02:35:25 AM
Quote from: www.girls-on-bikes.com
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?
Title: [MOD] Votes saved in DB
Post by: www.girls-on-bikes.com on June 11, 2003, 02:36:15 AM
Can you PM me the source or somethin?
I'd appreciate it.
Title: [MOD] Votes saved in DB
Post by: www.girls-on-bikes.com 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!
Title: [MOD] Votes saved in DB
Post by: Lucifix on June 11, 2003, 11:49:47 AM
What should we do if we want to show votes next to comments?
Title: [MOD] Votes saved in DB
Post by: Lucifix on June 11, 2003, 11:54:16 AM
I think there is bug in version A. I uploaded file voted_a_install.php and run it. But that one creates wrong table. It should create 4images_voted table not VOTED_CREATE or something like that.

And i have difficulte to unzip voted_a_install.zip file. One error is inside.
Title: [MOD] Votes saved in DB
Post by: V@no on June 11, 2003, 12:06:01 PM
Quote from: Lucifix1
I think there is bug in version A. I uploaded file voted_a_install.php and run it. But that one creates wrong table. It should create 4images_voted table not VOTED_CREATE or something like that.

And i have difficulte to unzip voted_a_install.zip file. One error is inside.
did u forgot do step 3?
Title: [MOD] Votes saved in DB
Post by: Lucifix on June 11, 2003, 12:08:59 PM
Nope i didnt forget it. But i was getting error that 4images_voted table doesnt exist. So i just changed that table to 4images_voted and now votes are saved in DB. But i just dont know how can i set that they will show in each comment
Title: [MOD] Votes saved in DB
Post by: www.girls-on-bikes.com on June 11, 2003, 08:45:25 PM
I also got the same error about the table name not being correct.
I think it did not pick up the variable "VOTED_TABLE", so it just named the table that.
Title: [MOD] Votes saved in DB
Post by: IngoT on June 11, 2003, 09:20:04 PM
The zip file of the version A is corrupted, you lets not extract.

Greeting Ingo.
Title: [MOD] Votes saved in DB
Post by: V@no on June 11, 2003, 09:32:35 PM
Quote from: IngoT
The zip file of the version A is corrupted, you lets not extract.

Greeting Ingo.

I dont know guys, what wrong with...who knows what, but I've tryed myself on 3 different browsers (NS6, Mozilla, IE6) on 3 different computers (including the server), none of my friends who downloaded this file, had any problems...I even made fresh .zip archive on different coputer...even switch back to Apache 1.3.6 now...
I'm pretty much sure its something wrong with your system.

P.S. I dont use WinZip or something, but I'm sure, that XP zip folders feature is standart as WinZip, so that cant cause the problem.
Title: [MOD] Votes saved in DB
Post by: www.girls-on-bikes.com on June 11, 2003, 10:13:28 PM
I tried with both winzip and winrar, and both said the file is corrupt.

I just tried here at work, first time downloading on this computer, and same error, so the file is definitely corrupt.
Title: [MOD] Votes saved in DB
Post by: V@no on June 12, 2003, 11:52:47 AM
ok, its turned out that the problem was PHP v4.3.3. I downgraded it to v4.2.3.
Try now and let me know if it still corrupted.
Title: [MOD] Votes saved in DB
Post by: IngoT on June 12, 2003, 02:44:22 PM
It works fine!

CU Ingo.
Title: [MOD] Votes saved in DB
Post by: Biggi on June 15, 2003, 12:09:34 PM
Great work, V@no! Thank you!

Quote
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)


I'd like to display each vote next to the comments, in the author's box for example. Would this be possible? What would I have to change?

Thanks in advance,

Biggi
Title: [MOD] Votes saved in DB
Post by: www.girls-on-bikes.com on June 15, 2003, 10:16:52 PM
Wow, this became a semi-popular mod :)
I just wanted to share what I decided to do for a gui:

http://new.girls-on-bikes.com/vote_stats.php
Title: [MOD] Votes saved in DB
Post by: SLL on June 16, 2003, 08:14:55 AM
Quote from: www.girls-on-bikes.com
I just wanted to share what I decided to do for a gui:

imho not a good idea... votes is a kind of privat information and i'm pretty sure my users will not be very happy when i disclose this info
Title: [MOD] Votes saved in DB
Post by: www.girls-on-bikes.com on June 17, 2003, 12:43:56 AM
This will not be something publicly available to users.
It will be moved into my password protected admin folder very soon, but I just wanted to share what I did as far as a gui is concerned.

And at a higher level, the reason I requested this mod is because I want to find out if any users are rating all the pictures with the lowest rating just to mess up the rating system.  I've had plenty of this with my old site, and this mod provides me with a way to easily check this.
Title: [MOD] Votes saved in DB
Post by: Lucifix on June 17, 2003, 11:20:16 PM
strange... my members and i want that the votes could be see next to comment. Is it possible?
Title: [MOD] Votes saved in DB
Post by: SLL on June 18, 2003, 08:14:58 AM
Quote from: Lucifix1
strange... my members and i want that the votes could be see next to comment. Is it possible?

nothing strange... it depends from the kind of gallery you're running... mine, for example, is for irc network, with photos of people chatting there, people knowing each other... i'm sure these people do not want to show their personal likes and dislikes on public

btw, admin plugin to "spy" all votes is ready, let's ask v@no to publish it  :wink:
Title: [MOD] Votes saved in DB
Post by: effemmess on June 21, 2003, 11:33:55 PM
Hi,

I´ve wrote 2 extensions to v@no´s mod. If you are interested, look here:
http://www.4homepages.de/forum/viewtopic.php?t=6404
http://www.4homepages.de/forum/viewtopic.php?t=6405

bye
Title: [MOD] Votes saved in DB
Post by: Lucifix on June 24, 2003, 05:44:08 PM
v@no will you publish it?  :roll:
Title: [MOD] Votes saved in DB
Post by: V@no on June 25, 2003, 12:52:54 AM
Quote from: Lucifix1
v@no will you publish it?  :roll:

no, because it doesnt work...properly...:(
Title: [MOD] Votes saved in DB
Post by: Lucifix on July 03, 2003, 05:10:42 PM
Well you sure knows php better then me, but its strange, couse in database you can actualy see  user_id  image_id  vote for specific photo. Tell us why is not working propertly, maybe we could solve it together?
Title: [MOD] Votes saved in DB
Post by: Lucifix on July 03, 2003, 05:14:33 PM
ups 2 posts together :(
Title: Re: [MOD] Votes saved in DB
Post by: sportman3333333 on March 11, 2005, 08:56:37 PM
Does anyone have the installer?

The file doesnt work.
Title: Re: [MOD] Votes saved in DB
Post by: V@no on March 12, 2005, 12:09:04 AM
Does anyone have the installer?

The file doesnt work.
The link fixed now.
Title: Re: [MOD] Votes saved in DB
Post by: sportman3333333 on March 12, 2005, 01:28:10 AM
Thanks, installing right now.

How do  i view the votes.
Title: Re: [MOD] Votes saved in DB
Post by: junethesis on May 08, 2005, 01:23:04 AM
Does anyone have the installer?

The file doesnt work.
The link fixed now.

All I get out of the link is a DLL file.  Is that correct?
Title: Re: [MOD] Votes saved in DB
Post by: V@no on May 08, 2005, 01:26:40 AM
All I get out of the link is a DLL file. Is that correct?
u are getting what?
I hope u are not trying right click on the link and save as...
Title: Re: [MOD] Votes saved in DB
Post by: junethesis on May 10, 2005, 06:30:26 AM
I wasn't right clicking, I just wasn't getting anywhere.  Must have been your server, or some server between yours and my IP...  anyway, I got it downloaded.

There's a problem though.  After testing, I found that deleting cookies makes it so that the user can vote again.  Isn't this supposed to prevent that from happening?  I'm using 4images 1.7.
Title: Re: [MOD] Votes saved in DB
Post by: V@no on May 10, 2005, 06:32:34 AM
if u tested it as a guest, then yes, that's supposed to be. Votes saved in the database only for members.
Title: Re: [MOD] Votes saved in DB
Post by: junethesis on May 10, 2005, 06:35:43 AM
Only registered members are able to vote.  No guests.
Title: Re: [MOD] Votes saved in DB
Post by: junethesis on May 10, 2005, 06:48:37 AM
Wait... I think I made a mistake.  Don't ponder over this just yet...
Title: Re: [MOD] Votes saved in DB
Post by: V@no on June 01, 2005, 01:29:00 AM
Here is a little addon for version A of this mod which I promised for a long time and never published it...
It will show who voted and if u logged in as admin also show what was the vote of each voted member on image details page (details.php)

Step 1
Open details.php
Find:
Code: [Select]
//-----------------------------------------------------
//--- Print Out ---------------------------------------
//-----------------------------------------------------

Insert above:
Code: [Select]
//-----------------------------------------------------
//--- Voted stats -------------------------------------
//-----------------------------------------------------
$sql = "SELECT v.user_id, v.vote, u.user_name
        FROM ".VOTED_TABLE." v
        LEFT JOIN ".USERS_TABLE." u ON (u.user_id = v.user_id)
        WHERE u.user_id = v.user_id AND image_id = ".$image_id;
$result = $site_db->query($sql);
$voted_list = "";
while ($row = $site_db->fetch_array($result))
{
  $vote = ($user_info['user_level'] == ADMIN) ? " (".$row['vote'].")" : "";
  $voted_list .= "<a href=\"".$site_sess->url(ROOT_PATH."member.php?action=showprofile&amp;user_id=".$row['user_id'])."\">".$row['user_name']."</a>".$vote."<br />"; //member name WITH a link to their profile page
//  $voted_list .= $row['user_name'].$vote."<br />"; //member name WITHOUT a link to their profile page
}
$site_template->register_vars(array(
  "voted_list" => $voted_list,
  "lang_voted_list" => $lang['voted_list']
));
//----- End Voted stats ----------------


Step 2
In lang/<your language>/main.php at the very end, above closing ?> insert:
Code: [Select]
$lang['voted_list'] = "Who voted";

Step 3
In templates/<your template>/details.html use the following tags:
{lang_voted_list} - this will show text "Who voted"
{voted_list} - this will show the list of members who has voted


P.S. if you installed a mod that changed details.php and that alteres $image_id variable, this mod might not work properly!
Title: Re: [MOD] Votes saved in DB
Post by: martrix on June 01, 2005, 09:35:49 AM
wonderful... thanks for this addon - I guess it was not only me waiting for this (no matter if 2 lazy or 2 stoopid to find out, how to do that)

I'll try to implement that tonight :D
Title: Re: [MOD] Votes saved in DB
Post by: txcherry1499 on June 08, 2005, 04:15:08 PM
Hi,
how can i insert more than one voting?
Perhaps u have a gallery and would like to let vote for graphic, quality, and so on ...

Best regards
Michaela
Title: Re: [MOD] Votes saved in DB
Post by: V@no on June 09, 2005, 12:04:33 AM
that would be a completly different mod ;)
perhaps u should start a new mod request topic
Title: Re: [MOD] Votes saved in DB
Post by: Zyga on November 13, 2005, 09:57:07 AM
What should I change to hide rating option ater vote (in version A) and show only how user rating this picture  :?:

something like "U voted already - > 5"



PS. thx great mod
Title: Re: [MOD] Votes saved in DB
Post by: Acidgod on November 13, 2005, 02:41:32 PM
you meen this?

http://www.4homepages.de/forum/index.php?topic=5853.0
Title: Re: [MOD] Votes saved in DB
Post by: Zyga on November 13, 2005, 05:09:44 PM
yes but how can i "mix it" with this mod ver. A
Title: Re: [MOD] Votes saved in DB
Post by: Fastian on January 15, 2006, 06:50:56 PM
Hi V@no

Few months back i install version B of this Mod. It was working good.

Now when i try to apply the mod "More than more statistics" I realised that i need Version A of your DB mode. I have undo the changes caused by v B in all three files but i dont know how to remove Database changes.

So what i am asking is. DO i need to remove anything caused by version B installer?

So far i cant see any error but i m not sure that i am not seeing it or is there no any error  :roll:
Title: Re: [MOD] Votes saved in DB
Post by: V@no on January 15, 2006, 07:43:59 PM
Dont worry about that ;) everything is ok :)
Title: Re: [MOD] Votes saved in DB
Post by: Joss on January 17, 2006, 04:00:12 PM
What about old ratings, which were voted, before this mod installed?
Will be all old votes displayed togeter with new votes from DB or not?
Thank you!
Title: Re: [MOD] Votes saved in DB
Post by: ch€ri{Bi}² on January 17, 2006, 07:04:20 PM
What about old ratings, which were voted, before this mod installed?
Unless you are an excellent magician or one powerful sorcerer, you can't get informations about it  :mrgreen:

Will be all old votes displayed togeter with new votes from DB or not?
same answer : you must reveal them initially  :lol:
Title: Re: [MOD] Votes saved in DB
Post by: V@no on January 18, 2006, 12:49:42 AM
What about old ratings, which were voted, before this mod installed?
Will be all old votes displayed togeter with new votes from DB or not?
Thank you!
This mod does not affect the image votes/ratings and it is more like a "logging" tool. But, as cheribibi said, you wont be able to tell who voted where and how much was the vote, before this mod installed ;)
Title: Re: [MOD] Votes saved in DB
Post by: Joss on January 18, 2006, 01:07:18 PM
Thanks! This was my bad english translation. I've spoke about the ratings, not about votes logging, of course.
Title: Re: [MOD] Votes saved in DB
Post by: Joss on January 18, 2006, 10:29:16 PM
Here is my changes for "Voted stats". I want to display users list with a comma delimeter, instead of a new line.
E.g.:

User1 (7), User2 (12), User3 (24)

instead of

User1 (7)
User2 (12)
User3 (24)

Code: [Select]
//-----------------------------------------------------
//--- Voted stats -------------------------------------
//-----------------------------------------------------
$sql = "SELECT v.user_id, v.vote, u.user_name
        FROM ".VOTED_TABLE." v
        LEFT JOIN ".USERS_TABLE." u ON (u.user_id = v.user_id)
        WHERE u.user_id = v.user_id AND image_id = ".$image_id;
$result = $site_db->query($sql);
$voted_list = "";
$vcnt = 0;
$sdelimeter = "";
while ($row = $site_db->fetch_array($result))
{
  if ($vcnt > 0)
  $sdelimeter = ", ";
  $vcnt++;
  $vote = ($user_info['user_level'] == ADMIN) ? " (".$row['vote'].")" : "";
  $voted_list .= $sdelimeter."<a href=\"".$site_sess->url(ROOT_PATH."member.php?action=showprofile&amp;user_id=".$row['user_id'])."\">".$row['user_name']."</a>".$vote;
  //member name WITH a link to their profile page

//$voted_list .= $row['user_name'].$vote."<br />"; //member name WITHOUT a link to their profile page
}
$site_template->register_vars(array(
  "voted_list" => $voted_list,
  "lang_voted_list" => $lang['voted_list']
));
//----- End Voted stats ----------------

Title: Re: [MOD] Votes saved in DB
Post by: Joss on January 18, 2006, 10:48:11 PM
V@no, can I fetch a number of votes for a user?  I want to decrease ulpoad limit for users who didn't votes, or who have less than 2 vote in DB. Thanks!
Title: Re: [MOD] Votes saved in DB
Post by: V@no 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 ;))
Title: Re: [MOD] Votes saved in DB
Post by: TIMT 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!
Title: Re: [MOD] Votes saved in DB
Post by: ch€ri{Bi}² on February 04, 2006, 10:35:23 AM
it seems you need this mod  (http://www.4homepages.de/forum/index.php?topic=5853) : [Mod] Rating Button Disabled After Vote
 :wink:
Title: Re: [MOD] Votes saved in DB
Post by: TIMT on February 04, 2006, 10:57:42 AM
upps... haven't seen this MOD    :oops:
Thanks cheribibi for the hint!  :)
Title: Re: [MOD] Votes saved in DB
Post by: Stoleti 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:
Title: Re: [MOD] Votes saved in DB
Post by: TIMT 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!!!
Title: Re: [MOD] Votes saved in DB
Post by: ch€ri{Bi}² 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 (http://www.4homepages.de/forum/index.php?topic=5853) 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:
Title: Re: [MOD] Votes saved in DB
Post by: trez 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?
Title: Re: [MOD] Votes saved in DB
Post by: ch€ri{Bi}² 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:
Title: Re: [MOD] Votes saved in DB
Post by: trez 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 ;)
Title: Re: [MOD] Votes saved in DB
Post by: V@no 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 ;)
Title: Re: [MOD] Votes saved in DB
Post by: trez 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)?
Title: Re: [MOD] Votes saved in DB
Post by: trez 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 ?
Title: Re: [MOD] Votes saved in DB
Post by: Stoleti 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 ...

Title: Re: [MOD] Votes saved in DB
Post by: trez 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 :)
Title: Re: [MOD] Votes saved in DB
Post by: Stoleti on February 11, 2006, 12:07:47 AM
Go to your DB (4images_XX) , there 4images_voted , and after choose "browse" , there you have a list of votes ;)

I've put as prefix 4images, maybe you've another one...but i hope you've understand (sorry for my english)
Title: Re: [MOD] Votes saved in DB
Post by: V@no on February 11, 2006, 12:09:12 AM
MySQL query:[qcode]DELETE FROM 4images_voted WHERE user_id = XXX[/qcode]where XXX is user id.

And yes, the code above will restrict voting for the same image from same IP, it will not work for guests though.
Title: Re: [MOD] Votes saved in DB
Post by: TIMT on February 11, 2006, 06:11:49 PM
cheribibi, V@no... thanks!!  :D

One more questions.
Is it correct, that the dropdownlist is not activ because of the DB entry, but the voting (e.g. 5) is shown becaus of a cookie?.
When I delete the cookies, the dropdown is not activ (perfect), but the voting isn't shown anymore.

Is it possible to show the voting stored in the DB?

Thanks!!
Title: Re: [MOD] Votes saved in DB
Post by: V@no on February 11, 2006, 06:27:44 PM
I just updated cheribibi's post (hope they dont mind ;))
replace
Code: [Select]
  $image_rated = (isset($row['vote']))? $row['vote'] : 0 ;with:
Code: [Select]
  $rating = (isset($row['vote']))? $row['vote'] : 0 ;
Title: Re: [MOD] Votes saved in DB
Post by: TIMT on February 11, 2006, 06:51:09 PM
Hi V@no,

now the MOD is perfect for me!

Again, thanks to you an cheribibi!   :D
Title: Re: [MOD] Votes saved in DB
Post by: Stoleti on February 11, 2006, 07:05:53 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:

Anyone can answer me ?  :roll:

Title: Re: [MOD] Votes saved in DB
Post by: V@no on February 11, 2006, 07:16:55 PM
http://www.4homepages.de/forum/index.php?topic=6123.45
Title: Re: [MOD] Votes saved in DB
Post by: Stoleti on February 11, 2006, 07:37:27 PM
http://www.4homepages.de/forum/index.php?topic=6123.45

But how make appear a message for non-admin's " You've no permission ... "   :?
Title: Re: [MOD] Votes saved in DB
Post by: Daniel on February 12, 2006, 01:43:02 PM
for Admin use:

$vote = ($user_info['user_level'] == ADMIN) ? " (".$row['vote'].")" : "";

for User use:

$vote = ($user_info['user_level'] == USER) ? " (".$row['vote'].")" : "";

and for Admin and User:

???

Sorry i dont no  :?
Title: Re: [MOD] Votes saved in DB
Post by: ch€ri{Bi}² on February 12, 2006, 03:02:41 PM
http://www.4homepages.de/forum/index.php?topic=6123.45

But how make appear a message for non-admin's " You've no permission ... "   :?

try to replace this code :
Code: [Select]
while ($row = $site_db->fetch_array($result))
{
  $vote = ($user_info['user_level'] == ADMIN) ? " (".$row['vote'].")" : "";
  $voted_list .= "<a href=\"".$site_sess->url(ROOT_PATH."member.php?action=showprofile&amp;user_id=".$row['user_id'])."\">".$row['user_name']."</a>".$vote."<br />"; //member name WITH a link to their profile page
//  $voted_list .= $row['user_name'].$vote."<br />"; //member name WITHOUT a link to their profile page
}
by this one :
Code: [Select]
if ($user_info['user_level'] == ADMIN) {
  while ($row = $site_db->fetch_array($result))
  {
    $vote = $row['vote'];
    $voted_list .= "<a href=\"".$site_sess->url(ROOT_PATH."member.php?action=showprofile&amp;user_id=".$row['user_id'])."\">".$row['user_name']."</a>".$vote."<br />"; //member name WITH a link to their profile page
  //  $voted_list .= $row['user_name'].$vote."<br />"; //member name WITHOUT a link to their profile page
  }
} else {
  $voted_list .= "You have no permission!" // or anything you want
}
Title: Re: [MOD] Votes saved in DB
Post by: TheOracle on February 12, 2006, 03:04:41 PM
@cheribibi:

Quote

if ($user_info['user_level'] == ADMIN) {
  while ($row = $site_db->fetch_array($result))
  {
    $vote = $row['vote'];
    $voted_list .= "<a href=\"".$site_sess->url(ROOT_PATH."member.php?action=showprofile&amp;".URL_USER_ID."=".$row[$user_table_fields['user_id']])."\">".$row[$user_table_fields['user_name']]."</a>".$vote."<br />"; //member name WITH a link to their profile page
  //  $voted_list .= $row[$user_table_fields['user_name']]. $vote."<br />"; //member name WITHOUT a link to their profile page
  }


And :

Quote

$voted_list .= "You have no permission!" // or anything you want


to :

Quote

$voted_list .= $lang['no_permission']; // or anything you want


This text has already been added as part of the core in 4images's lang/english/main.php definition file. ;)
Title: Re: [MOD] Votes saved in DB
Post by: ch€ri{Bi}² on February 12, 2006, 03:34:26 PM
@cheribibi:

Quote

if ($user_info['user_level'] == ADMIN) {
  while ($row = $site_db->fetch_array($result))
  {
    $vote = $row['vote'];
    $voted_list .= "<a href=\"".$site_sess->url(ROOT_PATH."member.php?action=showprofile&amp;URL_USER_ID."=".$row[$user_table_fields['user_id']])."\">".$row[$user_table_fields['user_name']]."</a>".$vote."<br />"; //member name WITH a link to their profile page
  //  $voted_list .= $row[$user_table_fields['user_name']]. $vote."<br />"; //member name WITHOUT a link to their profile page
  }



@TheOracle
well, the code I post was a copy/paste of another code this the topic. please can you also correct all the other codes in this thread ? thanks ! :mrgreen:
Title: Re: [MOD] Votes saved in DB
Post by: TheOracle on February 12, 2006, 03:57:55 PM
@Daniel:

Perhaps you're looking for this :

Code: [Select]

for User use:

$vote = ($user_info['user_level'] >= USER) ? " (".$row['vote'].")" : "";


;)
Title: Re: [MOD] Votes saved in DB
Post by: glitzer on February 12, 2006, 05:10:03 PM
 :Dworks perfect thank you very much!
Title: Re: [MOD] Votes saved in DB
Post by: wallpapers on February 12, 2006, 05:29:41 PM
I have made a plugin so you can view whitch member had voted in witch file.
My programming and my englisch are not good i know.

You can change a lot on this file. (it's a start for me  :lol:)

This is the code
Code: [Select]
<?php // PLUGIN_TITLE: voted

$nozip 1
define('IN_CP'1); 

$root_path "./../../"
define('ROOT_PATH'$root_path); 
require(
ROOT_PATH.'admin/admin_global.php'); 
show_admin_header(); 

function 
display_results() { 
  global $site_db
  
$sql 
'SELECT * FROM `4images_voted` LIMIT 0, 30 ';
  $result $site_db->query($sql); 
  while($row $site_db->fetch_array($result)){ 
    $user_id $row["user_id"]; 
    $postcard_date date("D d M, Y g:i a"$row["postcard_date"]); 
    $image_id $row["image_id"];
    $image_name $row["image_name"]; 
    $image_thumb_file $row["image_thumb_file"]; 
    $cat_id $row["cat_id"]; 
    $postcard_headline $row["postcard_headline"]; 
    $postcard_message $row["postcard_message"]; 
 
    
    $postcard_sender_name 
$row["postcard_sender_name"]; 
    $postcard_sender_email $row["postcard_sender_email"]; 
    $postcard_recipient_name $row["vote"]; 
    $postcard_recipient_email $row["postcard_recipient_email"]; 
    
    $cat_id 
$row['cat_id'];
    $pict_id get_media_code($row['image_media_file'], $image_id$cat_id$row['image_name']);
    $image_media_file get_media_code($row['image_media_file'], $image_id$cat_id$row['image_name']); 
    $template TEMPLATE_PATH
    
    
echo 
          
<font color=\"#000000\" size=\"1\"></td>
   </tr>
</tbody>
</table></td>
   </tr>
</tbody>
</table>
        <table border=\"1\">
                <tr>
                        <td height=\"15\" width=\"119\" align=\"center\" bgcolor=\"#E5E5E5\">
                        <p align=\"center\"><b>Gebruiker</b></td>
                        <td height=\"15\" width=\"148\" align=\"center\" bgcolor=\"#E5E5E5\"><b>
                        Cijfer</b></td>
                        <td height=\"15\" width=\"286\" align=\"center\" bgcolor=\"#E5E5E5\"><b>
                        Wallpaper</b></td>
                </tr>
                <tr>
                        <td height=\"21\" width=\"119\" align=\"center\" bgcolor=\"#F5F5F5\">
                        <font color=\"#000000\" size=\"2\" face=\"Tahoma\" >
$user_id</td>
                        <td height=\"21\" width=\"148\" align=\"center\" bgcolor=\"#F5F5F5\">
                        <font face=\"Tahoma\">  <font color=\"#000000\" size=\"2\" >
                        
$postcard_recipient_name</font><font size=\"2\">  </font>  <font color=\"#000000\" size=\"1\" >
                <a href=\"mailto:
$postcard_recipient_email\">
                        <font color=\"#000000\" size=\"2\">
$postcard_recipient_email</a></font></td>
                        <td height=\"21\" width=\"286\" align=\"center\" bgcolor=\"#F5F5F5\">
                        <font color=\"#555555\" size=\"2\" face=\"Tahoma\" >
&nbsp;(<a href=\"../../details.php?image_id=
$image_id\" target=\"_blank\">ID: $image_id</a>)
&nbsp;</font></td>
                </tr>
        </table>\n"
;
END;  


display_results(); 
show_admin_footer(); 
?>


Yes i change a other plugin to get this.
I enybody has a better code  8)
Title: Re: [MOD] Votes saved in DB
Post by: Daniel on February 12, 2006, 07:30:04 PM
@ theoracle

yes, thank you, very nice.  :D

>=

daniel
Title: Re: [MOD] Votes saved in DB
Post by: Stoleti on February 12, 2006, 08:59:31 PM
http://www.4homepages.de/forum/index.php?topic=6123.45

But how make appear a message for non-admin's " You've no permission ... "   :?

try to replace this code :
Code: [Select]
while ($row = $site_db->fetch_array($result))
{
  $vote = ($user_info['user_level'] == ADMIN) ? " (".$row['vote'].")" : "";
  $voted_list .= "<a href=\"".$site_sess->url(ROOT_PATH."member.php?action=showprofile&amp;user_id=".$row['user_id'])."\">".$row['user_name']."</a>".$vote."<br />"; //member name WITH a link to their profile page
//  $voted_list .= $row['user_name'].$vote."<br />"; //member name WITHOUT a link to their profile page
}
by this one :
Code: [Select]
if ($user_info['user_level'] == ADMIN) {
  while ($row = $site_db->fetch_array($result))
  {
    $vote = $row['vote'];
    $voted_list .= "<a href=\"".$site_sess->url(ROOT_PATH."member.php?action=showprofile&amp;user_id=".$row['user_id'])."\">".$row['user_name']."</a>".$vote."<br />"; //member name WITH a link to their profile page
  //  $voted_list .= $row['user_name'].$vote."<br />"; //member name WITHOUT a link to their profile page
  }
} else {
  $voted_list .= "You have no permission!" // or anything you want
}

Thanks its working very well  :mrgreen:
Title: Re: [MOD] Votes saved in DB
Post by: TheOracle on February 12, 2006, 09:33:12 PM
@stoleti:

please read this post in the mean time :

http://www.4homepages.de/forum/index.php?topic=6123.msg60862#msg60862

@daniel:

Glad it worked out for you. ;)
Title: Re: [MOD] Votes saved in DB
Post by: Stoleti on February 12, 2006, 09:45:56 PM
@stoleti:

please read this post in the mean time :

http://www.4homepages.de/forum/index.php?topic=6123.msg60862#msg60862

@daniel:

Glad it worked out for you. ;)

I've made that modifications  8)
Title: Re: [MOD] Votes saved in DB
Post by: dosensteck on February 13, 2006, 01:16:18 AM
i have a problem with this mod... all vote_date entries are "0"  :?:

i need the vote date for a toplist - i will select all images they have rating x with x votes and order by last vote date.... but without vote_date ist impossible  :|
Title: Re: [MOD] Votes saved in DB
Post by: V@no on February 13, 2006, 01:31:04 AM
This mod does not store the date...sorry.
Title: Re: [MOD] Votes saved in DB
Post by: dosensteck on February 13, 2006, 10:40:49 AM
hm, iam confused...

why i have in 4images_voted table a vote_date?
Title: Re: [MOD] Votes saved in DB
Post by: V@no on February 13, 2006, 10:48:18 AM
most probably after installing one of these mods:
http://www.4homepages.de/forum/index.php?topic=6484.0
http://www.4homepages.de/forum/index.php?topic=6404.0
Title: Re: [MOD] Votes saved in DB
Post by: dosensteck on February 14, 2006, 12:04:09 AM
ok, thx :/
Title: Re: [MOD] Votes saved in DB
Post by: trez on February 26, 2006, 02:16:55 PM
V@no, the IP-check is not working.
I can vote still twice with 2 diffrefrent usernames after deleting cookies  :roll:

edit: when i make the steps, i can even vote twice for an image  :roll:
Title: Re: [MOD] Votes saved in DB
Post by: V@no on February 26, 2006, 07:24:44 PM
The code by cheribi plus mine addition from this (http://www.4homepages.de/forum/index.php?topic=6123.msg60531#msg60531) page doesnt work? did you check all the step and make sure everything is correctly modifyed?
I've tested it on a fresh 4images, it worked just fine, in fact, I'm using the exact code on my site...
Title: Re: [MOD] Votes saved in DB
Post by: trez on February 26, 2006, 08:06:28 PM
yes!

i tried first to install the mod [rating buttoin disabled...] , then your update for the votes to database, after that cheribis code and after  that you modifications. Dont work. After that, i restored my backups and tried just to add the code from charibi and your addition - dont work either.

The problem is, that i have many users online, and now i have errors in the database, users are getting mad etc :(
Maybe i have made some error, even if i checked it many times, can i post my functions.php and my page_header in order to you to make the changes? I just dont wanna risk  more doubble-votings from my users.

thanks for the support, i really appreciate it.

Georgi
Title: Re: [MOD] Votes saved in DB
Post by: Zyga on March 07, 2006, 03:06:59 PM
next great addon for this mod could be something like "show only 10 (xx) last voters"   :idea:
Title: Re: [MOD] Votes saved in DB
Post by: IcEcReaM on March 07, 2006, 03:42:51 PM
you mean listed in the details page?
Title: Re: [MOD] Votes saved in DB
Post by: Zyga on March 07, 2006, 10:58:35 PM
yeah later list could be a really long  :wink:
Title: Re: [MOD] Votes saved in DB
Post by: Fryz on July 19, 2006, 04:57:08 PM
hallo,

ich hab das mod (version a) insalliert und bekomme beim abstimmen folgenden fehler:

DB Error: Bad SQL Query: SELECT user_id, image_id, vote FROM 4images_voted WHERE image_id = 2329 AND user_id = 1
Unknown column 'user_id' in 'field list'


kann mir da mal jemand helfen?

danke
Title: Re: [MOD] Votes saved in DB
Post by: V@no on July 20, 2006, 03:05:51 AM
huh? and what fields are in your 4images_voted table? Hope you didnt change anything that were not supposed to...
Title: Re: [MOD] Votes saved in DB
Post by: Fryz on July 20, 2006, 12:24:50 PM
Thanx for answering.
I didn't change anything that is not supposed to be changed, I made everything as advised. look---> http://fryz.fr.funpic.de/4images/statistics.php

In the moment i vote for a photo in my gallery, the following hint appears:


DB Error: Bad SQL Query: SELECT user_id, image_id, vote FROM 4images_voted WHERE image_id = 2354 AND user_id = 2
Unknown column 'user_id' in 'field list'

DB Error: Bad SQL Query: INSERT INTO 4images_voted (user_id, image_id, vote) VALUES (2, 2354, 5)
Unknown column 'user_id' in 'field list'
Title: Re: [MOD] Votes saved in DB
Post by: V@no on July 20, 2006, 02:39:18 PM
So, what are the fields in your 4images_voted table?
Title: Re: [MOD] Votes saved in DB
Post by: Fryz on July 20, 2006, 02:58:41 PM
VOTED_TABLE    INT    11    -----     UNSIGNED     not null     0     -----


you mean this?
Title: Re: [MOD] Votes saved in DB
Post by: V@no on July 20, 2006, 03:14:55 PM
No, I mean this something like this:[qcode]CREATE TABLE `4images_voted` (
  `id` mediumint(8) NOT NULL auto_increment,
  `user_id` mediumint(8) unsigned NOT NULL default '0',
  `image_id` mediumint(8) unsigned NOT NULL default '0',
  `vote` int(2) unsigned NOT NULL default '0',
  `date` int(11) NOT NULL default '0',
  PRIMARY KEY  (`id`),
  KEY `user_id` (`user_id`),
  KEY `image_id` (`image_id`)
) ENGINE=MyISAM;[/qcode](this is how it looks like when you export it in phpmyadmin)

or from mysql shell itself:[qcode]mysql> SHOW columns FROM 4images_voted;
+----------+-----------------------+------+-----+---------+----------------+
| Field    | Type                  | Null | Key | Default | Extra          |
+----------+-----------------------+------+-----+---------+----------------+
| id       | mediumint(8)          |      | PRI | NULL    | auto_increment |
| user_id  | mediumint(8) unsigned |      | MUL | 0       |                |
| image_id | mediumint(8) unsigned |      | MUL | 0       |                |
| vote     | int(2) unsigned       |      |     | 0       |                |
| date     | int(11)               |      |     | 0       |                |
+----------+-----------------------+------+-----+---------+----------------+
5 rows in set (0.00 sec)[/qcode]

I think you should delete the table and run the installer again.
Title: Re: [MOD] Votes saved in DB
Post by: mstgokcen on July 21, 2006, 12:03:32 PM
I have the same code like :

DB Error: Bad SQL Query: INSERT INTO 4images_voted (user_id, image_id, vote) VALUES (, 12, 3)
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' 12, 3)' at line 4
 

and my table on myphpadmin is like:

----------------------------------------------------

#
# Tablo yapısı : `4images_voted`
#

DROP TABLE IF EXISTS `4images_voted`;
CREATE TABLE `4images_voted` (
  `user_id` mediumint(8) unsigned NOT NULL default '0',
  `image_id` mediumint(8) unsigned NOT NULL default '0',
  `vote` int(2) unsigned NOT NULL default '0',
  KEY `user_id` (`user_id`),
  KEY `image_id` (`image_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;




whats wrong?

NOTE: I had already installed "more and more statistics MOD" before this mod.
Title: Re: [MOD] Votes saved in DB
Post by: mstgokcen on July 21, 2006, 12:10:47 PM
In the first page you say:



Open /includes/functions.php

Step 2.2
Find next:
Code: [Select]
    $sql = "UPDATE ".IMAGES_TABLE."
            SET image_votes = ($image_votes + 1), image_rating = '$new_rating'
Add before:

Code: [Select]
if ($user_info[$user_table_fields['user_id']] != GUEST) {
  $sql = "INSERT INTO ".VOTED_TABLE."
          (user_id, image_id, vote)
          VALUES
          (".$user_info[$user_table_fields['user_id']].", ".$image_id.", ".$rating.")";
  $site_db->query($sql);
}



but in my function.php I coudnt find the code you told but I have this code instead

$sql = "UPDATE ".IMAGES_TABLE."
            SET image_votes = ($old_votes + 1), image_rating = '$new_rating'
            WHERE image_id = $image_id";
    $site_db->query($sql);




why my code is different

should I follow the version B?
Title: Re: [MOD] Votes saved in DB
Post by: myr2904 on July 21, 2006, 01:19:14 PM
After i vote..apear this:


DB Error: Bad SQL Query: INSERT INTO 4images_voted (user_id, image_id, vote) VALUES (, 19, 1)
You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near ' 19, 1)' at line 4

Why?


Title: Re: [MOD] Votes saved in DB
Post by: V@no on July 21, 2006, 02:26:12 PM
Sorry, redo steps 1 and 2.2
Title: Re: [MOD] Votes saved in DB
Post by: myr2904 on July 21, 2006, 02:45:25 PM




but in my function.php I coudnt find the code you told but I have this code instead

$sql = "UPDATE ".IMAGES_TABLE."
            SET image_votes = ($old_votes + 1), image_rating = '$new_rating'
            WHERE image_id = $image_id";
    $site_db->query($sql);




why my code is different

should I follow the version B?


I have the same problem
Title: Re: [MOD] Votes saved in DB
Post by: V@no on July 21, 2006, 02:54:03 PM
yes, insert the new code above
Code: [Select]
$sql = "UPDATE ".IMAGES_TABLE."
            SET image_votes = ($old_votes + 1), image_rating = '$new_rating'

P.S. I've updated the original post, thanks.
Title: Re: [MOD] Votes saved in DB
Post by: myr2904 on July 21, 2006, 03:09:41 PM
function update_image_rating($image_id, $rating) {
  global $site_db, $user_info;
  $sql = "SELECT cat_id, image_votes, image_rating
          FROM ".IMAGES_TABLE."
          WHERE image_id = $image_id";
  $image_row = $site_db->query_firstrow($sql);
  if (check_permission("auth_vote", $image_row['cat_id'])) {
    $old_votes = $image_row['image_votes'];
    $old_rating = $image_row['image_rating'];
    $new_rating = (($old_rating * $old_votes) + $rating) / ($old_votes + 1);
    $new_rating = sprintf("%.2f", $new_rating);
    $sql = "UPDATE ".IMAGES_TABLE."
            SET image_votes = ($old_votes + 1), image_rating = '$new_rating'



/*line 555 >>>*/            if ($user_info[$user_table_fields['user_id']] != GUEST) {
  $sql = "INSERT INTO ".VOTED_TABLE."
          (user_id, image_id, vote)
          VALUES
          (".$user_info[$user_table_fields['user_id']].", ".$image_id.", ".$rating.")";
  $site_db->query($sql);
}   



         
            WHERE image_id = $image_id";
    $site_db->query($sql);
  }
}



The code it's ok?

because i have a problem >>>> Parse error: syntax error, unexpected '[', expecting ']' in /home/etop100/public_html/concurs/includes/functions.php on line 555
Title: Re: [MOD] Votes saved in DB
Post by: V@no on July 21, 2006, 03:37:50 PM
ABOVE (before), not BELOW (after) ;)
Title: Re: [MOD] Votes saved in DB
Post by: myr2904 on July 21, 2006, 04:30:34 PM
ups ... thx

but i steel have this error:
Code: [Select]
DB Error: Bad SQL Query: INSERT INTO 4images_voted (user_id, image_id, vote) VALUES (, 19, 1)
You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near ' 19, 1)' at line 4
Version 1.7.1
Title: Re: [MOD] Votes saved in DB
Post by: myr2904 on July 21, 2006, 04:38:49 PM
I have the same code like :

DB Error: Bad SQL Query: INSERT INTO 4images_voted (user_id, image_id, vote) VALUES (, 12, 3)
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' 12, 3)' at line 4
 

and my table on myphpadmin is like:

----------------------------------------------------

#
# Tablo yapısı : `4images_voted`
#

DROP TABLE IF EXISTS `4images_voted`;
CREATE TABLE `4images_voted` (
  `user_id` mediumint(8) unsigned NOT NULL default '0',
  `image_id` mediumint(8) unsigned NOT NULL default '0',
  `vote` int(2) unsigned NOT NULL default '0',
  KEY `user_id` (`user_id`),
  KEY `image_id` (`image_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;




whats wrong?

NOTE: I had already installed "more and more statistics MOD" before this mod.


The same problem!
Title: Re: [MOD] Votes saved in DB
Post by: V@no on July 22, 2006, 12:42:42 AM
I already answered you...you dont have to repeat yourself 3 times...
Sorry, redo steps 1 and 2.2
Title: Re: [MOD] Votes saved in DB
Post by: mstgokcen on July 22, 2006, 11:49:48 AM
Now it works perfect thnx V@no but it displays

who voted: user1
                 user2
                 user3

isnt it better to display user1,user2,user.....how can we change?

more import is (as asked before many times) I want the get vote in the comment table...

I mean
user1 ..... his comment ....and his vote ...not listing in details table

it is really important for me?
Title: Re: [MOD] Votes saved in DB
Post by: Ch*yeuk on July 23, 2006, 10:41:14 PM
Thanks for the mod, works great =D now I'm just trying to find out how to disable guest voting =\
Title: Re: [MOD] Votes saved in DB
Post by: tansamalaja on August 11, 2006, 04:20:48 PM
Quote
[qcode]CREATE TABLE `4images_voted` (
  `id` mediumint(8) NOT NULL auto_increment,
  `user_id` mediumint(8) unsigned NOT NULL default '0',
  `image_id` mediumint(8) unsigned NOT NULL default '0',
  `vote` int(2) unsigned NOT NULL default '0',
  `date` int(11) NOT NULL default '0',
  PRIMARY KEY  (`id`),
  KEY `user_id` (`user_id`),
  KEY `image_id` (`image_id`)
) ENGINE=MyISAM;[/qcode]

So I get the right table in the sql, but not with the voted_a_install.php from your zip from the first posting.
The table which is craeted by the install-php is named "VOTED_TABLE" then I got BD Errors, table not exist
Title: Re: [MOD] Votes saved in DB
Post by: mawenzi on August 11, 2006, 04:50:33 PM
Step 3
Open /includes/constants.php
Add just before closing ?>
Code: [Select]
define('VOTED_TABLE', $table_prefix.'voted');
Title: Re: [MOD] Votes saved in DB
Post by: tansamalaja on August 11, 2006, 07:52:41 PM
I did it as it was written by v@no but it didn't help...
Title: Re: [MOD] Votes saved in DB
Post by: V@no on August 12, 2006, 10:18:33 AM
You must do step 3 before you run the installer. if your new table named as "VOTED_TABLE", then you did not do properly the step 3.
Title: Re: [MOD] Votes saved in DB
Post by: tansamalaja on August 12, 2006, 09:25:48 PM
That could be the mistake...  :(
Title: Re: [MOD] Votes saved in DB
Post by: nacho-lopez on August 28, 2006, 03:35:11 PM
What should I change in the code so everybody, admin, guest and users can see what was the vote of each voted member on image details page?
Best regards from Spain and thank you very much  :D

Here is a little addon for version A of this mod which I promised for a long time and never published it...
It will show who voted and if u logged in as admin also show what was the vote of each voted member on image details page (details.php)

Step 1
Open details.php
Find:
Code: [Select]
//-----------------------------------------------------
//--- Print Out ---------------------------------------
//-----------------------------------------------------

Insert above:
Code: [Select]
//-----------------------------------------------------
//--- Voted stats -------------------------------------
//-----------------------------------------------------
$sql = "SELECT v.user_id, v.vote, u.user_name
        FROM ".VOTED_TABLE." v
        LEFT JOIN ".USERS_TABLE." u ON (u.user_id = v.user_id)
        WHERE u.user_id = v.user_id AND image_id = ".$image_id;
$result = $site_db->query($sql);
$voted_list = "";
while ($row = $site_db->fetch_array($result))
{
  $vote = ($user_info['user_level'] == ADMIN) ? " (".$row['vote'].")" : "";
  $voted_list .= "<a href=\"".$site_sess->url(ROOT_PATH."member.php?action=showprofile&amp;user_id=".$row['user_id'])."\">".$row['user_name']."</a>".$vote."<br />"; //member name WITH a link to their profile page
//  $voted_list .= $row['user_name'].$vote."<br />"; //member name WITHOUT a link to their profile page
}
$site_template->register_vars(array(
  "voted_list" => $voted_list,
  "lang_voted_list" => $lang['voted_list']
));
//----- End Voted stats ----------------


Step 2
In lang/<your language>/main.php at the very end, above closing ?> insert:
Code: [Select]
$lang['voted_list'] = "Who voted";

Step 3
In templates/<your template>/details.html use the following tags:
{lang_voted_list} - this will show text "Who voted"
{voted_list} - this will show the list of members who has voted


P.S. if you installed a mod that changed details.php and that alteres $image_id variable, this mod might not work properly!
Title: Re: [MOD] Votes saved in DB
Post by: V@no on August 28, 2006, 03:46:22 PM
Code: [Select]
  $vote = ($user_info['user_level'] == ADMIN) ? " (".$row['vote'].")" : "";
To this:
Code: [Select]
  $vote = " (".$row['vote'].")";
Title: Re: [MOD] Votes saved in DB
Post by: nacho-lopez on August 28, 2006, 04:20:01 PM
Thank you very much V@no
Title: Re: [MOD] Votes saved in DB
Post by: nacho-lopez on August 28, 2006, 07:29:20 PM
I think I have another problem...  :roll:
I tried to delete some votes from the database. I did it from phpmyadmin but I still can see them if i check the top images from my gallery...
Even I deleted them, they are showed in the top yet...
Do you understand what I mean?
Sorry for my horrible english  :oops:
Title: Re: [MOD] Votes saved in DB
Post by: V@no on August 29, 2006, 12:25:23 AM
Correct, thats because this mod does not change the way 4images stores the total votes/rating, its being saved into 4images_images table for each image individualy. So, what you see at top page, is the information stored in 4images_images table.
Title: Re: [MOD] Votes saved in DB
Post by: nacho-lopez on August 29, 2006, 07:39:34 AM
Thank you again V@no  :D
Is there any solution?. It is no so easy to change it by hand because people is voting often their own pics to appear in the top and I have to delete it...  :roll:
Correct, thats because this mod does not change the way 4images stores the total votes/rating, its being saved into 4images_images table for each image individualy. So, what you see at top page, is the information stored in 4images_images table.
Title: Re: [MOD] Votes saved in DB
Post by: soapycats on September 15, 2006, 03:00:52 PM
is there another link for the installer, I cant seem to get any action on the link given here.

also -- regarding 1.7.3 regular voting/rating data, is there any way "as is" without this mod or any other to pull the voting history - i need to see who has already voted, before install the mod.
also, can anyone explain the logic of the voting calculation 4images provides?

thanks in advance,
michelle
Title: Re: [MOD] Votes saved in DB
Post by: desperate_housewif on September 17, 2006, 10:16:14 AM
Habe die erforderlichen Statistikdateien soweit erstellt. Da beim Aufrufen der bekannte und hier schon beschrieben Datenbankfehler auftauchte, wollte ich V@no´s Vote installieren, was man offensichtlich dazu benötigt. Leider kann ich V@no über den in dem Forum angegebenen Link derzeit nicht erreichen. Kennt jemand einen anderen Link für den Mod?
Title: Re: [MOD] Votes saved in DB
Post by: V@no on September 17, 2006, 06:37:18 PM
I've attached the installers to the original post.
Title: Re: [MOD] Votes saved in DB
Post by: Stoleti on September 17, 2006, 07:26:25 PM
Its possible list at our profiles, the users who have rate our images ???

 :P
Title: Re: [MOD] Votes saved in DB
Post by: soapycats on September 18, 2006, 03:27:00 PM
I've attached the installers to the original post.

thanks Vano, i didn't notice the "attached zip files" at the bottom of the instructions on page1.

question -
i've already received some votes before the add-on was installed, is there any way i can find out who voted and what they voted for from the admin panel/database download for the votes received before the addon was added!????

otherwise, in the databases download before the addon was installed, there are fields as follows:
image_votes  / image_rating / image_hits
can you explain the logic behind the rating?
it does not seem to be a simple calculation of "votes" x "score" (given on rating template)??
does it factor in the hits too??? 

i really need help on this and appreciation feedback. 
thanks
Title: Re: [MOD] Votes saved in DB
Post by: V@no on September 18, 2006, 03:35:47 PM
No, such information is not available without this mod, so votes before this mod are not recoverable...
as of hits included in the vote system - no, the rating calculated as average of all votes. The formula is the following:

new rating = ((old rating * number of votes) + rating) / (number of votes + 1)
Title: Re: [MOD] Votes saved in DB
Post by: qvforum on September 18, 2006, 06:47:14 PM
Hello, does the Votes saved in DB MOD function with an integration phpbb of the user intergration? What do I have to consider thereby, change which code perhaps?

Andreas

PS: Please my very bad English excuses
Title: Re: [MOD] Votes saved in DB
Post by: soapycats on November 25, 2006, 04:25:22 PM
....the rating calculated as average of all votes. The formula is the following:

new rating = ((old rating * number of votes) + rating) / (number of votes + 1)

Hi Vano,   

I am still a little confused.

If i multiple votes x rating will that give me the over total value of the votes received for that image?

How can I back calculate from the formula you give above, e.g., new rating = ((old rating * nu. images) + rating).........????

For example, currently an image with a rating of 5 beats one with a rating of 4.75 BUT in actual fact the image with 4.75 actually received more votes and thus a higher overall score and was penalised when it was averaged! whereas the images with a rating of 5 sometimes only received one voter giving one good vote? 

and why do some calculate with a decimal?
for example, one image got 9 votes, and a rating of 3.34 which would give a total of 30.06 and as there isn't any decimals in my ratings which go 1 to 5 (best) I dont know how the total could have a decimal?????

any feedback advice on the formula and calculation would be greatly appreciated !!!

thanks,
michelle
Title: Re: [MOD] Votes saved in DB
Post by: {{DELIKANLIM}} on January 25, 2007, 08:11:21 PM
Die Version A habe ich installiert und es funktioniert alles, außer die DB Votes. Da steht jetzt allerdings "An unexpected error occured. Please try again later." Vorher stand aber, dass es Probleme mit der Datenbank gibt.
Hier ist die Adresse:
http://www.delikanlim.net/galery/

Könnten Sie mir bitte helfen?
Ich danke im Vorraus.
Title: Re: [MOD] Votes saved in DB
Post by: cipriansamoila on February 23, 2007, 12:57:52 AM
Hi,

what are the changes needed when using PHPBB user integration.

I am gettting errors in the details page http://icons.greenmap.org/gallery/details.php?image_id=400

i hope V@no will be around to help me out... i have been around for 2 years and it's now i need your help.

best,
cip
Title: Re: [MOD] Votes saved in DB
Post by: mstgokcen on May 09, 2007, 09:36:32 AM

who voted: user1
                 user2
                 user3

isnt it better to display

who voted: user1,user2,user.....

how can we change?


still need an answer..help plz
Title: ERROR in DB
Post by: Darkness2001 on July 30, 2007, 05:06:27 PM
Hi,

ich bekomme immer nach jedem Kommentareintrag auf der detail Seite einen Fehler angezeigt. Wenn ich im Adminbereich Bilder bearbeite und dann speichere kommt der selbe Fehler

Errormeldung: DB Error: Bad SQL Query: INSERT INTO galerie_voted (user_id, image_id, vote) VALUES (, 4, )
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' 4, )' at line 4

ich habe hier schon gesucht, aber nix gefunden.

Mein table voted in der DB sieht so aus:

--
-- Tabellenstruktur für Tabelle `galerie_voted`
--

DROP TABLE IF EXISTS `galerie_voted`;
CREATE TABLE `galerie_voted` (
  `user_id` mediumint(8) NOT NULL default '0',
  `image_id` mediumint(8) unsigned NOT NULL default '0',
  `vote` int(2) unsigned NOT NULL default '0',
  `vote_date` int(10) unsigned NOT NULL default '0',
  KEY `user_id` (`user_id`),
  KEY `image_id` (`image_id`),
  KEY `vote_date` (`vote_date`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_german2_ci;

Wer kann mir helfen  :mrgreen:

GRüße darkness
Title: Re: [MOD] Votes saved in DB
Post by: thunderstrike on August 18, 2007, 04:54:25 PM
This for see who rate in details.

In details.php file,

find:

Quote
//-----------------------------------------------------
//--- Show Image --------------------------------------
//-----------------------------------------------------

add before:

Quote
//-----------------------------------------------------
//--- Show user vote foreach image  -----
//-----------------------------------------------------
$sql = "

SELECT " . get_user_table_field("v.", "user_id") . get_user_table_field(", u.", "user_name") . ", v.vote
FROM (" . VOTED_TABLE . " v, " . IMAGES_TABLE . " i)
LEFT JOIN " . USERS_TABLE . " u ON (" . get_user_table_field("u.", "user_id") . " = v.user_id)
WHERE i.image_id = " . $image_id;

$result = $site_db->query($sql);

if (isset($result) && $result) {

while ($vote_row = $site_db->fetch_array($result)) {
}

}

In includes/functions.php file,

find:

Quote
function show_image($image_row, $mode = "", $show_link = 1, $detailed_view = 0) {
  global $self_url, $site_template, $site_sess, $user_info, $config, $cat_cache, $lang, $additional_image_fields, $user_table_fields, $url_show_profile;

replace:

Quote
function show_image($image_row, $mode = "", $show_link = 1, $detailed_view = 0) {
  global $self_url, $site_template, $site_sess, $user_info, $config, $cat_cache, $lang, $additional_image_fields, $user_table_fields, $url_show_profile, $vote_row;

Find:

Quote
"image_hits" => $image_row['image_hits'],

add after:

Quote
"vote_user_id" => $vote_row[$user_table_fields['user_id']],
"lang_vote_user_name" => preg_replace("/" . $site_template->start. "get_vote_user_name" . $site_template->end . "/siU", $vote_row[$user_table_fields['user_name']], $lang['vote_user_name']),
"vote_user_value" => $vote_row['vote'],

In lang/english/main.php file,

add before ?>:

Quote
$lang['vote_user_name'] = "Voted by: {get_vote_user_name}";

In templates/your_template/details.html file,

use:

Quote
{vote_user_id} (for URL)
{lang_vote_user_name}
{vote_user_value}

and create way you want. ;)
Title: Re: [MOD] Votes saved in DB
Post by: davy_74 on December 13, 2007, 10:59:34 PM
Hi folks.

I did option A of this mod, and works perfect. I added a new field to 4images_voted table. I called it user_ip just to store the IP of the user who votes. Everything I tried doesn't store the IP, that field is empty in all my records.

my function update_image_rating is as follows. I know I'm close but I don't know how to reach. Some help please

//function update_image_rating($image_id, $rating) {
//  global $site_db;


function update_image_rating($image_id, $rating) {
  global $site_db, $user_info; 
 
  $sql = "SELECT cat_id, image_votes, image_rating
          FROM ".IMAGES_TABLE."
          WHERE image_id = $image_id";
  $image_row = $site_db->query_firstrow($sql);
  if (check_permission("auth_vote", $image_row['cat_id'])) {
    $old_votes = $image_row['image_votes'];
    $old_rating = $image_row['image_rating'];
    $new_rating = (($old_rating * $old_votes) + $rating) / ($old_votes + 1);
    $new_rating = sprintf("%.2f", $new_rating);


//oooooooooooooooooooooooooooooooooooooooo

// this is for including guest's votes too

   //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);
    }
//oooooooooooooooooooooooooooooooooooooooo


    $sql = "UPDATE ".IMAGES_TABLE."
            SET image_votes = ($old_votes + 1), image_rating = '$new_rating'
            WHERE image_id = $image_id";
    $site_db->query($sql);
  }
}


Cheers

Davy
Title: Re: [MOD] Votes saved in DB
Post by: darvid on December 14, 2007, 05:07:06 PM
This is an addition for users who used Kurts "Star Rating Mod" (http://www.4homepages.de/forum/index.php?topic=17829.0)



OPEN RATING_NEW.PHP:

FIND:

Code: [Select]
?>
INSERT BEFORE




   
Code: [Select]

// Anfang: Hinzugefügt, SebastianScheuer.de, Datum: 12. Dezember 2007
   
$sql = "INSERT INTO ".VOTED_TABLE."
(user_id, image_id, vote)
VALUES
(".$user_info['user_id'].", ".$image_id_sent.", ".$vote_sent.")";
$site_db->query($sql);

// Ende: Hinzugefügt, SebastianScheuer.de, Datum: 12. Dezember 2007
Title: Re: [MOD] Votes saved in DB
Post by: KurtW on December 14, 2007, 06:08:53 PM
i thing, it is not working  :wink:


KurtW
Title: Re: [MOD] Votes saved in DB
Post by: darvid on December 14, 2007, 06:14:17 PM
oh yeah it is. you have to use the code in the thread vom V@no of course. and after that: use my piece and put it in rating_new.php.

notice: i have only members allowed to vote, so it is possible to save username, id, voting and a lot more ;)
Title: Re: [MOD] Votes saved in DB
Post by: KurtW on December 14, 2007, 06:18:01 PM
sorry, but i thing no...

you use a old mode code.

in rating_new.php:

search:
Code: [Select]
        if (($vote_sent >= 1 && $vote_sent <= $units)) {
                $update = "UPDATE " . IMAGES_TABLE . " SET image_votes='".$count_new."', image_rating='".$sum_new."', image_used_ips='".$ip."', image_used_ids='".$old_used_ids."".$leer."".$new_used_id."' WHERE image_id='" . $image_id_sent . "'";
                $result = $site_db->query($update);

after this code you can add the new code from c-bass


Kurt
Title: Problem deleting images and Ctegories in [MOD] Votes saved in DB - Option A
Post by: davy_74 on December 26, 2007, 04:04:26 PM
Hey guys

I already installed the [MOD] Votes saved in DB. I use Option A. I use a table called "voted" to store the image_id, the user_id, vote, and user_IP. The problem is when I delete an image or an entire category, it's ok. 4images delete the records in the images table, but doesn't delete the record in the voted table. How can we repair this?

I looked for the code to delete the image

  $sql = "DELETE FROM ".IMAGES_TABLE."
          WHERE image_id = $image_id";
  $del_img = $site_db->query($sql);


and the code to delete the comments

  $sql = "DELETE FROM ".COMMENTS_TABLE."
          WHERE image_id = $image_id";
  $del_com = $site_db->query($sql);

We should add something like this somewhere  (I don't know how) -- PLease Help

  $sql = "DELETE FROM ".VOTED_TABLE."
          WHERE image_id = $image_id";
  $del_img = $site_db->query($sql);

In ACP we should do something too.

Need some help from the author and the good programmers here to solve this.

Cheers

David
Title: Re: [MOD] Votes saved in DB
Post by: darvid on December 26, 2007, 05:01:32 PM
the same goes for deleting users. the user votes also have to be deleted.
Title: Re: [MOD] Votes saved in DB
Post by: davy_74 on December 26, 2007, 06:44:26 PM
Yes, c-bass you are right. But the problem I have is where to put the code. I know MySQL but I'm a newbie in PHP coding.
I need some help

Cheers

David

Title: Re: [MOD] Votes saved in DB
Post by: Daniel on December 31, 2007, 04:54:58 PM
David... i think in admin/users.php

and delete the user...not the images  :wink:

       $sql = "DELETE FROM ".VOTED_TABLE."
          WHERE user_id = $user_id";
       $site_db->query($sql);
Title: Re: [MOD] Votes saved in DB
Post by: Daniel on January 01, 2008, 03:07:48 PM
 :?:

Wie müßte bloß die sql-Abrafe lauten wenn man nur die neuen Votes aus dem VOTED_TABLE errechnen und in den images_table damit updaten wollen würde...

How can i use only new new votes (just from voted_table) to inset this in the image_table

 :?:


a happy new year  :wink:
Title: Re: [MOD] Votes saved in DB
Post by: Daniel on January 08, 2008, 06:22:37 PM
Du kannst für jede einzelne Kategorie angeben wer voten darf... ACP -> Kategorien bearbeiten
Title: Re: [MOD] Votes saved in DB
Post by: skiemor on January 12, 2008, 08:44:31 AM
From Configuration statistics.php "Note: Save Votes in DB type A must be installed and altered by votetime"
http://www.4homepages.de/forum/index.php?topic=6123.0

How to do that?

In der statistics.php ist der Tabellenname VOTED_TABLE vorgegeben.
Meine Tabelle heißt aber 4images_voted und da wird auch alles reingeschrieben. Zumindest wird eine Statistik erstellt
Die VOTED_TABLE ist leer.


Die Tabelle wird in der statistics.html angzeigt, wenn ich die Funktion aktiviere (1 statt 0).

Chris
Title: Re: [MOD] Votes saved in DB
Post by: skiemor on January 12, 2008, 11:19:11 AM
Ich habe jetzt einfach mal testweise bei den Bildern ein Datum (1200055080) eingetragen.
In der Statistik werden die Votes dann gezählt.
Neue Bewertungen werden aber nicht dazugezählt. ;-(

Ich glaube, dass die Anpasssung fehlt: "Note: Save Votes in DB type A must be installed and altered by votetime".
http://www.4homepages.de/forum/index.php?topic=6123.0

Kann mir jemand dabei helfen?

Chris.
Title: Re: [MOD] Votes saved in DB
Post by: shadowhunter on April 01, 2008, 09:32:57 PM
Hallo!

Ich habe den MOD Votes saved in DB - Option A installiert und versuchte die IP-Adresse zu speichern beim Berwerten.
Dazu machte ich folgendes:

DB-Code:
Code: [Select]
ALTER TABLE 4images_voted ADD vote_ip VARCHAR( 15 ) NOT NULL
includes/functions.php
Suche:
Code: [Select]
$sql = "INSERT INTO ".VOTED_TABLE."
        (user_id, image_id, vote)
        VALUES
        (".$user_info['user_id'].", ".$image_id.", ".$rating.")";

Ersetze mit:
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.")";

Jedoch dies alles funktionierte nicht.
Es stand nur "NULL" in "vote_ip". "global $site_sess;" vergass ich nicht...

Ich versuchte auch mit "$session_info['session_ip']" anstatt mit "$site_sess->user_ip".

Könntet ihr mir bitte weiterhelfen.
Vielen Dank
Gruss Jones


4images: 1.7.6
Php Version: 4.4.7
Title: Re: [MOD] Votes saved in DB
Post by: cliff on January 14, 2009, 11:31:48 AM
Hallo,

der MOD interessiert mich sehr, allerdings ist der Link zur Installationsdatei von Seite 1 nicht mehr aktuell. Hat hier jemand noch diese Datei oder den entsprechenden sql Befehl... ???

__________

I am very interested of this Mod, but the link to the installer at side 1 isn´t active. Has here anyone the file or the sql order...???

Besten Dank
ThanX
cliff
Title: Re: [MOD] Votes saved in DB
Post by: V@no on January 14, 2009, 04:35:03 PM
all needed files are attached to the original post:
http://www.4homepages.de/forum/index.php?topic=6123.msg26633#post_attach
Title: Re: [MOD] Votes saved in DB
Post by: cliff on January 14, 2009, 06:06:43 PM
ohhh... call me an idiot!  I didn´t see that file... Now it´s running wonderful!
ThanX a lot...

best regards
cliff
Title: Re: [MOD] Votes saved in DB
Post by: luktur on January 21, 2009, 11:26:51 AM
This mod is fantastic Thx for it.

It's working very good.

It's posiible to have data and hour of voting on photo?

http://ogk.cal.pl/details.php?image_id=684

After my nick.
Title: Re: [MOD] Votes saved in DB
Post by: mstgokcen on March 17, 2009, 02:02:48 PM
is it possible to delete my vote and re-vote? Or change the vote? But aain everyone must give vote for once not more then once
Title: Re: [MOD] Votes saved in DB
Post by: luktur on May 08, 2009, 04:15:13 PM
Hello.

How can I prevent from users that are voting from own photo?
Title: Re: [MOD] Votes saved in DB
Post by: luener on November 02, 2009, 04:40:59 PM
Thx for this Mod,
it works great on my Site. :D

Ralf
Title: Re: [MOD] Votes saved in DB
Post by: alekseyn1 on December 26, 2009, 01:34:17 PM
guys, anyone knows how to join this MOD and this MOD http://www.4homepages.de/forum/index.php?topic=4023.0?

I run a website where people comment, but are not  very keen in setting a rating....

so I would really appreciate any help in joining of this MOD with this MOD http://www.4homepages.de/forum/index.php?topic=4023.0

but i need that MOD to let visitors post comment ONLY with voting and vote without comment


EDIT
Nevermind...
Title: Re: [MOD] Votes saved in DB
Post by: alekseyn1 on December 27, 2009, 10:27:09 PM
OK guys... I solved it...

Here is what you do if you want to have a comment ONLY if your user rated an image... and the user can VOTE with no comments for the image...

1. Install this MOD  :lol:

2. in comments_form.html

add in the place where you would like this form to appear...

Code: [Select]
  <!--new rate system -->
{if rate_form}
<tr>
<td>
{rate}
</td>

<td valign="bottom">
<select name="rating" class="select" {rate_button}>
{rate_options}
</select>
<input type="hidden" name="action" value="rateimage" />
<input type="hidden" name="id" value="{image_id}" />
</td>
</tr>
   {endif rate_form}
  <!-- end of new rate system -->


3. in details.php

find:

Code: [Select]
if ($user_name == "")  {
and ADD BEFORE

Code: [Select]
//no comment without rating

//user rated before?
$image_rated_by_user = "";
    $sql = "SELECT vote
            FROM ".VOTED_TABLE."
            WHERE image_id =".$id." AND user_id =".$user_info['user_id'];
   
$row = $site_db->query_firstrow($sql);
    $image_rated_by_user = (isset($row['vote']))? 1 : 0 ;

//user is the owner of image?

$is_image_owner2 = "";
$sql2 = "SELECT i.image_id, i.cat_id, i.user_id, i.image_name, i.image_description, i.image_keywords, i.image_date, i.image_active, i.image_media_file, i.image_thumb_file, i.image_download_url, i.image_allow_comments, i.image_comments, i.image_downloads, i.image_votes, i.image_rating, i.image_hits".$additional_sql.", c.cat_name".get_user_table_field(", u.", "user_name").get_user_table_field(", u.", "user_email")."
        FROM (".IMAGES_TABLE." i,  ".CATEGORIES_TABLE." c)
        LEFT JOIN ".USERS_TABLE." u ON (".get_user_table_field("u.", "user_id")." = i.user_id)
        WHERE i.image_id = ".$id." AND i.image_active = 1 AND c.cat_id = i.cat_id";
$image_row2 = $site_db->query_firstrow($sql2);
$is_image_owner2 = ($user_info['user_id'] == $image_row2['user_id']) ? 1 : 0;


    if (!$is_image_owner2 && $image_rated_by_user == 0 && $rating == "--")  {
  $msg .= (($msg != "") ? "<br />" : "").$lang['rating_required'];
  $error = 1;
}

//end no comment without rating

3.1

find

Code: [Select]
update_comment_count($id, $user_info['user_id']);
and ADD AFTER

Code: [Select]
//save rating from comment form
 
  if (!$is_image_owner2 && $image_rated_by_user == 0) {
  update_image_rating($id, $rating);
  }
  //end save rating from comment form


4. in your language main.php

find

Code: [Select]
//-----------------------------------------------------
//--- Image Details -----------------------------------
//-----------------------------------------------------

and add after

Code: [Select]
$lang['rating_required'] = "You did not include the rating for this image";
this should work for you...

I can not remove one bug....

I have not removed the original rate form from below the image, so that user can vote as before and that rate form works perfectly... and shows the rating you have gived to the image....

but if you add a rating from the comments form, it gets entered into the database and the comment appears.. but the rate form does not change... thus letting the user vote again from the separate rate form...

anyways any ideas please.. I ran out of steam today trying to resolve this one...
Title: Re: [MOD] Votes saved in DB
Post by: V@no on December 27, 2009, 10:58:04 PM
Not quiet sure what exactly is the problem...it's not clear...also your tutorial is a mix of several other mods you've installed and would not work for everyone else, unfortunately.
Title: Re: [MOD] Votes saved in DB
Post by: alekseyn1 on December 27, 2009, 11:13:23 PM
well... trouble is, that when the comment is posted, the rating value is transfered with POST... database updates..

but the data for the rate form (not the one listed by me, but the one modded with the modification listed in this topic to show the user vote after he voted) does not get pulled from the database correctly...

EDIT

fixed by replacing in page_header.php

line

Code: [Select]
if ($action == "rateimage" && $id) {
with line
Code: [Select]
if ($action == "rateimage" && $id || $action == "postcomment" && $id) {
Title: Re: [MOD] Votes saved in DB
Post by: Joss on February 06, 2010, 02:00:32 AM
Hey guys

I already installed the [MOD] Votes saved in DB. I use Option A. I use a table called "voted" to store the image_id, the user_id, vote, and user_IP. The problem is when I delete an image or an entire category, it's ok. 4images delete the records in the images table, but doesn't delete the record in the voted table. How can we repair this?

I agree with it. For now I've deleted more than 25000 rows from 4images_voted table via phpMyAdmin:

Code: [Select]
DELETE
FROM `4images_voted`
WHERE NOT EXISTS
( SELECT *
FROM `4images_images`
WHERE 4images_images.image_id = 4images_voted.image_id
);

DELETE
FROM `4images_voted`
WHERE NOT EXISTS
( SELECT *
FROM `4images_users`
WHERE 4images_users.user_id = 4images_voted.user_id
);

But we need a correction on core delete (image/user) function.
Title: Re: [MOD] Votes saved in DB
Post by: luktur on February 27, 2010, 11:43:09 PM
This mod is super. But is it possible that users can't see who voted on photo? Now they can only see who voted but they can't see the point's.
I want that only admin know who voted on picture.
Title: Re: [MOD] Votes saved in DB
Post by: Joss on April 14, 2010, 08:12:41 PM
I want that only admin know who voted on picture.

Open details.php, find
Code: [Select]
//--- Voted stats -------------------------------------
and before

Code: [Select]
$site_template->register_vars(array(
insert something like (change YOURNAME to your login)

if ($user_info['user_name'] !="YOURNAME") {
    $voted_list = "Image was rated";
}
Title: Re: [MOD] Votes saved in DB
Post by: V@no on April 15, 2010, 04:00:56 AM
This mod is super. But is it possible that users can't see who voted on photo? Now they can only see who voted but they can't see the point's.
I want that only admin know who voted on picture.
What mod/code are you referring to?

@Joss:
better use if ($user_info['user_level'] == ADMIN)
{
  // your code here
}
;)
Title: Re: [MOD] Votes saved in DB
Post by: luktur on May 03, 2010, 08:31:47 PM

@Joss:
better use if ($user_info['user_level'] == ADMIN)
{
  // your code here
}
;)
[/quote]

When a putt Your code it's not working :/ I still see nick as quest or normal user.


if ($user_info['user_name'] !="YOURNAME") {
    $voted_list = "Image was rated";
}

Code above is working but how add more admins?
Title: Re: [MOD] Votes saved in DB
Post by: luktur on February 04, 2011, 07:05:05 PM
Is this possible?:

Create new category (photo of the month). I put for example 10 photos and user vote for it. But - on gallery a have voting scale 1-10.

Is this possible to do for this category:
- only one point - user can give only 1 (in other categories all the time 1-10)
- hide for user info about voting - only admins can see it. (now user can see in bellow thumbnail)
Title: Re: [MOD] Votes saved in DB
Post by: Artemios on March 05, 2011, 01:26:05 PM
Ich benutze [MOD] Votes saved in DB in der Version B.

Erstmal ein Dank an V@no. Es funktioniert ausgezeichnet. Es gibt keine Probleme.

Nun möchte ich verhindern, dass User ihre eigenen Bilder bewerten können.

Dafür habe ich ein Mod von 2006 gefunden, dass die functions.php ändert.

User darf sein eigenes Bild nicht bewerten:
http://www.4homepages.de/forum/index.php?topic=489.msg2197#msg2197 (http://www.4homepages.de/forum/index.php?topic=489.msg2197#msg2197)

Ich weiß nun nicht, ob sich diese beiden Mods vertragen.
Oder gibt es eine andere Möglichkeit, das [MOD] Votes saved in DB Version B, so anzupassen, dass eigene Bilder nicht bewertet werden können?


Nachtrag: ich habe es einfach ausprobiert und es klappt dann nicht mehr. Zwar können die eigenen Bilder nicht mehr bewertet werden, aber die Datenbank funktioniert nicht mehr.
Mit dem Ergebnis, dass jetzt wieder mehrfache Bewertungen aller anderen Bilder möglich sind.

Daher noch einmal die Frage, ob es eine anderes Mod gibt, dass man einsetzen könnte und das sich mit "Votes saved in DB in der Version B" verträgt?

Wäre schön, wenn sich mal jemand äußern könnte.

Gruß
Artemios


Title: Re: [MOD] Votes saved in DB
Post by: kandr on April 22, 2011, 03:35:45 PM
Vano, hi.
Explain me pls, only votes of registred users save in DB? what about guests?
After cookie delete, every guest can vote again!

Теперь по-русски. Проблема такова, что действительно, после удаления кукисов возможность голосования остается у гостей (-1), и их голос не сохраняется в БД.
Что можно сделать с этим?
Title: Re: [MOD] Votes saved in DB
Post by: luktur on August 17, 2011, 08:00:38 PM
It's possible?

I want that average of votes will be shown only for admins and the autor of the foto.
Title: Re: [MOD] Votes saved in DB
Post by: lailash on April 04, 2012, 12:05:37 PM
Hallo,
habe ein kleines Problem in (/member.php?action=showprofile&user_id=552), hätte es gerne so wie bei (Kommentare:    (19)  alle anzeigen)

Bilder bewertet    (15)  alle anzeigen (hier fehlt mir die Seite) bekomme ich nicht hin
Registriert seit:    22.07.2009
Aktualisiert:    04.04.2012 09:22
Kommentare:    (19)  alle anzeigen (geht)
Kommentare schreiben    Passives Mitglied, Beginner,  Aktives Mitglied, Super, Mega
Email:    
Homepage:    
ICQ:    
toni's Favoriten:    (34)  alle anzeigen (geht)

Gruss Lailash
Title: Re: [MOD] Votes saved in DB
Post by: V@no on April 04, 2012, 02:14:58 PM
Vano, hi.
Explain me pls, only votes of registred users save in DB? what about guests?
After cookie delete, every guest can vote again!
The only solution is to don't allow vote for guests.

Hallo,
habe ein kleines Problem in (/member.php?action=showprofile&user_id=552), hätte es gerne so wie bei (Kommentare:    (19)  alle anzeigen)

Bilder bewertet    (15)  alle anzeigen (hier fehlt mir die Seite) bekomme ich nicht hin
Registriert seit:    22.07.2009
Aktualisiert:    04.04.2012 09:22
Kommentare:    (19)  alle anzeigen (geht)
Kommentare schreiben    Passives Mitglied, Beginner,  Aktives Mitglied, Super, Mega
Email:    
Homepage:    
ICQ:    
toni's Favoriten:    (34)  alle anzeigen (geht)

Gruss Lailash
Yes, possible, but that would be a completely knew mod ;)
Try request it at mod request section.
Title: Re: [MOD] Votes saved in DB
Post by: pjotrek on June 19, 2012, 07:08:12 AM
Instructions from version A - first post in this topic.

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

So if I use method A I should download voted_b_install yes ?
Title: Re: [MOD] Votes saved in DB
Post by: Rembrandt on June 19, 2012, 07:23:21 AM
...So if I use method A I should download voted_b_install yes ?
no, voted_a_install.php, This is a read error in the instruction.
Title: Re: [MOD] Votes saved in DB
Post by: pjotrek on June 19, 2012, 11:35:13 AM
thx but it's a pity that when i install this mod : http://www.4homepages.de/forum/index.php?topic=6157.0 (http://www.4homepages.de/forum/index.php?topic=6157.0) (vote and comment sending together) the rating is not saving to database - there must be some error i think...unfortunatelly :(
Title: Re: [MOD] Votes saved in DB
Post by: Jackomo on October 26, 2013, 11:33:27 AM
Used version B, worked right away  :mrgreen:
Big thanks !
J.
Title: Re: [MOD] Votes saved in DB
Post by: wallward on January 16, 2014, 10:17:49 AM
Maybe a rather stupid question, but will this work on the latest version (1.7.11)?