source: trunk/admin/rating.php @ 2297

Last change on this file since 2297 was 2297, checked in by plg, 16 years ago

Modification: new header on PHP files, PhpWebGallery renamed Piwigo.

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 9.3 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based picture gallery                                  |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008      Piwigo Team                  http://piwigo.org |
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// +-----------------------------------------------------------------------+
23// +-----------------------------------------------------------------------+
24// | PhpWebGallery - a PHP based picture gallery                           |
25// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
26// | Copyright (C) 2003-2008 PhpWebGallery Team - http://phpwebgallery.net |
27// +-----------------------------------------------------------------------+
28// | file          : $Id: rating.php 2297 2008-04-04 22:57:23Z plg $
29// | last update   : $Date: 2008-04-04 22:57:23 +0000 (Fri, 04 Apr 2008) $
30// | last modifier : $Author: plg $
31// | revision      : $Revision: 2297 $
32// +-----------------------------------------------------------------------+
33// | This program is free software; you can redistribute it and/or modify  |
34// | it under the terms of the GNU General Public License as published by  |
35// | the Free Software Foundation                                          |
36// |                                                                       |
37// | This program is distributed in the hope that it will be useful, but   |
38// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
39// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
40// | General Public License for more details.                              |
41// |                                                                       |
42// | You should have received a copy of the GNU General Public License     |
43// | along with this program; if not, write to the Free Software           |
44// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
45// | USA.                                                                  |
46// +-----------------------------------------------------------------------+
47
48if (!defined('PHPWG_ROOT_PATH'))
49{
50  die ("Hacking attempt!");
51}
52
53include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
54
55// +-----------------------------------------------------------------------+
56// | Check Access and exit when user status is not ok                      |
57// +-----------------------------------------------------------------------+
58check_status(ACCESS_ADMINISTRATOR);
59
60// +-----------------------------------------------------------------------+
61// |                            initialization                             |
62// +-----------------------------------------------------------------------+
63if (isset($_GET['start']) and is_numeric($_GET['start']))
64{
65  $start = $_GET['start'];
66}
67else
68{
69  $start = 0;
70}
71
72$elements_per_page=10;
73if (isset($_GET['display']) and is_numeric($_GET['display']))
74{
75  $elements_per_page = $_GET['display'];
76}
77
78$order_by_index=0;
79if (isset($_GET['order_by']) and is_numeric($_GET['order_by']))
80{
81  $order_by_index = $_GET['order_by'];
82}
83
84$page['user_filter'] = '';
85if (isset($_GET['users']))
86{
87  if ($_GET['users'] == 'user')
88  {
89    $page['user_filter'] = ' AND r.user_id <> '.$conf['guest_id'];
90  }
91  elseif ($_GET['users'] == 'guest')
92  {
93    $page['user_filter'] = ' AND r.user_id = '.$conf['guest_id'];
94  }
95}
96
97if (isset($_GET['del']) and !is_adviser())
98{
99  $del_params = urldecode( $_GET['del'] );
100  parse_str($del_params, $vars);
101  if ( !is_numeric($vars['e']) or !is_numeric($vars['u']) )
102  {
103    die('Hacking attempt');
104  }
105  $query = '
106DELETE FROM '. RATE_TABLE .'
107WHERE element_id=' . $vars['e'] . '
108AND user_id=' . $vars['u'] . '
109AND anonymous_id=\'' . $vars['a'] . '\'
110;';
111  pwg_query($query);
112  update_average_rate( $vars['e'] );
113}
114
115$users = array();
116$query = '
117SELECT '.$conf['user_fields']['username'].' as username, '.$conf['user_fields']['id'].' as id
118  FROM '.USERS_TABLE.'
119;';
120$result = pwg_query($query);
121while ($row = mysql_fetch_array($result))
122{
123  $users[$row['id']]=$row['username'];
124}
125
126
127$query = 'SELECT COUNT(DISTINCT(i.id))
128FROM '.RATE_TABLE.' AS r, '.IMAGES_TABLE.' AS i
129WHERE r.element_id=i.id'. $page['user_filter'] .
130';';
131list($nb_images) = mysql_fetch_row(pwg_query($query));
132
133
134// +-----------------------------------------------------------------------+
135// |                             template init                             |
136// +-----------------------------------------------------------------------+
137
138$template->set_filename('rating', 'admin/rating.tpl');
139
140$template->assign(
141  array(
142    'NAVBAR' => create_navigation_bar(
143      PHPWG_ROOT_PATH.'admin.php'.get_query_string_diff(array('start','del')),
144      $nb_images,
145      $start,
146      $elements_per_page
147      ),
148    'F_ACTION' => PHPWG_ROOT_PATH.'admin.php',
149    'DISPLAY' => $elements_per_page,
150    'NB_ELEMENTS' => $nb_images,
151    )
152  );
153
154
155
156$available_order_by= array(
157    array(l10n('Rate date'), 'recently_rated DESC'),
158    array(l10n('Average rate'), 'average_rate DESC'),
159    array(l10n('Number of rates'), 'nb_rates DESC'),
160    array(l10n('Sum of rates'), 'sum_rates DESC'),
161    array(l10n('Controversy'), 'std_rates DESC'),
162    array(l10n('File name'), 'file DESC'),
163    array(l10n('Creation date'), 'date_creation DESC'),
164    array(l10n('Post date'), 'date_available DESC'),
165
166  );
167
168for ($i=0; $i<count($available_order_by); $i++)
169{
170  $template->append(
171    'order_by_options',
172    $available_order_by[$i][0]
173    );
174}
175$template->assign('order_by_options_selected', array($order_by_index) );
176
177
178$user_options = array(
179  'all'   => l10n('all'),
180  'user'  => l10n('Users'),
181  'guest' => l10n('Guests'),
182  );
183
184$template->assign('user_options', $user_options );
185$template->assign('user_options_selected', array(@$_GET['users']) );
186
187
188$query = '
189SELECT i.id,
190       i.path,
191       i.file,
192       i.tn_ext,
193       i.average_rate,
194       i.storage_category_id,
195       MAX(r.date)          AS recently_rated,
196       COUNT(r.rate)        AS nb_rates,
197       SUM(r.rate)          AS sum_rates,
198       ROUND(STD(r.rate),2) AS std_rates
199  FROM '.RATE_TABLE.' AS r
200    LEFT JOIN '.IMAGES_TABLE.' AS i ON r.element_id = i.id
201  WHERE 1 = 1 ' . $page['user_filter'] . '
202  GROUP BY r.element_id
203  ORDER BY ' . $available_order_by[$order_by_index][1] .'
204  LIMIT '.$start.','.$elements_per_page.'
205;';
206
207$images = array();
208$result = pwg_query($query);
209while ($row = mysql_fetch_assoc($result))
210{
211  array_push($images, $row);
212}
213
214$template->assign( 'images', array() );
215foreach ($images as $image)
216{
217  $thumbnail_src = get_thumbnail_url($image);
218
219  $image_url = PHPWG_ROOT_PATH.'admin.php?page=picture_modify'.
220            '&amp;image_id='.$image['id'];
221
222  $query = 'SELECT *
223FROM '.RATE_TABLE.' AS r
224WHERE r.element_id='.$image['id'] . '
225ORDER BY date DESC;';
226  $result = pwg_query($query);
227  $nb_rates = mysql_num_rows($result);
228
229  $tpl_image = 
230     array(
231       'U_THUMB' => $thumbnail_src,
232       'U_URL' => $image_url,
233       'AVG_RATE' => $image['average_rate'],
234       'STD_RATE' => $image['std_rates'],
235       'SUM_RATE' => $image['sum_rates'],
236       'NB_RATES' => (int)$image['nb_rates'],
237       'NB_RATES_TOTAL' => (int)$nb_rates,
238       'FILE' => $image['file'],
239       'rates'  => array()
240   );
241
242  while ($row = mysql_fetch_array($result))
243  {
244
245    $url_del = PHPWG_ROOT_PATH.'admin.php'.
246                get_query_string_diff(array('del'));
247
248    $del_param = 'e='.$image['id'].
249                 '&u='.$row['user_id'].
250                 '&a='.$row['anonymous_id'];
251
252    $url_del .= '&amp;del='.urlencode(urlencode($del_param));
253
254    if ( isset($users[$row['user_id']]) )
255    {
256      $user = $users[$row['user_id']];
257    }
258    else
259    {
260      $user = '? '. $row['user_id'];
261    }
262    if ( strlen($row['anonymous_id'])>0 )
263    {
264      $user .= '('.$row['anonymous_id'].')';
265    }
266
267    $tpl_image['rates'][] =
268       array(
269         'DATE' => format_date($row['date']),
270         'RATE' => $row['rate'],
271         'USER' => $user,
272         'U_DELETE' => $url_del
273     );
274  }
275  $template->append( 'images', $tpl_image );
276}
277
278// +-----------------------------------------------------------------------+
279// |                           sending html code                           |
280// +-----------------------------------------------------------------------+
281$template->assign_var_from_handle('ADMIN_CONTENT', 'rating');
282?>
Note: See TracBrowser for help on using the repository browser.