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-2007 PhpWebGallery Team - http://phpwebgallery.net | |
---|
6 | // +-----------------------------------------------------------------------+ |
---|
7 | // | branch : BSF (Best So Far) |
---|
8 | // | file : $RCSfile$ |
---|
9 | // | last update : $Date: 2007-03-12 23:10:35 +0000 (Mon, 12 Mar 2007) $ |
---|
10 | // | last modifier : $Author: rub $ |
---|
11 | // | revision : $Revision: 1901 $ |
---|
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 | include_once(PHPWG_ROOT_PATH.'admin/include/functions_tabsheet.inc.php'); |
---|
35 | |
---|
36 | // +-----------------------------------------------------------------------+ |
---|
37 | // | Check Access and exit when user status is not ok | |
---|
38 | // +-----------------------------------------------------------------------+ |
---|
39 | check_status(ACCESS_ADMINISTRATOR); |
---|
40 | |
---|
41 | //-------------------------------------------------------- sections definitions |
---|
42 | if (!isset($_GET['section'])) |
---|
43 | { |
---|
44 | $page['section'] = 'main'; |
---|
45 | } |
---|
46 | else |
---|
47 | { |
---|
48 | $page['section'] = $_GET['section']; |
---|
49 | } |
---|
50 | |
---|
51 | $main_checkboxes = array( |
---|
52 | 'email_admin_on_new_user', |
---|
53 | 'allow_user_registration', |
---|
54 | 'email_admin_on_picture_uploaded', |
---|
55 | ); |
---|
56 | |
---|
57 | $history_checkboxes = array( |
---|
58 | 'log', |
---|
59 | 'history_admin', |
---|
60 | 'history_guest' |
---|
61 | ); |
---|
62 | |
---|
63 | $comments_checkboxes = array( |
---|
64 | 'comments_forall', |
---|
65 | 'comments_validation', |
---|
66 | 'email_admin_on_comment', |
---|
67 | 'email_admin_on_comment_validation', |
---|
68 | ); |
---|
69 | |
---|
70 | //------------------------------ verification and registration of modifications |
---|
71 | if (isset($_POST['submit']) and !is_adviser()) |
---|
72 | { |
---|
73 | $int_pattern = '/^\d+$/'; |
---|
74 | switch ($page['section']) |
---|
75 | { |
---|
76 | case 'main' : |
---|
77 | { |
---|
78 | if ( !url_is_remote($_POST['gallery_url']) ) |
---|
79 | { |
---|
80 | array_push($page['errors'], $lang['conf_gallery_url_error']); |
---|
81 | } |
---|
82 | foreach( $main_checkboxes as $checkbox) |
---|
83 | { |
---|
84 | $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true'; |
---|
85 | } |
---|
86 | break; |
---|
87 | } |
---|
88 | case 'history' : |
---|
89 | { |
---|
90 | foreach( $history_checkboxes as $checkbox) |
---|
91 | { |
---|
92 | $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true'; |
---|
93 | } |
---|
94 | break; |
---|
95 | } |
---|
96 | case 'comments' : |
---|
97 | { |
---|
98 | // the number of comments per page must be an integer between 5 and 50 |
---|
99 | // included |
---|
100 | if (!preg_match($int_pattern, $_POST['nb_comment_page']) |
---|
101 | or $_POST['nb_comment_page'] < 5 |
---|
102 | or $_POST['nb_comment_page'] > 50) |
---|
103 | { |
---|
104 | array_push($page['errors'], $lang['conf_nb_comment_page_error']); |
---|
105 | } |
---|
106 | foreach( $comments_checkboxes as $checkbox) |
---|
107 | { |
---|
108 | $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true'; |
---|
109 | } |
---|
110 | break; |
---|
111 | } |
---|
112 | case 'default' : |
---|
113 | { |
---|
114 | // periods must be integer values, they represents number of days |
---|
115 | if (!preg_match($int_pattern, $_POST['recent_period']) |
---|
116 | or $_POST['recent_period'] <= 0) |
---|
117 | { |
---|
118 | array_push($page['errors'], $lang['periods_error']); |
---|
119 | } |
---|
120 | // maxwidth |
---|
121 | if (isset($_POST['default_maxwidth']) |
---|
122 | and !empty($_POST['default_maxwidth']) |
---|
123 | and (!preg_match($int_pattern, $_POST['default_maxwidth']) |
---|
124 | or $_POST['default_maxwidth'] < 50)) |
---|
125 | { |
---|
126 | array_push($page['errors'], $lang['maxwidth_error']); |
---|
127 | } |
---|
128 | // maxheight |
---|
129 | if (isset($_POST['default_maxheight']) |
---|
130 | and !empty($_POST['default_maxheight']) |
---|
131 | and (!preg_match($int_pattern, $_POST['default_maxheight']) |
---|
132 | or $_POST['default_maxheight'] < 50)) |
---|
133 | { |
---|
134 | array_push($page['errors'], $lang['maxheight_error']); |
---|
135 | } |
---|
136 | break; |
---|
137 | } |
---|
138 | } |
---|
139 | |
---|
140 | // updating configuration if no error found |
---|
141 | if (count($page['errors']) == 0) |
---|
142 | { |
---|
143 | //echo '<pre>'; print_r($_POST); echo '</pre>'; |
---|
144 | $result = pwg_query('SELECT param FROM '.CONFIG_TABLE); |
---|
145 | while ($row = mysql_fetch_array($result)) |
---|
146 | { |
---|
147 | if (isset($_POST[$row['param']])) |
---|
148 | { |
---|
149 | $value = $_POST[$row['param']]; |
---|
150 | |
---|
151 | if ('gallery_title' == $row['param']) |
---|
152 | { |
---|
153 | if (!$conf['allow_html_descriptions']) |
---|
154 | { |
---|
155 | $value = strip_tags($value); |
---|
156 | } |
---|
157 | } |
---|
158 | |
---|
159 | $query = ' |
---|
160 | UPDATE '.CONFIG_TABLE.' |
---|
161 | SET value = \''. str_replace("\'", "''", $value).'\' |
---|
162 | WHERE param = \''.$row['param'].'\' |
---|
163 | ;'; |
---|
164 | pwg_query($query); |
---|
165 | } |
---|
166 | } |
---|
167 | array_push($page['infos'], $lang['conf_confirmation']); |
---|
168 | } |
---|
169 | |
---|
170 | //------------------------------------------------------ $conf reinitialization |
---|
171 | load_conf_from_db(); |
---|
172 | } |
---|
173 | |
---|
174 | //----------------------------------------------------- template initialization |
---|
175 | $template->set_filename('config', 'admin/configuration.tpl'); |
---|
176 | |
---|
177 | // TabSheet initialization |
---|
178 | $page['tabsheet'] = array |
---|
179 | ( |
---|
180 | 'main' => array |
---|
181 | ( |
---|
182 | 'caption' => l10n('conf_main_title'), |
---|
183 | 'url' => $conf_link.'main' |
---|
184 | ), |
---|
185 | 'history' => array |
---|
186 | ( |
---|
187 | 'caption' => l10n('conf_history_title'), |
---|
188 | 'url' => $conf_link.'history' |
---|
189 | ), |
---|
190 | 'comments' => array |
---|
191 | ( |
---|
192 | 'caption' => l10n('conf_comments_title'), |
---|
193 | 'url' => $conf_link.'comments' |
---|
194 | ), |
---|
195 | 'default' => array |
---|
196 | ( |
---|
197 | 'caption' => l10n('conf_display'), |
---|
198 | 'url' => $conf_link.'default' |
---|
199 | ) |
---|
200 | ); |
---|
201 | |
---|
202 | $page['tabsheet'][$page['section']]['selected'] = true; |
---|
203 | |
---|
204 | // Assign tabsheet to template |
---|
205 | template_assign_tabsheet(); |
---|
206 | |
---|
207 | $action = PHPWG_ROOT_PATH.'admin.php?page=configuration'; |
---|
208 | $action.= '&section='.$page['section']; |
---|
209 | |
---|
210 | $template->assign_vars( |
---|
211 | array( |
---|
212 | 'L_YES'=>$lang['yes'], |
---|
213 | 'L_NO'=>$lang['no'], |
---|
214 | 'L_SUBMIT'=>$lang['submit'], |
---|
215 | 'L_RESET'=>$lang['reset'], |
---|
216 | |
---|
217 | 'U_HELP' => PHPWG_ROOT_PATH.'popuphelp.php?page=configuration', |
---|
218 | |
---|
219 | 'F_ACTION'=>$action |
---|
220 | )); |
---|
221 | |
---|
222 | $html_check='checked="checked"'; |
---|
223 | |
---|
224 | switch ($page['section']) |
---|
225 | { |
---|
226 | case 'main' : |
---|
227 | { |
---|
228 | $lock_yes = ($conf['gallery_locked']==true)?'checked="checked"':''; |
---|
229 | $lock_no = ($conf['gallery_locked']==false)?'checked="checked"':''; |
---|
230 | |
---|
231 | $template->assign_block_vars( |
---|
232 | 'main', |
---|
233 | array( |
---|
234 | 'GALLERY_LOCKED_YES'=>$lock_yes, |
---|
235 | 'GALLERY_LOCKED_NO'=>$lock_no, |
---|
236 | ($conf['rate']==true?'RATE_YES':'RATE_NO')=>$html_check, |
---|
237 | ($conf['rate_anonymous']==true |
---|
238 | ? 'RATE_ANONYMOUS_YES' : 'RATE_ANONYMOUS_NO')=>$html_check, |
---|
239 | 'CONF_GALLERY_TITLE' => $conf['gallery_title'], |
---|
240 | 'CONF_PAGE_BANNER' => $conf['page_banner'], |
---|
241 | 'CONF_GALLERY_URL' => $conf['gallery_url'], |
---|
242 | )); |
---|
243 | |
---|
244 | foreach( $main_checkboxes as $checkbox) |
---|
245 | { |
---|
246 | $template->merge_block_vars( |
---|
247 | 'main', |
---|
248 | array( |
---|
249 | strtoupper($checkbox) => ($conf[$checkbox]==true)?$html_check:'' |
---|
250 | ) |
---|
251 | ); |
---|
252 | } |
---|
253 | break; |
---|
254 | } |
---|
255 | case 'history' : |
---|
256 | { |
---|
257 | //Necessary for merge_block_vars |
---|
258 | $template->assign_block_vars('history', array()); |
---|
259 | |
---|
260 | foreach( $history_checkboxes as $checkbox) |
---|
261 | { |
---|
262 | $template->merge_block_vars( |
---|
263 | 'history', |
---|
264 | array( |
---|
265 | strtoupper($checkbox) => ($conf[$checkbox]==true)?$html_check:'' |
---|
266 | ) |
---|
267 | ); |
---|
268 | } |
---|
269 | break; |
---|
270 | } |
---|
271 | case 'comments' : |
---|
272 | { |
---|
273 | $template->assign_block_vars( |
---|
274 | 'comments', |
---|
275 | array( |
---|
276 | 'NB_COMMENTS_PAGE'=>$conf['nb_comment_page'], |
---|
277 | )); |
---|
278 | |
---|
279 | foreach( $comments_checkboxes as $checkbox) |
---|
280 | { |
---|
281 | $template->merge_block_vars( |
---|
282 | 'comments', |
---|
283 | array( |
---|
284 | strtoupper($checkbox) => ($conf[$checkbox]==true)?$html_check:'' |
---|
285 | ) |
---|
286 | ); |
---|
287 | } |
---|
288 | break; |
---|
289 | } |
---|
290 | case 'default' : |
---|
291 | { |
---|
292 | $show_yes = ($conf['show_nb_comments']==true)?'checked="checked"':''; |
---|
293 | $show_no = ($conf['show_nb_comments']==false)?'checked="checked"':''; |
---|
294 | $hits_yes = ($conf['show_nb_hits']==true)?'checked="checked"':''; |
---|
295 | $hits_no = ($conf['show_nb_hits']==false)?'checked="checked"':''; |
---|
296 | $expand_yes = ($conf['auto_expand']==true)?'checked="checked"':''; |
---|
297 | $expand_no = ($conf['auto_expand']==false)?'checked="checked"':''; |
---|
298 | |
---|
299 | $template->assign_block_vars( |
---|
300 | 'default', |
---|
301 | array( |
---|
302 | 'NB_IMAGE_LINE'=>$conf['nb_image_line'], |
---|
303 | 'NB_ROW_PAGE'=>$conf['nb_line_page'], |
---|
304 | 'CONF_RECENT'=>$conf['recent_period'], |
---|
305 | 'NB_COMMENTS_PAGE'=>$conf['nb_comment_page'], |
---|
306 | 'MAXWIDTH'=>$conf['default_maxwidth'], |
---|
307 | 'MAXHEIGHT'=>$conf['default_maxheight'], |
---|
308 | 'EXPAND_YES'=>$expand_yes, |
---|
309 | 'EXPAND_NO'=>$expand_no, |
---|
310 | 'SHOW_COMMENTS_YES'=>$show_yes, |
---|
311 | 'SHOW_COMMENTS_NO'=>$show_no, |
---|
312 | 'SHOW_HITS_YES'=>$hits_yes, |
---|
313 | 'SHOW_HITS_NO'=>$hits_no, |
---|
314 | )); |
---|
315 | |
---|
316 | $blockname = 'default.language_option'; |
---|
317 | |
---|
318 | foreach (get_languages() as $language_code => $language_name) |
---|
319 | { |
---|
320 | if (isset($_POST['submit'])) |
---|
321 | { |
---|
322 | $selected = |
---|
323 | $_POST['default_language'] == $language_code |
---|
324 | ? 'selected="selected"' : ''; |
---|
325 | } |
---|
326 | else if ($conf['default_language'] == $language_code) |
---|
327 | { |
---|
328 | $selected = 'selected="selected"'; |
---|
329 | } |
---|
330 | else |
---|
331 | { |
---|
332 | $selected = ''; |
---|
333 | } |
---|
334 | |
---|
335 | $template->assign_block_vars( |
---|
336 | $blockname, |
---|
337 | array( |
---|
338 | 'VALUE'=> $language_code, |
---|
339 | 'CONTENT' => $language_name, |
---|
340 | 'SELECTED' => $selected |
---|
341 | )); |
---|
342 | } |
---|
343 | |
---|
344 | $blockname = 'default.template_option'; |
---|
345 | |
---|
346 | foreach (get_pwg_themes() as $pwg_template) |
---|
347 | { |
---|
348 | if (isset($_POST['submit'])) |
---|
349 | { |
---|
350 | $selected = |
---|
351 | $_POST['default_template'] == $pwg_template |
---|
352 | ? 'selected="selected"' : ''; |
---|
353 | } |
---|
354 | else if ($conf['default_template'] == $pwg_template) |
---|
355 | { |
---|
356 | $selected = 'selected="selected"'; |
---|
357 | } |
---|
358 | else |
---|
359 | { |
---|
360 | $selected = ''; |
---|
361 | } |
---|
362 | |
---|
363 | $template->assign_block_vars( |
---|
364 | $blockname, |
---|
365 | array( |
---|
366 | 'VALUE'=> $pwg_template, |
---|
367 | 'CONTENT' => $pwg_template, |
---|
368 | 'SELECTED' => $selected |
---|
369 | ) |
---|
370 | ); |
---|
371 | } |
---|
372 | |
---|
373 | |
---|
374 | break; |
---|
375 | } |
---|
376 | } |
---|
377 | //----------------------------------------------------------- sending html code |
---|
378 | $template->assign_var_from_handle('ADMIN_CONTENT', 'config'); |
---|
379 | ?> |
---|