source: trunk/include/picture_rate.inc.php @ 2297

Last change on this file since 2297 was 2297, checked in by plg, 16 years ago

Modification: new header on PHP files, PhpWebGallery renamed Piwigo.

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 4.6 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based picture gallery                                  |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008      Piwigo Team                  http://piwigo.org |
6// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
7// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
8// +-----------------------------------------------------------------------+
9// | This program is free software; you can redistribute it and/or modify  |
10// | it under the terms of the GNU General Public License as published by  |
11// | the Free Software Foundation                                          |
12// |                                                                       |
13// | This program is distributed in the hope that it will be useful, but   |
14// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
15// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
16// | General Public License for more details.                              |
17// |                                                                       |
18// | You should have received a copy of the GNU General Public License     |
19// | along with this program; if not, write to the Free Software           |
20// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
21// | USA.                                                                  |
22// +-----------------------------------------------------------------------+
23// +-----------------------------------------------------------------------+
24// | PhpWebGallery - a PHP based picture gallery                           |
25// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
26// | Copyright (C) 2003-2008 PhpWebGallery Team - http://phpwebgallery.net |
27// +-----------------------------------------------------------------------+
28// | file          : $Id: picture_rate.inc.php 2297 2008-04-04 22:57:23Z plg $
29// | last update   : $Date: 2008-04-04 22:57:23 +0000 (Fri, 04 Apr 2008) $
30// | last modifier : $Author: plg $
31// | revision      : $Revision: 2297 $
32// +-----------------------------------------------------------------------+
33// | This program is free software; you can redistribute it and/or modify  |
34// | it under the terms of the GNU General Public License as published by  |
35// | the Free Software Foundation                                          |
36// |                                                                       |
37// | This program is distributed in the hope that it will be useful, but   |
38// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
39// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
40// | General Public License for more details.                              |
41// |                                                                       |
42// | You should have received a copy of the GNU General Public License     |
43// | along with this program; if not, write to the Free Software           |
44// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
45// | USA.                                                                  |
46// +-----------------------------------------------------------------------+
47
48/**
49 * This file is included by the picture page to manage rates
50 *
51 */
52
53if ($conf['rate'])
54{
55  $query = '
56SELECT COUNT(rate) AS count
57     , ROUND(AVG(rate),2) AS average
58     , ROUND(STD(rate),2) AS std
59  FROM '.RATE_TABLE.'
60  WHERE element_id = '.$picture['current']['id'].'
61;';
62  $row = mysql_fetch_array(pwg_query($query));
63  $template->assign('rate_summary', $row);
64
65  $user_rate = null;
66  if ($conf['rate_anonymous'] or is_autorize_status(ACCESS_CLASSIC) )
67  {
68    if ($row['count']>0)
69    {
70      $query = 'SELECT rate
71      FROM '.RATE_TABLE.'
72      WHERE element_id = '.$page['image_id'] . '
73      AND user_id = '.$user['id'] ;
74
75      if ( !is_autorize_status(ACCESS_CLASSIC) )
76      {
77        $ip_components = explode('.', $_SERVER['REMOTE_ADDR']);
78        if ( count($ip_components)>3 )
79        {
80          array_pop($ip_components);
81        }
82        $anonymous_id = implode ('.', $ip_components);
83        $query .= ' AND anonymous_id = \''.$anonymous_id . '\'';
84      }
85
86      $result = pwg_query($query);
87      if (mysql_num_rows($result) > 0)
88      {
89        $row = mysql_fetch_array($result);
90        $user_rate = $row['rate'];
91      }
92    }
93
94    $template->assign(
95        'rating',
96        array(
97          'F_ACTION' => add_url_params(
98                        $url_self,
99                        array('action'=>'rate')
100                      ),
101          'USER_RATE'=> $user_rate,
102          'marks'    => $conf['rate_items']
103        )
104      );
105  }
106}
107
108?>
Note: See TracBrowser for help on using the repository browser.