1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | configuration.php | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | application : PhpWebGallery <http://phpwebgallery.net> | |
---|
6 | // | branch : BSF (Best So Far) | |
---|
7 | // +-----------------------------------------------------------------------+ |
---|
8 | // | file : $RCSfile$ |
---|
9 | // | last update : $Date: 2004-09-05 15:49:54 +0000 (Sun, 05 Sep 2004) $ |
---|
10 | // | last modifier : $Author: z0rglub $ |
---|
11 | // | revision : $Revision: 516 $ |
---|
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 | include_once(PHPWG_ROOT_PATH.'admin/include/isadmin.inc.php'); |
---|
33 | //-------------------------------------------------------- sections definitions |
---|
34 | if (!isset($_GET['section'])) |
---|
35 | { |
---|
36 | $page['section'] = 'general'; |
---|
37 | } |
---|
38 | else |
---|
39 | { |
---|
40 | $page['section'] = $_GET['section']; |
---|
41 | } |
---|
42 | |
---|
43 | // templates for fields definitions |
---|
44 | $true_false = array('type' => 'radio', |
---|
45 | 'options' => array('true' => $lang['yes'], |
---|
46 | 'false' => $lang['no'])); |
---|
47 | $textfield = array('type' => 'textfield'); |
---|
48 | |
---|
49 | $sections = array( |
---|
50 | 'general' => array( |
---|
51 | 'mail_webmaster' => $textfield, |
---|
52 | 'prefix_thumbnail' => $textfield, |
---|
53 | 'access' => array('type' => 'radio', |
---|
54 | 'options' => array( |
---|
55 | 'free' => $lang['conf_general_access_1'], |
---|
56 | 'restricted' => $lang['conf_general_access_2'])), |
---|
57 | 'log' => $true_false, |
---|
58 | 'mail_notification' => $true_false, |
---|
59 | ), |
---|
60 | 'comments' => array( |
---|
61 | 'show_comments' => $true_false, |
---|
62 | 'comments_forall' => $true_false, |
---|
63 | 'nb_comment_page' => $textfield, |
---|
64 | 'comments_validation' => $true_false |
---|
65 | ), |
---|
66 | 'default' => array( |
---|
67 | 'default_language' => array('type' => 'select', |
---|
68 | 'options' => get_languages()), |
---|
69 | 'nb_image_line' => $textfield, |
---|
70 | 'nb_line_page' => $textfield, |
---|
71 | 'default_template' => array('type' => 'select', |
---|
72 | 'options' => get_templates()), |
---|
73 | 'recent_period' => $textfield, |
---|
74 | 'auto_expand' => $true_false, |
---|
75 | 'show_nb_comments' => $true_false |
---|
76 | ), |
---|
77 | 'upload' => array( |
---|
78 | 'upload_available' => $true_false, |
---|
79 | 'upload_maxfilesize' => $textfield, |
---|
80 | 'upload_maxwidth' => $textfield, |
---|
81 | 'upload_maxheight' => $textfield, |
---|
82 | 'upload_maxwidth_thumbnail' => $textfield, |
---|
83 | 'upload_maxheight_thumbnail' => $textfield |
---|
84 | ), |
---|
85 | 'session' => array( |
---|
86 | 'authorize_cookies' => $true_false, |
---|
87 | 'session_time' => $textfield, |
---|
88 | 'session_id_size' => $textfield |
---|
89 | ), |
---|
90 | 'metadata' => array( |
---|
91 | 'use_exif' => $true_false, |
---|
92 | 'use_iptc' => $true_false, |
---|
93 | 'show_exif' => $true_false, |
---|
94 | 'show_iptc' => $true_false |
---|
95 | ) |
---|
96 | ); |
---|
97 | //------------------------------------------------------ $conf reinitialization |
---|
98 | $result = mysql_query('SELECT param,value FROM '.CONFIG_TABLE); |
---|
99 | while ($row = mysql_fetch_array($result)) |
---|
100 | { |
---|
101 | $conf[$row['param']] = $row['value']; |
---|
102 | // if the parameter is present in $_POST array (if a form is submited), we |
---|
103 | // override it with the submited value |
---|
104 | if (isset($_POST[$row['param']])) |
---|
105 | { |
---|
106 | $conf[$row['param']] = $_POST[$row['param']]; |
---|
107 | } |
---|
108 | } |
---|
109 | //------------------------------ verification and registration of modifications |
---|
110 | $errors = array(); |
---|
111 | if (isset($_POST['submit'])) |
---|
112 | { |
---|
113 | // echo '<pre>'; |
---|
114 | // print_r($_POST); |
---|
115 | // echo '</pre>'; |
---|
116 | |
---|
117 | $int_pattern = '/^\d+$/'; |
---|
118 | switch ($page['section']) |
---|
119 | { |
---|
120 | case 'general' : |
---|
121 | { |
---|
122 | // thumbnail prefix must only contain simple ASCII characters |
---|
123 | if (!preg_match('/^[\w-]*$/', $_POST['prefix_thumbnail'])) |
---|
124 | { |
---|
125 | array_push($errors, $lang['conf_general_prefix_thumbnail_error']); |
---|
126 | } |
---|
127 | // mail must be formatted as follows : name@server.com |
---|
128 | $pattern = '/^[\w-]+(\.[\w-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)+$/'; |
---|
129 | if (!preg_match($pattern, $_POST['mail_webmaster'])) |
---|
130 | { |
---|
131 | array_push($errors, $lang['conf_general_mail_webmaster_error']); |
---|
132 | } |
---|
133 | break; |
---|
134 | } |
---|
135 | case 'comments' : |
---|
136 | { |
---|
137 | // the number of comments per page must be an integer between 5 and 50 |
---|
138 | // included |
---|
139 | if (!preg_match($int_pattern, $_POST['nb_comment_page']) |
---|
140 | or $_POST['nb_comment_page'] < 5 |
---|
141 | or $_POST['nb_comment_page'] > 50) |
---|
142 | { |
---|
143 | array_push($errors, $lang['conf_comments_nb_comment_page_error']); |
---|
144 | } |
---|
145 | break; |
---|
146 | } |
---|
147 | case 'default' : |
---|
148 | { |
---|
149 | // periods must be integer values, they represents number of days |
---|
150 | if (!preg_match($int_pattern, $_POST['recent_period']) |
---|
151 | or $_POST['recent_period'] <= 0) |
---|
152 | { |
---|
153 | array_push($errors, $lang['conf_default_recent_period_error']); |
---|
154 | } |
---|
155 | break; |
---|
156 | } |
---|
157 | case 'upload' : |
---|
158 | { |
---|
159 | // the maximum upload filesize must be an integer between 10 and 1000 |
---|
160 | if (!preg_match($int_pattern, $_POST['upload_maxfilesize']) |
---|
161 | or $_POST['upload_maxfilesize'] < 10 |
---|
162 | or $_POST['upload_maxfilesize'] > 1000) |
---|
163 | { |
---|
164 | array_push($errors, $lang['conf_upload_upload_maxfilesize_error']); |
---|
165 | } |
---|
166 | |
---|
167 | foreach (array('upload_maxwidth', |
---|
168 | 'upload_maxheight', |
---|
169 | 'upload_maxwidth_thumbnail', |
---|
170 | 'upload_maxheight_thumbnail') |
---|
171 | as $field) |
---|
172 | { |
---|
173 | if (!preg_match($int_pattern, $_POST[$field]) |
---|
174 | or $_POST[$field] < 10) |
---|
175 | { |
---|
176 | array_push($errors, $lang['conf_upload_'.$field.'_error']); |
---|
177 | } |
---|
178 | } |
---|
179 | break; |
---|
180 | } |
---|
181 | case 'session' : |
---|
182 | { |
---|
183 | // session_id size must be an integer between 4 and 50 |
---|
184 | if (!preg_match($int_pattern, $_POST['session_id_size']) |
---|
185 | or $_POST['session_id_size'] < 4 |
---|
186 | or $_POST['session_id_size'] > 50) |
---|
187 | { |
---|
188 | array_push($errors, $lang['conf_session_session_id_size_error']); |
---|
189 | } |
---|
190 | // session_time must be an integer between 5 and 60, in minutes |
---|
191 | if (!preg_match($int_pattern, $_POST['session_time']) |
---|
192 | or $_POST['session_time'] < 5 |
---|
193 | or $_POST['session_time'] > 60) |
---|
194 | { |
---|
195 | array_push($errors, $lang['conf_session_session_time_error']); |
---|
196 | } |
---|
197 | break; |
---|
198 | } |
---|
199 | } |
---|
200 | |
---|
201 | // updating configuraiton if no error found |
---|
202 | if (count($errors) == 0) |
---|
203 | { |
---|
204 | $result = mysql_query('SELECT * FROM '.CONFIG_TABLE); |
---|
205 | while ($row = mysql_fetch_array($result)) |
---|
206 | { |
---|
207 | if (isset($_POST[$row['param']])) |
---|
208 | { |
---|
209 | $query = ' |
---|
210 | UPDATE '.CONFIG_TABLE.' |
---|
211 | SET value = \''. str_replace("\'", "''", $_POST[$row['param']]).'\' |
---|
212 | WHERE param = \''.$row['param'].'\' |
---|
213 | ;'; |
---|
214 | mysql_query($query); |
---|
215 | } |
---|
216 | } |
---|
217 | } |
---|
218 | } |
---|
219 | //----------------------------------------------------- template initialization |
---|
220 | $template->set_filenames(array('config'=>'admin/configuration.tpl')); |
---|
221 | |
---|
222 | $action = PHPWG_ROOT_PATH.'admin.php?page=configuration'; |
---|
223 | $action.= '&section='.$page['section']; |
---|
224 | |
---|
225 | $template->assign_vars( |
---|
226 | array( |
---|
227 | 'L_CONFIRM'=>$lang['conf_confirmation'], |
---|
228 | 'L_SUBMIT'=>$lang['submit'], |
---|
229 | 'F_ACTION'=>add_session_id($action) |
---|
230 | ) |
---|
231 | ); |
---|
232 | |
---|
233 | $base_url = PHPWG_ROOT_PATH.'admin.php?page=configuration&section='; |
---|
234 | foreach (array_keys($sections) as $section) |
---|
235 | { |
---|
236 | if ($section == $page['section']) |
---|
237 | { |
---|
238 | $class = 'opened'; |
---|
239 | } |
---|
240 | else |
---|
241 | { |
---|
242 | $class = ''; |
---|
243 | } |
---|
244 | |
---|
245 | $template->assign_block_vars( |
---|
246 | 'confmenu_item', |
---|
247 | array( |
---|
248 | 'CLASS' => $class, |
---|
249 | 'URL' => add_session_id($base_url.$section), |
---|
250 | 'NAME' => $lang['conf_'.$section.'_title'] |
---|
251 | )); |
---|
252 | } |
---|
253 | |
---|
254 | $fields = $sections[$page['section']]; |
---|
255 | foreach ($fields as $field_name => $field) |
---|
256 | { |
---|
257 | $template->assign_block_vars( |
---|
258 | 'line', |
---|
259 | array( |
---|
260 | 'NAME' => $lang['conf_'.$page['section'].'_'.$field_name], |
---|
261 | 'INFO' => $lang['conf_'.$page['section'].'_'.$field_name.'_info'] |
---|
262 | )); |
---|
263 | if ($field['type'] == 'textfield') |
---|
264 | { |
---|
265 | $template->assign_block_vars( |
---|
266 | 'line.textfield', |
---|
267 | array( |
---|
268 | 'NAME' => $field_name, |
---|
269 | 'VALUE' => $conf[$field_name] |
---|
270 | )); |
---|
271 | } |
---|
272 | else if ($field['type'] == 'radio') |
---|
273 | { |
---|
274 | foreach ($field['options'] as $option_value => $option) |
---|
275 | { |
---|
276 | if ($conf[$field_name] == $option_value) |
---|
277 | { |
---|
278 | $checked = 'checked="checked"'; |
---|
279 | } |
---|
280 | else |
---|
281 | { |
---|
282 | $checked = ''; |
---|
283 | } |
---|
284 | |
---|
285 | $template->assign_block_vars( |
---|
286 | 'line.radio', |
---|
287 | array( |
---|
288 | 'NAME' => $field_name, |
---|
289 | 'VALUE' => $option_value, |
---|
290 | 'CHECKED' => $checked, |
---|
291 | 'OPTION' => $option |
---|
292 | )); |
---|
293 | } |
---|
294 | } |
---|
295 | else if ($field['type'] == 'select') |
---|
296 | { |
---|
297 | $template->assign_block_vars( |
---|
298 | 'line.select', |
---|
299 | array( |
---|
300 | 'NAME' => $field_name |
---|
301 | )); |
---|
302 | foreach ($field['options'] as $option_value => $option) |
---|
303 | { |
---|
304 | if ($conf[$field_name] == $option_value) |
---|
305 | { |
---|
306 | $selected = 'selected="selected"'; |
---|
307 | } |
---|
308 | else |
---|
309 | { |
---|
310 | $selected = ''; |
---|
311 | } |
---|
312 | |
---|
313 | $template->assign_block_vars( |
---|
314 | 'line.select.select_option', |
---|
315 | array( |
---|
316 | 'VALUE' => $option_value, |
---|
317 | 'SELECTED' => $selected, |
---|
318 | 'OPTION' => $option |
---|
319 | )); |
---|
320 | } |
---|
321 | } |
---|
322 | } |
---|
323 | //-------------------------------------------------------------- errors display |
---|
324 | if (count($errors) != 0) |
---|
325 | { |
---|
326 | $template->assign_block_vars('errors',array()); |
---|
327 | foreach ($errors as $error) |
---|
328 | { |
---|
329 | $template->assign_block_vars('errors.error',array('ERROR'=>$error)); |
---|
330 | } |
---|
331 | } |
---|
332 | else if (isset($_POST['submit'])) |
---|
333 | { |
---|
334 | $template->assign_block_vars('confirmation' ,array()); |
---|
335 | } |
---|
336 | //----------------------------------------------------------- sending html code |
---|
337 | $template->assign_var_from_handle('ADMIN_CONTENT', 'config'); |
---|
338 | ?> |
---|