source: trunk/admin/configuration.php @ 1865

Last change on this file since 1865 was 1865, checked in by rvelices, 17 years ago

admin pages: merge Categories/comments page into Configuration/comments page
(they are related and we reduce the # of links in the menu)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.6 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-02-28 00:16:53 +0000 (Wed, 28 Feb 2007) $
10// | last modifier : $Author: rvelices $
11// | revision      : $Revision: 1865 $
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');
34
35// +-----------------------------------------------------------------------+
36// | Check Access and exit when user status is not ok                      |
37// +-----------------------------------------------------------------------+
38check_status(ACCESS_ADMINISTRATOR);
39
40//-------------------------------------------------------- sections definitions
41if (!isset($_GET['section']))
42{
43  $page['section'] = 'general';
44}
45else
46{
47  $page['section'] = $_GET['section'];
48}
49
50$general_checkboxes = array(
51    'log',
52    'history_admin',
53    'history_guest',
54    'email_admin_on_new_user',
55    'allow_user_registration',
56   );
57
58$comments_checkboxes = array(
59    'comments_forall',
60    'comments_validation',
61    'email_admin_on_comment',
62    'email_admin_on_comment_validation',
63  );
64
65//------------------------------ verification and registration of modifications
66if (isset($_POST['submit']) and !is_adviser())
67{
68  $int_pattern = '/^\d+$/';
69  switch ($page['section'])
70  {
71    case 'general' :
72    {
73      if ( !url_is_remote($_POST['gallery_url']) )
74      {
75        array_push($page['errors'], $lang['conf_gallery_url_error']);
76      }
77      foreach( $general_checkboxes as $checkbox)
78      {
79        $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
80      }
81      break;
82    }
83    case 'comments' :
84    {
85      // the number of comments per page must be an integer between 5 and 50
86      // included
87      if (!preg_match($int_pattern, $_POST['nb_comment_page'])
88           or $_POST['nb_comment_page'] < 5
89           or $_POST['nb_comment_page'] > 50)
90      {
91        array_push($page['errors'], $lang['conf_nb_comment_page_error']);
92      }
93      foreach( $comments_checkboxes as $checkbox)
94      {
95        $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
96      }
97      break;
98    }
99    case 'default' :
100    {
101      // periods must be integer values, they represents number of days
102      if (!preg_match($int_pattern, $_POST['recent_period'])
103          or $_POST['recent_period'] <= 0)
104      {
105        array_push($page['errors'], $lang['periods_error']);
106      }
107      // maxwidth
108      if (isset($_POST['default_maxwidth'])
109          and !empty($_POST['default_maxwidth'])
110          and (!preg_match($int_pattern, $_POST['default_maxwidth'])
111               or $_POST['default_maxwidth'] < 50))
112      {
113        array_push($page['errors'], $lang['maxwidth_error']);
114      }
115      // maxheight
116      if (isset($_POST['default_maxheight'])
117          and !empty($_POST['default_maxheight'])
118          and (!preg_match($int_pattern, $_POST['default_maxheight'])
119               or $_POST['default_maxheight'] < 50))
120      {
121        array_push($page['errors'], $lang['maxheight_error']);
122      }
123      break;
124    }
125  }
126
127  // updating configuration if no error found
128  if (count($page['errors']) == 0)
129  {
130    //echo '<pre>'; print_r($_POST); echo '</pre>';
131    $result = pwg_query('SELECT param FROM '.CONFIG_TABLE);
132    while ($row = mysql_fetch_array($result))
133    {
134      if (isset($_POST[$row['param']]))
135      {
136        $value = $_POST[$row['param']];
137
138        if ('gallery_title' == $row['param'])
139        {
140          if (!$conf['allow_html_descriptions'])
141          {
142            $value = strip_tags($value);
143          }
144        }
145
146        $query = '
147UPDATE '.CONFIG_TABLE.'
148  SET value = \''. str_replace("\'", "''", $value).'\'
149  WHERE param = \''.$row['param'].'\'
150;';
151        pwg_query($query);
152      }
153    }
154    array_push($page['infos'], $lang['conf_confirmation']);
155  }
156
157  //------------------------------------------------------ $conf reinitialization
158  load_conf_from_db();
159}
160
161if ( $page['section']=='comments' and !is_adviser() )
162{
163  if (isset($_POST['falsify'])
164      and isset($_POST['cat_true'])
165      and count($_POST['cat_true']) > 0)
166  {
167      $query = '
168UPDATE '.CATEGORIES_TABLE.'
169  SET commentable = \'false\'
170  WHERE id IN ('.implode(',', $_POST['cat_true']).')
171;';
172      pwg_query($query);
173  }
174  if (isset($_POST['trueify'])
175         and isset($_POST['cat_false'])
176         and count($_POST['cat_false']) > 0)
177  {
178      $query = '
179UPDATE '.CATEGORIES_TABLE.'
180  SET commentable = \'true\'
181  WHERE id IN ('.implode(',', $_POST['cat_false']).')
182;';
183      pwg_query($query);
184  }
185}
186
187//----------------------------------------------------- template initialization
188$template->set_filenames( array('config'=>'admin/configuration.tpl') );
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   
256    $query_true = '
257SELECT id,name,uppercats,global_rank
258  FROM '.CATEGORIES_TABLE.'
259  WHERE commentable = \'true\'
260;';
261    $query_false = '
262SELECT id,name,uppercats,global_rank
263  FROM '.CATEGORIES_TABLE.'
264  WHERE commentable = \'false\'
265;';
266    display_select_cat_wrapper($query_true,array(),'comments.category_option_true');
267    display_select_cat_wrapper($query_false,array(),'comments.category_option_false');
268    break;
269  }
270  case 'default' :
271  {
272    $show_yes = ($conf['show_nb_comments']==true)?'checked="checked"':'';
273    $show_no = ($conf['show_nb_comments']==false)?'checked="checked"':'';
274    $hits_yes = ($conf['show_nb_hits']==true)?'checked="checked"':'';
275    $hits_no = ($conf['show_nb_hits']==false)?'checked="checked"':'';
276    $expand_yes = ($conf['auto_expand']==true)?'checked="checked"':'';
277    $expand_no  = ($conf['auto_expand']==false)?'checked="checked"':'';
278
279    $template->assign_block_vars(
280      'default',
281      array(
282        'NB_IMAGE_LINE'=>$conf['nb_image_line'],
283        'NB_ROW_PAGE'=>$conf['nb_line_page'],
284        'CONF_RECENT'=>$conf['recent_period'],
285        'NB_COMMENTS_PAGE'=>$conf['nb_comment_page'],
286        'MAXWIDTH'=>$conf['default_maxwidth'],
287        'MAXHEIGHT'=>$conf['default_maxheight'],
288        'EXPAND_YES'=>$expand_yes,
289        'EXPAND_NO'=>$expand_no,
290        'SHOW_COMMENTS_YES'=>$show_yes,
291        'SHOW_COMMENTS_NO'=>$show_no,
292        'SHOW_HITS_YES'=>$hits_yes,
293        'SHOW_HITS_NO'=>$hits_no,
294        ));
295
296    $blockname = 'default.language_option';
297
298    foreach (get_languages() as $language_code => $language_name)
299    {
300      if (isset($_POST['submit']))
301      {
302        $selected =
303          $_POST['default_language'] == $language_code
304            ? 'selected="selected"' : '';
305      }
306      else if ($conf['default_language'] == $language_code)
307      {
308        $selected = 'selected="selected"';
309      }
310      else
311      {
312        $selected = '';
313      }
314
315      $template->assign_block_vars(
316        $blockname,
317        array(
318          'VALUE'=> $language_code,
319          'CONTENT' => $language_name,
320          'SELECTED' => $selected
321          ));
322    }
323
324    $blockname = 'default.template_option';
325
326    foreach (get_pwg_themes() as $pwg_template)
327    {
328      if (isset($_POST['submit']))
329      {
330        $selected =
331          $_POST['default_template'] == $pwg_template
332            ? 'selected="selected"' : '';
333      }
334      else if ($conf['default_template'] == $pwg_template)
335      {
336        $selected = 'selected="selected"';
337      }
338      else
339      {
340        $selected = '';
341      }
342
343      $template->assign_block_vars(
344        $blockname,
345        array(
346          'VALUE'=> $pwg_template,
347          'CONTENT' => $pwg_template,
348          'SELECTED' => $selected
349          )
350        );
351    }
352
353
354    break;
355  }
356}
357//----------------------------------------------------------- sending html code
358$template->assign_var_from_handle('ADMIN_CONTENT', 'config');
359?>
Note: See TracBrowser for help on using the repository browser.