source: branches/2.0/include/picture_rate.inc.php @ 12495

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

Administration: happy new year 2009, all PHP headers updated.

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 3.2 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based picture gallery                                  |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2009 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/**
25 * This file is included by the picture page to manage rates
26 *
27 */
28
29if ($conf['rate'])
30{
31  if ( NULL != $picture['current']['average_rate'] )
32  {
33    $query = '
34SELECT COUNT(rate) AS count
35     , ROUND(AVG(rate),2) AS average
36     , ROUND(STD(rate),2) AS std
37  FROM '.RATE_TABLE.'
38  WHERE element_id = '.$picture['current']['id'].'
39;';
40    $row = mysql_fetch_array(pwg_query($query));
41  }
42  else
43  { // avg rate null -> no rate -> no need to query db
44    $row = array( 'count'=>0, 'average'=>NULL, 'std'=>NULL );
45  }
46  $template->assign('rate_summary', $row);
47
48  $user_rate = null;
49  if ($conf['rate_anonymous'] or is_autorize_status(ACCESS_CLASSIC) )
50  {
51    if ($row['count']>0)
52    {
53      $query = 'SELECT rate
54      FROM '.RATE_TABLE.'
55      WHERE element_id = '.$page['image_id'] . '
56      AND user_id = '.$user['id'] ;
57
58      if ( !is_autorize_status(ACCESS_CLASSIC) )
59      {
60        $ip_components = explode('.', $_SERVER['REMOTE_ADDR']);
61        if ( count($ip_components)>3 )
62        {
63          array_pop($ip_components);
64        }
65        $anonymous_id = implode ('.', $ip_components);
66        $query .= ' AND anonymous_id = \''.$anonymous_id . '\'';
67      }
68
69      $result = pwg_query($query);
70      if (mysql_num_rows($result) > 0)
71      {
72        $row = mysql_fetch_array($result);
73        $user_rate = $row['rate'];
74      }
75    }
76
77    $template->assign(
78        'rating',
79        array(
80          'F_ACTION' => add_url_params(
81                        $url_self,
82                        array('action'=>'rate')
83                      ),
84          'USER_RATE'=> $user_rate,
85          'marks'    => $conf['rate_items']
86        )
87      );
88  }
89}
90
91?>
Note: See TracBrowser for help on using the repository browser.