source: trunk/admin/rating.php @ 1064

Last change on this file since 1064 was 1064, checked in by plg, 18 years ago

new feature: source/destination links between categories. Will we keep this
feature? Code is complicated and very few people will understand how it
works...

modification: #images.storage_category_id replaced by
#image_category.is_storage

improvement: many code refactoring to improve readibility

improvement: virtual category creation code was moved to a dedicated
function in order to be called from admin/cat_list.php and
admin/cat_modify.php (create a new destination category)

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