source: trunk/admin/configuration.php @ 2226

Last change on this file since 2226 was 2226, checked in by rub, 16 years ago

0000809: Use more php classes implementation

Use class for tabsheet like grum class
Change way for tabsheet

  • 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-2008 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $RCSfile$
9// | last update   : $Date: 2008-02-28 23:41:47 +0000 (Thu, 28 Feb 2008) $
10// | last modifier : $Author: rub $
11// | revision      : $Revision: 2226 $
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/tabsheet.class.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'], l10n('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'], l10n('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'], l10n('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
161$tabsheet = new tabsheet();
162// TabSheet initialization
163$tabsheet->add('main', l10n('conf_main_title'), $conf_link.'main');
164$tabsheet->add('history', l10n('conf_history_title'), $conf_link.'history');
165$tabsheet->add('comments', l10n('conf_comments_title'), $conf_link.'comments');
166$tabsheet->add('default', l10n('conf_display'), $conf_link.'default');
167// TabSheet selection
168$tabsheet->select($page['section']);
169// Assign tabsheet to template
170$tabsheet->assign();
171
172$action = PHPWG_ROOT_PATH.'admin.php?page=configuration';
173$action.= '&amp;section='.$page['section'];
174
175$template->assign_vars(
176  array(
177    'L_YES'=>l10n('yes'),
178    'L_NO'=>l10n('no'),
179    'L_SUBMIT'=>l10n('submit'),
180    'L_RESET'=>l10n('reset'),
181
182    'U_HELP' => PHPWG_ROOT_PATH.'popuphelp.php?page=configuration',
183
184    'F_ACTION'=>$action
185    ));
186
187$html_check='checked="checked"';
188
189$include_submit_buttons = true;
190
191switch ($page['section'])
192{
193  case 'main' :
194  {
195    $lock_yes = ($conf['gallery_locked']==true)?'checked="checked"':'';
196    $lock_no = ($conf['gallery_locked']==false)?'checked="checked"':'';
197
198    $template->assign_block_vars(
199      'main',
200      array(
201        'GALLERY_LOCKED_YES'=>$lock_yes,
202        'GALLERY_LOCKED_NO'=>$lock_no,
203        'CONF_GALLERY_TITLE' => htmlspecialchars($conf['gallery_title']),
204        'CONF_PAGE_BANNER' => htmlspecialchars($conf['page_banner']),
205        'CONF_GALLERY_URL' => $conf['gallery_url'],
206        ));
207
208    foreach( $main_checkboxes as $checkbox)
209    {
210      $template->merge_block_vars(
211          'main',
212          array(
213            strtoupper($checkbox) => ($conf[$checkbox]==true)?$html_check:''
214            )
215        );
216    }
217    break;
218  }
219  case 'history' :
220  {
221    //Necessary for merge_block_vars
222    $template->assign_block_vars('history', array());
223
224    foreach( $history_checkboxes as $checkbox)
225    {
226      $template->merge_block_vars(
227          'history',
228          array(
229            strtoupper($checkbox) => ($conf[$checkbox]==true)?$html_check:''
230            )
231        );
232    }
233    break;
234  }
235  case 'comments' :
236  {
237    $template->assign_block_vars(
238      'comments',
239      array(
240        'NB_COMMENTS_PAGE'=>$conf['nb_comment_page'],
241        ));
242
243    foreach( $comments_checkboxes as $checkbox)
244    {
245      $template->merge_block_vars(
246          'comments',
247          array(
248            strtoupper($checkbox) => ($conf[$checkbox]==true)?$html_check:''
249            )
250        );
251    }
252    break;
253  }
254  case 'default' :
255  {
256    $edit_user = build_user($conf['default_user_id'], false);
257    include_once(PHPWG_ROOT_PATH.'profile.php');
258
259    $errors = array();
260    if ( !is_adviser() )
261    {
262      if (save_profile_from_post($edit_user, $errors))
263      {
264        // Reload user
265        $edit_user = build_user($conf['default_user_id'], false);
266        array_push($page['infos'], l10n('conf_confirmation'));
267      }
268    }
269    $page['errors'] = array_merge($page['errors'], $errors);
270
271    load_profile_in_template(
272      $action,
273      '',
274      $edit_user
275      );
276    $template->assign_block_vars('default', array());
277    $include_submit_buttons = false;
278    break;
279  }
280}
281
282if ($include_submit_buttons)
283{
284  $template->assign_block_vars('include_submit_buttons', array());
285}
286
287//----------------------------------------------------------- sending html code
288$template->assign_var_from_handle('ADMIN_CONTENT', 'config');
289?>
Note: See TracBrowser for help on using the repository browser.