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 | 'U_DISPLAY'=>$base_url.get_query_string_diff(array('display')), |
---|
476 | 'F_ACTION'=>$base_url.get_query_string_diff(array('cat')), |
---|
477 | ) |
---|
478 | ); |
---|
479 | |
---|
480 | // +-----------------------------------------------------------------------+ |
---|
481 | // | caddie options | |
---|
482 | // +-----------------------------------------------------------------------+ |
---|
483 | |
---|
484 | $in_caddie = false; |
---|
485 | if (isset($_SESSION['bulk_manager_filter']['prefilter']) |
---|
486 | and 'caddie' == $_SESSION['bulk_manager_filter']['prefilter']) |
---|
487 | { |
---|
488 | $in_caddie = true; |
---|
489 | } |
---|
490 | $template->assign('IN_CADDIE', $in_caddie); |
---|
491 | |
---|
492 | // +-----------------------------------------------------------------------+ |
---|
493 | // | deletion form | |
---|
494 | // +-----------------------------------------------------------------------+ |
---|
495 | |
---|
496 | // we can only remove photos that have no storage_category_id, in other |
---|
497 | // word, it currently (Butterfly) means that the photo was added with |
---|
498 | // pLoader |
---|
499 | if (count($page['cat_elements_id']) > 0) |
---|
500 | { |
---|
501 | $query = ' |
---|
502 | SELECT |
---|
503 | id |
---|
504 | FROM '.IMAGES_TABLE.' |
---|
505 | WHERE id IN ('.implode(',', $page['cat_elements_id']).') |
---|
506 | AND file NOT LIKE \'http%\' |
---|
507 | LIMIT 1 |
---|
508 | ;'; |
---|
509 | ; |
---|
510 | |
---|
511 | if ( pwg_db_fetch_row(pwg_query($query)) ) |
---|
512 | { |
---|
513 | $template->assign('show_delete_form', true); |
---|
514 | } |
---|
515 | } |
---|
516 | |
---|
517 | // +-----------------------------------------------------------------------+ |
---|
518 | // | global mode form | |
---|
519 | // +-----------------------------------------------------------------------+ |
---|
520 | |
---|
521 | // privacy level |
---|
522 | foreach ($conf['available_permission_levels'] as $level) |
---|
523 | { |
---|
524 | $level_options[$level] = l10n(sprintf('Level %d', $level)); |
---|
525 | |
---|
526 | if (0 == $level) |
---|
527 | { |
---|
528 | $level_options[$level] = l10n('Everybody'); |
---|
529 | } |
---|
530 | } |
---|
531 | $template->assign( |
---|
532 | array( |
---|
533 | 'filter_level_options'=> $level_options, |
---|
534 | 'filter_level_options_selected' => isset($_SESSION['bulk_manager_filter']['level']) |
---|
535 | ? $_SESSION['bulk_manager_filter']['level'] |
---|
536 | : 0, |
---|
537 | ) |
---|
538 | ); |
---|
539 | |
---|
540 | // tags |
---|
541 | if (!empty($_SESSION['bulk_manager_filter']['tags'])) |
---|
542 | { |
---|
543 | $query = ' |
---|
544 | SELECT |
---|
545 | id, |
---|
546 | name |
---|
547 | FROM '.TAGS_TABLE.' |
---|
548 | WHERE id IN ('.implode(',', $_SESSION['bulk_manager_filter']['tags']).') |
---|
549 | ;'; |
---|
550 | $template->assign('filter_tags', get_taglist($query)); |
---|
551 | } |
---|
552 | |
---|
553 | // Virtualy associate a picture to a category |
---|
554 | $query = ' |
---|
555 | SELECT id,name,uppercats,global_rank |
---|
556 | FROM '.CATEGORIES_TABLE.' |
---|
557 | ;'; |
---|
558 | display_select_cat_wrapper($query, array(), 'associate_options', true); |
---|
559 | display_select_cat_wrapper($query, array(), 'move_options', true); |
---|
560 | display_select_cat_wrapper($query, array(), 'category_parent_options'); |
---|
561 | |
---|
562 | // in the filter box, which category to select by default |
---|
563 | $selected_category = array(); |
---|
564 | |
---|
565 | if (isset($_SESSION['bulk_manager_filter']['category'])) |
---|
566 | { |
---|
567 | $selected_category = array($_SESSION['bulk_manager_filter']['category']); |
---|
568 | } |
---|
569 | else |
---|
570 | { |
---|
571 | // we need to know the category in which the last photo was added |
---|
572 | $selected_category = array(); |
---|
573 | |
---|
574 | $query = ' |
---|
575 | SELECT |
---|
576 | category_id, |
---|
577 | id_uppercat |
---|
578 | FROM '.IMAGES_TABLE.' AS i |
---|
579 | JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON image_id = i.id |
---|
580 | JOIN '.CATEGORIES_TABLE.' AS c ON category_id = c.id |
---|
581 | ORDER BY i.id DESC |
---|
582 | LIMIT 1 |
---|
583 | ;'; |
---|
584 | $result = pwg_query($query); |
---|
585 | if (pwg_db_num_rows($result) > 0) |
---|
586 | { |
---|
587 | $row = pwg_db_fetch_assoc($result); |
---|
588 | |
---|
589 | $selected_category = array($row['category_id']); |
---|
590 | } |
---|
591 | } |
---|
592 | |
---|
593 | $query = ' |
---|
594 | SELECT id,name,uppercats,global_rank |
---|
595 | FROM '.CATEGORIES_TABLE.' |
---|
596 | ;'; |
---|
597 | display_select_cat_wrapper($query, $selected_category, 'filter_category_options', true); |
---|
598 | |
---|
599 | // Dissociate from a category : categories listed for dissociation can only |
---|
600 | // represent virtual links. We can't create orphans. Links to physical |
---|
601 | // categories can't be broken. |
---|
602 | if (count($page['cat_elements_id']) > 0) |
---|
603 | { |
---|
604 | $query = ' |
---|
605 | SELECT |
---|
606 | DISTINCT(category_id) AS id, |
---|
607 | c.name, |
---|
608 | c.uppercats, |
---|
609 | c.global_rank |
---|
610 | FROM '.IMAGE_CATEGORY_TABLE.' AS ic |
---|
611 | JOIN '.CATEGORIES_TABLE.' AS c ON c.id = ic.category_id |
---|
612 | JOIN '.IMAGES_TABLE.' AS i ON i.id = ic.image_id |
---|
613 | WHERE ic.image_id IN ('.implode(',', $page['cat_elements_id']).') |
---|
614 | AND ( |
---|
615 | ic.category_id != i.storage_category_id |
---|
616 | OR i.storage_category_id IS NULL |
---|
617 | ) |
---|
618 | ;'; |
---|
619 | display_select_cat_wrapper($query, array(), 'dissociate_options', true); |
---|
620 | } |
---|
621 | |
---|
622 | if (count($page['cat_elements_id']) > 0) |
---|
623 | { |
---|
624 | // remove tags |
---|
625 | $tags = get_common_tags($page['cat_elements_id'], -1); |
---|
626 | |
---|
627 | $template->assign( |
---|
628 | array( |
---|
629 | 'DEL_TAG_SELECTION' => get_html_tag_selection($tags, 'del_tags'), |
---|
630 | ) |
---|
631 | ); |
---|
632 | } |
---|
633 | |
---|
634 | // creation date |
---|
635 | $day = |
---|
636 | empty($_POST['date_creation_day']) ? date('j') : $_POST['date_creation_day']; |
---|
637 | |
---|
638 | $month = |
---|
639 | empty($_POST['date_creation_month']) ? date('n') : $_POST['date_creation_month']; |
---|
640 | |
---|
641 | $year = |
---|
642 | empty($_POST['date_creation_year']) ? date('Y') : $_POST['date_creation_year']; |
---|
643 | |
---|
644 | $month_list = $lang['month']; |
---|
645 | $month_list[0]='------------'; |
---|
646 | ksort($month_list); |
---|
647 | $template->assign( array( |
---|
648 | 'month_list' => $month_list, |
---|
649 | 'DATE_CREATION_DAY' => (int)$day, |
---|
650 | 'DATE_CREATION_MONTH'=> (int)$month, |
---|
651 | 'DATE_CREATION_YEAR' => (int)$year, |
---|
652 | ) |
---|
653 | ); |
---|
654 | |
---|
655 | // image level options |
---|
656 | $template->assign( |
---|
657 | array( |
---|
658 | 'level_options'=> get_privacy_level_options(), |
---|
659 | 'level_options_selected' => 0, |
---|
660 | ) |
---|
661 | ); |
---|
662 | |
---|
663 | // metadata |
---|
664 | include_once( PHPWG_ROOT_PATH.'admin/site_reader_local.php'); |
---|
665 | $site_reader = new LocalSiteReader('./'); |
---|
666 | $used_metadata = implode( ', ', $site_reader->get_metadata_attributes()); |
---|
667 | |
---|
668 | $template->assign( |
---|
669 | array( |
---|
670 | 'used_metadata' => $used_metadata, |
---|
671 | ) |
---|
672 | ); |
---|
673 | |
---|
674 | //derivatives |
---|
675 | $del_deriv_map = array(); |
---|
676 | foreach(ImageStdParams::get_defined_type_map() as $params) |
---|
677 | { |
---|
678 | $del_deriv_map[$params->type] = l10n($params->type); |
---|
679 | } |
---|
680 | $gen_deriv_map = $del_deriv_map; |
---|
681 | $del_deriv_map[IMG_CUSTOM] = l10n(IMG_CUSTOM); |
---|
682 | $template->assign( |
---|
683 | array( |
---|
684 | 'del_derivatives_types' => $del_deriv_map, |
---|
685 | 'generate_derivatives_types' => $gen_deriv_map, |
---|
686 | ) |
---|
687 | ); |
---|
688 | |
---|
689 | // +-----------------------------------------------------------------------+ |
---|
690 | // | global mode thumbnails | |
---|
691 | // +-----------------------------------------------------------------------+ |
---|
692 | |
---|
693 | // how many items to display on this page |
---|
694 | if (!empty($_GET['display'])) |
---|
695 | { |
---|
696 | if ('all' == $_GET['display']) |
---|
697 | { |
---|
698 | $page['nb_images'] = count($page['cat_elements_id']); |
---|
699 | } |
---|
700 | else |
---|
701 | { |
---|
702 | $page['nb_images'] = intval($_GET['display']); |
---|
703 | } |
---|
704 | } |
---|
705 | else |
---|
706 | { |
---|
707 | $page['nb_images'] = 20; |
---|
708 | } |
---|
709 | |
---|
710 | $nb_thumbs_page = 0; |
---|
711 | |
---|
712 | if (count($page['cat_elements_id']) > 0) |
---|
713 | { |
---|
714 | $nav_bar = create_navigation_bar( |
---|
715 | $base_url.get_query_string_diff(array('start')), |
---|
716 | count($page['cat_elements_id']), |
---|
717 | $page['start'], |
---|
718 | $page['nb_images'] |
---|
719 | ); |
---|
720 | $template->assign('navbar', $nav_bar); |
---|
721 | |
---|
722 | $is_category = false; |
---|
723 | if (isset($_SESSION['bulk_manager_filter']['category']) |
---|
724 | and !isset($_SESSION['bulk_manager_filter']['category_recursive'])) |
---|
725 | { |
---|
726 | $is_category = true; |
---|
727 | } |
---|
728 | |
---|
729 | if (isset($_SESSION['bulk_manager_filter']['prefilter']) |
---|
730 | and 'duplicates' == $_SESSION['bulk_manager_filter']['prefilter']) |
---|
731 | { |
---|
732 | $conf['order_by'] = ' ORDER BY file, id'; |
---|
733 | } |
---|
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 | // template thumbnail initialization |
---|
770 | while ($row = pwg_db_fetch_assoc($result)) |
---|
771 | { |
---|
772 | $nb_thumbs_page++; |
---|
773 | $src_image = new SrcImage($row); |
---|
774 | |
---|
775 | $title = render_element_name($row); |
---|
776 | if ($title != get_name_from_file($row['file'])) |
---|
777 | { |
---|
778 | $title.= ' ('.$row['file'].')'; |
---|
779 | } |
---|
780 | |
---|
781 | $template->append( |
---|
782 | 'thumbnails', |
---|
783 | array( |
---|
784 | 'ID' => $row['id'], |
---|
785 | 'TN_SRC' => DerivativeImage::url(IMG_THUMB, $src_image), |
---|
786 | 'FILE' => $row['file'], |
---|
787 | 'TITLE' => $title, |
---|
788 | 'LEVEL' => $row['level'], |
---|
789 | 'FILE_SRC' => DerivativeImage::url(IMG_LARGE, $src_image), |
---|
790 | 'U_EDIT' => get_root_url().'admin.php?page=photo-'.$row['id'], |
---|
791 | ) |
---|
792 | ); |
---|
793 | } |
---|
794 | } |
---|
795 | |
---|
796 | $template->assign( |
---|
797 | array( |
---|
798 | 'nb_thumbs_page' => $nb_thumbs_page, |
---|
799 | 'nb_thumbs_set' => count($page['cat_elements_id']), |
---|
800 | ) |
---|
801 | ); |
---|
802 | |
---|
803 | trigger_action('loc_end_element_set_global'); |
---|
804 | |
---|
805 | //----------------------------------------------------------- sending html code |
---|
806 | $template->assign_var_from_handle('ADMIN_CONTENT', 'batch_manager_global'); |
---|
807 | ?> |
---|