source: tags/release-1_5_0RC1/admin/configuration.php @ 18996

Last change on this file since 18996 was 869, checked in by plg, 19 years ago
  • bug 111 fixed: "Can't add virtual category when cookie disabled". Correction reported from branch 1.4.
  • bug 109 fixed : "disabled "best rated" menu item when rating is not enabled". Correction reported from branch 1.4.
  • bug 95 fixed : "default maxwidth and maxheight not registered". Correction reported from branch 1.4.
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.4 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-2005 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $RCSfile$
9// | last update   : $Date: 2005-09-18 22:29:17 +0000 (Sun, 18 Sep 2005) $
10// | last modifier : $Author: plg $
11// | revision      : $Revision: 869 $
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/isadmin.inc.php' );
34//-------------------------------------------------------- sections definitions
35if (!isset($_GET['section']))
36{
37  $page['section'] = 'general';
38}
39else
40{
41  $page['section'] = $_GET['section'];
42}
43//------------------------------------------------------ $conf reinitialization
44$result = pwg_query('SELECT param,value FROM '.CONFIG_TABLE);
45while ($row = mysql_fetch_array($result))
46{
47  $conf[$row['param']] = $row['value'];
48  // if the parameter is present in $_POST array (if a form is submited), we
49  // override it with the submited value
50  if (isset($_POST[$row['param']]))
51  {
52    $conf[$row['param']] = $_POST[$row['param']];
53  }
54}                                         
55//------------------------------ verification and registration of modifications
56if (isset($_POST['submit']))
57{
58  $int_pattern = '/^\d+$/';
59  switch ($page['section'])
60  {
61    case 'general' :
62    {
63      break;
64    }
65    case 'comments' :
66    {
67      // the number of comments per page must be an integer between 5 and 50
68      // included
69      if (!preg_match($int_pattern, $_POST['nb_comment_page'])
70           or $_POST['nb_comment_page'] < 5
71           or $_POST['nb_comment_page'] > 50)
72      {
73        array_push($page['errors'], $lang['conf_nb_comment_page_error']);
74      }
75      break;
76    }
77    case 'default' :
78    {
79      // periods must be integer values, they represents number of days
80      if (!preg_match($int_pattern, $_POST['recent_period'])
81          or $_POST['recent_period'] <= 0)
82      {
83        array_push($page['errors'], $lang['periods_error']);
84      }
85      // maxwidth
86      if (isset($_POST['default_maxwidth'])
87          and !empty($_POST['default_maxwidth'])
88          and (!preg_match($int_pattern, $_POST['default_maxwidth'])
89               or $_POST['default_maxwidth'] < 50))
90      {
91        array_push($page['errors'], $lang['maxwidth_error']);
92      }
93      // maxheight
94      if (isset($_POST['default_maxheight'])
95          and !empty($_POST['default_maxheight'])
96          and (!preg_match($int_pattern, $_POST['default_maxheight'])
97               or $_POST['default_maxheight'] < 50))
98      {
99        array_push($page['errors'], $lang['maxheight_error']);
100      }
101      break;
102    }
103  }
104 
105  // updating configuration if no error found
106  if (count($page['errors']) == 0)
107  {
108//    echo '<pre>'; print_r($_POST); echo '</pre>';
109    $result = pwg_query('SELECT * FROM '.CONFIG_TABLE);
110    while ($row = mysql_fetch_array($result))
111    {
112      if (isset($_POST[$row['param']]))
113      {
114        $query = '
115UPDATE '.CONFIG_TABLE.'
116  SET value = \''. str_replace("\'", "''", $_POST[$row['param']]).'\'
117  WHERE param = \''.$row['param'].'\'
118;';
119        pwg_query($query);
120      }
121    }
122    array_push($page['infos'], $lang['conf_confirmation']);
123  }
124}
125
126//----------------------------------------------------- template initialization
127$template->set_filenames( array('config'=>'admin/configuration.tpl') );
128
129$action = PHPWG_ROOT_PATH.'admin.php?page=configuration';
130$action.= '&amp;section='.$page['section'];
131
132$template->assign_vars(
133  array(
134    'L_YES'=>$lang['yes'],
135    'L_NO'=>$lang['no'],
136    'L_SUBMIT'=>$lang['submit'],
137    'L_RESET'=>$lang['reset'],
138
139    'U_HELP' => PHPWG_ROOT_PATH.'/popuphelp.php?page=configuration',
140   
141    'F_ACTION'=>add_session_id($action)
142    ));
143
144switch ($page['section'])
145{
146  case 'general' :
147  {
148    $history_yes = ($conf['log']=='true')?'checked="checked"':'';
149    $history_no  = ($conf['log']=='false')?'checked="checked"':'';
150    $lock_yes = ($conf['gallery_locked']=='true')?'checked="checked"':'';
151    $lock_no = ($conf['gallery_locked']=='false')?'checked="checked"':'';
152   
153    $template->assign_block_vars(
154      'general',
155      array(
156        'HISTORY_YES'=>$history_yes,
157        'HISTORY_NO'=>$history_no,
158        'GALLERY_LOCKED_YES'=>$lock_yes,
159        'GALLERY_LOCKED_NO'=>$lock_no,
160        ));
161    break;
162  }
163  case 'comments' :
164  {
165    $all_yes = ($conf['comments_forall']=='true')?'checked="checked"':'';
166    $all_no  = ($conf['comments_forall']=='false')?'checked="checked"':'';
167    $validate_yes = ($conf['comments_validation']=='true')?'checked="checked"':'';
168    $validate_no = ($conf['comments_validation']=='false')?'checked="checked"':'';
169     
170    $template->assign_block_vars(
171      'comments',
172      array(
173        'NB_COMMENTS_PAGE'=>$conf['nb_comment_page'],
174        'COMMENTS_ALL_YES'=>$all_yes,
175        'COMMENTS_ALL_NO'=>$all_no,
176        'VALIDATE_YES'=>$validate_yes,
177        'VALIDATE_NO'=>$validate_no
178        ));
179    break;
180  }
181  case 'default' :
182  {
183    $show_yes = ($conf['show_nb_comments']=='true')?'checked="checked"':'';
184    $show_no = ($conf['show_nb_comments']=='false')?'checked="checked"':'';
185    $expand_yes = ($conf['auto_expand']=='true')?'checked="checked"':'';
186    $expand_no  = ($conf['auto_expand']=='false')?'checked="checked"':'';
187     
188    $template->assign_block_vars(
189      'default',
190      array(
191        'NB_IMAGE_LINE'=>$conf['nb_image_line'],
192        'NB_ROW_PAGE'=>$conf['nb_line_page'],
193        'CONF_RECENT'=>$conf['recent_period'],
194        'NB_COMMENTS_PAGE'=>$conf['nb_comment_page'],
195        'MAXWIDTH'=>$conf['default_maxwidth'],
196        'MAXHEIGHT'=>$conf['default_maxheight'],
197        'EXPAND_YES'=>$expand_yes,
198        'EXPAND_NO'=>$expand_no,
199        'SHOW_COMMENTS_YES'=>$show_yes,
200        'SHOW_COMMENTS_NO'=>$show_no
201        ));
202   
203    $blockname = 'default.language_option';
204   
205    foreach (get_languages() as $language_code => $language_name)
206    {
207      if (isset($_POST['submit']))
208      {
209        $selected =
210          $_POST['default_language'] == $language_code
211            ? 'selected="selected"' : '';
212      }
213      else if ($conf['default_language'] == $language_code)
214      {
215        $selected = 'selected="selected"';
216      }
217      else
218      {
219        $selected = '';
220      }
221     
222      $template->assign_block_vars(
223        $blockname,
224        array(
225          'VALUE'=> $language_code,
226          'CONTENT' => $language_name,
227          'SELECTED' => $selected
228          ));
229    }
230
231    $blockname = 'default.template_option';
232
233    foreach (get_templates() as $pwg_template)
234    {
235      if (isset($_POST['submit']))
236      {
237        $selected =
238          $_POST['default_template'] == $pwg_template
239            ? 'selected="selected"' : '';
240      }
241      else if ($conf['default_template'] == $pwg_template)
242      {
243        $selected = 'selected="selected"';
244      }
245      else
246      {
247        $selected = '';
248      }
249     
250      $template->assign_block_vars(
251        $blockname,
252        array(
253          'VALUE'=> $pwg_template,
254          'CONTENT' => $pwg_template,
255          'SELECTED' => $selected
256          )
257        );
258    }
259
260 
261    break;
262  }
263}
264//----------------------------------------------------------- sending html code
265$template->assign_var_from_handle('ADMIN_CONTENT', 'config');
266?>
Note: See TracBrowser for help on using the repository browser.