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

Last change on this file since 1094 was 1094, checked in by rvelices, 19 years ago

URL rewrite: 3 options in the config file define behaviour (question mark
removal, file name for picture and .php extension removal)

fix: added unsigned for column in install sql - for the sake of uniformization

change: add_url_param is now add_url_params and takes an array as parameter
instead of a string

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.0 KB
RevLine 
[1082]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-2005 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $RCSfile$
[1092]9// | last update   : $Date: 2006-03-23 01:49:04 +0000 (Thu, 23 Mar 2006) $
10// | last modifier : $Author: rvelices $
11// | revision      : $Revision: 1094 $
[1082]12// +-----------------------------------------------------------------------+
13// | This program is free software; you can redistribute it and/or modify  |
14// | it under the terms of the GNU General Public License as published by  |
15// | the Free Software Foundation                                          |
16// |                                                                       |
17// | This program is distributed in the hope that it will be useful, but   |
18// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
19// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
20// | General Public License for more details.                              |
21// |                                                                       |
22// | You should have received a copy of the GNU General Public License     |
23// | along with this program; if not, write to the Free Software           |
24// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
25// | USA.                                                                  |
26// +-----------------------------------------------------------------------+
27
28/**
29 * This file is included by the picture page to manage rates
[1090]30 *
[1082]31 */
32
33if ($conf['rate'])
34{
35  $query = '
36SELECT COUNT(rate) AS count
37     , ROUND(AVG(rate),2) AS average
38     , ROUND(STD(rate),2) AS STD
39  FROM '.RATE_TABLE.'
40  WHERE element_id = '.$picture['current']['id'].'
41;';
42  $row = mysql_fetch_array(pwg_query($query));
43  if ($row['count'] == 0)
44  {
45    $value = $lang['no_rate'];
46  }
47  else
48  {
49    $value = sprintf(
50      l10n('%.2f (rated %d times, standard deviation = %.2f)'),
51      $row['average'],
52      $row['count'],
53      $row['STD']
54      );
55  }
56
[1092]57  if ($conf['rate_anonymous'] or is_autorize_status(ACCESS_CLASSIC) )
[1082]58  {
59    if ($row['count']>0)
60    {
61      $query = 'SELECT rate
62      FROM '.RATE_TABLE.'
63      WHERE element_id = '.$page['image_id'] . '
64      AND user_id = '.$user['id'] ;
65
[1092]66      if ( !is_autorize_status(ACCESS_CLASSIC) )
[1082]67      {
68        $ip_components = explode('.', $_SERVER['REMOTE_ADDR']);
69        if ( count($ip_components)>3 )
70        {
71          array_pop($ip_components);
72        }
73        $anonymous_id = implode ('.', $ip_components);
74        $query .= ' AND anonymous_id = \''.$anonymous_id . '\'';
75      }
76
77      $result = pwg_query($query);
78      if (mysql_num_rows($result) > 0)
79      {
80        $row = mysql_fetch_array($result);
81        $sentence = $lang['already_rated'];
82        $sentence.= ' ('.$row['rate'].'). ';
83        $sentence.= $lang['update_rate'];
84      }
85      else
86      {
87        $sentence = $lang['never_rated'].'. '.$lang['Rate'];
88      }
89    }
90    else
91    {
92      $sentence = $lang['never_rated'].'. '.$lang['Rate'];
93    }
94    $template->assign_block_vars(
95      'rate',
96      array(
97        'CONTENT' => $value,
98        'SENTENCE' => $sentence
99        )
100      );
101
102    $template->assign_block_vars('info_rate', array('CONTENT' => $value));
103
104    $template->assign_vars(
105      array(
106        'INFO_RATE' => $value
107        )
108      );
109
[1084]110    foreach ($conf['rate_items'] as $num => $mark)
[1082]111    {
112      $template->assign_block_vars(
113        'rate.rate_option',
114        array(
115          'OPTION'    => $mark,
[1094]116          'URL'       => add_url_params(
117                          $url_self,
118                          array(
119                            'action'=>'rate',
120                            'rate'=>$mark
121                          )
122                        ),
[1082]123          'SEPARATOR' => ($num > 0 ? '|' : ''),
124          )
125        );
126    }
127  }
128}
129
130?>
Note: See TracBrowser for help on using the repository browser.