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'); |
---|
36 | |
---|
37 | // +-----------------------------------------------------------------------+ |
---|
38 | // | Check Access and exit when user status is not ok | |
---|
39 | // +-----------------------------------------------------------------------+ |
---|
40 | |
---|
41 | check_status(ACCESS_ADMINISTRATOR); |
---|
42 | |
---|
43 | trigger_action('loc_begin_element_set_global'); |
---|
44 | |
---|
45 | // the $_POST['selection'] was already checked in element_set.php |
---|
46 | check_input_parameter('del_tags', $_POST, true, PATTERN_ID); |
---|
47 | check_input_parameter('associate', $_POST, false, PATTERN_ID); |
---|
48 | check_input_parameter('dissociate', $_POST, false, PATTERN_ID); |
---|
49 | |
---|
50 | // +-----------------------------------------------------------------------+ |
---|
51 | // | current selection | |
---|
52 | // +-----------------------------------------------------------------------+ |
---|
53 | |
---|
54 | $collection = array(); |
---|
55 | if (isset($_POST['setSelected'])) |
---|
56 | { |
---|
57 | $collection = $page['cat_elements_id']; |
---|
58 | } |
---|
59 | else if (isset($_POST['selection'])) |
---|
60 | { |
---|
61 | $collection = $_POST['selection']; |
---|
62 | } |
---|
63 | |
---|
64 | // +-----------------------------------------------------------------------+ |
---|
65 | // | global mode form submission | |
---|
66 | // +-----------------------------------------------------------------------+ |
---|
67 | |
---|
68 | if (isset($_POST['submit'])) |
---|
69 | { |
---|
70 | // if the user tries to apply an action, it means that there is at least 1 |
---|
71 | // photo in the selection |
---|
72 | if (count($collection) == 0) |
---|
73 | { |
---|
74 | array_push($page['errors'], l10n('Select at least one picture')); |
---|
75 | } |
---|
76 | |
---|
77 | $action = $_POST['selectAction']; |
---|
78 | |
---|
79 | if ('remove_from_caddie' == $action) |
---|
80 | { |
---|
81 | $query = ' |
---|
82 | DELETE |
---|
83 | FROM '.CADDIE_TABLE.' |
---|
84 | WHERE element_id IN ('.implode(',', $collection).') |
---|
85 | AND user_id = '.$user['id'].' |
---|
86 | ;'; |
---|
87 | pwg_query($query); |
---|
88 | |
---|
89 | // if we are here in the code, it means that the user is currently |
---|
90 | // displaying the caddie content, so we have to remove the current |
---|
91 | // selection from the current set |
---|
92 | $page['cat_elements_id'] = array_diff($page['cat_elements_id'], $collection); |
---|
93 | } |
---|
94 | |
---|
95 | if ('add_tags' == $action) |
---|
96 | { |
---|
97 | $tag_ids = get_fckb_tag_ids($_POST['add_tags']); |
---|
98 | add_tags($tag_ids, $collection); |
---|
99 | } |
---|
100 | |
---|
101 | if ('del_tags' == $action) |
---|
102 | { |
---|
103 | if (count($_POST['del_tags']) == 0) |
---|
104 | { |
---|
105 | array_push($page['errors'], l10n('Select at least one tag')); |
---|
106 | } |
---|
107 | |
---|
108 | $query = ' |
---|
109 | DELETE |
---|
110 | FROM '.IMAGE_TAG_TABLE.' |
---|
111 | WHERE image_id IN ('.implode(',', $collection).') |
---|
112 | AND tag_id IN ('.implode(',', $_POST['del_tags']).') |
---|
113 | ;'; |
---|
114 | pwg_query($query); |
---|
115 | } |
---|
116 | |
---|
117 | if ('associate' == $action) |
---|
118 | { |
---|
119 | associate_images_to_categories( |
---|
120 | $collection, |
---|
121 | array($_POST['associate']) |
---|
122 | ); |
---|
123 | } |
---|
124 | |
---|
125 | if ('dissociate' == $action) |
---|
126 | { |
---|
127 | // physical links must not be broken, so we must first retrieve image_id |
---|
128 | // which create virtual links with the category to "dissociate from". |
---|
129 | $query = ' |
---|
130 | SELECT id |
---|
131 | FROM '.IMAGE_CATEGORY_TABLE.' |
---|
132 | INNER JOIN '.IMAGES_TABLE.' ON image_id = id |
---|
133 | WHERE category_id = '.$_POST['dissociate'].' |
---|
134 | AND id IN ('.implode(',', $collection).') |
---|
135 | AND ( |
---|
136 | category_id != storage_category_id |
---|
137 | OR storage_category_id IS NULL |
---|
138 | ) |
---|
139 | ;'; |
---|
140 | $dissociables = array_from_query($query, 'id'); |
---|
141 | |
---|
142 | if (!empty($dissociables)) |
---|
143 | { |
---|
144 | $query = ' |
---|
145 | DELETE |
---|
146 | FROM '.IMAGE_CATEGORY_TABLE.' |
---|
147 | WHERE category_id = '.$_POST['dissociate'].' |
---|
148 | AND image_id IN ('.implode(',', $dissociables).') |
---|
149 | '; |
---|
150 | pwg_query($query); |
---|
151 | |
---|
152 | // we remove the dissociated images if we are currently displaying the |
---|
153 | // category to dissociate from. |
---|
154 | if (is_numeric($_GET['cat']) and $_POST['dissociate'] == $_GET['cat']) |
---|
155 | { |
---|
156 | $page['cat_elements_id'] = array_diff( |
---|
157 | $page['cat_elements_id'], |
---|
158 | $dissociables |
---|
159 | ); |
---|
160 | } |
---|
161 | } |
---|
162 | |
---|
163 | update_category($_POST['dissociate']); |
---|
164 | } |
---|
165 | |
---|
166 | // author |
---|
167 | if ('author' == $action) |
---|
168 | { |
---|
169 | $datas = array(); |
---|
170 | foreach ($collection as $image_id) |
---|
171 | { |
---|
172 | array_push( |
---|
173 | $datas, |
---|
174 | array( |
---|
175 | 'id' => $image_id, |
---|
176 | 'author' => $_POST['author'] |
---|
177 | ) |
---|
178 | ); |
---|
179 | } |
---|
180 | |
---|
181 | mass_updates( |
---|
182 | IMAGES_TABLE, |
---|
183 | array('primary' => array('id'), 'update' => array('author')), |
---|
184 | $datas |
---|
185 | ); |
---|
186 | } |
---|
187 | |
---|
188 | // name |
---|
189 | if ('name' == $action) |
---|
190 | { |
---|
191 | $datas = array(); |
---|
192 | foreach ($collection as $image_id) |
---|
193 | { |
---|
194 | array_push( |
---|
195 | $datas, |
---|
196 | array( |
---|
197 | 'id' => $image_id, |
---|
198 | 'name' => $_POST['name'] |
---|
199 | ) |
---|
200 | ); |
---|
201 | } |
---|
202 | |
---|
203 | mass_updates( |
---|
204 | IMAGES_TABLE, |
---|
205 | array('primary' => array('id'), 'update' => array('name')), |
---|
206 | $datas |
---|
207 | ); |
---|
208 | } |
---|
209 | |
---|
210 | // date_creation |
---|
211 | if ('date_creation' == $action) |
---|
212 | { |
---|
213 | $date_creation = sprintf( |
---|
214 | '%u-%u-%u', |
---|
215 | $_POST['date_creation_year'], |
---|
216 | $_POST['date_creation_month'], |
---|
217 | $_POST['date_creation_day'] |
---|
218 | ); |
---|
219 | |
---|
220 | $datas = array(); |
---|
221 | foreach ($collection as $image_id) |
---|
222 | { |
---|
223 | array_push( |
---|
224 | $datas, |
---|
225 | array( |
---|
226 | 'id' => $image_id, |
---|
227 | 'date_creation' => $date_creation |
---|
228 | ) |
---|
229 | ); |
---|
230 | } |
---|
231 | |
---|
232 | mass_updates( |
---|
233 | IMAGES_TABLE, |
---|
234 | array('primary' => array('id'), 'update' => array('date_creation')), |
---|
235 | $datas |
---|
236 | ); |
---|
237 | } |
---|
238 | |
---|
239 | // privacy_level |
---|
240 | if ('level' == $action) |
---|
241 | { |
---|
242 | $datas = array(); |
---|
243 | foreach ($collection as $image_id) |
---|
244 | { |
---|
245 | array_push( |
---|
246 | $datas, |
---|
247 | array( |
---|
248 | 'id' => $image_id, |
---|
249 | 'level' => $_POST['level'] |
---|
250 | ) |
---|
251 | ); |
---|
252 | } |
---|
253 | |
---|
254 | mass_updates( |
---|
255 | IMAGES_TABLE, |
---|
256 | array('primary' => array('id'), 'update' => array('level')), |
---|
257 | $datas |
---|
258 | ); |
---|
259 | } |
---|
260 | |
---|
261 | // add_to_caddie |
---|
262 | if ('add_to_caddie' == $action) |
---|
263 | { |
---|
264 | fill_caddie($collection); |
---|
265 | } |
---|
266 | |
---|
267 | // delete |
---|
268 | if ('delete' == $action) |
---|
269 | { |
---|
270 | if (isset($_POST['confirm_deletion']) and 1 == $_POST['confirm_deletion']) |
---|
271 | { |
---|
272 | // filter selection on photos that have no storage_category_id (ie |
---|
273 | // that were added via pLoader) |
---|
274 | $query = ' |
---|
275 | SELECT id |
---|
276 | FROM '.IMAGES_TABLE.' |
---|
277 | WHERE id IN ('.implode(',', $collection).') |
---|
278 | AND storage_category_id IS NULL |
---|
279 | ;'; |
---|
280 | $deletables = array_from_query($query, 'id'); |
---|
281 | |
---|
282 | if (count($deletables) > 0) |
---|
283 | { |
---|
284 | $physical_deletion = true; |
---|
285 | delete_elements($deletables, $physical_deletion); |
---|
286 | |
---|
287 | array_push( |
---|
288 | $page['infos'], |
---|
289 | sprintf( |
---|
290 | l10n_dec( |
---|
291 | '%d photo was deleted', |
---|
292 | '%d photos were deleted', |
---|
293 | count($deletables) |
---|
294 | ), |
---|
295 | count($deletables) |
---|
296 | ) |
---|
297 | ); |
---|
298 | |
---|
299 | // we have to remove the deleted photos from the current set |
---|
300 | $page['cat_elements_id'] = array_diff($page['cat_elements_id'], $deletables); |
---|
301 | } |
---|
302 | else |
---|
303 | { |
---|
304 | array_push($page['errors'], l10n('No photo can be deleted')); |
---|
305 | } |
---|
306 | } |
---|
307 | else |
---|
308 | { |
---|
309 | array_push($page['errors'], l10n('You need to confirm deletion')); |
---|
310 | } |
---|
311 | } |
---|
312 | } |
---|
313 | |
---|
314 | // +-----------------------------------------------------------------------+ |
---|
315 | // | template init | |
---|
316 | // +-----------------------------------------------------------------------+ |
---|
317 | $template->set_filenames(array('batch_manager_global' => 'batch_manager_global.tpl')); |
---|
318 | |
---|
319 | $base_url = get_root_url().'admin.php'; |
---|
320 | |
---|
321 | $template->assign( |
---|
322 | array( |
---|
323 | 'filter' => $_SESSION['bulk_manager_filter'], |
---|
324 | |
---|
325 | 'selection' => $collection, |
---|
326 | |
---|
327 | 'U_DISPLAY'=>$base_url.get_query_string_diff(array('display')), |
---|
328 | |
---|
329 | 'U_UNIT_MODE' |
---|
330 | => |
---|
331 | $base_url |
---|
332 | .get_query_string_diff(array('mode','display')) |
---|
333 | .'&mode=unit', |
---|
334 | |
---|
335 | 'F_ACTION'=>$base_url.get_query_string_diff(array('cat')), |
---|
336 | ) |
---|
337 | ); |
---|
338 | |
---|
339 | // +-----------------------------------------------------------------------+ |
---|
340 | // | caddie options | |
---|
341 | // +-----------------------------------------------------------------------+ |
---|
342 | |
---|
343 | $in_caddie = false; |
---|
344 | if (isset($_SESSION['bulk_manager_filter']['prefilter']) |
---|
345 | and 'caddie' == $_SESSION['bulk_manager_filter']['prefilter']) |
---|
346 | { |
---|
347 | $in_caddie = true; |
---|
348 | } |
---|
349 | $template->assign('IN_CADDIE', $in_caddie); |
---|
350 | |
---|
351 | // +-----------------------------------------------------------------------+ |
---|
352 | // | deletion form | |
---|
353 | // +-----------------------------------------------------------------------+ |
---|
354 | |
---|
355 | // we can only remove photos that have no storage_category_id, in other |
---|
356 | // word, it currently (Butterfly) means that the photo was added with |
---|
357 | // pLoader |
---|
358 | if (count($page['cat_elements_id']) > 0) |
---|
359 | { |
---|
360 | $query = ' |
---|
361 | SELECT |
---|
362 | COUNT(*) |
---|
363 | FROM '.IMAGES_TABLE.' |
---|
364 | WHERE id IN ('.implode(',', $page['cat_elements_id']).') |
---|
365 | AND storage_category_id IS NULL |
---|
366 | ;'; |
---|
367 | list($counter) = pwg_db_fetch_row(pwg_query($query)); |
---|
368 | |
---|
369 | if ($counter > 0) |
---|
370 | { |
---|
371 | $template->assign('show_delete_form', true); |
---|
372 | } |
---|
373 | } |
---|
374 | |
---|
375 | // +-----------------------------------------------------------------------+ |
---|
376 | // | global mode form | |
---|
377 | // +-----------------------------------------------------------------------+ |
---|
378 | |
---|
379 | // privacy level |
---|
380 | $template->assign( |
---|
381 | array( |
---|
382 | 'filter_level_options'=> get_privacy_level_options(), |
---|
383 | 'filter_level_options_selected' => isset($_SESSION['bulk_manager_filter']['level']) |
---|
384 | ? $_SESSION['bulk_manager_filter']['level'] |
---|
385 | : 0, |
---|
386 | ) |
---|
387 | ); |
---|
388 | |
---|
389 | // Virtualy associate a picture to a category |
---|
390 | $query = ' |
---|
391 | SELECT id,name,uppercats,global_rank |
---|
392 | FROM '.CATEGORIES_TABLE.' |
---|
393 | ;'; |
---|
394 | display_select_cat_wrapper($query, array(), 'associate_options', true); |
---|
395 | |
---|
396 | // in the filter box, which category to select by default |
---|
397 | $selected_category = array(); |
---|
398 | |
---|
399 | if (isset($_SESSION['bulk_manager_filter']['category'])) |
---|
400 | { |
---|
401 | $selected_category = array($_SESSION['bulk_manager_filter']['category']); |
---|
402 | } |
---|
403 | else |
---|
404 | { |
---|
405 | // we need to know the category in which the last photo was added |
---|
406 | $selected_category = array(); |
---|
407 | |
---|
408 | $query = ' |
---|
409 | SELECT |
---|
410 | category_id, |
---|
411 | id_uppercat |
---|
412 | FROM '.IMAGES_TABLE.' AS i |
---|
413 | JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON image_id = i.id |
---|
414 | JOIN '.CATEGORIES_TABLE.' AS c ON category_id = c.id |
---|
415 | ORDER BY i.id DESC |
---|
416 | LIMIT 1 |
---|
417 | ;'; |
---|
418 | $result = pwg_query($query); |
---|
419 | if (pwg_db_num_rows($result) > 0) |
---|
420 | { |
---|
421 | $row = pwg_db_fetch_assoc($result); |
---|
422 | |
---|
423 | $selected_category = array($row['category_id']); |
---|
424 | } |
---|
425 | } |
---|
426 | |
---|
427 | $query = ' |
---|
428 | SELECT id,name,uppercats,global_rank |
---|
429 | FROM '.CATEGORIES_TABLE.' |
---|
430 | ;'; |
---|
431 | display_select_cat_wrapper($query, $selected_category, 'filter_category_options', true); |
---|
432 | |
---|
433 | // Dissociate from a category : categories listed for dissociation can |
---|
434 | // only represent virtual links. Links to physical categories can't be |
---|
435 | // broken |
---|
436 | if (count($page['cat_elements_id']) > 0) |
---|
437 | { |
---|
438 | $query = ' |
---|
439 | SELECT |
---|
440 | DISTINCT(category_id) AS id, |
---|
441 | c.name, |
---|
442 | c.uppercats, |
---|
443 | c.global_rank |
---|
444 | FROM '.IMAGE_CATEGORY_TABLE.' AS ic |
---|
445 | JOIN '.CATEGORIES_TABLE.' AS c ON c.id = ic.category_id |
---|
446 | JOIN '.IMAGES_TABLE.' AS i ON i.id = ic.image_id |
---|
447 | WHERE ic.image_id IN ('.implode(',', $page['cat_elements_id']).') |
---|
448 | AND ( |
---|
449 | ic.category_id != i.storage_category_id |
---|
450 | OR i.storage_category_id IS NULL |
---|
451 | ) |
---|
452 | ;'; |
---|
453 | display_select_cat_wrapper($query, array(), 'dissociate_options', true); |
---|
454 | } |
---|
455 | |
---|
456 | if (count($page['cat_elements_id']) > 0) |
---|
457 | { |
---|
458 | // remove tags |
---|
459 | $tags = get_common_tags($page['cat_elements_id'], -1); |
---|
460 | |
---|
461 | $template->assign( |
---|
462 | array( |
---|
463 | 'DEL_TAG_SELECTION' => get_html_tag_selection($tags, 'del_tags'), |
---|
464 | ) |
---|
465 | ); |
---|
466 | } |
---|
467 | |
---|
468 | // creation date |
---|
469 | $day = |
---|
470 | empty($_POST['date_creation_day']) ? date('j') : $_POST['date_creation_day']; |
---|
471 | |
---|
472 | $month = |
---|
473 | empty($_POST['date_creation_month']) ? date('n') : $_POST['date_creation_month']; |
---|
474 | |
---|
475 | $year = |
---|
476 | empty($_POST['date_creation_year']) ? date('Y') : $_POST['date_creation_year']; |
---|
477 | |
---|
478 | $month_list = $lang['month']; |
---|
479 | $month_list[0]='------------'; |
---|
480 | ksort($month_list); |
---|
481 | $template->assign( array( |
---|
482 | 'month_list' => $month_list, |
---|
483 | 'DATE_CREATION_DAY' => (int)$day, |
---|
484 | 'DATE_CREATION_MONTH'=> (int)$month, |
---|
485 | 'DATE_CREATION_YEAR' => (int)$year, |
---|
486 | ) |
---|
487 | ); |
---|
488 | |
---|
489 | // image level options |
---|
490 | $template->assign( |
---|
491 | array( |
---|
492 | 'level_options'=> get_privacy_level_options(), |
---|
493 | 'level_options_selected' => 0, |
---|
494 | ) |
---|
495 | ); |
---|
496 | |
---|
497 | // +-----------------------------------------------------------------------+ |
---|
498 | // | global mode thumbnails | |
---|
499 | // +-----------------------------------------------------------------------+ |
---|
500 | |
---|
501 | // how many items to display on this page |
---|
502 | if (!empty($_GET['display'])) |
---|
503 | { |
---|
504 | if ('all' == $_GET['display']) |
---|
505 | { |
---|
506 | $page['nb_images'] = count($page['cat_elements_id']); |
---|
507 | } |
---|
508 | else |
---|
509 | { |
---|
510 | $page['nb_images'] = intval($_GET['display']); |
---|
511 | } |
---|
512 | } |
---|
513 | else |
---|
514 | { |
---|
515 | $page['nb_images'] = 20; |
---|
516 | } |
---|
517 | |
---|
518 | $nb_thumbs_page = 0; |
---|
519 | |
---|
520 | if (count($page['cat_elements_id']) > 0) |
---|
521 | { |
---|
522 | $nav_bar = create_navigation_bar( |
---|
523 | $base_url.get_query_string_diff(array('start')), |
---|
524 | count($page['cat_elements_id']), |
---|
525 | $page['start'], |
---|
526 | $page['nb_images'] |
---|
527 | ); |
---|
528 | $template->assign('navbar', $nav_bar); |
---|
529 | |
---|
530 | $query = ' |
---|
531 | SELECT id,path,tn_ext,file,filesize,level,name |
---|
532 | FROM '.IMAGES_TABLE.' |
---|
533 | WHERE id IN ('.implode(',', $page['cat_elements_id']).') |
---|
534 | '.$conf['order_by'].' |
---|
535 | LIMIT '.$page['nb_images'].' OFFSET '.$page['start'].' |
---|
536 | ;'; |
---|
537 | $result = pwg_query($query); |
---|
538 | |
---|
539 | // template thumbnail initialization |
---|
540 | while ($row = pwg_db_fetch_assoc($result)) |
---|
541 | { |
---|
542 | $nb_thumbs_page++; |
---|
543 | $src = get_thumbnail_url($row); |
---|
544 | |
---|
545 | $title = $row['name']; |
---|
546 | if (empty($title)) |
---|
547 | { |
---|
548 | $title = get_name_from_file($row['file']); |
---|
549 | } |
---|
550 | |
---|
551 | $template->append( |
---|
552 | 'thumbnails', |
---|
553 | array( |
---|
554 | 'ID' => $row['id'], |
---|
555 | 'TN_SRC' => $src, |
---|
556 | 'FILE' => $row['file'], |
---|
557 | 'TITLE' => $title, |
---|
558 | 'LEVEL' => $row['level'] |
---|
559 | ) |
---|
560 | ); |
---|
561 | } |
---|
562 | } |
---|
563 | |
---|
564 | $template->assign( |
---|
565 | array( |
---|
566 | 'nb_thumbs_page' => $nb_thumbs_page, |
---|
567 | 'nb_thumbs_set' => count($page['cat_elements_id']), |
---|
568 | ) |
---|
569 | ); |
---|
570 | |
---|
571 | trigger_action('loc_end_element_set_global'); |
---|
572 | |
---|
573 | //----------------------------------------------------------- sending html code |
---|
574 | $template->assign_var_from_handle('ADMIN_CONTENT', 'batch_manager_global'); |
---|
575 | ?> |
---|