[61] | 1 | <?php |
---|
[362] | 2 | // +-----------------------------------------------------------------------+ |
---|
[2297] | 3 | // | Piwigo - a PHP based picture gallery | |
---|
| 4 | // +-----------------------------------------------------------------------+ |
---|
[3046] | 5 | // | Copyright(C) 2008-2009 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 | // +-----------------------------------------------------------------------+ |
---|
[61] | 23 | |
---|
[575] | 24 | if(!defined("PHPWG_ROOT_PATH")) |
---|
[509] | 25 | { |
---|
[825] | 26 | die('Hacking attempt!'); |
---|
[509] | 27 | } |
---|
[825] | 28 | |
---|
[1072] | 29 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
| 30 | |
---|
[825] | 31 | // +-----------------------------------------------------------------------+ |
---|
[1072] | 32 | // | Check Access and exit when user status is not ok | |
---|
| 33 | // +-----------------------------------------------------------------------+ |
---|
| 34 | check_status(ACCESS_ADMINISTRATOR); |
---|
| 35 | |
---|
[5003] | 36 | check_input_parameter('image_id', $_GET, false, PATTERN_ID); |
---|
| 37 | check_input_parameter('cat_id', $_GET, false, PATTERN_ID); |
---|
[4495] | 38 | |
---|
[1072] | 39 | // +-----------------------------------------------------------------------+ |
---|
[825] | 40 | // | synchronize metadata | |
---|
| 41 | // +-----------------------------------------------------------------------+ |
---|
| 42 | |
---|
[1085] | 43 | if (isset($_GET['sync_metadata']) and !is_adviser()) |
---|
[825] | 44 | { |
---|
| 45 | $query = ' |
---|
| 46 | SELECT path |
---|
| 47 | FROM '.IMAGES_TABLE.' |
---|
| 48 | WHERE id = '.$_GET['image_id'].' |
---|
| 49 | ;'; |
---|
| 50 | list($path) = mysql_fetch_row(pwg_query($query)); |
---|
| 51 | update_metadata(array($_GET['image_id'] => $path)); |
---|
| 52 | |
---|
| 53 | array_push($page['infos'], l10n('Metadata synchronized from file')); |
---|
| 54 | } |
---|
| 55 | |
---|
[61] | 56 | //--------------------------------------------------------- update informations |
---|
[825] | 57 | |
---|
[61] | 58 | // first, we verify whether there is a mistake on the given creation date |
---|
[825] | 59 | if (isset($_POST['date_creation_action']) |
---|
| 60 | and 'set' == $_POST['date_creation_action']) |
---|
[61] | 61 | { |
---|
[825] | 62 | if (!checkdate( |
---|
| 63 | $_POST['date_creation_month'], |
---|
| 64 | $_POST['date_creation_day'], |
---|
| 65 | $_POST['date_creation_year']) |
---|
| 66 | ) |
---|
[575] | 67 | { |
---|
[2201] | 68 | array_push($page['errors'], l10n('err_date')); |
---|
[575] | 69 | } |
---|
[61] | 70 | } |
---|
[825] | 71 | |
---|
[1571] | 72 | if (isset($_POST['submit']) and count($page['errors']) == 0 and !is_adviser()) |
---|
[61] | 73 | { |
---|
[825] | 74 | $data = array(); |
---|
| 75 | $data{'id'} = $_GET['image_id']; |
---|
| 76 | $data{'name'} = $_POST['name']; |
---|
| 77 | $data{'author'} = $_POST['author']; |
---|
[2090] | 78 | $data['level'] = $_POST['level']; |
---|
[61] | 79 | |
---|
[825] | 80 | if ($conf['allow_html_descriptions']) |
---|
| 81 | { |
---|
| 82 | $data{'comment'} = @$_POST['description']; |
---|
| 83 | } |
---|
[61] | 84 | else |
---|
[825] | 85 | { |
---|
| 86 | $data{'comment'} = strip_tags(@$_POST['description']); |
---|
| 87 | } |
---|
[61] | 88 | |
---|
[825] | 89 | if (isset($_POST['date_creation_action'])) |
---|
| 90 | { |
---|
| 91 | if ('set' == $_POST['date_creation_action']) |
---|
| 92 | { |
---|
| 93 | $data{'date_creation'} = $_POST['date_creation_year'] |
---|
| 94 | .'-'.$_POST['date_creation_month'] |
---|
| 95 | .'-'.$_POST['date_creation_day']; |
---|
| 96 | } |
---|
| 97 | else if ('unset' == $_POST['date_creation_action']) |
---|
| 98 | { |
---|
| 99 | $data{'date_creation'} = ''; |
---|
| 100 | } |
---|
| 101 | } |
---|
[61] | 102 | |
---|
[825] | 103 | mass_updates( |
---|
| 104 | IMAGES_TABLE, |
---|
| 105 | array( |
---|
| 106 | 'primary' => array('id'), |
---|
| 107 | 'update' => array_diff(array_keys($data), array('id')) |
---|
| 108 | ), |
---|
| 109 | array($data) |
---|
| 110 | ); |
---|
| 111 | |
---|
[1119] | 112 | set_tags( |
---|
| 113 | isset($_POST['tags']) ? $_POST['tags'] : array(), |
---|
| 114 | $_GET['image_id'] |
---|
| 115 | ); |
---|
| 116 | |
---|
[825] | 117 | array_push($page['infos'], l10n('Picture informations updated')); |
---|
[635] | 118 | } |
---|
| 119 | // associate the element to other categories than its storage category |
---|
| 120 | if (isset($_POST['associate']) |
---|
| 121 | and isset($_POST['cat_dissociated']) |
---|
[1571] | 122 | and count($_POST['cat_dissociated']) > 0 |
---|
| 123 | and !is_adviser() |
---|
| 124 | ) |
---|
[635] | 125 | { |
---|
[1121] | 126 | associate_images_to_categories( |
---|
| 127 | array($_GET['image_id']), |
---|
| 128 | $_POST['cat_dissociated'] |
---|
[1065] | 129 | ); |
---|
[635] | 130 | } |
---|
| 131 | // dissociate the element from categories (but not from its storage category) |
---|
| 132 | if (isset($_POST['dissociate']) |
---|
| 133 | and isset($_POST['cat_associated']) |
---|
[1571] | 134 | and count($_POST['cat_associated']) > 0 |
---|
| 135 | and !is_adviser() |
---|
| 136 | ) |
---|
[635] | 137 | { |
---|
[575] | 138 | $query = ' |
---|
| 139 | DELETE FROM '.IMAGE_CATEGORY_TABLE.' |
---|
| 140 | WHERE image_id = '.$_GET['image_id'].' |
---|
[1121] | 141 | AND category_id IN ('.implode(',', $_POST['cat_associated']).') |
---|
[635] | 142 | '; |
---|
| 143 | pwg_query($query); |
---|
[1609] | 144 | |
---|
[635] | 145 | update_category($_POST['cat_associated']); |
---|
[61] | 146 | } |
---|
[640] | 147 | // elect the element to represent the given categories |
---|
| 148 | if (isset($_POST['elect']) |
---|
| 149 | and isset($_POST['cat_dismissed']) |
---|
[1571] | 150 | and count($_POST['cat_dismissed']) > 0 |
---|
| 151 | and !is_adviser() |
---|
| 152 | ) |
---|
[640] | 153 | { |
---|
| 154 | $datas = array(); |
---|
| 155 | foreach ($_POST['cat_dismissed'] as $category_id) |
---|
| 156 | { |
---|
| 157 | array_push($datas, |
---|
| 158 | array('id' => $category_id, |
---|
| 159 | 'representative_picture_id' => $_GET['image_id'])); |
---|
| 160 | } |
---|
| 161 | $fields = array('primary' => array('id'), |
---|
| 162 | 'update' => array('representative_picture_id')); |
---|
| 163 | mass_updates(CATEGORIES_TABLE, $fields, $datas); |
---|
| 164 | } |
---|
| 165 | // dismiss the element as representant of the given categories |
---|
| 166 | if (isset($_POST['dismiss']) |
---|
| 167 | and isset($_POST['cat_elected']) |
---|
[1571] | 168 | and count($_POST['cat_elected']) > 0 |
---|
| 169 | and !is_adviser() |
---|
| 170 | ) |
---|
[640] | 171 | { |
---|
| 172 | set_random_representant($_POST['cat_elected']); |
---|
| 173 | } |
---|
[61] | 174 | |
---|
| 175 | // retrieving direct information about picture |
---|
[575] | 176 | $query = ' |
---|
[825] | 177 | SELECT * |
---|
| 178 | FROM '.IMAGES_TABLE.' |
---|
| 179 | WHERE id = '.$_GET['image_id'].' |
---|
[575] | 180 | ;'; |
---|
[587] | 181 | $row = mysql_fetch_array(pwg_query($query)); |
---|
[345] | 182 | |
---|
[2575] | 183 | $storage_category_id = null; |
---|
| 184 | if (!empty($row['storage_category_id'])) |
---|
| 185 | { |
---|
| 186 | $storage_category_id = $row['storage_category_id']; |
---|
| 187 | } |
---|
| 188 | |
---|
[1092] | 189 | $image_file = $row['file']; |
---|
[635] | 190 | |
---|
[1119] | 191 | // tags |
---|
| 192 | $query = ' |
---|
| 193 | SELECT tag_id |
---|
| 194 | FROM '.IMAGE_TAG_TABLE.' |
---|
| 195 | WHERE image_id = '.$_GET['image_id'].' |
---|
| 196 | ;'; |
---|
| 197 | $selected_tags = array_from_query($query, 'tag_id'); |
---|
| 198 | |
---|
[825] | 199 | // +-----------------------------------------------------------------------+ |
---|
| 200 | // | template init | |
---|
| 201 | // +-----------------------------------------------------------------------+ |
---|
| 202 | |
---|
[817] | 203 | $template->set_filenames( |
---|
| 204 | array( |
---|
[2530] | 205 | 'picture_modify' => 'picture_modify.tpl' |
---|
[817] | 206 | ) |
---|
| 207 | ); |
---|
| 208 | |
---|
[1314] | 209 | $all_tags = get_all_tags(); |
---|
| 210 | |
---|
| 211 | if (count($all_tags) > 0) |
---|
| 212 | { |
---|
| 213 | $tag_selection = get_html_tag_selection( |
---|
[1815] | 214 | $all_tags, |
---|
[1314] | 215 | 'tags', |
---|
| 216 | $selected_tags |
---|
| 217 | ); |
---|
| 218 | } |
---|
| 219 | else |
---|
| 220 | { |
---|
| 221 | $tag_selection = |
---|
| 222 | '<p>'. |
---|
| 223 | l10n('No tag defined. Use Administration>Pictures>Tags'). |
---|
| 224 | '</p>'; |
---|
| 225 | } |
---|
[1609] | 226 | |
---|
[2227] | 227 | $template->assign( |
---|
[825] | 228 | array( |
---|
| 229 | 'U_SYNC' => |
---|
[2304] | 230 | get_root_url().'admin.php?page=picture_modify'. |
---|
[825] | 231 | '&image_id='.$_GET['image_id']. |
---|
| 232 | (isset($_GET['cat_id']) ? '&cat_id='.$_GET['cat_id'] : ''). |
---|
[1004] | 233 | '&sync_metadata=1', |
---|
[1092] | 234 | |
---|
[825] | 235 | 'PATH'=>$row['path'], |
---|
[1092] | 236 | |
---|
[1609] | 237 | 'TN_SRC' => get_thumbnail_url($row), |
---|
[1092] | 238 | |
---|
[825] | 239 | 'NAME' => |
---|
| 240 | isset($_POST['name']) ? |
---|
| 241 | stripslashes($_POST['name']) : @$row['name'], |
---|
[1092] | 242 | |
---|
[825] | 243 | 'DIMENSIONS' => @$row['width'].' * '.@$row['height'], |
---|
[1092] | 244 | |
---|
[825] | 245 | 'FILESIZE' => @$row['filesize'].' KB', |
---|
[1092] | 246 | |
---|
[3123] | 247 | 'REGISTRATION_DATE' => format_date($row['date_available']), |
---|
[1092] | 248 | |
---|
[825] | 249 | 'AUTHOR' => isset($_POST['author']) ? $_POST['author'] : @$row['author'], |
---|
[1092] | 250 | |
---|
[1314] | 251 | 'TAG_SELECTION' => $tag_selection, |
---|
[1092] | 252 | |
---|
[825] | 253 | 'DESCRIPTION' => |
---|
[1861] | 254 | htmlspecialchars( isset($_POST['description']) ? |
---|
| 255 | stripslashes($_POST['description']) : @$row['comment'] ), |
---|
[1092] | 256 | |
---|
[825] | 257 | 'F_ACTION' => |
---|
[2304] | 258 | get_root_url().'admin.php' |
---|
[825] | 259 | .get_query_string_diff(array('sync_metadata')) |
---|
| 260 | ) |
---|
| 261 | ); |
---|
| 262 | |
---|
[1883] | 263 | if ($row['has_high'] == 'true') |
---|
| 264 | { |
---|
[2227] | 265 | $template->assign( |
---|
| 266 | 'HIGH_FILESIZE', |
---|
| 267 | isset($row['high_filesize']) |
---|
[1883] | 268 | ? $row['high_filesize'].' KB' |
---|
[2227] | 269 | : l10n('unknown') |
---|
[1883] | 270 | ); |
---|
| 271 | } |
---|
| 272 | |
---|
[2090] | 273 | // image level options |
---|
[2227] | 274 | $tpl_options = array(); |
---|
[2090] | 275 | foreach ($conf['available_permission_levels'] as $level) |
---|
| 276 | { |
---|
[2227] | 277 | $tpl_options[$level] = l10n( sprintf('Level %d', $level) ).' ('.$level.')'; |
---|
| 278 | } |
---|
| 279 | $selected_level = isset($_POST['level']) ? $_POST['level'] : $row['level']; |
---|
| 280 | $template->assign( |
---|
[2090] | 281 | array( |
---|
[2227] | 282 | 'level_options'=> $tpl_options, |
---|
| 283 | 'level_options_selected' => array($selected_level) |
---|
| 284 | ) |
---|
| 285 | ); |
---|
[2090] | 286 | |
---|
[825] | 287 | // creation date |
---|
| 288 | unset($day, $month, $year); |
---|
| 289 | |
---|
| 290 | if (isset($_POST['date_creation_action']) |
---|
| 291 | and 'set' == $_POST['date_creation_action']) |
---|
| 292 | { |
---|
| 293 | foreach (array('day', 'month', 'year') as $varname) |
---|
| 294 | { |
---|
| 295 | $$varname = $_POST['date_creation_'.$varname]; |
---|
| 296 | } |
---|
| 297 | } |
---|
| 298 | else if (isset($row['date_creation']) and !empty($row['date_creation'])) |
---|
| 299 | { |
---|
| 300 | list($year, $month, $day) = explode('-', $row['date_creation']); |
---|
| 301 | } |
---|
| 302 | else |
---|
| 303 | { |
---|
| 304 | list($year, $month, $day) = array('', 0, 0); |
---|
| 305 | } |
---|
[2227] | 306 | |
---|
| 307 | |
---|
| 308 | $month_list = $lang['month']; |
---|
| 309 | $month_list[0]='------------'; |
---|
| 310 | ksort($month_list); |
---|
[1092] | 311 | |
---|
[2227] | 312 | $template->assign( |
---|
| 313 | array( |
---|
| 314 | 'DATE_CREATION_DAY_VALUE' => $day, |
---|
| 315 | 'DATE_CREATION_MONTH_VALUE' => $month, |
---|
| 316 | 'DATE_CREATION_YEAR_VALUE' => $year, |
---|
| 317 | 'month_list' => $month_list, |
---|
| 318 | ) |
---|
| 319 | ); |
---|
| 320 | |
---|
[825] | 321 | $query = ' |
---|
| 322 | SELECT category_id, uppercats |
---|
| 323 | FROM '.IMAGE_CATEGORY_TABLE.' AS ic |
---|
| 324 | INNER JOIN '.CATEGORIES_TABLE.' AS c |
---|
| 325 | ON c.id = ic.category_id |
---|
| 326 | WHERE image_id = '.$_GET['image_id'].' |
---|
| 327 | ;'; |
---|
| 328 | $result = pwg_query($query); |
---|
| 329 | |
---|
| 330 | while ($row = mysql_fetch_array($result)) |
---|
| 331 | { |
---|
| 332 | $name = |
---|
| 333 | get_cat_display_name_cache( |
---|
| 334 | $row['uppercats'], |
---|
[2227] | 335 | get_root_url().'admin.php?page=cat_modify&cat_id=', |
---|
[825] | 336 | false |
---|
| 337 | ); |
---|
[1092] | 338 | |
---|
[825] | 339 | if ($row['category_id'] == $storage_category_id) |
---|
| 340 | { |
---|
[2227] | 341 | $template->assign('STORAGE_CATEGORY', $name); |
---|
[825] | 342 | } |
---|
| 343 | else |
---|
| 344 | { |
---|
[2227] | 345 | $template->append('related_categories', $name); |
---|
[825] | 346 | } |
---|
| 347 | } |
---|
| 348 | |
---|
| 349 | // jump to link |
---|
| 350 | // |
---|
| 351 | // 1. find all linked categories that are reachable for the current user. |
---|
| 352 | // 2. if a category is available in the URL, use it if reachable |
---|
| 353 | // 3. if URL category not available or reachable, use the first reachable |
---|
| 354 | // linked category |
---|
| 355 | // 4. if no category reachable, no jumpto link |
---|
| 356 | |
---|
| 357 | $query = ' |
---|
| 358 | SELECT category_id |
---|
| 359 | FROM '.IMAGE_CATEGORY_TABLE.' |
---|
| 360 | WHERE image_id = '.$_GET['image_id'].' |
---|
| 361 | ;'; |
---|
[1082] | 362 | |
---|
[825] | 363 | $authorizeds = array_diff( |
---|
| 364 | array_from_query($query, 'category_id'), |
---|
[1082] | 365 | explode( |
---|
| 366 | ',', |
---|
| 367 | calculate_permissions($user['id'], $user['status']) |
---|
| 368 | ) |
---|
[825] | 369 | ); |
---|
| 370 | |
---|
| 371 | if (isset($_GET['cat_id']) |
---|
| 372 | and in_array($_GET['cat_id'], $authorizeds)) |
---|
| 373 | { |
---|
[1503] | 374 | $url_img = make_picture_url( |
---|
[1082] | 375 | array( |
---|
| 376 | 'image_id' => $_GET['image_id'], |
---|
[1092] | 377 | 'image_file' => $image_file, |
---|
[1861] | 378 | 'category' => $cache['cat_names'][ $_GET['cat_id'] ], |
---|
[1082] | 379 | ) |
---|
| 380 | ); |
---|
[825] | 381 | } |
---|
| 382 | else |
---|
| 383 | { |
---|
| 384 | foreach ($authorizeds as $category) |
---|
| 385 | { |
---|
[1503] | 386 | $url_img = make_picture_url( |
---|
[1082] | 387 | array( |
---|
| 388 | 'image_id' => $_GET['image_id'], |
---|
[1092] | 389 | 'image_file' => $image_file, |
---|
[1861] | 390 | 'category' => $cache['cat_names'][ $category ], |
---|
[1082] | 391 | ) |
---|
| 392 | ); |
---|
[825] | 393 | break; |
---|
| 394 | } |
---|
| 395 | } |
---|
| 396 | |
---|
| 397 | if (isset($url_img)) |
---|
| 398 | { |
---|
[2227] | 399 | $template->assign( 'U_JUMPTO', $url_img ); |
---|
[825] | 400 | } |
---|
[1092] | 401 | |
---|
[61] | 402 | // associate to another category ? |
---|
[635] | 403 | $query = ' |
---|
| 404 | SELECT id,name,uppercats,global_rank |
---|
| 405 | FROM '.CATEGORIES_TABLE.' |
---|
| 406 | INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = category_id |
---|
[2575] | 407 | WHERE image_id = '.$_GET['image_id']; |
---|
| 408 | if (isset($storage_category_id)) |
---|
| 409 | { |
---|
| 410 | $query.= ' |
---|
| 411 | AND id != '.$storage_category_id; |
---|
| 412 | } |
---|
| 413 | $query.= ' |
---|
[635] | 414 | ;'; |
---|
[2227] | 415 | display_select_cat_wrapper($query, array(), 'associated_options'); |
---|
[635] | 416 | |
---|
| 417 | $result = pwg_query($query); |
---|
[3389] | 418 | $associateds = array(-1); |
---|
[2575] | 419 | if (isset($storage_category_id)) |
---|
| 420 | { |
---|
| 421 | array_push($associateds, $storage_category_id); |
---|
| 422 | } |
---|
[635] | 423 | while ($row = mysql_fetch_array($result)) |
---|
[345] | 424 | { |
---|
[635] | 425 | array_push($associateds, $row['id']); |
---|
[345] | 426 | } |
---|
[635] | 427 | $query = ' |
---|
| 428 | SELECT id,name,uppercats,global_rank |
---|
| 429 | FROM '.CATEGORIES_TABLE.' |
---|
| 430 | WHERE id NOT IN ('.implode(',', $associateds).') |
---|
| 431 | ;'; |
---|
[2227] | 432 | display_select_cat_wrapper($query, array(), 'dissociated_options'); |
---|
[809] | 433 | |
---|
[640] | 434 | // representing |
---|
| 435 | $query = ' |
---|
| 436 | SELECT id,name,uppercats,global_rank |
---|
| 437 | FROM '.CATEGORIES_TABLE.' |
---|
| 438 | WHERE representative_picture_id = '.$_GET['image_id'].' |
---|
| 439 | ;'; |
---|
[2227] | 440 | display_select_cat_wrapper($query, array(), 'elected_options'); |
---|
[640] | 441 | |
---|
| 442 | $query = ' |
---|
| 443 | SELECT id,name,uppercats,global_rank |
---|
| 444 | FROM '.CATEGORIES_TABLE.' |
---|
[809] | 445 | WHERE representative_picture_id != '.$_GET['image_id'].' |
---|
| 446 | OR representative_picture_id IS NULL |
---|
[640] | 447 | ;'; |
---|
[2227] | 448 | display_select_cat_wrapper($query, array(), 'dismissed_options'); |
---|
[817] | 449 | |
---|
[61] | 450 | //----------------------------------------------------------- sending html code |
---|
[817] | 451 | |
---|
[509] | 452 | $template->assign_var_from_handle('ADMIN_CONTENT', 'picture_modify'); |
---|
[362] | 453 | ?> |
---|