1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | PhpWebGallery - a PHP based picture gallery | |
---|
4 | // | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | |
---|
5 | // | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net | |
---|
6 | // +-----------------------------------------------------------------------+ |
---|
7 | // | branch : BSF (Best So Far) |
---|
8 | // | file : $RCSfile$ |
---|
9 | // | last update : $Date: 2006-03-09 22:46:28 +0000 (Thu, 09 Mar 2006) $ |
---|
10 | // | last modifier : $Author: rub $ |
---|
11 | // | revision : $Revision: 1072 $ |
---|
12 | // +-----------------------------------------------------------------------+ |
---|
13 | // | This program is free software; you can redistribute it and/or modify | |
---|
14 | // | it under the terms of the GNU General Public License as published by | |
---|
15 | // | the Free Software Foundation | |
---|
16 | // | | |
---|
17 | // | This program is distributed in the hope that it will be useful, but | |
---|
18 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
19 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
20 | // | General Public License for more details. | |
---|
21 | // | | |
---|
22 | // | You should have received a copy of the GNU General Public License | |
---|
23 | // | along with this program; if not, write to the Free Software | |
---|
24 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
25 | // | USA. | |
---|
26 | // +-----------------------------------------------------------------------+ |
---|
27 | |
---|
28 | if(!defined("PHPWG_ROOT_PATH")) |
---|
29 | { |
---|
30 | die('Hacking attempt!'); |
---|
31 | } |
---|
32 | |
---|
33 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
34 | |
---|
35 | // +-----------------------------------------------------------------------+ |
---|
36 | // | Check Access and exit when user status is not ok | |
---|
37 | // +-----------------------------------------------------------------------+ |
---|
38 | check_status(ACCESS_ADMINISTRATOR); |
---|
39 | |
---|
40 | // +-----------------------------------------------------------------------+ |
---|
41 | // | synchronize metadata | |
---|
42 | // +-----------------------------------------------------------------------+ |
---|
43 | |
---|
44 | if (isset($_GET['sync_metadata'])) |
---|
45 | { |
---|
46 | $query = ' |
---|
47 | SELECT path |
---|
48 | FROM '.IMAGES_TABLE.' |
---|
49 | WHERE id = '.$_GET['image_id'].' |
---|
50 | ;'; |
---|
51 | list($path) = mysql_fetch_row(pwg_query($query)); |
---|
52 | update_metadata(array($_GET['image_id'] => $path)); |
---|
53 | |
---|
54 | array_push($page['infos'], l10n('Metadata synchronized from file')); |
---|
55 | } |
---|
56 | |
---|
57 | //--------------------------------------------------------- update informations |
---|
58 | |
---|
59 | // first, we verify whether there is a mistake on the given creation date |
---|
60 | if (isset($_POST['date_creation_action']) |
---|
61 | and 'set' == $_POST['date_creation_action']) |
---|
62 | { |
---|
63 | if (!checkdate( |
---|
64 | $_POST['date_creation_month'], |
---|
65 | $_POST['date_creation_day'], |
---|
66 | $_POST['date_creation_year']) |
---|
67 | ) |
---|
68 | { |
---|
69 | array_push($page['errors'], $lang['err_date']); |
---|
70 | } |
---|
71 | } |
---|
72 | |
---|
73 | if (isset($_POST['submit']) and count($page['errors']) == 0) |
---|
74 | { |
---|
75 | $data = array(); |
---|
76 | $data{'id'} = $_GET['image_id']; |
---|
77 | $data{'name'} = $_POST['name']; |
---|
78 | $data{'author'} = $_POST['author']; |
---|
79 | |
---|
80 | if ($conf['allow_html_descriptions']) |
---|
81 | { |
---|
82 | $data{'comment'} = @$_POST['description']; |
---|
83 | } |
---|
84 | else |
---|
85 | { |
---|
86 | $data{'comment'} = strip_tags(@$_POST['description']); |
---|
87 | } |
---|
88 | |
---|
89 | if (isset($_POST['date_creation_action'])) |
---|
90 | { |
---|
91 | if ('set' == $_POST['date_creation_action']) |
---|
92 | { |
---|
93 | $data{'date_creation'} = $_POST['date_creation_year'] |
---|
94 | .'-'.$_POST['date_creation_month'] |
---|
95 | .'-'.$_POST['date_creation_day']; |
---|
96 | } |
---|
97 | else if ('unset' == $_POST['date_creation_action']) |
---|
98 | { |
---|
99 | $data{'date_creation'} = ''; |
---|
100 | } |
---|
101 | } |
---|
102 | |
---|
103 | $keywords = get_keywords($_POST['keywords']); |
---|
104 | if (count($keywords) > 0) |
---|
105 | { |
---|
106 | $data{'keywords'} = implode(',', $keywords); |
---|
107 | } |
---|
108 | else |
---|
109 | { |
---|
110 | $data{'keywords'} = ''; |
---|
111 | } |
---|
112 | |
---|
113 | mass_updates( |
---|
114 | IMAGES_TABLE, |
---|
115 | array( |
---|
116 | 'primary' => array('id'), |
---|
117 | 'update' => array_diff(array_keys($data), array('id')) |
---|
118 | ), |
---|
119 | array($data) |
---|
120 | ); |
---|
121 | |
---|
122 | array_push($page['infos'], l10n('Picture informations updated')); |
---|
123 | } |
---|
124 | // associate the element to other categories than its storage category |
---|
125 | if (isset($_POST['associate']) |
---|
126 | and isset($_POST['cat_dissociated']) |
---|
127 | and count($_POST['cat_dissociated']) > 0) |
---|
128 | { |
---|
129 | $datas = array(); |
---|
130 | |
---|
131 | foreach ($_POST['cat_dissociated'] as $category_id) |
---|
132 | { |
---|
133 | array_push( |
---|
134 | $datas, |
---|
135 | array( |
---|
136 | 'image_id' => $_GET['image_id'], |
---|
137 | 'category_id' => $category_id |
---|
138 | ) |
---|
139 | ); |
---|
140 | } |
---|
141 | |
---|
142 | mass_inserts( |
---|
143 | IMAGE_CATEGORY_TABLE, |
---|
144 | array('image_id', 'category_id'), |
---|
145 | $datas |
---|
146 | ); |
---|
147 | |
---|
148 | check_links(); |
---|
149 | update_category($_POST['cat_dissociated']); |
---|
150 | } |
---|
151 | // dissociate the element from categories (but not from its storage category) |
---|
152 | if (isset($_POST['dissociate']) |
---|
153 | and isset($_POST['cat_associated']) |
---|
154 | and count($_POST['cat_associated']) > 0) |
---|
155 | { |
---|
156 | $associated_categories = $_POST['cat_associated']; |
---|
157 | |
---|
158 | // If the same element is associated to a source and its destinations, |
---|
159 | // dissociating the element with the source implies dissociating the |
---|
160 | // element fwith the destination. |
---|
161 | $destinations_of = get_destinations($_POST['cat_associated']); |
---|
162 | foreach ($destinations_of as $source => $destinations) |
---|
163 | { |
---|
164 | $associated_categories = array_merge( |
---|
165 | $associated_categories, |
---|
166 | $destinations |
---|
167 | ); |
---|
168 | } |
---|
169 | |
---|
170 | $query = ' |
---|
171 | DELETE FROM '.IMAGE_CATEGORY_TABLE.' |
---|
172 | WHERE image_id = '.$_GET['image_id'].' |
---|
173 | AND category_id IN ('.implode(',', $associated_categories).') |
---|
174 | AND is_storage = \'false\' |
---|
175 | '; |
---|
176 | pwg_query($query); |
---|
177 | |
---|
178 | check_links(); |
---|
179 | update_category($_POST['cat_associated']); |
---|
180 | } |
---|
181 | // elect the element to represent the given categories |
---|
182 | if (isset($_POST['elect']) |
---|
183 | and isset($_POST['cat_dismissed']) |
---|
184 | and count($_POST['cat_dismissed']) > 0) |
---|
185 | { |
---|
186 | $datas = array(); |
---|
187 | foreach ($_POST['cat_dismissed'] as $category_id) |
---|
188 | { |
---|
189 | array_push($datas, |
---|
190 | array('id' => $category_id, |
---|
191 | 'representative_picture_id' => $_GET['image_id'])); |
---|
192 | } |
---|
193 | $fields = array('primary' => array('id'), |
---|
194 | 'update' => array('representative_picture_id')); |
---|
195 | mass_updates(CATEGORIES_TABLE, $fields, $datas); |
---|
196 | } |
---|
197 | // dismiss the element as representant of the given categories |
---|
198 | if (isset($_POST['dismiss']) |
---|
199 | and isset($_POST['cat_elected']) |
---|
200 | and count($_POST['cat_elected']) > 0) |
---|
201 | { |
---|
202 | set_random_representant($_POST['cat_elected']); |
---|
203 | } |
---|
204 | |
---|
205 | // retrieving direct information about picture |
---|
206 | $query = ' |
---|
207 | SELECT * |
---|
208 | FROM '.IMAGES_TABLE.' |
---|
209 | INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON image_id = id |
---|
210 | WHERE id = '.$_GET['image_id'].' |
---|
211 | AND is_storage = \'true\' |
---|
212 | ;'; |
---|
213 | $row = mysql_fetch_array(pwg_query($query)); |
---|
214 | |
---|
215 | $storage_category_id = $row['category_id']; |
---|
216 | |
---|
217 | // Navigation path |
---|
218 | |
---|
219 | $date = isset($_POST['date_creation']) && empty($page['errors']) |
---|
220 | ?$_POST['date_creation']:date_convert_back(@$row['date_creation']); |
---|
221 | |
---|
222 | // +-----------------------------------------------------------------------+ |
---|
223 | // | template init | |
---|
224 | // +-----------------------------------------------------------------------+ |
---|
225 | |
---|
226 | $template->set_filenames( |
---|
227 | array( |
---|
228 | 'picture_modify' => 'admin/picture_modify.tpl' |
---|
229 | ) |
---|
230 | ); |
---|
231 | |
---|
232 | $template->assign_vars( |
---|
233 | array( |
---|
234 | 'U_SYNC' => |
---|
235 | PHPWG_ROOT_PATH.'admin.php?page=picture_modify'. |
---|
236 | '&image_id='.$_GET['image_id']. |
---|
237 | (isset($_GET['cat_id']) ? '&cat_id='.$_GET['cat_id'] : ''). |
---|
238 | '&sync_metadata=1', |
---|
239 | |
---|
240 | 'PATH'=>$row['path'], |
---|
241 | |
---|
242 | 'TN_SRC' => get_thumbnail_src($row['path'], @$row['tn_ext']), |
---|
243 | |
---|
244 | 'NAME' => |
---|
245 | isset($_POST['name']) ? |
---|
246 | stripslashes($_POST['name']) : @$row['name'], |
---|
247 | |
---|
248 | 'DIMENSIONS' => @$row['width'].' * '.@$row['height'], |
---|
249 | |
---|
250 | 'FILESIZE' => @$row['filesize'].' KB', |
---|
251 | |
---|
252 | 'REGISTRATION_DATE' => |
---|
253 | format_date($row['date_available'], 'mysql_datetime', false), |
---|
254 | |
---|
255 | 'AUTHOR' => isset($_POST['author']) ? $_POST['author'] : @$row['author'], |
---|
256 | |
---|
257 | 'CREATION_DATE' => $date, |
---|
258 | |
---|
259 | 'KEYWORDS' => |
---|
260 | isset($_POST['keywords']) ? |
---|
261 | stripslashes($_POST['keywords']) : @$row['keywords'], |
---|
262 | |
---|
263 | 'DESCRIPTION' => |
---|
264 | isset($_POST['description']) ? |
---|
265 | stripslashes($_POST['description']) : @$row['comment'], |
---|
266 | |
---|
267 | 'F_ACTION' => |
---|
268 | PHPWG_ROOT_PATH.'admin.php' |
---|
269 | .get_query_string_diff(array('sync_metadata')) |
---|
270 | ) |
---|
271 | ); |
---|
272 | |
---|
273 | // creation date |
---|
274 | unset($day, $month, $year); |
---|
275 | |
---|
276 | if (isset($_POST['date_creation_action']) |
---|
277 | and 'set' == $_POST['date_creation_action']) |
---|
278 | { |
---|
279 | foreach (array('day', 'month', 'year') as $varname) |
---|
280 | { |
---|
281 | $$varname = $_POST['date_creation_'.$varname]; |
---|
282 | } |
---|
283 | } |
---|
284 | else if (isset($row['date_creation']) and !empty($row['date_creation'])) |
---|
285 | { |
---|
286 | list($year, $month, $day) = explode('-', $row['date_creation']); |
---|
287 | } |
---|
288 | else |
---|
289 | { |
---|
290 | list($year, $month, $day) = array('', 0, 0); |
---|
291 | } |
---|
292 | get_day_list('date_creation_day', $day); |
---|
293 | get_month_list('date_creation_month', $month); |
---|
294 | $template->assign_vars(array('DATE_CREATION_YEAR_VALUE' => $year)); |
---|
295 | |
---|
296 | $query = ' |
---|
297 | SELECT category_id, uppercats |
---|
298 | FROM '.IMAGE_CATEGORY_TABLE.' AS ic |
---|
299 | INNER JOIN '.CATEGORIES_TABLE.' AS c |
---|
300 | ON c.id = ic.category_id |
---|
301 | WHERE image_id = '.$_GET['image_id'].' |
---|
302 | ;'; |
---|
303 | $result = pwg_query($query); |
---|
304 | |
---|
305 | if (mysql_num_rows($result) > 1) |
---|
306 | { |
---|
307 | $template->assign_block_vars('links', array()); |
---|
308 | } |
---|
309 | |
---|
310 | while ($row = mysql_fetch_array($result)) |
---|
311 | { |
---|
312 | $name = |
---|
313 | get_cat_display_name_cache( |
---|
314 | $row['uppercats'], |
---|
315 | PHPWG_ROOT_PATH.'admin.php?page=cat_modify&cat_id=', |
---|
316 | false |
---|
317 | ); |
---|
318 | |
---|
319 | if ($row['category_id'] == $storage_category_id) |
---|
320 | { |
---|
321 | $template->assign_vars(array('STORAGE_CATEGORY' => $name)); |
---|
322 | } |
---|
323 | else |
---|
324 | { |
---|
325 | $template->assign_block_vars('links.category', array('NAME' => $name)); |
---|
326 | } |
---|
327 | } |
---|
328 | |
---|
329 | // jump to link |
---|
330 | // |
---|
331 | // 1. find all linked categories that are reachable for the current user. |
---|
332 | // 2. if a category is available in the URL, use it if reachable |
---|
333 | // 3. if URL category not available or reachable, use the first reachable |
---|
334 | // linked category |
---|
335 | // 4. if no category reachable, no jumpto link |
---|
336 | $base_url_img = PHPWG_ROOT_PATH.'picture.php'; |
---|
337 | $base_url_img.= '?image_id='.$_GET['image_id']; |
---|
338 | $base_url_img.= '&cat='; |
---|
339 | unset($url_img); |
---|
340 | |
---|
341 | $query = ' |
---|
342 | SELECT category_id |
---|
343 | FROM '.IMAGE_CATEGORY_TABLE.' |
---|
344 | WHERE image_id = '.$_GET['image_id'].' |
---|
345 | ;'; |
---|
346 | $authorizeds = array_diff( |
---|
347 | array_from_query($query, 'category_id'), |
---|
348 | explode(',', calculate_permissions($user['id'], $user['status'])) |
---|
349 | ); |
---|
350 | |
---|
351 | if (isset($_GET['cat_id']) |
---|
352 | and in_array($_GET['cat_id'], $authorizeds)) |
---|
353 | { |
---|
354 | $url_img = $base_url_img.$_GET['cat_id']; |
---|
355 | } |
---|
356 | else |
---|
357 | { |
---|
358 | foreach ($authorizeds as $category) |
---|
359 | { |
---|
360 | $url_img = $base_url_img.$category; |
---|
361 | break; |
---|
362 | } |
---|
363 | } |
---|
364 | |
---|
365 | if (isset($url_img)) |
---|
366 | { |
---|
367 | $template->assign_block_vars( |
---|
368 | 'jumpto', |
---|
369 | array( |
---|
370 | 'URL' => $url_img |
---|
371 | ) |
---|
372 | ); |
---|
373 | } |
---|
374 | |
---|
375 | // associate to another category ? |
---|
376 | $query = ' |
---|
377 | SELECT id,name,uppercats,global_rank |
---|
378 | FROM '.CATEGORIES_TABLE.' |
---|
379 | INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = category_id |
---|
380 | WHERE image_id = '.$_GET['image_id'].' |
---|
381 | AND is_storage = \'false\' |
---|
382 | ;'; |
---|
383 | display_select_cat_wrapper($query, array(), 'associated_option'); |
---|
384 | |
---|
385 | $result = pwg_query($query); |
---|
386 | $associateds = array($storage_category_id); |
---|
387 | while ($row = mysql_fetch_array($result)) |
---|
388 | { |
---|
389 | array_push($associateds, $row['id']); |
---|
390 | } |
---|
391 | $query = ' |
---|
392 | SELECT id,name,uppercats,global_rank |
---|
393 | FROM '.CATEGORIES_TABLE.' |
---|
394 | WHERE id NOT IN ('.implode(',', $associateds).') |
---|
395 | ;'; |
---|
396 | display_select_cat_wrapper($query, array(), 'dissociated_option'); |
---|
397 | |
---|
398 | // representing |
---|
399 | $query = ' |
---|
400 | SELECT id,name,uppercats,global_rank |
---|
401 | FROM '.CATEGORIES_TABLE.' |
---|
402 | WHERE representative_picture_id = '.$_GET['image_id'].' |
---|
403 | ;'; |
---|
404 | display_select_cat_wrapper($query, array(), 'elected_option'); |
---|
405 | |
---|
406 | $query = ' |
---|
407 | SELECT id,name,uppercats,global_rank |
---|
408 | FROM '.CATEGORIES_TABLE.' |
---|
409 | WHERE representative_picture_id != '.$_GET['image_id'].' |
---|
410 | OR representative_picture_id IS NULL |
---|
411 | ;'; |
---|
412 | display_select_cat_wrapper($query, array(), 'dismissed_option'); |
---|
413 | |
---|
414 | //----------------------------------------------------------- sending html code |
---|
415 | |
---|
416 | $template->assign_var_from_handle('ADMIN_CONTENT', 'picture_modify'); |
---|
417 | ?> |
---|