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