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