source: tags/build-A01/admin/configuration.php @ 8487

Last change on this file since 8487 was 1652, checked in by rvelices, 18 years ago
  • feature 599: option to forbid user registration
  • 1 language cleanup
  • added page_forbidden function (sends 403)
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.5 KB
Line 
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-2006 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $RCSfile$
9// | last update   : $Date: 2006-12-13 01:05:38 +0000 (Wed, 13 Dec 2006) $
10// | last modifier : $Author: rvelices $
11// | revision      : $Revision: 1652 $
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
28if( !defined("PHPWG_ROOT_PATH") )
29{
30  die ("Hacking attempt!");
31}
32
33include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
34
35// +-----------------------------------------------------------------------+
36// | Check Access and exit when user status is not ok                      |
37// +-----------------------------------------------------------------------+
38check_status(ACCESS_ADMINISTRATOR);
39
40//-------------------------------------------------------- sections definitions
41if (!isset($_GET['section']))
42{
43  $page['section'] = 'general';
44}
45else
46{
47  $page['section'] = $_GET['section'];
48}
49
50$general_checkboxes = array(
51    'log',
52    'history_admin',
53    'history_guest',
54    'login_history',
55    'email_admin_on_new_user',
56    'allow_user_registration',
57   );
58
59$comments_checkboxes = array(
60    'comments_forall',
61    'comments_validation',
62    'email_admin_on_comment',
63    'email_admin_on_comment_validation',
64  );
65
66//------------------------------ verification and registration of modifications
67if (isset($_POST['submit']) and !is_adviser())
68{
69  $int_pattern = '/^\d+$/';
70  switch ($page['section'])
71  {
72    case 'general' :
73    {
74      if ( !url_is_remote($_POST['gallery_url']) )
75      {
76        array_push($page['errors'], $lang['conf_gallery_url_error']);
77      }
78      foreach( $general_checkboxes as $checkbox)
79      {
80        $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
81      }
82      break;
83    }
84    case 'comments' :
85    {
86      // the number of comments per page must be an integer between 5 and 50
87      // included
88      if (!preg_match($int_pattern, $_POST['nb_comment_page'])
89           or $_POST['nb_comment_page'] < 5
90           or $_POST['nb_comment_page'] > 50)
91      {
92        array_push($page['errors'], $lang['conf_nb_comment_page_error']);
93      }
94      foreach( $comments_checkboxes as $checkbox)
95      {
96        $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
97      }
98      break;
99    }
100    case 'default' :
101    {
102      // periods must be integer values, they represents number of days
103      if (!preg_match($int_pattern, $_POST['recent_period'])
104          or $_POST['recent_period'] <= 0)
105      {
106        array_push($page['errors'], $lang['periods_error']);
107      }
108      // maxwidth
109      if (isset($_POST['default_maxwidth'])
110          and !empty($_POST['default_maxwidth'])
111          and (!preg_match($int_pattern, $_POST['default_maxwidth'])
112               or $_POST['default_maxwidth'] < 50))
113      {
114        array_push($page['errors'], $lang['maxwidth_error']);
115      }
116      // maxheight
117      if (isset($_POST['default_maxheight'])
118          and !empty($_POST['default_maxheight'])
119          and (!preg_match($int_pattern, $_POST['default_maxheight'])
120               or $_POST['default_maxheight'] < 50))
121      {
122        array_push($page['errors'], $lang['maxheight_error']);
123      }
124      break;
125    }
126  }
127
128  // updating configuration if no error found
129  if (count($page['errors']) == 0)
130  {
131    //echo '<pre>'; print_r($_POST); echo '</pre>';
132    $result = pwg_query('SELECT * FROM '.CONFIG_TABLE);
133    while ($row = mysql_fetch_array($result))
134    {
135      if (isset($_POST[$row['param']]))
136      {
137        $value = $_POST[$row['param']];
138
139        if ('gallery_title' == $row['param'])
140        {
141          if (!$conf['allow_html_descriptions'])
142          {
143            $value = strip_tags($value);
144          }
145        }
146
147        $query = '
148UPDATE '.CONFIG_TABLE.'
149  SET value = \''. str_replace("\'", "''", $value).'\'
150  WHERE param = \''.$row['param'].'\'
151;';
152        pwg_query($query);
153      }
154    }
155    array_push($page['infos'], $lang['conf_confirmation']);
156  }
157}
158
159//------------------------------------------------------ $conf reinitialization
160$result = pwg_query('SELECT param,value FROM '.CONFIG_TABLE);
161while ($row = mysql_fetch_array($result))
162{
163  $conf[$row['param']] = $row['value'];
164}
165
166//----------------------------------------------------- template initialization
167$template->set_filenames( array('config'=>'admin/configuration.tpl') );
168
169$action = PHPWG_ROOT_PATH.'admin.php?page=configuration';
170$action.= '&amp;section='.$page['section'];
171
172$template->assign_vars(
173  array(
174    'L_YES'=>$lang['yes'],
175    'L_NO'=>$lang['no'],
176    'L_SUBMIT'=>$lang['submit'],
177    'L_RESET'=>$lang['reset'],
178
179    'U_HELP' => PHPWG_ROOT_PATH.'popuphelp.php?page=configuration',
180
181    'F_ACTION'=>$action
182    ));
183
184$html_check='checked="checked"';
185
186switch ($page['section'])
187{
188  case 'general' :
189  {
190    $lock_yes = ($conf['gallery_locked']=='true')?'checked="checked"':'';
191    $lock_no = ($conf['gallery_locked']=='false')?'checked="checked"':'';
192
193    $template->assign_block_vars(
194      'general',
195      array(
196        'GALLERY_LOCKED_YES'=>$lock_yes,
197        'GALLERY_LOCKED_NO'=>$lock_no,
198        ($conf['rate']=='true'?'RATE_YES':'RATE_NO')=>$html_check,
199        ($conf['rate_anonymous']=='true'
200             ? 'RATE_ANONYMOUS_YES' : 'RATE_ANONYMOUS_NO')=>$html_check,
201        'CONF_GALLERY_TITLE' => $conf['gallery_title'],
202        'CONF_PAGE_BANNER' => $conf['page_banner'],
203        'CONF_GALLERY_URL' => $conf['gallery_url'],
204        ));
205
206    foreach( $general_checkboxes as $checkbox)
207    {
208      $template->merge_block_vars(
209          'general',
210          array(
211            strtoupper($checkbox) => ($conf[$checkbox]=='true')?$html_check:''
212            )
213        );
214    }
215    break;
216  }
217  case 'comments' :
218  {
219    $template->assign_block_vars(
220      'comments',
221      array(
222        'NB_COMMENTS_PAGE'=>$conf['nb_comment_page'],
223        ));
224
225    foreach( $comments_checkboxes as $checkbox)
226    {
227      $template->merge_block_vars(
228          'comments',
229          array(
230            strtoupper($checkbox) => ($conf[$checkbox]=='true')?$html_check:''
231            )
232        );
233    }
234    break;
235  }
236  case 'default' :
237  {
238    $show_yes = ($conf['show_nb_comments']=='true')?'checked="checked"':'';
239    $show_no = ($conf['show_nb_comments']=='false')?'checked="checked"':'';
240    $expand_yes = ($conf['auto_expand']=='true')?'checked="checked"':'';
241    $expand_no  = ($conf['auto_expand']=='false')?'checked="checked"':'';
242
243    $template->assign_block_vars(
244      'default',
245      array(
246        'NB_IMAGE_LINE'=>$conf['nb_image_line'],
247        'NB_ROW_PAGE'=>$conf['nb_line_page'],
248        'CONF_RECENT'=>$conf['recent_period'],
249        'NB_COMMENTS_PAGE'=>$conf['nb_comment_page'],
250        'MAXWIDTH'=>$conf['default_maxwidth'],
251        'MAXHEIGHT'=>$conf['default_maxheight'],
252        'EXPAND_YES'=>$expand_yes,
253        'EXPAND_NO'=>$expand_no,
254        'SHOW_COMMENTS_YES'=>$show_yes,
255        'SHOW_COMMENTS_NO'=>$show_no
256        ));
257
258    $blockname = 'default.language_option';
259
260    foreach (get_languages() as $language_code => $language_name)
261    {
262      if (isset($_POST['submit']))
263      {
264        $selected =
265          $_POST['default_language'] == $language_code
266            ? 'selected="selected"' : '';
267      }
268      else if ($conf['default_language'] == $language_code)
269      {
270        $selected = 'selected="selected"';
271      }
272      else
273      {
274        $selected = '';
275      }
276
277      $template->assign_block_vars(
278        $blockname,
279        array(
280          'VALUE'=> $language_code,
281          'CONTENT' => $language_name,
282          'SELECTED' => $selected
283          ));
284    }
285
286    $blockname = 'default.template_option';
287
288    foreach (get_pwg_themes() as $pwg_template)
289    {
290      if (isset($_POST['submit']))
291      {
292        $selected =
293          $_POST['default_template'] == $pwg_template
294            ? 'selected="selected"' : '';
295      }
296      else if ($conf['default_template'] == $pwg_template)
297      {
298        $selected = 'selected="selected"';
299      }
300      else
301      {
302        $selected = '';
303      }
304
305      $template->assign_block_vars(
306        $blockname,
307        array(
308          'VALUE'=> $pwg_template,
309          'CONTENT' => $pwg_template,
310          'SELECTED' => $selected
311          )
312        );
313    }
314
315
316    break;
317  }
318}
319//----------------------------------------------------------- sending html code
320$template->assign_var_from_handle('ADMIN_CONTENT', 'config');
321?>
Note: See TracBrowser for help on using the repository browser.