source: trunk/admin/configuration.php @ 1048

Last change on this file since 1048 was 1048, checked in by plg, 18 years ago

request 290: replace function get_themes name to avoid redeclaration from
Wordpress in jillij template.

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