source: trunk/admin/rating.php @ 2223

Last change on this file since 2223 was 2223, checked in by rvelices, 16 years ago
  • migrate many templates to smarty
  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 7.7 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: rating.php 2223 2008-02-28 02:41:48Z rvelices $
8// | last update   : $Date: 2008-02-28 02:41:48 +0000 (Thu, 28 Feb 2008) $
9// | last modifier : $Author: rvelices $
10// | revision      : $Revision: 2223 $
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
27if (!defined('PHPWG_ROOT_PATH'))
28{
29  die ("Hacking attempt!");
30}
31
32include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
33
34// +-----------------------------------------------------------------------+
35// | Check Access and exit when user status is not ok                      |
36// +-----------------------------------------------------------------------+
37check_status(ACCESS_ADMINISTRATOR);
38
39// +-----------------------------------------------------------------------+
40// |                            initialization                             |
41// +-----------------------------------------------------------------------+
42if (isset($_GET['start']) and is_numeric($_GET['start']))
43{
44  $start = $_GET['start'];
45}
46else
47{
48  $start = 0;
49}
50
51$elements_per_page=10;
52if (isset($_GET['display']) and is_numeric($_GET['display']))
53{
54  $elements_per_page = $_GET['display'];
55}
56
57$order_by_index=0;
58if (isset($_GET['order_by']) and is_numeric($_GET['order_by']))
59{
60  $order_by_index = $_GET['order_by'];
61}
62
63$page['user_filter'] = '';
64if (isset($_GET['users']))
65{
66  if ($_GET['users'] == 'user')
67  {
68    $page['user_filter'] = ' AND r.user_id <> '.$conf['guest_id'];
69  }
70  elseif ($_GET['users'] == 'guest')
71  {
72    $page['user_filter'] = ' AND r.user_id = '.$conf['guest_id'];
73  }
74}
75
76if (isset($_GET['del']) and !is_adviser())
77{
78  $del_params = urldecode( $_GET['del'] );
79  parse_str($del_params, $vars);
80  if ( !is_numeric($vars['e']) or !is_numeric($vars['u']) )
81  {
82    die('Hacking attempt');
83  }
84  $query = '
85DELETE FROM '. RATE_TABLE .'
86WHERE element_id=' . $vars['e'] . '
87AND user_id=' . $vars['u'] . '
88AND anonymous_id=\'' . $vars['a'] . '\'
89;';
90  pwg_query($query);
91  update_average_rate( $vars['e'] );
92}
93
94$users = array();
95$query = '
96SELECT '.$conf['user_fields']['username'].' as username, '.$conf['user_fields']['id'].' as id
97  FROM '.USERS_TABLE.'
98;';
99$result = pwg_query($query);
100while ($row = mysql_fetch_array($result))
101{
102  $users[$row['id']]=$row['username'];
103}
104
105
106$query = 'SELECT COUNT(DISTINCT(i.id))
107FROM '.RATE_TABLE.' AS r, '.IMAGES_TABLE.' AS i
108WHERE r.element_id=i.id'. $page['user_filter'] .
109';';
110list($nb_images) = mysql_fetch_row(pwg_query($query));
111
112
113// +-----------------------------------------------------------------------+
114// |                             template init                             |
115// +-----------------------------------------------------------------------+
116
117$template->set_filename('rating', 'admin/rating.tpl');
118
119$template->assign(
120  array(
121    'NAVBAR' => create_navigation_bar(
122      PHPWG_ROOT_PATH.'admin.php'.get_query_string_diff(array('start','del')),
123      $nb_images,
124      $start,
125      $elements_per_page
126      ),
127    'F_ACTION' => PHPWG_ROOT_PATH.'admin.php',
128    'DISPLAY' => $elements_per_page,
129    'NB_ELEMENTS' => $nb_images,
130    )
131  );
132
133
134
135$available_order_by= array(
136    array(l10n('Rate date'), 'recently_rated DESC'),
137    array(l10n('Average rate'), 'average_rate DESC'),
138    array(l10n('Number of rates'), 'nb_rates DESC'),
139    array(l10n('Sum of rates'), 'sum_rates DESC'),
140    array(l10n('Controversy'), 'std_rates DESC'),
141    array(l10n('File name'), 'file DESC'),
142    array(l10n('Creation date'), 'date_creation DESC'),
143    array(l10n('Post date'), 'date_available DESC'),
144
145  );
146
147for ($i=0; $i<count($available_order_by); $i++)
148{
149  $template->append(
150    'order_by_options',
151    $available_order_by[$i][0]
152    );
153}
154$template->assign('order_by_options_selected', array($order_by_index) );
155
156
157$user_options = array(
158  'all'   => l10n('all'),
159  'user'  => l10n('Users'),
160  'guest' => l10n('Guests'),
161  );
162
163$template->assign('user_options', $user_options );
164$template->assign('user_options_selected', array(@$_GET['users']) );
165
166
167$query = '
168SELECT i.id,
169       i.path,
170       i.file,
171       i.tn_ext,
172       i.average_rate,
173       i.storage_category_id,
174       MAX(r.date)          AS recently_rated,
175       COUNT(r.rate)        AS nb_rates,
176       SUM(r.rate)          AS sum_rates,
177       ROUND(STD(r.rate),2) AS std_rates
178  FROM '.RATE_TABLE.' AS r
179    LEFT JOIN '.IMAGES_TABLE.' AS i ON r.element_id = i.id
180  WHERE 1 = 1 ' . $page['user_filter'] . '
181  GROUP BY r.element_id
182  ORDER BY ' . $available_order_by[$order_by_index][1] .'
183  LIMIT '.$start.','.$elements_per_page.'
184;';
185
186$images = array();
187$result = pwg_query($query);
188while ($row = mysql_fetch_assoc($result))
189{
190  array_push($images, $row);
191}
192
193$template->assign( 'images', array() );
194foreach ($images as $image)
195{
196  $thumbnail_src = get_thumbnail_url($image);
197
198  $image_url = PHPWG_ROOT_PATH.'admin.php?page=picture_modify'.
199            '&amp;image_id='.$image['id'];
200
201  $query = 'SELECT *
202FROM '.RATE_TABLE.' AS r
203WHERE r.element_id='.$image['id'] . '
204ORDER BY date DESC;';
205  $result = pwg_query($query);
206  $nb_rates = mysql_num_rows($result);
207
208  $tpl_image = 
209     array(
210       'U_THUMB' => $thumbnail_src,
211       'U_URL' => $image_url,
212       'AVG_RATE' => $image['average_rate'],
213       'STD_RATE' => $image['std_rates'],
214       'SUM_RATE' => $image['sum_rates'],
215       'NB_RATES' => (int)$image['nb_rates'],
216       'NB_RATES_TOTAL' => (int)$nb_rates,
217       'FILE' => $image['file'],
218       'rates'  => array()
219   );
220
221  while ($row = mysql_fetch_array($result))
222  {
223
224    $url_del = PHPWG_ROOT_PATH.'admin.php'.
225                get_query_string_diff(array('del'));
226
227    $del_param = 'e='.$image['id'].
228                 '&u='.$row['user_id'].
229                 '&a='.$row['anonymous_id'];
230
231    $url_del .= '&amp;del='.urlencode(urlencode($del_param));
232
233    if ( isset($users[$row['user_id']]) )
234    {
235      $user = $users[$row['user_id']];
236    }
237    else
238    {
239      $user = '? '. $row['user_id'];
240    }
241    if ( strlen($row['anonymous_id'])>0 )
242    {
243      $user .= '('.$row['anonymous_id'].')';
244    }
245
246    $tpl_image['rates'][] =
247       array(
248         'DATE' => format_date($row['date']),
249         'RATE' => $row['rate'],
250         'USER' => $user,
251         'U_DELETE' => $url_del
252     );
253  }
254  $template->append( 'images', $tpl_image );
255}
256
257// +-----------------------------------------------------------------------+
258// |                           sending html code                           |
259// +-----------------------------------------------------------------------+
260$template->assign_var_from_handle('ADMIN_CONTENT', 'rating');
261?>
Note: See TracBrowser for help on using the repository browser.