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