[1056] | 1 | <?php |
---|
| 2 | // +-----------------------------------------------------------------------+ |
---|
[8728] | 3 | // | Piwigo - a PHP based photo gallery | |
---|
[2297] | 4 | // +-----------------------------------------------------------------------+ |
---|
[12922] | 5 | // | Copyright(C) 2008-2012 Piwigo Team http://piwigo.org | |
---|
[2297] | 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 | // +-----------------------------------------------------------------------+ |
---|
[1056] | 23 | |
---|
| 24 | if (!defined('PHPWG_ROOT_PATH')) |
---|
| 25 | { |
---|
| 26 | die ("Hacking attempt!"); |
---|
| 27 | } |
---|
| 28 | |
---|
[1072] | 29 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
[1056] | 30 | |
---|
| 31 | // +-----------------------------------------------------------------------+ |
---|
[1072] | 32 | // | Check Access and exit when user status is not ok | |
---|
| 33 | // +-----------------------------------------------------------------------+ |
---|
| 34 | check_status(ACCESS_ADMINISTRATOR); |
---|
| 35 | |
---|
[12624] | 36 | |
---|
| 37 | include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php'); |
---|
| 38 | $tabsheet = new tabsheet(); |
---|
[16926] | 39 | $tabsheet->set_id('rating'); |
---|
[12624] | 40 | $tabsheet->add('rating', l10n('Photos'), get_root_url().'admin.php?page=rating'); |
---|
| 41 | $tabsheet->add('rating_user', l10n('Users'), get_root_url().'admin.php?page=rating_user'); |
---|
| 42 | $tabsheet->select('rating'); |
---|
| 43 | $tabsheet->assign(); |
---|
| 44 | |
---|
[1072] | 45 | // +-----------------------------------------------------------------------+ |
---|
[1056] | 46 | // | initialization | |
---|
| 47 | // +-----------------------------------------------------------------------+ |
---|
| 48 | if (isset($_GET['start']) and is_numeric($_GET['start'])) |
---|
| 49 | { |
---|
| 50 | $start = $_GET['start']; |
---|
| 51 | } |
---|
| 52 | else |
---|
| 53 | { |
---|
| 54 | $start = 0; |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | $elements_per_page=10; |
---|
| 58 | if (isset($_GET['display']) and is_numeric($_GET['display'])) |
---|
| 59 | { |
---|
| 60 | $elements_per_page = $_GET['display']; |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | $order_by_index=0; |
---|
| 64 | if (isset($_GET['order_by']) and is_numeric($_GET['order_by'])) |
---|
| 65 | { |
---|
| 66 | $order_by_index = $_GET['order_by']; |
---|
| 67 | } |
---|
| 68 | |
---|
[1211] | 69 | $page['user_filter'] = ''; |
---|
| 70 | if (isset($_GET['users'])) |
---|
[1056] | 71 | { |
---|
[1211] | 72 | if ($_GET['users'] == 'user') |
---|
[1056] | 73 | { |
---|
[1211] | 74 | $page['user_filter'] = ' AND r.user_id <> '.$conf['guest_id']; |
---|
[1056] | 75 | } |
---|
[1211] | 76 | elseif ($_GET['users'] == 'guest') |
---|
[1056] | 77 | { |
---|
[1211] | 78 | $page['user_filter'] = ' AND r.user_id = '.$conf['guest_id']; |
---|
[1056] | 79 | } |
---|
| 80 | } |
---|
| 81 | |
---|
[8126] | 82 | if (isset($_GET['del'])) |
---|
[1056] | 83 | { |
---|
[12255] | 84 | include_once(PHPWG_ROOT_PATH.'include/functions_rate.inc.php'); |
---|
[1056] | 85 | $del_params = urldecode( $_GET['del'] ); |
---|
| 86 | parse_str($del_params, $vars); |
---|
| 87 | if ( !is_numeric($vars['e']) or !is_numeric($vars['u']) ) |
---|
| 88 | { |
---|
| 89 | die('Hacking attempt'); |
---|
| 90 | } |
---|
| 91 | $query = ' |
---|
| 92 | DELETE FROM '. RATE_TABLE .' |
---|
| 93 | WHERE element_id=' . $vars['e'] . ' |
---|
| 94 | AND user_id=' . $vars['u'] . ' |
---|
| 95 | AND anonymous_id=\'' . $vars['a'] . '\' |
---|
| 96 | ;'; |
---|
| 97 | pwg_query($query); |
---|
[11827] | 98 | update_rating_score( $vars['e'] ); |
---|
[1056] | 99 | } |
---|
| 100 | |
---|
| 101 | $users = array(); |
---|
| 102 | $query = ' |
---|
| 103 | SELECT '.$conf['user_fields']['username'].' as username, '.$conf['user_fields']['id'].' as id |
---|
| 104 | FROM '.USERS_TABLE.' |
---|
| 105 | ;'; |
---|
| 106 | $result = pwg_query($query); |
---|
[4325] | 107 | while ($row = pwg_db_fetch_assoc($result)) |
---|
[1056] | 108 | { |
---|
[4304] | 109 | $users[$row['id']]=stripslashes($row['username']); |
---|
[1056] | 110 | } |
---|
| 111 | |
---|
| 112 | |
---|
[11827] | 113 | $query = 'SELECT COUNT(DISTINCT(r.element_id)) |
---|
| 114 | FROM '.RATE_TABLE.' AS r |
---|
| 115 | WHERE 1=1'. $page['user_filter']; |
---|
[4325] | 116 | list($nb_images) = pwg_db_fetch_row(pwg_query($query)); |
---|
[1056] | 117 | |
---|
| 118 | |
---|
| 119 | // +-----------------------------------------------------------------------+ |
---|
| 120 | // | template init | |
---|
| 121 | // +-----------------------------------------------------------------------+ |
---|
| 122 | |
---|
[2530] | 123 | $template->set_filename('rating', 'rating.tpl'); |
---|
[1056] | 124 | |
---|
[2223] | 125 | $template->assign( |
---|
[1084] | 126 | array( |
---|
[3172] | 127 | 'navbar' => create_navigation_bar( |
---|
[1084] | 128 | PHPWG_ROOT_PATH.'admin.php'.get_query_string_diff(array('start','del')), |
---|
| 129 | $nb_images, |
---|
| 130 | $start, |
---|
[1090] | 131 | $elements_per_page |
---|
[2223] | 132 | ), |
---|
[1056] | 133 | 'F_ACTION' => PHPWG_ROOT_PATH.'admin.php', |
---|
| 134 | 'DISPLAY' => $elements_per_page, |
---|
[2223] | 135 | 'NB_ELEMENTS' => $nb_images, |
---|
[1056] | 136 | ) |
---|
| 137 | ); |
---|
| 138 | |
---|
[2223] | 139 | |
---|
| 140 | |
---|
[1056] | 141 | $available_order_by= array( |
---|
| 142 | array(l10n('Rate date'), 'recently_rated DESC'), |
---|
[12528] | 143 | array(l10n('Rating score'), 'score DESC'), |
---|
[11827] | 144 | array(l10n('Average rate'), 'avg_rates DESC'), |
---|
[1059] | 145 | array(l10n('Number of rates'), 'nb_rates DESC'), |
---|
| 146 | array(l10n('Sum of rates'), 'sum_rates DESC'), |
---|
| 147 | array(l10n('File name'), 'file DESC'), |
---|
[1056] | 148 | array(l10n('Creation date'), 'date_creation DESC'), |
---|
[1059] | 149 | array(l10n('Post date'), 'date_available DESC'), |
---|
[1056] | 150 | ); |
---|
| 151 | |
---|
| 152 | for ($i=0; $i<count($available_order_by); $i++) |
---|
| 153 | { |
---|
[2223] | 154 | $template->append( |
---|
| 155 | 'order_by_options', |
---|
| 156 | $available_order_by[$i][0] |
---|
[1056] | 157 | ); |
---|
| 158 | } |
---|
[2223] | 159 | $template->assign('order_by_options_selected', array($order_by_index) ); |
---|
[1056] | 160 | |
---|
[2223] | 161 | |
---|
[1211] | 162 | $user_options = array( |
---|
[2223] | 163 | 'all' => l10n('all'), |
---|
| 164 | 'user' => l10n('Users'), |
---|
| 165 | 'guest' => l10n('Guests'), |
---|
[1211] | 166 | ); |
---|
| 167 | |
---|
[2223] | 168 | $template->assign('user_options', $user_options ); |
---|
| 169 | $template->assign('user_options_selected', array(@$_GET['users']) ); |
---|
[1211] | 170 | |
---|
[2223] | 171 | |
---|
[1064] | 172 | $query = ' |
---|
| 173 | SELECT i.id, |
---|
[12528] | 174 | i.path, |
---|
| 175 | i.file, |
---|
[12797] | 176 | i.representative_ext, |
---|
[12528] | 177 | i.rating_score AS score, |
---|
| 178 | MAX(r.date) AS recently_rated, |
---|
| 179 | ROUND(AVG(r.rate),2) AS avg_rates, |
---|
| 180 | COUNT(r.rate) AS nb_rates, |
---|
| 181 | SUM(r.rate) AS sum_rates |
---|
[1064] | 182 | FROM '.RATE_TABLE.' AS r |
---|
| 183 | LEFT JOIN '.IMAGES_TABLE.' AS i ON r.element_id = i.id |
---|
[1211] | 184 | WHERE 1 = 1 ' . $page['user_filter'] . ' |
---|
[6607] | 185 | GROUP BY i.id, |
---|
| 186 | i.path, |
---|
| 187 | i.file, |
---|
[12796] | 188 | i.representative_ext, |
---|
[11893] | 189 | i.rating_score, |
---|
[6607] | 190 | r.element_id |
---|
[1064] | 191 | ORDER BY ' . $available_order_by[$order_by_index][1] .' |
---|
[4334] | 192 | LIMIT '.$elements_per_page.' OFFSET '.$start.' |
---|
[1064] | 193 | ;'; |
---|
[1056] | 194 | |
---|
| 195 | $images = array(); |
---|
| 196 | $result = pwg_query($query); |
---|
[4325] | 197 | while ($row = pwg_db_fetch_assoc($result)) |
---|
[1056] | 198 | { |
---|
| 199 | array_push($images, $row); |
---|
| 200 | } |
---|
| 201 | |
---|
[2223] | 202 | $template->assign( 'images', array() ); |
---|
[1056] | 203 | foreach ($images as $image) |
---|
| 204 | { |
---|
[12796] | 205 | $thumbnail_src = DerivativeImage::thumb_url($image); |
---|
[1056] | 206 | |
---|
[13077] | 207 | $image_url = get_root_url().'admin.php?page=photo-'.$image['id']; |
---|
[1059] | 208 | |
---|
[1056] | 209 | $query = 'SELECT * |
---|
| 210 | FROM '.RATE_TABLE.' AS r |
---|
| 211 | WHERE r.element_id='.$image['id'] . ' |
---|
| 212 | ORDER BY date DESC;'; |
---|
| 213 | $result = pwg_query($query); |
---|
[4325] | 214 | $nb_rates = pwg_db_num_rows($result); |
---|
[1056] | 215 | |
---|
[2223] | 216 | $tpl_image = |
---|
[1056] | 217 | array( |
---|
| 218 | 'U_THUMB' => $thumbnail_src, |
---|
| 219 | 'U_URL' => $image_url, |
---|
[11827] | 220 | 'SCORE_RATE' => $image['score'], |
---|
| 221 | 'AVG_RATE' => $image['avg_rates'], |
---|
[1056] | 222 | 'SUM_RATE' => $image['sum_rates'], |
---|
[2223] | 223 | 'NB_RATES' => (int)$image['nb_rates'], |
---|
| 224 | 'NB_RATES_TOTAL' => (int)$nb_rates, |
---|
[1056] | 225 | 'FILE' => $image['file'], |
---|
[2223] | 226 | 'rates' => array() |
---|
[1056] | 227 | ); |
---|
| 228 | |
---|
[4325] | 229 | while ($row = pwg_db_fetch_assoc($result)) |
---|
[1056] | 230 | { |
---|
| 231 | |
---|
| 232 | $url_del = PHPWG_ROOT_PATH.'admin.php'. |
---|
| 233 | get_query_string_diff(array('del')); |
---|
[1059] | 234 | |
---|
[1056] | 235 | $del_param = 'e='.$image['id']. |
---|
| 236 | '&u='.$row['user_id']. |
---|
| 237 | '&a='.$row['anonymous_id']; |
---|
[1059] | 238 | |
---|
[1056] | 239 | $url_del .= '&del='.urlencode(urlencode($del_param)); |
---|
| 240 | |
---|
| 241 | if ( isset($users[$row['user_id']]) ) |
---|
| 242 | { |
---|
[2475] | 243 | $user_rate = $users[$row['user_id']]; |
---|
[1056] | 244 | } |
---|
| 245 | else |
---|
| 246 | { |
---|
[2475] | 247 | $user_rate = '? '. $row['user_id']; |
---|
[1056] | 248 | } |
---|
| 249 | if ( strlen($row['anonymous_id'])>0 ) |
---|
| 250 | { |
---|
[2475] | 251 | $user_rate .= '('.$row['anonymous_id'].')'; |
---|
[1056] | 252 | } |
---|
[1059] | 253 | |
---|
[2223] | 254 | $tpl_image['rates'][] = |
---|
[1056] | 255 | array( |
---|
[12528] | 256 | 'DATE' => /*format_date*/($row['date']), |
---|
[1056] | 257 | 'RATE' => $row['rate'], |
---|
[2475] | 258 | 'USER' => $user_rate, |
---|
[1056] | 259 | 'U_DELETE' => $url_del |
---|
| 260 | ); |
---|
| 261 | } |
---|
[2223] | 262 | $template->append( 'images', $tpl_image ); |
---|
[1056] | 263 | } |
---|
[2223] | 264 | |
---|
[1056] | 265 | // +-----------------------------------------------------------------------+ |
---|
| 266 | // | sending html code | |
---|
| 267 | // +-----------------------------------------------------------------------+ |
---|
| 268 | $template->assign_var_from_handle('ADMIN_CONTENT', 'rating'); |
---|
[6402] | 269 | ?> |
---|