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

Last change on this file since 15174 was 12922, checked in by mistic100, 13 years ago

update Piwigo headers to 2012, last change before the expected (or not) apocalypse

  • Property svn:eol-style set to LF
File size: 3.2 KB
RevLine 
[1082]1<?php
2// +-----------------------------------------------------------------------+
[8728]3// | Piwigo - a PHP based photo gallery                                    |
[2297]4// +-----------------------------------------------------------------------+
[12922]5// | Copyright(C) 2008-2012 Piwigo Team                  http://piwigo.org |
[2297]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// +-----------------------------------------------------------------------+
[1082]23
24/**
25 * This file is included by the picture page to manage rates
[1090]26 *
[1082]27 */
28
29if ($conf['rate'])
30{
[11893]31  $rate_summary = array( 'count'=>0, 'score'=>$picture['current']['rating_score'], 'average'=>null );
[11827]32  if ( NULL != $rate_summary['score'] )
[2309]33  {
34    $query = '
[1082]35SELECT COUNT(rate) AS count
36     , ROUND(AVG(rate),2) AS average
37  FROM '.RATE_TABLE.'
38  WHERE element_id = '.$picture['current']['id'].'
39;';
[11827]40                list($rate_summary['count'], $rate_summary['average']) = pwg_db_fetch_row(pwg_query($query));
[2309]41  }
[11827]42  $template->assign('rate_summary', $rate_summary);
[1082]43
[1286]44  $user_rate = null;
[1092]45  if ($conf['rate_anonymous'] or is_autorize_status(ACCESS_CLASSIC) )
[1082]46  {
[11827]47    if ($rate_summary['count']>0)
[1082]48    {
49      $query = 'SELECT rate
50      FROM '.RATE_TABLE.'
51      WHERE element_id = '.$page['image_id'] . '
52      AND user_id = '.$user['id'] ;
53
[1092]54      if ( !is_autorize_status(ACCESS_CLASSIC) )
[1082]55      {
56        $ip_components = explode('.', $_SERVER['REMOTE_ADDR']);
57        if ( count($ip_components)>3 )
58        {
59          array_pop($ip_components);
60        }
61        $anonymous_id = implode ('.', $ip_components);
62        $query .= ' AND anonymous_id = \''.$anonymous_id . '\'';
63      }
64
65      $result = pwg_query($query);
[4325]66      if (pwg_db_num_rows($result) > 0)
[1082]67      {
[4325]68        $row = pwg_db_fetch_assoc($result);
[1286]69        $user_rate = $row['rate'];
[1082]70      }
71    }
[1286]72
[2227]73    $template->assign(
74        'rating',
75        array(
76          'F_ACTION' => add_url_params(
[1286]77                        $url_self,
78                        array('action'=>'rate')
[2227]79                      ),
80          'USER_RATE'=> $user_rate,
81          'marks'    => $conf['rate_items']
[1082]82        )
83      );
84  }
85}
86
87?>
Note: See TracBrowser for help on using the repository browser.