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