[29609] | 1 | <?php |
---|
[8394] | 2 | // +-----------------------------------------------------------------------+ |
---|
[8728] | 3 | // | Piwigo - a PHP based photo gallery | |
---|
[8394] | 4 | // +-----------------------------------------------------------------------+ |
---|
[26461] | 5 | // | Copyright(C) 2008-2014 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'); |
---|
[8413] | 36 | include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php'); |
---|
[8394] | 37 | |
---|
| 38 | // +-----------------------------------------------------------------------+ |
---|
| 39 | // | Check Access and exit when user status is not ok | |
---|
| 40 | // +-----------------------------------------------------------------------+ |
---|
| 41 | |
---|
| 42 | check_status(ACCESS_ADMINISTRATOR); |
---|
| 43 | |
---|
| 44 | check_input_parameter('selection', $_POST, true, PATTERN_ID); |
---|
| 45 | |
---|
[29076] | 46 | // +-----------------------------------------------------------------------+ |
---|
| 47 | // | specific actions | |
---|
| 48 | // +-----------------------------------------------------------------------+ |
---|
[24834] | 49 | |
---|
[29076] | 50 | if (isset($_GET['action'])) |
---|
| 51 | { |
---|
| 52 | if ('empty_caddie' == $_GET['action']) |
---|
| 53 | { |
---|
| 54 | $query = ' |
---|
| 55 | DELETE FROM '.CADDIE_TABLE.' |
---|
| 56 | WHERE user_id = '.$user['id'].' |
---|
| 57 | ;'; |
---|
| 58 | pwg_query($query); |
---|
| 59 | |
---|
| 60 | $_SESSION['page_infos'] = array( |
---|
| 61 | l10n('Information data registered in database') |
---|
| 62 | ); |
---|
| 63 | |
---|
| 64 | redirect(get_root_url().'admin.php?page='.$_GET['page']); |
---|
| 65 | } |
---|
| 66 | } |
---|
| 67 | |
---|
[8394] | 68 | // +-----------------------------------------------------------------------+ |
---|
| 69 | // | initialize current set | |
---|
| 70 | // +-----------------------------------------------------------------------+ |
---|
| 71 | |
---|
[24834] | 72 | // filters from form |
---|
[8394] | 73 | if (isset($_POST['submitFilter'])) |
---|
| 74 | { |
---|
| 75 | // echo '<pre>'; print_r($_POST); echo '</pre>'; |
---|
[17289] | 76 | unset($_REQUEST['start']); // new photo set must reset the page |
---|
[8394] | 77 | $_SESSION['bulk_manager_filter'] = array(); |
---|
| 78 | |
---|
| 79 | if (isset($_POST['filter_prefilter_use'])) |
---|
| 80 | { |
---|
[10354] | 81 | $_SESSION['bulk_manager_filter']['prefilter'] = $_POST['filter_prefilter']; |
---|
[29244] | 82 | |
---|
| 83 | if ('duplicates' == $_POST['filter_prefilter']) |
---|
| 84 | { |
---|
| 85 | if (isset($_POST['filter_duplicates_date'])) |
---|
| 86 | { |
---|
| 87 | $_SESSION['bulk_manager_filter']['duplicates_date'] = true; |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | if (isset($_POST['filter_duplicates_dimensions'])) |
---|
| 91 | { |
---|
| 92 | $_SESSION['bulk_manager_filter']['duplicates_dimensions'] = true; |
---|
| 93 | } |
---|
| 94 | } |
---|
[8394] | 95 | } |
---|
| 96 | |
---|
| 97 | if (isset($_POST['filter_category_use'])) |
---|
| 98 | { |
---|
| 99 | $_SESSION['bulk_manager_filter']['category'] = $_POST['filter_category']; |
---|
| 100 | |
---|
| 101 | if (isset($_POST['filter_category_recursive'])) |
---|
| 102 | { |
---|
| 103 | $_SESSION['bulk_manager_filter']['category_recursive'] = true; |
---|
| 104 | } |
---|
| 105 | } |
---|
| 106 | |
---|
[11853] | 107 | if (isset($_POST['filter_tags_use'])) |
---|
| 108 | { |
---|
| 109 | $_SESSION['bulk_manager_filter']['tags'] = get_tag_ids($_POST['filter_tags'], false); |
---|
[12630] | 110 | |
---|
| 111 | if (isset($_POST['tag_mode']) and in_array($_POST['tag_mode'], array('AND', 'OR'))) |
---|
| 112 | { |
---|
| 113 | $_SESSION['bulk_manager_filter']['tag_mode'] = $_POST['tag_mode']; |
---|
| 114 | } |
---|
[11853] | 115 | } |
---|
| 116 | |
---|
[8394] | 117 | if (isset($_POST['filter_level_use'])) |
---|
| 118 | { |
---|
| 119 | if (in_array($_POST['filter_level'], $conf['available_permission_levels'])) |
---|
| 120 | { |
---|
| 121 | $_SESSION['bulk_manager_filter']['level'] = $_POST['filter_level']; |
---|
[28087] | 122 | |
---|
[13646] | 123 | if (isset($_POST['filter_level_include_lower'])) |
---|
| 124 | { |
---|
| 125 | $_SESSION['bulk_manager_filter']['level_include_lower'] = true; |
---|
| 126 | } |
---|
[8394] | 127 | } |
---|
| 128 | } |
---|
[28087] | 129 | |
---|
[17931] | 130 | if (isset($_POST['filter_dimension_use'])) |
---|
| 131 | { |
---|
[18758] | 132 | foreach (array('min_width','max_width','min_height','max_height') as $type) |
---|
[17931] | 133 | { |
---|
[29245] | 134 | if (filter_var($_POST['filter_dimension_'.$type], FILTER_VALIDATE_INT) !== false) |
---|
[18758] | 135 | { |
---|
| 136 | $_SESSION['bulk_manager_filter']['dimension'][$type] = $_POST['filter_dimension_'. $type ]; |
---|
| 137 | } |
---|
[17931] | 138 | } |
---|
[18988] | 139 | foreach (array('min_ratio','max_ratio') as $type) |
---|
[17931] | 140 | { |
---|
[29245] | 141 | if (filter_var($_POST['filter_dimension_'.$type], FILTER_VALIDATE_FLOAT) !== false) |
---|
[18758] | 142 | { |
---|
[18988] | 143 | $_SESSION['bulk_manager_filter']['dimension'][$type] = $_POST['filter_dimension_'. $type ]; |
---|
[18758] | 144 | } |
---|
[17931] | 145 | } |
---|
| 146 | } |
---|
[28087] | 147 | |
---|
[29238] | 148 | if (isset($_POST['filter_filesize_use'])) |
---|
| 149 | { |
---|
| 150 | foreach (array('min','max') as $type) |
---|
| 151 | { |
---|
[29245] | 152 | if (filter_var($_POST['filter_filesize_'.$type], FILTER_VALIDATE_FLOAT) !== false) |
---|
[29238] | 153 | { |
---|
| 154 | $_SESSION['bulk_manager_filter']['filesize'][$type] = $_POST['filter_filesize_'. $type ]; |
---|
| 155 | } |
---|
| 156 | } |
---|
| 157 | } |
---|
| 158 | |
---|
[28087] | 159 | if (isset($_POST['filter_search_use'])) |
---|
| 160 | { |
---|
| 161 | $_SESSION['bulk_manager_filter']['search']['q'] = $_POST['q']; |
---|
| 162 | } |
---|
[29377] | 163 | |
---|
[29598] | 164 | $_SESSION['bulk_manager_filter'] = trigger_change('batch_manager_register_filters', $_SESSION['bulk_manager_filter']); |
---|
[8394] | 165 | } |
---|
[24834] | 166 | // filters from url |
---|
[28087] | 167 | elseif (isset($_GET['filter'])) |
---|
[8394] | 168 | { |
---|
[24834] | 169 | if (!is_array($_GET['filter'])) |
---|
[8394] | 170 | { |
---|
[24834] | 171 | $_GET['filter'] = explode(',', $_GET['filter']); |
---|
[8394] | 172 | } |
---|
[28087] | 173 | |
---|
[24834] | 174 | $_SESSION['bulk_manager_filter'] = array(); |
---|
[28087] | 175 | |
---|
[24834] | 176 | foreach ($_GET['filter'] as $filter) |
---|
[8423] | 177 | { |
---|
[29505] | 178 | list($type, $value) = explode('-', $filter, 2); |
---|
[28087] | 179 | |
---|
[24834] | 180 | switch ($type) |
---|
| 181 | { |
---|
| 182 | case 'prefilter': |
---|
| 183 | $_SESSION['bulk_manager_filter']['prefilter'] = $value; |
---|
| 184 | break; |
---|
[28087] | 185 | |
---|
[29505] | 186 | case 'album': case 'category': case 'cat': |
---|
[24834] | 187 | if (is_numeric($value)) |
---|
| 188 | { |
---|
| 189 | $_SESSION['bulk_manager_filter']['category'] = $value; |
---|
| 190 | } |
---|
| 191 | break; |
---|
[28087] | 192 | |
---|
[24834] | 193 | case 'tag': |
---|
| 194 | if (is_numeric($value)) |
---|
| 195 | { |
---|
| 196 | $_SESSION['bulk_manager_filter']['tags'] = array($value); |
---|
| 197 | $_SESSION['bulk_manager_filter']['tag_mode'] = 'AND'; |
---|
| 198 | } |
---|
| 199 | break; |
---|
[28087] | 200 | |
---|
[24834] | 201 | case 'level': |
---|
| 202 | if (is_numeric($value) && in_array($value, $conf['available_permission_levels'])) |
---|
| 203 | { |
---|
| 204 | $_SESSION['bulk_manager_filter']['level'] = $value; |
---|
| 205 | } |
---|
| 206 | break; |
---|
[29505] | 207 | |
---|
[29481] | 208 | case 'search': |
---|
| 209 | $_SESSION['bulk_manager_filter']['search']['q'] = $value; |
---|
| 210 | break; |
---|
[29505] | 211 | |
---|
| 212 | case 'dimension': |
---|
| 213 | $dim_map = array('w'=>'width','h'=>'height','r'=>'ratio'); |
---|
| 214 | foreach (explode('-', $value) as $part) |
---|
| 215 | { |
---|
| 216 | $values = explode('..', substr($part, 1)); |
---|
| 217 | if (isset($dim_map[$part[0]])) |
---|
| 218 | { |
---|
| 219 | $type = $dim_map[$part[0]]; |
---|
| 220 | list( |
---|
| 221 | $_SESSION['bulk_manager_filter']['dimension']['min_'.$type], |
---|
| 222 | $_SESSION['bulk_manager_filter']['dimension']['max_'.$type] |
---|
| 223 | ) = $values; |
---|
| 224 | } |
---|
| 225 | } |
---|
| 226 | break; |
---|
| 227 | |
---|
| 228 | case 'filesize': |
---|
| 229 | list( |
---|
| 230 | $_SESSION['bulk_manager_filter']['filesize']['min'], |
---|
| 231 | $_SESSION['bulk_manager_filter']['filesize']['max'] |
---|
| 232 | ) = explode('..', $value); |
---|
| 233 | break; |
---|
| 234 | |
---|
| 235 | default: |
---|
[29598] | 236 | $_SESSION['bulk_manager_filter'] = trigger_change('batch_manager_url_filter', $_SESSION['bulk_manager_filter'], $filter); |
---|
[29505] | 237 | break; |
---|
[24834] | 238 | } |
---|
[8423] | 239 | } |
---|
[18459] | 240 | } |
---|
[8394] | 241 | |
---|
[24834] | 242 | if (empty($_SESSION['bulk_manager_filter'])) |
---|
[8394] | 243 | { |
---|
| 244 | $_SESSION['bulk_manager_filter'] = array( |
---|
| 245 | 'prefilter' => 'caddie' |
---|
| 246 | ); |
---|
| 247 | } |
---|
| 248 | |
---|
| 249 | // echo '<pre>'; print_r($_SESSION['bulk_manager_filter']); echo '</pre>'; |
---|
| 250 | |
---|
[24834] | 251 | // depending on the current filter (in session), we find the appropriate photos |
---|
[8394] | 252 | $filter_sets = array(); |
---|
| 253 | if (isset($_SESSION['bulk_manager_filter']['prefilter'])) |
---|
| 254 | { |
---|
[24834] | 255 | switch ($_SESSION['bulk_manager_filter']['prefilter']) |
---|
[8394] | 256 | { |
---|
[24834] | 257 | case 'caddie': |
---|
[8394] | 258 | $query = ' |
---|
| 259 | SELECT element_id |
---|
| 260 | FROM '.CADDIE_TABLE.' |
---|
| 261 | WHERE user_id = '.$user['id'].' |
---|
| 262 | ;'; |
---|
[29065] | 263 | $filter_sets[] = query2array($query, null, 'element_id'); |
---|
[28087] | 264 | |
---|
[24834] | 265 | break; |
---|
[8394] | 266 | |
---|
[24834] | 267 | case 'favorites': |
---|
[23746] | 268 | $query = ' |
---|
| 269 | SELECT image_id |
---|
| 270 | FROM '.FAVORITES_TABLE.' |
---|
| 271 | WHERE user_id = '.$user['id'].' |
---|
| 272 | ;'; |
---|
[29065] | 273 | $filter_sets[] = query2array($query, null, 'image_id'); |
---|
[28087] | 274 | |
---|
[24834] | 275 | break; |
---|
[23746] | 276 | |
---|
[24834] | 277 | case 'last_import': |
---|
[8394] | 278 | $query = ' |
---|
| 279 | SELECT MAX(date_available) AS date |
---|
| 280 | FROM '.IMAGES_TABLE.' |
---|
| 281 | ;'; |
---|
| 282 | $row = pwg_db_fetch_assoc(pwg_query($query)); |
---|
| 283 | if (!empty($row['date'])) |
---|
| 284 | { |
---|
| 285 | $query = ' |
---|
| 286 | SELECT id |
---|
| 287 | FROM '.IMAGES_TABLE.' |
---|
| 288 | WHERE date_available BETWEEN '.pwg_db_get_recent_period_expression(1, $row['date']).' AND \''.$row['date'].'\' |
---|
| 289 | ;'; |
---|
[29065] | 290 | $filter_sets[] = query2array($query, null, 'id'); |
---|
[8394] | 291 | } |
---|
[28087] | 292 | |
---|
[24834] | 293 | break; |
---|
[8403] | 294 | |
---|
[24834] | 295 | case 'no_virtual_album': |
---|
[8403] | 296 | // we are searching elements not linked to any virtual category |
---|
| 297 | $query = ' |
---|
| 298 | SELECT id |
---|
| 299 | FROM '.IMAGES_TABLE.' |
---|
| 300 | ;'; |
---|
[29065] | 301 | $all_elements = query2array($query, null, 'id'); |
---|
[9068] | 302 | |
---|
[8403] | 303 | $query = ' |
---|
| 304 | SELECT id |
---|
| 305 | FROM '.CATEGORIES_TABLE.' |
---|
| 306 | WHERE dir IS NULL |
---|
| 307 | ;'; |
---|
[29065] | 308 | $virtual_categories = query2array($query, null, 'id'); |
---|
[8403] | 309 | if (!empty($virtual_categories)) |
---|
| 310 | { |
---|
| 311 | $query = ' |
---|
| 312 | SELECT DISTINCT(image_id) |
---|
| 313 | FROM '.IMAGE_CATEGORY_TABLE.' |
---|
| 314 | WHERE category_id IN ('.implode(',', $virtual_categories).') |
---|
| 315 | ;'; |
---|
[29065] | 316 | $linked_to_virtual = query2array($query, null, 'image_id'); |
---|
[8403] | 317 | } |
---|
| 318 | |
---|
[25018] | 319 | $filter_sets[] = array_diff($all_elements, $linked_to_virtual); |
---|
[28087] | 320 | |
---|
[24834] | 321 | break; |
---|
[8404] | 322 | |
---|
[24834] | 323 | case 'no_album': |
---|
[8419] | 324 | $query = ' |
---|
| 325 | SELECT |
---|
| 326 | id |
---|
| 327 | FROM '.IMAGES_TABLE.' |
---|
| 328 | LEFT JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id |
---|
| 329 | WHERE category_id is null |
---|
| 330 | ;'; |
---|
[29065] | 331 | $filter_sets[] = query2array($query, null, 'id'); |
---|
[28087] | 332 | |
---|
[24834] | 333 | break; |
---|
[8419] | 334 | |
---|
[24834] | 335 | case 'no_tag': |
---|
[8422] | 336 | $query = ' |
---|
| 337 | SELECT |
---|
| 338 | id |
---|
| 339 | FROM '.IMAGES_TABLE.' |
---|
| 340 | LEFT JOIN '.IMAGE_TAG_TABLE.' ON id = image_id |
---|
| 341 | WHERE tag_id is null |
---|
| 342 | ;'; |
---|
[29065] | 343 | $filter_sets[] = query2array($query, null, 'id'); |
---|
[28087] | 344 | |
---|
[24834] | 345 | break; |
---|
[8422] | 346 | |
---|
| 347 | |
---|
[24834] | 348 | case 'duplicates': |
---|
[29244] | 349 | $duplicates_on_fields = array('file'); |
---|
| 350 | |
---|
| 351 | if (isset($_SESSION['bulk_manager_filter']['duplicates_date'])) |
---|
| 352 | { |
---|
| 353 | $duplicates_on_fields[] = 'date_creation'; |
---|
| 354 | } |
---|
| 355 | |
---|
| 356 | if (isset($_SESSION['bulk_manager_filter']['duplicates_dimensions'])) |
---|
| 357 | { |
---|
| 358 | $duplicates_on_fields[] = 'width'; |
---|
| 359 | $duplicates_on_fields[] = 'height'; |
---|
| 360 | } |
---|
| 361 | |
---|
[8404] | 362 | $query = ' |
---|
[29244] | 363 | SELECT |
---|
| 364 | GROUP_CONCAT(id) AS ids |
---|
[8404] | 365 | FROM '.IMAGES_TABLE.' |
---|
[29244] | 366 | GROUP BY '.implode(',', $duplicates_on_fields).' |
---|
[8404] | 367 | HAVING COUNT(*) > 1 |
---|
| 368 | ;'; |
---|
[29244] | 369 | $array_of_ids_string = query2array($query, null, 'ids'); |
---|
[9068] | 370 | |
---|
[29244] | 371 | $ids = array(); |
---|
| 372 | |
---|
| 373 | foreach ($array_of_ids_string as $ids_string) |
---|
| 374 | { |
---|
| 375 | $ids = array_merge($ids, explode(',', $ids_string)); |
---|
| 376 | } |
---|
| 377 | |
---|
| 378 | $filter_sets[] = $ids; |
---|
[28087] | 379 | |
---|
[24834] | 380 | break; |
---|
[9912] | 381 | |
---|
[24834] | 382 | case 'all_photos': |
---|
[28318] | 383 | if ( count($_SESSION['bulk_manager_filter']) == 1 ) |
---|
| 384 | {// make the query only if this is the only filter |
---|
| 385 | $query = ' |
---|
[9912] | 386 | SELECT id |
---|
| 387 | FROM '.IMAGES_TABLE.' |
---|
[14689] | 388 | '.$conf['order_by']; |
---|
[9912] | 389 | |
---|
[29065] | 390 | $filter_sets[] = query2array($query, null, 'id'); |
---|
[28318] | 391 | } |
---|
[24834] | 392 | break; |
---|
[29598] | 393 | |
---|
| 394 | default: |
---|
| 395 | $filter_sets = trigger_change('perform_batch_manager_prefilters', $filter_sets, $_SESSION['bulk_manager_filter']['prefilter']); |
---|
| 396 | break; |
---|
[9912] | 397 | } |
---|
[8394] | 398 | } |
---|
| 399 | |
---|
| 400 | if (isset($_SESSION['bulk_manager_filter']['category'])) |
---|
| 401 | { |
---|
| 402 | $categories = array(); |
---|
[9068] | 403 | |
---|
[8394] | 404 | if (isset($_SESSION['bulk_manager_filter']['category_recursive'])) |
---|
| 405 | { |
---|
| 406 | $categories = get_subcat_ids(array($_SESSION['bulk_manager_filter']['category'])); |
---|
| 407 | } |
---|
| 408 | else |
---|
| 409 | { |
---|
| 410 | $categories = array($_SESSION['bulk_manager_filter']['category']); |
---|
| 411 | } |
---|
[9068] | 412 | |
---|
[8394] | 413 | $query = ' |
---|
| 414 | SELECT DISTINCT(image_id) |
---|
| 415 | FROM '.IMAGE_CATEGORY_TABLE.' |
---|
| 416 | WHERE category_id IN ('.implode(',', $categories).') |
---|
| 417 | ;'; |
---|
[29065] | 418 | $filter_sets[] = query2array($query, null, 'image_id'); |
---|
[8394] | 419 | } |
---|
| 420 | |
---|
| 421 | if (isset($_SESSION['bulk_manager_filter']['level'])) |
---|
| 422 | { |
---|
[13646] | 423 | $operator = '='; |
---|
| 424 | if (isset($_SESSION['bulk_manager_filter']['level_include_lower'])) |
---|
| 425 | { |
---|
| 426 | $operator = '<='; |
---|
| 427 | } |
---|
[28087] | 428 | |
---|
[8394] | 429 | $query = ' |
---|
| 430 | SELECT id |
---|
| 431 | FROM '.IMAGES_TABLE.' |
---|
[13646] | 432 | WHERE level '.$operator.' '.$_SESSION['bulk_manager_filter']['level'].' |
---|
[14689] | 433 | '.$conf['order_by']; |
---|
| 434 | |
---|
[29065] | 435 | $filter_sets[] = query2array($query, null, 'id'); |
---|
[8394] | 436 | } |
---|
| 437 | |
---|
[11853] | 438 | if (!empty($_SESSION['bulk_manager_filter']['tags'])) |
---|
| 439 | { |
---|
[25018] | 440 | $filter_sets[] = get_image_ids_for_tags( |
---|
| 441 | $_SESSION['bulk_manager_filter']['tags'], |
---|
| 442 | $_SESSION['bulk_manager_filter']['tag_mode'], |
---|
| 443 | null, |
---|
| 444 | null, |
---|
| 445 | false // we don't apply permissions in administration screens |
---|
[12630] | 446 | ); |
---|
[11853] | 447 | } |
---|
| 448 | |
---|
[18988] | 449 | if (isset($_SESSION['bulk_manager_filter']['dimension'])) |
---|
[17931] | 450 | { |
---|
[18758] | 451 | $where_clauses = array(); |
---|
| 452 | if (isset($_SESSION['bulk_manager_filter']['dimension']['min_width'])) |
---|
[17931] | 453 | { |
---|
[18758] | 454 | $where_clause[] = 'width >= '.$_SESSION['bulk_manager_filter']['dimension']['min_width']; |
---|
[17931] | 455 | } |
---|
[18758] | 456 | if (isset($_SESSION['bulk_manager_filter']['dimension']['max_width'])) |
---|
| 457 | { |
---|
| 458 | $where_clause[] = 'width <= '.$_SESSION['bulk_manager_filter']['dimension']['max_width']; |
---|
| 459 | } |
---|
| 460 | if (isset($_SESSION['bulk_manager_filter']['dimension']['min_height'])) |
---|
| 461 | { |
---|
| 462 | $where_clause[] = 'height >= '.$_SESSION['bulk_manager_filter']['dimension']['min_height']; |
---|
| 463 | } |
---|
| 464 | if (isset($_SESSION['bulk_manager_filter']['dimension']['max_height'])) |
---|
| 465 | { |
---|
| 466 | $where_clause[] = 'height <= '.$_SESSION['bulk_manager_filter']['dimension']['max_height']; |
---|
| 467 | } |
---|
[18988] | 468 | if (isset($_SESSION['bulk_manager_filter']['dimension']['min_ratio'])) |
---|
[18758] | 469 | { |
---|
[18988] | 470 | $where_clause[] = 'width/height >= '.$_SESSION['bulk_manager_filter']['dimension']['min_ratio']; |
---|
[18758] | 471 | } |
---|
[18988] | 472 | if (isset($_SESSION['bulk_manager_filter']['dimension']['max_ratio'])) |
---|
[18758] | 473 | { |
---|
[19121] | 474 | // max_ratio is a floor value, so must be a bit increased |
---|
| 475 | $where_clause[] = 'width/height < '.($_SESSION['bulk_manager_filter']['dimension']['max_ratio']+0.01); |
---|
[18758] | 476 | } |
---|
[28087] | 477 | |
---|
[17931] | 478 | $query = ' |
---|
| 479 | SELECT id |
---|
| 480 | FROM '.IMAGES_TABLE.' |
---|
[18758] | 481 | WHERE '.implode(' AND ',$where_clause).' |
---|
[17931] | 482 | '.$conf['order_by']; |
---|
| 483 | |
---|
[29065] | 484 | $filter_sets[] = query2array($query, null, 'id'); |
---|
[17931] | 485 | } |
---|
| 486 | |
---|
[29238] | 487 | if (isset($_SESSION['bulk_manager_filter']['filesize'])) |
---|
| 488 | { |
---|
| 489 | $where_clauses = array(); |
---|
| 490 | |
---|
| 491 | if (isset($_SESSION['bulk_manager_filter']['filesize']['min'])) |
---|
| 492 | { |
---|
| 493 | $where_clause[] = 'filesize >= '.$_SESSION['bulk_manager_filter']['filesize']['min']*1024; |
---|
| 494 | } |
---|
| 495 | |
---|
| 496 | if (isset($_SESSION['bulk_manager_filter']['filesize']['max'])) |
---|
| 497 | { |
---|
| 498 | $where_clause[] = 'filesize <= '.$_SESSION['bulk_manager_filter']['filesize']['max']*1024; |
---|
| 499 | } |
---|
| 500 | |
---|
| 501 | $query = ' |
---|
| 502 | SELECT id |
---|
| 503 | FROM '.IMAGES_TABLE.' |
---|
| 504 | WHERE '.implode(' AND ',$where_clause).' |
---|
| 505 | '.$conf['order_by']; |
---|
| 506 | |
---|
| 507 | $filter_sets[] = query2array($query, null, 'id'); |
---|
| 508 | } |
---|
| 509 | |
---|
[29600] | 510 | if (isset($_SESSION['bulk_manager_filter']['search']) && |
---|
[29607] | 511 | strlen($_SESSION['bulk_manager_filter']['search']['q'])) |
---|
[28087] | 512 | { |
---|
| 513 | include_once( PHPWG_ROOT_PATH .'include/functions_search.inc.php' ); |
---|
[28459] | 514 | $res = get_quick_search_results_no_cache($_SESSION['bulk_manager_filter']['search']['q'], array('permissions'=>false)); |
---|
[29606] | 515 | if (!empty($res['items']) && !empty($res['qs']['unmatched_terms'])) |
---|
| 516 | { |
---|
[29852] | 517 | $template->assign('no_search_results', array_map('htmlspecialchars', $res['qs']['unmatched_terms']) ); |
---|
[29606] | 518 | } |
---|
[28087] | 519 | $filter_sets[] = $res['items']; |
---|
| 520 | } |
---|
| 521 | |
---|
[29598] | 522 | $filter_sets = trigger_change('batch_manager_perform_filters', $filter_sets, $_SESSION['bulk_manager_filter']); |
---|
[29377] | 523 | |
---|
[8394] | 524 | $current_set = array_shift($filter_sets); |
---|
| 525 | foreach ($filter_sets as $set) |
---|
| 526 | { |
---|
| 527 | $current_set = array_intersect($current_set, $set); |
---|
| 528 | } |
---|
| 529 | $page['cat_elements_id'] = $current_set; |
---|
| 530 | |
---|
[24834] | 531 | |
---|
[8394] | 532 | // +-----------------------------------------------------------------------+ |
---|
| 533 | // | first element to display | |
---|
| 534 | // +-----------------------------------------------------------------------+ |
---|
| 535 | |
---|
| 536 | // $page['start'] contains the number of the first element in its |
---|
| 537 | // category. For exampe, $page['start'] = 12 means we must show elements #12 |
---|
| 538 | // and $page['nb_images'] next elements |
---|
| 539 | |
---|
[17289] | 540 | if (!isset($_REQUEST['start']) |
---|
| 541 | or !is_numeric($_REQUEST['start']) |
---|
| 542 | or $_REQUEST['start'] < 0 |
---|
| 543 | or (isset($_REQUEST['display']) and 'all' == $_REQUEST['display'])) |
---|
[8394] | 544 | { |
---|
| 545 | $page['start'] = 0; |
---|
| 546 | } |
---|
| 547 | else |
---|
| 548 | { |
---|
[17289] | 549 | $page['start'] = $_REQUEST['start']; |
---|
[8394] | 550 | } |
---|
| 551 | |
---|
[24834] | 552 | |
---|
[8394] | 553 | // +-----------------------------------------------------------------------+ |
---|
[8413] | 554 | // | Tabs | |
---|
[8394] | 555 | // +-----------------------------------------------------------------------+ |
---|
[16928] | 556 | $manager_link = get_root_url().'admin.php?page=batch_manager&mode='; |
---|
[8394] | 557 | |
---|
[9068] | 558 | if (isset($_GET['mode'])) |
---|
[8394] | 559 | { |
---|
[8413] | 560 | $page['tab'] = $_GET['mode']; |
---|
[8394] | 561 | } |
---|
[8413] | 562 | else |
---|
| 563 | { |
---|
[16928] | 564 | $page['tab'] = 'global'; |
---|
[8413] | 565 | } |
---|
| 566 | |
---|
[16928] | 567 | $tabsheet = new tabsheet(); |
---|
| 568 | $tabsheet->set_id('batch_manager'); |
---|
| 569 | $tabsheet->select($page['tab']); |
---|
| 570 | $tabsheet->assign(); |
---|
[8413] | 571 | |
---|
[24834] | 572 | |
---|
[8413] | 573 | // +-----------------------------------------------------------------------+ |
---|
[18988] | 574 | // | dimensions | |
---|
| 575 | // +-----------------------------------------------------------------------+ |
---|
[19069] | 576 | |
---|
| 577 | $widths = array(); |
---|
| 578 | $heights = array(); |
---|
| 579 | $ratios = array(); |
---|
[29249] | 580 | $dimensions = array(); |
---|
[19069] | 581 | |
---|
[19121] | 582 | // get all width, height and ratios |
---|
[18988] | 583 | $query = ' |
---|
| 584 | SELECT |
---|
[19069] | 585 | DISTINCT width, height |
---|
[18988] | 586 | FROM '.IMAGES_TABLE.' |
---|
[19069] | 587 | WHERE width IS NOT NULL |
---|
| 588 | AND height IS NOT NULL |
---|
[18988] | 589 | ;'; |
---|
[19069] | 590 | $result = pwg_query($query); |
---|
[19121] | 591 | |
---|
[24835] | 592 | if (pwg_db_num_rows($result)) |
---|
| 593 | { |
---|
| 594 | while ($row = pwg_db_fetch_assoc($result)) |
---|
| 595 | { |
---|
| 596 | if ($row['width']>0 && $row['height']>0) |
---|
| 597 | { |
---|
| 598 | $widths[] = $row['width']; |
---|
| 599 | $heights[] = $row['height']; |
---|
| 600 | $ratios[] = floor($row['width'] / $row['height'] * 100) / 100; |
---|
| 601 | } |
---|
| 602 | } |
---|
| 603 | } |
---|
| 604 | if (empty($widths)) |
---|
[19920] | 605 | { // arbitrary values, only used when no photos on the gallery |
---|
| 606 | $widths = array(600, 1920, 3500); |
---|
| 607 | $heights = array(480, 1080, 2300); |
---|
| 608 | $ratios = array(1.25, 1.52, 1.78); |
---|
| 609 | } |
---|
[19069] | 610 | |
---|
[29249] | 611 | foreach (array('widths','heights','ratios') as $type) |
---|
| 612 | { |
---|
| 613 | ${$type} = array_unique(${$type}); |
---|
| 614 | sort(${$type}); |
---|
| 615 | $dimensions[$type] = implode(',', ${$type}); |
---|
| 616 | } |
---|
[19920] | 617 | |
---|
[19069] | 618 | $dimensions['bounds'] = array( |
---|
| 619 | 'min_width' => $widths[0], |
---|
[29249] | 620 | 'max_width' => end($widths), |
---|
[19069] | 621 | 'min_height' => $heights[0], |
---|
[29249] | 622 | 'max_height' => end($heights), |
---|
[19069] | 623 | 'min_ratio' => $ratios[0], |
---|
[29249] | 624 | 'max_ratio' => end($ratios), |
---|
[19069] | 625 | ); |
---|
| 626 | |
---|
[19121] | 627 | // find ratio categories |
---|
[19069] | 628 | $ratio_categories = array( |
---|
| 629 | 'portrait' => array(), |
---|
| 630 | 'square' => array(), |
---|
| 631 | 'landscape' => array(), |
---|
| 632 | 'panorama' => array(), |
---|
| 633 | ); |
---|
| 634 | |
---|
| 635 | foreach ($ratios as $ratio) |
---|
| 636 | { |
---|
| 637 | if ($ratio < 0.95) |
---|
| 638 | { |
---|
| 639 | $ratio_categories['portrait'][] = $ratio; |
---|
| 640 | } |
---|
[19121] | 641 | else if ($ratio >= 0.95 and $ratio <= 1.05) |
---|
[19069] | 642 | { |
---|
| 643 | $ratio_categories['square'][] = $ratio; |
---|
| 644 | } |
---|
[19121] | 645 | else if ($ratio > 1.05 and $ratio < 2) |
---|
[19069] | 646 | { |
---|
| 647 | $ratio_categories['landscape'][] = $ratio; |
---|
| 648 | } |
---|
[19121] | 649 | else if ($ratio >= 2) |
---|
[19069] | 650 | { |
---|
| 651 | $ratio_categories['panorama'][] = $ratio; |
---|
| 652 | } |
---|
| 653 | } |
---|
| 654 | |
---|
[29249] | 655 | foreach (array_keys($ratio_categories) as $type) |
---|
[19069] | 656 | { |
---|
[29249] | 657 | if (count($ratio_categories[$type]) > 0) |
---|
[19069] | 658 | { |
---|
[29249] | 659 | $dimensions['ratio_'.$type] = array( |
---|
| 660 | 'min' => $ratio_categories[$type][0], |
---|
| 661 | 'max' => end($ratio_categories[$type]), |
---|
[19069] | 662 | ); |
---|
| 663 | } |
---|
| 664 | } |
---|
| 665 | |
---|
[19121] | 666 | // selected=bound if nothing selected |
---|
[18988] | 667 | foreach (array_keys($dimensions['bounds']) as $type) |
---|
| 668 | { |
---|
[19069] | 669 | $dimensions['selected'][$type] = isset($_SESSION['bulk_manager_filter']['dimension'][$type]) |
---|
| 670 | ? $_SESSION['bulk_manager_filter']['dimension'][$type] |
---|
| 671 | : $dimensions['bounds'][$type] |
---|
| 672 | ; |
---|
[18988] | 673 | } |
---|
[19069] | 674 | |
---|
[18988] | 675 | $template->assign('dimensions', $dimensions); |
---|
| 676 | |
---|
[29238] | 677 | // +-----------------------------------------------------------------------+ |
---|
| 678 | // | filesize | |
---|
| 679 | // +-----------------------------------------------------------------------+ |
---|
[18988] | 680 | |
---|
[29238] | 681 | $filesizes = array(); |
---|
[29249] | 682 | $filesize = array(); |
---|
[29238] | 683 | |
---|
| 684 | $query = ' |
---|
| 685 | SELECT |
---|
| 686 | filesize |
---|
| 687 | FROM '.IMAGES_TABLE.' |
---|
| 688 | WHERE filesize IS NOT NULL |
---|
| 689 | GROUP BY filesize |
---|
| 690 | ;'; |
---|
| 691 | $result = pwg_query($query); |
---|
| 692 | |
---|
| 693 | while ($row = pwg_db_fetch_assoc($result)) |
---|
| 694 | { |
---|
| 695 | $filesizes[] = sprintf('%.1f', $row['filesize']/1024); |
---|
| 696 | } |
---|
| 697 | |
---|
| 698 | if (empty($filesizes)) |
---|
| 699 | { // arbitrary values, only used when no photos on the gallery |
---|
| 700 | $filesizes = array(0, 1, 2, 5, 8, 15); |
---|
| 701 | } |
---|
| 702 | |
---|
| 703 | $filesizes = array_unique($filesizes); |
---|
| 704 | sort($filesizes); |
---|
| 705 | |
---|
| 706 | // add 0.1MB to the last value, to make sure the heavier photo will be in |
---|
| 707 | // the result |
---|
| 708 | $filesizes[count($filesizes)-1]+= 0.1; |
---|
| 709 | |
---|
| 710 | $filesize['list'] = implode(',', $filesizes); |
---|
| 711 | |
---|
| 712 | $filesize['bounds'] = array( |
---|
| 713 | 'min' => $filesizes[0], |
---|
[29249] | 714 | 'max' => end($filesizes), |
---|
[29238] | 715 | ); |
---|
| 716 | |
---|
| 717 | // selected=bound if nothing selected |
---|
| 718 | foreach (array_keys($filesize['bounds']) as $type) |
---|
| 719 | { |
---|
| 720 | $filesize['selected'][$type] = isset($_SESSION['bulk_manager_filter']['filesize'][$type]) |
---|
| 721 | ? $_SESSION['bulk_manager_filter']['filesize'][$type] |
---|
| 722 | : $filesize['bounds'][$type] |
---|
| 723 | ; |
---|
| 724 | } |
---|
| 725 | |
---|
| 726 | $template->assign('filesize', $filesize); |
---|
| 727 | |
---|
[18988] | 728 | // +-----------------------------------------------------------------------+ |
---|
[8413] | 729 | // | open specific mode | |
---|
| 730 | // +-----------------------------------------------------------------------+ |
---|
| 731 | |
---|
[16928] | 732 | include(PHPWG_ROOT_PATH.'admin/batch_manager_'.$page['tab'].'.php'); |
---|
[9068] | 733 | ?> |
---|