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