source: trunk/admin/configuration.php @ 2032

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

Resolved issue 0000489: Mail address obligatory

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 8.4 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-06-10 22:01:18 +0000 (Sun, 10 Jun 2007) $
10// | last modifier : $Author: rub $
11// | revision      : $Revision: 2032 $
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    'allow_user_registration',
53    'obligatory_user_mail_address',
54    'rate',
55    'rate_anonymous',
56    'email_admin_on_new_user',
57    'email_admin_on_picture_uploaded',
58   );
59
60$history_checkboxes = array(
61    'log',
62    'history_admin',
63    'history_guest'
64   );
65
66$comments_checkboxes = array(
67    'comments_forall',
68    'comments_validation',
69    'email_admin_on_comment',
70    'email_admin_on_comment_validation',
71  );
72
73//------------------------------ verification and registration of modifications
74if (isset($_POST['submit']) and !is_adviser())
75{
76  $int_pattern = '/^\d+$/';
77
78  switch ($page['section'])
79  {
80    case 'main' :
81    {
82      if ( !url_is_remote($_POST['gallery_url']) )
83      {
84        array_push($page['errors'], $lang['conf_gallery_url_error']);
85      }
86      foreach( $main_checkboxes as $checkbox)
87      {
88        $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
89      }
90      break;
91    }
92    case 'history' :
93    {
94      foreach( $history_checkboxes as $checkbox)
95      {
96        $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
97      }
98      break;
99    }
100    case 'comments' :
101    {
102      // the number of comments per page must be an integer between 5 and 50
103      // included
104      if (!preg_match($int_pattern, $_POST['nb_comment_page'])
105           or $_POST['nb_comment_page'] < 5
106           or $_POST['nb_comment_page'] > 50)
107      {
108        array_push($page['errors'], $lang['conf_nb_comment_page_error']);
109      }
110      foreach( $comments_checkboxes as $checkbox)
111      {
112        $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
113      }
114      break;
115    }
116    case 'default' :
117    {
118      // Never go here
119      break;
120    }
121  }
122
123  // updating configuration if no error found
124  if (count($page['errors']) == 0)
125  {
126    //echo '<pre>'; print_r($_POST); echo '</pre>';
127    $result = pwg_query('SELECT param FROM '.CONFIG_TABLE);
128    while ($row = mysql_fetch_array($result))
129    {
130      if (isset($_POST[$row['param']]))
131      {
132        $value = $_POST[$row['param']];
133
134        if ('gallery_title' == $row['param'])
135        {
136          if (!$conf['allow_html_descriptions'])
137          {
138            $value = strip_tags($value);
139          }
140        }
141
142        $query = '
143UPDATE '.CONFIG_TABLE.'
144SET value = \''. str_replace("\'", "''", $value).'\'
145WHERE param = \''.$row['param'].'\'
146;';
147        pwg_query($query);
148      }
149    }
150    array_push($page['infos'], $lang['conf_confirmation']);
151  }
152
153  //------------------------------------------------------ $conf reinitialization
154  load_conf_from_db();
155}
156
157//----------------------------------------------------- template initialization
158$template->set_filename('config', 'admin/configuration.tpl');
159
160// TabSheet initialization
161$page['tabsheet'] = array
162(
163  'main' => array
164   (
165    'caption' => l10n('conf_main_title'),
166    'url' => $conf_link.'main'
167   ),
168  'history' => array
169   (
170    'caption' => l10n('conf_history_title'),
171    'url' => $conf_link.'history'
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_display'),
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
207$include_submit_buttons = true;
208
209switch ($page['section'])
210{
211  case 'main' :
212  {
213    $lock_yes = ($conf['gallery_locked']==true)?'checked="checked"':'';
214    $lock_no = ($conf['gallery_locked']==false)?'checked="checked"':'';
215
216    $template->assign_block_vars(
217      'main',
218      array(
219        'GALLERY_LOCKED_YES'=>$lock_yes,
220        'GALLERY_LOCKED_NO'=>$lock_no,
221        'CONF_GALLERY_TITLE' => htmlspecialchars($conf['gallery_title']),
222        'CONF_PAGE_BANNER' => htmlspecialchars($conf['page_banner']),
223        'CONF_GALLERY_URL' => $conf['gallery_url'],
224        ));
225
226    foreach( $main_checkboxes as $checkbox)
227    {
228      $template->merge_block_vars(
229          'main',
230          array(
231            strtoupper($checkbox) => ($conf[$checkbox]==true)?$html_check:''
232            )
233        );
234    }
235    break;
236  }
237  case 'history' :
238  {
239    //Necessary for merge_block_vars
240    $template->assign_block_vars('history', array());
241
242    foreach( $history_checkboxes as $checkbox)
243    {
244      $template->merge_block_vars(
245          'history',
246          array(
247            strtoupper($checkbox) => ($conf[$checkbox]==true)?$html_check:''
248            )
249        );
250    }
251    break;
252  }
253  case 'comments' :
254  {
255    $template->assign_block_vars(
256      'comments',
257      array(
258        'NB_COMMENTS_PAGE'=>$conf['nb_comment_page'],
259        ));
260
261    foreach( $comments_checkboxes as $checkbox)
262    {
263      $template->merge_block_vars(
264          'comments',
265          array(
266            strtoupper($checkbox) => ($conf[$checkbox]==true)?$html_check:''
267            )
268        );
269    }
270    break;
271  }
272  case 'default' :
273  {
274    $edit_user = build_user($conf['default_user_id'], false);
275    include_once(PHPWG_ROOT_PATH.'profile.php');
276
277    $errors = array();
278    if ( !is_adviser() )
279    {
280      if (save_profile_from_post($edit_user, $errors))
281      {
282        // Reload user
283        $edit_user = build_user($conf['default_user_id'], false);
284        array_push($page['infos'], $lang['conf_confirmation']);
285      }
286    }
287    $page['errors'] = array_merge($page['errors'], $errors);
288
289    load_profile_in_template(
290      $action,
291      '',
292      $edit_user
293      );
294    $template->assign_block_vars('default', array());
295    $include_submit_buttons = false;
296    break;
297  }
298}
299
300if ($include_submit_buttons)
301{
302  $template->assign_block_vars('include_submit_buttons', array());
303}
304
305//----------------------------------------------------------- sending html code
306$template->assign_var_from_handle('ADMIN_CONTENT', 'config');
307?>
Note: See TracBrowser for help on using the repository browser.