1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | Piwigo - a PHP based photo gallery | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | Copyright(C) 2008-2014 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 | if(!defined("PHPWG_ROOT_PATH")) |
---|
25 | { |
---|
26 | die('Hacking attempt!'); |
---|
27 | } |
---|
28 | |
---|
29 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
30 | |
---|
31 | // +-----------------------------------------------------------------------+ |
---|
32 | // | Check Access and exit when user status is not ok | |
---|
33 | // +-----------------------------------------------------------------------+ |
---|
34 | check_status(ACCESS_ADMINISTRATOR); |
---|
35 | |
---|
36 | check_input_parameter('image_id', $_GET, false, PATTERN_ID); |
---|
37 | check_input_parameter('cat_id', $_GET, false, PATTERN_ID); |
---|
38 | |
---|
39 | // represent |
---|
40 | $query = ' |
---|
41 | SELECT id |
---|
42 | FROM '.CATEGORIES_TABLE.' |
---|
43 | WHERE representative_picture_id = '.$_GET['image_id'].' |
---|
44 | ;'; |
---|
45 | $represent_options_selected = array_from_query($query, 'id'); |
---|
46 | |
---|
47 | // +-----------------------------------------------------------------------+ |
---|
48 | // | delete photo | |
---|
49 | // +-----------------------------------------------------------------------+ |
---|
50 | |
---|
51 | if (isset($_GET['delete'])) |
---|
52 | { |
---|
53 | check_pwg_token(); |
---|
54 | |
---|
55 | delete_elements(array($_GET['image_id']), true); |
---|
56 | invalidate_user_cache(); |
---|
57 | |
---|
58 | // where to redirect the user now? |
---|
59 | // |
---|
60 | // 1. if a category is available in the URL, use it |
---|
61 | // 2. else use the first reachable linked category |
---|
62 | // 3. redirect to gallery root |
---|
63 | |
---|
64 | if (isset($_GET['cat_id']) and !empty($_GET['cat_id'])) |
---|
65 | { |
---|
66 | redirect( |
---|
67 | make_index_url( |
---|
68 | array( |
---|
69 | 'category' => get_cat_info($_GET['cat_id']) |
---|
70 | ) |
---|
71 | ) |
---|
72 | ); |
---|
73 | } |
---|
74 | |
---|
75 | $query = ' |
---|
76 | SELECT category_id |
---|
77 | FROM '.IMAGE_CATEGORY_TABLE.' |
---|
78 | WHERE image_id = '.$_GET['image_id'].' |
---|
79 | ;'; |
---|
80 | |
---|
81 | $authorizeds = array_diff( |
---|
82 | array_from_query($query, 'category_id'), |
---|
83 | explode(',', calculate_permissions($user['id'], $user['status'])) |
---|
84 | ); |
---|
85 | |
---|
86 | foreach ($authorizeds as $category_id) |
---|
87 | { |
---|
88 | redirect( |
---|
89 | make_index_url( |
---|
90 | array( |
---|
91 | 'category' => get_cat_info($category_id) |
---|
92 | ) |
---|
93 | ) |
---|
94 | ); |
---|
95 | } |
---|
96 | |
---|
97 | redirect(make_index_url()); |
---|
98 | } |
---|
99 | |
---|
100 | // +-----------------------------------------------------------------------+ |
---|
101 | // | synchronize metadata | |
---|
102 | // +-----------------------------------------------------------------------+ |
---|
103 | |
---|
104 | if (isset($_GET['sync_metadata'])) |
---|
105 | { |
---|
106 | sync_metadata(array( intval($_GET['image_id']))); |
---|
107 | $page['infos'][] = l10n('Metadata synchronized from file'); |
---|
108 | } |
---|
109 | |
---|
110 | //--------------------------------------------------------- update informations |
---|
111 | |
---|
112 | // first, we verify whether there is a mistake on the given creation date |
---|
113 | if (isset($_POST['date_creation_action']) |
---|
114 | and 'set' == $_POST['date_creation_action']) |
---|
115 | { |
---|
116 | if (!is_numeric($_POST['date_creation_year']) |
---|
117 | or !checkdate( |
---|
118 | $_POST['date_creation_month'], |
---|
119 | $_POST['date_creation_day'], |
---|
120 | $_POST['date_creation_year']) |
---|
121 | ) |
---|
122 | { |
---|
123 | $page['errors'][] = l10n('wrong date'); |
---|
124 | } |
---|
125 | } |
---|
126 | |
---|
127 | if (isset($_POST['submit']) and count($page['errors']) == 0) |
---|
128 | { |
---|
129 | $data = array(); |
---|
130 | $data{'id'} = $_GET['image_id']; |
---|
131 | $data{'name'} = $_POST['name']; |
---|
132 | $data{'author'} = $_POST['author']; |
---|
133 | $data['level'] = $_POST['level']; |
---|
134 | |
---|
135 | if ($conf['allow_html_descriptions']) |
---|
136 | { |
---|
137 | $data{'comment'} = @$_POST['description']; |
---|
138 | } |
---|
139 | else |
---|
140 | { |
---|
141 | $data{'comment'} = strip_tags(@$_POST['description']); |
---|
142 | } |
---|
143 | |
---|
144 | if (!empty($_POST['date_creation_year'])) |
---|
145 | { |
---|
146 | $data{'date_creation'} = |
---|
147 | $_POST['date_creation_year'] |
---|
148 | .'-'.$_POST['date_creation_month'] |
---|
149 | .'-'.$_POST['date_creation_day'] |
---|
150 | .' '.$_POST['date_creation_time']; |
---|
151 | } |
---|
152 | else |
---|
153 | { |
---|
154 | $data{'date_creation'} = null; |
---|
155 | } |
---|
156 | |
---|
157 | single_update( |
---|
158 | IMAGES_TABLE, |
---|
159 | $data, |
---|
160 | array('id' => $data['id']) |
---|
161 | ); |
---|
162 | |
---|
163 | // time to deal with tags |
---|
164 | $tag_ids = array(); |
---|
165 | if (!empty($_POST['tags'])) |
---|
166 | { |
---|
167 | $tag_ids = get_tag_ids($_POST['tags']); |
---|
168 | } |
---|
169 | set_tags($tag_ids, $_GET['image_id']); |
---|
170 | |
---|
171 | // association to albums |
---|
172 | if (!isset($_POST['associate'])) |
---|
173 | { |
---|
174 | $_POST['associate'] = array(); |
---|
175 | } |
---|
176 | move_images_to_categories(array($_GET['image_id']), $_POST['associate']); |
---|
177 | |
---|
178 | invalidate_user_cache(); |
---|
179 | |
---|
180 | // thumbnail for albums |
---|
181 | if (!isset($_POST['represent'])) |
---|
182 | { |
---|
183 | $_POST['represent'] = array(); |
---|
184 | } |
---|
185 | |
---|
186 | $no_longer_thumbnail_for = array_diff($represent_options_selected, $_POST['represent']); |
---|
187 | if (count($no_longer_thumbnail_for) > 0) |
---|
188 | { |
---|
189 | set_random_representant($no_longer_thumbnail_for); |
---|
190 | } |
---|
191 | |
---|
192 | $new_thumbnail_for = array_diff($_POST['represent'], $represent_options_selected); |
---|
193 | if (count($new_thumbnail_for) > 0) |
---|
194 | { |
---|
195 | $query = ' |
---|
196 | UPDATE '.CATEGORIES_TABLE.' |
---|
197 | SET representative_picture_id = '.$_GET['image_id'].' |
---|
198 | WHERE id IN ('.implode(',', $new_thumbnail_for).') |
---|
199 | ;'; |
---|
200 | pwg_query($query); |
---|
201 | } |
---|
202 | |
---|
203 | $represent_options_selected = $_POST['represent']; |
---|
204 | |
---|
205 | $page['infos'][] = l10n('Photo informations updated'); |
---|
206 | } |
---|
207 | |
---|
208 | // tags |
---|
209 | $query = ' |
---|
210 | SELECT |
---|
211 | id, |
---|
212 | name |
---|
213 | FROM '.IMAGE_TAG_TABLE.' AS it |
---|
214 | JOIN '.TAGS_TABLE.' AS t ON t.id = it.tag_id |
---|
215 | WHERE image_id = '.$_GET['image_id'].' |
---|
216 | ;'; |
---|
217 | $tag_selection = get_taglist($query); |
---|
218 | |
---|
219 | $query = ' |
---|
220 | SELECT |
---|
221 | id, |
---|
222 | name |
---|
223 | FROM '.TAGS_TABLE.' |
---|
224 | ;'; |
---|
225 | $tags = get_taglist($query, false); |
---|
226 | |
---|
227 | // retrieving direct information about picture |
---|
228 | $query = ' |
---|
229 | SELECT * |
---|
230 | FROM '.IMAGES_TABLE.' |
---|
231 | WHERE id = '.$_GET['image_id'].' |
---|
232 | ;'; |
---|
233 | $row = pwg_db_fetch_assoc(pwg_query($query)); |
---|
234 | |
---|
235 | $storage_category_id = null; |
---|
236 | if (!empty($row['storage_category_id'])) |
---|
237 | { |
---|
238 | $storage_category_id = $row['storage_category_id']; |
---|
239 | } |
---|
240 | |
---|
241 | $image_file = $row['file']; |
---|
242 | |
---|
243 | // +-----------------------------------------------------------------------+ |
---|
244 | // | template init | |
---|
245 | // +-----------------------------------------------------------------------+ |
---|
246 | |
---|
247 | $template->set_filenames( |
---|
248 | array( |
---|
249 | 'picture_modify' => 'picture_modify.tpl' |
---|
250 | ) |
---|
251 | ); |
---|
252 | |
---|
253 | $admin_url_start = $admin_photo_base_url.'-properties'; |
---|
254 | $admin_url_start.= isset($_GET['cat_id']) ? '&cat_id='.$_GET['cat_id'] : ''; |
---|
255 | |
---|
256 | $template->assign( |
---|
257 | array( |
---|
258 | 'tag_selection' => $tag_selection, |
---|
259 | 'tags' => $tags, |
---|
260 | 'U_SYNC' => $admin_url_start.'&sync_metadata=1', |
---|
261 | 'U_DELETE' => $admin_url_start.'&delete=1&pwg_token='.get_pwg_token(), |
---|
262 | |
---|
263 | 'PATH'=>$row['path'], |
---|
264 | |
---|
265 | 'TN_SRC' => DerivativeImage::thumb_url($row), |
---|
266 | |
---|
267 | 'NAME' => |
---|
268 | isset($_POST['name']) ? |
---|
269 | stripslashes($_POST['name']) : @$row['name'], |
---|
270 | |
---|
271 | 'TITLE' => render_element_name($row), |
---|
272 | |
---|
273 | 'DIMENSIONS' => @$row['width'].' * '.@$row['height'], |
---|
274 | |
---|
275 | 'FILESIZE' => @$row['filesize'].' KB', |
---|
276 | |
---|
277 | 'REGISTRATION_DATE' => format_date($row['date_available']), |
---|
278 | |
---|
279 | 'AUTHOR' => htmlspecialchars( |
---|
280 | isset($_POST['author']) |
---|
281 | ? stripslashes($_POST['author']) |
---|
282 | : @$row['author'] |
---|
283 | ), |
---|
284 | |
---|
285 | 'DESCRIPTION' => |
---|
286 | htmlspecialchars( isset($_POST['description']) ? |
---|
287 | stripslashes($_POST['description']) : @$row['comment'] ), |
---|
288 | |
---|
289 | 'F_ACTION' => |
---|
290 | get_root_url().'admin.php' |
---|
291 | .get_query_string_diff(array('sync_metadata')) |
---|
292 | ) |
---|
293 | ); |
---|
294 | |
---|
295 | $added_by = 'N/A'; |
---|
296 | $query = ' |
---|
297 | SELECT '.$conf['user_fields']['username'].' AS username |
---|
298 | FROM '.USERS_TABLE.' |
---|
299 | WHERE '.$conf['user_fields']['id'].' = '.$row['added_by'].' |
---|
300 | ;'; |
---|
301 | $result = pwg_query($query); |
---|
302 | while ($user_row = pwg_db_fetch_assoc($result)) |
---|
303 | { |
---|
304 | $row['added_by'] = $user_row['username']; |
---|
305 | } |
---|
306 | |
---|
307 | $intro_vars = array( |
---|
308 | 'file' => l10n('Original file : %s', $row['file']), |
---|
309 | 'add_date' => l10n('Posted %s on %s', time_since($row['date_available'], 'year'), format_date($row['date_available'], false, false)), |
---|
310 | 'added_by' => l10n('Added by %s', $row['added_by']), |
---|
311 | 'size' => $row['width'].'×'.$row['height'].' pixels, '.sprintf('%.2f', $row['filesize']/1024).'MB', |
---|
312 | 'stats' => l10n('Visited %d times', $row['hit']), |
---|
313 | 'id' => l10n('Numeric identifier : %d', $row['id']), |
---|
314 | ); |
---|
315 | |
---|
316 | if ($conf['rate'] and !empty($row['rating_score'])) |
---|
317 | { |
---|
318 | $query = ' |
---|
319 | SELECT |
---|
320 | COUNT(*) |
---|
321 | FROM '.RATE_TABLE.' |
---|
322 | WHERE element_id = '.$_GET['image_id'].' |
---|
323 | ;'; |
---|
324 | list($row['nb_rates']) = pwg_db_fetch_row(pwg_query($query)); |
---|
325 | |
---|
326 | $intro_vars['stats'].= ', '.sprintf(l10n('Rated %d times, score : %.2f'), $row['nb_rates'], $row['rating_score']); |
---|
327 | } |
---|
328 | |
---|
329 | $template->assign('INTRO', $intro_vars); |
---|
330 | |
---|
331 | |
---|
332 | if (in_array(get_extension($row['path']),$conf['picture_ext'])) |
---|
333 | { |
---|
334 | $template->assign('U_COI', get_root_url().'admin.php?page=picture_coi&image_id='.$_GET['image_id']); |
---|
335 | } |
---|
336 | |
---|
337 | // image level options |
---|
338 | $selected_level = isset($_POST['level']) ? $_POST['level'] : $row['level']; |
---|
339 | $template->assign( |
---|
340 | array( |
---|
341 | 'level_options'=> get_privacy_level_options(), |
---|
342 | 'level_options_selected' => array($selected_level) |
---|
343 | ) |
---|
344 | ); |
---|
345 | |
---|
346 | // creation date |
---|
347 | unset($day, $month, $year); |
---|
348 | |
---|
349 | if (isset($_POST['date_creation_action']) |
---|
350 | and 'set' == $_POST['date_creation_action']) |
---|
351 | { |
---|
352 | foreach (array('day', 'month', 'year', 'time') as $varname) |
---|
353 | { |
---|
354 | $$varname = $_POST['date_creation_'.$varname]; |
---|
355 | } |
---|
356 | } |
---|
357 | else if (isset($row['date_creation']) and !empty($row['date_creation'])) |
---|
358 | { |
---|
359 | list($year, $month, $day) = explode('-', substr($row['date_creation'],0,10)); |
---|
360 | $time = substr($row['date_creation'],11); |
---|
361 | } |
---|
362 | else |
---|
363 | { |
---|
364 | list($year, $month, $day) = array('', 0, 0); |
---|
365 | $time = '00:00:00'; |
---|
366 | } |
---|
367 | |
---|
368 | |
---|
369 | $month_list = $lang['month']; |
---|
370 | $month_list[0]='------------'; |
---|
371 | ksort($month_list); |
---|
372 | |
---|
373 | $template->assign( |
---|
374 | array( |
---|
375 | 'DATE_CREATION_DAY_VALUE' => (int)$day, |
---|
376 | 'DATE_CREATION_MONTH_VALUE' => (int)$month, |
---|
377 | 'DATE_CREATION_YEAR_VALUE' => $year, |
---|
378 | 'DATE_CREATION_TIME_VALUE' => $time, |
---|
379 | 'month_list' => $month_list, |
---|
380 | ) |
---|
381 | ); |
---|
382 | |
---|
383 | $query = ' |
---|
384 | SELECT category_id, uppercats |
---|
385 | FROM '.IMAGE_CATEGORY_TABLE.' AS ic |
---|
386 | INNER JOIN '.CATEGORIES_TABLE.' AS c |
---|
387 | ON c.id = ic.category_id |
---|
388 | WHERE image_id = '.$_GET['image_id'].' |
---|
389 | ;'; |
---|
390 | $result = pwg_query($query); |
---|
391 | |
---|
392 | while ($row = pwg_db_fetch_assoc($result)) |
---|
393 | { |
---|
394 | $name = |
---|
395 | get_cat_display_name_cache( |
---|
396 | $row['uppercats'], |
---|
397 | get_root_url().'admin.php?page=album-' |
---|
398 | ); |
---|
399 | |
---|
400 | if ($row['category_id'] == $storage_category_id) |
---|
401 | { |
---|
402 | $template->assign('STORAGE_CATEGORY', $name); |
---|
403 | } |
---|
404 | else |
---|
405 | { |
---|
406 | $template->append('related_categories', $name); |
---|
407 | } |
---|
408 | } |
---|
409 | |
---|
410 | // jump to link |
---|
411 | // |
---|
412 | // 1. find all linked categories that are reachable for the current user. |
---|
413 | // 2. if a category is available in the URL, use it if reachable |
---|
414 | // 3. if URL category not available or reachable, use the first reachable |
---|
415 | // linked category |
---|
416 | // 4. if no category reachable, no jumpto link |
---|
417 | |
---|
418 | $query = ' |
---|
419 | SELECT category_id |
---|
420 | FROM '.IMAGE_CATEGORY_TABLE.' |
---|
421 | WHERE image_id = '.$_GET['image_id'].' |
---|
422 | ;'; |
---|
423 | |
---|
424 | $authorizeds = array_diff( |
---|
425 | array_from_query($query, 'category_id'), |
---|
426 | explode( |
---|
427 | ',', |
---|
428 | calculate_permissions($user['id'], $user['status']) |
---|
429 | ) |
---|
430 | ); |
---|
431 | |
---|
432 | if (isset($_GET['cat_id']) |
---|
433 | and in_array($_GET['cat_id'], $authorizeds)) |
---|
434 | { |
---|
435 | $url_img = make_picture_url( |
---|
436 | array( |
---|
437 | 'image_id' => $_GET['image_id'], |
---|
438 | 'image_file' => $image_file, |
---|
439 | 'category' => $cache['cat_names'][ $_GET['cat_id'] ], |
---|
440 | ) |
---|
441 | ); |
---|
442 | } |
---|
443 | else |
---|
444 | { |
---|
445 | foreach ($authorizeds as $category) |
---|
446 | { |
---|
447 | $url_img = make_picture_url( |
---|
448 | array( |
---|
449 | 'image_id' => $_GET['image_id'], |
---|
450 | 'image_file' => $image_file, |
---|
451 | 'category' => $cache['cat_names'][ $category ], |
---|
452 | ) |
---|
453 | ); |
---|
454 | break; |
---|
455 | } |
---|
456 | } |
---|
457 | |
---|
458 | if (isset($url_img)) |
---|
459 | { |
---|
460 | $template->assign( 'U_JUMPTO', $url_img ); |
---|
461 | } |
---|
462 | |
---|
463 | // associate to albums |
---|
464 | $query = ' |
---|
465 | SELECT id |
---|
466 | FROM '.CATEGORIES_TABLE.' |
---|
467 | INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = category_id |
---|
468 | WHERE image_id = '.$_GET['image_id'].' |
---|
469 | ;'; |
---|
470 | $associate_options_selected = array_from_query($query, 'id'); |
---|
471 | |
---|
472 | $query = ' |
---|
473 | SELECT id,name,uppercats,global_rank |
---|
474 | FROM '.CATEGORIES_TABLE.' |
---|
475 | ;'; |
---|
476 | display_select_cat_wrapper($query, $associate_options_selected, 'associate_options'); |
---|
477 | display_select_cat_wrapper($query, $represent_options_selected, 'represent_options'); |
---|
478 | |
---|
479 | //----------------------------------------------------------- sending html code |
---|
480 | |
---|
481 | $template->assign_var_from_handle('ADMIN_CONTENT', 'picture_modify'); |
---|
482 | ?> |
---|