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

Last change on this file since 2227 was 2227, checked in by rvelices, 16 years ago

picture, footer and picture modify template migration

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 3.1 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-2008 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | file          : $Id: picture_rate.inc.php 2227 2008-02-29 01:25:13Z rvelices $
8// | last update   : $Date: 2008-02-29 01:25:13 +0000 (Fri, 29 Feb 2008) $
9// | last modifier : $Author: rvelices $
10// | revision      : $Revision: 2227 $
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 * This file is included by the picture page to manage rates
29 *
30 */
31
32if ($conf['rate'])
33{
34  $query = '
35SELECT COUNT(rate) AS count
36     , ROUND(AVG(rate),2) AS average
37     , ROUND(STD(rate),2) AS std
38  FROM '.RATE_TABLE.'
39  WHERE element_id = '.$picture['current']['id'].'
40;';
41  $row = mysql_fetch_array(pwg_query($query));
42  $template->assign('rate_summary', $row);
43
44  $user_rate = null;
45  if ($conf['rate_anonymous'] or is_autorize_status(ACCESS_CLASSIC) )
46  {
47    if ($row['count']>0)
48    {
49      $query = 'SELECT rate
50      FROM '.RATE_TABLE.'
51      WHERE element_id = '.$page['image_id'] . '
52      AND user_id = '.$user['id'] ;
53
54      if ( !is_autorize_status(ACCESS_CLASSIC) )
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);
66      if (mysql_num_rows($result) > 0)
67      {
68        $row = mysql_fetch_array($result);
69        $user_rate = $row['rate'];
70      }
71    }
72
73    $template->assign(
74        'rating',
75        array(
76          'F_ACTION' => add_url_params(
77                        $url_self,
78                        array('action'=>'rate')
79                      ),
80          'USER_RATE'=> $user_rate,
81          'marks'    => $conf['rate_items']
82        )
83      );
84  }
85}
86
87?>
Note: See TracBrowser for help on using the repository browser.