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-2008 PhpWebGallery Team - http://phpwebgallery.net | |
---|
6 | // +-----------------------------------------------------------------------+ |
---|
7 | // | file : $Id: configuration.php 2288 2008-03-21 01:01:25Z rvelices $ |
---|
8 | // | last update : $Date: 2008-03-21 01:01:25 +0000 (Fri, 21 Mar 2008) $ |
---|
9 | // | last modifier : $Author: rvelices $ |
---|
10 | // | revision : $Revision: 2288 $ |
---|
11 | // +-----------------------------------------------------------------------+ |
---|
12 | // | This program is free software; you can redistribute it and/or modify | |
---|
13 | // | it under the terms of the GNU General Public License as published by | |
---|
14 | // | the Free Software Foundation | |
---|
15 | // | | |
---|
16 | // | This program is distributed in the hope that it will be useful, but | |
---|
17 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
18 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
19 | // | General Public License for more details. | |
---|
20 | // | | |
---|
21 | // | You should have received a copy of the GNU General Public License | |
---|
22 | // | along with this program; if not, write to the Free Software | |
---|
23 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
24 | // | USA. | |
---|
25 | // +-----------------------------------------------------------------------+ |
---|
26 | |
---|
27 | if( !defined("PHPWG_ROOT_PATH") ) |
---|
28 | { |
---|
29 | die ("Hacking attempt!"); |
---|
30 | } |
---|
31 | |
---|
32 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
33 | include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php'); |
---|
34 | |
---|
35 | // +-----------------------------------------------------------------------+ |
---|
36 | // | Check Access and exit when user status is not ok | |
---|
37 | // +-----------------------------------------------------------------------+ |
---|
38 | check_status(ACCESS_ADMINISTRATOR); |
---|
39 | |
---|
40 | //-------------------------------------------------------- sections definitions |
---|
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 | 'email_admin_on_picture_uploaded', |
---|
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 | ); |
---|
72 | |
---|
73 | //------------------------------ verification and registration of modifications |
---|
74 | if (isset($_POST['submit']) and !is_adviser()) |
---|
75 | { |
---|
76 | $int_pattern = '/^\d+$/'; |
---|
77 | |
---|
78 | switch ($page['section']) |
---|
79 | { |
---|
80 | case 'main' : |
---|
81 | { |
---|
82 | if ( !url_is_remote($_POST['gallery_url']) ) |
---|
83 | { |
---|
84 | array_push($page['errors'], l10n('conf_gallery_url_error')); |
---|
85 | } |
---|
86 | foreach( $main_checkboxes as $checkbox) |
---|
87 | { |
---|
88 | $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true'; |
---|
89 | } |
---|
90 | break; |
---|
91 | } |
---|
92 | case 'history' : |
---|
93 | { |
---|
94 | foreach( $history_checkboxes as $checkbox) |
---|
95 | { |
---|
96 | $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true'; |
---|
97 | } |
---|
98 | break; |
---|
99 | } |
---|
100 | case 'comments' : |
---|
101 | { |
---|
102 | // the number of comments per page must be an integer between 5 and 50 |
---|
103 | // included |
---|
104 | if (!preg_match($int_pattern, $_POST['nb_comment_page']) |
---|
105 | or $_POST['nb_comment_page'] < 5 |
---|
106 | or $_POST['nb_comment_page'] > 50) |
---|
107 | { |
---|
108 | array_push($page['errors'], l10n('conf_nb_comment_page_error')); |
---|
109 | } |
---|
110 | foreach( $comments_checkboxes as $checkbox) |
---|
111 | { |
---|
112 | $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true'; |
---|
113 | } |
---|
114 | break; |
---|
115 | } |
---|
116 | case 'default' : |
---|
117 | { |
---|
118 | // Never go here |
---|
119 | break; |
---|
120 | } |
---|
121 | } |
---|
122 | |
---|
123 | // updating configuration if no error found |
---|
124 | if (count($page['errors']) == 0) |
---|
125 | { |
---|
126 | //echo '<pre>'; print_r($_POST); echo '</pre>'; |
---|
127 | $result = pwg_query('SELECT param FROM '.CONFIG_TABLE); |
---|
128 | while ($row = mysql_fetch_array($result)) |
---|
129 | { |
---|
130 | if (isset($_POST[$row['param']])) |
---|
131 | { |
---|
132 | $value = $_POST[$row['param']]; |
---|
133 | |
---|
134 | if ('gallery_title' == $row['param']) |
---|
135 | { |
---|
136 | if (!$conf['allow_html_descriptions']) |
---|
137 | { |
---|
138 | $value = strip_tags($value); |
---|
139 | } |
---|
140 | } |
---|
141 | |
---|
142 | $query = ' |
---|
143 | UPDATE '.CONFIG_TABLE.' |
---|
144 | SET value = \''. str_replace("\'", "''", $value).'\' |
---|
145 | WHERE param = \''.$row['param'].'\' |
---|
146 | ;'; |
---|
147 | pwg_query($query); |
---|
148 | } |
---|
149 | } |
---|
150 | array_push($page['infos'], l10n('conf_confirmation')); |
---|
151 | } |
---|
152 | |
---|
153 | //------------------------------------------------------ $conf reinitialization |
---|
154 | load_conf_from_db(); |
---|
155 | } |
---|
156 | |
---|
157 | //----------------------------------------------------- template initialization |
---|
158 | $template->set_filename('config', 'admin/configuration.tpl'); |
---|
159 | |
---|
160 | // TabSheet |
---|
161 | $tabsheet = new tabsheet(); |
---|
162 | // TabSheet initialization |
---|
163 | $tabsheet->add('main', l10n('conf_main_title'), $conf_link.'main'); |
---|
164 | $tabsheet->add('history', l10n('conf_history_title'), $conf_link.'history'); |
---|
165 | $tabsheet->add('comments', l10n('conf_comments_title'), $conf_link.'comments'); |
---|
166 | $tabsheet->add('default', l10n('conf_display'), $conf_link.'default'); |
---|
167 | // TabSheet selection |
---|
168 | $tabsheet->select($page['section']); |
---|
169 | // Assign tabsheet to template |
---|
170 | $tabsheet->assign(); |
---|
171 | |
---|
172 | $action = get_root_url().'admin.php?page=configuration'; |
---|
173 | $action.= '&section='.$page['section']; |
---|
174 | |
---|
175 | $template->assign( |
---|
176 | array( |
---|
177 | 'U_HELP' => get_root_url().'popuphelp.php?page=configuration', |
---|
178 | 'F_ACTION'=>$action |
---|
179 | )); |
---|
180 | |
---|
181 | switch ($page['section']) |
---|
182 | { |
---|
183 | case 'main' : |
---|
184 | { |
---|
185 | $template->assign( |
---|
186 | 'main', |
---|
187 | array( |
---|
188 | 'CONF_GALLERY_TITLE' => htmlspecialchars($conf['gallery_title']), |
---|
189 | 'CONF_PAGE_BANNER' => htmlspecialchars($conf['page_banner']), |
---|
190 | 'CONF_GALLERY_URL' => $conf['gallery_url'], |
---|
191 | )); |
---|
192 | |
---|
193 | foreach( $main_checkboxes as $checkbox) |
---|
194 | { |
---|
195 | $template->append( |
---|
196 | 'main', |
---|
197 | array( |
---|
198 | $checkbox => $conf[$checkbox] |
---|
199 | ), |
---|
200 | true |
---|
201 | ); |
---|
202 | } |
---|
203 | break; |
---|
204 | } |
---|
205 | case 'history' : |
---|
206 | { |
---|
207 | //Necessary for merge_block_vars |
---|
208 | foreach( $history_checkboxes as $checkbox) |
---|
209 | { |
---|
210 | $template->append( |
---|
211 | 'history', |
---|
212 | array( |
---|
213 | $checkbox => $conf[$checkbox] |
---|
214 | ), |
---|
215 | true |
---|
216 | ); |
---|
217 | } |
---|
218 | break; |
---|
219 | } |
---|
220 | case 'comments' : |
---|
221 | { |
---|
222 | $template->assign( |
---|
223 | 'comments', |
---|
224 | array( |
---|
225 | 'NB_COMMENTS_PAGE'=>$conf['nb_comment_page'], |
---|
226 | )); |
---|
227 | |
---|
228 | foreach( $comments_checkboxes as $checkbox) |
---|
229 | { |
---|
230 | $template->append( |
---|
231 | 'comments', |
---|
232 | array( |
---|
233 | $checkbox => $conf[$checkbox] |
---|
234 | ), |
---|
235 | true |
---|
236 | ); |
---|
237 | } |
---|
238 | break; |
---|
239 | } |
---|
240 | case 'default' : |
---|
241 | { |
---|
242 | $edit_user = build_user($conf['default_user_id'], false); |
---|
243 | include_once(PHPWG_ROOT_PATH.'profile.php'); |
---|
244 | |
---|
245 | $errors = array(); |
---|
246 | if ( !is_adviser() ) |
---|
247 | { |
---|
248 | if (save_profile_from_post($edit_user, $errors)) |
---|
249 | { |
---|
250 | // Reload user |
---|
251 | $edit_user = build_user($conf['default_user_id'], false); |
---|
252 | array_push($page['infos'], l10n('conf_confirmation')); |
---|
253 | } |
---|
254 | } |
---|
255 | $page['errors'] = array_merge($page['errors'], $errors); |
---|
256 | |
---|
257 | load_profile_in_template( |
---|
258 | $action, |
---|
259 | '', |
---|
260 | $edit_user |
---|
261 | ); |
---|
262 | $template->assign('default', array()); |
---|
263 | break; |
---|
264 | } |
---|
265 | } |
---|
266 | |
---|
267 | //----------------------------------------------------------- sending html code |
---|
268 | $template->assign_var_from_handle('ADMIN_CONTENT', 'config'); |
---|
269 | ?> |
---|