source: trunk/admin/configuration.php @ 1920

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

"Put checkbox on the left!"

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 10.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-2007 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $RCSfile$
9// | last update   : $Date: 2007-03-26 19:15:52 +0000 (Mon, 26 Mar 2007) $
10// | last modifier : $Author: rub $
11// | revision      : $Revision: 1920 $
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'] = 'main';
45}
46else
47{
48  $page['section'] = $_GET['section'];
49}
50
51$main_checkboxes = array(
52    'rate',
53    'rate_anonymous',
54    'email_admin_on_new_user',
55    'allow_user_registration',
56    'email_admin_on_picture_uploaded',
57   );
58
59$history_checkboxes = array(
60    'log',
61    'history_admin',
62    'history_guest'
63   );
64
65$comments_checkboxes = array(
66    'comments_forall',
67    'comments_validation',
68    'email_admin_on_comment',
69    'email_admin_on_comment_validation',
70  );
71
72//------------------------------ verification and registration of modifications
73if (isset($_POST['submit']) and !is_adviser())
74{
75  $int_pattern = '/^\d+$/';
76  switch ($page['section'])
77  {
78    case 'main' :
79    {
80      if ( !url_is_remote($_POST['gallery_url']) )
81      {
82        array_push($page['errors'], $lang['conf_gallery_url_error']);
83      }
84      foreach( $main_checkboxes as $checkbox)
85      {
86        $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
87      }
88      break;
89    }
90    case 'history' :
91    {
92      foreach( $history_checkboxes as $checkbox)
93      {
94        $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
95      }
96      break;
97    }
98    case 'comments' :
99    {
100      // the number of comments per page must be an integer between 5 and 50
101      // included
102      if (!preg_match($int_pattern, $_POST['nb_comment_page'])
103           or $_POST['nb_comment_page'] < 5
104           or $_POST['nb_comment_page'] > 50)
105      {
106        array_push($page['errors'], $lang['conf_nb_comment_page_error']);
107      }
108      foreach( $comments_checkboxes as $checkbox)
109      {
110        $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
111      }
112      break;
113    }
114    case 'default' :
115    {
116      // periods must be integer values, they represents number of days
117      if (!preg_match($int_pattern, $_POST['recent_period'])
118          or $_POST['recent_period'] <= 0)
119      {
120        array_push($page['errors'], $lang['periods_error']);
121      }
122      // maxwidth
123      if (isset($_POST['default_maxwidth'])
124          and !empty($_POST['default_maxwidth'])
125          and (!preg_match($int_pattern, $_POST['default_maxwidth'])
126               or $_POST['default_maxwidth'] < 50))
127      {
128        array_push($page['errors'], $lang['maxwidth_error']);
129      }
130      // maxheight
131      if (isset($_POST['default_maxheight'])
132          and !empty($_POST['default_maxheight'])
133          and (!preg_match($int_pattern, $_POST['default_maxheight'])
134               or $_POST['default_maxheight'] < 50))
135      {
136        array_push($page['errors'], $lang['maxheight_error']);
137      }
138      break;
139    }
140  }
141
142  // updating configuration if no error found
143  if (count($page['errors']) == 0)
144  {
145    //echo '<pre>'; print_r($_POST); echo '</pre>';
146    $result = pwg_query('SELECT param FROM '.CONFIG_TABLE);
147    while ($row = mysql_fetch_array($result))
148    {
149      if (isset($_POST[$row['param']]))
150      {
151        $value = $_POST[$row['param']];
152
153        if ('gallery_title' == $row['param'])
154        {
155          if (!$conf['allow_html_descriptions'])
156          {
157            $value = strip_tags($value);
158          }
159        }
160
161        $query = '
162UPDATE '.CONFIG_TABLE.'
163  SET value = \''. str_replace("\'", "''", $value).'\'
164  WHERE param = \''.$row['param'].'\'
165;';
166        pwg_query($query);
167      }
168    }
169    array_push($page['infos'], $lang['conf_confirmation']);
170  }
171
172  //------------------------------------------------------ $conf reinitialization
173  load_conf_from_db();
174}
175
176//----------------------------------------------------- template initialization
177$template->set_filename('config', 'admin/configuration.tpl');
178
179// TabSheet initialization
180$page['tabsheet'] = array
181(
182  'main' => array
183   (
184    'caption' => l10n('conf_main_title'),
185    'url' => $conf_link.'main'
186   ),
187  'history' => array
188   (
189    'caption' => l10n('conf_history_title'),
190    'url' => $conf_link.'history'
191   ),
192  'comments' => array
193   (
194    'caption' => l10n('conf_comments_title'),
195    'url' => $conf_link.'comments'
196   ),
197  'default' => array
198   (
199    'caption' => l10n('conf_display'),
200    'url' => $conf_link.'default'
201   )
202);
203
204$page['tabsheet'][$page['section']]['selected'] = true;
205
206// Assign tabsheet to template
207template_assign_tabsheet();
208
209$action = PHPWG_ROOT_PATH.'admin.php?page=configuration';
210$action.= '&amp;section='.$page['section'];
211
212$template->assign_vars(
213  array(
214    'L_YES'=>$lang['yes'],
215    'L_NO'=>$lang['no'],
216    'L_SUBMIT'=>$lang['submit'],
217    'L_RESET'=>$lang['reset'],
218
219    'U_HELP' => PHPWG_ROOT_PATH.'popuphelp.php?page=configuration',
220
221    'F_ACTION'=>$action
222    ));
223
224$html_check='checked="checked"';
225
226switch ($page['section'])
227{
228  case 'main' :
229  {
230    $lock_yes = ($conf['gallery_locked']==true)?'checked="checked"':'';
231    $lock_no = ($conf['gallery_locked']==false)?'checked="checked"':'';
232
233    $template->assign_block_vars(
234      'main',
235      array(
236        'GALLERY_LOCKED_YES'=>$lock_yes,
237        'GALLERY_LOCKED_NO'=>$lock_no,
238        'CONF_GALLERY_TITLE' => $conf['gallery_title'],
239        'CONF_PAGE_BANNER' => $conf['page_banner'],
240        'CONF_GALLERY_URL' => $conf['gallery_url'],
241        ));
242
243    foreach( $main_checkboxes as $checkbox)
244    {
245      $template->merge_block_vars(
246          'main',
247          array(
248            strtoupper($checkbox) => ($conf[$checkbox]==true)?$html_check:''
249            )
250        );
251    }
252    break;
253  }
254  case 'history' :
255  {
256    //Necessary for merge_block_vars
257    $template->assign_block_vars('history', array());
258
259    foreach( $history_checkboxes as $checkbox)
260    {
261      $template->merge_block_vars(
262          'history',
263          array(
264            strtoupper($checkbox) => ($conf[$checkbox]==true)?$html_check:''
265            )
266        );
267    }
268    break;
269  }
270  case 'comments' :
271  {
272    $template->assign_block_vars(
273      'comments',
274      array(
275        'NB_COMMENTS_PAGE'=>$conf['nb_comment_page'],
276        ));
277
278    foreach( $comments_checkboxes as $checkbox)
279    {
280      $template->merge_block_vars(
281          'comments',
282          array(
283            strtoupper($checkbox) => ($conf[$checkbox]==true)?$html_check:''
284            )
285        );
286    }
287    break;
288  }
289  case 'default' :
290  {
291    $show_yes = ($conf['show_nb_comments']==true)?'checked="checked"':'';
292    $show_no = ($conf['show_nb_comments']==false)?'checked="checked"':'';
293    $hits_yes = ($conf['show_nb_hits']==true)?'checked="checked"':'';
294    $hits_no = ($conf['show_nb_hits']==false)?'checked="checked"':'';
295    $expand_yes = ($conf['auto_expand']==true)?'checked="checked"':'';
296    $expand_no  = ($conf['auto_expand']==false)?'checked="checked"':'';
297
298    $template->assign_block_vars(
299      'default',
300      array(
301        'NB_IMAGE_LINE'=>$conf['nb_image_line'],
302        'NB_ROW_PAGE'=>$conf['nb_line_page'],
303        'CONF_RECENT'=>$conf['recent_period'],
304        'NB_COMMENTS_PAGE'=>$conf['nb_comment_page'],
305        'MAXWIDTH'=>$conf['default_maxwidth'],
306        'MAXHEIGHT'=>$conf['default_maxheight'],
307        'EXPAND_YES'=>$expand_yes,
308        'EXPAND_NO'=>$expand_no,
309        'SHOW_COMMENTS_YES'=>$show_yes,
310        'SHOW_COMMENTS_NO'=>$show_no,
311        'SHOW_HITS_YES'=>$hits_yes,
312        'SHOW_HITS_NO'=>$hits_no,
313        ));
314
315    $blockname = 'default.language_option';
316
317    foreach (get_languages() as $language_code => $language_name)
318    {
319      if (isset($_POST['submit']))
320      {
321        $selected =
322          $_POST['default_language'] == $language_code
323            ? 'selected="selected"' : '';
324      }
325      else if ($conf['default_language'] == $language_code)
326      {
327        $selected = 'selected="selected"';
328      }
329      else
330      {
331        $selected = '';
332      }
333
334      $template->assign_block_vars(
335        $blockname,
336        array(
337          'VALUE'=> $language_code,
338          'CONTENT' => $language_name,
339          'SELECTED' => $selected
340          ));
341    }
342
343    $blockname = 'default.template_option';
344
345    foreach (get_pwg_themes() as $pwg_template)
346    {
347      if (isset($_POST['submit']))
348      {
349        $selected =
350          $_POST['default_template'] == $pwg_template
351            ? 'selected="selected"' : '';
352      }
353      else if ($conf['default_template'] == $pwg_template)
354      {
355        $selected = 'selected="selected"';
356      }
357      else
358      {
359        $selected = '';
360      }
361
362      $template->assign_block_vars(
363        $blockname,
364        array(
365          'VALUE'=> $pwg_template,
366          'CONTENT' => $pwg_template,
367          'SELECTED' => $selected
368          )
369        );
370    }
371
372
373    break;
374  }
375}
376//----------------------------------------------------------- sending html code
377$template->assign_var_from_handle('ADMIN_CONTENT', 'config');
378?>
Note: See TracBrowser for help on using the repository browser.