source: trunk/admin/configuration.php @ 1565

Last change on this file since 1565 was 1565, checked in by rvelices, 18 years ago

feature 564: logs in the history table each user login
feature 562: possibility to log page visits for any combination of
administrators/users/guests

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.7 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-10-19 00:41:07 +0000 (Thu, 19 Oct 2006) $
10// | last modifier : $Author: rvelices $
11// | revision      : $Revision: 1565 $
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//------------------------------ verification and registration of modifications
50if (isset($_POST['submit']))
51{
52  $int_pattern = '/^\d+$/';
53  switch ($page['section'])
54  {
55    case 'general' :
56    {
57      if ( !url_is_remote($_POST['gallery_url']) )
58      {
59        array_push($page['errors'], $lang['conf_gallery_url_error']);
60      }
61      $_POST['log'] = empty($_POST['log'])?'false':'true';
62      $_POST['history_admin'] = empty($_POST['history_admin'])?'false':'true';
63      $_POST['history_guest'] = empty($_POST['history_guest'])?'false':'true';
64      $_POST['login_history'] = empty($_POST['login_history'])?'false':'true';
65      break;
66    }
67    case 'comments' :
68    {
69      // the number of comments per page must be an integer between 5 and 50
70      // included
71      if (!preg_match($int_pattern, $_POST['nb_comment_page'])
72           or $_POST['nb_comment_page'] < 5
73           or $_POST['nb_comment_page'] > 50)
74      {
75        array_push($page['errors'], $lang['conf_nb_comment_page_error']);
76      }
77      break;
78    }
79    case 'default' :
80    {
81      // periods must be integer values, they represents number of days
82      if (!preg_match($int_pattern, $_POST['recent_period'])
83          or $_POST['recent_period'] <= 0)
84      {
85        array_push($page['errors'], $lang['periods_error']);
86      }
87      // maxwidth
88      if (isset($_POST['default_maxwidth'])
89          and !empty($_POST['default_maxwidth'])
90          and (!preg_match($int_pattern, $_POST['default_maxwidth'])
91               or $_POST['default_maxwidth'] < 50))
92      {
93        array_push($page['errors'], $lang['maxwidth_error']);
94      }
95      // maxheight
96      if (isset($_POST['default_maxheight'])
97          and !empty($_POST['default_maxheight'])
98          and (!preg_match($int_pattern, $_POST['default_maxheight'])
99               or $_POST['default_maxheight'] < 50))
100      {
101        array_push($page['errors'], $lang['maxheight_error']);
102      }
103      break;
104    }
105  }
106
107  // updating configuration if no error found
108  if (count($page['errors']) == 0)
109  {
110    //echo '<pre>'; print_r($_POST); echo '</pre>';
111    $result = pwg_query('SELECT * FROM '.CONFIG_TABLE);
112    while ($row = mysql_fetch_array($result))
113    {
114      if (isset($_POST[$row['param']]))
115      {
116        $value = $_POST[$row['param']];
117
118        if ('gallery_title' == $row['param'])
119        {
120          if (!$conf['allow_html_descriptions'])
121          {
122            $value = strip_tags($value);
123          }
124        }
125
126        $query = '
127UPDATE '.CONFIG_TABLE.'
128  SET value = \''. str_replace("\'", "''", $value).'\'
129  WHERE param = \''.$row['param'].'\'
130;';
131        pwg_query($query);
132      }
133    }
134    array_push($page['infos'], $lang['conf_confirmation']);
135  }
136}
137
138//------------------------------------------------------ $conf reinitialization
139$result = pwg_query('SELECT param,value FROM '.CONFIG_TABLE);
140while ($row = mysql_fetch_array($result))
141{
142  $conf[$row['param']] = $row['value'];
143}
144
145//----------------------------------------------------- template initialization
146$template->set_filenames( array('config'=>'admin/configuration.tpl') );
147
148$action = PHPWG_ROOT_PATH.'admin.php?page=configuration';
149$action.= '&amp;section='.$page['section'];
150
151$template->assign_vars(
152  array(
153    'L_YES'=>$lang['yes'],
154    'L_NO'=>$lang['no'],
155    'L_SUBMIT'=>$lang['submit'],
156    'L_RESET'=>$lang['reset'],
157
158    'U_HELP' => PHPWG_ROOT_PATH.'popuphelp.php?page=configuration',
159
160    'F_ACTION'=>$action
161    ));
162
163switch ($page['section'])
164{
165  case 'general' :
166  {
167    $html_check='checked="checked"';
168
169    $lock_yes = ($conf['gallery_locked']=='true')?'checked="checked"':'';
170    $lock_no = ($conf['gallery_locked']=='false')?'checked="checked"':'';
171    $history_users = ($conf['log']=='true')?$html_check:'';
172    $history_admin = ($conf['history_admin']=='true')?$html_check:'';
173    $history_guest = ($conf['history_guest']=='true')?$html_check:'';
174    $login_history = ($conf['login_history']=='true')?$html_check:'';
175
176    $template->assign_block_vars(
177      'general',
178      array(
179        'HISTORY_USERS'=>$history_users,
180        'HISTORY_ADMIN'=>$history_admin,
181        'HISTORY_GUEST'=>$history_guest,
182        'LOGIN_HISTORY'=>$login_history,
183        'GALLERY_LOCKED_YES'=>$lock_yes,
184        'GALLERY_LOCKED_NO'=>$lock_no,
185        ($conf['rate']=='true'?'RATE_YES':'RATE_NO')=>$html_check,
186        ($conf['rate_anonymous']=='true'
187             ? 'RATE_ANONYMOUS_YES' : 'RATE_ANONYMOUS_NO')=>$html_check,
188        'CONF_GALLERY_TITLE' => $conf['gallery_title'],
189        'CONF_PAGE_BANNER' => $conf['page_banner'],
190        'CONF_GALLERY_URL' => $conf['gallery_url'],
191        ));
192    break;
193  }
194  case 'comments' :
195  {
196    $all_yes = ($conf['comments_forall']=='true')?'checked="checked"':'';
197    $all_no  = ($conf['comments_forall']=='false')?'checked="checked"':'';
198    $validate_yes = ($conf['comments_validation']=='true')?'checked="checked"':'';
199    $validate_no = ($conf['comments_validation']=='false')?'checked="checked"':'';
200
201    $template->assign_block_vars(
202      'comments',
203      array(
204        'NB_COMMENTS_PAGE'=>$conf['nb_comment_page'],
205        'COMMENTS_ALL_YES'=>$all_yes,
206        'COMMENTS_ALL_NO'=>$all_no,
207        'VALIDATE_YES'=>$validate_yes,
208        'VALIDATE_NO'=>$validate_no
209        ));
210    break;
211  }
212  case 'default' :
213  {
214    $show_yes = ($conf['show_nb_comments']=='true')?'checked="checked"':'';
215    $show_no = ($conf['show_nb_comments']=='false')?'checked="checked"':'';
216    $expand_yes = ($conf['auto_expand']=='true')?'checked="checked"':'';
217    $expand_no  = ($conf['auto_expand']=='false')?'checked="checked"':'';
218
219    $template->assign_block_vars(
220      'default',
221      array(
222        'NB_IMAGE_LINE'=>$conf['nb_image_line'],
223        'NB_ROW_PAGE'=>$conf['nb_line_page'],
224        'CONF_RECENT'=>$conf['recent_period'],
225        'NB_COMMENTS_PAGE'=>$conf['nb_comment_page'],
226        'MAXWIDTH'=>$conf['default_maxwidth'],
227        'MAXHEIGHT'=>$conf['default_maxheight'],
228        'EXPAND_YES'=>$expand_yes,
229        'EXPAND_NO'=>$expand_no,
230        'SHOW_COMMENTS_YES'=>$show_yes,
231        'SHOW_COMMENTS_NO'=>$show_no
232        ));
233
234    $blockname = 'default.language_option';
235
236    foreach (get_languages() as $language_code => $language_name)
237    {
238      if (isset($_POST['submit']))
239      {
240        $selected =
241          $_POST['default_language'] == $language_code
242            ? 'selected="selected"' : '';
243      }
244      else if ($conf['default_language'] == $language_code)
245      {
246        $selected = 'selected="selected"';
247      }
248      else
249      {
250        $selected = '';
251      }
252
253      $template->assign_block_vars(
254        $blockname,
255        array(
256          'VALUE'=> $language_code,
257          'CONTENT' => $language_name,
258          'SELECTED' => $selected
259          ));
260    }
261
262    $blockname = 'default.template_option';
263
264    foreach (get_pwg_themes() as $pwg_template)
265    {
266      if (isset($_POST['submit']))
267      {
268        $selected =
269          $_POST['default_template'] == $pwg_template
270            ? 'selected="selected"' : '';
271      }
272      else if ($conf['default_template'] == $pwg_template)
273      {
274        $selected = 'selected="selected"';
275      }
276      else
277      {
278        $selected = '';
279      }
280
281      $template->assign_block_vars(
282        $blockname,
283        array(
284          'VALUE'=> $pwg_template,
285          'CONTENT' => $pwg_template,
286          'SELECTED' => $selected
287          )
288        );
289    }
290
291
292    break;
293  }
294}
295//----------------------------------------------------------- sending html code
296$template->assign_var_from_handle('ADMIN_CONTENT', 'config');
297?>
Note: See TracBrowser for help on using the repository browser.