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