source: trunk/admin/rating.php @ 1912

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

Update svn properties (svn:eol-style and svn:keywords)

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