source: trunk/admin/rating.php @ 1072

Last change on this file since 1072 was 1072, checked in by rub, 18 years ago

Step 2 improvement issue 0000301:

o Add and use Functions Check of status
o Restricted Access for user generic

  • Property svn:eol-style set to native
File size: 8.4 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$navbar = create_navigation_bar(
136           PHPWG_ROOT_PATH.'admin.php'.get_query_string_diff(array('start','del')),
137                                $nb_images,
138                                $start,
139                                $elements_per_page,
140                                '');
141$template->assign_vars(array('NAVBAR' => $navbar));
142
143
144$template->assign_vars(
145  array(
146    'F_ACTION' => PHPWG_ROOT_PATH.'admin.php',
147    'DISPLAY' => $elements_per_page,
148    'NB_ELEMENTS' => $nb_images
149    )
150  );
151
152$available_order_by= array(
153    array(l10n('Rate date'), 'recently_rated DESC'),
154    array(l10n('Average rate'), 'average_rate DESC'),
155    array(l10n('Number of rates'), 'nb_rates DESC'),
156    array(l10n('Sum of rates'), 'sum_rates DESC'),
157    array(l10n('Controversy'), 'std_rates DESC'),
158    array(l10n('File name'), 'file DESC'),
159    array(l10n('Creation date'), 'date_creation DESC'),
160    array(l10n('Post date'), 'date_available DESC'),
161
162  );
163
164for ($i=0; $i<count($available_order_by); $i++)
165{
166  $template->assign_block_vars(
167    'order_by',
168    array(
169      'VALUE' => $i,
170      'CONTENT' => $available_order_by[$i][0],
171      'SELECTED' => $i==$order_by_index ? 'SELECTED' : ''
172      )
173    );
174}
175
176$query = '
177SELECT i.id,
178       i.path,
179       i.file,
180       i.tn_ext,
181       i.average_rate,
182       MAX(r.date)          AS recently_rated,
183       COUNT(r.rate)        AS nb_rates,
184       SUM(r.rate)          AS sum_rates,
185       ROUND(STD(r.rate),2) AS std_rates,
186       ic.category_id       AS storage_category_id
187  FROM '.RATE_TABLE.' AS r
188    LEFT JOIN '.IMAGES_TABLE.' AS i ON r.element_id = i.id
189    INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON ic.image_id = i.id
190  WHERE 1 = 1 ' . $display_filter . '
191    AND ic.is_storage = \'true\'
192  GROUP BY r.element_id
193  ORDER BY ' . $available_order_by[$order_by_index][1] .'
194  LIMIT '.$start.','.$elements_per_page.'
195;';
196
197$images = array();
198$result = pwg_query($query);
199while ($row = mysql_fetch_array($result))
200{
201  array_push($images, $row);
202}
203
204foreach ($images as $image)
205{
206  $thumbnail_src = get_thumbnail_src($image['path'], $image['tn_ext']);
207
208  $image_url =
209    PHPWG_ROOT_PATH.'picture.php?'.
210    'cat=' . $image['storage_category_id'].
211    '&amp;image_id=' . $image['id']
212    ;
213
214  $query = 'SELECT *
215FROM '.RATE_TABLE.' AS r
216WHERE r.element_id='.$image['id'] . '
217ORDER BY date DESC;';
218  $result = pwg_query($query);
219  $nb_rates = mysql_num_rows($result);
220
221  $template->assign_block_vars('image',
222     array(
223       'U_THUMB' => $thumbnail_src,
224       'U_URL' => $image_url,
225       'AVG_RATE' => $image['average_rate'],
226       'STD_RATE' => $image['std_rates'],
227       'SUM_RATE' => $image['sum_rates'],
228       'NB_RATES' =>  $image['nb_rates'],
229       'NB_RATES_TOTAL' =>  $nb_rates,
230       'FILE' => $image['file'],
231       'NB_RATES_PLUS1' => $nb_rates+1,
232     )
233   );
234
235  while ($row = mysql_fetch_array($result))
236  {
237
238    $url_del = PHPWG_ROOT_PATH.'admin.php'.
239                get_query_string_diff(array('del'));
240
241    $del_param = 'e='.$image['id'].
242                 '&u='.$row['user_id'].
243                 '&a='.$row['anonymous_id'];
244
245    $url_del .= '&amp;del='.urlencode(urlencode($del_param));
246
247    if ( isset($users[$row['user_id']]) )
248    {
249      $user = $users[$row['user_id']];
250    }
251    else
252    {
253      $user = '? '. $row['user_id'];
254    }
255    if ( strlen($row['anonymous_id'])>0 )
256    {
257      $user .= '('.$row['anonymous_id'].')';
258    }
259
260    $template->assign_block_vars('image.rate',
261       array(
262         'DATE' => format_date($row['date']),
263         'RATE' => $row['rate'],
264         'USER' => $user,
265         'U_DELETE' => $url_del
266       )
267     );
268  }
269}
270//print_r($template->_tpldata);
271// +-----------------------------------------------------------------------+
272// |                           sending html code                           |
273// +-----------------------------------------------------------------------+
274$template->assign_var_from_handle('ADMIN_CONTENT', 'rating');
275?>
Note: See TracBrowser for help on using the repository browser.