1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | Piwigo - a PHP based photo gallery | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | Copyright(C) 2008-2011 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/tabsheet.class.php'); |
---|
31 | |
---|
32 | // +-----------------------------------------------------------------------+ |
---|
33 | // | Check Access and exit when user status is not ok | |
---|
34 | // +-----------------------------------------------------------------------+ |
---|
35 | check_status(ACCESS_ADMINISTRATOR); |
---|
36 | |
---|
37 | //-------------------------------------------------------- sections definitions |
---|
38 | |
---|
39 | check_input_parameter('section', $_GET, false, '/^[a-z]+$/i'); |
---|
40 | |
---|
41 | if (!isset($_GET['section'])) |
---|
42 | { |
---|
43 | $page['section'] = 'main'; |
---|
44 | } |
---|
45 | else |
---|
46 | { |
---|
47 | $page['section'] = $_GET['section']; |
---|
48 | } |
---|
49 | |
---|
50 | $main_checkboxes = array( |
---|
51 | 'gallery_locked', |
---|
52 | 'allow_user_registration', |
---|
53 | 'obligatory_user_mail_address', |
---|
54 | 'rate', |
---|
55 | 'rate_anonymous', |
---|
56 | 'email_admin_on_new_user', |
---|
57 | 'allow_user_customization', |
---|
58 | ); |
---|
59 | |
---|
60 | $history_checkboxes = array( |
---|
61 | 'log', |
---|
62 | 'history_admin', |
---|
63 | 'history_guest' |
---|
64 | ); |
---|
65 | |
---|
66 | $comments_checkboxes = array( |
---|
67 | 'comments_forall', |
---|
68 | 'comments_validation', |
---|
69 | 'email_admin_on_comment', |
---|
70 | 'email_admin_on_comment_validation', |
---|
71 | 'user_can_delete_comment', |
---|
72 | 'user_can_edit_comment', |
---|
73 | 'email_admin_on_comment_edition', |
---|
74 | 'email_admin_on_comment_deletion' |
---|
75 | ); |
---|
76 | |
---|
77 | $display_checkboxes = array( |
---|
78 | 'menubar_filter_icon', |
---|
79 | 'index_sort_order_input', |
---|
80 | 'index_flat_icon', |
---|
81 | 'index_posted_date_icon', |
---|
82 | 'index_created_date_icon', |
---|
83 | 'index_slideshow_icon', |
---|
84 | 'index_new_icon', |
---|
85 | 'picture_metadata_icon', |
---|
86 | 'picture_slideshow_icon', |
---|
87 | 'picture_favorite_icon', |
---|
88 | 'picture_download_icon', |
---|
89 | 'picture_navigation_icons', |
---|
90 | 'picture_navigation_thumb', |
---|
91 | 'picture_menu', |
---|
92 | ); |
---|
93 | |
---|
94 | $display_info_checkboxes = array( |
---|
95 | 'author', |
---|
96 | 'created_on', |
---|
97 | 'posted_on', |
---|
98 | 'dimensions', |
---|
99 | 'file', |
---|
100 | 'filesize', |
---|
101 | 'tags', |
---|
102 | 'categories', |
---|
103 | 'visits', |
---|
104 | 'rating_score', |
---|
105 | 'privacy_level', |
---|
106 | ); |
---|
107 | |
---|
108 | // image order management |
---|
109 | $sort_fields = array( |
---|
110 | '' => '', |
---|
111 | 'rank' => l10n('Rank'), |
---|
112 | 'file' => l10n('File 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 | if (empty($_POST['gallery_locked']) and $conf['gallery_locked']) |
---|
172 | { |
---|
173 | $tpl_var = & $template->get_template_vars('header_msgs'); |
---|
174 | $msg_key = array_search(l10n('The gallery is locked for maintenance. Please, come back later.'), $tpl_var); |
---|
175 | unset($tpl_var[$msg_key]); |
---|
176 | } |
---|
177 | elseif (!empty($_POST['gallery_locked']) and !$conf['gallery_locked']) |
---|
178 | { |
---|
179 | $template->append('header_msgs', l10n('The gallery is locked for maintenance. Please, come back later.')); |
---|
180 | } |
---|
181 | foreach( $main_checkboxes as $checkbox) |
---|
182 | { |
---|
183 | $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true'; |
---|
184 | } |
---|
185 | break; |
---|
186 | } |
---|
187 | case 'history' : |
---|
188 | { |
---|
189 | foreach( $history_checkboxes as $checkbox) |
---|
190 | { |
---|
191 | $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true'; |
---|
192 | } |
---|
193 | break; |
---|
194 | } |
---|
195 | case 'comments' : |
---|
196 | { |
---|
197 | // the number of comments per page must be an integer between 5 and 50 |
---|
198 | // included |
---|
199 | if (!preg_match($int_pattern, $_POST['nb_comment_page']) |
---|
200 | or $_POST['nb_comment_page'] < 5 |
---|
201 | or $_POST['nb_comment_page'] > 50) |
---|
202 | { |
---|
203 | array_push($page['errors'], l10n('The number of comments a page must be between 5 and 50 included.')); |
---|
204 | } |
---|
205 | foreach( $comments_checkboxes as $checkbox) |
---|
206 | { |
---|
207 | $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true'; |
---|
208 | } |
---|
209 | break; |
---|
210 | } |
---|
211 | case 'default' : |
---|
212 | { |
---|
213 | // Never go here |
---|
214 | break; |
---|
215 | } |
---|
216 | case 'display' : |
---|
217 | { |
---|
218 | foreach( $display_checkboxes as $checkbox) |
---|
219 | { |
---|
220 | $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true'; |
---|
221 | } |
---|
222 | foreach( $display_info_checkboxes as $checkbox) |
---|
223 | { |
---|
224 | $_POST['picture_informations'][$checkbox] = |
---|
225 | empty($_POST['picture_informations'][$checkbox])? false : true; |
---|
226 | } |
---|
227 | $_POST['picture_informations'] = addslashes(serialize($_POST['picture_informations'])); |
---|
228 | break; |
---|
229 | } |
---|
230 | } |
---|
231 | |
---|
232 | // updating configuration if no error found |
---|
233 | if (count($page['errors']) == 0) |
---|
234 | { |
---|
235 | //echo '<pre>'; print_r($_POST); echo '</pre>'; |
---|
236 | $result = pwg_query('SELECT param FROM '.CONFIG_TABLE); |
---|
237 | while ($row = pwg_db_fetch_assoc($result)) |
---|
238 | { |
---|
239 | if (isset($_POST[$row['param']])) |
---|
240 | { |
---|
241 | $value = $_POST[$row['param']]; |
---|
242 | |
---|
243 | if ('gallery_title' == $row['param']) |
---|
244 | { |
---|
245 | if (!$conf['allow_html_descriptions']) |
---|
246 | { |
---|
247 | $value = strip_tags($value); |
---|
248 | } |
---|
249 | } |
---|
250 | |
---|
251 | $query = ' |
---|
252 | UPDATE '.CONFIG_TABLE.' |
---|
253 | SET value = \''. str_replace("\'", "''", $value).'\' |
---|
254 | WHERE param = \''.$row['param'].'\' |
---|
255 | ;'; |
---|
256 | pwg_query($query); |
---|
257 | } |
---|
258 | } |
---|
259 | array_push($page['infos'], l10n('Information data registered in database')); |
---|
260 | } |
---|
261 | |
---|
262 | //------------------------------------------------------ $conf reinitialization |
---|
263 | load_conf_from_db(); |
---|
264 | } |
---|
265 | |
---|
266 | //----------------------------------------------------- template initialization |
---|
267 | $template->set_filename('config', 'configuration.tpl'); |
---|
268 | |
---|
269 | // TabSheet |
---|
270 | $tabsheet = new tabsheet(); |
---|
271 | // TabSheet initialization |
---|
272 | $tabsheet->add('main', l10n('Main'), $conf_link.'main'); |
---|
273 | $tabsheet->add('display', l10n('Display'), $conf_link.'display'); |
---|
274 | $tabsheet->add('history', l10n('History'), $conf_link.'history'); |
---|
275 | $tabsheet->add('comments', l10n('Comments'), $conf_link.'comments'); |
---|
276 | $tabsheet->add('default', l10n('Guest Settings'), $conf_link.'default'); |
---|
277 | // TabSheet selection |
---|
278 | $tabsheet->select($page['section']); |
---|
279 | // Assign tabsheet to template |
---|
280 | $tabsheet->assign(); |
---|
281 | |
---|
282 | $action = get_root_url().'admin.php?page=configuration'; |
---|
283 | $action.= '&section='.$page['section']; |
---|
284 | |
---|
285 | $template->assign( |
---|
286 | array( |
---|
287 | 'U_HELP' => get_root_url().'admin/popuphelp.php?page=configuration', |
---|
288 | 'F_ACTION'=>$action |
---|
289 | )); |
---|
290 | |
---|
291 | switch ($page['section']) |
---|
292 | { |
---|
293 | case 'main' : |
---|
294 | { |
---|
295 | |
---|
296 | function order_by_is_local() |
---|
297 | { |
---|
298 | @include(PHPWG_ROOT_PATH. 'local/config/config.inc.php'); |
---|
299 | if (isset($conf['local_dir_site'])) |
---|
300 | { |
---|
301 | @include(PHPWG_ROOT_PATH.PWG_LOCAL_DIR. 'config/config.inc.php'); |
---|
302 | } |
---|
303 | |
---|
304 | return isset($conf['order_by']) or isset($conf['order_by_inside_category']); |
---|
305 | } |
---|
306 | |
---|
307 | if (order_by_is_local()) |
---|
308 | { |
---|
309 | 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> !')); |
---|
310 | } |
---|
311 | |
---|
312 | if ( isset($conf['order_by_custom']) or isset($conf['order_by_inside_category_custom']) ) |
---|
313 | { |
---|
314 | $order_by = array(array( |
---|
315 | 'FIELD' => '', |
---|
316 | 'DIRECTION' => 'ASC', |
---|
317 | )); |
---|
318 | |
---|
319 | $template->assign('ORDER_BY_IS_CUSTOM', true); |
---|
320 | } |
---|
321 | else |
---|
322 | { |
---|
323 | $out = array(); |
---|
324 | $order_by = trim($conf['order_by_inside_category']); |
---|
325 | $order_by = str_replace('ORDER BY ', null, $order_by); |
---|
326 | $order_by = explode(', ', $order_by); |
---|
327 | foreach ($order_by as $field) |
---|
328 | { |
---|
329 | $field= explode(' ', $field); |
---|
330 | $out[] = array( |
---|
331 | 'FIELD' => $field[0], |
---|
332 | 'DIRECTION' => $field[1], |
---|
333 | ); |
---|
334 | } |
---|
335 | $order_by = $out; |
---|
336 | } |
---|
337 | |
---|
338 | $template->assign( |
---|
339 | 'main', |
---|
340 | array( |
---|
341 | 'CONF_GALLERY_TITLE' => htmlspecialchars($conf['gallery_title']), |
---|
342 | 'CONF_PAGE_BANNER' => htmlspecialchars($conf['page_banner']), |
---|
343 | 'week_starts_on_options' => array( |
---|
344 | 'sunday' => $lang['day'][0], |
---|
345 | 'monday' => $lang['day'][1], |
---|
346 | ), |
---|
347 | 'week_starts_on_options_selected' => $conf['week_starts_on'], |
---|
348 | 'order_by' => $order_by, |
---|
349 | 'order_field_options' => $sort_fields, |
---|
350 | 'order_direction_options' => $sort_directions, |
---|
351 | ) |
---|
352 | ); |
---|
353 | |
---|
354 | foreach ($main_checkboxes as $checkbox) |
---|
355 | { |
---|
356 | $template->append( |
---|
357 | 'main', |
---|
358 | array( |
---|
359 | $checkbox => $conf[$checkbox] |
---|
360 | ), |
---|
361 | true |
---|
362 | ); |
---|
363 | } |
---|
364 | break; |
---|
365 | } |
---|
366 | case 'history' : |
---|
367 | { |
---|
368 | //Necessary for merge_block_vars |
---|
369 | foreach ($history_checkboxes as $checkbox) |
---|
370 | { |
---|
371 | $template->append( |
---|
372 | 'history', |
---|
373 | array( |
---|
374 | $checkbox => $conf[$checkbox] |
---|
375 | ), |
---|
376 | true |
---|
377 | ); |
---|
378 | } |
---|
379 | break; |
---|
380 | } |
---|
381 | case 'comments' : |
---|
382 | { |
---|
383 | $template->assign( |
---|
384 | 'comments', |
---|
385 | array( |
---|
386 | 'NB_COMMENTS_PAGE'=>$conf['nb_comment_page'], |
---|
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 | } |
---|
445 | |
---|
446 | //----------------------------------------------------------- sending html code |
---|
447 | $template->assign_var_from_handle('ADMIN_CONTENT', 'config'); |
---|
448 | ?> |
---|