source: trunk/admin/configuration.php @ 2249

Last change on this file since 2249 was 2249, checked in by rvelices, 16 years ago
  • admin comments, configuration, element_set_global, element_set_unit, thumbnail and double_select migration to smarty
  • fix in redirect.tpl
  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 7.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-2008 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $RCSfile$
9// | last update   : $Date: 2008-03-05 01:50:08 +0000 (Wed, 05 Mar 2008) $
10// | last modifier : $Author: rvelices $
11// | revision      : $Revision: 2249 $
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    'gallery_locked',
53    'allow_user_registration',
54    'obligatory_user_mail_address',
55    'rate',
56    'rate_anonymous',
57    'email_admin_on_new_user',
58    'email_admin_on_picture_uploaded',
59   );
60
61$history_checkboxes = array(
62    'log',
63    'history_admin',
64    'history_guest'
65   );
66
67$comments_checkboxes = array(
68    'comments_forall',
69    'comments_validation',
70    'email_admin_on_comment',
71    'email_admin_on_comment_validation',
72  );
73
74//------------------------------ verification and registration of modifications
75if (isset($_POST['submit']) and !is_adviser())
76{
77  $int_pattern = '/^\d+$/';
78
79  switch ($page['section'])
80  {
81    case 'main' :
82    {
83      if ( !url_is_remote($_POST['gallery_url']) )
84      {
85        array_push($page['errors'], l10n('conf_gallery_url_error'));
86      }
87      foreach( $main_checkboxes as $checkbox)
88      {
89        $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
90      }
91      break;
92    }
93    case 'history' :
94    {
95      foreach( $history_checkboxes as $checkbox)
96      {
97        $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
98      }
99      break;
100    }
101    case 'comments' :
102    {
103      // the number of comments per page must be an integer between 5 and 50
104      // included
105      if (!preg_match($int_pattern, $_POST['nb_comment_page'])
106           or $_POST['nb_comment_page'] < 5
107           or $_POST['nb_comment_page'] > 50)
108      {
109        array_push($page['errors'], l10n('conf_nb_comment_page_error'));
110      }
111      foreach( $comments_checkboxes as $checkbox)
112      {
113        $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
114      }
115      break;
116    }
117    case 'default' :
118    {
119      // Never go here
120      break;
121    }
122  }
123
124  // updating configuration if no error found
125  if (count($page['errors']) == 0)
126  {
127    //echo '<pre>'; print_r($_POST); echo '</pre>';
128    $result = pwg_query('SELECT param FROM '.CONFIG_TABLE);
129    while ($row = mysql_fetch_array($result))
130    {
131      if (isset($_POST[$row['param']]))
132      {
133        $value = $_POST[$row['param']];
134
135        if ('gallery_title' == $row['param'])
136        {
137          if (!$conf['allow_html_descriptions'])
138          {
139            $value = strip_tags($value);
140          }
141        }
142
143        $query = '
144UPDATE '.CONFIG_TABLE.'
145SET value = \''. str_replace("\'", "''", $value).'\'
146WHERE param = \''.$row['param'].'\'
147;';
148        pwg_query($query);
149      }
150    }
151    array_push($page['infos'], l10n('conf_confirmation'));
152  }
153
154  //------------------------------------------------------ $conf reinitialization
155  load_conf_from_db();
156}
157
158//----------------------------------------------------- template initialization
159$template->set_filename('config', 'admin/configuration.tpl');
160
161// TabSheet
162$tabsheet = new tabsheet();
163// TabSheet initialization
164$tabsheet->add('main', l10n('conf_main_title'), $conf_link.'main');
165$tabsheet->add('history', l10n('conf_history_title'), $conf_link.'history');
166$tabsheet->add('comments', l10n('conf_comments_title'), $conf_link.'comments');
167$tabsheet->add('default', l10n('conf_display'), $conf_link.'default');
168// TabSheet selection
169$tabsheet->select($page['section']);
170// Assign tabsheet to template
171$tabsheet->assign();
172
173$action = get_root_url().'admin.php?page=configuration';
174$action.= '&amp;section='.$page['section'];
175
176$template->assign_vars(
177  array(
178    'U_HELP' => get_root_url().'popuphelp.php?page=configuration',
179
180    'F_ACTION'=>$action
181    ));
182
183switch ($page['section'])
184{
185  case 'main' :
186  {
187    $template->assign(
188      'main',
189      array(
190        'CONF_GALLERY_TITLE' => htmlspecialchars($conf['gallery_title']),
191        'CONF_PAGE_BANNER' => htmlspecialchars($conf['page_banner']),
192        'CONF_GALLERY_URL' => $conf['gallery_url'],
193        ));
194
195    foreach( $main_checkboxes as $checkbox)
196    {
197      $template->append(
198          'main',
199          array(
200            $checkbox => $conf[$checkbox]
201            ),
202          true
203        );
204    }
205    break;
206  }
207  case 'history' :
208  {
209    //Necessary for merge_block_vars
210    foreach( $history_checkboxes as $checkbox)
211    {
212      $template->append(
213          'history',
214          array(
215            $checkbox => $conf[$checkbox]
216            ),
217          true
218        );
219    }
220    break;
221  }
222  case 'comments' :
223  {
224    $template->assign(
225      'comments',
226      array(
227        'NB_COMMENTS_PAGE'=>$conf['nb_comment_page'],
228        ));
229
230    foreach( $comments_checkboxes as $checkbox)
231    {
232      $template->append(
233          'comments',
234          array(
235            $checkbox => $conf[$checkbox]
236            ),
237          true
238        );
239    }
240    break;
241  }
242  case 'default' :
243  {
244    $edit_user = build_user($conf['default_user_id'], false);
245    include_once(PHPWG_ROOT_PATH.'profile.php');
246
247    $errors = array();
248    if ( !is_adviser() )
249    {
250      if (save_profile_from_post($edit_user, $errors))
251      {
252        // Reload user
253        $edit_user = build_user($conf['default_user_id'], false);
254        array_push($page['infos'], l10n('conf_confirmation'));
255      }
256    }
257    $page['errors'] = array_merge($page['errors'], $errors);
258
259    load_profile_in_template(
260      $action,
261      '',
262      $edit_user
263      );
264    $template->assign('default', array());
265    break;
266  }
267}
268
269//----------------------------------------------------------- sending html code
270$template->assign_var_from_handle('ADMIN_CONTENT', 'config');
271?>
Note: See TracBrowser for help on using the repository browser.