1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | Piwigo - a PHP based photo gallery | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | Copyright(C) 2008-2012 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 | include_once(PHPWG_ROOT_PATH.'admin/include/functions_upload.inc.php'); |
---|
31 | include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php'); |
---|
32 | |
---|
33 | // +-----------------------------------------------------------------------+ |
---|
34 | // | Check Access and exit when user status is not ok | |
---|
35 | // +-----------------------------------------------------------------------+ |
---|
36 | check_status(ACCESS_ADMINISTRATOR); |
---|
37 | |
---|
38 | //-------------------------------------------------------- sections definitions |
---|
39 | if (!isset($_GET['section'])) |
---|
40 | { |
---|
41 | $page['section'] = 'main'; |
---|
42 | } |
---|
43 | else |
---|
44 | { |
---|
45 | $page['section'] = $_GET['section']; |
---|
46 | } |
---|
47 | |
---|
48 | $main_checkboxes = array( |
---|
49 | 'allow_user_registration', |
---|
50 | 'obligatory_user_mail_address', |
---|
51 | 'rate', |
---|
52 | 'rate_anonymous', |
---|
53 | 'email_admin_on_new_user', |
---|
54 | 'allow_user_customization', |
---|
55 | 'log', |
---|
56 | 'history_admin', |
---|
57 | 'history_guest', |
---|
58 | ); |
---|
59 | |
---|
60 | $sizes_checkboxes = array( |
---|
61 | 'original_resize', |
---|
62 | ); |
---|
63 | |
---|
64 | $comments_checkboxes = array( |
---|
65 | 'activate_comments', |
---|
66 | 'comments_forall', |
---|
67 | 'comments_validation', |
---|
68 | 'email_admin_on_comment', |
---|
69 | 'email_admin_on_comment_validation', |
---|
70 | 'user_can_delete_comment', |
---|
71 | 'user_can_edit_comment', |
---|
72 | 'email_admin_on_comment_edition', |
---|
73 | 'email_admin_on_comment_deletion' |
---|
74 | ); |
---|
75 | |
---|
76 | $display_checkboxes = array( |
---|
77 | 'menubar_filter_icon', |
---|
78 | 'index_sort_order_input', |
---|
79 | 'index_flat_icon', |
---|
80 | 'index_posted_date_icon', |
---|
81 | 'index_created_date_icon', |
---|
82 | 'index_slideshow_icon', |
---|
83 | 'index_new_icon', |
---|
84 | 'picture_metadata_icon', |
---|
85 | 'picture_slideshow_icon', |
---|
86 | 'picture_favorite_icon', |
---|
87 | 'picture_download_icon', |
---|
88 | 'picture_navigation_icons', |
---|
89 | 'picture_navigation_thumb', |
---|
90 | 'picture_menu', |
---|
91 | ); |
---|
92 | |
---|
93 | $display_info_checkboxes = array( |
---|
94 | 'author', |
---|
95 | 'created_on', |
---|
96 | 'posted_on', |
---|
97 | 'dimensions', |
---|
98 | 'file', |
---|
99 | 'filesize', |
---|
100 | 'tags', |
---|
101 | 'categories', |
---|
102 | 'visits', |
---|
103 | 'rating_score', |
---|
104 | 'privacy_level', |
---|
105 | ); |
---|
106 | |
---|
107 | // image order management |
---|
108 | $sort_fields = array( |
---|
109 | '' => '', |
---|
110 | 'rank' => l10n('Rank'), |
---|
111 | 'file' => l10n('File name'), |
---|
112 | 'name' => l10n('Photo name'), |
---|
113 | 'date_creation' => l10n('Creation date'), |
---|
114 | 'date_available' => l10n('Post date'), |
---|
115 | 'rating_score' => l10n('Rating score'), |
---|
116 | 'hit' => l10n('Most visited'), |
---|
117 | 'id' => 'Id', |
---|
118 | ); |
---|
119 | |
---|
120 | $sort_directions = array( |
---|
121 | 'ASC' => l10n('ascending'), |
---|
122 | 'DESC' => l10n('descending'), |
---|
123 | ); |
---|
124 | |
---|
125 | //------------------------------ verification and registration of modifications |
---|
126 | if (isset($_POST['submit'])) |
---|
127 | { |
---|
128 | $int_pattern = '/^\d+$/'; |
---|
129 | |
---|
130 | switch ($page['section']) |
---|
131 | { |
---|
132 | case 'main' : |
---|
133 | { |
---|
134 | if ( !isset($conf['order_by_custom']) and !isset($conf['order_by_inside_category_custom']) ) |
---|
135 | { |
---|
136 | if ( !empty($_POST['order_by_field']) ) |
---|
137 | { |
---|
138 | $order_by = array(); |
---|
139 | $order_by_inside_category = array(); |
---|
140 | |
---|
141 | for ($i=0; $i<count($_POST['order_by_field']); $i++) |
---|
142 | { |
---|
143 | if ( $i >= (count($sort_fields)-1) ) break; // limit to the number of available parameters |
---|
144 | if ( empty($_POST['order_by_field'][$i]) ) |
---|
145 | { |
---|
146 | array_push($page['errors'], l10n('No field selected')); |
---|
147 | break; |
---|
148 | } |
---|
149 | else |
---|
150 | { |
---|
151 | // there is no rank outside categories |
---|
152 | if ($_POST['order_by_field'][$i] != 'rank') |
---|
153 | { |
---|
154 | $order_by[] = $_POST['order_by_field'][$i].' '.$_POST['order_by_direction'][$i]; |
---|
155 | } |
---|
156 | $order_by_inside_category[] = $_POST['order_by_field'][$i].' '.$_POST['order_by_direction'][$i]; |
---|
157 | } |
---|
158 | } |
---|
159 | // must define a default order_by if user want to order by rank only |
---|
160 | if ( count($order_by) == 0 ) |
---|
161 | { |
---|
162 | $order_by = array('id ASC'); |
---|
163 | } |
---|
164 | |
---|
165 | $_POST['order_by'] = 'ORDER BY '.implode(', ', $order_by); |
---|
166 | $_POST['order_by_inside_category'] = 'ORDER BY '.implode(', ', $order_by_inside_category); |
---|
167 | unset($_POST['order_by_field']); |
---|
168 | } |
---|
169 | } |
---|
170 | |
---|
171 | foreach( $main_checkboxes as $checkbox) |
---|
172 | { |
---|
173 | $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true'; |
---|
174 | } |
---|
175 | break; |
---|
176 | } |
---|
177 | case 'sizes' : |
---|
178 | { |
---|
179 | $fields = array( |
---|
180 | 'original_resize', |
---|
181 | 'original_resize_maxwidth', |
---|
182 | 'original_resize_maxheight', |
---|
183 | 'original_resize_quality', |
---|
184 | ); |
---|
185 | |
---|
186 | $updates = array(); |
---|
187 | |
---|
188 | foreach ($fields as $field) |
---|
189 | { |
---|
190 | $value = !empty($_POST[$field]) ? $_POST[$field] : null; |
---|
191 | $form_values[$field] = $value; |
---|
192 | $updates[$field] = $value; |
---|
193 | } |
---|
194 | |
---|
195 | save_upload_form_config($updates, $page['errors']); |
---|
196 | |
---|
197 | if (count($page['errors']) == 0) |
---|
198 | { |
---|
199 | array_push( |
---|
200 | $page['infos'], |
---|
201 | l10n('Your configuration settings are saved') |
---|
202 | ); |
---|
203 | } |
---|
204 | |
---|
205 | break; |
---|
206 | } |
---|
207 | case 'comments' : |
---|
208 | { |
---|
209 | // the number of comments per page must be an integer between 5 and 50 |
---|
210 | // included |
---|
211 | if (!preg_match($int_pattern, $_POST['nb_comment_page']) |
---|
212 | or $_POST['nb_comment_page'] < 5 |
---|
213 | or $_POST['nb_comment_page'] > 50) |
---|
214 | { |
---|
215 | array_push($page['errors'], l10n('The number of comments a page must be between 5 and 50 included.')); |
---|
216 | } |
---|
217 | foreach( $comments_checkboxes as $checkbox) |
---|
218 | { |
---|
219 | $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true'; |
---|
220 | } |
---|
221 | break; |
---|
222 | } |
---|
223 | case 'default' : |
---|
224 | { |
---|
225 | // Never go here |
---|
226 | break; |
---|
227 | } |
---|
228 | case 'display' : |
---|
229 | { |
---|
230 | foreach( $display_checkboxes as $checkbox) |
---|
231 | { |
---|
232 | $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true'; |
---|
233 | } |
---|
234 | foreach( $display_info_checkboxes as $checkbox) |
---|
235 | { |
---|
236 | $_POST['picture_informations'][$checkbox] = |
---|
237 | empty($_POST['picture_informations'][$checkbox])? false : true; |
---|
238 | } |
---|
239 | $_POST['picture_informations'] = addslashes(serialize($_POST['picture_informations'])); |
---|
240 | break; |
---|
241 | } |
---|
242 | } |
---|
243 | |
---|
244 | // updating configuration if no error found |
---|
245 | if ('sizes' != $page['section'] and count($page['errors']) == 0) |
---|
246 | { |
---|
247 | //echo '<pre>'; print_r($_POST); echo '</pre>'; |
---|
248 | $result = pwg_query('SELECT param FROM '.CONFIG_TABLE); |
---|
249 | while ($row = pwg_db_fetch_assoc($result)) |
---|
250 | { |
---|
251 | if (isset($_POST[$row['param']])) |
---|
252 | { |
---|
253 | $value = $_POST[$row['param']]; |
---|
254 | |
---|
255 | if ('gallery_title' == $row['param']) |
---|
256 | { |
---|
257 | if (!$conf['allow_html_descriptions']) |
---|
258 | { |
---|
259 | $value = strip_tags($value); |
---|
260 | } |
---|
261 | } |
---|
262 | |
---|
263 | $query = ' |
---|
264 | UPDATE '.CONFIG_TABLE.' |
---|
265 | SET value = \''. str_replace("\'", "''", $value).'\' |
---|
266 | WHERE param = \''.$row['param'].'\' |
---|
267 | ;'; |
---|
268 | pwg_query($query); |
---|
269 | } |
---|
270 | } |
---|
271 | array_push($page['infos'], l10n('Information data registered in database')); |
---|
272 | } |
---|
273 | |
---|
274 | //------------------------------------------------------ $conf reinitialization |
---|
275 | load_conf_from_db(); |
---|
276 | } |
---|
277 | |
---|
278 | //----------------------------------------------------- template initialization |
---|
279 | $template->set_filename('config', 'configuration.tpl'); |
---|
280 | |
---|
281 | // TabSheet |
---|
282 | $tabsheet = new tabsheet(); |
---|
283 | // TabSheet initialization |
---|
284 | $tabsheet->add('main', l10n('Main'), $conf_link.'main'); |
---|
285 | $tabsheet->add('sizes', l10n('Photo Sizes'), $conf_link.'sizes'); |
---|
286 | $tabsheet->add('display', l10n('Display'), $conf_link.'display'); |
---|
287 | $tabsheet->add('comments', l10n('Comments'), $conf_link.'comments'); |
---|
288 | $tabsheet->add('default', l10n('Guest Settings'), $conf_link.'default'); |
---|
289 | // TabSheet selection |
---|
290 | $tabsheet->select($page['section']); |
---|
291 | // Assign tabsheet to template |
---|
292 | $tabsheet->assign(); |
---|
293 | |
---|
294 | $action = get_root_url().'admin.php?page=configuration'; |
---|
295 | $action.= '&section='.$page['section']; |
---|
296 | |
---|
297 | $template->assign( |
---|
298 | array( |
---|
299 | 'U_HELP' => get_root_url().'admin/popuphelp.php?page=configuration', |
---|
300 | 'F_ACTION'=>$action |
---|
301 | )); |
---|
302 | |
---|
303 | switch ($page['section']) |
---|
304 | { |
---|
305 | case 'main' : |
---|
306 | { |
---|
307 | |
---|
308 | function order_by_is_local() |
---|
309 | { |
---|
310 | @include(PHPWG_ROOT_PATH. 'local/config/config.inc.php'); |
---|
311 | if (isset($conf['local_dir_site'])) |
---|
312 | { |
---|
313 | @include(PHPWG_ROOT_PATH.PWG_LOCAL_DIR. 'config/config.inc.php'); |
---|
314 | } |
---|
315 | |
---|
316 | return isset($conf['order_by']) or isset($conf['order_by_inside_category']); |
---|
317 | } |
---|
318 | |
---|
319 | if (order_by_is_local()) |
---|
320 | { |
---|
321 | array_push($page['warnings'], l10n('You have specified <i>$conf[\'order_by\']</i> in your local configuration file, this parameter in deprecated, please remove it or rename it into <i>$conf[\'order_by_custom\']</i> !')); |
---|
322 | } |
---|
323 | |
---|
324 | if ( isset($conf['order_by_custom']) or isset($conf['order_by_inside_category_custom']) ) |
---|
325 | { |
---|
326 | $order_by = array(array( |
---|
327 | 'FIELD' => '', |
---|
328 | 'DIRECTION' => 'ASC', |
---|
329 | )); |
---|
330 | |
---|
331 | $template->assign('ORDER_BY_IS_CUSTOM', true); |
---|
332 | } |
---|
333 | else |
---|
334 | { |
---|
335 | $out = array(); |
---|
336 | $order_by = trim($conf['order_by_inside_category']); |
---|
337 | $order_by = str_replace('ORDER BY ', null, $order_by); |
---|
338 | $order_by = explode(', ', $order_by); |
---|
339 | foreach ($order_by as $field) |
---|
340 | { |
---|
341 | $field= explode(' ', $field); |
---|
342 | $out[] = array( |
---|
343 | 'FIELD' => $field[0], |
---|
344 | 'DIRECTION' => $field[1], |
---|
345 | ); |
---|
346 | } |
---|
347 | $order_by = $out; |
---|
348 | } |
---|
349 | |
---|
350 | $template->assign( |
---|
351 | 'main', |
---|
352 | array( |
---|
353 | 'CONF_GALLERY_TITLE' => htmlspecialchars($conf['gallery_title']), |
---|
354 | 'CONF_PAGE_BANNER' => htmlspecialchars($conf['page_banner']), |
---|
355 | 'week_starts_on_options' => array( |
---|
356 | 'sunday' => $lang['day'][0], |
---|
357 | 'monday' => $lang['day'][1], |
---|
358 | ), |
---|
359 | 'week_starts_on_options_selected' => $conf['week_starts_on'], |
---|
360 | 'order_by' => $order_by, |
---|
361 | 'order_field_options' => $sort_fields, |
---|
362 | 'order_direction_options' => $sort_directions, |
---|
363 | ) |
---|
364 | ); |
---|
365 | |
---|
366 | foreach ($main_checkboxes as $checkbox) |
---|
367 | { |
---|
368 | $template->append( |
---|
369 | 'main', |
---|
370 | array( |
---|
371 | $checkbox => $conf[$checkbox] |
---|
372 | ), |
---|
373 | true |
---|
374 | ); |
---|
375 | } |
---|
376 | break; |
---|
377 | } |
---|
378 | case 'comments' : |
---|
379 | { |
---|
380 | $template->assign( |
---|
381 | 'comments', |
---|
382 | array( |
---|
383 | 'NB_COMMENTS_PAGE'=>$conf['nb_comment_page'], |
---|
384 | 'comments_order'=>$conf['comments_order'], |
---|
385 | 'comments_order_options'=> $sort_directions |
---|
386 | ) |
---|
387 | ); |
---|
388 | |
---|
389 | foreach ($comments_checkboxes as $checkbox) |
---|
390 | { |
---|
391 | $template->append( |
---|
392 | 'comments', |
---|
393 | array( |
---|
394 | $checkbox => $conf[$checkbox] |
---|
395 | ), |
---|
396 | true |
---|
397 | ); |
---|
398 | } |
---|
399 | break; |
---|
400 | } |
---|
401 | case 'default' : |
---|
402 | { |
---|
403 | $edit_user = build_user($conf['guest_id'], false); |
---|
404 | include_once(PHPWG_ROOT_PATH.'profile.php'); |
---|
405 | |
---|
406 | $errors = array(); |
---|
407 | if (save_profile_from_post($edit_user, $errors)) |
---|
408 | { |
---|
409 | // Reload user |
---|
410 | $edit_user = build_user($conf['guest_id'], false); |
---|
411 | array_push($page['infos'], l10n('Information data registered in database')); |
---|
412 | } |
---|
413 | $page['errors'] = array_merge($page['errors'], $errors); |
---|
414 | |
---|
415 | load_profile_in_template( |
---|
416 | $action, |
---|
417 | '', |
---|
418 | $edit_user |
---|
419 | ); |
---|
420 | $template->assign('default', array()); |
---|
421 | break; |
---|
422 | } |
---|
423 | case 'display' : |
---|
424 | { |
---|
425 | foreach ($display_checkboxes as $checkbox) |
---|
426 | { |
---|
427 | $template->append( |
---|
428 | 'display', |
---|
429 | array( |
---|
430 | $checkbox => $conf[$checkbox] |
---|
431 | ), |
---|
432 | true |
---|
433 | ); |
---|
434 | } |
---|
435 | $template->append( |
---|
436 | 'display', |
---|
437 | array( |
---|
438 | 'picture_informations' => unserialize($conf['picture_informations']) |
---|
439 | ), |
---|
440 | true |
---|
441 | ); |
---|
442 | break; |
---|
443 | } |
---|
444 | case 'sizes' : |
---|
445 | { |
---|
446 | $template->assign( |
---|
447 | 'sizes', |
---|
448 | array( |
---|
449 | 'original_resize_maxwidth' => $conf['original_resize_maxwidth'], |
---|
450 | 'original_resize_maxheight' => $conf['original_resize_maxheight'], |
---|
451 | 'original_resize_quality' => $conf['original_resize_quality'], |
---|
452 | ) |
---|
453 | ); |
---|
454 | |
---|
455 | foreach ($sizes_checkboxes as $checkbox) |
---|
456 | { |
---|
457 | $template->append( |
---|
458 | 'sizes', |
---|
459 | array( |
---|
460 | $checkbox => $conf[$checkbox] |
---|
461 | ), |
---|
462 | true |
---|
463 | ); |
---|
464 | } |
---|
465 | |
---|
466 | break; |
---|
467 | } |
---|
468 | } |
---|
469 | |
---|
470 | //----------------------------------------------------------- sending html code |
---|
471 | $template->assign_var_from_handle('ADMIN_CONTENT', 'config'); |
---|
472 | ?> |
---|