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 | $data = trigger_change('picture_modify_before_update', $data); |
---|
158 | |
---|
159 | single_update( |
---|
160 | IMAGES_TABLE, |
---|
161 | $data, |
---|
162 | array('id' => $data['id']) |
---|
163 | ); |
---|
164 | |
---|
165 | // time to deal with tags |
---|
166 | $tag_ids = array(); |
---|
167 | if (!empty($_POST['tags'])) |
---|
168 | { |
---|
169 | $tag_ids = get_tag_ids($_POST['tags']); |
---|
170 | } |
---|
171 | set_tags($tag_ids, $_GET['image_id']); |
---|
172 | |
---|
173 | // association to albums |
---|
174 | if (!isset($_POST['associate'])) |
---|
175 | { |
---|
176 | $_POST['associate'] = array(); |
---|
177 | } |
---|
178 | move_images_to_categories(array($_GET['image_id']), $_POST['associate']); |
---|
179 | |
---|
180 | invalidate_user_cache(); |
---|
181 | |
---|
182 | // thumbnail for albums |
---|
183 | if (!isset($_POST['represent'])) |
---|
184 | { |
---|
185 | $_POST['represent'] = array(); |
---|
186 | } |
---|
187 | |
---|
188 | $no_longer_thumbnail_for = array_diff($represent_options_selected, $_POST['represent']); |
---|
189 | if (count($no_longer_thumbnail_for) > 0) |
---|
190 | { |
---|
191 | set_random_representant($no_longer_thumbnail_for); |
---|
192 | } |
---|
193 | |
---|
194 | $new_thumbnail_for = array_diff($_POST['represent'], $represent_options_selected); |
---|
195 | if (count($new_thumbnail_for) > 0) |
---|
196 | { |
---|
197 | $query = ' |
---|
198 | UPDATE '.CATEGORIES_TABLE.' |
---|
199 | SET representative_picture_id = '.$_GET['image_id'].' |
---|
200 | WHERE id IN ('.implode(',', $new_thumbnail_for).') |
---|
201 | ;'; |
---|
202 | pwg_query($query); |
---|
203 | } |
---|
204 | |
---|
205 | $represent_options_selected = $_POST['represent']; |
---|
206 | |
---|
207 | $page['infos'][] = l10n('Photo informations updated'); |
---|
208 | } |
---|
209 | |
---|
210 | // tags |
---|
211 | $query = ' |
---|
212 | SELECT |
---|
213 | id, |
---|
214 | name |
---|
215 | FROM '.IMAGE_TAG_TABLE.' AS it |
---|
216 | JOIN '.TAGS_TABLE.' AS t ON t.id = it.tag_id |
---|
217 | WHERE image_id = '.$_GET['image_id'].' |
---|
218 | ;'; |
---|
219 | $tag_selection = get_taglist($query); |
---|
220 | |
---|
221 | $query = ' |
---|
222 | SELECT |
---|
223 | id, |
---|
224 | name |
---|
225 | FROM '.TAGS_TABLE.' |
---|
226 | ;'; |
---|
227 | $tags = get_taglist($query, false); |
---|
228 | |
---|
229 | // retrieving direct information about picture |
---|
230 | $query = ' |
---|
231 | SELECT * |
---|
232 | FROM '.IMAGES_TABLE.' |
---|
233 | WHERE id = '.$_GET['image_id'].' |
---|
234 | ;'; |
---|
235 | $row = pwg_db_fetch_assoc(pwg_query($query)); |
---|
236 | |
---|
237 | $storage_category_id = null; |
---|
238 | if (!empty($row['storage_category_id'])) |
---|
239 | { |
---|
240 | $storage_category_id = $row['storage_category_id']; |
---|
241 | } |
---|
242 | |
---|
243 | $image_file = $row['file']; |
---|
244 | |
---|
245 | // +-----------------------------------------------------------------------+ |
---|
246 | // | template init | |
---|
247 | // +-----------------------------------------------------------------------+ |
---|
248 | |
---|
249 | $template->set_filenames( |
---|
250 | array( |
---|
251 | 'picture_modify' => 'picture_modify.tpl' |
---|
252 | ) |
---|
253 | ); |
---|
254 | |
---|
255 | $admin_url_start = $admin_photo_base_url.'-properties'; |
---|
256 | $admin_url_start.= isset($_GET['cat_id']) ? '&cat_id='.$_GET['cat_id'] : ''; |
---|
257 | |
---|
258 | $template->assign( |
---|
259 | array( |
---|
260 | 'tag_selection' => $tag_selection, |
---|
261 | 'tags' => $tags, |
---|
262 | 'U_SYNC' => $admin_url_start.'&sync_metadata=1', |
---|
263 | 'U_DELETE' => $admin_url_start.'&delete=1&pwg_token='.get_pwg_token(), |
---|
264 | |
---|
265 | 'PATH'=>$row['path'], |
---|
266 | |
---|
267 | 'TN_SRC' => DerivativeImage::thumb_url($row), |
---|
268 | |
---|
269 | 'NAME' => |
---|
270 | isset($_POST['name']) ? |
---|
271 | stripslashes($_POST['name']) : @$row['name'], |
---|
272 | |
---|
273 | 'TITLE' => render_element_name($row), |
---|
274 | |
---|
275 | 'DIMENSIONS' => @$row['width'].' * '.@$row['height'], |
---|
276 | |
---|
277 | 'FILESIZE' => @$row['filesize'].' KB', |
---|
278 | |
---|
279 | 'REGISTRATION_DATE' => format_date($row['date_available']), |
---|
280 | |
---|
281 | 'AUTHOR' => htmlspecialchars( |
---|
282 | isset($_POST['author']) |
---|
283 | ? stripslashes($_POST['author']) |
---|
284 | : @$row['author'] |
---|
285 | ), |
---|
286 | |
---|
287 | 'DESCRIPTION' => |
---|
288 | htmlspecialchars( isset($_POST['description']) ? |
---|
289 | stripslashes($_POST['description']) : @$row['comment'] ), |
---|
290 | |
---|
291 | 'F_ACTION' => |
---|
292 | get_root_url().'admin.php' |
---|
293 | .get_query_string_diff(array('sync_metadata')) |
---|
294 | ) |
---|
295 | ); |
---|
296 | |
---|
297 | $added_by = 'N/A'; |
---|
298 | $query = ' |
---|
299 | SELECT '.$conf['user_fields']['username'].' AS username |
---|
300 | FROM '.USERS_TABLE.' |
---|
301 | WHERE '.$conf['user_fields']['id'].' = '.$row['added_by'].' |
---|
302 | ;'; |
---|
303 | $result = pwg_query($query); |
---|
304 | while ($user_row = pwg_db_fetch_assoc($result)) |
---|
305 | { |
---|
306 | $row['added_by'] = $user_row['username']; |
---|
307 | } |
---|
308 | |
---|
309 | $intro_vars = array( |
---|
310 | 'file' => l10n('Original file : %s', $row['file']), |
---|
311 | 'add_date' => l10n('Posted %s on %s', time_since($row['date_available'], 'year'), format_date($row['date_available'], false, false)), |
---|
312 | 'added_by' => l10n('Added by %s', $row['added_by']), |
---|
313 | 'size' => $row['width'].'×'.$row['height'].' pixels, '.sprintf('%.2f', $row['filesize']/1024).'MB', |
---|
314 | 'stats' => l10n('Visited %d times', $row['hit']), |
---|
315 | 'id' => l10n('Numeric identifier : %d', $row['id']), |
---|
316 | ); |
---|
317 | |
---|
318 | if ($conf['rate'] and !empty($row['rating_score'])) |
---|
319 | { |
---|
320 | $query = ' |
---|
321 | SELECT |
---|
322 | COUNT(*) |
---|
323 | FROM '.RATE_TABLE.' |
---|
324 | WHERE element_id = '.$_GET['image_id'].' |
---|
325 | ;'; |
---|
326 | list($row['nb_rates']) = pwg_db_fetch_row(pwg_query($query)); |
---|
327 | |
---|
328 | $intro_vars['stats'].= ', '.sprintf(l10n('Rated %d times, score : %.2f'), $row['nb_rates'], $row['rating_score']); |
---|
329 | } |
---|
330 | |
---|
331 | $template->assign('INTRO', $intro_vars); |
---|
332 | |
---|
333 | |
---|
334 | if (in_array(get_extension($row['path']),$conf['picture_ext'])) |
---|
335 | { |
---|
336 | $template->assign('U_COI', get_root_url().'admin.php?page=picture_coi&image_id='.$_GET['image_id']); |
---|
337 | } |
---|
338 | |
---|
339 | // image level options |
---|
340 | $selected_level = isset($_POST['level']) ? $_POST['level'] : $row['level']; |
---|
341 | $template->assign( |
---|
342 | array( |
---|
343 | 'level_options'=> get_privacy_level_options(), |
---|
344 | 'level_options_selected' => array($selected_level) |
---|
345 | ) |
---|
346 | ); |
---|
347 | |
---|
348 | // creation date |
---|
349 | unset($day, $month, $year); |
---|
350 | |
---|
351 | if (isset($_POST['date_creation_action']) |
---|
352 | and 'set' == $_POST['date_creation_action']) |
---|
353 | { |
---|
354 | foreach (array('day', 'month', 'year', 'time') as $varname) |
---|
355 | { |
---|
356 | $$varname = $_POST['date_creation_'.$varname]; |
---|
357 | } |
---|
358 | } |
---|
359 | else if (isset($row['date_creation']) and !empty($row['date_creation'])) |
---|
360 | { |
---|
361 | list($year, $month, $day) = explode('-', substr($row['date_creation'],0,10)); |
---|
362 | $time = substr($row['date_creation'],11); |
---|
363 | } |
---|
364 | else |
---|
365 | { |
---|
366 | list($year, $month, $day) = array('', 0, 0); |
---|
367 | $time = '00:00:00'; |
---|
368 | } |
---|
369 | |
---|
370 | |
---|
371 | $month_list = $lang['month']; |
---|
372 | $month_list[0]='------------'; |
---|
373 | ksort($month_list); |
---|
374 | |
---|
375 | $template->assign( |
---|
376 | array( |
---|
377 | 'DATE_CREATION_DAY_VALUE' => (int)$day, |
---|
378 | 'DATE_CREATION_MONTH_VALUE' => (int)$month, |
---|
379 | 'DATE_CREATION_YEAR_VALUE' => $year, |
---|
380 | 'DATE_CREATION_TIME_VALUE' => $time, |
---|
381 | 'month_list' => $month_list, |
---|
382 | ) |
---|
383 | ); |
---|
384 | |
---|
385 | $query = ' |
---|
386 | SELECT category_id, uppercats |
---|
387 | FROM '.IMAGE_CATEGORY_TABLE.' AS ic |
---|
388 | INNER JOIN '.CATEGORIES_TABLE.' AS c |
---|
389 | ON c.id = ic.category_id |
---|
390 | WHERE image_id = '.$_GET['image_id'].' |
---|
391 | ;'; |
---|
392 | $result = pwg_query($query); |
---|
393 | |
---|
394 | while ($row = pwg_db_fetch_assoc($result)) |
---|
395 | { |
---|
396 | $name = |
---|
397 | get_cat_display_name_cache( |
---|
398 | $row['uppercats'], |
---|
399 | get_root_url().'admin.php?page=album-' |
---|
400 | ); |
---|
401 | |
---|
402 | if ($row['category_id'] == $storage_category_id) |
---|
403 | { |
---|
404 | $template->assign('STORAGE_CATEGORY', $name); |
---|
405 | } |
---|
406 | else |
---|
407 | { |
---|
408 | $template->append('related_categories', $name); |
---|
409 | } |
---|
410 | } |
---|
411 | |
---|
412 | // jump to link |
---|
413 | // |
---|
414 | // 1. find all linked categories that are reachable for the current user. |
---|
415 | // 2. if a category is available in the URL, use it if reachable |
---|
416 | // 3. if URL category not available or reachable, use the first reachable |
---|
417 | // linked category |
---|
418 | // 4. if no category reachable, no jumpto link |
---|
419 | |
---|
420 | $query = ' |
---|
421 | SELECT category_id |
---|
422 | FROM '.IMAGE_CATEGORY_TABLE.' |
---|
423 | WHERE image_id = '.$_GET['image_id'].' |
---|
424 | ;'; |
---|
425 | |
---|
426 | $authorizeds = array_diff( |
---|
427 | array_from_query($query, 'category_id'), |
---|
428 | explode( |
---|
429 | ',', |
---|
430 | calculate_permissions($user['id'], $user['status']) |
---|
431 | ) |
---|
432 | ); |
---|
433 | |
---|
434 | if (isset($_GET['cat_id']) |
---|
435 | and in_array($_GET['cat_id'], $authorizeds)) |
---|
436 | { |
---|
437 | $url_img = make_picture_url( |
---|
438 | array( |
---|
439 | 'image_id' => $_GET['image_id'], |
---|
440 | 'image_file' => $image_file, |
---|
441 | 'category' => $cache['cat_names'][ $_GET['cat_id'] ], |
---|
442 | ) |
---|
443 | ); |
---|
444 | } |
---|
445 | else |
---|
446 | { |
---|
447 | foreach ($authorizeds as $category) |
---|
448 | { |
---|
449 | $url_img = make_picture_url( |
---|
450 | array( |
---|
451 | 'image_id' => $_GET['image_id'], |
---|
452 | 'image_file' => $image_file, |
---|
453 | 'category' => $cache['cat_names'][ $category ], |
---|
454 | ) |
---|
455 | ); |
---|
456 | break; |
---|
457 | } |
---|
458 | } |
---|
459 | |
---|
460 | if (isset($url_img)) |
---|
461 | { |
---|
462 | $template->assign( 'U_JUMPTO', $url_img ); |
---|
463 | } |
---|
464 | |
---|
465 | // associate to albums |
---|
466 | $query = ' |
---|
467 | SELECT id |
---|
468 | FROM '.CATEGORIES_TABLE.' |
---|
469 | INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = category_id |
---|
470 | WHERE image_id = '.$_GET['image_id'].' |
---|
471 | ;'; |
---|
472 | $associate_options_selected = array_from_query($query, 'id'); |
---|
473 | |
---|
474 | $query = ' |
---|
475 | SELECT id,name,uppercats,global_rank |
---|
476 | FROM '.CATEGORIES_TABLE.' |
---|
477 | ;'; |
---|
478 | display_select_cat_wrapper($query, $associate_options_selected, 'associate_options'); |
---|
479 | display_select_cat_wrapper($query, $represent_options_selected, 'represent_options'); |
---|
480 | |
---|
481 | //----------------------------------------------------------- sending html code |
---|
482 | |
---|
483 | $template->assign_var_from_handle('ADMIN_CONTENT', 'picture_modify'); |
---|
484 | ?> |
---|