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