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 | 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 | // +-----------------------------------------------------------------------+ |
---|
40 | // | synchronize metadata | |
---|
41 | // +-----------------------------------------------------------------------+ |
---|
42 | |
---|
43 | if (isset($_GET['sync_metadata']) and !is_adviser()) |
---|
44 | { |
---|
45 | $query = ' |
---|
46 | SELECT path |
---|
47 | FROM '.IMAGES_TABLE.' |
---|
48 | WHERE id = '.$_GET['image_id'].' |
---|
49 | ;'; |
---|
50 | list($path) = pwg_db_fetch_row(pwg_query($query)); |
---|
51 | update_metadata(array($_GET['image_id'] => $path)); |
---|
52 | |
---|
53 | array_push($page['infos'], l10n('Metadata synchronized from file')); |
---|
54 | } |
---|
55 | |
---|
56 | //--------------------------------------------------------- update informations |
---|
57 | |
---|
58 | // first, we verify whether there is a mistake on the given creation date |
---|
59 | if (isset($_POST['date_creation_action']) |
---|
60 | and 'set' == $_POST['date_creation_action']) |
---|
61 | { |
---|
62 | if (!is_numeric($_POST['date_creation_year']) |
---|
63 | or !checkdate( |
---|
64 | $_POST['date_creation_month'], |
---|
65 | $_POST['date_creation_day'], |
---|
66 | $_POST['date_creation_year']) |
---|
67 | ) |
---|
68 | { |
---|
69 | array_push($page['errors'], l10n('wrong date')); |
---|
70 | } |
---|
71 | } |
---|
72 | |
---|
73 | if (isset($_POST['submit']) and count($page['errors']) == 0 and !is_adviser()) |
---|
74 | { |
---|
75 | $data = array(); |
---|
76 | $data{'id'} = $_GET['image_id']; |
---|
77 | $data{'name'} = $_POST['name']; |
---|
78 | $data{'author'} = $_POST['author']; |
---|
79 | $data['level'] = $_POST['level']; |
---|
80 | |
---|
81 | if ($conf['allow_html_descriptions']) |
---|
82 | { |
---|
83 | $data{'comment'} = @$_POST['description']; |
---|
84 | } |
---|
85 | else |
---|
86 | { |
---|
87 | $data{'comment'} = strip_tags(@$_POST['description']); |
---|
88 | } |
---|
89 | |
---|
90 | if (isset($_POST['date_creation_action'])) |
---|
91 | { |
---|
92 | if ('set' == $_POST['date_creation_action']) |
---|
93 | { |
---|
94 | $data{'date_creation'} = $_POST['date_creation_year'] |
---|
95 | .'-'.$_POST['date_creation_month'] |
---|
96 | .'-'.$_POST['date_creation_day']; |
---|
97 | } |
---|
98 | else if ('unset' == $_POST['date_creation_action']) |
---|
99 | { |
---|
100 | $data{'date_creation'} = ''; |
---|
101 | } |
---|
102 | } |
---|
103 | |
---|
104 | mass_updates( |
---|
105 | IMAGES_TABLE, |
---|
106 | array( |
---|
107 | 'primary' => array('id'), |
---|
108 | 'update' => array_diff(array_keys($data), array('id')) |
---|
109 | ), |
---|
110 | array($data) |
---|
111 | ); |
---|
112 | |
---|
113 | // time to deal with tags |
---|
114 | $tag_ids = array(); |
---|
115 | if (isset($_POST['tags'])) |
---|
116 | { |
---|
117 | $tag_ids = get_fckb_tag_ids($_POST['tags']); |
---|
118 | } |
---|
119 | set_tags($tag_ids, $_GET['image_id']); |
---|
120 | |
---|
121 | array_push($page['infos'], l10n('Picture informations updated')); |
---|
122 | } |
---|
123 | // associate the element to other categories than its storage category |
---|
124 | if (isset($_POST['associate']) |
---|
125 | and isset($_POST['cat_dissociated']) |
---|
126 | and count($_POST['cat_dissociated']) > 0 |
---|
127 | and !is_adviser() |
---|
128 | ) |
---|
129 | { |
---|
130 | associate_images_to_categories( |
---|
131 | array($_GET['image_id']), |
---|
132 | $_POST['cat_dissociated'] |
---|
133 | ); |
---|
134 | } |
---|
135 | // dissociate the element from categories (but not from its storage category) |
---|
136 | if (isset($_POST['dissociate']) |
---|
137 | and isset($_POST['cat_associated']) |
---|
138 | and count($_POST['cat_associated']) > 0 |
---|
139 | and !is_adviser() |
---|
140 | ) |
---|
141 | { |
---|
142 | $query = ' |
---|
143 | DELETE FROM '.IMAGE_CATEGORY_TABLE.' |
---|
144 | WHERE image_id = '.$_GET['image_id'].' |
---|
145 | AND category_id IN ('.implode(',', $_POST['cat_associated']).') |
---|
146 | '; |
---|
147 | pwg_query($query); |
---|
148 | |
---|
149 | update_category($_POST['cat_associated']); |
---|
150 | } |
---|
151 | // elect the element to represent the given categories |
---|
152 | if (isset($_POST['elect']) |
---|
153 | and isset($_POST['cat_dismissed']) |
---|
154 | and count($_POST['cat_dismissed']) > 0 |
---|
155 | and !is_adviser() |
---|
156 | ) |
---|
157 | { |
---|
158 | $datas = array(); |
---|
159 | foreach ($_POST['cat_dismissed'] as $category_id) |
---|
160 | { |
---|
161 | array_push($datas, |
---|
162 | array('id' => $category_id, |
---|
163 | 'representative_picture_id' => $_GET['image_id'])); |
---|
164 | } |
---|
165 | $fields = array('primary' => array('id'), |
---|
166 | 'update' => array('representative_picture_id')); |
---|
167 | mass_updates(CATEGORIES_TABLE, $fields, $datas); |
---|
168 | } |
---|
169 | // dismiss the element as representant of the given categories |
---|
170 | if (isset($_POST['dismiss']) |
---|
171 | and isset($_POST['cat_elected']) |
---|
172 | and count($_POST['cat_elected']) > 0 |
---|
173 | and !is_adviser() |
---|
174 | ) |
---|
175 | { |
---|
176 | set_random_representant($_POST['cat_elected']); |
---|
177 | } |
---|
178 | |
---|
179 | // tags |
---|
180 | $query = ' |
---|
181 | SELECT |
---|
182 | tag_id, |
---|
183 | name AS tag_name |
---|
184 | FROM '.IMAGE_TAG_TABLE.' AS it |
---|
185 | JOIN '.TAGS_TABLE.' AS t ON t.id = it.tag_id |
---|
186 | WHERE image_id = '.$_GET['image_id'].' |
---|
187 | ;'; |
---|
188 | $tags = get_fckb_taglist($query); |
---|
189 | |
---|
190 | // retrieving direct information about picture |
---|
191 | $query = ' |
---|
192 | SELECT * |
---|
193 | FROM '.IMAGES_TABLE.' |
---|
194 | WHERE id = '.$_GET['image_id'].' |
---|
195 | ;'; |
---|
196 | $row = pwg_db_fetch_assoc(pwg_query($query)); |
---|
197 | |
---|
198 | $storage_category_id = null; |
---|
199 | if (!empty($row['storage_category_id'])) |
---|
200 | { |
---|
201 | $storage_category_id = $row['storage_category_id']; |
---|
202 | } |
---|
203 | |
---|
204 | $image_file = $row['file']; |
---|
205 | |
---|
206 | // +-----------------------------------------------------------------------+ |
---|
207 | // | template init | |
---|
208 | // +-----------------------------------------------------------------------+ |
---|
209 | |
---|
210 | $template->set_filenames( |
---|
211 | array( |
---|
212 | 'picture_modify' => 'picture_modify.tpl' |
---|
213 | ) |
---|
214 | ); |
---|
215 | |
---|
216 | $template->assign( |
---|
217 | array( |
---|
218 | 'tags' => $tags, |
---|
219 | 'U_SYNC' => |
---|
220 | get_root_url().'admin.php?page=picture_modify'. |
---|
221 | '&image_id='.$_GET['image_id']. |
---|
222 | (isset($_GET['cat_id']) ? '&cat_id='.$_GET['cat_id'] : ''). |
---|
223 | '&sync_metadata=1', |
---|
224 | |
---|
225 | 'PATH'=>$row['path'], |
---|
226 | |
---|
227 | 'TN_SRC' => get_thumbnail_url($row), |
---|
228 | |
---|
229 | 'NAME' => |
---|
230 | isset($_POST['name']) ? |
---|
231 | stripslashes($_POST['name']) : @$row['name'], |
---|
232 | |
---|
233 | 'DIMENSIONS' => @$row['width'].' * '.@$row['height'], |
---|
234 | |
---|
235 | 'FILESIZE' => @$row['filesize'].' KB', |
---|
236 | |
---|
237 | 'REGISTRATION_DATE' => format_date($row['date_available']), |
---|
238 | |
---|
239 | 'AUTHOR' => isset($_POST['author']) ? $_POST['author'] : @$row['author'], |
---|
240 | |
---|
241 | 'DESCRIPTION' => |
---|
242 | htmlspecialchars( isset($_POST['description']) ? |
---|
243 | stripslashes($_POST['description']) : @$row['comment'] ), |
---|
244 | |
---|
245 | 'F_ACTION' => |
---|
246 | get_root_url().'admin.php' |
---|
247 | .get_query_string_diff(array('sync_metadata')) |
---|
248 | ) |
---|
249 | ); |
---|
250 | |
---|
251 | if ($row['has_high'] == 'true') |
---|
252 | { |
---|
253 | $template->assign( |
---|
254 | 'HIGH_FILESIZE', |
---|
255 | isset($row['high_filesize']) |
---|
256 | ? $row['high_filesize'].' KB' |
---|
257 | : l10n('unknown') |
---|
258 | ); |
---|
259 | } |
---|
260 | |
---|
261 | // image level options |
---|
262 | $tpl_options = array(); |
---|
263 | foreach ($conf['available_permission_levels'] as $level) |
---|
264 | { |
---|
265 | $tpl_options[$level] = l10n( sprintf('Level %d', $level) ).' ('.$level.')'; |
---|
266 | } |
---|
267 | $selected_level = isset($_POST['level']) ? $_POST['level'] : $row['level']; |
---|
268 | $template->assign( |
---|
269 | array( |
---|
270 | 'level_options'=> $tpl_options, |
---|
271 | 'level_options_selected' => array($selected_level) |
---|
272 | ) |
---|
273 | ); |
---|
274 | |
---|
275 | // creation date |
---|
276 | unset($day, $month, $year); |
---|
277 | |
---|
278 | if (isset($_POST['date_creation_action']) |
---|
279 | and 'set' == $_POST['date_creation_action']) |
---|
280 | { |
---|
281 | foreach (array('day', 'month', 'year') as $varname) |
---|
282 | { |
---|
283 | $$varname = $_POST['date_creation_'.$varname]; |
---|
284 | } |
---|
285 | } |
---|
286 | else if (isset($row['date_creation']) and !empty($row['date_creation'])) |
---|
287 | { |
---|
288 | list($year, $month, $day) = explode('-', $row['date_creation']); |
---|
289 | } |
---|
290 | else |
---|
291 | { |
---|
292 | list($year, $month, $day) = array('', 0, 0); |
---|
293 | } |
---|
294 | |
---|
295 | |
---|
296 | $month_list = $lang['month']; |
---|
297 | $month_list[0]='------------'; |
---|
298 | ksort($month_list); |
---|
299 | |
---|
300 | $template->assign( |
---|
301 | array( |
---|
302 | 'DATE_CREATION_DAY_VALUE' => $day, |
---|
303 | 'DATE_CREATION_MONTH_VALUE' => $month, |
---|
304 | 'DATE_CREATION_YEAR_VALUE' => $year, |
---|
305 | 'month_list' => $month_list, |
---|
306 | ) |
---|
307 | ); |
---|
308 | |
---|
309 | $query = ' |
---|
310 | SELECT category_id, uppercats |
---|
311 | FROM '.IMAGE_CATEGORY_TABLE.' AS ic |
---|
312 | INNER JOIN '.CATEGORIES_TABLE.' AS c |
---|
313 | ON c.id = ic.category_id |
---|
314 | WHERE image_id = '.$_GET['image_id'].' |
---|
315 | ;'; |
---|
316 | $result = pwg_query($query); |
---|
317 | |
---|
318 | while ($row = pwg_db_fetch_assoc($result)) |
---|
319 | { |
---|
320 | $name = |
---|
321 | get_cat_display_name_cache( |
---|
322 | $row['uppercats'], |
---|
323 | get_root_url().'admin.php?page=cat_modify&cat_id=', |
---|
324 | false |
---|
325 | ); |
---|
326 | |
---|
327 | if ($row['category_id'] == $storage_category_id) |
---|
328 | { |
---|
329 | $template->assign('STORAGE_CATEGORY', $name); |
---|
330 | } |
---|
331 | else |
---|
332 | { |
---|
333 | $template->append('related_categories', $name); |
---|
334 | } |
---|
335 | } |
---|
336 | |
---|
337 | // jump to link |
---|
338 | // |
---|
339 | // 1. find all linked categories that are reachable for the current user. |
---|
340 | // 2. if a category is available in the URL, use it if reachable |
---|
341 | // 3. if URL category not available or reachable, use the first reachable |
---|
342 | // linked category |
---|
343 | // 4. if no category reachable, no jumpto link |
---|
344 | |
---|
345 | $query = ' |
---|
346 | SELECT category_id |
---|
347 | FROM '.IMAGE_CATEGORY_TABLE.' |
---|
348 | WHERE image_id = '.$_GET['image_id'].' |
---|
349 | ;'; |
---|
350 | |
---|
351 | $authorizeds = array_diff( |
---|
352 | array_from_query($query, 'category_id'), |
---|
353 | explode( |
---|
354 | ',', |
---|
355 | calculate_permissions($user['id'], $user['status']) |
---|
356 | ) |
---|
357 | ); |
---|
358 | |
---|
359 | if (isset($_GET['cat_id']) |
---|
360 | and in_array($_GET['cat_id'], $authorizeds)) |
---|
361 | { |
---|
362 | $url_img = make_picture_url( |
---|
363 | array( |
---|
364 | 'image_id' => $_GET['image_id'], |
---|
365 | 'image_file' => $image_file, |
---|
366 | 'category' => $cache['cat_names'][ $_GET['cat_id'] ], |
---|
367 | ) |
---|
368 | ); |
---|
369 | } |
---|
370 | else |
---|
371 | { |
---|
372 | foreach ($authorizeds as $category) |
---|
373 | { |
---|
374 | $url_img = make_picture_url( |
---|
375 | array( |
---|
376 | 'image_id' => $_GET['image_id'], |
---|
377 | 'image_file' => $image_file, |
---|
378 | 'category' => $cache['cat_names'][ $category ], |
---|
379 | ) |
---|
380 | ); |
---|
381 | break; |
---|
382 | } |
---|
383 | } |
---|
384 | |
---|
385 | if (isset($url_img)) |
---|
386 | { |
---|
387 | $template->assign( 'U_JUMPTO', $url_img ); |
---|
388 | } |
---|
389 | |
---|
390 | // associate to another category ? |
---|
391 | $query = ' |
---|
392 | SELECT id,name,uppercats,global_rank |
---|
393 | FROM '.CATEGORIES_TABLE.' |
---|
394 | INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = category_id |
---|
395 | WHERE image_id = '.$_GET['image_id']; |
---|
396 | if (isset($storage_category_id)) |
---|
397 | { |
---|
398 | $query.= ' |
---|
399 | AND id != '.$storage_category_id; |
---|
400 | } |
---|
401 | $query.= ' |
---|
402 | ;'; |
---|
403 | display_select_cat_wrapper($query, array(), 'associated_options'); |
---|
404 | |
---|
405 | $result = pwg_query($query); |
---|
406 | $associateds = array(-1); |
---|
407 | if (isset($storage_category_id)) |
---|
408 | { |
---|
409 | array_push($associateds, $storage_category_id); |
---|
410 | } |
---|
411 | while ($row = pwg_db_fetch_assoc($result)) |
---|
412 | { |
---|
413 | array_push($associateds, $row['id']); |
---|
414 | } |
---|
415 | $query = ' |
---|
416 | SELECT id,name,uppercats,global_rank |
---|
417 | FROM '.CATEGORIES_TABLE.' |
---|
418 | WHERE id NOT IN ('.implode(',', $associateds).') |
---|
419 | ;'; |
---|
420 | display_select_cat_wrapper($query, array(), 'dissociated_options'); |
---|
421 | |
---|
422 | // representing |
---|
423 | $query = ' |
---|
424 | SELECT id,name,uppercats,global_rank |
---|
425 | FROM '.CATEGORIES_TABLE.' |
---|
426 | WHERE representative_picture_id = '.$_GET['image_id'].' |
---|
427 | ;'; |
---|
428 | display_select_cat_wrapper($query, array(), 'elected_options'); |
---|
429 | |
---|
430 | $query = ' |
---|
431 | SELECT id,name,uppercats,global_rank |
---|
432 | FROM '.CATEGORIES_TABLE.' |
---|
433 | WHERE representative_picture_id != '.$_GET['image_id'].' |
---|
434 | OR representative_picture_id IS NULL |
---|
435 | ;'; |
---|
436 | display_select_cat_wrapper($query, array(), 'dismissed_options'); |
---|
437 | |
---|
438 | //----------------------------------------------------------- sending html code |
---|
439 | |
---|
440 | $template->assign_var_from_handle('ADMIN_CONTENT', 'picture_modify'); |
---|
441 | ?> |
---|