[8394] | 1 | <?php |
---|
| 2 | // +-----------------------------------------------------------------------+ |
---|
[8728] | 3 | // | Piwigo - a PHP based photo gallery | |
---|
[8394] | 4 | // +-----------------------------------------------------------------------+ |
---|
[8728] | 5 | // | Copyright(C) 2008-2011 Piwigo Team http://piwigo.org | |
---|
[8394] | 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 | // +-----------------------------------------------------------------------+ |
---|
| 23 | |
---|
| 24 | /** |
---|
| 25 | * Management of elements set. Elements can belong to a category or to the |
---|
| 26 | * user caddie. |
---|
| 27 | * |
---|
| 28 | */ |
---|
| 29 | |
---|
| 30 | if (!defined('PHPWG_ROOT_PATH')) |
---|
| 31 | { |
---|
| 32 | die('Hacking attempt!'); |
---|
| 33 | } |
---|
| 34 | |
---|
| 35 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
| 36 | |
---|
| 37 | // +-----------------------------------------------------------------------+ |
---|
| 38 | // | Check Access and exit when user status is not ok | |
---|
| 39 | // +-----------------------------------------------------------------------+ |
---|
| 40 | |
---|
| 41 | check_status(ACCESS_ADMINISTRATOR); |
---|
| 42 | |
---|
| 43 | trigger_action('loc_begin_element_set_global'); |
---|
| 44 | |
---|
| 45 | check_input_parameter('del_tags', $_POST, true, PATTERN_ID); |
---|
| 46 | check_input_parameter('associate', $_POST, false, PATTERN_ID); |
---|
| 47 | check_input_parameter('dissociate', $_POST, false, PATTERN_ID); |
---|
| 48 | |
---|
| 49 | // +-----------------------------------------------------------------------+ |
---|
| 50 | // | current selection | |
---|
| 51 | // +-----------------------------------------------------------------------+ |
---|
| 52 | |
---|
| 53 | $collection = array(); |
---|
| 54 | if (isset($_POST['setSelected'])) |
---|
| 55 | { |
---|
| 56 | $collection = $page['cat_elements_id']; |
---|
| 57 | } |
---|
| 58 | else if (isset($_POST['selection'])) |
---|
| 59 | { |
---|
| 60 | $collection = $_POST['selection']; |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | // +-----------------------------------------------------------------------+ |
---|
| 64 | // | global mode form submission | |
---|
| 65 | // +-----------------------------------------------------------------------+ |
---|
| 66 | |
---|
[8422] | 67 | // $page['prefilter'] is a shortcut to test if the current filter contains a |
---|
| 68 | // given prefilter. The idea is to make conditions simpler to write in the |
---|
| 69 | // code. |
---|
| 70 | $page['prefilter'] = 'none'; |
---|
| 71 | if (isset($_SESSION['bulk_manager_filter']['prefilter'])) |
---|
| 72 | { |
---|
| 73 | $page['prefilter'] = $_SESSION['bulk_manager_filter']['prefilter']; |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | // $page['category'] is a shortcut to test if the current filter contains a |
---|
| 77 | // given category. The idea is the same as for prefilter |
---|
| 78 | $page['category'] = -1; |
---|
| 79 | if (isset($_SESSION['bulk_manager_filter']['category'])) |
---|
| 80 | { |
---|
| 81 | $page['category'] = $_SESSION['bulk_manager_filter']['category']; |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | $redirect_url = get_root_url().'admin.php?page='.$_GET['page']; |
---|
| 85 | |
---|
[8394] | 86 | if (isset($_POST['submit'])) |
---|
| 87 | { |
---|
| 88 | // if the user tries to apply an action, it means that there is at least 1 |
---|
| 89 | // photo in the selection |
---|
| 90 | if (count($collection) == 0) |
---|
| 91 | { |
---|
[8682] | 92 | array_push($page['errors'], l10n('Select at least one photo')); |
---|
[8394] | 93 | } |
---|
| 94 | |
---|
| 95 | $action = $_POST['selectAction']; |
---|
| 96 | |
---|
| 97 | if ('remove_from_caddie' == $action) |
---|
| 98 | { |
---|
| 99 | $query = ' |
---|
| 100 | DELETE |
---|
| 101 | FROM '.CADDIE_TABLE.' |
---|
| 102 | WHERE element_id IN ('.implode(',', $collection).') |
---|
| 103 | AND user_id = '.$user['id'].' |
---|
| 104 | ;'; |
---|
| 105 | pwg_query($query); |
---|
| 106 | |
---|
[8422] | 107 | if ('caddie' == $page['prefilter']) |
---|
| 108 | { |
---|
| 109 | redirect($redirect_url); |
---|
| 110 | } |
---|
| 111 | |
---|
[8394] | 112 | // if we are here in the code, it means that the user is currently |
---|
| 113 | // displaying the caddie content, so we have to remove the current |
---|
| 114 | // selection from the current set |
---|
| 115 | $page['cat_elements_id'] = array_diff($page['cat_elements_id'], $collection); |
---|
| 116 | } |
---|
| 117 | |
---|
| 118 | if ('add_tags' == $action) |
---|
| 119 | { |
---|
[10009] | 120 | if (empty($_POST['add_tags'])) |
---|
[8422] | 121 | { |
---|
[10009] | 122 | array_push($page['errors'], l10n('Select at least one tag')); |
---|
[8422] | 123 | } |
---|
[10009] | 124 | else |
---|
| 125 | { |
---|
[11056] | 126 | $tag_ids = get_tag_ids($_POST['add_tags']); |
---|
[10009] | 127 | add_tags($tag_ids, $collection); |
---|
| 128 | |
---|
| 129 | if ('with no tag' == $page['prefilter']) |
---|
| 130 | { |
---|
| 131 | redirect(get_root_url().'admin.php?page='.$_GET['page']); |
---|
| 132 | } |
---|
| 133 | } |
---|
[8394] | 134 | } |
---|
| 135 | |
---|
| 136 | if ('del_tags' == $action) |
---|
| 137 | { |
---|
| 138 | if (count($_POST['del_tags']) == 0) |
---|
| 139 | { |
---|
| 140 | array_push($page['errors'], l10n('Select at least one tag')); |
---|
| 141 | } |
---|
| 142 | |
---|
| 143 | $query = ' |
---|
| 144 | DELETE |
---|
| 145 | FROM '.IMAGE_TAG_TABLE.' |
---|
| 146 | WHERE image_id IN ('.implode(',', $collection).') |
---|
| 147 | AND tag_id IN ('.implode(',', $_POST['del_tags']).') |
---|
| 148 | ;'; |
---|
| 149 | pwg_query($query); |
---|
| 150 | } |
---|
| 151 | |
---|
| 152 | if ('associate' == $action) |
---|
| 153 | { |
---|
| 154 | associate_images_to_categories( |
---|
| 155 | $collection, |
---|
| 156 | array($_POST['associate']) |
---|
| 157 | ); |
---|
[8403] | 158 | |
---|
| 159 | $_SESSION['page_infos'] = array( |
---|
| 160 | l10n('Information data registered in database') |
---|
| 161 | ); |
---|
| 162 | |
---|
| 163 | // let's refresh the page because we the current set might be modified |
---|
[8422] | 164 | if ('with no album' == $page['prefilter']) |
---|
| 165 | { |
---|
| 166 | redirect($redirect_url); |
---|
| 167 | } |
---|
| 168 | |
---|
| 169 | if ('with no virtual album' == $page['prefilter']) |
---|
| 170 | { |
---|
| 171 | $category_info = get_cat_info($_POST['associate']); |
---|
| 172 | if (empty($category_info['dir'])) |
---|
| 173 | { |
---|
| 174 | redirect($redirect_url); |
---|
| 175 | } |
---|
| 176 | } |
---|
[8394] | 177 | } |
---|
| 178 | |
---|
| 179 | if ('dissociate' == $action) |
---|
| 180 | { |
---|
| 181 | // physical links must not be broken, so we must first retrieve image_id |
---|
| 182 | // which create virtual links with the category to "dissociate from". |
---|
| 183 | $query = ' |
---|
| 184 | SELECT id |
---|
| 185 | FROM '.IMAGE_CATEGORY_TABLE.' |
---|
| 186 | INNER JOIN '.IMAGES_TABLE.' ON image_id = id |
---|
| 187 | WHERE category_id = '.$_POST['dissociate'].' |
---|
| 188 | AND id IN ('.implode(',', $collection).') |
---|
| 189 | AND ( |
---|
| 190 | category_id != storage_category_id |
---|
| 191 | OR storage_category_id IS NULL |
---|
| 192 | ) |
---|
| 193 | ;'; |
---|
| 194 | $dissociables = array_from_query($query, 'id'); |
---|
| 195 | |
---|
| 196 | if (!empty($dissociables)) |
---|
| 197 | { |
---|
| 198 | $query = ' |
---|
| 199 | DELETE |
---|
| 200 | FROM '.IMAGE_CATEGORY_TABLE.' |
---|
| 201 | WHERE category_id = '.$_POST['dissociate'].' |
---|
| 202 | AND image_id IN ('.implode(',', $dissociables).') |
---|
| 203 | '; |
---|
| 204 | pwg_query($query); |
---|
| 205 | |
---|
[8403] | 206 | update_category($_POST['dissociate']); |
---|
| 207 | |
---|
| 208 | $_SESSION['page_infos'] = array( |
---|
| 209 | l10n('Information data registered in database') |
---|
| 210 | ); |
---|
| 211 | |
---|
| 212 | // let's refresh the page because we the current set might be modified |
---|
| 213 | redirect($redirect_url); |
---|
[8394] | 214 | } |
---|
| 215 | } |
---|
| 216 | |
---|
| 217 | // author |
---|
| 218 | if ('author' == $action) |
---|
| 219 | { |
---|
[9035] | 220 | if (isset($_POST['remove_author'])) |
---|
| 221 | { |
---|
| 222 | $_POST['author'] = null; |
---|
| 223 | } |
---|
| 224 | |
---|
[8394] | 225 | $datas = array(); |
---|
| 226 | foreach ($collection as $image_id) |
---|
| 227 | { |
---|
| 228 | array_push( |
---|
| 229 | $datas, |
---|
| 230 | array( |
---|
| 231 | 'id' => $image_id, |
---|
| 232 | 'author' => $_POST['author'] |
---|
| 233 | ) |
---|
| 234 | ); |
---|
| 235 | } |
---|
| 236 | |
---|
| 237 | mass_updates( |
---|
| 238 | IMAGES_TABLE, |
---|
| 239 | array('primary' => array('id'), 'update' => array('author')), |
---|
| 240 | $datas |
---|
| 241 | ); |
---|
| 242 | } |
---|
| 243 | |
---|
[8408] | 244 | // title |
---|
| 245 | if ('title' == $action) |
---|
[8394] | 246 | { |
---|
[9035] | 247 | if (isset($_POST['remove_title'])) |
---|
| 248 | { |
---|
| 249 | $_POST['title'] = null; |
---|
| 250 | } |
---|
| 251 | |
---|
[8394] | 252 | $datas = array(); |
---|
| 253 | foreach ($collection as $image_id) |
---|
| 254 | { |
---|
| 255 | array_push( |
---|
| 256 | $datas, |
---|
| 257 | array( |
---|
| 258 | 'id' => $image_id, |
---|
[8408] | 259 | 'name' => $_POST['title'] |
---|
[8394] | 260 | ) |
---|
| 261 | ); |
---|
| 262 | } |
---|
| 263 | |
---|
| 264 | mass_updates( |
---|
| 265 | IMAGES_TABLE, |
---|
| 266 | array('primary' => array('id'), 'update' => array('name')), |
---|
| 267 | $datas |
---|
| 268 | ); |
---|
| 269 | } |
---|
| 270 | |
---|
| 271 | // date_creation |
---|
| 272 | if ('date_creation' == $action) |
---|
| 273 | { |
---|
| 274 | $date_creation = sprintf( |
---|
| 275 | '%u-%u-%u', |
---|
| 276 | $_POST['date_creation_year'], |
---|
| 277 | $_POST['date_creation_month'], |
---|
| 278 | $_POST['date_creation_day'] |
---|
| 279 | ); |
---|
| 280 | |
---|
[9035] | 281 | if (isset($_POST['remove_date_creation'])) |
---|
| 282 | { |
---|
| 283 | $date_creation = null; |
---|
| 284 | } |
---|
| 285 | |
---|
[8394] | 286 | $datas = array(); |
---|
| 287 | foreach ($collection as $image_id) |
---|
| 288 | { |
---|
| 289 | array_push( |
---|
| 290 | $datas, |
---|
| 291 | array( |
---|
| 292 | 'id' => $image_id, |
---|
| 293 | 'date_creation' => $date_creation |
---|
| 294 | ) |
---|
| 295 | ); |
---|
| 296 | } |
---|
| 297 | |
---|
| 298 | mass_updates( |
---|
| 299 | IMAGES_TABLE, |
---|
| 300 | array('primary' => array('id'), 'update' => array('date_creation')), |
---|
| 301 | $datas |
---|
| 302 | ); |
---|
| 303 | } |
---|
| 304 | |
---|
| 305 | // privacy_level |
---|
| 306 | if ('level' == $action) |
---|
| 307 | { |
---|
| 308 | $datas = array(); |
---|
| 309 | foreach ($collection as $image_id) |
---|
| 310 | { |
---|
| 311 | array_push( |
---|
| 312 | $datas, |
---|
| 313 | array( |
---|
| 314 | 'id' => $image_id, |
---|
| 315 | 'level' => $_POST['level'] |
---|
| 316 | ) |
---|
| 317 | ); |
---|
| 318 | } |
---|
| 319 | |
---|
| 320 | mass_updates( |
---|
| 321 | IMAGES_TABLE, |
---|
| 322 | array('primary' => array('id'), 'update' => array('level')), |
---|
| 323 | $datas |
---|
| 324 | ); |
---|
[8422] | 325 | |
---|
| 326 | if (isset($_SESSION['bulk_manager_filter']['level'])) |
---|
| 327 | { |
---|
| 328 | if ($_POST['level'] < $_SESSION['bulk_manager_filter']['level']) |
---|
| 329 | { |
---|
| 330 | redirect($redirect_url); |
---|
| 331 | } |
---|
| 332 | } |
---|
[8394] | 333 | } |
---|
| 334 | |
---|
| 335 | // add_to_caddie |
---|
| 336 | if ('add_to_caddie' == $action) |
---|
| 337 | { |
---|
| 338 | fill_caddie($collection); |
---|
| 339 | } |
---|
| 340 | |
---|
| 341 | // delete |
---|
| 342 | if ('delete' == $action) |
---|
| 343 | { |
---|
| 344 | if (isset($_POST['confirm_deletion']) and 1 == $_POST['confirm_deletion']) |
---|
| 345 | { |
---|
[8398] | 346 | $deleted_count = delete_elements($collection, true); |
---|
| 347 | if ($deleted_count > 0) |
---|
[8394] | 348 | { |
---|
[8398] | 349 | $_SESSION['page_infos'] = array( |
---|
[8394] | 350 | sprintf( |
---|
| 351 | l10n_dec( |
---|
| 352 | '%d photo was deleted', |
---|
| 353 | '%d photos were deleted', |
---|
[8398] | 354 | $deleted_count |
---|
[8394] | 355 | ), |
---|
[8398] | 356 | $deleted_count |
---|
[8394] | 357 | ) |
---|
| 358 | ); |
---|
| 359 | |
---|
[8398] | 360 | $redirect_url = get_root_url().'admin.php?page='.$_GET['page']; |
---|
| 361 | redirect($redirect_url); |
---|
[8394] | 362 | } |
---|
| 363 | else |
---|
| 364 | { |
---|
| 365 | array_push($page['errors'], l10n('No photo can be deleted')); |
---|
| 366 | } |
---|
| 367 | } |
---|
| 368 | else |
---|
| 369 | { |
---|
| 370 | array_push($page['errors'], l10n('You need to confirm deletion')); |
---|
| 371 | } |
---|
| 372 | } |
---|
[8422] | 373 | |
---|
| 374 | // synchronize metadata |
---|
| 375 | if ('metadata' == $action) |
---|
| 376 | { |
---|
| 377 | $query = ' |
---|
| 378 | SELECT id, path |
---|
| 379 | FROM '.IMAGES_TABLE.' |
---|
| 380 | WHERE id IN ('.implode(',', $collection).') |
---|
| 381 | ;'; |
---|
| 382 | $id_to_path = array(); |
---|
| 383 | $result = pwg_query($query); |
---|
| 384 | while ($row = pwg_db_fetch_assoc($result)) |
---|
| 385 | { |
---|
| 386 | $id_to_path[$row['id']] = $row['path']; |
---|
| 387 | } |
---|
| 388 | |
---|
| 389 | update_metadata($id_to_path); |
---|
| 390 | |
---|
| 391 | array_push( |
---|
| 392 | $page['infos'], |
---|
| 393 | l10n('Metadata synchronized from file') |
---|
| 394 | ); |
---|
| 395 | } |
---|
[9916] | 396 | |
---|
| 397 | trigger_action('element_set_global_action', $action, $collection); |
---|
[8394] | 398 | } |
---|
| 399 | |
---|
| 400 | // +-----------------------------------------------------------------------+ |
---|
| 401 | // | template init | |
---|
| 402 | // +-----------------------------------------------------------------------+ |
---|
| 403 | $template->set_filenames(array('batch_manager_global' => 'batch_manager_global.tpl')); |
---|
| 404 | |
---|
| 405 | $base_url = get_root_url().'admin.php'; |
---|
| 406 | |
---|
[10381] | 407 | $prefilters = array(); |
---|
| 408 | |
---|
| 409 | array_push($prefilters, |
---|
| 410 | array('ID' => 'caddie', 'NAME' => l10n('caddie')), |
---|
| 411 | array('ID' => 'last import', 'NAME' => l10n('last import')), |
---|
| 412 | array('ID' => 'with no album', 'NAME' => l10n('with no album')), |
---|
| 413 | array('ID' => 'with no tag', 'NAME' => l10n('with no tag')), |
---|
| 414 | array('ID' => 'duplicates', 'NAME' => l10n('duplicates')), |
---|
| 415 | array('ID' => 'all photos', 'NAME' => l10n('All')) |
---|
| 416 | ); |
---|
| 417 | |
---|
| 418 | if ($conf['enable_synchronization']) |
---|
| 419 | { |
---|
| 420 | array_push($prefilters, |
---|
| 421 | array('ID' => 'with no virtual album', 'NAME' => l10n('with no virtual album')) |
---|
| 422 | ); |
---|
| 423 | } |
---|
| 424 | |
---|
| 425 | $prefilters = trigger_event('get_batch_manager_prefilters', $prefilters); |
---|
| 426 | usort($prefilters, 'UC_name_compare'); |
---|
| 427 | |
---|
[8394] | 428 | $template->assign( |
---|
| 429 | array( |
---|
[10381] | 430 | 'prefilters' => $prefilters, |
---|
[8394] | 431 | 'filter' => $_SESSION['bulk_manager_filter'], |
---|
| 432 | 'selection' => $collection, |
---|
| 433 | 'U_DISPLAY'=>$base_url.get_query_string_diff(array('display')), |
---|
| 434 | 'F_ACTION'=>$base_url.get_query_string_diff(array('cat')), |
---|
| 435 | ) |
---|
| 436 | ); |
---|
| 437 | |
---|
| 438 | // +-----------------------------------------------------------------------+ |
---|
| 439 | // | caddie options | |
---|
| 440 | // +-----------------------------------------------------------------------+ |
---|
| 441 | |
---|
| 442 | $in_caddie = false; |
---|
| 443 | if (isset($_SESSION['bulk_manager_filter']['prefilter']) |
---|
| 444 | and 'caddie' == $_SESSION['bulk_manager_filter']['prefilter']) |
---|
| 445 | { |
---|
| 446 | $in_caddie = true; |
---|
| 447 | } |
---|
| 448 | $template->assign('IN_CADDIE', $in_caddie); |
---|
| 449 | |
---|
| 450 | // +-----------------------------------------------------------------------+ |
---|
| 451 | // | deletion form | |
---|
| 452 | // +-----------------------------------------------------------------------+ |
---|
| 453 | |
---|
| 454 | // we can only remove photos that have no storage_category_id, in other |
---|
| 455 | // word, it currently (Butterfly) means that the photo was added with |
---|
| 456 | // pLoader |
---|
| 457 | if (count($page['cat_elements_id']) > 0) |
---|
| 458 | { |
---|
| 459 | $query = ' |
---|
| 460 | SELECT |
---|
[8756] | 461 | id |
---|
[8394] | 462 | FROM '.IMAGES_TABLE.' |
---|
| 463 | WHERE id IN ('.implode(',', $page['cat_elements_id']).') |
---|
[8756] | 464 | AND file NOT LIKE \'http%\' |
---|
| 465 | LIMIT 1 |
---|
[8394] | 466 | ;'; |
---|
[8756] | 467 | ; |
---|
[8394] | 468 | |
---|
[8756] | 469 | if ( pwg_db_fetch_row(pwg_query($query)) ) |
---|
[8394] | 470 | { |
---|
| 471 | $template->assign('show_delete_form', true); |
---|
| 472 | } |
---|
| 473 | } |
---|
| 474 | |
---|
| 475 | // +-----------------------------------------------------------------------+ |
---|
| 476 | // | global mode form | |
---|
| 477 | // +-----------------------------------------------------------------------+ |
---|
| 478 | |
---|
| 479 | // privacy level |
---|
| 480 | $template->assign( |
---|
| 481 | array( |
---|
| 482 | 'filter_level_options'=> get_privacy_level_options(), |
---|
| 483 | 'filter_level_options_selected' => isset($_SESSION['bulk_manager_filter']['level']) |
---|
| 484 | ? $_SESSION['bulk_manager_filter']['level'] |
---|
| 485 | : 0, |
---|
| 486 | ) |
---|
| 487 | ); |
---|
| 488 | |
---|
[11854] | 489 | if (!empty($_SESSION['bulk_manager_filter']['tags'])) |
---|
| 490 | { |
---|
| 491 | $query = ' |
---|
| 492 | SELECT id, name |
---|
| 493 | FROM '.TAGS_TABLE.' |
---|
| 494 | WHERE id IN ('.implode(',', $_SESSION['bulk_manager_filter']['tags']).')'; |
---|
| 495 | $template->assign('filter_tags', get_taglist($query)); |
---|
| 496 | } |
---|
| 497 | |
---|
[8394] | 498 | // Virtualy associate a picture to a category |
---|
| 499 | $query = ' |
---|
| 500 | SELECT id,name,uppercats,global_rank |
---|
| 501 | FROM '.CATEGORIES_TABLE.' |
---|
| 502 | ;'; |
---|
| 503 | display_select_cat_wrapper($query, array(), 'associate_options', true); |
---|
| 504 | |
---|
| 505 | // in the filter box, which category to select by default |
---|
| 506 | $selected_category = array(); |
---|
| 507 | |
---|
| 508 | if (isset($_SESSION['bulk_manager_filter']['category'])) |
---|
| 509 | { |
---|
| 510 | $selected_category = array($_SESSION['bulk_manager_filter']['category']); |
---|
| 511 | } |
---|
| 512 | else |
---|
| 513 | { |
---|
| 514 | // we need to know the category in which the last photo was added |
---|
| 515 | $selected_category = array(); |
---|
| 516 | |
---|
| 517 | $query = ' |
---|
| 518 | SELECT |
---|
| 519 | category_id, |
---|
| 520 | id_uppercat |
---|
| 521 | FROM '.IMAGES_TABLE.' AS i |
---|
| 522 | JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON image_id = i.id |
---|
| 523 | JOIN '.CATEGORIES_TABLE.' AS c ON category_id = c.id |
---|
| 524 | ORDER BY i.id DESC |
---|
| 525 | LIMIT 1 |
---|
| 526 | ;'; |
---|
| 527 | $result = pwg_query($query); |
---|
| 528 | if (pwg_db_num_rows($result) > 0) |
---|
| 529 | { |
---|
| 530 | $row = pwg_db_fetch_assoc($result); |
---|
| 531 | |
---|
| 532 | $selected_category = array($row['category_id']); |
---|
| 533 | } |
---|
| 534 | } |
---|
| 535 | |
---|
| 536 | $query = ' |
---|
| 537 | SELECT id,name,uppercats,global_rank |
---|
| 538 | FROM '.CATEGORIES_TABLE.' |
---|
| 539 | ;'; |
---|
| 540 | display_select_cat_wrapper($query, $selected_category, 'filter_category_options', true); |
---|
| 541 | |
---|
[8397] | 542 | // Dissociate from a category : categories listed for dissociation can only |
---|
| 543 | // represent virtual links. We can't create orphans. Links to physical |
---|
| 544 | // categories can't be broken. |
---|
[8394] | 545 | if (count($page['cat_elements_id']) > 0) |
---|
| 546 | { |
---|
| 547 | $query = ' |
---|
| 548 | SELECT |
---|
| 549 | DISTINCT(category_id) AS id, |
---|
| 550 | c.name, |
---|
| 551 | c.uppercats, |
---|
| 552 | c.global_rank |
---|
| 553 | FROM '.IMAGE_CATEGORY_TABLE.' AS ic |
---|
| 554 | JOIN '.CATEGORIES_TABLE.' AS c ON c.id = ic.category_id |
---|
| 555 | JOIN '.IMAGES_TABLE.' AS i ON i.id = ic.image_id |
---|
| 556 | WHERE ic.image_id IN ('.implode(',', $page['cat_elements_id']).') |
---|
| 557 | AND ( |
---|
| 558 | ic.category_id != i.storage_category_id |
---|
| 559 | OR i.storage_category_id IS NULL |
---|
| 560 | ) |
---|
| 561 | ;'; |
---|
| 562 | display_select_cat_wrapper($query, array(), 'dissociate_options', true); |
---|
| 563 | } |
---|
| 564 | |
---|
| 565 | if (count($page['cat_elements_id']) > 0) |
---|
| 566 | { |
---|
| 567 | // remove tags |
---|
| 568 | $tags = get_common_tags($page['cat_elements_id'], -1); |
---|
| 569 | |
---|
| 570 | $template->assign( |
---|
| 571 | array( |
---|
| 572 | 'DEL_TAG_SELECTION' => get_html_tag_selection($tags, 'del_tags'), |
---|
| 573 | ) |
---|
| 574 | ); |
---|
| 575 | } |
---|
| 576 | |
---|
| 577 | // creation date |
---|
| 578 | $day = |
---|
| 579 | empty($_POST['date_creation_day']) ? date('j') : $_POST['date_creation_day']; |
---|
| 580 | |
---|
| 581 | $month = |
---|
| 582 | empty($_POST['date_creation_month']) ? date('n') : $_POST['date_creation_month']; |
---|
| 583 | |
---|
| 584 | $year = |
---|
| 585 | empty($_POST['date_creation_year']) ? date('Y') : $_POST['date_creation_year']; |
---|
| 586 | |
---|
| 587 | $month_list = $lang['month']; |
---|
| 588 | $month_list[0]='------------'; |
---|
| 589 | ksort($month_list); |
---|
| 590 | $template->assign( array( |
---|
| 591 | 'month_list' => $month_list, |
---|
| 592 | 'DATE_CREATION_DAY' => (int)$day, |
---|
| 593 | 'DATE_CREATION_MONTH'=> (int)$month, |
---|
| 594 | 'DATE_CREATION_YEAR' => (int)$year, |
---|
| 595 | ) |
---|
| 596 | ); |
---|
| 597 | |
---|
| 598 | // image level options |
---|
| 599 | $template->assign( |
---|
| 600 | array( |
---|
| 601 | 'level_options'=> get_privacy_level_options(), |
---|
| 602 | 'level_options_selected' => 0, |
---|
| 603 | ) |
---|
| 604 | ); |
---|
| 605 | |
---|
[8422] | 606 | // metadata |
---|
| 607 | include_once( PHPWG_ROOT_PATH.'admin/site_reader_local.php'); |
---|
| 608 | $site_reader = new LocalSiteReader('./'); |
---|
| 609 | $used_metadata = implode( ', ', $site_reader->get_metadata_attributes()); |
---|
| 610 | |
---|
| 611 | $template->assign( |
---|
| 612 | array( |
---|
| 613 | 'used_metadata' => $used_metadata, |
---|
| 614 | ) |
---|
| 615 | ); |
---|
| 616 | |
---|
[8394] | 617 | // +-----------------------------------------------------------------------+ |
---|
| 618 | // | global mode thumbnails | |
---|
| 619 | // +-----------------------------------------------------------------------+ |
---|
| 620 | |
---|
| 621 | // how many items to display on this page |
---|
| 622 | if (!empty($_GET['display'])) |
---|
| 623 | { |
---|
| 624 | if ('all' == $_GET['display']) |
---|
| 625 | { |
---|
| 626 | $page['nb_images'] = count($page['cat_elements_id']); |
---|
| 627 | } |
---|
| 628 | else |
---|
| 629 | { |
---|
| 630 | $page['nb_images'] = intval($_GET['display']); |
---|
| 631 | } |
---|
| 632 | } |
---|
| 633 | else |
---|
| 634 | { |
---|
| 635 | $page['nb_images'] = 20; |
---|
| 636 | } |
---|
| 637 | |
---|
| 638 | $nb_thumbs_page = 0; |
---|
| 639 | |
---|
| 640 | if (count($page['cat_elements_id']) > 0) |
---|
| 641 | { |
---|
| 642 | $nav_bar = create_navigation_bar( |
---|
| 643 | $base_url.get_query_string_diff(array('start')), |
---|
| 644 | count($page['cat_elements_id']), |
---|
| 645 | $page['start'], |
---|
| 646 | $page['nb_images'] |
---|
| 647 | ); |
---|
| 648 | $template->assign('navbar', $nav_bar); |
---|
| 649 | |
---|
[8397] | 650 | $is_category = false; |
---|
| 651 | if (isset($_SESSION['bulk_manager_filter']['category']) |
---|
| 652 | and !isset($_SESSION['bulk_manager_filter']['category_recursive'])) |
---|
| 653 | { |
---|
| 654 | $is_category = true; |
---|
| 655 | } |
---|
| 656 | |
---|
[8404] | 657 | if (isset($_SESSION['bulk_manager_filter']['prefilter']) |
---|
| 658 | and 'duplicates' == $_SESSION['bulk_manager_filter']['prefilter']) |
---|
| 659 | { |
---|
| 660 | $conf['order_by'] = ' ORDER BY file, id'; |
---|
| 661 | } |
---|
| 662 | |
---|
| 663 | |
---|
[8394] | 664 | $query = ' |
---|
| 665 | SELECT id,path,tn_ext,file,filesize,level,name |
---|
[8397] | 666 | FROM '.IMAGES_TABLE; |
---|
| 667 | |
---|
| 668 | if ($is_category) |
---|
| 669 | { |
---|
| 670 | $category_info = get_cat_info($_SESSION['bulk_manager_filter']['category']); |
---|
| 671 | |
---|
| 672 | $conf['order_by'] = $conf['order_by_inside_category']; |
---|
| 673 | if (!empty($category_info['image_order'])) |
---|
| 674 | { |
---|
| 675 | $conf['order_by'] = ' ORDER BY '.$category_info['image_order']; |
---|
| 676 | } |
---|
| 677 | |
---|
| 678 | $query.= ' |
---|
| 679 | JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id'; |
---|
| 680 | } |
---|
| 681 | |
---|
| 682 | $query.= ' |
---|
| 683 | WHERE id IN ('.implode(',', $page['cat_elements_id']).')'; |
---|
| 684 | |
---|
| 685 | if ($is_category) |
---|
| 686 | { |
---|
| 687 | $query.= ' |
---|
| 688 | AND category_id = '.$_SESSION['bulk_manager_filter']['category']; |
---|
| 689 | } |
---|
| 690 | |
---|
| 691 | $query.= ' |
---|
[8394] | 692 | '.$conf['order_by'].' |
---|
| 693 | LIMIT '.$page['nb_images'].' OFFSET '.$page['start'].' |
---|
| 694 | ;'; |
---|
| 695 | $result = pwg_query($query); |
---|
| 696 | |
---|
| 697 | // template thumbnail initialization |
---|
| 698 | while ($row = pwg_db_fetch_assoc($result)) |
---|
| 699 | { |
---|
| 700 | $nb_thumbs_page++; |
---|
| 701 | $src = get_thumbnail_url($row); |
---|
| 702 | |
---|
| 703 | $title = $row['name']; |
---|
| 704 | if (empty($title)) |
---|
| 705 | { |
---|
| 706 | $title = get_name_from_file($row['file']); |
---|
| 707 | } |
---|
| 708 | |
---|
| 709 | $template->append( |
---|
| 710 | 'thumbnails', |
---|
| 711 | array( |
---|
| 712 | 'ID' => $row['id'], |
---|
| 713 | 'TN_SRC' => $src, |
---|
| 714 | 'FILE' => $row['file'], |
---|
| 715 | 'TITLE' => $title, |
---|
| 716 | 'LEVEL' => $row['level'] |
---|
| 717 | ) |
---|
| 718 | ); |
---|
| 719 | } |
---|
| 720 | } |
---|
| 721 | |
---|
| 722 | $template->assign( |
---|
| 723 | array( |
---|
| 724 | 'nb_thumbs_page' => $nb_thumbs_page, |
---|
| 725 | 'nb_thumbs_set' => count($page['cat_elements_id']), |
---|
| 726 | ) |
---|
| 727 | ); |
---|
| 728 | |
---|
| 729 | trigger_action('loc_end_element_set_global'); |
---|
| 730 | |
---|
| 731 | //----------------------------------------------------------- sending html code |
---|
| 732 | $template->assign_var_from_handle('ADMIN_CONTENT', 'batch_manager_global'); |
---|
| 733 | ?> |
---|