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 | $represented_albums = query2array($query, null, '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 | if (isset($_POST['submit'])) |
---|
112 | { |
---|
113 | $data = array(); |
---|
114 | $data['id'] = $_GET['image_id']; |
---|
115 | $data['name'] = $_POST['name']; |
---|
116 | $data['author'] = $_POST['author']; |
---|
117 | $data['level'] = $_POST['level']; |
---|
118 | |
---|
119 | if ($conf['allow_html_descriptions']) |
---|
120 | { |
---|
121 | $data['comment'] = @$_POST['description']; |
---|
122 | } |
---|
123 | else |
---|
124 | { |
---|
125 | $data['comment'] = strip_tags(@$_POST['description']); |
---|
126 | } |
---|
127 | |
---|
128 | if (!empty($_POST['date_creation'])) |
---|
129 | { |
---|
130 | $data['date_creation'] = $_POST['date_creation']; |
---|
131 | } |
---|
132 | else |
---|
133 | { |
---|
134 | $data['date_creation'] = null; |
---|
135 | } |
---|
136 | |
---|
137 | $data = trigger_change('picture_modify_before_update', $data); |
---|
138 | |
---|
139 | single_update( |
---|
140 | IMAGES_TABLE, |
---|
141 | $data, |
---|
142 | array('id' => $data['id']) |
---|
143 | ); |
---|
144 | |
---|
145 | // time to deal with tags |
---|
146 | $tag_ids = array(); |
---|
147 | if (!empty($_POST['tags'])) |
---|
148 | { |
---|
149 | $tag_ids = get_tag_ids($_POST['tags']); |
---|
150 | } |
---|
151 | set_tags($tag_ids, $_GET['image_id']); |
---|
152 | |
---|
153 | // association to albums |
---|
154 | if (!isset($_POST['associate'])) |
---|
155 | { |
---|
156 | $_POST['associate'] = array(); |
---|
157 | } |
---|
158 | check_input_parameter('associate', $_POST, true, PATTERN_ID); |
---|
159 | move_images_to_categories(array($_GET['image_id']), $_POST['associate']); |
---|
160 | |
---|
161 | invalidate_user_cache(); |
---|
162 | |
---|
163 | // thumbnail for albums |
---|
164 | if (!isset($_POST['represent'])) |
---|
165 | { |
---|
166 | $_POST['represent'] = array(); |
---|
167 | } |
---|
168 | check_input_parameter('represent', $_POST, true, PATTERN_ID); |
---|
169 | |
---|
170 | $no_longer_thumbnail_for = array_diff($represented_albums, $_POST['represent']); |
---|
171 | if (count($no_longer_thumbnail_for) > 0) |
---|
172 | { |
---|
173 | set_random_representant($no_longer_thumbnail_for); |
---|
174 | } |
---|
175 | |
---|
176 | $new_thumbnail_for = array_diff($_POST['represent'], $represented_albums); |
---|
177 | if (count($new_thumbnail_for) > 0) |
---|
178 | { |
---|
179 | $query = ' |
---|
180 | UPDATE '.CATEGORIES_TABLE.' |
---|
181 | SET representative_picture_id = '.$_GET['image_id'].' |
---|
182 | WHERE id IN ('.implode(',', $new_thumbnail_for).') |
---|
183 | ;'; |
---|
184 | pwg_query($query); |
---|
185 | } |
---|
186 | |
---|
187 | $represented_albums = $_POST['represent']; |
---|
188 | |
---|
189 | $page['infos'][] = l10n('Photo informations updated'); |
---|
190 | } |
---|
191 | |
---|
192 | // tags |
---|
193 | $query = ' |
---|
194 | SELECT |
---|
195 | id, |
---|
196 | name |
---|
197 | FROM '.IMAGE_TAG_TABLE.' AS it |
---|
198 | JOIN '.TAGS_TABLE.' AS t ON t.id = it.tag_id |
---|
199 | WHERE image_id = '.$_GET['image_id'].' |
---|
200 | ;'; |
---|
201 | $tag_selection = get_taglist($query); |
---|
202 | |
---|
203 | // retrieving direct information about picture |
---|
204 | $query = ' |
---|
205 | SELECT * |
---|
206 | FROM '.IMAGES_TABLE.' |
---|
207 | WHERE id = '.$_GET['image_id'].' |
---|
208 | ;'; |
---|
209 | $row = pwg_db_fetch_assoc(pwg_query($query)); |
---|
210 | |
---|
211 | $storage_category_id = null; |
---|
212 | if (!empty($row['storage_category_id'])) |
---|
213 | { |
---|
214 | $storage_category_id = $row['storage_category_id']; |
---|
215 | } |
---|
216 | |
---|
217 | $image_file = $row['file']; |
---|
218 | |
---|
219 | // +-----------------------------------------------------------------------+ |
---|
220 | // | template init | |
---|
221 | // +-----------------------------------------------------------------------+ |
---|
222 | |
---|
223 | $template->set_filenames( |
---|
224 | array( |
---|
225 | 'picture_modify' => 'picture_modify.tpl' |
---|
226 | ) |
---|
227 | ); |
---|
228 | |
---|
229 | $admin_url_start = $admin_photo_base_url.'-properties'; |
---|
230 | $admin_url_start.= isset($_GET['cat_id']) ? '&cat_id='.$_GET['cat_id'] : ''; |
---|
231 | |
---|
232 | $src_image = new SrcImage($row); |
---|
233 | |
---|
234 | $template->assign( |
---|
235 | array( |
---|
236 | 'tag_selection' => $tag_selection, |
---|
237 | 'U_SYNC' => $admin_url_start.'&sync_metadata=1', |
---|
238 | 'U_DELETE' => $admin_url_start.'&delete=1&pwg_token='.get_pwg_token(), |
---|
239 | |
---|
240 | 'PATH'=>$row['path'], |
---|
241 | |
---|
242 | 'TN_SRC' => DerivativeImage::url(IMG_THUMB, $src_image), |
---|
243 | 'FILE_SRC' => DerivativeImage::url(IMG_LARGE, $src_image), |
---|
244 | |
---|
245 | 'NAME' => |
---|
246 | isset($_POST['name']) ? |
---|
247 | stripslashes($_POST['name']) : @$row['name'], |
---|
248 | |
---|
249 | 'TITLE' => render_element_name($row), |
---|
250 | |
---|
251 | 'DIMENSIONS' => @$row['width'].' * '.@$row['height'], |
---|
252 | |
---|
253 | 'FILESIZE' => @$row['filesize'].' KB', |
---|
254 | |
---|
255 | 'REGISTRATION_DATE' => format_date($row['date_available']), |
---|
256 | |
---|
257 | 'AUTHOR' => htmlspecialchars( |
---|
258 | isset($_POST['author']) |
---|
259 | ? stripslashes($_POST['author']) |
---|
260 | : @$row['author'] |
---|
261 | ), |
---|
262 | |
---|
263 | 'DATE_CREATION' => $row['date_creation'], |
---|
264 | |
---|
265 | 'DESCRIPTION' => |
---|
266 | htmlspecialchars( isset($_POST['description']) ? |
---|
267 | stripslashes($_POST['description']) : @$row['comment'] ), |
---|
268 | |
---|
269 | 'F_ACTION' => |
---|
270 | get_root_url().'admin.php' |
---|
271 | .get_query_string_diff(array('sync_metadata')) |
---|
272 | ) |
---|
273 | ); |
---|
274 | |
---|
275 | $added_by = 'N/A'; |
---|
276 | $query = ' |
---|
277 | SELECT '.$conf['user_fields']['username'].' AS username |
---|
278 | FROM '.USERS_TABLE.' |
---|
279 | WHERE '.$conf['user_fields']['id'].' = '.$row['added_by'].' |
---|
280 | ;'; |
---|
281 | $result = pwg_query($query); |
---|
282 | while ($user_row = pwg_db_fetch_assoc($result)) |
---|
283 | { |
---|
284 | $row['added_by'] = $user_row['username']; |
---|
285 | } |
---|
286 | |
---|
287 | $intro_vars = array( |
---|
288 | 'file' => l10n('Original file : %s', $row['file']), |
---|
289 | 'add_date' => l10n('Posted %s on %s', time_since($row['date_available'], 'year'), format_date($row['date_available'], array('day', 'month', 'year'))), |
---|
290 | 'added_by' => l10n('Added by %s', $row['added_by']), |
---|
291 | 'size' => $row['width'].'×'.$row['height'].' pixels, '.sprintf('%.2f', $row['filesize']/1024).'MB', |
---|
292 | 'stats' => l10n('Visited %d times', $row['hit']), |
---|
293 | 'id' => l10n('Numeric identifier : %d', $row['id']), |
---|
294 | ); |
---|
295 | |
---|
296 | if ($conf['rate'] and !empty($row['rating_score'])) |
---|
297 | { |
---|
298 | $query = ' |
---|
299 | SELECT |
---|
300 | COUNT(*) |
---|
301 | FROM '.RATE_TABLE.' |
---|
302 | WHERE element_id = '.$_GET['image_id'].' |
---|
303 | ;'; |
---|
304 | list($row['nb_rates']) = pwg_db_fetch_row(pwg_query($query)); |
---|
305 | |
---|
306 | $intro_vars['stats'].= ', '.sprintf(l10n('Rated %d times, score : %.2f'), $row['nb_rates'], $row['rating_score']); |
---|
307 | } |
---|
308 | |
---|
309 | $template->assign('INTRO', $intro_vars); |
---|
310 | |
---|
311 | |
---|
312 | if (in_array(get_extension($row['path']),$conf['picture_ext'])) |
---|
313 | { |
---|
314 | $template->assign('U_COI', get_root_url().'admin.php?page=picture_coi&image_id='.$_GET['image_id']); |
---|
315 | } |
---|
316 | |
---|
317 | // image level options |
---|
318 | $selected_level = isset($_POST['level']) ? $_POST['level'] : $row['level']; |
---|
319 | $template->assign( |
---|
320 | array( |
---|
321 | 'level_options'=> get_privacy_level_options(), |
---|
322 | 'level_options_selected' => array($selected_level) |
---|
323 | ) |
---|
324 | ); |
---|
325 | |
---|
326 | // categories |
---|
327 | $query = ' |
---|
328 | SELECT category_id, uppercats |
---|
329 | FROM '.IMAGE_CATEGORY_TABLE.' AS ic |
---|
330 | INNER JOIN '.CATEGORIES_TABLE.' AS c |
---|
331 | ON c.id = ic.category_id |
---|
332 | WHERE image_id = '.$_GET['image_id'].' |
---|
333 | ;'; |
---|
334 | $result = pwg_query($query); |
---|
335 | |
---|
336 | while ($row = pwg_db_fetch_assoc($result)) |
---|
337 | { |
---|
338 | $name = |
---|
339 | get_cat_display_name_cache( |
---|
340 | $row['uppercats'], |
---|
341 | get_root_url().'admin.php?page=album-' |
---|
342 | ); |
---|
343 | |
---|
344 | if ($row['category_id'] == $storage_category_id) |
---|
345 | { |
---|
346 | $template->assign('STORAGE_CATEGORY', $name); |
---|
347 | } |
---|
348 | else |
---|
349 | { |
---|
350 | $template->append('related_categories', $name); |
---|
351 | } |
---|
352 | } |
---|
353 | |
---|
354 | // jump to link |
---|
355 | // |
---|
356 | // 1. find all linked categories that are reachable for the current user. |
---|
357 | // 2. if a category is available in the URL, use it if reachable |
---|
358 | // 3. if URL category not available or reachable, use the first reachable |
---|
359 | // linked category |
---|
360 | // 4. if no category reachable, no jumpto link |
---|
361 | |
---|
362 | $query = ' |
---|
363 | SELECT category_id |
---|
364 | FROM '.IMAGE_CATEGORY_TABLE.' |
---|
365 | WHERE image_id = '.$_GET['image_id'].' |
---|
366 | ;'; |
---|
367 | |
---|
368 | $authorizeds = array_diff( |
---|
369 | array_from_query($query, 'category_id'), |
---|
370 | explode( |
---|
371 | ',', |
---|
372 | calculate_permissions($user['id'], $user['status']) |
---|
373 | ) |
---|
374 | ); |
---|
375 | |
---|
376 | if (isset($_GET['cat_id']) |
---|
377 | and in_array($_GET['cat_id'], $authorizeds)) |
---|
378 | { |
---|
379 | $url_img = make_picture_url( |
---|
380 | array( |
---|
381 | 'image_id' => $_GET['image_id'], |
---|
382 | 'image_file' => $image_file, |
---|
383 | 'category' => $cache['cat_names'][ $_GET['cat_id'] ], |
---|
384 | ) |
---|
385 | ); |
---|
386 | } |
---|
387 | else |
---|
388 | { |
---|
389 | foreach ($authorizeds as $category) |
---|
390 | { |
---|
391 | $url_img = make_picture_url( |
---|
392 | array( |
---|
393 | 'image_id' => $_GET['image_id'], |
---|
394 | 'image_file' => $image_file, |
---|
395 | 'category' => $cache['cat_names'][ $category ], |
---|
396 | ) |
---|
397 | ); |
---|
398 | break; |
---|
399 | } |
---|
400 | } |
---|
401 | |
---|
402 | if (isset($url_img)) |
---|
403 | { |
---|
404 | $template->assign( 'U_JUMPTO', $url_img ); |
---|
405 | } |
---|
406 | |
---|
407 | // associate to albums |
---|
408 | $query = ' |
---|
409 | SELECT id |
---|
410 | FROM '.CATEGORIES_TABLE.' |
---|
411 | INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = category_id |
---|
412 | WHERE image_id = '.$_GET['image_id'].' |
---|
413 | ;'; |
---|
414 | $associated_albums = query2array($query, null, 'id'); |
---|
415 | |
---|
416 | $template->assign(array( |
---|
417 | 'associated_albums' => $associated_albums, |
---|
418 | 'represented_albums' => $represented_albums, |
---|
419 | 'STORAGE_ALBUM' => $storage_category_id, |
---|
420 | 'CACHE_KEYS' => get_admin_client_cache_keys(array('tags', 'categories')), |
---|
421 | )); |
---|
422 | |
---|
423 | trigger_notify('loc_end_picture_modify'); |
---|
424 | |
---|
425 | //----------------------------------------------------------- sending html code |
---|
426 | |
---|
427 | $template->assign_var_from_handle('ADMIN_CONTENT', 'picture_modify'); |
---|
428 | ?> |
---|