source: trunk/admin/configuration.php @ 1071

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

bug 255: parameter values in #config limited to 255 chars (value becomes text)

feature 303: page banner moved from combination of gallery_title,
gallery_description and template to database (simplifies user customization)

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