1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | Piwigo - a PHP based photo gallery | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | Copyright(C) 2008-2012 Piwigo Team http://piwigo.org | |
---|
6 | // | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net | |
---|
7 | // | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick | |
---|
8 | // +-----------------------------------------------------------------------+ |
---|
9 | // | This program is free software; you can redistribute it and/or modify | |
---|
10 | // | it under the terms of the GNU General Public License as published by | |
---|
11 | // | the Free Software Foundation | |
---|
12 | // | | |
---|
13 | // | This program is distributed in the hope that it will be useful, but | |
---|
14 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
15 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
16 | // | General Public License for more details. | |
---|
17 | // | | |
---|
18 | // | You should have received a copy of the GNU General Public License | |
---|
19 | // | along with this program; if not, write to the Free Software | |
---|
20 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
21 | // | USA. | |
---|
22 | // +-----------------------------------------------------------------------+ |
---|
23 | |
---|
24 | if (!defined('PHPWG_ROOT_PATH')) |
---|
25 | { |
---|
26 | die ("Hacking attempt!"); |
---|
27 | } |
---|
28 | |
---|
29 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
30 | |
---|
31 | // +-----------------------------------------------------------------------+ |
---|
32 | // | Check Access and exit when user status is not ok | |
---|
33 | // +-----------------------------------------------------------------------+ |
---|
34 | check_status(ACCESS_ADMINISTRATOR); |
---|
35 | |
---|
36 | |
---|
37 | include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php'); |
---|
38 | $tabsheet = new tabsheet(); |
---|
39 | $tabsheet->add('rating', l10n('Photos'), get_root_url().'admin.php?page=rating'); |
---|
40 | $tabsheet->add('rating_user', l10n('Users'), get_root_url().'admin.php?page=rating_user'); |
---|
41 | $tabsheet->select('rating'); |
---|
42 | $tabsheet->assign(); |
---|
43 | |
---|
44 | // +-----------------------------------------------------------------------+ |
---|
45 | // | initialization | |
---|
46 | // +-----------------------------------------------------------------------+ |
---|
47 | if (isset($_GET['start']) and is_numeric($_GET['start'])) |
---|
48 | { |
---|
49 | $start = $_GET['start']; |
---|
50 | } |
---|
51 | else |
---|
52 | { |
---|
53 | $start = 0; |
---|
54 | } |
---|
55 | |
---|
56 | $elements_per_page=10; |
---|
57 | if (isset($_GET['display']) and is_numeric($_GET['display'])) |
---|
58 | { |
---|
59 | $elements_per_page = $_GET['display']; |
---|
60 | } |
---|
61 | |
---|
62 | $order_by_index=0; |
---|
63 | if (isset($_GET['order_by']) and is_numeric($_GET['order_by'])) |
---|
64 | { |
---|
65 | $order_by_index = $_GET['order_by']; |
---|
66 | } |
---|
67 | |
---|
68 | $page['user_filter'] = ''; |
---|
69 | if (isset($_GET['users'])) |
---|
70 | { |
---|
71 | if ($_GET['users'] == 'user') |
---|
72 | { |
---|
73 | $page['user_filter'] = ' AND r.user_id <> '.$conf['guest_id']; |
---|
74 | } |
---|
75 | elseif ($_GET['users'] == 'guest') |
---|
76 | { |
---|
77 | $page['user_filter'] = ' AND r.user_id = '.$conf['guest_id']; |
---|
78 | } |
---|
79 | } |
---|
80 | |
---|
81 | if (isset($_GET['del'])) |
---|
82 | { |
---|
83 | include_once(PHPWG_ROOT_PATH.'include/functions_rate.inc.php'); |
---|
84 | $del_params = urldecode( $_GET['del'] ); |
---|
85 | parse_str($del_params, $vars); |
---|
86 | if ( !is_numeric($vars['e']) or !is_numeric($vars['u']) ) |
---|
87 | { |
---|
88 | die('Hacking attempt'); |
---|
89 | } |
---|
90 | $query = ' |
---|
91 | DELETE FROM '. RATE_TABLE .' |
---|
92 | WHERE element_id=' . $vars['e'] . ' |
---|
93 | AND user_id=' . $vars['u'] . ' |
---|
94 | AND anonymous_id=\'' . $vars['a'] . '\' |
---|
95 | ;'; |
---|
96 | pwg_query($query); |
---|
97 | update_rating_score( $vars['e'] ); |
---|
98 | } |
---|
99 | |
---|
100 | $users = array(); |
---|
101 | $query = ' |
---|
102 | SELECT '.$conf['user_fields']['username'].' as username, '.$conf['user_fields']['id'].' as id |
---|
103 | FROM '.USERS_TABLE.' |
---|
104 | ;'; |
---|
105 | $result = pwg_query($query); |
---|
106 | while ($row = pwg_db_fetch_assoc($result)) |
---|
107 | { |
---|
108 | $users[$row['id']]=stripslashes($row['username']); |
---|
109 | } |
---|
110 | |
---|
111 | |
---|
112 | $query = 'SELECT COUNT(DISTINCT(r.element_id)) |
---|
113 | FROM '.RATE_TABLE.' AS r |
---|
114 | WHERE 1=1'. $page['user_filter']; |
---|
115 | list($nb_images) = pwg_db_fetch_row(pwg_query($query)); |
---|
116 | |
---|
117 | |
---|
118 | // +-----------------------------------------------------------------------+ |
---|
119 | // | template init | |
---|
120 | // +-----------------------------------------------------------------------+ |
---|
121 | |
---|
122 | $template->set_filename('rating', 'rating.tpl'); |
---|
123 | |
---|
124 | $template->assign( |
---|
125 | array( |
---|
126 | 'navbar' => create_navigation_bar( |
---|
127 | PHPWG_ROOT_PATH.'admin.php'.get_query_string_diff(array('start','del')), |
---|
128 | $nb_images, |
---|
129 | $start, |
---|
130 | $elements_per_page |
---|
131 | ), |
---|
132 | 'F_ACTION' => PHPWG_ROOT_PATH.'admin.php', |
---|
133 | 'DISPLAY' => $elements_per_page, |
---|
134 | 'NB_ELEMENTS' => $nb_images, |
---|
135 | ) |
---|
136 | ); |
---|
137 | |
---|
138 | |
---|
139 | |
---|
140 | $available_order_by= array( |
---|
141 | array(l10n('Rate date'), 'recently_rated DESC'), |
---|
142 | array(l10n('Rating score'), 'score DESC'), |
---|
143 | array(l10n('Average rate'), 'avg_rates DESC'), |
---|
144 | array(l10n('Number of rates'), 'nb_rates DESC'), |
---|
145 | array(l10n('Sum of rates'), 'sum_rates DESC'), |
---|
146 | array(l10n('File name'), 'file DESC'), |
---|
147 | array(l10n('Creation date'), 'date_creation DESC'), |
---|
148 | array(l10n('Post date'), 'date_available DESC'), |
---|
149 | ); |
---|
150 | |
---|
151 | for ($i=0; $i<count($available_order_by); $i++) |
---|
152 | { |
---|
153 | $template->append( |
---|
154 | 'order_by_options', |
---|
155 | $available_order_by[$i][0] |
---|
156 | ); |
---|
157 | } |
---|
158 | $template->assign('order_by_options_selected', array($order_by_index) ); |
---|
159 | |
---|
160 | |
---|
161 | $user_options = array( |
---|
162 | 'all' => l10n('all'), |
---|
163 | 'user' => l10n('Users'), |
---|
164 | 'guest' => l10n('Guests'), |
---|
165 | ); |
---|
166 | |
---|
167 | $template->assign('user_options', $user_options ); |
---|
168 | $template->assign('user_options_selected', array(@$_GET['users']) ); |
---|
169 | |
---|
170 | |
---|
171 | $query = ' |
---|
172 | SELECT i.id, |
---|
173 | i.path, |
---|
174 | i.file, |
---|
175 | i.representative_ext, |
---|
176 | i.rating_score AS score, |
---|
177 | MAX(r.date) AS recently_rated, |
---|
178 | ROUND(AVG(r.rate),2) AS avg_rates, |
---|
179 | COUNT(r.rate) AS nb_rates, |
---|
180 | SUM(r.rate) AS sum_rates |
---|
181 | FROM '.RATE_TABLE.' AS r |
---|
182 | LEFT JOIN '.IMAGES_TABLE.' AS i ON r.element_id = i.id |
---|
183 | WHERE 1 = 1 ' . $page['user_filter'] . ' |
---|
184 | GROUP BY i.id, |
---|
185 | i.path, |
---|
186 | i.file, |
---|
187 | i.representative_ext, |
---|
188 | i.rating_score, |
---|
189 | r.element_id |
---|
190 | ORDER BY ' . $available_order_by[$order_by_index][1] .' |
---|
191 | LIMIT '.$elements_per_page.' OFFSET '.$start.' |
---|
192 | ;'; |
---|
193 | |
---|
194 | $images = array(); |
---|
195 | $result = pwg_query($query); |
---|
196 | while ($row = pwg_db_fetch_assoc($result)) |
---|
197 | { |
---|
198 | array_push($images, $row); |
---|
199 | } |
---|
200 | |
---|
201 | $template->assign( 'images', array() ); |
---|
202 | foreach ($images as $image) |
---|
203 | { |
---|
204 | $thumbnail_src = DerivativeImage::thumb_url($image); |
---|
205 | |
---|
206 | $image_url = get_root_url().'admin.php?page=photo-'.$image['id']; |
---|
207 | |
---|
208 | $query = 'SELECT * |
---|
209 | FROM '.RATE_TABLE.' AS r |
---|
210 | WHERE r.element_id='.$image['id'] . ' |
---|
211 | ORDER BY date DESC;'; |
---|
212 | $result = pwg_query($query); |
---|
213 | $nb_rates = pwg_db_num_rows($result); |
---|
214 | |
---|
215 | $tpl_image = |
---|
216 | array( |
---|
217 | 'U_THUMB' => $thumbnail_src, |
---|
218 | 'U_URL' => $image_url, |
---|
219 | 'SCORE_RATE' => $image['score'], |
---|
220 | 'AVG_RATE' => $image['avg_rates'], |
---|
221 | 'SUM_RATE' => $image['sum_rates'], |
---|
222 | 'NB_RATES' => (int)$image['nb_rates'], |
---|
223 | 'NB_RATES_TOTAL' => (int)$nb_rates, |
---|
224 | 'FILE' => $image['file'], |
---|
225 | 'rates' => array() |
---|
226 | ); |
---|
227 | |
---|
228 | while ($row = pwg_db_fetch_assoc($result)) |
---|
229 | { |
---|
230 | |
---|
231 | $url_del = PHPWG_ROOT_PATH.'admin.php'. |
---|
232 | get_query_string_diff(array('del')); |
---|
233 | |
---|
234 | $del_param = 'e='.$image['id']. |
---|
235 | '&u='.$row['user_id']. |
---|
236 | '&a='.$row['anonymous_id']; |
---|
237 | |
---|
238 | $url_del .= '&del='.urlencode(urlencode($del_param)); |
---|
239 | |
---|
240 | if ( isset($users[$row['user_id']]) ) |
---|
241 | { |
---|
242 | $user_rate = $users[$row['user_id']]; |
---|
243 | } |
---|
244 | else |
---|
245 | { |
---|
246 | $user_rate = '? '. $row['user_id']; |
---|
247 | } |
---|
248 | if ( strlen($row['anonymous_id'])>0 ) |
---|
249 | { |
---|
250 | $user_rate .= '('.$row['anonymous_id'].')'; |
---|
251 | } |
---|
252 | |
---|
253 | $tpl_image['rates'][] = |
---|
254 | array( |
---|
255 | 'DATE' => /*format_date*/($row['date']), |
---|
256 | 'RATE' => $row['rate'], |
---|
257 | 'USER' => $user_rate, |
---|
258 | 'U_DELETE' => $url_del |
---|
259 | ); |
---|
260 | } |
---|
261 | $template->append( 'images', $tpl_image ); |
---|
262 | } |
---|
263 | |
---|
264 | // +-----------------------------------------------------------------------+ |
---|
265 | // | sending html code | |
---|
266 | // +-----------------------------------------------------------------------+ |
---|
267 | $template->assign_var_from_handle('ADMIN_CONTENT', 'rating'); |
---|
268 | ?> |
---|