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 | |
---|
28 | if (!defined('PHPWG_ROOT_PATH')) |
---|
29 | { |
---|
30 | die ("Hacking attempt!"); |
---|
31 | } |
---|
32 | include_once(PHPWG_ROOT_PATH.'admin/include/isadmin.inc.php'); |
---|
33 | |
---|
34 | |
---|
35 | // +-----------------------------------------------------------------------+ |
---|
36 | // | initialization | |
---|
37 | // +-----------------------------------------------------------------------+ |
---|
38 | if (isset($_GET['start']) and is_numeric($_GET['start'])) |
---|
39 | { |
---|
40 | $start = $_GET['start']; |
---|
41 | } |
---|
42 | else |
---|
43 | { |
---|
44 | $start = 0; |
---|
45 | } |
---|
46 | |
---|
47 | $elements_per_page=10; |
---|
48 | if (isset($_GET['display']) and is_numeric($_GET['display'])) |
---|
49 | { |
---|
50 | $elements_per_page = $_GET['display']; |
---|
51 | } |
---|
52 | |
---|
53 | $order_by_index=0; |
---|
54 | if (isset($_GET['order_by']) and is_numeric($_GET['order_by'])) |
---|
55 | { |
---|
56 | $order_by_index = $_GET['order_by']; |
---|
57 | } |
---|
58 | |
---|
59 | $display_filter= ''; |
---|
60 | if (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 | } |
---|
79 | if ($display_filter=='') |
---|
80 | { |
---|
81 | $template->assign_vars( array( |
---|
82 | 'DISPLAY_FILTER_ALL_CHECKED'=>'checked="checked"' |
---|
83 | ) |
---|
84 | ); |
---|
85 | } |
---|
86 | |
---|
87 | if (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 = ' |
---|
96 | DELETE FROM '. RATE_TABLE .' |
---|
97 | WHERE element_id=' . $vars['e'] . ' |
---|
98 | AND user_id=' . $vars['u'] . ' |
---|
99 | AND anonymous_id=\'' . $vars['a'] . '\' |
---|
100 | ;'; |
---|
101 | pwg_query($query); |
---|
102 | update_average_rate( $vars['e'] ); |
---|
103 | } |
---|
104 | |
---|
105 | $users = array(); |
---|
106 | $query = ' |
---|
107 | SELECT '.$conf['user_fields']['username'].' as username, '.$conf['user_fields']['id'].' as id |
---|
108 | FROM '.USERS_TABLE.' |
---|
109 | ;'; |
---|
110 | $result = pwg_query($query); |
---|
111 | while ($row = mysql_fetch_array($result)) |
---|
112 | { |
---|
113 | $users[$row['id']]=$row['username']; |
---|
114 | } |
---|
115 | |
---|
116 | |
---|
117 | $query = 'SELECT COUNT(DISTINCT(i.id)) |
---|
118 | FROM '.RATE_TABLE.' AS r, '.IMAGES_TABLE.' AS i |
---|
119 | WHERE r.element_id=i.id'. $display_filter . |
---|
120 | ';'; |
---|
121 | list($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 | |
---|
159 | for ($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 = 'SELECT i.id, i.path, i.file, i.tn_ext, i.average_rate, i.storage_category_id, |
---|
172 | MAX(r.date) as recently_rated, COUNT(r.rate) as nb_rates, |
---|
173 | SUM(r.rate) as sum_rates, ROUND(STD(r.rate),2) as std_rates |
---|
174 | FROM '.RATE_TABLE.' AS r LEFT JOIN '.IMAGES_TABLE.' AS i |
---|
175 | ON r.element_id=i.id |
---|
176 | WHERE 1=1 ' . $display_filter . ' |
---|
177 | GROUP BY r.element_id |
---|
178 | ORDER BY ' . $available_order_by[$order_by_index][1] .' |
---|
179 | LIMIT '.$start.','.$elements_per_page . |
---|
180 | ';'; |
---|
181 | |
---|
182 | $images = array(); |
---|
183 | $result = pwg_query($query); |
---|
184 | while ($row = mysql_fetch_array($result)) |
---|
185 | { |
---|
186 | array_push($images, $row); |
---|
187 | } |
---|
188 | |
---|
189 | foreach ($images as $image) |
---|
190 | { |
---|
191 | $thumbnail_src = get_thumbnail_src( |
---|
192 | $image['path'], $image['tn_ext'] |
---|
193 | ); |
---|
194 | |
---|
195 | $image_url = PHPWG_ROOT_PATH.'picture.php?'. |
---|
196 | 'cat=' . $image['storage_category_id']. |
---|
197 | '&image_id=' . $image['id']; |
---|
198 | |
---|
199 | $query = 'SELECT * |
---|
200 | FROM '.RATE_TABLE.' AS r |
---|
201 | WHERE r.element_id='.$image['id'] . ' |
---|
202 | ORDER BY date DESC;'; |
---|
203 | $result = pwg_query($query); |
---|
204 | $nb_rates = mysql_num_rows($result); |
---|
205 | |
---|
206 | $template->assign_block_vars('image', |
---|
207 | array( |
---|
208 | 'U_THUMB' => $thumbnail_src, |
---|
209 | 'U_URL' => $image_url, |
---|
210 | 'AVG_RATE' => $image['average_rate'], |
---|
211 | 'STD_RATE' => $image['std_rates'], |
---|
212 | 'SUM_RATE' => $image['sum_rates'], |
---|
213 | 'NB_RATES' => $image['nb_rates'], |
---|
214 | 'NB_RATES_TOTAL' => $nb_rates, |
---|
215 | 'FILE' => $image['file'], |
---|
216 | 'NB_RATES_PLUS1' => $nb_rates+1, |
---|
217 | ) |
---|
218 | ); |
---|
219 | |
---|
220 | while ($row = mysql_fetch_array($result)) |
---|
221 | { |
---|
222 | |
---|
223 | $url_del = PHPWG_ROOT_PATH.'admin.php'. |
---|
224 | get_query_string_diff(array('del')); |
---|
225 | |
---|
226 | $del_param = 'e='.$image['id']. |
---|
227 | '&u='.$row['user_id']. |
---|
228 | '&a='.$row['anonymous_id']; |
---|
229 | |
---|
230 | $url_del .= '&del='.urlencode(urlencode($del_param)); |
---|
231 | |
---|
232 | if ( isset($users[$row['user_id']]) ) |
---|
233 | { |
---|
234 | $user = $users[$row['user_id']]; |
---|
235 | } |
---|
236 | else |
---|
237 | { |
---|
238 | $user = '? '. $row['user_id']; |
---|
239 | } |
---|
240 | if ( strlen($row['anonymous_id'])>0 ) |
---|
241 | { |
---|
242 | $user .= '('.$row['anonymous_id'].')'; |
---|
243 | } |
---|
244 | |
---|
245 | $template->assign_block_vars('image.rate', |
---|
246 | array( |
---|
247 | 'DATE' => format_date($row['date']), |
---|
248 | 'RATE' => $row['rate'], |
---|
249 | 'USER' => $user, |
---|
250 | 'U_DELETE' => $url_del |
---|
251 | ) |
---|
252 | ); |
---|
253 | } |
---|
254 | } |
---|
255 | //print_r($template->_tpldata); |
---|
256 | // +-----------------------------------------------------------------------+ |
---|
257 | // | sending html code | |
---|
258 | // +-----------------------------------------------------------------------+ |
---|
259 | $template->assign_var_from_handle('ADMIN_CONTENT', 'rating'); |
---|
260 | ?> |
---|