[8394] | 1 | <?php |
---|
| 2 | // +-----------------------------------------------------------------------+ |
---|
[8728] | 3 | // | Piwigo - a PHP based photo gallery | |
---|
[8394] | 4 | // +-----------------------------------------------------------------------+ |
---|
[12922] | 5 | // | Copyright(C) 2008-2012 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>'; |
---|
[17290] | 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 | } |
---|
| 93 | } |
---|
[18460] | 94 | else if (isset($_GET['cat'])) |
---|
[8394] | 95 | { |
---|
| 96 | if ('caddie' == $_GET['cat']) |
---|
| 97 | { |
---|
| 98 | $_SESSION['bulk_manager_filter'] = array( |
---|
| 99 | 'prefilter' => 'caddie' |
---|
| 100 | ); |
---|
| 101 | } |
---|
[18460] | 102 | else if ('recent' == $_GET['cat']) |
---|
[8423] | 103 | { |
---|
| 104 | $_SESSION['bulk_manager_filter'] = array( |
---|
| 105 | 'prefilter' => 'last import' |
---|
| 106 | ); |
---|
| 107 | } |
---|
[18460] | 108 | else if (is_numeric($_GET['cat'])) |
---|
[8394] | 109 | { |
---|
| 110 | $_SESSION['bulk_manager_filter'] = array( |
---|
| 111 | 'category' => $_GET['cat'] |
---|
| 112 | ); |
---|
| 113 | } |
---|
[18460] | 114 | } |
---|
| 115 | else if (isset($_GET['tag'])) |
---|
| 116 | { |
---|
| 117 | if (is_numeric($_GET['tag'])) |
---|
[17766] | 118 | { |
---|
[18460] | 119 | $_SESSION['bulk_manager_filter'] = array( |
---|
| 120 | 'tags' => array($_GET['tag']), |
---|
| 121 | 'tag_mode' => 'AND', |
---|
| 122 | ); |
---|
[17766] | 123 | } |
---|
[8394] | 124 | } |
---|
| 125 | |
---|
| 126 | if (!isset($_SESSION['bulk_manager_filter'])) |
---|
| 127 | { |
---|
| 128 | $_SESSION['bulk_manager_filter'] = array( |
---|
| 129 | 'prefilter' => 'caddie' |
---|
| 130 | ); |
---|
| 131 | } |
---|
| 132 | |
---|
| 133 | // echo '<pre>'; print_r($_SESSION['bulk_manager_filter']); echo '</pre>'; |
---|
| 134 | |
---|
| 135 | // depending on the current filter (in session), we find the appropriate |
---|
| 136 | // photos |
---|
| 137 | $filter_sets = array(); |
---|
| 138 | if (isset($_SESSION['bulk_manager_filter']['prefilter'])) |
---|
| 139 | { |
---|
| 140 | if ('caddie' == $_SESSION['bulk_manager_filter']['prefilter']) |
---|
| 141 | { |
---|
| 142 | $query = ' |
---|
| 143 | SELECT element_id |
---|
| 144 | FROM '.CADDIE_TABLE.' |
---|
| 145 | WHERE user_id = '.$user['id'].' |
---|
| 146 | ;'; |
---|
| 147 | array_push( |
---|
| 148 | $filter_sets, |
---|
| 149 | array_from_query($query, 'element_id') |
---|
| 150 | ); |
---|
| 151 | } |
---|
| 152 | |
---|
| 153 | if ('last import'== $_SESSION['bulk_manager_filter']['prefilter']) |
---|
| 154 | { |
---|
| 155 | $query = ' |
---|
| 156 | SELECT MAX(date_available) AS date |
---|
| 157 | FROM '.IMAGES_TABLE.' |
---|
| 158 | ;'; |
---|
| 159 | $row = pwg_db_fetch_assoc(pwg_query($query)); |
---|
| 160 | if (!empty($row['date'])) |
---|
| 161 | { |
---|
| 162 | $query = ' |
---|
| 163 | SELECT id |
---|
| 164 | FROM '.IMAGES_TABLE.' |
---|
| 165 | WHERE date_available BETWEEN '.pwg_db_get_recent_period_expression(1, $row['date']).' AND \''.$row['date'].'\' |
---|
| 166 | ;'; |
---|
| 167 | array_push( |
---|
| 168 | $filter_sets, |
---|
| 169 | array_from_query($query, 'id') |
---|
| 170 | ); |
---|
| 171 | } |
---|
| 172 | } |
---|
[8403] | 173 | |
---|
| 174 | if ('with no virtual album' == $_SESSION['bulk_manager_filter']['prefilter']) |
---|
| 175 | { |
---|
| 176 | // we are searching elements not linked to any virtual category |
---|
| 177 | $query = ' |
---|
| 178 | SELECT id |
---|
| 179 | FROM '.IMAGES_TABLE.' |
---|
| 180 | ;'; |
---|
| 181 | $all_elements = array_from_query($query, 'id'); |
---|
[9068] | 182 | |
---|
[8403] | 183 | $query = ' |
---|
| 184 | SELECT id |
---|
| 185 | FROM '.CATEGORIES_TABLE.' |
---|
| 186 | WHERE dir IS NULL |
---|
| 187 | ;'; |
---|
| 188 | $virtual_categories = array_from_query($query, 'id'); |
---|
| 189 | if (!empty($virtual_categories)) |
---|
| 190 | { |
---|
| 191 | $query = ' |
---|
| 192 | SELECT DISTINCT(image_id) |
---|
| 193 | FROM '.IMAGE_CATEGORY_TABLE.' |
---|
| 194 | WHERE category_id IN ('.implode(',', $virtual_categories).') |
---|
| 195 | ;'; |
---|
| 196 | $linked_to_virtual = array_from_query($query, 'image_id'); |
---|
| 197 | } |
---|
| 198 | |
---|
| 199 | array_push( |
---|
| 200 | $filter_sets, |
---|
| 201 | array_diff($all_elements, $linked_to_virtual) |
---|
| 202 | ); |
---|
| 203 | } |
---|
[8404] | 204 | |
---|
[8419] | 205 | if ('with no album' == $_SESSION['bulk_manager_filter']['prefilter']) |
---|
| 206 | { |
---|
| 207 | $query = ' |
---|
| 208 | SELECT |
---|
| 209 | id |
---|
| 210 | FROM '.IMAGES_TABLE.' |
---|
| 211 | LEFT JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id |
---|
| 212 | WHERE category_id is null |
---|
| 213 | ;'; |
---|
| 214 | array_push( |
---|
| 215 | $filter_sets, |
---|
| 216 | array_from_query($query, 'id') |
---|
| 217 | ); |
---|
| 218 | } |
---|
| 219 | |
---|
[8422] | 220 | if ('with no tag' == $_SESSION['bulk_manager_filter']['prefilter']) |
---|
| 221 | { |
---|
| 222 | $query = ' |
---|
| 223 | SELECT |
---|
| 224 | id |
---|
| 225 | FROM '.IMAGES_TABLE.' |
---|
| 226 | LEFT JOIN '.IMAGE_TAG_TABLE.' ON id = image_id |
---|
| 227 | WHERE tag_id is null |
---|
| 228 | ;'; |
---|
| 229 | array_push( |
---|
| 230 | $filter_sets, |
---|
| 231 | array_from_query($query, 'id') |
---|
| 232 | ); |
---|
| 233 | } |
---|
| 234 | |
---|
| 235 | |
---|
[8404] | 236 | if ('duplicates' == $_SESSION['bulk_manager_filter']['prefilter']) |
---|
| 237 | { |
---|
| 238 | // we could use the group_concat MySQL function to retrieve the list of |
---|
| 239 | // image_ids but it would not be compatible with PostgreSQL, so let's |
---|
| 240 | // perform 2 queries instead. We hope there are not too many duplicates. |
---|
[9068] | 241 | |
---|
[8404] | 242 | $query = ' |
---|
| 243 | SELECT file |
---|
| 244 | FROM '.IMAGES_TABLE.' |
---|
| 245 | GROUP BY file |
---|
| 246 | HAVING COUNT(*) > 1 |
---|
| 247 | ;'; |
---|
| 248 | $duplicate_files = array_from_query($query, 'file'); |
---|
[9068] | 249 | |
---|
[8404] | 250 | $query = ' |
---|
| 251 | SELECT id |
---|
| 252 | FROM '.IMAGES_TABLE.' |
---|
| 253 | WHERE file IN (\''.implode("','", $duplicate_files).'\') |
---|
| 254 | ;'; |
---|
| 255 | |
---|
| 256 | array_push( |
---|
| 257 | $filter_sets, |
---|
| 258 | array_from_query($query, 'id') |
---|
| 259 | ); |
---|
| 260 | } |
---|
[9912] | 261 | |
---|
| 262 | if ('all photos' == $_SESSION['bulk_manager_filter']['prefilter']) |
---|
| 263 | { |
---|
| 264 | $query = ' |
---|
| 265 | SELECT id |
---|
| 266 | FROM '.IMAGES_TABLE.' |
---|
[14689] | 267 | '.$conf['order_by']; |
---|
[9912] | 268 | |
---|
[14689] | 269 | $filter_sets[] = array_from_query($query, 'id'); |
---|
[9912] | 270 | } |
---|
[10354] | 271 | |
---|
[10380] | 272 | $filter_sets = trigger_event('perform_batch_manager_prefilters', $filter_sets, $_SESSION['bulk_manager_filter']['prefilter']); |
---|
[8394] | 273 | } |
---|
| 274 | |
---|
| 275 | if (isset($_SESSION['bulk_manager_filter']['category'])) |
---|
| 276 | { |
---|
| 277 | $categories = array(); |
---|
[9068] | 278 | |
---|
[8394] | 279 | if (isset($_SESSION['bulk_manager_filter']['category_recursive'])) |
---|
| 280 | { |
---|
| 281 | $categories = get_subcat_ids(array($_SESSION['bulk_manager_filter']['category'])); |
---|
| 282 | } |
---|
| 283 | else |
---|
| 284 | { |
---|
| 285 | $categories = array($_SESSION['bulk_manager_filter']['category']); |
---|
| 286 | } |
---|
[9068] | 287 | |
---|
[8394] | 288 | $query = ' |
---|
| 289 | SELECT DISTINCT(image_id) |
---|
| 290 | FROM '.IMAGE_CATEGORY_TABLE.' |
---|
| 291 | WHERE category_id IN ('.implode(',', $categories).') |
---|
| 292 | ;'; |
---|
| 293 | array_push( |
---|
| 294 | $filter_sets, |
---|
| 295 | array_from_query($query, 'image_id') |
---|
| 296 | ); |
---|
| 297 | } |
---|
| 298 | |
---|
| 299 | if (isset($_SESSION['bulk_manager_filter']['level'])) |
---|
| 300 | { |
---|
[13646] | 301 | $operator = '='; |
---|
| 302 | if (isset($_SESSION['bulk_manager_filter']['level_include_lower'])) |
---|
| 303 | { |
---|
| 304 | $operator = '<='; |
---|
| 305 | } |
---|
| 306 | |
---|
[8394] | 307 | $query = ' |
---|
| 308 | SELECT id |
---|
| 309 | FROM '.IMAGES_TABLE.' |
---|
[13646] | 310 | WHERE level '.$operator.' '.$_SESSION['bulk_manager_filter']['level'].' |
---|
[14689] | 311 | '.$conf['order_by']; |
---|
| 312 | |
---|
| 313 | $filter_sets[] = array_from_query($query, 'id'); |
---|
[8394] | 314 | } |
---|
| 315 | |
---|
[11853] | 316 | if (!empty($_SESSION['bulk_manager_filter']['tags'])) |
---|
| 317 | { |
---|
[12630] | 318 | array_push( |
---|
[11853] | 319 | $filter_sets, |
---|
[12630] | 320 | get_image_ids_for_tags( |
---|
| 321 | $_SESSION['bulk_manager_filter']['tags'], |
---|
| 322 | $_SESSION['bulk_manager_filter']['tag_mode'], |
---|
| 323 | null, |
---|
| 324 | null, |
---|
| 325 | false // we don't apply permissions in administration screens |
---|
| 326 | ) |
---|
| 327 | ); |
---|
[11853] | 328 | } |
---|
| 329 | |
---|
[8394] | 330 | $current_set = array_shift($filter_sets); |
---|
| 331 | foreach ($filter_sets as $set) |
---|
| 332 | { |
---|
| 333 | $current_set = array_intersect($current_set, $set); |
---|
| 334 | } |
---|
| 335 | $page['cat_elements_id'] = $current_set; |
---|
| 336 | |
---|
| 337 | // +-----------------------------------------------------------------------+ |
---|
| 338 | // | first element to display | |
---|
| 339 | // +-----------------------------------------------------------------------+ |
---|
| 340 | |
---|
| 341 | // $page['start'] contains the number of the first element in its |
---|
| 342 | // category. For exampe, $page['start'] = 12 means we must show elements #12 |
---|
| 343 | // and $page['nb_images'] next elements |
---|
| 344 | |
---|
[17290] | 345 | if (!isset($_REQUEST['start']) |
---|
| 346 | or !is_numeric($_REQUEST['start']) |
---|
| 347 | or $_REQUEST['start'] < 0 |
---|
| 348 | or (isset($_REQUEST['display']) and 'all' == $_REQUEST['display'])) |
---|
[8394] | 349 | { |
---|
| 350 | $page['start'] = 0; |
---|
| 351 | } |
---|
| 352 | else |
---|
| 353 | { |
---|
[17290] | 354 | $page['start'] = $_REQUEST['start']; |
---|
[8394] | 355 | } |
---|
| 356 | |
---|
| 357 | // +-----------------------------------------------------------------------+ |
---|
[8413] | 358 | // | Tabs | |
---|
[8394] | 359 | // +-----------------------------------------------------------------------+ |
---|
[16929] | 360 | $manager_link = get_root_url().'admin.php?page=batch_manager&mode='; |
---|
[8394] | 361 | |
---|
[9068] | 362 | if (isset($_GET['mode'])) |
---|
[8394] | 363 | { |
---|
[8413] | 364 | $page['tab'] = $_GET['mode']; |
---|
[8394] | 365 | } |
---|
[8413] | 366 | else |
---|
| 367 | { |
---|
[16929] | 368 | $page['tab'] = 'global'; |
---|
[8413] | 369 | } |
---|
| 370 | |
---|
[16929] | 371 | $tabsheet = new tabsheet(); |
---|
| 372 | $tabsheet->set_id('batch_manager'); |
---|
| 373 | $tabsheet->select($page['tab']); |
---|
| 374 | $tabsheet->assign(); |
---|
[8413] | 375 | |
---|
| 376 | // +-----------------------------------------------------------------------+ |
---|
[11039] | 377 | // | tags | |
---|
| 378 | // +-----------------------------------------------------------------------+ |
---|
| 379 | |
---|
| 380 | $query = ' |
---|
[11853] | 381 | SELECT id, name |
---|
[11039] | 382 | FROM '.TAGS_TABLE.' |
---|
| 383 | ;'; |
---|
[12259] | 384 | $template->assign('tags', get_taglist($query, false)); |
---|
[11039] | 385 | |
---|
| 386 | // +-----------------------------------------------------------------------+ |
---|
[8413] | 387 | // | open specific mode | |
---|
| 388 | // +-----------------------------------------------------------------------+ |
---|
| 389 | |
---|
[16929] | 390 | include(PHPWG_ROOT_PATH.'admin/batch_manager_'.$page['tab'].'.php'); |
---|
[9068] | 391 | ?> |
---|