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 | check_status(ACCESS_ADMINISTRATOR); |
---|
41 | |
---|
42 | trigger_action('loc_begin_element_set_global'); |
---|
43 | |
---|
44 | // +-----------------------------------------------------------------------+ |
---|
45 | // | deletion form submission | |
---|
46 | // +-----------------------------------------------------------------------+ |
---|
47 | |
---|
48 | // the $_POST['selection'] was already checked in element_set.php |
---|
49 | check_input_parameter('del_tags', $_POST, true, PATTERN_ID); |
---|
50 | check_input_parameter('associate', $_POST, false, PATTERN_ID); |
---|
51 | check_input_parameter('dissociate', $_POST, false, PATTERN_ID); |
---|
52 | |
---|
53 | if (isset($_POST['delete'])) |
---|
54 | { |
---|
55 | if (isset($_POST['confirm_deletion']) and 1 == $_POST['confirm_deletion']) |
---|
56 | { |
---|
57 | $collection = array(); |
---|
58 | |
---|
59 | switch ($_POST['target_deletion']) |
---|
60 | { |
---|
61 | case 'all' : |
---|
62 | { |
---|
63 | $collection = $page['cat_elements_id']; |
---|
64 | break; |
---|
65 | } |
---|
66 | case 'selection' : |
---|
67 | { |
---|
68 | if (!isset($_POST['selection']) or count($_POST['selection']) == 0) |
---|
69 | { |
---|
70 | array_push($page['errors'], l10n('Select at least one picture')); |
---|
71 | } |
---|
72 | else |
---|
73 | { |
---|
74 | $collection = $_POST['selection']; |
---|
75 | } |
---|
76 | break; |
---|
77 | } |
---|
78 | } |
---|
79 | |
---|
80 | if (count($collection) > 0) |
---|
81 | { |
---|
82 | $deleted_count = delete_elements($collection, true); |
---|
83 | if ($deleted_count > 0) |
---|
84 | { |
---|
85 | array_push( |
---|
86 | $page['infos'], |
---|
87 | sprintf( |
---|
88 | l10n_dec( |
---|
89 | '%d photo was deleted', |
---|
90 | '%d photos were deleted', |
---|
91 | $deleted_count |
---|
92 | ), |
---|
93 | $deleted_count |
---|
94 | ) |
---|
95 | ); |
---|
96 | } |
---|
97 | else |
---|
98 | { |
---|
99 | array_push($page['errors'], l10n('No photo can be deleted')); |
---|
100 | } |
---|
101 | } |
---|
102 | } |
---|
103 | else |
---|
104 | { |
---|
105 | array_push($page['errors'], l10n('You need to confirm deletion')); |
---|
106 | } |
---|
107 | } |
---|
108 | |
---|
109 | // +-----------------------------------------------------------------------+ |
---|
110 | // | global mode form submission | |
---|
111 | // +-----------------------------------------------------------------------+ |
---|
112 | |
---|
113 | if (isset($_POST['submit'])) |
---|
114 | { |
---|
115 | $collection = array(); |
---|
116 | |
---|
117 | // echo '<pre>'; |
---|
118 | // print_r($_POST); |
---|
119 | // echo '</pre>'; |
---|
120 | // exit(); |
---|
121 | |
---|
122 | switch ($_POST['target']) |
---|
123 | { |
---|
124 | case 'all' : |
---|
125 | { |
---|
126 | $collection = $page['cat_elements_id']; |
---|
127 | break; |
---|
128 | } |
---|
129 | case 'selection' : |
---|
130 | { |
---|
131 | if (!isset($_POST['selection']) or count($_POST['selection']) == 0) |
---|
132 | { |
---|
133 | array_push($page['errors'], l10n('Select at least one picture')); |
---|
134 | } |
---|
135 | else |
---|
136 | { |
---|
137 | $collection = $_POST['selection']; |
---|
138 | } |
---|
139 | break; |
---|
140 | } |
---|
141 | } |
---|
142 | |
---|
143 | if (isset($_POST['add_tags']) and count($collection) > 0) |
---|
144 | { |
---|
145 | $tag_ids = get_fckb_tag_ids($_POST['add_tags']); |
---|
146 | add_tags($tag_ids, $collection); |
---|
147 | } |
---|
148 | |
---|
149 | if (isset($_POST['del_tags']) and count($collection) > 0) |
---|
150 | { |
---|
151 | $query = ' |
---|
152 | DELETE |
---|
153 | FROM '.IMAGE_TAG_TABLE.' |
---|
154 | WHERE image_id IN ('.implode(',', $collection).') |
---|
155 | AND tag_id IN ('.implode(',', $_POST['del_tags']).') |
---|
156 | ;'; |
---|
157 | pwg_query($query); |
---|
158 | } |
---|
159 | |
---|
160 | if ($_POST['associate'] != 0 and count($collection) > 0) |
---|
161 | { |
---|
162 | associate_images_to_categories( |
---|
163 | $collection, |
---|
164 | array($_POST['associate']) |
---|
165 | ); |
---|
166 | } |
---|
167 | |
---|
168 | if ($_POST['dissociate'] != 0 and count($collection) > 0) |
---|
169 | { |
---|
170 | // physical links must not be broken, so we must first retrieve image_id |
---|
171 | // which create virtual links with the category to "dissociate from". |
---|
172 | $query = ' |
---|
173 | SELECT id |
---|
174 | FROM '.IMAGE_CATEGORY_TABLE.' |
---|
175 | INNER JOIN '.IMAGES_TABLE.' ON image_id = id |
---|
176 | WHERE category_id = '.$_POST['dissociate'].' |
---|
177 | AND id IN ('.implode(',', $collection).') |
---|
178 | AND ( |
---|
179 | category_id != storage_category_id |
---|
180 | OR storage_category_id IS NULL |
---|
181 | ) |
---|
182 | ;'; |
---|
183 | $dissociables = array_from_query($query, 'id'); |
---|
184 | |
---|
185 | if (!empty($dissociables)) |
---|
186 | { |
---|
187 | $query = ' |
---|
188 | DELETE |
---|
189 | FROM '.IMAGE_CATEGORY_TABLE.' |
---|
190 | WHERE category_id = '.$_POST['dissociate'].' |
---|
191 | AND image_id IN ('.implode(',', $dissociables).') |
---|
192 | '; |
---|
193 | pwg_query($query); |
---|
194 | |
---|
195 | // we remove the dissociated images if we are currently displaying the |
---|
196 | // category to dissociate from. |
---|
197 | if (is_numeric($_GET['cat']) and $_POST['dissociate'] == $_GET['cat']) |
---|
198 | { |
---|
199 | $page['cat_elements_id'] = array_diff( |
---|
200 | $page['cat_elements_id'], |
---|
201 | $dissociables |
---|
202 | ); |
---|
203 | } |
---|
204 | } |
---|
205 | |
---|
206 | update_category($_POST['dissociate']); |
---|
207 | } |
---|
208 | |
---|
209 | $datas = array(); |
---|
210 | $dbfields = array('primary' => array('id'), 'update' => array()); |
---|
211 | |
---|
212 | $formfields = array('author', 'name', 'date_creation', 'level'); |
---|
213 | foreach ($formfields as $formfield) |
---|
214 | { |
---|
215 | if ($_POST[$formfield.'_action'] != 'leave') |
---|
216 | { |
---|
217 | array_push($dbfields['update'], $formfield); |
---|
218 | } |
---|
219 | } |
---|
220 | |
---|
221 | // updating elements is useful only if needed... |
---|
222 | if (count($dbfields['update']) > 0 and count($collection) > 0) |
---|
223 | { |
---|
224 | $query = ' |
---|
225 | SELECT id |
---|
226 | FROM '.IMAGES_TABLE.' |
---|
227 | WHERE id IN ('.implode(',', $collection).') |
---|
228 | ;'; |
---|
229 | $result = pwg_query($query); |
---|
230 | |
---|
231 | while ($row = pwg_db_fetch_assoc($result)) |
---|
232 | { |
---|
233 | $data = array(); |
---|
234 | $data['id'] = $row['id']; |
---|
235 | |
---|
236 | if ('set' == $_POST['author_action']) |
---|
237 | { |
---|
238 | $data['author'] = $_POST['author']; |
---|
239 | if ('' == $data['author']) |
---|
240 | { |
---|
241 | unset($data['author']); |
---|
242 | } |
---|
243 | } |
---|
244 | |
---|
245 | if ('set' == $_POST['name_action']) |
---|
246 | { |
---|
247 | $data['name'] = $_POST['name']; |
---|
248 | if ('' == $data['name']) |
---|
249 | { |
---|
250 | unset($data['name']); |
---|
251 | } |
---|
252 | } |
---|
253 | |
---|
254 | if ('set' == $_POST['date_creation_action']) |
---|
255 | { |
---|
256 | $data['date_creation'] = |
---|
257 | $_POST['date_creation_year'] |
---|
258 | .'-'.$_POST['date_creation_month'] |
---|
259 | .'-'.$_POST['date_creation_day'] |
---|
260 | ; |
---|
261 | } |
---|
262 | |
---|
263 | if ('set' == $_POST['level_action']) |
---|
264 | { |
---|
265 | $data['level'] = $_POST['level']; |
---|
266 | } |
---|
267 | |
---|
268 | array_push($datas, $data); |
---|
269 | } |
---|
270 | // echo '<pre>'; print_r($datas); echo '</pre>'; |
---|
271 | mass_updates(IMAGES_TABLE, $dbfields, $datas); |
---|
272 | } |
---|
273 | } |
---|
274 | |
---|
275 | // +-----------------------------------------------------------------------+ |
---|
276 | // | template init | |
---|
277 | // +-----------------------------------------------------------------------+ |
---|
278 | $template->set_filenames( |
---|
279 | array('element_set_global' => 'element_set_global.tpl')); |
---|
280 | |
---|
281 | $base_url = get_root_url().'admin.php'; |
---|
282 | |
---|
283 | // $form_action = $base_url.'?page=element_set_global'; |
---|
284 | |
---|
285 | $template->assign( |
---|
286 | array( |
---|
287 | 'CATEGORIES_NAV'=>$page['title'], |
---|
288 | |
---|
289 | 'U_DISPLAY'=>$base_url.get_query_string_diff(array('display')), |
---|
290 | |
---|
291 | 'U_UNIT_MODE' |
---|
292 | => |
---|
293 | $base_url |
---|
294 | .get_query_string_diff(array('mode','display')) |
---|
295 | .'&mode=unit', |
---|
296 | |
---|
297 | 'F_ACTION'=>$base_url.get_query_string_diff(array()), |
---|
298 | ) |
---|
299 | ); |
---|
300 | |
---|
301 | // +-----------------------------------------------------------------------+ |
---|
302 | // | caddie options | |
---|
303 | // +-----------------------------------------------------------------------+ |
---|
304 | |
---|
305 | $template->assign('IN_CADDIE', 'caddie' == $_GET['cat'] ? true : false ); |
---|
306 | |
---|
307 | // +-----------------------------------------------------------------------+ |
---|
308 | // | deletion form | |
---|
309 | // +-----------------------------------------------------------------------+ |
---|
310 | |
---|
311 | // we can only remove photos that are not remote |
---|
312 | if (count($page['cat_elements_id']) > 0) |
---|
313 | { |
---|
314 | $query = ' |
---|
315 | SELECT |
---|
316 | COUNT(*) |
---|
317 | FROM '.IMAGES_TABLE.' |
---|
318 | WHERE id IN ('.implode(',', $page['cat_elements_id']).') |
---|
319 | AND path NOT LIKE \'http%\' |
---|
320 | ;'; |
---|
321 | list($counter) = pwg_db_fetch_row(pwg_query($query)); |
---|
322 | |
---|
323 | if ($counter > 0) |
---|
324 | { |
---|
325 | $template->assign('show_delete_form', true); |
---|
326 | } |
---|
327 | } |
---|
328 | |
---|
329 | // +-----------------------------------------------------------------------+ |
---|
330 | // | global mode form | |
---|
331 | // +-----------------------------------------------------------------------+ |
---|
332 | |
---|
333 | // Virtualy associate a picture to a category |
---|
334 | $query = ' |
---|
335 | SELECT id,name,uppercats,global_rank |
---|
336 | FROM '.CATEGORIES_TABLE.' |
---|
337 | ;'; |
---|
338 | display_select_cat_wrapper($query, array(), 'associate_options', true); |
---|
339 | |
---|
340 | // Dissociate from a category : categories listed for dissociation can |
---|
341 | // only represent virtual links. Links to physical categories can't be |
---|
342 | // broken |
---|
343 | if (count($page['cat_elements_id']) > 0) |
---|
344 | { |
---|
345 | $query = ' |
---|
346 | SELECT |
---|
347 | DISTINCT(category_id) AS id, |
---|
348 | c.name, |
---|
349 | c.uppercats, |
---|
350 | c.global_rank |
---|
351 | FROM '.IMAGE_CATEGORY_TABLE.' AS ic |
---|
352 | JOIN '.CATEGORIES_TABLE.' AS c ON c.id = ic.category_id |
---|
353 | JOIN '.IMAGES_TABLE.' AS i ON i.id = ic.image_id |
---|
354 | WHERE ic.image_id IN ('.implode(',', $page['cat_elements_id']).') |
---|
355 | AND ( |
---|
356 | ic.category_id != i.storage_category_id |
---|
357 | OR i.storage_category_id IS NULL |
---|
358 | ) |
---|
359 | ;'; |
---|
360 | display_select_cat_wrapper($query, array(), 'dissociate_options', true); |
---|
361 | } |
---|
362 | |
---|
363 | if (count($page['cat_elements_id']) > 0) |
---|
364 | { |
---|
365 | // remove tags |
---|
366 | $tags = get_common_tags($page['cat_elements_id'], -1); |
---|
367 | |
---|
368 | $template->assign( |
---|
369 | array( |
---|
370 | 'DEL_TAG_SELECTION' => get_html_tag_selection($tags, 'del_tags'), |
---|
371 | ) |
---|
372 | ); |
---|
373 | } |
---|
374 | |
---|
375 | // creation date |
---|
376 | $day = |
---|
377 | empty($_POST['date_creation_day']) ? date('j') : $_POST['date_creation_day']; |
---|
378 | |
---|
379 | $month = |
---|
380 | empty($_POST['date_creation_month']) ? date('n') : $_POST['date_creation_month']; |
---|
381 | |
---|
382 | $year = |
---|
383 | empty($_POST['date_creation_year']) ? date('Y') : $_POST['date_creation_year']; |
---|
384 | |
---|
385 | $month_list = $lang['month']; |
---|
386 | $month_list[0]='------------'; |
---|
387 | ksort($month_list); |
---|
388 | $template->assign( array( |
---|
389 | 'month_list' => $month_list, |
---|
390 | 'DATE_CREATION_DAY' => (int)$day, |
---|
391 | 'DATE_CREATION_MONTH'=> (int)$month, |
---|
392 | 'DATE_CREATION_YEAR' => (int)$year, |
---|
393 | ) |
---|
394 | ); |
---|
395 | |
---|
396 | // image level options |
---|
397 | $template->assign( |
---|
398 | array( |
---|
399 | 'level_options'=> get_privacy_level_options(), |
---|
400 | 'level_options_selected' => 0, |
---|
401 | ) |
---|
402 | ); |
---|
403 | |
---|
404 | // +-----------------------------------------------------------------------+ |
---|
405 | // | global mode thumbnails | |
---|
406 | // +-----------------------------------------------------------------------+ |
---|
407 | |
---|
408 | // how many items to display on this page |
---|
409 | if (!empty($_GET['display'])) |
---|
410 | { |
---|
411 | if ('all' == $_GET['display']) |
---|
412 | { |
---|
413 | $page['nb_images'] = count($page['cat_elements_id']); |
---|
414 | } |
---|
415 | else |
---|
416 | { |
---|
417 | $page['nb_images'] = intval($_GET['display']); |
---|
418 | } |
---|
419 | } |
---|
420 | else |
---|
421 | { |
---|
422 | $page['nb_images'] = 20; |
---|
423 | } |
---|
424 | |
---|
425 | if (count($page['cat_elements_id']) > 0) |
---|
426 | { |
---|
427 | $nav_bar = create_navigation_bar( |
---|
428 | $base_url.get_query_string_diff(array('start')), |
---|
429 | count($page['cat_elements_id']), |
---|
430 | $page['start'], |
---|
431 | $page['nb_images'] |
---|
432 | ); |
---|
433 | $template->assign('navbar', $nav_bar); |
---|
434 | |
---|
435 | $query = ' |
---|
436 | SELECT id,path,tn_ext,file,filesize,level |
---|
437 | FROM '.IMAGES_TABLE; |
---|
438 | |
---|
439 | if (is_numeric($_GET['cat'])) |
---|
440 | { |
---|
441 | $category_info = get_cat_info($_GET['cat']); |
---|
442 | |
---|
443 | $conf['order_by'] = $conf['order_by_inside_category']; |
---|
444 | if (!empty($category_info['image_order'])) |
---|
445 | { |
---|
446 | $conf['order_by'] = ' ORDER BY '.$category_info['image_order']; |
---|
447 | } |
---|
448 | |
---|
449 | $query.= ' |
---|
450 | JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id'; |
---|
451 | } |
---|
452 | |
---|
453 | $query.= ' |
---|
454 | WHERE id IN ('.implode(',', $page['cat_elements_id']).')'; |
---|
455 | |
---|
456 | if (is_numeric($_GET['cat'])) |
---|
457 | { |
---|
458 | $query.= ' |
---|
459 | AND category_id = '.$_GET['cat']; |
---|
460 | } |
---|
461 | |
---|
462 | $query.= ' |
---|
463 | '.$conf['order_by'].' |
---|
464 | LIMIT '.$page['nb_images'].' OFFSET '.$page['start'].' |
---|
465 | ;'; |
---|
466 | $result = pwg_query($query); |
---|
467 | |
---|
468 | // template thumbnail initialization |
---|
469 | while ($row = pwg_db_fetch_assoc($result)) |
---|
470 | { |
---|
471 | $src = get_thumbnail_url($row); |
---|
472 | |
---|
473 | $template->append( |
---|
474 | 'thumbnails', |
---|
475 | array( |
---|
476 | 'ID' => $row['id'], |
---|
477 | 'TN_SRC' => $src, |
---|
478 | 'FILE' => $row['file'], |
---|
479 | 'TITLE' => get_thumbnail_title($row), |
---|
480 | 'LEVEL' => $row['level'] |
---|
481 | ) |
---|
482 | ); |
---|
483 | } |
---|
484 | } |
---|
485 | |
---|
486 | trigger_action('loc_end_element_set_global'); |
---|
487 | |
---|
488 | //----------------------------------------------------------- sending html code |
---|
489 | $template->assign_var_from_handle('ADMIN_CONTENT', 'element_set_global'); |
---|
490 | ?> |
---|