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