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

Last change on this file since 1900 was 1900, checked in by rub, 17 years ago

Apply property svn:eol-style Value: LF

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 3.9 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-2005 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $RCSfile$
9// | last update   : $Date: 2007-03-12 22:33:53 +0000 (Mon, 12 Mar 2007) $
10// | last modifier : $Author: rub $
11// | revision      : $Revision: 1900 $
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
30 *
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
57  $user_rate = null;
58  if ($conf['rate_anonymous'] or is_autorize_status(ACCESS_CLASSIC) )
59  {
60    if ($row['count']>0)
61    {
62      $query = 'SELECT rate
63      FROM '.RATE_TABLE.'
64      WHERE element_id = '.$page['image_id'] . '
65      AND user_id = '.$user['id'] ;
66
67      if ( !is_autorize_status(ACCESS_CLASSIC) )
68      {
69        $ip_components = explode('.', $_SERVER['REMOTE_ADDR']);
70        if ( count($ip_components)>3 )
71        {
72          array_pop($ip_components);
73        }
74        $anonymous_id = implode ('.', $ip_components);
75        $query .= ' AND anonymous_id = \''.$anonymous_id . '\'';
76      }
77
78      $result = pwg_query($query);
79      if (mysql_num_rows($result) > 0)
80      {
81        $row = mysql_fetch_array($result);
82        $user_rate = $row['rate'];
83      }
84    }
85
86    $template->assign_block_vars(
87      'rate',
88      array(
89        'SENTENCE' =>isset($user_rate) ? l10n('update_rate') : l10n('new_rate'),
90        'F_ACTION' => add_url_params(
91                        $url_self,
92                        array('action'=>'rate')
93                      )
94        )
95      );
96
97    $template->assign_block_vars('info_rate', array('CONTENT' => $value));
98
99    foreach ($conf['rate_items'] as $num => $mark)
100    {
101      $template->assign_block_vars(
102        'rate.rate_option',
103        array(
104          'OPTION'    => $mark,
105          'SEPARATOR' => ($num > 0 ? '|' : ''),
106          )
107        );
108      if (isset($user_rate) and $user_rate==$mark)
109      {
110        $template->assign_block_vars('rate.rate_option.my_rate', array() );
111      }
112      else
113      {
114        $template->assign_block_vars('rate.rate_option.not_my_rate', array() );
115      }
116    }
117  }
118}
119
120?>
Note: See TracBrowser for help on using the repository browser.