source: trunk/include/functions_rate.inc.php @ 1992

Last change on this file since 1992 was 1992, checked in by rub, 17 years ago

Issue 0000684: History [Search] - Add a thumbnail display

o Display choice can be selected
o Display choice is saved on on cookie
o Small improvement picture link (hoverbox on all the link, alt&title on classic mode)
o New cookie functions and use

Enhance computing method of script_basename function.

http://forum.phpwebgallery.net/viewtopic.php?pid=58258#p58258

Merge BSF 1988:1989 into branch-1_7

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 4.0 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | PhpWebGallery - a PHP based picture gallery                           |
4// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
5// | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | file          : $Id: functions_rate.inc.php 1992 2007-05-01 13:57:52Z rub $
8// | last update   : $Date: 2007-05-01 13:57:52 +0000 (Tue, 01 May 2007) $
9// | last modifier : $Author: rub $
10// | revision      : $Revision: 1992 $
11// +-----------------------------------------------------------------------+
12// | This program is free software; you can redistribute it and/or modify  |
13// | it under the terms of the GNU General Public License as published by  |
14// | the Free Software Foundation                                          |
15// |                                                                       |
16// | This program is distributed in the hope that it will be useful, but   |
17// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
18// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
19// | General Public License for more details.                              |
20// |                                                                       |
21// | You should have received a copy of the GNU General Public License     |
22// | along with this program; if not, write to the Free Software           |
23// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
24// | USA.                                                                  |
25// +-----------------------------------------------------------------------+
26
27/**
28 * rate a picture by a user
29 *
30 * @param int image identifier
31 * @param int rate
32 * @return void
33 */
34function rate_picture($image_id, $rate)
35{
36  global $conf, $user;
37
38  if (!isset($rate)
39      or !$conf['rate']
40      or !in_array($rate, $conf['rate_items']))
41  {
42    return;
43  }
44
45  $user_anonymous = is_autorize_status(ACCESS_CLASSIC) ? false : true;
46
47  if ($user_anonymous and !$conf['rate_anonymous'])
48  {
49    return;
50  }
51
52  if ($user_anonymous)
53  {
54    $ip_components = explode('.', $_SERVER["REMOTE_ADDR"]);
55    if (count($ip_components) > 3)
56    {
57      array_pop($ip_components);
58    }
59    $anonymous_id = implode ('.', $ip_components);
60
61    $save_anonymous_id = pwg_get_cookie_var('anonymous_rater', $anonymous_id);
62
63    if ($anonymous_id != $save_anonymous_id)
64    { // client has changed his IP adress or he's trying to fool us
65      $query = '
66SELECT element_id
67FROM '.RATE_TABLE.'
68WHERE user_id = '.$user['id'].'
69  AND anonymous_id = \''.$anonymous_id.'\'
70;';
71      $already_there = array_from_query($query, 'element_id');
72
73      if (count($already_there) > 0)
74      {
75        $query = '
76DELETE
77FROM '.RATE_TABLE.'
78WHERE user_id = '.$user['id'].'
79  AND anonymous_id = \''.$save_anonymous_id.'\'
80  AND element_id NOT IN ('.implode(',', $already_there).')
81;';
82         pwg_query($query);
83       }
84
85       $query = '
86UPDATE
87'.RATE_TABLE.'
88SET anonymous_id = \'' .$anonymous_id.'\'
89WHERE user_id = '.$user['id'].'
90  AND anonymous_id = \'' . $save_anonymous_id.'\'
91;';
92       pwg_query($query);
93    } // end client changed ip
94
95  pwg_get_cookie_var('anonymous_rater', $anonymous_id);
96  } // end anonymous user
97
98  $query = '
99DELETE
100  FROM '.RATE_TABLE.'
101  WHERE element_id = '.$image_id.'
102  AND user_id = '.$user['id'].'
103';
104  if (isset($anonymous_id))
105  {
106    $query.= ' AND anonymous_id = \''.$anonymous_id.'\'';
107  }
108  pwg_query($query);
109  $query = '
110INSERT
111  INTO '.RATE_TABLE.'
112  (user_id,anonymous_id,element_id,rate,date)
113  VALUES
114  ('
115    .$user['id'].','
116    .(isset($anonymous_id) ? '\''.$anonymous_id.'\'' : "''").','
117    .$image_id.','
118    .$rate
119    .',NOW())
120;';
121  pwg_query($query);
122
123  // update of images.average_rate field
124  $query = '
125SELECT ROUND(AVG(rate),2) AS average_rate
126  FROM '.RATE_TABLE.'
127  WHERE element_id = '.$image_id.'
128;';
129  $row = mysql_fetch_array(pwg_query($query));
130  $query = '
131UPDATE '.IMAGES_TABLE.'
132  SET average_rate = '.$row['average_rate'].'
133  WHERE id = '.$image_id.'
134;';
135  pwg_query($query);
136}
137
138?>
Note: See TracBrowser for help on using the repository browser.