source: trunk/admin/configuration.php @ 1884

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

Add DateTime on administration introduction page (Useful to help user on the forum, ...)
Move history configuration in a other tab.
Use translation on picture hint (Kb).
Show hint oh the menu text (not only on counter)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.8 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-09 22:52:22 +0000 (Fri, 09 Mar 2007) $
10// | last modifier : $Author: rub $
11// | revision      : $Revision: 1884 $
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    'email_admin_on_new_user',
53    'allow_user_registration',
54   );
55
56$history_checkboxes = array(
57    'log',
58    'history_admin',
59    'history_guest'
60   );
61
62$comments_checkboxes = array(
63    'comments_forall',
64    'comments_validation',
65    'email_admin_on_comment',
66    'email_admin_on_comment_validation',
67  );
68
69//------------------------------ verification and registration of modifications
70if (isset($_POST['submit']) and !is_adviser())
71{
72  $int_pattern = '/^\d+$/';
73  switch ($page['section'])
74  {
75    case 'general' :
76    {
77      if ( !url_is_remote($_POST['gallery_url']) )
78      {
79        array_push($page['errors'], $lang['conf_gallery_url_error']);
80      }
81      foreach( $general_checkboxes as $checkbox)
82      {
83        $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
84      }
85      break;
86    }
87    case 'history' :
88    {
89      foreach( $history_checkboxes as $checkbox)
90      {
91        $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
92      }
93      break;
94    }
95    case 'comments' :
96    {
97      // the number of comments per page must be an integer between 5 and 50
98      // included
99      if (!preg_match($int_pattern, $_POST['nb_comment_page'])
100           or $_POST['nb_comment_page'] < 5
101           or $_POST['nb_comment_page'] > 50)
102      {
103        array_push($page['errors'], $lang['conf_nb_comment_page_error']);
104      }
105      foreach( $comments_checkboxes as $checkbox)
106      {
107        $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
108      }
109      break;
110    }
111    case 'default' :
112    {
113      // periods must be integer values, they represents number of days
114      if (!preg_match($int_pattern, $_POST['recent_period'])
115          or $_POST['recent_period'] <= 0)
116      {
117        array_push($page['errors'], $lang['periods_error']);
118      }
119      // maxwidth
120      if (isset($_POST['default_maxwidth'])
121          and !empty($_POST['default_maxwidth'])
122          and (!preg_match($int_pattern, $_POST['default_maxwidth'])
123               or $_POST['default_maxwidth'] < 50))
124      {
125        array_push($page['errors'], $lang['maxwidth_error']);
126      }
127      // maxheight
128      if (isset($_POST['default_maxheight'])
129          and !empty($_POST['default_maxheight'])
130          and (!preg_match($int_pattern, $_POST['default_maxheight'])
131               or $_POST['default_maxheight'] < 50))
132      {
133        array_push($page['errors'], $lang['maxheight_error']);
134      }
135      break;
136    }
137  }
138
139  // updating configuration if no error found
140  if (count($page['errors']) == 0)
141  {
142    //echo '<pre>'; print_r($_POST); echo '</pre>';
143    $result = pwg_query('SELECT param FROM '.CONFIG_TABLE);
144    while ($row = mysql_fetch_array($result))
145    {
146      if (isset($_POST[$row['param']]))
147      {
148        $value = $_POST[$row['param']];
149
150        if ('gallery_title' == $row['param'])
151        {
152          if (!$conf['allow_html_descriptions'])
153          {
154            $value = strip_tags($value);
155          }
156        }
157
158        $query = '
159UPDATE '.CONFIG_TABLE.'
160  SET value = \''. str_replace("\'", "''", $value).'\'
161  WHERE param = \''.$row['param'].'\'
162;';
163        pwg_query($query);
164      }
165    }
166    array_push($page['infos'], $lang['conf_confirmation']);
167  }
168
169  //------------------------------------------------------ $conf reinitialization
170  load_conf_from_db();
171}
172
173//----------------------------------------------------- template initialization
174$template->set_filename('config', 'admin/configuration.tpl');
175
176// TabSheet initialization
177$page['tabsheet'] = array
178(
179  'general' => array
180   (
181    'caption' => l10n('conf_general_title'),
182    'url' => $conf_link.'general'
183   ),
184  'history' => array
185   (
186    'caption' => l10n('conf_history_title'),
187    'url' => $conf_link.'history'
188   ),
189  'comments' => array
190   (
191    'caption' => l10n('conf_comments_title'),
192    'url' => $conf_link.'comments'
193   ),
194  'default' => array
195   (
196    'caption' => l10n('conf_default'),
197    'url' => $conf_link.'default'
198   )
199);
200
201$page['tabsheet'][$page['section']]['selected'] = true;
202
203// Assign tabsheet to template
204template_assign_tabsheet();
205
206$action = PHPWG_ROOT_PATH.'admin.php?page=configuration';
207$action.= '&amp;section='.$page['section'];
208
209$template->assign_vars(
210  array(
211    'L_YES'=>$lang['yes'],
212    'L_NO'=>$lang['no'],
213    'L_SUBMIT'=>$lang['submit'],
214    'L_RESET'=>$lang['reset'],
215
216    'U_HELP' => PHPWG_ROOT_PATH.'popuphelp.php?page=configuration',
217
218    'F_ACTION'=>$action
219    ));
220
221$html_check='checked="checked"';
222
223switch ($page['section'])
224{
225  case 'general' :
226  {
227    $lock_yes = ($conf['gallery_locked']==true)?'checked="checked"':'';
228    $lock_no = ($conf['gallery_locked']==false)?'checked="checked"':'';
229
230    $template->assign_block_vars(
231      'general',
232      array(
233        'GALLERY_LOCKED_YES'=>$lock_yes,
234        'GALLERY_LOCKED_NO'=>$lock_no,
235        ($conf['rate']==true?'RATE_YES':'RATE_NO')=>$html_check,
236        ($conf['rate_anonymous']==true
237             ? 'RATE_ANONYMOUS_YES' : 'RATE_ANONYMOUS_NO')=>$html_check,
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( $general_checkboxes as $checkbox)
244    {
245      $template->merge_block_vars(
246          'general',
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.