[755] | 1 | <?php |
---|
| 2 | // +-----------------------------------------------------------------------+ |
---|
[2297] | 3 | // | Piwigo - a PHP based picture gallery | |
---|
| 4 | // +-----------------------------------------------------------------------+ |
---|
[3049] | 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 | // +-----------------------------------------------------------------------+ |
---|
[755] | 23 | |
---|
| 24 | /** |
---|
| 25 | * Management of elements set. Elements can belong to a category or to the |
---|
| 26 | * user caddie. |
---|
[1092] | 27 | * |
---|
[755] | 28 | */ |
---|
[1092] | 29 | |
---|
[755] | 30 | if (!defined('PHPWG_ROOT_PATH')) |
---|
| 31 | { |
---|
| 32 | die('Hacking attempt!'); |
---|
| 33 | } |
---|
| 34 | |
---|
[1072] | 35 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
| 36 | |
---|
[755] | 37 | // +-----------------------------------------------------------------------+ |
---|
[1072] | 38 | // | Check Access and exit when user status is not ok | |
---|
| 39 | // +-----------------------------------------------------------------------+ |
---|
| 40 | check_status(ACCESS_ADMINISTRATOR); |
---|
| 41 | |
---|
| 42 | // +-----------------------------------------------------------------------+ |
---|
[2678] | 43 | // | deletion form submission | |
---|
| 44 | // +-----------------------------------------------------------------------+ |
---|
| 45 | |
---|
| 46 | if (isset($_POST['delete'])) |
---|
| 47 | { |
---|
| 48 | if (isset($_POST['confirm_deletion']) and 1 == $_POST['confirm_deletion']) |
---|
| 49 | { |
---|
| 50 | $collection = array(); |
---|
| 51 | |
---|
| 52 | switch ($_POST['target_deletion']) |
---|
| 53 | { |
---|
| 54 | case 'all' : |
---|
| 55 | { |
---|
| 56 | $collection = $page['cat_elements_id']; |
---|
| 57 | break; |
---|
| 58 | } |
---|
| 59 | case 'selection' : |
---|
| 60 | { |
---|
| 61 | if (!isset($_POST['selection']) or count($_POST['selection']) == 0) |
---|
| 62 | { |
---|
| 63 | array_push($page['errors'], l10n('Select at least one picture')); |
---|
| 64 | } |
---|
| 65 | else |
---|
| 66 | { |
---|
| 67 | $collection = $_POST['selection']; |
---|
| 68 | } |
---|
| 69 | break; |
---|
| 70 | } |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | // filter selection on photos that have no storage_category_id (ie that |
---|
| 74 | // were added via pLoader) |
---|
| 75 | if (count($collection) > 0) |
---|
| 76 | { |
---|
| 77 | $query = ' |
---|
| 78 | SELECT |
---|
| 79 | id |
---|
| 80 | FROM '.IMAGES_TABLE.' |
---|
| 81 | WHERE id IN ('.implode(',', $collection).') |
---|
| 82 | AND storage_category_id IS NULL |
---|
| 83 | ;'; |
---|
| 84 | $deletables = array_from_query($query, 'id'); |
---|
| 85 | |
---|
| 86 | if (count($deletables) > 0) |
---|
| 87 | { |
---|
| 88 | $physical_deletion = true; |
---|
| 89 | delete_elements($deletables, $physical_deletion); |
---|
| 90 | |
---|
| 91 | array_push( |
---|
| 92 | $page['infos'], |
---|
| 93 | sprintf( |
---|
| 94 | l10n_dec( |
---|
| 95 | '%d photo was deleted', |
---|
| 96 | '%d photos were deleted', |
---|
| 97 | count($deletables) |
---|
| 98 | ), |
---|
| 99 | count($deletables) |
---|
| 100 | ) |
---|
| 101 | ); |
---|
| 102 | } |
---|
| 103 | else |
---|
| 104 | { |
---|
| 105 | array_push($page['errors'], l10n('No photo can be deleted')); |
---|
| 106 | } |
---|
| 107 | } |
---|
| 108 | } |
---|
| 109 | else |
---|
| 110 | { |
---|
| 111 | array_push($page['errors'], l10n('You need to confirm deletion')); |
---|
| 112 | } |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | // +-----------------------------------------------------------------------+ |
---|
[755] | 116 | // | global mode form submission | |
---|
| 117 | // +-----------------------------------------------------------------------+ |
---|
| 118 | |
---|
| 119 | if (isset($_POST['submit'])) |
---|
| 120 | { |
---|
| 121 | $collection = array(); |
---|
[1092] | 122 | |
---|
[755] | 123 | // echo '<pre>'; |
---|
[762] | 124 | // print_r($_POST); |
---|
[755] | 125 | // echo '</pre>'; |
---|
| 126 | // exit(); |
---|
| 127 | |
---|
| 128 | switch ($_POST['target']) |
---|
| 129 | { |
---|
| 130 | case 'all' : |
---|
| 131 | { |
---|
[764] | 132 | $collection = $page['cat_elements_id']; |
---|
[755] | 133 | break; |
---|
| 134 | } |
---|
| 135 | case 'selection' : |
---|
| 136 | { |
---|
[875] | 137 | if (!isset($_POST['selection']) or count($_POST['selection']) == 0) |
---|
| 138 | { |
---|
| 139 | array_push($page['errors'], l10n('Select at least one picture')); |
---|
| 140 | } |
---|
| 141 | else |
---|
| 142 | { |
---|
| 143 | $collection = $_POST['selection']; |
---|
| 144 | } |
---|
[755] | 145 | break; |
---|
| 146 | } |
---|
| 147 | } |
---|
| 148 | |
---|
[1119] | 149 | if (isset($_POST['add_tags']) and count($collection) > 0) |
---|
| 150 | { |
---|
| 151 | add_tags($_POST['add_tags'], $collection); |
---|
| 152 | } |
---|
| 153 | |
---|
| 154 | if (isset($_POST['del_tags']) and count($collection) > 0) |
---|
| 155 | { |
---|
| 156 | $query = ' |
---|
| 157 | DELETE |
---|
| 158 | FROM '.IMAGE_TAG_TABLE.' |
---|
| 159 | WHERE image_id IN ('.implode(',', $collection).') |
---|
| 160 | AND tag_id IN ('.implode(',', $_POST['del_tags']).') |
---|
| 161 | ;'; |
---|
| 162 | pwg_query($query); |
---|
| 163 | } |
---|
[1120] | 164 | |
---|
[875] | 165 | if ($_POST['associate'] != 0 and count($collection) > 0) |
---|
[755] | 166 | { |
---|
[1121] | 167 | associate_images_to_categories( |
---|
| 168 | $collection, |
---|
| 169 | array($_POST['associate']) |
---|
| 170 | ); |
---|
[755] | 171 | } |
---|
| 172 | |
---|
[875] | 173 | if ($_POST['dissociate'] != 0 and count($collection) > 0) |
---|
[755] | 174 | { |
---|
[1121] | 175 | // physical links must not be broken, so we must first retrieve image_id |
---|
| 176 | // which create virtual links with the category to "dissociate from". |
---|
[755] | 177 | $query = ' |
---|
[1121] | 178 | SELECT id |
---|
[1065] | 179 | FROM '.IMAGE_CATEGORY_TABLE.' |
---|
[1121] | 180 | INNER JOIN '.IMAGES_TABLE.' ON image_id = id |
---|
[755] | 181 | WHERE category_id = '.$_POST['dissociate'].' |
---|
[1121] | 182 | AND id IN ('.implode(',', $collection).') |
---|
[2575] | 183 | AND ( |
---|
| 184 | category_id != storage_category_id |
---|
| 185 | OR storage_category_id IS NULL |
---|
| 186 | ) |
---|
[755] | 187 | ;'; |
---|
[1121] | 188 | $dissociables = array_from_query($query, 'id'); |
---|
[755] | 189 | |
---|
[2003] | 190 | if (!empty($dissociables)) |
---|
| 191 | { |
---|
| 192 | $query = ' |
---|
[1065] | 193 | DELETE |
---|
| 194 | FROM '.IMAGE_CATEGORY_TABLE.' |
---|
[1121] | 195 | WHERE category_id = '.$_POST['dissociate'].' |
---|
| 196 | AND image_id IN ('.implode(',', $dissociables).') |
---|
[755] | 197 | '; |
---|
[2003] | 198 | pwg_query($query); |
---|
[1609] | 199 | |
---|
[2576] | 200 | // we remove the dissociated images if we are currently displaying the |
---|
| 201 | // category to dissociate from. |
---|
| 202 | if (is_numeric($_GET['cat']) and $_POST['dissociate'] == $_GET['cat']) |
---|
| 203 | { |
---|
| 204 | $page['cat_elements_id'] = array_diff( |
---|
| 205 | $page['cat_elements_id'], |
---|
| 206 | $dissociables |
---|
| 207 | ); |
---|
| 208 | } |
---|
[2003] | 209 | } |
---|
| 210 | |
---|
[1121] | 211 | update_category($_POST['dissociate']); |
---|
[755] | 212 | } |
---|
[762] | 213 | |
---|
| 214 | $datas = array(); |
---|
| 215 | $dbfields = array('primary' => array('id'), 'update' => array()); |
---|
| 216 | |
---|
[2084] | 217 | $formfields = array('author', 'name', 'date_creation', 'level'); |
---|
[762] | 218 | foreach ($formfields as $formfield) |
---|
| 219 | { |
---|
| 220 | if ($_POST[$formfield.'_action'] != 'leave') |
---|
| 221 | { |
---|
| 222 | array_push($dbfields['update'], $formfield); |
---|
| 223 | } |
---|
| 224 | } |
---|
[1092] | 225 | |
---|
[762] | 226 | // updating elements is useful only if needed... |
---|
[875] | 227 | if (count($dbfields['update']) > 0 and count($collection) > 0) |
---|
[762] | 228 | { |
---|
| 229 | $query = ' |
---|
[1119] | 230 | SELECT id |
---|
[762] | 231 | FROM '.IMAGES_TABLE.' |
---|
| 232 | WHERE id IN ('.implode(',', $collection).') |
---|
| 233 | ;'; |
---|
| 234 | $result = pwg_query($query); |
---|
| 235 | |
---|
[4325] | 236 | while ($row = pwg_db_fetch_assoc($result)) |
---|
[762] | 237 | { |
---|
| 238 | $data = array(); |
---|
| 239 | $data['id'] = $row['id']; |
---|
[1092] | 240 | |
---|
[762] | 241 | if ('set' == $_POST['author_action']) |
---|
| 242 | { |
---|
| 243 | $data['author'] = $_POST['author']; |
---|
| 244 | if ('' == $data['author']) |
---|
| 245 | { |
---|
| 246 | unset($data['author']); |
---|
| 247 | } |
---|
| 248 | } |
---|
| 249 | |
---|
| 250 | if ('set' == $_POST['name_action']) |
---|
| 251 | { |
---|
| 252 | $data['name'] = $_POST['name']; |
---|
| 253 | if ('' == $data['name']) |
---|
| 254 | { |
---|
| 255 | unset($data['name']); |
---|
| 256 | } |
---|
| 257 | } |
---|
| 258 | |
---|
| 259 | if ('set' == $_POST['date_creation_action']) |
---|
| 260 | { |
---|
| 261 | $data['date_creation'] = |
---|
| 262 | $_POST['date_creation_year'] |
---|
| 263 | .'-'.$_POST['date_creation_month'] |
---|
| 264 | .'-'.$_POST['date_creation_day'] |
---|
| 265 | ; |
---|
| 266 | } |
---|
[1092] | 267 | |
---|
[2084] | 268 | if ('set' == $_POST['level_action']) |
---|
| 269 | { |
---|
| 270 | $data['level'] = $_POST['level']; |
---|
| 271 | } |
---|
| 272 | |
---|
[762] | 273 | array_push($datas, $data); |
---|
| 274 | } |
---|
[763] | 275 | // echo '<pre>'; print_r($datas); echo '</pre>'; |
---|
[762] | 276 | mass_updates(IMAGES_TABLE, $dbfields, $datas); |
---|
| 277 | } |
---|
[755] | 278 | } |
---|
| 279 | |
---|
| 280 | // +-----------------------------------------------------------------------+ |
---|
| 281 | // | template init | |
---|
| 282 | // +-----------------------------------------------------------------------+ |
---|
| 283 | $template->set_filenames( |
---|
[2530] | 284 | array('element_set_global' => 'element_set_global.tpl')); |
---|
[755] | 285 | |
---|
[2249] | 286 | $base_url = get_root_url().'admin.php'; |
---|
[755] | 287 | |
---|
[762] | 288 | // $form_action = $base_url.'?page=element_set_global'; |
---|
| 289 | |
---|
[2249] | 290 | $template->assign( |
---|
[755] | 291 | array( |
---|
[834] | 292 | 'CATEGORIES_NAV'=>$page['title'], |
---|
[1092] | 293 | |
---|
[764] | 294 | 'U_DISPLAY'=>$base_url.get_query_string_diff(array('display')), |
---|
[1092] | 295 | |
---|
[764] | 296 | 'U_UNIT_MODE' |
---|
| 297 | => |
---|
| 298 | $base_url |
---|
| 299 | .get_query_string_diff(array('mode','display')) |
---|
| 300 | .'&mode=unit', |
---|
[1092] | 301 | |
---|
[762] | 302 | 'F_ACTION'=>$base_url.get_query_string_diff(array()), |
---|
[755] | 303 | ) |
---|
| 304 | ); |
---|
[764] | 305 | |
---|
[755] | 306 | // +-----------------------------------------------------------------------+ |
---|
[764] | 307 | // | caddie options | |
---|
| 308 | // +-----------------------------------------------------------------------+ |
---|
| 309 | |
---|
[2249] | 310 | $template->assign('IN_CADDIE', 'caddie' == $_GET['cat'] ? true : false ); |
---|
[764] | 311 | |
---|
| 312 | // +-----------------------------------------------------------------------+ |
---|
[2678] | 313 | // | deletion form | |
---|
| 314 | // +-----------------------------------------------------------------------+ |
---|
| 315 | |
---|
| 316 | // we can only remove photos that have no storage_category_id, in other |
---|
| 317 | // word, it currently (Butterfly) means that the photo was added with |
---|
| 318 | // pLoader |
---|
| 319 | if (count($page['cat_elements_id']) > 0) |
---|
| 320 | { |
---|
| 321 | $query = ' |
---|
| 322 | SELECT |
---|
| 323 | COUNT(*) |
---|
| 324 | FROM '.IMAGES_TABLE.' |
---|
| 325 | WHERE id IN ('.implode(',', $page['cat_elements_id']).') |
---|
| 326 | AND storage_category_id IS NULL |
---|
| 327 | ;'; |
---|
[4325] | 328 | list($counter) = pwg_db_fetch_row(pwg_query($query)); |
---|
[2678] | 329 | |
---|
| 330 | if ($counter > 0) |
---|
| 331 | { |
---|
| 332 | $template->assign('show_delete_form', true); |
---|
| 333 | } |
---|
| 334 | } |
---|
| 335 | |
---|
| 336 | // +-----------------------------------------------------------------------+ |
---|
[755] | 337 | // | global mode form | |
---|
| 338 | // +-----------------------------------------------------------------------+ |
---|
| 339 | |
---|
| 340 | // Virtualy associate a picture to a category |
---|
| 341 | $query = ' |
---|
| 342 | SELECT id,name,uppercats,global_rank |
---|
| 343 | FROM '.CATEGORIES_TABLE.' |
---|
| 344 | ;'; |
---|
[2249] | 345 | display_select_cat_wrapper($query, array(), 'associate_options', true); |
---|
[755] | 346 | |
---|
| 347 | // Dissociate from a category : categories listed for dissociation can |
---|
| 348 | // only represent virtual links. Links to physical categories can't be |
---|
| 349 | // broken |
---|
[764] | 350 | if (count($page['cat_elements_id']) > 0) |
---|
| 351 | { |
---|
| 352 | $query = ' |
---|
[2575] | 353 | SELECT |
---|
| 354 | DISTINCT(category_id) AS id, |
---|
| 355 | c.name, |
---|
| 356 | c.uppercats, |
---|
| 357 | c.global_rank |
---|
| 358 | FROM '.IMAGE_CATEGORY_TABLE.' AS ic |
---|
| 359 | JOIN '.CATEGORIES_TABLE.' AS c ON c.id = ic.category_id |
---|
| 360 | JOIN '.IMAGES_TABLE.' AS i ON i.id = ic.image_id |
---|
[764] | 361 | WHERE ic.image_id IN ('.implode(',', $page['cat_elements_id']).') |
---|
[2575] | 362 | AND ( |
---|
| 363 | ic.category_id != i.storage_category_id |
---|
| 364 | OR i.storage_category_id IS NULL |
---|
| 365 | ) |
---|
[755] | 366 | ;'; |
---|
[2249] | 367 | display_select_cat_wrapper($query, array(), 'dissociate_options', true); |
---|
[764] | 368 | } |
---|
[755] | 369 | |
---|
[1314] | 370 | $all_tags = get_all_tags(); |
---|
| 371 | |
---|
[2249] | 372 | if (count($all_tags) > 0) |
---|
| 373 | {// add tags |
---|
| 374 | $template->assign( |
---|
| 375 | array( |
---|
| 376 | 'ADD_TAG_SELECTION' => get_html_tag_selection( |
---|
| 377 | $all_tags, |
---|
| 378 | 'add_tags' |
---|
| 379 | ), |
---|
| 380 | ) |
---|
[1314] | 381 | ); |
---|
| 382 | } |
---|
| 383 | |
---|
[1120] | 384 | if (count($page['cat_elements_id']) > 0) |
---|
[762] | 385 | { |
---|
[1120] | 386 | // remove tags |
---|
[1815] | 387 | $tags = get_common_tags($page['cat_elements_id'], -1); |
---|
[1310] | 388 | |
---|
[2249] | 389 | $template->assign( |
---|
[1120] | 390 | array( |
---|
| 391 | 'DEL_TAG_SELECTION' => get_html_tag_selection($tags, 'del_tags'), |
---|
| 392 | ) |
---|
| 393 | ); |
---|
| 394 | } |
---|
[2249] | 395 | |
---|
[762] | 396 | // creation date |
---|
| 397 | $day = |
---|
| 398 | empty($_POST['date_creation_day']) ? date('j') : $_POST['date_creation_day']; |
---|
| 399 | |
---|
[2249] | 400 | $month = |
---|
| 401 | empty($_POST['date_creation_month']) ? date('n') : $_POST['date_creation_month']; |
---|
[762] | 402 | |
---|
[2249] | 403 | $year = |
---|
| 404 | empty($_POST['date_creation_year']) ? date('Y') : $_POST['date_creation_year']; |
---|
[762] | 405 | |
---|
[2249] | 406 | $month_list = $lang['month']; |
---|
| 407 | $month_list[0]='------------'; |
---|
| 408 | ksort($month_list); |
---|
| 409 | $template->assign( array( |
---|
| 410 | 'month_list' => $month_list, |
---|
| 411 | 'DATE_CREATION_DAY' => (int)$day, |
---|
| 412 | 'DATE_CREATION_MONTH'=> (int)$month, |
---|
| 413 | 'DATE_CREATION_YEAR' => (int)$year, |
---|
| 414 | ) |
---|
| 415 | ); |
---|
| 416 | |
---|
[2084] | 417 | // image level options |
---|
[2249] | 418 | $tpl_options = array(); |
---|
[2084] | 419 | foreach ($conf['available_permission_levels'] as $level) |
---|
| 420 | { |
---|
[2249] | 421 | $tpl_options[$level] = l10n( sprintf('Level %d', $level) ); |
---|
| 422 | } |
---|
| 423 | $template->assign( |
---|
[2084] | 424 | array( |
---|
[2249] | 425 | 'level_options'=> $tpl_options, |
---|
| 426 | ) |
---|
| 427 | ); |
---|
[2084] | 428 | |
---|
[755] | 429 | // +-----------------------------------------------------------------------+ |
---|
| 430 | // | global mode thumbnails | |
---|
| 431 | // +-----------------------------------------------------------------------+ |
---|
| 432 | |
---|
[875] | 433 | // how many items to display on this page |
---|
| 434 | if (!empty($_GET['display'])) |
---|
| 435 | { |
---|
| 436 | if ('all' == $_GET['display']) |
---|
| 437 | { |
---|
| 438 | $page['nb_images'] = count($page['cat_elements_id']); |
---|
| 439 | } |
---|
| 440 | else |
---|
| 441 | { |
---|
| 442 | $page['nb_images'] = intval($_GET['display']); |
---|
| 443 | } |
---|
| 444 | } |
---|
| 445 | else |
---|
| 446 | { |
---|
| 447 | $page['nb_images'] = 20; |
---|
| 448 | } |
---|
| 449 | |
---|
[764] | 450 | if (count($page['cat_elements_id']) > 0) |
---|
| 451 | { |
---|
| 452 | $nav_bar = create_navigation_bar( |
---|
| 453 | $base_url.get_query_string_diff(array('start')), |
---|
| 454 | count($page['cat_elements_id']), |
---|
| 455 | $page['start'], |
---|
[1084] | 456 | $page['nb_images'] |
---|
| 457 | ); |
---|
[3172] | 458 | $template->assign('navbar', $nav_bar); |
---|
[764] | 459 | |
---|
| 460 | $query = ' |
---|
[2084] | 461 | SELECT id,path,tn_ext,file,filesize,level |
---|
[764] | 462 | FROM '.IMAGES_TABLE.' |
---|
| 463 | WHERE id IN ('.implode(',', $page['cat_elements_id']).') |
---|
[755] | 464 | '.$conf['order_by'].' |
---|
[4334] | 465 | LIMIT '.$page['nb_images'].' OFFSET '.$page['start'].' |
---|
[755] | 466 | ;'; |
---|
[764] | 467 | $result = pwg_query($query); |
---|
[755] | 468 | |
---|
[764] | 469 | // template thumbnail initialization |
---|
[4325] | 470 | while ($row = pwg_db_fetch_assoc($result)) |
---|
[755] | 471 | { |
---|
[1609] | 472 | $src = get_thumbnail_url($row); |
---|
[1092] | 473 | |
---|
[2249] | 474 | $template->append( |
---|
| 475 | 'thumbnails', |
---|
[764] | 476 | array( |
---|
| 477 | 'ID' => $row['id'], |
---|
[2249] | 478 | 'TN_SRC' => $src, |
---|
| 479 | 'FILE' => $row['file'], |
---|
| 480 | 'TITLE' => get_thumbnail_title($row), |
---|
| 481 | 'LEVEL' => $row['level'] |
---|
[764] | 482 | ) |
---|
| 483 | ); |
---|
[755] | 484 | } |
---|
| 485 | } |
---|
| 486 | |
---|
| 487 | //----------------------------------------------------------- sending html code |
---|
| 488 | $template->assign_var_from_handle('ADMIN_CONTENT', 'element_set_global'); |
---|
| 489 | ?> |
---|