1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | Piwigo - a PHP based photo gallery | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | Copyright(C) 2008-2013 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.'include/functions_mail.inc.php'); |
---|
30 | |
---|
31 | |
---|
32 | // get_complete_dir returns the concatenation of get_site_url and |
---|
33 | // get_local_dir |
---|
34 | // Example : "pets > rex > 1_year_old" is on the the same site as the |
---|
35 | // Piwigo files and this category has 22 for identifier |
---|
36 | // get_complete_dir(22) returns "./galleries/pets/rex/1_year_old/" |
---|
37 | function get_complete_dir( $category_id ) |
---|
38 | { |
---|
39 | return get_site_url($category_id).get_local_dir($category_id); |
---|
40 | } |
---|
41 | |
---|
42 | // get_local_dir returns an array with complete path without the site url |
---|
43 | // Example : "pets > rex > 1_year_old" is on the the same site as the |
---|
44 | // Piwigo files and this category has 22 for identifier |
---|
45 | // get_local_dir(22) returns "pets/rex/1_year_old/" |
---|
46 | function get_local_dir( $category_id ) |
---|
47 | { |
---|
48 | global $page; |
---|
49 | |
---|
50 | $uppercats = ''; |
---|
51 | $local_dir = ''; |
---|
52 | |
---|
53 | if ( isset( $page['plain_structure'][$category_id]['uppercats'] ) ) |
---|
54 | { |
---|
55 | $uppercats = $page['plain_structure'][$category_id]['uppercats']; |
---|
56 | } |
---|
57 | else |
---|
58 | { |
---|
59 | $query = 'SELECT uppercats'; |
---|
60 | $query.= ' FROM '.CATEGORIES_TABLE.' WHERE id = '.$category_id; |
---|
61 | $query.= ';'; |
---|
62 | $row = pwg_db_fetch_assoc( pwg_query( $query ) ); |
---|
63 | $uppercats = $row['uppercats']; |
---|
64 | } |
---|
65 | |
---|
66 | $upper_array = explode( ',', $uppercats ); |
---|
67 | |
---|
68 | $database_dirs = array(); |
---|
69 | $query = 'SELECT id,dir'; |
---|
70 | $query.= ' FROM '.CATEGORIES_TABLE.' WHERE id IN ('.$uppercats.')'; |
---|
71 | $query.= ';'; |
---|
72 | $result = pwg_query( $query ); |
---|
73 | while( $row = pwg_db_fetch_assoc( $result ) ) |
---|
74 | { |
---|
75 | $database_dirs[$row['id']] = $row['dir']; |
---|
76 | } |
---|
77 | foreach ($upper_array as $id) |
---|
78 | { |
---|
79 | $local_dir.= $database_dirs[$id].'/'; |
---|
80 | } |
---|
81 | |
---|
82 | return $local_dir; |
---|
83 | } |
---|
84 | |
---|
85 | // retrieving the site url : "http://domain.com/gallery/" or |
---|
86 | // simply "./galleries/" |
---|
87 | function get_site_url($category_id) |
---|
88 | { |
---|
89 | global $page; |
---|
90 | |
---|
91 | $query = ' |
---|
92 | SELECT galleries_url |
---|
93 | FROM '.SITES_TABLE.' AS s,'.CATEGORIES_TABLE.' AS c |
---|
94 | WHERE s.id = c.site_id |
---|
95 | AND c.id = '.$category_id.' |
---|
96 | ;'; |
---|
97 | $row = pwg_db_fetch_assoc(pwg_query($query)); |
---|
98 | return $row['galleries_url']; |
---|
99 | } |
---|
100 | |
---|
101 | // +-----------------------------------------------------------------------+ |
---|
102 | // | Check Access and exit when user status is not ok | |
---|
103 | // +-----------------------------------------------------------------------+ |
---|
104 | check_status(ACCESS_ADMINISTRATOR); |
---|
105 | |
---|
106 | trigger_action('loc_begin_cat_modify'); |
---|
107 | |
---|
108 | //---------------------------------------------------------------- verification |
---|
109 | if ( !isset( $_GET['cat_id'] ) || !is_numeric( $_GET['cat_id'] ) ) |
---|
110 | { |
---|
111 | trigger_error( 'missing cat_id param', E_USER_ERROR); |
---|
112 | } |
---|
113 | |
---|
114 | //--------------------------------------------------------- form criteria check |
---|
115 | if (isset($_POST['submit'])) |
---|
116 | { |
---|
117 | $data = |
---|
118 | array( |
---|
119 | 'id' => $_GET['cat_id'], |
---|
120 | 'name' => @$_POST['name'], |
---|
121 | 'comment' => |
---|
122 | $conf['allow_html_descriptions'] ? |
---|
123 | @$_POST['comment'] : strip_tags(@$_POST['comment']), |
---|
124 | ); |
---|
125 | |
---|
126 | if ($conf['activate_comments']) |
---|
127 | { |
---|
128 | $data['commentable'] = isset($_POST['commentable'])?$_POST['commentable']:'false'; |
---|
129 | } |
---|
130 | |
---|
131 | mass_updates( |
---|
132 | CATEGORIES_TABLE, |
---|
133 | array( |
---|
134 | 'primary' => array('id'), |
---|
135 | 'update' => array_diff(array_keys($data), array('id')) |
---|
136 | ), |
---|
137 | array($data) |
---|
138 | ); |
---|
139 | |
---|
140 | // retrieve cat infos before continuing (following updates are expensive) |
---|
141 | $cat_info = get_cat_info($_GET['cat_id']); |
---|
142 | |
---|
143 | if ($cat_info['visible'] != get_boolean( $_POST['visible'] ) ) |
---|
144 | { |
---|
145 | set_cat_visible(array($_GET['cat_id']), $_POST['visible']); |
---|
146 | } |
---|
147 | |
---|
148 | // in case the use moves his album to the gallery root, we force |
---|
149 | // $_POST['parent'] from 0 to null to be compared with |
---|
150 | // $cat_info['id_uppercat'] |
---|
151 | if (empty($_POST['parent'])) |
---|
152 | { |
---|
153 | $_POST['parent'] = null; |
---|
154 | } |
---|
155 | |
---|
156 | // only move virtual albums |
---|
157 | if (empty($cat_info['dir']) and $cat_info['id_uppercat'] != $_POST['parent']) |
---|
158 | { |
---|
159 | move_categories( array($_GET['cat_id']), $_POST['parent'] ); |
---|
160 | } |
---|
161 | |
---|
162 | $_SESSION['page_infos'][] = l10n('Album updated successfully'); |
---|
163 | $redirect = true; |
---|
164 | } |
---|
165 | elseif (isset($_POST['set_random_representant'])) |
---|
166 | { |
---|
167 | set_random_representant(array($_GET['cat_id'])); |
---|
168 | $redirect = true; |
---|
169 | } |
---|
170 | elseif (isset($_POST['delete_representant'])) |
---|
171 | { |
---|
172 | $query = ' |
---|
173 | UPDATE '.CATEGORIES_TABLE.' |
---|
174 | SET representative_picture_id = NULL |
---|
175 | WHERE id = '.$_GET['cat_id'].' |
---|
176 | ;'; |
---|
177 | pwg_query($query); |
---|
178 | $redirect = true; |
---|
179 | } |
---|
180 | |
---|
181 | if (isset($redirect)) |
---|
182 | { |
---|
183 | redirect($admin_album_base_url.'-properties'); |
---|
184 | } |
---|
185 | |
---|
186 | // nullable fields |
---|
187 | foreach (array('comment','dir','site_id', 'id_uppercat') as $nullable) |
---|
188 | { |
---|
189 | if (!isset($category[$nullable])) |
---|
190 | { |
---|
191 | $category[$nullable] = ''; |
---|
192 | } |
---|
193 | } |
---|
194 | |
---|
195 | $category['is_virtual'] = empty($category['dir']) ? true : false; |
---|
196 | |
---|
197 | $query = 'SELECT DISTINCT category_id |
---|
198 | FROM '.IMAGE_CATEGORY_TABLE.' |
---|
199 | WHERE category_id = '.$_GET['cat_id'].' |
---|
200 | LIMIT 1'; |
---|
201 | $result = pwg_query($query); |
---|
202 | $category['has_images'] = pwg_db_num_rows($result)>0 ? true : false; |
---|
203 | |
---|
204 | // Navigation path |
---|
205 | $navigation = get_cat_display_name_cache( |
---|
206 | $category['uppercats'], |
---|
207 | get_root_url().'admin.php?page=album-' |
---|
208 | ); |
---|
209 | |
---|
210 | $form_action = $admin_album_base_url.'-properties'; |
---|
211 | |
---|
212 | //----------------------------------------------------- template initialization |
---|
213 | $template->set_filename( 'album_properties', 'cat_modify.tpl'); |
---|
214 | |
---|
215 | $base_url = get_root_url().'admin.php?page='; |
---|
216 | $cat_list_url = $base_url.'cat_list'; |
---|
217 | |
---|
218 | $self_url = $cat_list_url; |
---|
219 | if (!empty($category['id_uppercat'])) |
---|
220 | { |
---|
221 | $self_url.= '&parent_id='.$category['id_uppercat']; |
---|
222 | } |
---|
223 | |
---|
224 | $template->assign( |
---|
225 | array( |
---|
226 | 'CATEGORIES_NAV' => $navigation, |
---|
227 | 'CAT_ID' => $category['id'], |
---|
228 | 'CAT_NAME' => @htmlspecialchars($category['name']), |
---|
229 | 'CAT_COMMENT' => @htmlspecialchars($category['comment']), |
---|
230 | 'CAT_VISIBLE' => boolean_to_string($category['visible']), |
---|
231 | |
---|
232 | 'U_JUMPTO' => make_index_url( |
---|
233 | array( |
---|
234 | 'category' => $category |
---|
235 | ) |
---|
236 | ), |
---|
237 | |
---|
238 | 'U_CHILDREN' => $cat_list_url.'&parent_id='.$category['id'], |
---|
239 | 'U_HELP' => get_root_url().'admin/popuphelp.php?page=cat_modify', |
---|
240 | |
---|
241 | 'F_ACTION' => $form_action, |
---|
242 | ) |
---|
243 | ); |
---|
244 | |
---|
245 | if ($conf['activate_comments']) |
---|
246 | { |
---|
247 | $template->assign('CAT_COMMENTABLE', boolean_to_string($category['commentable'])); |
---|
248 | } |
---|
249 | |
---|
250 | // manage album elements link |
---|
251 | if ($category['has_images']) |
---|
252 | { |
---|
253 | $template->assign( |
---|
254 | 'U_MANAGE_ELEMENTS', |
---|
255 | $base_url.'batch_manager&cat='.$category['id'] |
---|
256 | ); |
---|
257 | |
---|
258 | $query = ' |
---|
259 | SELECT |
---|
260 | COUNT(image_id), |
---|
261 | MIN(DATE(date_available)), |
---|
262 | MAX(DATE(date_available)) |
---|
263 | FROM '.IMAGES_TABLE.' |
---|
264 | JOIN '.IMAGE_CATEGORY_TABLE.' ON image_id = id |
---|
265 | WHERE category_id = '.$category['id'].' |
---|
266 | ;'; |
---|
267 | list($image_count, $min_date, $max_date) = pwg_db_fetch_row(pwg_query($query)); |
---|
268 | |
---|
269 | if ($min_date == $max_date) |
---|
270 | { |
---|
271 | $intro = sprintf( |
---|
272 | l10n('This album contains %d photos, added on %s.'), |
---|
273 | $image_count, |
---|
274 | format_date($min_date) |
---|
275 | ); |
---|
276 | } |
---|
277 | else |
---|
278 | { |
---|
279 | $intro = sprintf( |
---|
280 | l10n('This album contains %d photos, added between %s and %s.'), |
---|
281 | $image_count, |
---|
282 | format_date($min_date), |
---|
283 | format_date($max_date) |
---|
284 | ); |
---|
285 | } |
---|
286 | } |
---|
287 | else |
---|
288 | { |
---|
289 | $intro = l10n('This album contains no photo.'); |
---|
290 | } |
---|
291 | |
---|
292 | $intro.= '<br>'.sprintf(l10n('Numeric identifier : %d'), $category['id']); |
---|
293 | |
---|
294 | $template->assign('INTRO', $intro); |
---|
295 | |
---|
296 | $template->assign( |
---|
297 | 'U_MANAGE_RANKS', |
---|
298 | $base_url.'element_set_ranks&cat_id='.$category['id'] |
---|
299 | ); |
---|
300 | |
---|
301 | if ($category['is_virtual']) |
---|
302 | { |
---|
303 | $template->assign( |
---|
304 | array( |
---|
305 | 'U_DELETE' => $self_url.'&delete='.$category['id'].'&pwg_token='.get_pwg_token(), |
---|
306 | ) |
---|
307 | ); |
---|
308 | } |
---|
309 | else |
---|
310 | { |
---|
311 | $category['cat_full_dir'] = get_complete_dir($_GET['cat_id']); |
---|
312 | $template->assign( |
---|
313 | array( |
---|
314 | 'CAT_FULL_DIR' => preg_replace('/\/$/', '', $category['cat_full_dir']) |
---|
315 | ) |
---|
316 | ); |
---|
317 | |
---|
318 | if ($conf['enable_synchronization']) |
---|
319 | { |
---|
320 | $template->assign( |
---|
321 | 'U_SYNC', |
---|
322 | $base_url.'site_update&site=1&cat_id='.$category['id'] |
---|
323 | ); |
---|
324 | } |
---|
325 | |
---|
326 | } |
---|
327 | |
---|
328 | // representant management |
---|
329 | if ($category['has_images'] |
---|
330 | or !empty($category['representative_picture_id'])) |
---|
331 | { |
---|
332 | $tpl_representant = array(); |
---|
333 | |
---|
334 | // picture to display : the identified representant or the generic random |
---|
335 | // representant ? |
---|
336 | if (!empty($category['representative_picture_id'])) |
---|
337 | { |
---|
338 | $query = ' |
---|
339 | SELECT id,representative_ext,path |
---|
340 | FROM '.IMAGES_TABLE.' |
---|
341 | WHERE id = '.$category['representative_picture_id'].' |
---|
342 | ;'; |
---|
343 | $row = pwg_db_fetch_assoc(pwg_query($query)); |
---|
344 | $src = DerivativeImage::thumb_url($row); |
---|
345 | $url = get_root_url().'admin.php?page=photo-'.$category['representative_picture_id']; |
---|
346 | |
---|
347 | $tpl_representant['picture'] = |
---|
348 | array( |
---|
349 | 'SRC' => $src, |
---|
350 | 'URL' => $url |
---|
351 | ); |
---|
352 | } |
---|
353 | |
---|
354 | // can the admin choose to set a new random representant ? |
---|
355 | $tpl_representant['ALLOW_SET_RANDOM'] = ($category['has_images']) ? true : false; |
---|
356 | |
---|
357 | // can the admin delete the current representant ? |
---|
358 | if ( |
---|
359 | ($category['has_images'] |
---|
360 | and $conf['allow_random_representative']) |
---|
361 | or |
---|
362 | (!$category['has_images'] |
---|
363 | and !empty($category['representative_picture_id']))) |
---|
364 | { |
---|
365 | $tpl_representant['ALLOW_DELETE'] = true; |
---|
366 | } |
---|
367 | $template->assign('representant', $tpl_representant); |
---|
368 | } |
---|
369 | |
---|
370 | if ($category['is_virtual']) |
---|
371 | { |
---|
372 | // the category can be moved in any category but in itself, in any |
---|
373 | // sub-category |
---|
374 | $unmovables = get_subcat_ids(array($category['id'])); |
---|
375 | |
---|
376 | $query = ' |
---|
377 | SELECT id,name,uppercats,global_rank |
---|
378 | FROM '.CATEGORIES_TABLE.' |
---|
379 | WHERE id NOT IN ('.implode(',', $unmovables).') |
---|
380 | ;'; |
---|
381 | |
---|
382 | display_select_cat_wrapper( |
---|
383 | $query, |
---|
384 | empty($category['id_uppercat']) ? array() : array($category['id_uppercat']), |
---|
385 | 'move_cat_options' |
---|
386 | ); |
---|
387 | } |
---|
388 | |
---|
389 | trigger_action('loc_end_cat_modify'); |
---|
390 | |
---|
391 | //----------------------------------------------------------- sending html code |
---|
392 | $template->assign_var_from_handle('ADMIN_CONTENT', 'album_properties'); |
---|
393 | ?> |
---|