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 | if (!isset($_GET['section'])) |
---|
39 | { |
---|
40 | $page['section'] = 'main'; |
---|
41 | } |
---|
42 | else |
---|
43 | { |
---|
44 | $page['section'] = $_GET['section']; |
---|
45 | } |
---|
46 | |
---|
47 | $main_checkboxes = array( |
---|
48 | 'gallery_locked', |
---|
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 | ); |
---|
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 | 'user_can_delete_comment', |
---|
69 | 'user_can_edit_comment', |
---|
70 | 'email_admin_on_comment_edition', |
---|
71 | 'email_admin_on_comment_deletion' |
---|
72 | ); |
---|
73 | |
---|
74 | $display_checkboxes = array( |
---|
75 | 'menubar_filter_icon', |
---|
76 | 'index_sort_order_input', |
---|
77 | 'index_flat_icon', |
---|
78 | 'index_posted_date_icon', |
---|
79 | 'index_created_date_icon', |
---|
80 | 'index_slideshow_icon', |
---|
81 | 'picture_metadata_icon', |
---|
82 | 'picture_slideshow_icon', |
---|
83 | 'picture_favorite_icon', |
---|
84 | 'picture_download_icon', |
---|
85 | 'picture_navigation_icons', |
---|
86 | 'picture_navigation_thumb', |
---|
87 | ); |
---|
88 | |
---|
89 | $display_info_checkboxes = array( |
---|
90 | 'author', |
---|
91 | 'created_on', |
---|
92 | 'posted_on', |
---|
93 | 'dimensions', |
---|
94 | 'file', |
---|
95 | 'filesize', |
---|
96 | 'tags', |
---|
97 | 'categories', |
---|
98 | 'visits', |
---|
99 | 'average_rate', |
---|
100 | 'privacy_level', |
---|
101 | ); |
---|
102 | |
---|
103 | //------------------------------ verification and registration of modifications |
---|
104 | if (isset($_POST['submit'])) |
---|
105 | { |
---|
106 | $int_pattern = '/^\d+$/'; |
---|
107 | |
---|
108 | switch ($page['section']) |
---|
109 | { |
---|
110 | case 'main' : |
---|
111 | { |
---|
112 | if (empty($_POST['gallery_locked']) and $conf['gallery_locked']) |
---|
113 | { |
---|
114 | $tpl_var = & $template->get_template_vars('header_msgs'); |
---|
115 | $msg_key = array_search(l10n('The gallery is locked for maintenance. Please, come back later.'), $tpl_var); |
---|
116 | unset($tpl_var[$msg_key]); |
---|
117 | } |
---|
118 | elseif (!empty($_POST['gallery_locked']) and !$conf['gallery_locked']) |
---|
119 | { |
---|
120 | $template->append('header_msgs', l10n('The gallery is locked for maintenance. Please, come back later.')); |
---|
121 | } |
---|
122 | foreach( $main_checkboxes as $checkbox) |
---|
123 | { |
---|
124 | $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true'; |
---|
125 | } |
---|
126 | break; |
---|
127 | } |
---|
128 | case 'history' : |
---|
129 | { |
---|
130 | foreach( $history_checkboxes as $checkbox) |
---|
131 | { |
---|
132 | $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true'; |
---|
133 | } |
---|
134 | break; |
---|
135 | } |
---|
136 | case 'comments' : |
---|
137 | { |
---|
138 | // the number of comments per page must be an integer between 5 and 50 |
---|
139 | // included |
---|
140 | if (!preg_match($int_pattern, $_POST['nb_comment_page']) |
---|
141 | or $_POST['nb_comment_page'] < 5 |
---|
142 | or $_POST['nb_comment_page'] > 50) |
---|
143 | { |
---|
144 | array_push($page['errors'], l10n('The number of comments a page must be between 5 and 50 included.')); |
---|
145 | } |
---|
146 | foreach( $comments_checkboxes as $checkbox) |
---|
147 | { |
---|
148 | $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true'; |
---|
149 | } |
---|
150 | break; |
---|
151 | } |
---|
152 | case 'default' : |
---|
153 | { |
---|
154 | // Never go here |
---|
155 | break; |
---|
156 | } |
---|
157 | case 'display' : |
---|
158 | { |
---|
159 | foreach( $display_checkboxes as $checkbox) |
---|
160 | { |
---|
161 | $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true'; |
---|
162 | } |
---|
163 | foreach( $display_info_checkboxes as $checkbox) |
---|
164 | { |
---|
165 | $_POST['picture_informations'][$checkbox] = |
---|
166 | empty($_POST['picture_informations'][$checkbox])? false : true; |
---|
167 | } |
---|
168 | $_POST['picture_informations'] = addslashes(serialize($_POST['picture_informations'])); |
---|
169 | break; |
---|
170 | } |
---|
171 | } |
---|
172 | |
---|
173 | // updating configuration if no error found |
---|
174 | if (count($page['errors']) == 0) |
---|
175 | { |
---|
176 | //echo '<pre>'; print_r($_POST); echo '</pre>'; |
---|
177 | $result = pwg_query('SELECT param FROM '.CONFIG_TABLE); |
---|
178 | while ($row = pwg_db_fetch_assoc($result)) |
---|
179 | { |
---|
180 | if (isset($_POST[$row['param']])) |
---|
181 | { |
---|
182 | $value = $_POST[$row['param']]; |
---|
183 | |
---|
184 | if ('gallery_title' == $row['param']) |
---|
185 | { |
---|
186 | if (!$conf['allow_html_descriptions']) |
---|
187 | { |
---|
188 | $value = strip_tags($value); |
---|
189 | } |
---|
190 | } |
---|
191 | |
---|
192 | $query = ' |
---|
193 | UPDATE '.CONFIG_TABLE.' |
---|
194 | SET value = \''. str_replace("\'", "''", $value).'\' |
---|
195 | WHERE param = \''.$row['param'].'\' |
---|
196 | ;'; |
---|
197 | pwg_query($query); |
---|
198 | } |
---|
199 | } |
---|
200 | array_push($page['infos'], l10n('Information data registered in database')); |
---|
201 | } |
---|
202 | |
---|
203 | //------------------------------------------------------ $conf reinitialization |
---|
204 | load_conf_from_db(); |
---|
205 | } |
---|
206 | |
---|
207 | //----------------------------------------------------- template initialization |
---|
208 | $template->set_filename('config', 'configuration.tpl'); |
---|
209 | |
---|
210 | // TabSheet |
---|
211 | $tabsheet = new tabsheet(); |
---|
212 | // TabSheet initialization |
---|
213 | $tabsheet->add('main', l10n('Main'), $conf_link.'main'); |
---|
214 | $tabsheet->add('display', l10n('Display'), $conf_link.'display'); |
---|
215 | $tabsheet->add('history', l10n('History'), $conf_link.'history'); |
---|
216 | $tabsheet->add('comments', l10n('Comments'), $conf_link.'comments'); |
---|
217 | $tabsheet->add('default', l10n('Guest Settings'), $conf_link.'default'); |
---|
218 | // TabSheet selection |
---|
219 | $tabsheet->select($page['section']); |
---|
220 | // Assign tabsheet to template |
---|
221 | $tabsheet->assign(); |
---|
222 | |
---|
223 | $action = get_root_url().'admin.php?page=configuration'; |
---|
224 | $action.= '&section='.$page['section']; |
---|
225 | |
---|
226 | $template->assign( |
---|
227 | array( |
---|
228 | 'U_HELP' => get_root_url().'admin/popuphelp.php?page=configuration', |
---|
229 | 'F_ACTION'=>$action |
---|
230 | )); |
---|
231 | |
---|
232 | switch ($page['section']) |
---|
233 | { |
---|
234 | case 'main' : |
---|
235 | { |
---|
236 | $template->assign( |
---|
237 | 'main', |
---|
238 | array( |
---|
239 | 'CONF_GALLERY_TITLE' => htmlspecialchars($conf['gallery_title']), |
---|
240 | 'CONF_PAGE_BANNER' => htmlspecialchars($conf['page_banner']), |
---|
241 | 'CONF_GALLERY_URL' => $conf['gallery_url'], |
---|
242 | 'week_starts_on_options' => array( |
---|
243 | 'sunday' => $lang['day'][0], |
---|
244 | 'monday' => $lang['day'][1], |
---|
245 | ), |
---|
246 | 'week_starts_on_options_selected' => $conf['week_starts_on'], |
---|
247 | )); |
---|
248 | |
---|
249 | foreach ($main_checkboxes as $checkbox) |
---|
250 | { |
---|
251 | $template->append( |
---|
252 | 'main', |
---|
253 | array( |
---|
254 | $checkbox => $conf[$checkbox] |
---|
255 | ), |
---|
256 | true |
---|
257 | ); |
---|
258 | } |
---|
259 | break; |
---|
260 | } |
---|
261 | case 'history' : |
---|
262 | { |
---|
263 | //Necessary for merge_block_vars |
---|
264 | foreach ($history_checkboxes as $checkbox) |
---|
265 | { |
---|
266 | $template->append( |
---|
267 | 'history', |
---|
268 | array( |
---|
269 | $checkbox => $conf[$checkbox] |
---|
270 | ), |
---|
271 | true |
---|
272 | ); |
---|
273 | } |
---|
274 | break; |
---|
275 | } |
---|
276 | case 'comments' : |
---|
277 | { |
---|
278 | $template->assign( |
---|
279 | 'comments', |
---|
280 | array( |
---|
281 | 'NB_COMMENTS_PAGE'=>$conf['nb_comment_page'], |
---|
282 | )); |
---|
283 | |
---|
284 | foreach ($comments_checkboxes as $checkbox) |
---|
285 | { |
---|
286 | $template->append( |
---|
287 | 'comments', |
---|
288 | array( |
---|
289 | $checkbox => $conf[$checkbox] |
---|
290 | ), |
---|
291 | true |
---|
292 | ); |
---|
293 | } |
---|
294 | break; |
---|
295 | } |
---|
296 | case 'default' : |
---|
297 | { |
---|
298 | $edit_user = build_user($conf['guest_id'], false); |
---|
299 | include_once(PHPWG_ROOT_PATH.'profile.php'); |
---|
300 | |
---|
301 | $errors = array(); |
---|
302 | if (save_profile_from_post($edit_user, $errors)) |
---|
303 | { |
---|
304 | // Reload user |
---|
305 | $edit_user = build_user($conf['guest_id'], false); |
---|
306 | array_push($page['infos'], l10n('Information data registered in database')); |
---|
307 | } |
---|
308 | $page['errors'] = array_merge($page['errors'], $errors); |
---|
309 | |
---|
310 | load_profile_in_template( |
---|
311 | $action, |
---|
312 | '', |
---|
313 | $edit_user |
---|
314 | ); |
---|
315 | $template->assign('default', array()); |
---|
316 | break; |
---|
317 | } |
---|
318 | case 'display' : |
---|
319 | { |
---|
320 | foreach ($display_checkboxes as $checkbox) |
---|
321 | { |
---|
322 | $template->append( |
---|
323 | 'display', |
---|
324 | array( |
---|
325 | $checkbox => $conf[$checkbox] |
---|
326 | ), |
---|
327 | true |
---|
328 | ); |
---|
329 | } |
---|
330 | $template->append( |
---|
331 | 'display', |
---|
332 | array( |
---|
333 | 'picture_informations' => unserialize($conf['picture_informations']) |
---|
334 | ), |
---|
335 | true |
---|
336 | ); |
---|
337 | break; |
---|
338 | } |
---|
339 | } |
---|
340 | |
---|
341 | //----------------------------------------------------------- sending html code |
---|
342 | $template->assign_var_from_handle('ADMIN_CONTENT', 'config'); |
---|
343 | ?> |
---|