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