source: trunk/admin/rating.php @ 1156

Last change on this file since 1156 was 1121, checked in by plg, 19 years ago

feature deleted: code for categories link was too complicated for such a
simple fature. Replaced by static association. Links are not persistent
anymore.

modification removed: #image_category.is_storage replaced by
#images.storage_category_id as in branche 1.5..

  • Property svn:eol-style set to native
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-2006 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $RCSfile$
9// | last update   : $Date: 2006-01-15 08:45:42 -0500 (Sun, 15 Jan 2006) $
10// | last modifier : $Author: nikrou $
11// | revision      : $Revision: 1004 $
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$display_filter= '';
65if (isset($_GET['display_filter']))
66{
67  if ( $_GET['display_filter']=='user' )
68  {
69    $display_filter= ' AND r.user_id <> ' . $conf['guest_id'];
70    $template->assign_vars( array(
71        'DISPLAY_FILTER_USER_CHECKED'=>'checked="checked"'
72        )
73    );
74  }
75  elseif ( $_GET['display_filter']=='guest' )
76  {
77    $display_filter= ' AND r.user_id =' . $conf['guest_id'];
78    $template->assign_vars( array(
79        'DISPLAY_FILTER_GUEST_CHECKED'=>'checked="checked"'
80        )
81     );
82  }
83}
84if ($display_filter=='')
85{
86    $template->assign_vars( array(
87        'DISPLAY_FILTER_ALL_CHECKED'=>'checked="checked"'
88        )
89     );
90}
91
92if (isset($_GET['del']))
93{
94  $del_params = urldecode( $_GET['del'] );
95  parse_str($del_params, $vars);
96  if ( !is_numeric($vars['e']) or !is_numeric($vars['u']) )
97  {
98    die('Hacking attempt');
99  }
100  $query = '
101DELETE FROM '. RATE_TABLE .'
102WHERE element_id=' . $vars['e'] . '
103AND user_id=' . $vars['u'] . '
104AND anonymous_id=\'' . $vars['a'] . '\'
105;';
106  pwg_query($query);
107  update_average_rate( $vars['e'] );
108}
109
110$users = array();
111$query = '
112SELECT '.$conf['user_fields']['username'].' as username, '.$conf['user_fields']['id'].' as id
113  FROM '.USERS_TABLE.'
114;';
115$result = pwg_query($query);
116while ($row = mysql_fetch_array($result))
117{
118  $users[$row['id']]=$row['username'];
119}
120
121
122$query = 'SELECT COUNT(DISTINCT(i.id))
123FROM '.RATE_TABLE.' AS r, '.IMAGES_TABLE.' AS i
124WHERE r.element_id=i.id'. $display_filter .
125';';
126list($nb_images) = mysql_fetch_row(pwg_query($query));
127
128
129// +-----------------------------------------------------------------------+
130// |                             template init                             |
131// +-----------------------------------------------------------------------+
132
133$template->set_filenames(array('rating'=>'admin/rating.tpl'));
134
135$template->assign_vars(
136  array(
137    'NAVBAR' => create_navigation_bar(
138      PHPWG_ROOT_PATH.'admin.php'.get_query_string_diff(array('start','del')),
139      $nb_images,
140      $start,
141      $elements_per_page
142      )
143    )
144  );
145
146
147$template->assign_vars(
148  array(
149    'F_ACTION' => PHPWG_ROOT_PATH.'admin.php',
150    'DISPLAY' => $elements_per_page,
151    'NB_ELEMENTS' => $nb_images
152    )
153  );
154
155$available_order_by= array(
156    array(l10n('Rate date'), 'recently_rated DESC'),
157    array(l10n('Average rate'), 'average_rate DESC'),
158    array(l10n('Number of rates'), 'nb_rates DESC'),
159    array(l10n('Sum of rates'), 'sum_rates DESC'),
160    array(l10n('Controversy'), 'std_rates DESC'),
161    array(l10n('File name'), 'file DESC'),
162    array(l10n('Creation date'), 'date_creation DESC'),
163    array(l10n('Post date'), 'date_available DESC'),
164
165  );
166
167for ($i=0; $i<count($available_order_by); $i++)
168{
169  $template->assign_block_vars(
170    'order_by',
171    array(
172      'VALUE' => $i,
173      'CONTENT' => $available_order_by[$i][0],
174      'SELECTED' => $i==$order_by_index ? 'SELECTED' : ''
175      )
176    );
177}
178
179$query = '
180SELECT i.id,
181       i.path,
182       i.file,
183       i.tn_ext,
184       i.average_rate,
185       i.storage_category_id,
186       MAX(r.date)          AS recently_rated,
187       COUNT(r.rate)        AS nb_rates,
188       SUM(r.rate)          AS sum_rates,
189       ROUND(STD(r.rate),2) AS std_rates
190  FROM '.RATE_TABLE.' AS r
191    LEFT JOIN '.IMAGES_TABLE.' AS i ON r.element_id = i.id
192  WHERE 1 = 1 ' . $display_filter . '
193  GROUP BY r.element_id
194  ORDER BY ' . $available_order_by[$order_by_index][1] .'
195  LIMIT '.$start.','.$elements_per_page.'
196;';
197
198$images = array();
199$result = pwg_query($query);
200while ($row = mysql_fetch_array($result))
201{
202  array_push($images, $row);
203}
204
205foreach ($images as $image)
206{
207  $thumbnail_src = get_thumbnail_src($image['path'], $image['tn_ext']);
208
209  $image_url = make_picture_url(
210      array(
211        'category' => $image['storage_category_id'],
212        'image_id' => $image['id'],
213        'image_file' => $image['file'],
214      )
215    );
216
217  $query = 'SELECT *
218FROM '.RATE_TABLE.' AS r
219WHERE r.element_id='.$image['id'] . '
220ORDER BY date DESC;';
221  $result = pwg_query($query);
222  $nb_rates = mysql_num_rows($result);
223
224  $template->assign_block_vars('image',
225     array(
226       'U_THUMB' => $thumbnail_src,
227       'U_URL' => $image_url,
228       'AVG_RATE' => $image['average_rate'],
229       'STD_RATE' => $image['std_rates'],
230       'SUM_RATE' => $image['sum_rates'],
231       'NB_RATES' =>  $image['nb_rates'],
232       'NB_RATES_TOTAL' =>  $nb_rates,
233       'FILE' => $image['file'],
234       'NB_RATES_PLUS1' => $nb_rates+1,
235     )
236   );
237
238  while ($row = mysql_fetch_array($result))
239  {
240
241    $url_del = PHPWG_ROOT_PATH.'admin.php'.
242                get_query_string_diff(array('del'));
243
244    $del_param = 'e='.$image['id'].
245                 '&u='.$row['user_id'].
246                 '&a='.$row['anonymous_id'];
247
248    $url_del .= '&amp;del='.urlencode(urlencode($del_param));
249
250    if ( isset($users[$row['user_id']]) )
251    {
252      $user = $users[$row['user_id']];
253    }
254    else
255    {
256      $user = '? '. $row['user_id'];
257    }
258    if ( strlen($row['anonymous_id'])>0 )
259    {
260      $user .= '('.$row['anonymous_id'].')';
261    }
262
263    $template->assign_block_vars('image.rate',
264       array(
265         'DATE' => format_date($row['date']),
266         'RATE' => $row['rate'],
267         'USER' => $user,
268         'U_DELETE' => $url_del
269       )
270     );
271  }
272}
273//print_r($template->_tpldata);
274// +-----------------------------------------------------------------------+
275// |                           sending html code                           |
276// +-----------------------------------------------------------------------+
277$template->assign_var_from_handle('ADMIN_CONTENT', 'rating');
278?>
Note: See TracBrowser for help on using the repository browser.