source: trunk/admin/configuration.php @ 1881

Last change on this file since 1881 was 1881, checked in by rub, 17 years ago

Add tabsheet on administration pages.

Step 3: Tabsheet for configuration & history

Change css tabsheet to do like p0w0 for all themes

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.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-2007 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $RCSfile$
9// | last update   : $Date: 2007-03-08 22:14:14 +0000 (Thu, 08 Mar 2007) $
10// | last modifier : $Author: rub $
11// | revision      : $Revision: 1881 $
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');
34include_once(PHPWG_ROOT_PATH.'admin/include/functions_tabsheet.inc.php');
35
36// +-----------------------------------------------------------------------+
37// | Check Access and exit when user status is not ok                      |
38// +-----------------------------------------------------------------------+
39check_status(ACCESS_ADMINISTRATOR);
40
41//-------------------------------------------------------- sections definitions
42if (!isset($_GET['section']))
43{
44  $page['section'] = 'general';
45}
46else
47{
48  $page['section'] = $_GET['section'];
49}
50
51$general_checkboxes = array(
52    'log',
53    'history_admin',
54    'history_guest',
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 param 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  //------------------------------------------------------ $conf reinitialization
159  load_conf_from_db();
160}
161
162//----------------------------------------------------- template initialization
163$template->set_filename('config', 'admin/configuration.tpl');
164
165// TabSheet initialization
166$page['tabsheet'] = array
167(
168  'general' => array
169   (
170    'caption' => l10n('conf_general_title'),
171    'url' => $conf_link.'general'
172   ),
173  'comments' => array
174   (
175    'caption' => l10n('conf_comments_title'),
176    'url' => $conf_link.'comments'
177   ),
178  'default' => array
179   (
180    'caption' => l10n('conf_default'),
181    'url' => $conf_link.'default'
182   )
183);
184
185$page['tabsheet'][$page['section']]['selected'] = true;
186
187// Assign tabsheet to template
188template_assign_tabsheet();
189
190$action = PHPWG_ROOT_PATH.'admin.php?page=configuration';
191$action.= '&amp;section='.$page['section'];
192
193$template->assign_vars(
194  array(
195    'L_YES'=>$lang['yes'],
196    'L_NO'=>$lang['no'],
197    'L_SUBMIT'=>$lang['submit'],
198    'L_RESET'=>$lang['reset'],
199
200    'U_HELP' => PHPWG_ROOT_PATH.'popuphelp.php?page=configuration',
201
202    'F_ACTION'=>$action
203    ));
204
205$html_check='checked="checked"';
206
207switch ($page['section'])
208{
209  case 'general' :
210  {
211    $lock_yes = ($conf['gallery_locked']==true)?'checked="checked"':'';
212    $lock_no = ($conf['gallery_locked']==false)?'checked="checked"':'';
213
214    $template->assign_block_vars(
215      'general',
216      array(
217        'GALLERY_LOCKED_YES'=>$lock_yes,
218        'GALLERY_LOCKED_NO'=>$lock_no,
219        ($conf['rate']==true?'RATE_YES':'RATE_NO')=>$html_check,
220        ($conf['rate_anonymous']==true
221             ? 'RATE_ANONYMOUS_YES' : 'RATE_ANONYMOUS_NO')=>$html_check,
222        'CONF_GALLERY_TITLE' => $conf['gallery_title'],
223        'CONF_PAGE_BANNER' => $conf['page_banner'],
224        'CONF_GALLERY_URL' => $conf['gallery_url'],
225        ));
226
227    foreach( $general_checkboxes as $checkbox)
228    {
229      $template->merge_block_vars(
230          'general',
231          array(
232            strtoupper($checkbox) => ($conf[$checkbox]==true)?$html_check:''
233            )
234        );
235    }
236    break;
237  }
238  case 'comments' :
239  {
240    $template->assign_block_vars(
241      'comments',
242      array(
243        'NB_COMMENTS_PAGE'=>$conf['nb_comment_page'],
244        ));
245
246    foreach( $comments_checkboxes as $checkbox)
247    {
248      $template->merge_block_vars(
249          'comments',
250          array(
251            strtoupper($checkbox) => ($conf[$checkbox]==true)?$html_check:''
252            )
253        );
254    }
255    break;
256  }
257  case 'default' :
258  {
259    $show_yes = ($conf['show_nb_comments']==true)?'checked="checked"':'';
260    $show_no = ($conf['show_nb_comments']==false)?'checked="checked"':'';
261    $hits_yes = ($conf['show_nb_hits']==true)?'checked="checked"':'';
262    $hits_no = ($conf['show_nb_hits']==false)?'checked="checked"':'';
263    $expand_yes = ($conf['auto_expand']==true)?'checked="checked"':'';
264    $expand_no  = ($conf['auto_expand']==false)?'checked="checked"':'';
265
266    $template->assign_block_vars(
267      'default',
268      array(
269        'NB_IMAGE_LINE'=>$conf['nb_image_line'],
270        'NB_ROW_PAGE'=>$conf['nb_line_page'],
271        'CONF_RECENT'=>$conf['recent_period'],
272        'NB_COMMENTS_PAGE'=>$conf['nb_comment_page'],
273        'MAXWIDTH'=>$conf['default_maxwidth'],
274        'MAXHEIGHT'=>$conf['default_maxheight'],
275        'EXPAND_YES'=>$expand_yes,
276        'EXPAND_NO'=>$expand_no,
277        'SHOW_COMMENTS_YES'=>$show_yes,
278        'SHOW_COMMENTS_NO'=>$show_no,
279        'SHOW_HITS_YES'=>$hits_yes,
280        'SHOW_HITS_NO'=>$hits_no,
281        ));
282
283    $blockname = 'default.language_option';
284
285    foreach (get_languages() as $language_code => $language_name)
286    {
287      if (isset($_POST['submit']))
288      {
289        $selected =
290          $_POST['default_language'] == $language_code
291            ? 'selected="selected"' : '';
292      }
293      else if ($conf['default_language'] == $language_code)
294      {
295        $selected = 'selected="selected"';
296      }
297      else
298      {
299        $selected = '';
300      }
301
302      $template->assign_block_vars(
303        $blockname,
304        array(
305          'VALUE'=> $language_code,
306          'CONTENT' => $language_name,
307          'SELECTED' => $selected
308          ));
309    }
310
311    $blockname = 'default.template_option';
312
313    foreach (get_pwg_themes() as $pwg_template)
314    {
315      if (isset($_POST['submit']))
316      {
317        $selected =
318          $_POST['default_template'] == $pwg_template
319            ? 'selected="selected"' : '';
320      }
321      else if ($conf['default_template'] == $pwg_template)
322      {
323        $selected = 'selected="selected"';
324      }
325      else
326      {
327        $selected = '';
328      }
329
330      $template->assign_block_vars(
331        $blockname,
332        array(
333          'VALUE'=> $pwg_template,
334          'CONTENT' => $pwg_template,
335          'SELECTED' => $selected
336          )
337        );
338    }
339
340
341    break;
342  }
343}
344//----------------------------------------------------------- sending html code
345$template->assign_var_from_handle('ADMIN_CONTENT', 'config');
346?>
Note: See TracBrowser for help on using the repository browser.