[8394] | 1 | <?php |
---|
| 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 | |
---|
| 164 | trigger_notify('batch_manager_register_filters'); |
---|
[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 | { |
---|
[24834] | 178 | list($type, $value) = explode('-', $filter); |
---|
[28087] | 179 | |
---|
[24834] | 180 | switch ($type) |
---|
| 181 | { |
---|
| 182 | case 'prefilter': |
---|
| 183 | $_SESSION['bulk_manager_filter']['prefilter'] = $value; |
---|
| 184 | break; |
---|
[28087] | 185 | |
---|
[24834] | 186 | case 'album': |
---|
| 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; |
---|
| 207 | } |
---|
[8423] | 208 | } |
---|
[18459] | 209 | } |
---|
[8394] | 210 | |
---|
[24834] | 211 | if (empty($_SESSION['bulk_manager_filter'])) |
---|
[8394] | 212 | { |
---|
| 213 | $_SESSION['bulk_manager_filter'] = array( |
---|
| 214 | 'prefilter' => 'caddie' |
---|
| 215 | ); |
---|
| 216 | } |
---|
| 217 | |
---|
| 218 | // echo '<pre>'; print_r($_SESSION['bulk_manager_filter']); echo '</pre>'; |
---|
| 219 | |
---|
[24834] | 220 | // depending on the current filter (in session), we find the appropriate photos |
---|
[8394] | 221 | $filter_sets = array(); |
---|
| 222 | if (isset($_SESSION['bulk_manager_filter']['prefilter'])) |
---|
| 223 | { |
---|
[24834] | 224 | switch ($_SESSION['bulk_manager_filter']['prefilter']) |
---|
[8394] | 225 | { |
---|
[24834] | 226 | case 'caddie': |
---|
[8394] | 227 | $query = ' |
---|
| 228 | SELECT element_id |
---|
| 229 | FROM '.CADDIE_TABLE.' |
---|
| 230 | WHERE user_id = '.$user['id'].' |
---|
| 231 | ;'; |
---|
[29065] | 232 | $filter_sets[] = query2array($query, null, 'element_id'); |
---|
[28087] | 233 | |
---|
[24834] | 234 | break; |
---|
[8394] | 235 | |
---|
[24834] | 236 | case 'favorites': |
---|
[23746] | 237 | $query = ' |
---|
| 238 | SELECT image_id |
---|
| 239 | FROM '.FAVORITES_TABLE.' |
---|
| 240 | WHERE user_id = '.$user['id'].' |
---|
| 241 | ;'; |
---|
[29065] | 242 | $filter_sets[] = query2array($query, null, 'image_id'); |
---|
[28087] | 243 | |
---|
[24834] | 244 | break; |
---|
[23746] | 245 | |
---|
[24834] | 246 | case 'last_import': |
---|
[8394] | 247 | $query = ' |
---|
| 248 | SELECT MAX(date_available) AS date |
---|
| 249 | FROM '.IMAGES_TABLE.' |
---|
| 250 | ;'; |
---|
| 251 | $row = pwg_db_fetch_assoc(pwg_query($query)); |
---|
| 252 | if (!empty($row['date'])) |
---|
| 253 | { |
---|
| 254 | $query = ' |
---|
| 255 | SELECT id |
---|
| 256 | FROM '.IMAGES_TABLE.' |
---|
| 257 | WHERE date_available BETWEEN '.pwg_db_get_recent_period_expression(1, $row['date']).' AND \''.$row['date'].'\' |
---|
| 258 | ;'; |
---|
[29065] | 259 | $filter_sets[] = query2array($query, null, 'id'); |
---|
[8394] | 260 | } |
---|
[28087] | 261 | |
---|
[24834] | 262 | break; |
---|
[8403] | 263 | |
---|
[24834] | 264 | case 'no_virtual_album': |
---|
[8403] | 265 | // we are searching elements not linked to any virtual category |
---|
| 266 | $query = ' |
---|
| 267 | SELECT id |
---|
| 268 | FROM '.IMAGES_TABLE.' |
---|
| 269 | ;'; |
---|
[29065] | 270 | $all_elements = query2array($query, null, 'id'); |
---|
[9068] | 271 | |
---|
[8403] | 272 | $query = ' |
---|
| 273 | SELECT id |
---|
| 274 | FROM '.CATEGORIES_TABLE.' |
---|
| 275 | WHERE dir IS NULL |
---|
| 276 | ;'; |
---|
[29065] | 277 | $virtual_categories = query2array($query, null, 'id'); |
---|
[8403] | 278 | if (!empty($virtual_categories)) |
---|
| 279 | { |
---|
| 280 | $query = ' |
---|
| 281 | SELECT DISTINCT(image_id) |
---|
| 282 | FROM '.IMAGE_CATEGORY_TABLE.' |
---|
| 283 | WHERE category_id IN ('.implode(',', $virtual_categories).') |
---|
| 284 | ;'; |
---|
[29065] | 285 | $linked_to_virtual = query2array($query, null, 'image_id'); |
---|
[8403] | 286 | } |
---|
| 287 | |
---|
[25018] | 288 | $filter_sets[] = array_diff($all_elements, $linked_to_virtual); |
---|
[28087] | 289 | |
---|
[24834] | 290 | break; |
---|
[8404] | 291 | |
---|
[24834] | 292 | case 'no_album': |
---|
[8419] | 293 | $query = ' |
---|
| 294 | SELECT |
---|
| 295 | id |
---|
| 296 | FROM '.IMAGES_TABLE.' |
---|
| 297 | LEFT JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id |
---|
| 298 | WHERE category_id is null |
---|
| 299 | ;'; |
---|
[29065] | 300 | $filter_sets[] = query2array($query, null, 'id'); |
---|
[28087] | 301 | |
---|
[24834] | 302 | break; |
---|
[8419] | 303 | |
---|
[24834] | 304 | case 'no_tag': |
---|
[8422] | 305 | $query = ' |
---|
| 306 | SELECT |
---|
| 307 | id |
---|
| 308 | FROM '.IMAGES_TABLE.' |
---|
| 309 | LEFT JOIN '.IMAGE_TAG_TABLE.' ON id = image_id |
---|
| 310 | WHERE tag_id is null |
---|
| 311 | ;'; |
---|
[29065] | 312 | $filter_sets[] = query2array($query, null, 'id'); |
---|
[28087] | 313 | |
---|
[24834] | 314 | break; |
---|
[8422] | 315 | |
---|
| 316 | |
---|
[24834] | 317 | case 'duplicates': |
---|
[29244] | 318 | $duplicates_on_fields = array('file'); |
---|
| 319 | |
---|
| 320 | if (isset($_SESSION['bulk_manager_filter']['duplicates_date'])) |
---|
| 321 | { |
---|
| 322 | $duplicates_on_fields[] = 'date_creation'; |
---|
| 323 | } |
---|
| 324 | |
---|
| 325 | if (isset($_SESSION['bulk_manager_filter']['duplicates_dimensions'])) |
---|
| 326 | { |
---|
| 327 | $duplicates_on_fields[] = 'width'; |
---|
| 328 | $duplicates_on_fields[] = 'height'; |
---|
| 329 | } |
---|
| 330 | |
---|
[8404] | 331 | $query = ' |
---|
[29244] | 332 | SELECT |
---|
| 333 | GROUP_CONCAT(id) AS ids |
---|
[8404] | 334 | FROM '.IMAGES_TABLE.' |
---|
[29244] | 335 | GROUP BY '.implode(',', $duplicates_on_fields).' |
---|
[8404] | 336 | HAVING COUNT(*) > 1 |
---|
| 337 | ;'; |
---|
[29244] | 338 | $array_of_ids_string = query2array($query, null, 'ids'); |
---|
[9068] | 339 | |
---|
[29244] | 340 | $ids = array(); |
---|
| 341 | |
---|
| 342 | foreach ($array_of_ids_string as $ids_string) |
---|
| 343 | { |
---|
| 344 | $ids = array_merge($ids, explode(',', $ids_string)); |
---|
| 345 | } |
---|
| 346 | |
---|
| 347 | $filter_sets[] = $ids; |
---|
[28087] | 348 | |
---|
[24834] | 349 | break; |
---|
[9912] | 350 | |
---|
[24834] | 351 | case 'all_photos': |
---|
[28318] | 352 | if ( count($_SESSION['bulk_manager_filter']) == 1 ) |
---|
| 353 | {// make the query only if this is the only filter |
---|
| 354 | $query = ' |
---|
[9912] | 355 | SELECT id |
---|
| 356 | FROM '.IMAGES_TABLE.' |
---|
[14689] | 357 | '.$conf['order_by']; |
---|
[9912] | 358 | |
---|
[29065] | 359 | $filter_sets[] = query2array($query, null, 'id'); |
---|
[28318] | 360 | } |
---|
[24834] | 361 | break; |
---|
[9912] | 362 | } |
---|
[10354] | 363 | |
---|
[28587] | 364 | $filter_sets = trigger_change('perform_batch_manager_prefilters', $filter_sets, $_SESSION['bulk_manager_filter']['prefilter']); |
---|
[8394] | 365 | } |
---|
| 366 | |
---|
| 367 | if (isset($_SESSION['bulk_manager_filter']['category'])) |
---|
| 368 | { |
---|
| 369 | $categories = array(); |
---|
[9068] | 370 | |
---|
[8394] | 371 | if (isset($_SESSION['bulk_manager_filter']['category_recursive'])) |
---|
| 372 | { |
---|
| 373 | $categories = get_subcat_ids(array($_SESSION['bulk_manager_filter']['category'])); |
---|
| 374 | } |
---|
| 375 | else |
---|
| 376 | { |
---|
| 377 | $categories = array($_SESSION['bulk_manager_filter']['category']); |
---|
| 378 | } |
---|
[9068] | 379 | |
---|
[8394] | 380 | $query = ' |
---|
| 381 | SELECT DISTINCT(image_id) |
---|
| 382 | FROM '.IMAGE_CATEGORY_TABLE.' |
---|
| 383 | WHERE category_id IN ('.implode(',', $categories).') |
---|
| 384 | ;'; |
---|
[29065] | 385 | $filter_sets[] = query2array($query, null, 'image_id'); |
---|
[8394] | 386 | } |
---|
| 387 | |
---|
| 388 | if (isset($_SESSION['bulk_manager_filter']['level'])) |
---|
| 389 | { |
---|
[13646] | 390 | $operator = '='; |
---|
| 391 | if (isset($_SESSION['bulk_manager_filter']['level_include_lower'])) |
---|
| 392 | { |
---|
| 393 | $operator = '<='; |
---|
| 394 | } |
---|
[28087] | 395 | |
---|
[8394] | 396 | $query = ' |
---|
| 397 | SELECT id |
---|
| 398 | FROM '.IMAGES_TABLE.' |
---|
[13646] | 399 | WHERE level '.$operator.' '.$_SESSION['bulk_manager_filter']['level'].' |
---|
[14689] | 400 | '.$conf['order_by']; |
---|
| 401 | |
---|
[29065] | 402 | $filter_sets[] = query2array($query, null, 'id'); |
---|
[8394] | 403 | } |
---|
| 404 | |
---|
[11853] | 405 | if (!empty($_SESSION['bulk_manager_filter']['tags'])) |
---|
| 406 | { |
---|
[25018] | 407 | $filter_sets[] = get_image_ids_for_tags( |
---|
| 408 | $_SESSION['bulk_manager_filter']['tags'], |
---|
| 409 | $_SESSION['bulk_manager_filter']['tag_mode'], |
---|
| 410 | null, |
---|
| 411 | null, |
---|
| 412 | false // we don't apply permissions in administration screens |
---|
[12630] | 413 | ); |
---|
[11853] | 414 | } |
---|
| 415 | |
---|
[18988] | 416 | if (isset($_SESSION['bulk_manager_filter']['dimension'])) |
---|
[17931] | 417 | { |
---|
[18758] | 418 | $where_clauses = array(); |
---|
| 419 | if (isset($_SESSION['bulk_manager_filter']['dimension']['min_width'])) |
---|
[17931] | 420 | { |
---|
[18758] | 421 | $where_clause[] = 'width >= '.$_SESSION['bulk_manager_filter']['dimension']['min_width']; |
---|
[17931] | 422 | } |
---|
[18758] | 423 | if (isset($_SESSION['bulk_manager_filter']['dimension']['max_width'])) |
---|
| 424 | { |
---|
| 425 | $where_clause[] = 'width <= '.$_SESSION['bulk_manager_filter']['dimension']['max_width']; |
---|
| 426 | } |
---|
| 427 | if (isset($_SESSION['bulk_manager_filter']['dimension']['min_height'])) |
---|
| 428 | { |
---|
| 429 | $where_clause[] = 'height >= '.$_SESSION['bulk_manager_filter']['dimension']['min_height']; |
---|
| 430 | } |
---|
| 431 | if (isset($_SESSION['bulk_manager_filter']['dimension']['max_height'])) |
---|
| 432 | { |
---|
| 433 | $where_clause[] = 'height <= '.$_SESSION['bulk_manager_filter']['dimension']['max_height']; |
---|
| 434 | } |
---|
[18988] | 435 | if (isset($_SESSION['bulk_manager_filter']['dimension']['min_ratio'])) |
---|
[18758] | 436 | { |
---|
[18988] | 437 | $where_clause[] = 'width/height >= '.$_SESSION['bulk_manager_filter']['dimension']['min_ratio']; |
---|
[18758] | 438 | } |
---|
[18988] | 439 | if (isset($_SESSION['bulk_manager_filter']['dimension']['max_ratio'])) |
---|
[18758] | 440 | { |
---|
[19121] | 441 | // max_ratio is a floor value, so must be a bit increased |
---|
| 442 | $where_clause[] = 'width/height < '.($_SESSION['bulk_manager_filter']['dimension']['max_ratio']+0.01); |
---|
[18758] | 443 | } |
---|
[28087] | 444 | |
---|
[17931] | 445 | $query = ' |
---|
| 446 | SELECT id |
---|
| 447 | FROM '.IMAGES_TABLE.' |
---|
[18758] | 448 | WHERE '.implode(' AND ',$where_clause).' |
---|
[17931] | 449 | '.$conf['order_by']; |
---|
| 450 | |
---|
[29065] | 451 | $filter_sets[] = query2array($query, null, 'id'); |
---|
[17931] | 452 | } |
---|
| 453 | |
---|
[29238] | 454 | if (isset($_SESSION['bulk_manager_filter']['filesize'])) |
---|
| 455 | { |
---|
| 456 | $where_clauses = array(); |
---|
| 457 | |
---|
| 458 | if (isset($_SESSION['bulk_manager_filter']['filesize']['min'])) |
---|
| 459 | { |
---|
| 460 | $where_clause[] = 'filesize >= '.$_SESSION['bulk_manager_filter']['filesize']['min']*1024; |
---|
| 461 | } |
---|
| 462 | |
---|
| 463 | if (isset($_SESSION['bulk_manager_filter']['filesize']['max'])) |
---|
| 464 | { |
---|
| 465 | $where_clause[] = 'filesize <= '.$_SESSION['bulk_manager_filter']['filesize']['max']*1024; |
---|
| 466 | } |
---|
| 467 | |
---|
| 468 | $query = ' |
---|
| 469 | SELECT id |
---|
| 470 | FROM '.IMAGES_TABLE.' |
---|
| 471 | WHERE '.implode(' AND ',$where_clause).' |
---|
| 472 | '.$conf['order_by']; |
---|
| 473 | |
---|
| 474 | $filter_sets[] = query2array($query, null, 'id'); |
---|
| 475 | } |
---|
| 476 | |
---|
[28087] | 477 | if (isset($_SESSION['bulk_manager_filter']['search'])) |
---|
| 478 | { |
---|
| 479 | include_once( PHPWG_ROOT_PATH .'include/functions_search.inc.php' ); |
---|
[28459] | 480 | $res = get_quick_search_results_no_cache($_SESSION['bulk_manager_filter']['search']['q'], array('permissions'=>false)); |
---|
[28087] | 481 | $filter_sets[] = $res['items']; |
---|
| 482 | } |
---|
| 483 | |
---|
[29377] | 484 | $filter_sets = trigger_change('batch_manager_perform_filters', $filter_sets); |
---|
| 485 | |
---|
[8394] | 486 | $current_set = array_shift($filter_sets); |
---|
| 487 | foreach ($filter_sets as $set) |
---|
| 488 | { |
---|
| 489 | $current_set = array_intersect($current_set, $set); |
---|
| 490 | } |
---|
| 491 | $page['cat_elements_id'] = $current_set; |
---|
| 492 | |
---|
[24834] | 493 | |
---|
[8394] | 494 | // +-----------------------------------------------------------------------+ |
---|
| 495 | // | first element to display | |
---|
| 496 | // +-----------------------------------------------------------------------+ |
---|
| 497 | |
---|
| 498 | // $page['start'] contains the number of the first element in its |
---|
| 499 | // category. For exampe, $page['start'] = 12 means we must show elements #12 |
---|
| 500 | // and $page['nb_images'] next elements |
---|
| 501 | |
---|
[17289] | 502 | if (!isset($_REQUEST['start']) |
---|
| 503 | or !is_numeric($_REQUEST['start']) |
---|
| 504 | or $_REQUEST['start'] < 0 |
---|
| 505 | or (isset($_REQUEST['display']) and 'all' == $_REQUEST['display'])) |
---|
[8394] | 506 | { |
---|
| 507 | $page['start'] = 0; |
---|
| 508 | } |
---|
| 509 | else |
---|
| 510 | { |
---|
[17289] | 511 | $page['start'] = $_REQUEST['start']; |
---|
[8394] | 512 | } |
---|
| 513 | |
---|
[24834] | 514 | |
---|
[8394] | 515 | // +-----------------------------------------------------------------------+ |
---|
[8413] | 516 | // | Tabs | |
---|
[8394] | 517 | // +-----------------------------------------------------------------------+ |
---|
[16928] | 518 | $manager_link = get_root_url().'admin.php?page=batch_manager&mode='; |
---|
[8394] | 519 | |
---|
[9068] | 520 | if (isset($_GET['mode'])) |
---|
[8394] | 521 | { |
---|
[8413] | 522 | $page['tab'] = $_GET['mode']; |
---|
[8394] | 523 | } |
---|
[8413] | 524 | else |
---|
| 525 | { |
---|
[16928] | 526 | $page['tab'] = 'global'; |
---|
[8413] | 527 | } |
---|
| 528 | |
---|
[16928] | 529 | $tabsheet = new tabsheet(); |
---|
| 530 | $tabsheet->set_id('batch_manager'); |
---|
| 531 | $tabsheet->select($page['tab']); |
---|
| 532 | $tabsheet->assign(); |
---|
[8413] | 533 | |
---|
[24834] | 534 | |
---|
[8413] | 535 | // +-----------------------------------------------------------------------+ |
---|
[18988] | 536 | // | dimensions | |
---|
| 537 | // +-----------------------------------------------------------------------+ |
---|
[19069] | 538 | |
---|
| 539 | $widths = array(); |
---|
| 540 | $heights = array(); |
---|
| 541 | $ratios = array(); |
---|
[29249] | 542 | $dimensions = array(); |
---|
[19069] | 543 | |
---|
[19121] | 544 | // get all width, height and ratios |
---|
[18988] | 545 | $query = ' |
---|
| 546 | SELECT |
---|
[19069] | 547 | DISTINCT width, height |
---|
[18988] | 548 | FROM '.IMAGES_TABLE.' |
---|
[19069] | 549 | WHERE width IS NOT NULL |
---|
| 550 | AND height IS NOT NULL |
---|
[18988] | 551 | ;'; |
---|
[19069] | 552 | $result = pwg_query($query); |
---|
[19121] | 553 | |
---|
[24835] | 554 | if (pwg_db_num_rows($result)) |
---|
| 555 | { |
---|
| 556 | while ($row = pwg_db_fetch_assoc($result)) |
---|
| 557 | { |
---|
| 558 | if ($row['width']>0 && $row['height']>0) |
---|
| 559 | { |
---|
| 560 | $widths[] = $row['width']; |
---|
| 561 | $heights[] = $row['height']; |
---|
| 562 | $ratios[] = floor($row['width'] / $row['height'] * 100) / 100; |
---|
| 563 | } |
---|
| 564 | } |
---|
| 565 | } |
---|
| 566 | if (empty($widths)) |
---|
[19920] | 567 | { // arbitrary values, only used when no photos on the gallery |
---|
| 568 | $widths = array(600, 1920, 3500); |
---|
| 569 | $heights = array(480, 1080, 2300); |
---|
| 570 | $ratios = array(1.25, 1.52, 1.78); |
---|
| 571 | } |
---|
[19069] | 572 | |
---|
[29249] | 573 | foreach (array('widths','heights','ratios') as $type) |
---|
| 574 | { |
---|
| 575 | ${$type} = array_unique(${$type}); |
---|
| 576 | sort(${$type}); |
---|
| 577 | $dimensions[$type] = implode(',', ${$type}); |
---|
| 578 | } |
---|
[19920] | 579 | |
---|
[19069] | 580 | $dimensions['bounds'] = array( |
---|
| 581 | 'min_width' => $widths[0], |
---|
[29249] | 582 | 'max_width' => end($widths), |
---|
[19069] | 583 | 'min_height' => $heights[0], |
---|
[29249] | 584 | 'max_height' => end($heights), |
---|
[19069] | 585 | 'min_ratio' => $ratios[0], |
---|
[29249] | 586 | 'max_ratio' => end($ratios), |
---|
[19069] | 587 | ); |
---|
| 588 | |
---|
[19121] | 589 | // find ratio categories |
---|
[19069] | 590 | $ratio_categories = array( |
---|
| 591 | 'portrait' => array(), |
---|
| 592 | 'square' => array(), |
---|
| 593 | 'landscape' => array(), |
---|
| 594 | 'panorama' => array(), |
---|
| 595 | ); |
---|
| 596 | |
---|
| 597 | foreach ($ratios as $ratio) |
---|
| 598 | { |
---|
| 599 | if ($ratio < 0.95) |
---|
| 600 | { |
---|
| 601 | $ratio_categories['portrait'][] = $ratio; |
---|
| 602 | } |
---|
[19121] | 603 | else if ($ratio >= 0.95 and $ratio <= 1.05) |
---|
[19069] | 604 | { |
---|
| 605 | $ratio_categories['square'][] = $ratio; |
---|
| 606 | } |
---|
[19121] | 607 | else if ($ratio > 1.05 and $ratio < 2) |
---|
[19069] | 608 | { |
---|
| 609 | $ratio_categories['landscape'][] = $ratio; |
---|
| 610 | } |
---|
[19121] | 611 | else if ($ratio >= 2) |
---|
[19069] | 612 | { |
---|
| 613 | $ratio_categories['panorama'][] = $ratio; |
---|
| 614 | } |
---|
| 615 | } |
---|
| 616 | |
---|
[29249] | 617 | foreach (array_keys($ratio_categories) as $type) |
---|
[19069] | 618 | { |
---|
[29249] | 619 | if (count($ratio_categories[$type]) > 0) |
---|
[19069] | 620 | { |
---|
[29249] | 621 | $dimensions['ratio_'.$type] = array( |
---|
| 622 | 'min' => $ratio_categories[$type][0], |
---|
| 623 | 'max' => end($ratio_categories[$type]), |
---|
[19069] | 624 | ); |
---|
| 625 | } |
---|
| 626 | } |
---|
| 627 | |
---|
[19121] | 628 | // selected=bound if nothing selected |
---|
[18988] | 629 | foreach (array_keys($dimensions['bounds']) as $type) |
---|
| 630 | { |
---|
[19069] | 631 | $dimensions['selected'][$type] = isset($_SESSION['bulk_manager_filter']['dimension'][$type]) |
---|
| 632 | ? $_SESSION['bulk_manager_filter']['dimension'][$type] |
---|
| 633 | : $dimensions['bounds'][$type] |
---|
| 634 | ; |
---|
[18988] | 635 | } |
---|
[19069] | 636 | |
---|
[18988] | 637 | $template->assign('dimensions', $dimensions); |
---|
| 638 | |
---|
[29238] | 639 | // +-----------------------------------------------------------------------+ |
---|
| 640 | // | filesize | |
---|
| 641 | // +-----------------------------------------------------------------------+ |
---|
[18988] | 642 | |
---|
[29238] | 643 | $filesizes = array(); |
---|
[29249] | 644 | $filesize = array(); |
---|
[29238] | 645 | |
---|
| 646 | $query = ' |
---|
| 647 | SELECT |
---|
| 648 | filesize |
---|
| 649 | FROM '.IMAGES_TABLE.' |
---|
| 650 | WHERE filesize IS NOT NULL |
---|
| 651 | GROUP BY filesize |
---|
| 652 | ;'; |
---|
| 653 | $result = pwg_query($query); |
---|
| 654 | |
---|
| 655 | while ($row = pwg_db_fetch_assoc($result)) |
---|
| 656 | { |
---|
| 657 | $filesizes[] = sprintf('%.1f', $row['filesize']/1024); |
---|
| 658 | } |
---|
| 659 | |
---|
| 660 | if (empty($filesizes)) |
---|
| 661 | { // arbitrary values, only used when no photos on the gallery |
---|
| 662 | $filesizes = array(0, 1, 2, 5, 8, 15); |
---|
| 663 | } |
---|
| 664 | |
---|
| 665 | $filesizes = array_unique($filesizes); |
---|
| 666 | sort($filesizes); |
---|
| 667 | |
---|
| 668 | // add 0.1MB to the last value, to make sure the heavier photo will be in |
---|
| 669 | // the result |
---|
| 670 | $filesizes[count($filesizes)-1]+= 0.1; |
---|
| 671 | |
---|
| 672 | $filesize['list'] = implode(',', $filesizes); |
---|
| 673 | |
---|
| 674 | $filesize['bounds'] = array( |
---|
| 675 | 'min' => $filesizes[0], |
---|
[29249] | 676 | 'max' => end($filesizes), |
---|
[29238] | 677 | ); |
---|
| 678 | |
---|
| 679 | // selected=bound if nothing selected |
---|
| 680 | foreach (array_keys($filesize['bounds']) as $type) |
---|
| 681 | { |
---|
| 682 | $filesize['selected'][$type] = isset($_SESSION['bulk_manager_filter']['filesize'][$type]) |
---|
| 683 | ? $_SESSION['bulk_manager_filter']['filesize'][$type] |
---|
| 684 | : $filesize['bounds'][$type] |
---|
| 685 | ; |
---|
| 686 | } |
---|
| 687 | |
---|
| 688 | $template->assign('filesize', $filesize); |
---|
| 689 | |
---|
[18988] | 690 | // +-----------------------------------------------------------------------+ |
---|
[8413] | 691 | // | open specific mode | |
---|
| 692 | // +-----------------------------------------------------------------------+ |
---|
| 693 | |
---|
[16928] | 694 | include(PHPWG_ROOT_PATH.'admin/batch_manager_'.$page['tab'].'.php'); |
---|
[9068] | 695 | ?> |
---|