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