[8394] | 1 | <?php |
---|
| 2 | // +-----------------------------------------------------------------------+ |
---|
[8728] | 3 | // | Piwigo - a PHP based photo gallery | |
---|
[8394] | 4 | // +-----------------------------------------------------------------------+ |
---|
[19703] | 5 | // | Copyright(C) 2008-2013 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 | |
---|
| 46 | // +-----------------------------------------------------------------------+ |
---|
| 47 | // | initialize current set | |
---|
| 48 | // +-----------------------------------------------------------------------+ |
---|
| 49 | |
---|
| 50 | if (isset($_POST['submitFilter'])) |
---|
| 51 | { |
---|
| 52 | // echo '<pre>'; print_r($_POST); echo '</pre>'; |
---|
[17289] | 53 | unset($_REQUEST['start']); // new photo set must reset the page |
---|
[8394] | 54 | $_SESSION['bulk_manager_filter'] = array(); |
---|
| 55 | |
---|
| 56 | if (isset($_POST['filter_prefilter_use'])) |
---|
| 57 | { |
---|
[10354] | 58 | $_SESSION['bulk_manager_filter']['prefilter'] = $_POST['filter_prefilter']; |
---|
[8394] | 59 | } |
---|
| 60 | |
---|
| 61 | if (isset($_POST['filter_category_use'])) |
---|
| 62 | { |
---|
| 63 | $_SESSION['bulk_manager_filter']['category'] = $_POST['filter_category']; |
---|
| 64 | |
---|
| 65 | if (isset($_POST['filter_category_recursive'])) |
---|
| 66 | { |
---|
| 67 | $_SESSION['bulk_manager_filter']['category_recursive'] = true; |
---|
| 68 | } |
---|
| 69 | } |
---|
| 70 | |
---|
[11853] | 71 | if (isset($_POST['filter_tags_use'])) |
---|
| 72 | { |
---|
| 73 | $_SESSION['bulk_manager_filter']['tags'] = get_tag_ids($_POST['filter_tags'], false); |
---|
[12630] | 74 | |
---|
| 75 | if (isset($_POST['tag_mode']) and in_array($_POST['tag_mode'], array('AND', 'OR'))) |
---|
| 76 | { |
---|
| 77 | $_SESSION['bulk_manager_filter']['tag_mode'] = $_POST['tag_mode']; |
---|
| 78 | } |
---|
[11853] | 79 | } |
---|
| 80 | |
---|
[8394] | 81 | if (isset($_POST['filter_level_use'])) |
---|
| 82 | { |
---|
| 83 | if (in_array($_POST['filter_level'], $conf['available_permission_levels'])) |
---|
| 84 | { |
---|
| 85 | $_SESSION['bulk_manager_filter']['level'] = $_POST['filter_level']; |
---|
[13646] | 86 | |
---|
| 87 | if (isset($_POST['filter_level_include_lower'])) |
---|
| 88 | { |
---|
| 89 | $_SESSION['bulk_manager_filter']['level_include_lower'] = true; |
---|
| 90 | } |
---|
[8394] | 91 | } |
---|
| 92 | } |
---|
[17931] | 93 | |
---|
| 94 | if (isset($_POST['filter_dimension_use'])) |
---|
| 95 | { |
---|
[18758] | 96 | foreach (array('min_width','max_width','min_height','max_height') as $type) |
---|
[17931] | 97 | { |
---|
[18758] | 98 | if ( preg_match('#^[0-9]+$#', $_POST['filter_dimension_'. $type ]) ) |
---|
| 99 | { |
---|
| 100 | $_SESSION['bulk_manager_filter']['dimension'][$type] = $_POST['filter_dimension_'. $type ]; |
---|
| 101 | } |
---|
[17931] | 102 | } |
---|
[18988] | 103 | foreach (array('min_ratio','max_ratio') as $type) |
---|
[17931] | 104 | { |
---|
[18988] | 105 | if ( preg_match('#^[0-9\.]+$#', $_POST['filter_dimension_'. $type ]) ) |
---|
[18758] | 106 | { |
---|
[18988] | 107 | $_SESSION['bulk_manager_filter']['dimension'][$type] = $_POST['filter_dimension_'. $type ]; |
---|
[18758] | 108 | } |
---|
[17931] | 109 | } |
---|
| 110 | } |
---|
[8394] | 111 | } |
---|
[18459] | 112 | else if (isset($_GET['cat'])) |
---|
[8394] | 113 | { |
---|
| 114 | if ('caddie' == $_GET['cat']) |
---|
| 115 | { |
---|
| 116 | $_SESSION['bulk_manager_filter'] = array( |
---|
| 117 | 'prefilter' => 'caddie' |
---|
| 118 | ); |
---|
| 119 | } |
---|
[18459] | 120 | else if ('recent' == $_GET['cat']) |
---|
[8423] | 121 | { |
---|
| 122 | $_SESSION['bulk_manager_filter'] = array( |
---|
| 123 | 'prefilter' => 'last import' |
---|
| 124 | ); |
---|
| 125 | } |
---|
[18459] | 126 | else if (is_numeric($_GET['cat'])) |
---|
[8394] | 127 | { |
---|
| 128 | $_SESSION['bulk_manager_filter'] = array( |
---|
| 129 | 'category' => $_GET['cat'] |
---|
| 130 | ); |
---|
| 131 | } |
---|
[18459] | 132 | } |
---|
| 133 | else if (isset($_GET['tag'])) |
---|
| 134 | { |
---|
| 135 | if (is_numeric($_GET['tag'])) |
---|
[17765] | 136 | { |
---|
[18459] | 137 | $_SESSION['bulk_manager_filter'] = array( |
---|
| 138 | 'tags' => array($_GET['tag']), |
---|
| 139 | 'tag_mode' => 'AND', |
---|
| 140 | ); |
---|
[17765] | 141 | } |
---|
[8394] | 142 | } |
---|
| 143 | |
---|
| 144 | if (!isset($_SESSION['bulk_manager_filter'])) |
---|
| 145 | { |
---|
| 146 | $_SESSION['bulk_manager_filter'] = array( |
---|
| 147 | 'prefilter' => 'caddie' |
---|
| 148 | ); |
---|
| 149 | } |
---|
| 150 | |
---|
| 151 | // echo '<pre>'; print_r($_SESSION['bulk_manager_filter']); echo '</pre>'; |
---|
| 152 | |
---|
| 153 | // depending on the current filter (in session), we find the appropriate |
---|
| 154 | // photos |
---|
| 155 | $filter_sets = array(); |
---|
| 156 | if (isset($_SESSION['bulk_manager_filter']['prefilter'])) |
---|
| 157 | { |
---|
| 158 | if ('caddie' == $_SESSION['bulk_manager_filter']['prefilter']) |
---|
| 159 | { |
---|
| 160 | $query = ' |
---|
| 161 | SELECT element_id |
---|
| 162 | FROM '.CADDIE_TABLE.' |
---|
| 163 | WHERE user_id = '.$user['id'].' |
---|
| 164 | ;'; |
---|
| 165 | array_push( |
---|
| 166 | $filter_sets, |
---|
| 167 | array_from_query($query, 'element_id') |
---|
| 168 | ); |
---|
| 169 | } |
---|
| 170 | |
---|
| 171 | if ('last import'== $_SESSION['bulk_manager_filter']['prefilter']) |
---|
| 172 | { |
---|
| 173 | $query = ' |
---|
| 174 | SELECT MAX(date_available) AS date |
---|
| 175 | FROM '.IMAGES_TABLE.' |
---|
| 176 | ;'; |
---|
| 177 | $row = pwg_db_fetch_assoc(pwg_query($query)); |
---|
| 178 | if (!empty($row['date'])) |
---|
| 179 | { |
---|
| 180 | $query = ' |
---|
| 181 | SELECT id |
---|
| 182 | FROM '.IMAGES_TABLE.' |
---|
| 183 | WHERE date_available BETWEEN '.pwg_db_get_recent_period_expression(1, $row['date']).' AND \''.$row['date'].'\' |
---|
| 184 | ;'; |
---|
| 185 | array_push( |
---|
| 186 | $filter_sets, |
---|
| 187 | array_from_query($query, 'id') |
---|
| 188 | ); |
---|
| 189 | } |
---|
| 190 | } |
---|
[8403] | 191 | |
---|
| 192 | if ('with no virtual album' == $_SESSION['bulk_manager_filter']['prefilter']) |
---|
| 193 | { |
---|
| 194 | // we are searching elements not linked to any virtual category |
---|
| 195 | $query = ' |
---|
| 196 | SELECT id |
---|
| 197 | FROM '.IMAGES_TABLE.' |
---|
| 198 | ;'; |
---|
| 199 | $all_elements = array_from_query($query, 'id'); |
---|
[9068] | 200 | |
---|
[8403] | 201 | $query = ' |
---|
| 202 | SELECT id |
---|
| 203 | FROM '.CATEGORIES_TABLE.' |
---|
| 204 | WHERE dir IS NULL |
---|
| 205 | ;'; |
---|
| 206 | $virtual_categories = array_from_query($query, 'id'); |
---|
| 207 | if (!empty($virtual_categories)) |
---|
| 208 | { |
---|
| 209 | $query = ' |
---|
| 210 | SELECT DISTINCT(image_id) |
---|
| 211 | FROM '.IMAGE_CATEGORY_TABLE.' |
---|
| 212 | WHERE category_id IN ('.implode(',', $virtual_categories).') |
---|
| 213 | ;'; |
---|
| 214 | $linked_to_virtual = array_from_query($query, 'image_id'); |
---|
| 215 | } |
---|
| 216 | |
---|
| 217 | array_push( |
---|
| 218 | $filter_sets, |
---|
| 219 | array_diff($all_elements, $linked_to_virtual) |
---|
| 220 | ); |
---|
| 221 | } |
---|
[8404] | 222 | |
---|
[8419] | 223 | if ('with no album' == $_SESSION['bulk_manager_filter']['prefilter']) |
---|
| 224 | { |
---|
| 225 | $query = ' |
---|
| 226 | SELECT |
---|
| 227 | id |
---|
| 228 | FROM '.IMAGES_TABLE.' |
---|
| 229 | LEFT JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id |
---|
| 230 | WHERE category_id is null |
---|
| 231 | ;'; |
---|
| 232 | array_push( |
---|
| 233 | $filter_sets, |
---|
| 234 | array_from_query($query, 'id') |
---|
| 235 | ); |
---|
| 236 | } |
---|
| 237 | |
---|
[8422] | 238 | if ('with no tag' == $_SESSION['bulk_manager_filter']['prefilter']) |
---|
| 239 | { |
---|
| 240 | $query = ' |
---|
| 241 | SELECT |
---|
| 242 | id |
---|
| 243 | FROM '.IMAGES_TABLE.' |
---|
| 244 | LEFT JOIN '.IMAGE_TAG_TABLE.' ON id = image_id |
---|
| 245 | WHERE tag_id is null |
---|
| 246 | ;'; |
---|
| 247 | array_push( |
---|
| 248 | $filter_sets, |
---|
| 249 | array_from_query($query, 'id') |
---|
| 250 | ); |
---|
| 251 | } |
---|
| 252 | |
---|
| 253 | |
---|
[8404] | 254 | if ('duplicates' == $_SESSION['bulk_manager_filter']['prefilter']) |
---|
| 255 | { |
---|
| 256 | // we could use the group_concat MySQL function to retrieve the list of |
---|
| 257 | // image_ids but it would not be compatible with PostgreSQL, so let's |
---|
| 258 | // perform 2 queries instead. We hope there are not too many duplicates. |
---|
[9068] | 259 | |
---|
[8404] | 260 | $query = ' |
---|
| 261 | SELECT file |
---|
| 262 | FROM '.IMAGES_TABLE.' |
---|
| 263 | GROUP BY file |
---|
| 264 | HAVING COUNT(*) > 1 |
---|
| 265 | ;'; |
---|
| 266 | $duplicate_files = array_from_query($query, 'file'); |
---|
[9068] | 267 | |
---|
[8404] | 268 | $query = ' |
---|
| 269 | SELECT id |
---|
| 270 | FROM '.IMAGES_TABLE.' |
---|
| 271 | WHERE file IN (\''.implode("','", $duplicate_files).'\') |
---|
| 272 | ;'; |
---|
| 273 | |
---|
| 274 | array_push( |
---|
| 275 | $filter_sets, |
---|
| 276 | array_from_query($query, 'id') |
---|
| 277 | ); |
---|
| 278 | } |
---|
[9912] | 279 | |
---|
| 280 | if ('all photos' == $_SESSION['bulk_manager_filter']['prefilter']) |
---|
| 281 | { |
---|
| 282 | $query = ' |
---|
| 283 | SELECT id |
---|
| 284 | FROM '.IMAGES_TABLE.' |
---|
[14689] | 285 | '.$conf['order_by']; |
---|
[9912] | 286 | |
---|
[14689] | 287 | $filter_sets[] = array_from_query($query, 'id'); |
---|
[9912] | 288 | } |
---|
[10354] | 289 | |
---|
[10380] | 290 | $filter_sets = trigger_event('perform_batch_manager_prefilters', $filter_sets, $_SESSION['bulk_manager_filter']['prefilter']); |
---|
[8394] | 291 | } |
---|
| 292 | |
---|
| 293 | if (isset($_SESSION['bulk_manager_filter']['category'])) |
---|
| 294 | { |
---|
| 295 | $categories = array(); |
---|
[9068] | 296 | |
---|
[8394] | 297 | if (isset($_SESSION['bulk_manager_filter']['category_recursive'])) |
---|
| 298 | { |
---|
| 299 | $categories = get_subcat_ids(array($_SESSION['bulk_manager_filter']['category'])); |
---|
| 300 | } |
---|
| 301 | else |
---|
| 302 | { |
---|
| 303 | $categories = array($_SESSION['bulk_manager_filter']['category']); |
---|
| 304 | } |
---|
[9068] | 305 | |
---|
[8394] | 306 | $query = ' |
---|
| 307 | SELECT DISTINCT(image_id) |
---|
| 308 | FROM '.IMAGE_CATEGORY_TABLE.' |
---|
| 309 | WHERE category_id IN ('.implode(',', $categories).') |
---|
| 310 | ;'; |
---|
| 311 | array_push( |
---|
| 312 | $filter_sets, |
---|
| 313 | array_from_query($query, 'image_id') |
---|
| 314 | ); |
---|
| 315 | } |
---|
| 316 | |
---|
| 317 | if (isset($_SESSION['bulk_manager_filter']['level'])) |
---|
| 318 | { |
---|
[13646] | 319 | $operator = '='; |
---|
| 320 | if (isset($_SESSION['bulk_manager_filter']['level_include_lower'])) |
---|
| 321 | { |
---|
| 322 | $operator = '<='; |
---|
| 323 | } |
---|
| 324 | |
---|
[8394] | 325 | $query = ' |
---|
| 326 | SELECT id |
---|
| 327 | FROM '.IMAGES_TABLE.' |
---|
[13646] | 328 | WHERE level '.$operator.' '.$_SESSION['bulk_manager_filter']['level'].' |
---|
[14689] | 329 | '.$conf['order_by']; |
---|
| 330 | |
---|
| 331 | $filter_sets[] = array_from_query($query, 'id'); |
---|
[8394] | 332 | } |
---|
| 333 | |
---|
[11853] | 334 | if (!empty($_SESSION['bulk_manager_filter']['tags'])) |
---|
| 335 | { |
---|
[12630] | 336 | array_push( |
---|
[11853] | 337 | $filter_sets, |
---|
[12630] | 338 | get_image_ids_for_tags( |
---|
| 339 | $_SESSION['bulk_manager_filter']['tags'], |
---|
| 340 | $_SESSION['bulk_manager_filter']['tag_mode'], |
---|
| 341 | null, |
---|
| 342 | null, |
---|
| 343 | false // we don't apply permissions in administration screens |
---|
| 344 | ) |
---|
| 345 | ); |
---|
[11853] | 346 | } |
---|
| 347 | |
---|
[18988] | 348 | if (isset($_SESSION['bulk_manager_filter']['dimension'])) |
---|
[17931] | 349 | { |
---|
[18758] | 350 | $where_clauses = array(); |
---|
| 351 | if (isset($_SESSION['bulk_manager_filter']['dimension']['min_width'])) |
---|
[17931] | 352 | { |
---|
[18758] | 353 | $where_clause[] = 'width >= '.$_SESSION['bulk_manager_filter']['dimension']['min_width']; |
---|
[17931] | 354 | } |
---|
[18758] | 355 | if (isset($_SESSION['bulk_manager_filter']['dimension']['max_width'])) |
---|
| 356 | { |
---|
| 357 | $where_clause[] = 'width <= '.$_SESSION['bulk_manager_filter']['dimension']['max_width']; |
---|
| 358 | } |
---|
| 359 | if (isset($_SESSION['bulk_manager_filter']['dimension']['min_height'])) |
---|
| 360 | { |
---|
| 361 | $where_clause[] = 'height >= '.$_SESSION['bulk_manager_filter']['dimension']['min_height']; |
---|
| 362 | } |
---|
| 363 | if (isset($_SESSION['bulk_manager_filter']['dimension']['max_height'])) |
---|
| 364 | { |
---|
| 365 | $where_clause[] = 'height <= '.$_SESSION['bulk_manager_filter']['dimension']['max_height']; |
---|
| 366 | } |
---|
[18988] | 367 | if (isset($_SESSION['bulk_manager_filter']['dimension']['min_ratio'])) |
---|
[18758] | 368 | { |
---|
[18988] | 369 | $where_clause[] = 'width/height >= '.$_SESSION['bulk_manager_filter']['dimension']['min_ratio']; |
---|
[18758] | 370 | } |
---|
[18988] | 371 | if (isset($_SESSION['bulk_manager_filter']['dimension']['max_ratio'])) |
---|
[18758] | 372 | { |
---|
[19121] | 373 | // max_ratio is a floor value, so must be a bit increased |
---|
| 374 | $where_clause[] = 'width/height < '.($_SESSION['bulk_manager_filter']['dimension']['max_ratio']+0.01); |
---|
[18758] | 375 | } |
---|
[17931] | 376 | |
---|
| 377 | $query = ' |
---|
| 378 | SELECT id |
---|
| 379 | FROM '.IMAGES_TABLE.' |
---|
[18758] | 380 | WHERE '.implode(' AND ',$where_clause).' |
---|
[17931] | 381 | '.$conf['order_by']; |
---|
| 382 | |
---|
| 383 | $filter_sets[] = array_from_query($query, 'id'); |
---|
| 384 | } |
---|
| 385 | |
---|
[8394] | 386 | $current_set = array_shift($filter_sets); |
---|
| 387 | foreach ($filter_sets as $set) |
---|
| 388 | { |
---|
| 389 | $current_set = array_intersect($current_set, $set); |
---|
| 390 | } |
---|
| 391 | $page['cat_elements_id'] = $current_set; |
---|
| 392 | |
---|
| 393 | // +-----------------------------------------------------------------------+ |
---|
| 394 | // | first element to display | |
---|
| 395 | // +-----------------------------------------------------------------------+ |
---|
| 396 | |
---|
| 397 | // $page['start'] contains the number of the first element in its |
---|
| 398 | // category. For exampe, $page['start'] = 12 means we must show elements #12 |
---|
| 399 | // and $page['nb_images'] next elements |
---|
| 400 | |
---|
[17289] | 401 | if (!isset($_REQUEST['start']) |
---|
| 402 | or !is_numeric($_REQUEST['start']) |
---|
| 403 | or $_REQUEST['start'] < 0 |
---|
| 404 | or (isset($_REQUEST['display']) and 'all' == $_REQUEST['display'])) |
---|
[8394] | 405 | { |
---|
| 406 | $page['start'] = 0; |
---|
| 407 | } |
---|
| 408 | else |
---|
| 409 | { |
---|
[17289] | 410 | $page['start'] = $_REQUEST['start']; |
---|
[8394] | 411 | } |
---|
| 412 | |
---|
| 413 | // +-----------------------------------------------------------------------+ |
---|
[8413] | 414 | // | Tabs | |
---|
[8394] | 415 | // +-----------------------------------------------------------------------+ |
---|
[16928] | 416 | $manager_link = get_root_url().'admin.php?page=batch_manager&mode='; |
---|
[8394] | 417 | |
---|
[9068] | 418 | if (isset($_GET['mode'])) |
---|
[8394] | 419 | { |
---|
[8413] | 420 | $page['tab'] = $_GET['mode']; |
---|
[8394] | 421 | } |
---|
[8413] | 422 | else |
---|
| 423 | { |
---|
[16928] | 424 | $page['tab'] = 'global'; |
---|
[8413] | 425 | } |
---|
| 426 | |
---|
[16928] | 427 | $tabsheet = new tabsheet(); |
---|
| 428 | $tabsheet->set_id('batch_manager'); |
---|
| 429 | $tabsheet->select($page['tab']); |
---|
| 430 | $tabsheet->assign(); |
---|
[8413] | 431 | |
---|
| 432 | // +-----------------------------------------------------------------------+ |
---|
[11039] | 433 | // | tags | |
---|
| 434 | // +-----------------------------------------------------------------------+ |
---|
| 435 | |
---|
| 436 | $query = ' |
---|
[11853] | 437 | SELECT id, name |
---|
[11039] | 438 | FROM '.TAGS_TABLE.' |
---|
| 439 | ;'; |
---|
[12259] | 440 | $template->assign('tags', get_taglist($query, false)); |
---|
[11039] | 441 | |
---|
| 442 | // +-----------------------------------------------------------------------+ |
---|
[18988] | 443 | // | dimensions | |
---|
| 444 | // +-----------------------------------------------------------------------+ |
---|
[19069] | 445 | |
---|
| 446 | $widths = array(); |
---|
| 447 | $heights = array(); |
---|
| 448 | $ratios = array(); |
---|
| 449 | |
---|
[19121] | 450 | // get all width, height and ratios |
---|
[18988] | 451 | $query = ' |
---|
| 452 | SELECT |
---|
[19069] | 453 | DISTINCT width, height |
---|
[18988] | 454 | FROM '.IMAGES_TABLE.' |
---|
[19069] | 455 | WHERE width IS NOT NULL |
---|
| 456 | AND height IS NOT NULL |
---|
[18988] | 457 | ;'; |
---|
[19069] | 458 | $result = pwg_query($query); |
---|
[19121] | 459 | |
---|
[19069] | 460 | while ($row = pwg_db_fetch_assoc($result)) |
---|
| 461 | { |
---|
| 462 | $widths[] = $row['width']; |
---|
| 463 | $heights[] = $row['height']; |
---|
| 464 | $ratios[] = floor($row['width'] * 100 / $row['height']) / 100; |
---|
| 465 | } |
---|
| 466 | |
---|
| 467 | $widths = array_unique($widths); |
---|
| 468 | sort($widths); |
---|
| 469 | |
---|
| 470 | $heights = array_unique($heights); |
---|
| 471 | sort($heights); |
---|
| 472 | |
---|
| 473 | $ratios = array_unique($ratios); |
---|
| 474 | sort($ratios); |
---|
| 475 | |
---|
| 476 | $dimensions['widths'] = implode(',', $widths); |
---|
| 477 | $dimensions['heights'] = implode(',', $heights); |
---|
| 478 | $dimensions['ratios'] = implode(',', $ratios); |
---|
| 479 | |
---|
| 480 | $dimensions['bounds'] = array( |
---|
| 481 | 'min_width' => $widths[0], |
---|
| 482 | 'max_width' => $widths[count($widths)-1], |
---|
| 483 | 'min_height' => $heights[0], |
---|
| 484 | 'max_height' => $heights[count($heights)-1], |
---|
| 485 | 'min_ratio' => $ratios[0], |
---|
| 486 | 'max_ratio' => $ratios[count($ratios)-1], |
---|
| 487 | ); |
---|
| 488 | |
---|
[19121] | 489 | // find ratio categories |
---|
[19069] | 490 | $ratio_categories = array( |
---|
| 491 | 'portrait' => array(), |
---|
| 492 | 'square' => array(), |
---|
| 493 | 'landscape' => array(), |
---|
| 494 | 'panorama' => array(), |
---|
| 495 | ); |
---|
| 496 | |
---|
| 497 | foreach ($ratios as $ratio) |
---|
| 498 | { |
---|
| 499 | if ($ratio < 0.95) |
---|
| 500 | { |
---|
| 501 | $ratio_categories['portrait'][] = $ratio; |
---|
| 502 | } |
---|
[19121] | 503 | else if ($ratio >= 0.95 and $ratio <= 1.05) |
---|
[19069] | 504 | { |
---|
| 505 | $ratio_categories['square'][] = $ratio; |
---|
| 506 | } |
---|
[19121] | 507 | else if ($ratio > 1.05 and $ratio < 2) |
---|
[19069] | 508 | { |
---|
| 509 | $ratio_categories['landscape'][] = $ratio; |
---|
| 510 | } |
---|
[19121] | 511 | else if ($ratio >= 2) |
---|
[19069] | 512 | { |
---|
| 513 | $ratio_categories['panorama'][] = $ratio; |
---|
| 514 | } |
---|
| 515 | } |
---|
| 516 | |
---|
| 517 | foreach (array_keys($ratio_categories) as $ratio_category) |
---|
| 518 | { |
---|
| 519 | if (count($ratio_categories[$ratio_category]) > 0) |
---|
| 520 | { |
---|
| 521 | $dimensions['ratio_'.$ratio_category] = array( |
---|
| 522 | 'min' => $ratio_categories[$ratio_category][0], |
---|
| 523 | 'max' => $ratio_categories[$ratio_category][count($ratio_categories[$ratio_category]) - 1] |
---|
| 524 | ); |
---|
| 525 | } |
---|
| 526 | } |
---|
| 527 | |
---|
[19121] | 528 | // selected=bound if nothing selected |
---|
[18988] | 529 | foreach (array_keys($dimensions['bounds']) as $type) |
---|
| 530 | { |
---|
[19069] | 531 | $dimensions['selected'][$type] = isset($_SESSION['bulk_manager_filter']['dimension'][$type]) |
---|
| 532 | ? $_SESSION['bulk_manager_filter']['dimension'][$type] |
---|
| 533 | : $dimensions['bounds'][$type] |
---|
| 534 | ; |
---|
[18988] | 535 | } |
---|
[19069] | 536 | |
---|
[18988] | 537 | $template->assign('dimensions', $dimensions); |
---|
| 538 | |
---|
| 539 | |
---|
| 540 | // +-----------------------------------------------------------------------+ |
---|
[8413] | 541 | // | open specific mode | |
---|
| 542 | // +-----------------------------------------------------------------------+ |
---|
| 543 | |
---|
[16928] | 544 | include(PHPWG_ROOT_PATH.'admin/batch_manager_'.$page['tab'].'.php'); |
---|
[9068] | 545 | ?> |
---|