source: trunk/admin/configuration.php @ 1926

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

Issue 578
User guest must be real user

Step 1: guest is a real user

On next commit, I finish installation and use of guest of user list and group

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 8.3 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-28 19:57:00 +0000 (Wed, 28 Mar 2007) $
10// | last modifier : $Author: rub $
11// | revision      : $Revision: 1926 $
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
77  switch ($page['section'])
78  {
79    case 'main' :
80    {
81      if ( !url_is_remote($_POST['gallery_url']) )
82      {
83        array_push($page['errors'], $lang['conf_gallery_url_error']);
84      }
85      foreach( $main_checkboxes as $checkbox)
86      {
87        $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
88      }
89      break;
90    }
91    case 'history' :
92    {
93      foreach( $history_checkboxes as $checkbox)
94      {
95        $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
96      }
97      break;
98    }
99    case 'comments' :
100    {
101      // the number of comments per page must be an integer between 5 and 50
102      // included
103      if (!preg_match($int_pattern, $_POST['nb_comment_page'])
104           or $_POST['nb_comment_page'] < 5
105           or $_POST['nb_comment_page'] > 50)
106      {
107        array_push($page['errors'], $lang['conf_nb_comment_page_error']);
108      }
109      foreach( $comments_checkboxes as $checkbox)
110      {
111        $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
112      }
113      break;
114    }
115    case 'default' :
116    {
117      // Never go here
118      break;
119    }
120  }
121
122  // updating configuration if no error found
123  if (count($page['errors']) == 0)
124  {
125    //echo '<pre>'; print_r($_POST); echo '</pre>';
126    $result = pwg_query('SELECT param FROM '.CONFIG_TABLE);
127    while ($row = mysql_fetch_array($result))
128    {
129      if (isset($_POST[$row['param']]))
130      {
131        $value = $_POST[$row['param']];
132
133        if ('gallery_title' == $row['param'])
134        {
135          if (!$conf['allow_html_descriptions'])
136          {
137            $value = strip_tags($value);
138          }
139        }
140
141        $query = '
142UPDATE '.CONFIG_TABLE.'
143SET value = \''. str_replace("\'", "''", $value).'\'
144WHERE param = \''.$row['param'].'\'
145;';
146        pwg_query($query);
147      }
148    }
149    array_push($page['infos'], $lang['conf_confirmation']);
150  }
151
152  //------------------------------------------------------ $conf reinitialization
153  load_conf_from_db();
154}
155
156//----------------------------------------------------- template initialization
157$template->set_filename('config', 'admin/configuration.tpl');
158
159// TabSheet initialization
160$page['tabsheet'] = array
161(
162  'main' => array
163   (
164    'caption' => l10n('conf_main_title'),
165    'url' => $conf_link.'main'
166   ),
167  'history' => array
168   (
169    'caption' => l10n('conf_history_title'),
170    'url' => $conf_link.'history'
171   ),
172  'comments' => array
173   (
174    'caption' => l10n('conf_comments_title'),
175    'url' => $conf_link.'comments'
176   ),
177  'default' => array
178   (
179    'caption' => l10n('conf_display'),
180    'url' => $conf_link.'default'
181   )
182);
183
184$page['tabsheet'][$page['section']]['selected'] = true;
185
186// Assign tabsheet to template
187template_assign_tabsheet();
188
189$action = PHPWG_ROOT_PATH.'admin.php?page=configuration';
190$action.= '&amp;section='.$page['section'];
191
192$template->assign_vars(
193  array(
194    'L_YES'=>$lang['yes'],
195    'L_NO'=>$lang['no'],
196    'L_SUBMIT'=>$lang['submit'],
197    'L_RESET'=>$lang['reset'],
198
199    'U_HELP' => PHPWG_ROOT_PATH.'popuphelp.php?page=configuration',
200
201    'F_ACTION'=>$action
202    ));
203
204$html_check='checked="checked"';
205
206$include_submit_buttons = true;
207
208switch ($page['section'])
209{
210  case 'main' :
211  {
212    $lock_yes = ($conf['gallery_locked']==true)?'checked="checked"':'';
213    $lock_no = ($conf['gallery_locked']==false)?'checked="checked"':'';
214
215    $template->assign_block_vars(
216      'main',
217      array(
218        'GALLERY_LOCKED_YES'=>$lock_yes,
219        'GALLERY_LOCKED_NO'=>$lock_no,
220        'CONF_GALLERY_TITLE' => $conf['gallery_title'],
221        'CONF_PAGE_BANNER' => $conf['page_banner'],
222        'CONF_GALLERY_URL' => $conf['gallery_url'],
223        ));
224
225    foreach( $main_checkboxes as $checkbox)
226    {
227      $template->merge_block_vars(
228          'main',
229          array(
230            strtoupper($checkbox) => ($conf[$checkbox]==true)?$html_check:''
231            )
232        );
233    }
234    break;
235  }
236  case 'history' :
237  {
238    //Necessary for merge_block_vars
239    $template->assign_block_vars('history', array());
240
241    foreach( $history_checkboxes as $checkbox)
242    {
243      $template->merge_block_vars(
244          'history',
245          array(
246            strtoupper($checkbox) => ($conf[$checkbox]==true)?$html_check:''
247            )
248        );
249    }
250    break;
251  }
252  case 'comments' :
253  {
254    $template->assign_block_vars(
255      'comments',
256      array(
257        'NB_COMMENTS_PAGE'=>$conf['nb_comment_page'],
258        ));
259
260    foreach( $comments_checkboxes as $checkbox)
261    {
262      $template->merge_block_vars(
263          'comments',
264          array(
265            strtoupper($checkbox) => ($conf[$checkbox]==true)?$html_check:''
266            )
267        );
268    }
269    break;
270  }
271  case 'default' :
272  {
273    $edit_user = build_user($conf['default_user_id'], false);
274    include_once(PHPWG_ROOT_PATH.'profile.php');
275
276    $errors = array();
277    if ( !is_adviser() )
278    {
279      if (save_profile_from_post($edit_user, $errors))
280      {
281        // Reload user
282        $edit_user = build_user($conf['default_user_id'], false);
283        array_push($page['infos'], $lang['conf_confirmation']);
284      }
285    }
286    $page['errors'] = array_merge($page['errors'], $errors);
287
288    load_profile_in_template(
289      $action,
290      '',
291      $edit_user
292      );
293    $template->assign_block_vars('default', array());
294    $include_submit_buttons = false;
295    break;
296  }
297}
298
299if ($include_submit_buttons)
300{
301  $template->assign_block_vars('include_submit_buttons', array());
302}
303
304//----------------------------------------------------------- sending html code
305$template->assign_var_from_handle('ADMIN_CONTENT', 'config');
306?>
Note: See TracBrowser for help on using the repository browser.