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 | |
---|
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 | check_input_parameter('del_tags', $_POST, true, PATTERN_ID); |
---|
46 | check_input_parameter('associate', $_POST, false, PATTERN_ID); |
---|
47 | check_input_parameter('move', $_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 | // $page['prefilter'] is a shortcut to test if the current filter contains a |
---|
69 | // given prefilter. The idea is to make conditions simpler to write in the |
---|
70 | // code. |
---|
71 | $page['prefilter'] = 'none'; |
---|
72 | if (isset($_SESSION['bulk_manager_filter']['prefilter'])) |
---|
73 | { |
---|
74 | $page['prefilter'] = $_SESSION['bulk_manager_filter']['prefilter']; |
---|
75 | } |
---|
76 | |
---|
77 | // $page['category'] is a shortcut to test if the current filter contains a |
---|
78 | // given category. The idea is the same as for prefilter |
---|
79 | $page['category'] = -1; |
---|
80 | if (isset($_SESSION['bulk_manager_filter']['category'])) |
---|
81 | { |
---|
82 | $page['category'] = $_SESSION['bulk_manager_filter']['category']; |
---|
83 | } |
---|
84 | |
---|
85 | $redirect_url = get_root_url().'admin.php?page='.$_GET['page']; |
---|
86 | |
---|
87 | if (isset($_POST['submit'])) |
---|
88 | { |
---|
89 | // if the user tries to apply an action, it means that there is at least 1 |
---|
90 | // photo in the selection |
---|
91 | if (count($collection) == 0) |
---|
92 | { |
---|
93 | array_push($page['errors'], l10n('Select at least one photo')); |
---|
94 | } |
---|
95 | |
---|
96 | $action = $_POST['selectAction']; |
---|
97 | |
---|
98 | if ('remove_from_caddie' == $action) |
---|
99 | { |
---|
100 | $query = ' |
---|
101 | DELETE |
---|
102 | FROM '.CADDIE_TABLE.' |
---|
103 | WHERE element_id IN ('.implode(',', $collection).') |
---|
104 | AND user_id = '.$user['id'].' |
---|
105 | ;'; |
---|
106 | pwg_query($query); |
---|
107 | |
---|
108 | if ('caddie' == $page['prefilter']) |
---|
109 | { |
---|
110 | redirect($redirect_url); |
---|
111 | } |
---|
112 | |
---|
113 | // if we are here in the code, it means that the user is currently |
---|
114 | // displaying the caddie content, so we have to remove the current |
---|
115 | // selection from the current set |
---|
116 | $page['cat_elements_id'] = array_diff($page['cat_elements_id'], $collection); |
---|
117 | } |
---|
118 | |
---|
119 | if ('add_tags' == $action) |
---|
120 | { |
---|
121 | if (empty($_POST['add_tags'])) |
---|
122 | { |
---|
123 | array_push($page['errors'], l10n('Select at least one tag')); |
---|
124 | } |
---|
125 | else |
---|
126 | { |
---|
127 | $tag_ids = get_tag_ids($_POST['add_tags']); |
---|
128 | add_tags($tag_ids, $collection); |
---|
129 | |
---|
130 | if ('with no tag' == $page['prefilter']) |
---|
131 | { |
---|
132 | redirect(get_root_url().'admin.php?page='.$_GET['page']); |
---|
133 | } |
---|
134 | } |
---|
135 | } |
---|
136 | |
---|
137 | if ('del_tags' == $action) |
---|
138 | { |
---|
139 | if (count($_POST['del_tags']) == 0) |
---|
140 | { |
---|
141 | array_push($page['errors'], l10n('Select at least one tag')); |
---|
142 | } |
---|
143 | |
---|
144 | $query = ' |
---|
145 | DELETE |
---|
146 | FROM '.IMAGE_TAG_TABLE.' |
---|
147 | WHERE image_id IN ('.implode(',', $collection).') |
---|
148 | AND tag_id IN ('.implode(',', $_POST['del_tags']).') |
---|
149 | ;'; |
---|
150 | pwg_query($query); |
---|
151 | } |
---|
152 | |
---|
153 | if ('associate' == $action) |
---|
154 | { |
---|
155 | associate_images_to_categories( |
---|
156 | $collection, |
---|
157 | array($_POST['associate']) |
---|
158 | ); |
---|
159 | |
---|
160 | $_SESSION['page_infos'] = array( |
---|
161 | l10n('Information data registered in database') |
---|
162 | ); |
---|
163 | |
---|
164 | // let's refresh the page because we the current set might be modified |
---|
165 | if ('with no album' == $page['prefilter']) |
---|
166 | { |
---|
167 | redirect($redirect_url); |
---|
168 | } |
---|
169 | |
---|
170 | if ('with no virtual album' == $page['prefilter']) |
---|
171 | { |
---|
172 | $category_info = get_cat_info($_POST['associate']); |
---|
173 | if (empty($category_info['dir'])) |
---|
174 | { |
---|
175 | redirect($redirect_url); |
---|
176 | } |
---|
177 | } |
---|
178 | } |
---|
179 | |
---|
180 | if ('move' == $action) |
---|
181 | { |
---|
182 | move_images_to_categories($collection, array($_POST['move'])); |
---|
183 | |
---|
184 | $_SESSION['page_infos'] = array( |
---|
185 | l10n('Information data registered in database') |
---|
186 | ); |
---|
187 | |
---|
188 | // let's refresh the page because we the current set might be modified |
---|
189 | if ('with no album' == $page['prefilter']) |
---|
190 | { |
---|
191 | redirect($redirect_url); |
---|
192 | } |
---|
193 | |
---|
194 | if ('with no virtual album' == $page['prefilter']) |
---|
195 | { |
---|
196 | $category_info = get_cat_info($_POST['move']); |
---|
197 | if (empty($category_info['dir'])) |
---|
198 | { |
---|
199 | redirect($redirect_url); |
---|
200 | } |
---|
201 | } |
---|
202 | |
---|
203 | if (isset($_SESSION['bulk_manager_filter']['category']) |
---|
204 | and $_POST['move'] != $_SESSION['bulk_manager_filter']['category']) |
---|
205 | { |
---|
206 | redirect($redirect_url); |
---|
207 | } |
---|
208 | } |
---|
209 | |
---|
210 | if ('dissociate' == $action) |
---|
211 | { |
---|
212 | // physical links must not be broken, so we must first retrieve image_id |
---|
213 | // which create virtual links with the category to "dissociate from". |
---|
214 | $query = ' |
---|
215 | SELECT id |
---|
216 | FROM '.IMAGE_CATEGORY_TABLE.' |
---|
217 | INNER JOIN '.IMAGES_TABLE.' ON image_id = id |
---|
218 | WHERE category_id = '.$_POST['dissociate'].' |
---|
219 | AND id IN ('.implode(',', $collection).') |
---|
220 | AND ( |
---|
221 | category_id != storage_category_id |
---|
222 | OR storage_category_id IS NULL |
---|
223 | ) |
---|
224 | ;'; |
---|
225 | $dissociables = array_from_query($query, 'id'); |
---|
226 | |
---|
227 | if (!empty($dissociables)) |
---|
228 | { |
---|
229 | $query = ' |
---|
230 | DELETE |
---|
231 | FROM '.IMAGE_CATEGORY_TABLE.' |
---|
232 | WHERE category_id = '.$_POST['dissociate'].' |
---|
233 | AND image_id IN ('.implode(',', $dissociables).') |
---|
234 | '; |
---|
235 | pwg_query($query); |
---|
236 | |
---|
237 | $_SESSION['page_infos'] = array( |
---|
238 | l10n('Information data registered in database') |
---|
239 | ); |
---|
240 | |
---|
241 | // let's refresh the page because the current set might be modified |
---|
242 | redirect($redirect_url); |
---|
243 | } |
---|
244 | } |
---|
245 | |
---|
246 | // author |
---|
247 | if ('author' == $action) |
---|
248 | { |
---|
249 | if (isset($_POST['remove_author'])) |
---|
250 | { |
---|
251 | $_POST['author'] = null; |
---|
252 | } |
---|
253 | |
---|
254 | $datas = array(); |
---|
255 | foreach ($collection as $image_id) |
---|
256 | { |
---|
257 | array_push( |
---|
258 | $datas, |
---|
259 | array( |
---|
260 | 'id' => $image_id, |
---|
261 | 'author' => $_POST['author'] |
---|
262 | ) |
---|
263 | ); |
---|
264 | } |
---|
265 | |
---|
266 | mass_updates( |
---|
267 | IMAGES_TABLE, |
---|
268 | array('primary' => array('id'), 'update' => array('author')), |
---|
269 | $datas |
---|
270 | ); |
---|
271 | } |
---|
272 | |
---|
273 | // title |
---|
274 | if ('title' == $action) |
---|
275 | { |
---|
276 | if (isset($_POST['remove_title'])) |
---|
277 | { |
---|
278 | $_POST['title'] = null; |
---|
279 | } |
---|
280 | |
---|
281 | $datas = array(); |
---|
282 | foreach ($collection as $image_id) |
---|
283 | { |
---|
284 | array_push( |
---|
285 | $datas, |
---|
286 | array( |
---|
287 | 'id' => $image_id, |
---|
288 | 'name' => $_POST['title'] |
---|
289 | ) |
---|
290 | ); |
---|
291 | } |
---|
292 | |
---|
293 | mass_updates( |
---|
294 | IMAGES_TABLE, |
---|
295 | array('primary' => array('id'), 'update' => array('name')), |
---|
296 | $datas |
---|
297 | ); |
---|
298 | } |
---|
299 | |
---|
300 | // date_creation |
---|
301 | if ('date_creation' == $action) |
---|
302 | { |
---|
303 | $date_creation = sprintf( |
---|
304 | '%u-%u-%u', |
---|
305 | $_POST['date_creation_year'], |
---|
306 | $_POST['date_creation_month'], |
---|
307 | $_POST['date_creation_day'] |
---|
308 | ); |
---|
309 | |
---|
310 | if (isset($_POST['remove_date_creation'])) |
---|
311 | { |
---|
312 | $date_creation = null; |
---|
313 | } |
---|
314 | |
---|
315 | $datas = array(); |
---|
316 | foreach ($collection as $image_id) |
---|
317 | { |
---|
318 | array_push( |
---|
319 | $datas, |
---|
320 | array( |
---|
321 | 'id' => $image_id, |
---|
322 | 'date_creation' => $date_creation |
---|
323 | ) |
---|
324 | ); |
---|
325 | } |
---|
326 | |
---|
327 | mass_updates( |
---|
328 | IMAGES_TABLE, |
---|
329 | array('primary' => array('id'), 'update' => array('date_creation')), |
---|
330 | $datas |
---|
331 | ); |
---|
332 | } |
---|
333 | |
---|
334 | // privacy_level |
---|
335 | if ('level' == $action) |
---|
336 | { |
---|
337 | $datas = array(); |
---|
338 | foreach ($collection as $image_id) |
---|
339 | { |
---|
340 | array_push( |
---|
341 | $datas, |
---|
342 | array( |
---|
343 | 'id' => $image_id, |
---|
344 | 'level' => $_POST['level'] |
---|
345 | ) |
---|
346 | ); |
---|
347 | } |
---|
348 | |
---|
349 | mass_updates( |
---|
350 | IMAGES_TABLE, |
---|
351 | array('primary' => array('id'), 'update' => array('level')), |
---|
352 | $datas |
---|
353 | ); |
---|
354 | |
---|
355 | if (isset($_SESSION['bulk_manager_filter']['level'])) |
---|
356 | { |
---|
357 | if ($_POST['level'] < $_SESSION['bulk_manager_filter']['level']) |
---|
358 | { |
---|
359 | redirect($redirect_url); |
---|
360 | } |
---|
361 | } |
---|
362 | } |
---|
363 | |
---|
364 | // add_to_caddie |
---|
365 | if ('add_to_caddie' == $action) |
---|
366 | { |
---|
367 | fill_caddie($collection); |
---|
368 | } |
---|
369 | |
---|
370 | // delete |
---|
371 | if ('delete' == $action) |
---|
372 | { |
---|
373 | if (isset($_POST['confirm_deletion']) and 1 == $_POST['confirm_deletion']) |
---|
374 | { |
---|
375 | $deleted_count = delete_elements($collection, true); |
---|
376 | if ($deleted_count > 0) |
---|
377 | { |
---|
378 | $_SESSION['page_infos'] = array( |
---|
379 | sprintf( |
---|
380 | l10n_dec( |
---|
381 | '%d photo was deleted', |
---|
382 | '%d photos were deleted', |
---|
383 | $deleted_count |
---|
384 | ), |
---|
385 | $deleted_count |
---|
386 | ) |
---|
387 | ); |
---|
388 | |
---|
389 | $redirect_url = get_root_url().'admin.php?page='.$_GET['page']; |
---|
390 | redirect($redirect_url); |
---|
391 | } |
---|
392 | else |
---|
393 | { |
---|
394 | array_push($page['errors'], l10n('No photo can be deleted')); |
---|
395 | } |
---|
396 | } |
---|
397 | else |
---|
398 | { |
---|
399 | array_push($page['errors'], l10n('You need to confirm deletion')); |
---|
400 | } |
---|
401 | } |
---|
402 | |
---|
403 | // synchronize metadata |
---|
404 | if ('metadata' == $action) |
---|
405 | { |
---|
406 | sync_metadata($collection); |
---|
407 | |
---|
408 | array_push( |
---|
409 | $page['infos'], |
---|
410 | l10n('Metadata synchronized from file') |
---|
411 | ); |
---|
412 | } |
---|
413 | |
---|
414 | if ('delete_derivatives' == $action) |
---|
415 | { |
---|
416 | $query='SELECT path,representative_ext FROM '.IMAGES_TABLE.' |
---|
417 | WHERE id IN ('.implode(',', $collection).')'; |
---|
418 | $result = pwg_query($query); |
---|
419 | while ($info = pwg_db_fetch_assoc($result)) |
---|
420 | { |
---|
421 | foreach( $_POST['del_derivatives_type'] as $type) |
---|
422 | { |
---|
423 | delete_element_derivatives($info, $type); |
---|
424 | } |
---|
425 | } |
---|
426 | } |
---|
427 | |
---|
428 | if ('generate_derivatives' == $action) |
---|
429 | { |
---|
430 | if ($_POST['regenerateSuccess'] != '0') |
---|
431 | array_push($page['infos'], sprintf(l10n('%s photos were generated'), $_POST['regenerateSuccess'])); |
---|
432 | |
---|
433 | if ($_POST['regenerateError'] != '0') |
---|
434 | array_push($page['warnings'], sprintf(l10n('%s photos were not generated'), $_POST['regenerateError'])); |
---|
435 | |
---|
436 | } |
---|
437 | |
---|
438 | trigger_action('element_set_global_action', $action, $collection); |
---|
439 | } |
---|
440 | |
---|
441 | // +-----------------------------------------------------------------------+ |
---|
442 | // | template init | |
---|
443 | // +-----------------------------------------------------------------------+ |
---|
444 | $template->set_filenames(array('batch_manager_global' => 'batch_manager_global.tpl')); |
---|
445 | |
---|
446 | $base_url = get_root_url().'admin.php'; |
---|
447 | |
---|
448 | $prefilters = array(); |
---|
449 | |
---|
450 | array_push($prefilters, |
---|
451 | array('ID' => 'caddie', 'NAME' => l10n('Caddie')), |
---|
452 | array('ID' => 'last import', 'NAME' => l10n('Last import')), |
---|
453 | array('ID' => 'with no album', 'NAME' => l10n('With no album')), |
---|
454 | array('ID' => 'with no tag', 'NAME' => l10n('With no tag')), |
---|
455 | array('ID' => 'duplicates', 'NAME' => l10n('Duplicates')), |
---|
456 | array('ID' => 'all photos', 'NAME' => l10n('All')) |
---|
457 | ); |
---|
458 | |
---|
459 | if ($conf['enable_synchronization']) |
---|
460 | { |
---|
461 | array_push($prefilters, |
---|
462 | array('ID' => 'with no virtual album', 'NAME' => l10n('With no virtual album')) |
---|
463 | ); |
---|
464 | } |
---|
465 | |
---|
466 | $prefilters = trigger_event('get_batch_manager_prefilters', $prefilters); |
---|
467 | usort($prefilters, 'UC_name_compare'); |
---|
468 | |
---|
469 | $template->assign( |
---|
470 | array( |
---|
471 | 'prefilters' => $prefilters, |
---|
472 | 'filter' => $_SESSION['bulk_manager_filter'], |
---|
473 | 'selection' => $collection, |
---|
474 | 'all_elements' => $page['cat_elements_id'], |
---|
475 | 'START' => $page['start'], |
---|
476 | 'U_DISPLAY'=>$base_url.get_query_string_diff(array('display')), |
---|
477 | 'F_ACTION'=>$base_url.get_query_string_diff(array('cat','start','tag')), |
---|
478 | ) |
---|
479 | ); |
---|
480 | |
---|
481 | // +-----------------------------------------------------------------------+ |
---|
482 | // | caddie options | |
---|
483 | // +-----------------------------------------------------------------------+ |
---|
484 | |
---|
485 | $in_caddie = false; |
---|
486 | if (isset($_SESSION['bulk_manager_filter']['prefilter']) |
---|
487 | and 'caddie' == $_SESSION['bulk_manager_filter']['prefilter']) |
---|
488 | { |
---|
489 | $in_caddie = true; |
---|
490 | } |
---|
491 | $template->assign('IN_CADDIE', $in_caddie); |
---|
492 | |
---|
493 | // +-----------------------------------------------------------------------+ |
---|
494 | // | deletion form | |
---|
495 | // +-----------------------------------------------------------------------+ |
---|
496 | |
---|
497 | // we can only remove photos that have no storage_category_id, in other |
---|
498 | // word, it currently (Butterfly) means that the photo was added with |
---|
499 | // pLoader |
---|
500 | if (count($page['cat_elements_id']) > 0) |
---|
501 | { |
---|
502 | $query = ' |
---|
503 | SELECT |
---|
504 | id |
---|
505 | FROM '.IMAGES_TABLE.' |
---|
506 | WHERE id IN ('.implode(',', $page['cat_elements_id']).') |
---|
507 | AND file NOT LIKE \'http%\' |
---|
508 | LIMIT 1 |
---|
509 | ;'; |
---|
510 | ; |
---|
511 | |
---|
512 | if ( pwg_db_fetch_row(pwg_query($query)) ) |
---|
513 | { |
---|
514 | $template->assign('show_delete_form', true); |
---|
515 | } |
---|
516 | } |
---|
517 | |
---|
518 | // +-----------------------------------------------------------------------+ |
---|
519 | // | global mode form | |
---|
520 | // +-----------------------------------------------------------------------+ |
---|
521 | |
---|
522 | // privacy level |
---|
523 | foreach ($conf['available_permission_levels'] as $level) |
---|
524 | { |
---|
525 | $level_options[$level] = l10n(sprintf('Level %d', $level)); |
---|
526 | |
---|
527 | if (0 == $level) |
---|
528 | { |
---|
529 | $level_options[$level] = l10n('Everybody'); |
---|
530 | } |
---|
531 | } |
---|
532 | $template->assign( |
---|
533 | array( |
---|
534 | 'filter_level_options'=> $level_options, |
---|
535 | 'filter_level_options_selected' => isset($_SESSION['bulk_manager_filter']['level']) |
---|
536 | ? $_SESSION['bulk_manager_filter']['level'] |
---|
537 | : 0, |
---|
538 | ) |
---|
539 | ); |
---|
540 | |
---|
541 | // tags |
---|
542 | if (!empty($_SESSION['bulk_manager_filter']['tags'])) |
---|
543 | { |
---|
544 | $query = ' |
---|
545 | SELECT |
---|
546 | id, |
---|
547 | name |
---|
548 | FROM '.TAGS_TABLE.' |
---|
549 | WHERE id IN ('.implode(',', $_SESSION['bulk_manager_filter']['tags']).') |
---|
550 | ;'; |
---|
551 | $template->assign('filter_tags', get_taglist($query)); |
---|
552 | } |
---|
553 | |
---|
554 | // Virtualy associate a picture to a category |
---|
555 | $query = ' |
---|
556 | SELECT id,name,uppercats,global_rank |
---|
557 | FROM '.CATEGORIES_TABLE.' |
---|
558 | ;'; |
---|
559 | display_select_cat_wrapper($query, array(), 'associate_options', true); |
---|
560 | display_select_cat_wrapper($query, array(), 'move_options', true); |
---|
561 | display_select_cat_wrapper($query, array(), 'category_parent_options'); |
---|
562 | |
---|
563 | // in the filter box, which category to select by default |
---|
564 | $selected_category = array(); |
---|
565 | |
---|
566 | if (isset($_SESSION['bulk_manager_filter']['category'])) |
---|
567 | { |
---|
568 | $selected_category = array($_SESSION['bulk_manager_filter']['category']); |
---|
569 | } |
---|
570 | else |
---|
571 | { |
---|
572 | // we need to know the category in which the last photo was added |
---|
573 | $selected_category = array(); |
---|
574 | |
---|
575 | $query = ' |
---|
576 | SELECT |
---|
577 | category_id, |
---|
578 | id_uppercat |
---|
579 | FROM '.IMAGES_TABLE.' AS i |
---|
580 | JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON image_id = i.id |
---|
581 | JOIN '.CATEGORIES_TABLE.' AS c ON category_id = c.id |
---|
582 | ORDER BY i.id DESC |
---|
583 | LIMIT 1 |
---|
584 | ;'; |
---|
585 | $result = pwg_query($query); |
---|
586 | if (pwg_db_num_rows($result) > 0) |
---|
587 | { |
---|
588 | $row = pwg_db_fetch_assoc($result); |
---|
589 | |
---|
590 | $selected_category = array($row['category_id']); |
---|
591 | } |
---|
592 | } |
---|
593 | |
---|
594 | $query = ' |
---|
595 | SELECT id,name,uppercats,global_rank |
---|
596 | FROM '.CATEGORIES_TABLE.' |
---|
597 | ;'; |
---|
598 | display_select_cat_wrapper($query, $selected_category, 'filter_category_options', true); |
---|
599 | |
---|
600 | // Dissociate from a category : categories listed for dissociation can only |
---|
601 | // represent virtual links. We can't create orphans. Links to physical |
---|
602 | // categories can't be broken. |
---|
603 | if (count($page['cat_elements_id']) > 0) |
---|
604 | { |
---|
605 | $query = ' |
---|
606 | SELECT |
---|
607 | DISTINCT(category_id) AS id, |
---|
608 | c.name, |
---|
609 | c.uppercats, |
---|
610 | c.global_rank |
---|
611 | FROM '.IMAGE_CATEGORY_TABLE.' AS ic |
---|
612 | JOIN '.CATEGORIES_TABLE.' AS c ON c.id = ic.category_id |
---|
613 | JOIN '.IMAGES_TABLE.' AS i ON i.id = ic.image_id |
---|
614 | WHERE ic.image_id IN ('.implode(',', $page['cat_elements_id']).') |
---|
615 | AND ( |
---|
616 | ic.category_id != i.storage_category_id |
---|
617 | OR i.storage_category_id IS NULL |
---|
618 | ) |
---|
619 | ;'; |
---|
620 | display_select_cat_wrapper($query, array(), 'dissociate_options', true); |
---|
621 | } |
---|
622 | |
---|
623 | if (count($page['cat_elements_id']) > 0) |
---|
624 | { |
---|
625 | // remove tags |
---|
626 | $tags = get_common_tags($page['cat_elements_id'], -1); |
---|
627 | |
---|
628 | $template->assign( |
---|
629 | array( |
---|
630 | 'DEL_TAG_SELECTION' => get_html_tag_selection($tags, 'del_tags'), |
---|
631 | ) |
---|
632 | ); |
---|
633 | } |
---|
634 | |
---|
635 | // creation date |
---|
636 | $day = |
---|
637 | empty($_POST['date_creation_day']) ? date('j') : $_POST['date_creation_day']; |
---|
638 | |
---|
639 | $month = |
---|
640 | empty($_POST['date_creation_month']) ? date('n') : $_POST['date_creation_month']; |
---|
641 | |
---|
642 | $year = |
---|
643 | empty($_POST['date_creation_year']) ? date('Y') : $_POST['date_creation_year']; |
---|
644 | |
---|
645 | $month_list = $lang['month']; |
---|
646 | $month_list[0]='------------'; |
---|
647 | ksort($month_list); |
---|
648 | $template->assign( array( |
---|
649 | 'month_list' => $month_list, |
---|
650 | 'DATE_CREATION_DAY' => (int)$day, |
---|
651 | 'DATE_CREATION_MONTH'=> (int)$month, |
---|
652 | 'DATE_CREATION_YEAR' => (int)$year, |
---|
653 | ) |
---|
654 | ); |
---|
655 | |
---|
656 | // image level options |
---|
657 | $template->assign( |
---|
658 | array( |
---|
659 | 'level_options'=> get_privacy_level_options(), |
---|
660 | 'level_options_selected' => 0, |
---|
661 | ) |
---|
662 | ); |
---|
663 | |
---|
664 | // metadata |
---|
665 | include_once( PHPWG_ROOT_PATH.'admin/site_reader_local.php'); |
---|
666 | $site_reader = new LocalSiteReader('./'); |
---|
667 | $used_metadata = implode( ', ', $site_reader->get_metadata_attributes()); |
---|
668 | |
---|
669 | $template->assign( |
---|
670 | array( |
---|
671 | 'used_metadata' => $used_metadata, |
---|
672 | ) |
---|
673 | ); |
---|
674 | |
---|
675 | //derivatives |
---|
676 | $del_deriv_map = array(); |
---|
677 | foreach(ImageStdParams::get_defined_type_map() as $params) |
---|
678 | { |
---|
679 | $del_deriv_map[$params->type] = l10n($params->type); |
---|
680 | } |
---|
681 | $gen_deriv_map = $del_deriv_map; |
---|
682 | $del_deriv_map[IMG_CUSTOM] = l10n(IMG_CUSTOM); |
---|
683 | $template->assign( |
---|
684 | array( |
---|
685 | 'del_derivatives_types' => $del_deriv_map, |
---|
686 | 'generate_derivatives_types' => $gen_deriv_map, |
---|
687 | ) |
---|
688 | ); |
---|
689 | |
---|
690 | // +-----------------------------------------------------------------------+ |
---|
691 | // | global mode thumbnails | |
---|
692 | // +-----------------------------------------------------------------------+ |
---|
693 | |
---|
694 | // how many items to display on this page |
---|
695 | if (!empty($_GET['display'])) |
---|
696 | { |
---|
697 | if ('all' == $_GET['display']) |
---|
698 | { |
---|
699 | $page['nb_images'] = count($page['cat_elements_id']); |
---|
700 | } |
---|
701 | else |
---|
702 | { |
---|
703 | $page['nb_images'] = intval($_GET['display']); |
---|
704 | } |
---|
705 | } |
---|
706 | else |
---|
707 | { |
---|
708 | $page['nb_images'] = 20; |
---|
709 | } |
---|
710 | |
---|
711 | $nb_thumbs_page = 0; |
---|
712 | |
---|
713 | if (count($page['cat_elements_id']) > 0) |
---|
714 | { |
---|
715 | $nav_bar = create_navigation_bar( |
---|
716 | $base_url.get_query_string_diff(array('start')), |
---|
717 | count($page['cat_elements_id']), |
---|
718 | $page['start'], |
---|
719 | $page['nb_images'] |
---|
720 | ); |
---|
721 | $template->assign('navbar', $nav_bar); |
---|
722 | |
---|
723 | $is_category = false; |
---|
724 | if (isset($_SESSION['bulk_manager_filter']['category']) |
---|
725 | and !isset($_SESSION['bulk_manager_filter']['category_recursive'])) |
---|
726 | { |
---|
727 | $is_category = true; |
---|
728 | } |
---|
729 | |
---|
730 | if (isset($_SESSION['bulk_manager_filter']['prefilter']) |
---|
731 | and 'duplicates' == $_SESSION['bulk_manager_filter']['prefilter']) |
---|
732 | { |
---|
733 | $conf['order_by'] = ' ORDER BY file, id'; |
---|
734 | } |
---|
735 | |
---|
736 | $query = ' |
---|
737 | SELECT id,path,representative_ext,file,filesize,level,name,width,height,rotation |
---|
738 | FROM '.IMAGES_TABLE; |
---|
739 | |
---|
740 | if ($is_category) |
---|
741 | { |
---|
742 | $category_info = get_cat_info($_SESSION['bulk_manager_filter']['category']); |
---|
743 | |
---|
744 | $conf['order_by'] = $conf['order_by_inside_category']; |
---|
745 | if (!empty($category_info['image_order'])) |
---|
746 | { |
---|
747 | $conf['order_by'] = ' ORDER BY '.$category_info['image_order']; |
---|
748 | } |
---|
749 | |
---|
750 | $query.= ' |
---|
751 | JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id'; |
---|
752 | } |
---|
753 | |
---|
754 | $query.= ' |
---|
755 | WHERE id IN ('.implode(',', $page['cat_elements_id']).')'; |
---|
756 | |
---|
757 | if ($is_category) |
---|
758 | { |
---|
759 | $query.= ' |
---|
760 | AND category_id = '.$_SESSION['bulk_manager_filter']['category']; |
---|
761 | } |
---|
762 | |
---|
763 | $query.= ' |
---|
764 | '.$conf['order_by'].' |
---|
765 | LIMIT '.$page['nb_images'].' OFFSET '.$page['start'].' |
---|
766 | ;'; |
---|
767 | $result = pwg_query($query); |
---|
768 | |
---|
769 | $thumb_params = ImageStdParams::get_by_type(IMG_THUMB); |
---|
770 | // template thumbnail initialization |
---|
771 | while ($row = pwg_db_fetch_assoc($result)) |
---|
772 | { |
---|
773 | $nb_thumbs_page++; |
---|
774 | $src_image = new SrcImage($row); |
---|
775 | |
---|
776 | $ttitle = render_element_name($row); |
---|
777 | if ($ttitle != get_name_from_file($row['file'])) |
---|
778 | { |
---|
779 | $ttitle.= ' ('.$row['file'].')'; |
---|
780 | } |
---|
781 | |
---|
782 | $template->append( |
---|
783 | 'thumbnails', array_merge($row, |
---|
784 | array( |
---|
785 | 'thumb' => new DerivativeImage($thumb_params, $src_image), |
---|
786 | 'TITLE' => $ttitle, |
---|
787 | 'FILE_SRC' => DerivativeImage::url(IMG_LARGE, $src_image), |
---|
788 | 'U_EDIT' => get_root_url().'admin.php?page=photo-'.$row['id'], |
---|
789 | ) |
---|
790 | )); |
---|
791 | } |
---|
792 | $template->assign('thumb_params', $thumb_params); |
---|
793 | } |
---|
794 | |
---|
795 | $template->assign( |
---|
796 | array( |
---|
797 | 'nb_thumbs_page' => $nb_thumbs_page, |
---|
798 | 'nb_thumbs_set' => count($page['cat_elements_id']), |
---|
799 | ) |
---|
800 | ); |
---|
801 | |
---|
802 | trigger_action('loc_end_element_set_global'); |
---|
803 | |
---|
804 | //----------------------------------------------------------- sending html code |
---|
805 | $template->assign_var_from_handle('ADMIN_CONTENT', 'batch_manager_global'); |
---|
806 | ?> |
---|