source: trunk/admin/configuration.php @ 4423

Last change on this file since 4423 was 4325, checked in by nikrou, 14 years ago

Feature 1244 resolved
Replace all mysql functions in core code by ones independant of database engine

Fix small php code synxtax : hash must be accessed with [ ] and not { }.

  • Property svn:eol-style set to LF
File size: 8.4 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based picture gallery                                  |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2009 Piwigo Team                  http://piwigo.org |
6// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
7// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
8// +-----------------------------------------------------------------------+
9// | This program is free software; you can redistribute it and/or modify  |
10// | it under the terms of the GNU General Public License as published by  |
11// | the Free Software Foundation                                          |
12// |                                                                       |
13// | This program is distributed in the hope that it will be useful, but   |
14// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
15// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
16// | General Public License for more details.                              |
17// |                                                                       |
18// | You should have received a copy of the GNU General Public License     |
19// | along with this program; if not, write to the Free Software           |
20// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
21// | USA.                                                                  |
22// +-----------------------------------------------------------------------+
23
24if( !defined("PHPWG_ROOT_PATH") )
25{
26  die ("Hacking attempt!");
27}
28
29include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
30include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');
31
32// +-----------------------------------------------------------------------+
33// | Check Access and exit when user status is not ok                      |
34// +-----------------------------------------------------------------------+
35check_status(ACCESS_ADMINISTRATOR);
36
37//-------------------------------------------------------- sections definitions
38if (!isset($_GET['section']))
39{
40  $page['section'] = 'main';
41}
42else
43{
44  $page['section'] = $_GET['section'];
45}
46
47$main_checkboxes = array(
48    'gallery_locked',
49    'allow_user_registration',
50    'obligatory_user_mail_address',
51    'rate',
52    'rate_anonymous',
53    'email_admin_on_new_user',
54   );
55
56$history_checkboxes = array(
57    'log',
58    'history_admin',
59    'history_guest'
60   );
61
62$upload_checkboxes = array(
63    'upload_link_everytime',
64    'email_admin_on_picture_uploaded',
65   );
66
67$comments_checkboxes = array(
68    'comments_forall',
69    'comments_validation',
70    'email_admin_on_comment',
71    'email_admin_on_comment_validation',
72    'user_can_delete_comment',
73    'user_can_edit_comment',
74    'email_admin_on_comment_edition',
75    'email_admin_on_comment_deletion'
76  );
77
78//------------------------------ verification and registration of modifications
79if (isset($_POST['submit']) and !is_adviser())
80{
81  $int_pattern = '/^\d+$/';
82
83  switch ($page['section'])
84  {
85    case 'main' :
86    {
87      if ( !url_is_remote($_POST['gallery_url']) )
88      {
89        array_push($page['errors'], l10n('conf_gallery_url_error'));
90      }
91      foreach( $main_checkboxes as $checkbox)
92      {
93        $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
94      }
95      break;
96    }
97    case 'history' :
98    {
99      foreach( $history_checkboxes as $checkbox)
100      {
101        $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
102      }
103      break;
104    }
105    case 'comments' :
106    {
107      // the number of comments per page must be an integer between 5 and 50
108      // included
109      if (!preg_match($int_pattern, $_POST['nb_comment_page'])
110           or $_POST['nb_comment_page'] < 5
111           or $_POST['nb_comment_page'] > 50)
112      {
113        array_push($page['errors'], l10n('conf_nb_comment_page_error'));
114      }
115      foreach( $comments_checkboxes as $checkbox)
116      {
117        $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
118      }
119      break;
120    }
121    case 'upload' :
122    {
123      foreach( $upload_checkboxes as $checkbox)
124      {
125        $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
126      }
127      break;
128    }
129    case 'default' :
130    {
131      // Never go here
132      break;
133    }
134  }
135
136  // updating configuration if no error found
137  if (count($page['errors']) == 0)
138  {
139    //echo '<pre>'; print_r($_POST); echo '</pre>';
140    $result = pwg_query('SELECT param FROM '.CONFIG_TABLE);
141    while ($row = pwg_db_fetch_assoc($result))
142    {
143      if (isset($_POST[$row['param']]))
144      {
145        $value = $_POST[$row['param']];
146
147        if ('gallery_title' == $row['param'])
148        {
149          if (!$conf['allow_html_descriptions'])
150          {
151            $value = strip_tags($value);
152          }
153        }
154
155        $query = '
156UPDATE '.CONFIG_TABLE.'
157SET value = \''. str_replace("\'", "''", $value).'\'
158WHERE param = \''.$row['param'].'\'
159;';
160        pwg_query($query);
161      }
162    }
163    array_push($page['infos'], l10n('conf_confirmation'));
164  }
165
166  //------------------------------------------------------ $conf reinitialization
167  load_conf_from_db();
168}
169
170//----------------------------------------------------- template initialization
171$template->set_filename('config', 'configuration.tpl');
172
173// TabSheet
174$tabsheet = new tabsheet();
175// TabSheet initialization
176$tabsheet->add('main', l10n('conf_main_title'), $conf_link.'main');
177$tabsheet->add('history', l10n('conf_history_title'), $conf_link.'history');
178$tabsheet->add('comments', l10n('conf_comments_title'), $conf_link.'comments');
179$tabsheet->add('upload', l10n('conf_upload_title'), $conf_link.'upload');
180$tabsheet->add('default', l10n('conf_display'), $conf_link.'default');
181// TabSheet selection
182$tabsheet->select($page['section']);
183// Assign tabsheet to template
184$tabsheet->assign();
185
186$action = get_root_url().'admin.php?page=configuration';
187$action.= '&amp;section='.$page['section'];
188
189$template->assign(
190  array(
191    'U_HELP' => get_root_url().'popuphelp.php?page=configuration',
192    'F_ACTION'=>$action
193    ));
194
195switch ($page['section'])
196{
197  case 'main' :
198  {
199    $template->assign(
200      'main',
201      array(
202        'CONF_GALLERY_TITLE' => htmlspecialchars($conf['gallery_title']),
203        'CONF_PAGE_BANNER' => htmlspecialchars($conf['page_banner']),
204        'CONF_GALLERY_URL' => $conf['gallery_url'],
205        ));
206
207    foreach ($main_checkboxes as $checkbox)
208    {
209      $template->append(
210          'main',
211          array(
212            $checkbox => $conf[$checkbox]
213            ),
214          true
215        );
216    }
217    break;
218  }
219  case 'history' :
220  {
221    //Necessary for merge_block_vars
222    foreach ($history_checkboxes as $checkbox)
223    {
224      $template->append(
225          'history',
226          array(
227            $checkbox => $conf[$checkbox]
228            ),
229          true
230        );
231    }
232    break;
233  }
234  case 'comments' :
235  {
236    $template->assign(
237      'comments',
238      array(
239        'NB_COMMENTS_PAGE'=>$conf['nb_comment_page'],
240        ));
241
242    foreach ($comments_checkboxes as $checkbox)
243    {
244      $template->append(
245          'comments',
246          array(
247            $checkbox => $conf[$checkbox]
248            ),
249          true
250        );
251    }
252    break;
253  }
254  case 'upload' :
255  {
256    $template->assign(
257      'upload',
258      array(
259        'upload_user_access_options'=> get_user_access_level_html_options(ACCESS_GUEST),
260        'upload_user_access_options_selected' => array($conf['upload_user_access'])
261        )
262      );
263    //Necessary for merge_block_vars
264    foreach ($upload_checkboxes as $checkbox)
265    {
266      $template->append(
267          'upload',
268          array(
269            $checkbox => $conf[$checkbox]
270            ),
271          true
272        );
273    }
274    break;
275  }
276  case 'default' :
277  {
278    $edit_user = build_user($conf['default_user_id'], false);
279    include_once(PHPWG_ROOT_PATH.'profile.php');
280
281    $errors = array();
282    if ( !is_adviser() )
283    {
284      if (save_profile_from_post($edit_user, $errors))
285      {
286        // Reload user
287        $edit_user = build_user($conf['default_user_id'], false);
288        array_push($page['infos'], l10n('conf_confirmation'));
289      }
290    }
291    $page['errors'] = array_merge($page['errors'], $errors);
292
293    load_profile_in_template(
294      $action,
295      '',
296      $edit_user
297      );
298    $template->assign('default', array());
299    break;
300  }
301}
302
303//----------------------------------------------------------- sending html code
304$template->assign_var_from_handle('ADMIN_CONTENT', 'config');
305?>
Note: See TracBrowser for help on using the repository browser.