source: trunk/admin/rating.php @ 1090

Last change on this file since 1090 was 1090, checked in by rvelices, 18 years ago

URL rewriting: fix some old links, calendar simplification and prepare code
for urls without ? (added functions get_root_url and add_url_param)

  • Property svn:eol-style set to native
File size: 8.3 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       MAX(r.date)          AS recently_rated,
186       COUNT(r.rate)        AS nb_rates,
187       SUM(r.rate)          AS sum_rates,
188       ROUND(STD(r.rate),2) AS std_rates,
189       ic.category_id       AS storage_category_id
190  FROM '.RATE_TABLE.' AS r
191    LEFT JOIN '.IMAGES_TABLE.' AS i ON r.element_id = i.id
192    INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON ic.image_id = i.id
193  WHERE 1 = 1 ' . $display_filter . '
194    AND ic.is_storage = \'true\'
195  GROUP BY r.element_id
196  ORDER BY ' . $available_order_by[$order_by_index][1] .'
197  LIMIT '.$start.','.$elements_per_page.'
198;';
199
200$images = array();
201$result = pwg_query($query);
202while ($row = mysql_fetch_array($result))
203{
204  array_push($images, $row);
205}
206
207foreach ($images as $image)
208{
209  $thumbnail_src = get_thumbnail_src($image['path'], $image['tn_ext']);
210
211  $image_url = make_picture_url(
212      array(
213        'category' => $image['storage_category_id'],
214        'image_id' => $image['id'],
215        'image_file' => $image['file'],
216      )
217    );
218
219  $query = 'SELECT *
220FROM '.RATE_TABLE.' AS r
221WHERE r.element_id='.$image['id'] . '
222ORDER BY date DESC;';
223  $result = pwg_query($query);
224  $nb_rates = mysql_num_rows($result);
225
226  $template->assign_block_vars('image',
227     array(
228       'U_THUMB' => $thumbnail_src,
229       'U_URL' => $image_url,
230       'AVG_RATE' => $image['average_rate'],
231       'STD_RATE' => $image['std_rates'],
232       'SUM_RATE' => $image['sum_rates'],
233       'NB_RATES' =>  $image['nb_rates'],
234       'NB_RATES_TOTAL' =>  $nb_rates,
235       'FILE' => $image['file'],
236       'NB_RATES_PLUS1' => $nb_rates+1,
237     )
238   );
239
240  while ($row = mysql_fetch_array($result))
241  {
242
243    $url_del = PHPWG_ROOT_PATH.'admin.php'.
244                get_query_string_diff(array('del'));
245
246    $del_param = 'e='.$image['id'].
247                 '&u='.$row['user_id'].
248                 '&a='.$row['anonymous_id'];
249
250    $url_del .= '&amp;del='.urlencode(urlencode($del_param));
251
252    if ( isset($users[$row['user_id']]) )
253    {
254      $user = $users[$row['user_id']];
255    }
256    else
257    {
258      $user = '? '. $row['user_id'];
259    }
260    if ( strlen($row['anonymous_id'])>0 )
261    {
262      $user .= '('.$row['anonymous_id'].')';
263    }
264
265    $template->assign_block_vars('image.rate',
266       array(
267         'DATE' => format_date($row['date']),
268         'RATE' => $row['rate'],
269         'USER' => $user,
270         'U_DELETE' => $url_del
271       )
272     );
273  }
274}
275//print_r($template->_tpldata);
276// +-----------------------------------------------------------------------+
277// |                           sending html code                           |
278// +-----------------------------------------------------------------------+
279$template->assign_var_from_handle('ADMIN_CONTENT', 'rating');
280?>
Note: See TracBrowser for help on using the repository browser.