source: trunk/admin/configuration.php @ 10812

Last change on this file since 10812 was 10812, checked in by mistic100, 13 years ago

merge spread_menus to the core

  • Property svn:eol-style set to LF
File size: 9.7 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based photo gallery                                    |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2011 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    'allow_user_customization',
55   );
56
57$history_checkboxes = array(
58    'log',
59    'history_admin',
60    'history_guest'
61   );
62
63$comments_checkboxes = array(
64    'comments_forall',
65    'comments_validation',
66    'email_admin_on_comment',
67    'email_admin_on_comment_validation',
68    'user_can_delete_comment',
69    'user_can_edit_comment',
70    'email_admin_on_comment_edition',
71    'email_admin_on_comment_deletion'
72  );
73
74$display_checkboxes = array(
75    'menubar_filter_icon',
76    'index_sort_order_input',
77    'index_flat_icon',
78    'index_posted_date_icon',
79    'index_created_date_icon',
80    'index_slideshow_icon',
81    'picture_metadata_icon',
82    'picture_slideshow_icon',
83    'picture_favorite_icon',
84    'picture_download_icon',
85    'picture_navigation_icons',
86    'picture_navigation_thumb',
87    'picture_menu',
88  );
89
90$display_info_checkboxes = array(
91    'author',
92    'created_on',
93    'posted_on',
94    'dimensions',
95    'file',
96    'filesize',
97    'tags',
98    'categories',
99    'visits',
100    'average_rate',
101    'privacy_level',
102  );
103
104//------------------------------ verification and registration of modifications
105if (isset($_POST['submit']))
106{
107  $int_pattern = '/^\d+$/';
108
109  switch ($page['section'])
110  {
111    case 'main' :
112    {
113      if (empty($_POST['gallery_locked']) and $conf['gallery_locked'])
114      {
115        $tpl_var = & $template->get_template_vars('header_msgs');
116        $msg_key = array_search(l10n('The gallery is locked for maintenance. Please, come back later.'), $tpl_var);
117        unset($tpl_var[$msg_key]);
118      }
119      elseif (!empty($_POST['gallery_locked']) and !$conf['gallery_locked'])
120      {
121        $template->append('header_msgs', l10n('The gallery is locked for maintenance. Please, come back later.'));
122      }
123      foreach( $main_checkboxes as $checkbox)
124      {
125        $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
126      }
127      break;
128    }
129    case 'history' :
130    {
131      foreach( $history_checkboxes as $checkbox)
132      {
133        $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
134      }
135      break;
136    }
137    case 'comments' :
138    {
139      // the number of comments per page must be an integer between 5 and 50
140      // included
141      if (!preg_match($int_pattern, $_POST['nb_comment_page'])
142           or $_POST['nb_comment_page'] < 5
143           or $_POST['nb_comment_page'] > 50)
144      {
145        array_push($page['errors'], l10n('The number of comments a page must be between 5 and 50 included.'));
146      }
147      foreach( $comments_checkboxes as $checkbox)
148      {
149        $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
150      }
151      break;
152    }
153    case 'default' :
154    {
155      // Never go here
156      break;
157    }
158    case 'display' :
159    {
160      foreach( $display_checkboxes as $checkbox)
161      {
162        $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
163      }
164      foreach( $display_info_checkboxes as $checkbox)
165      {
166        $_POST['picture_informations'][$checkbox] =
167          empty($_POST['picture_informations'][$checkbox])? false : true;
168      }
169      $_POST['picture_informations'] = addslashes(serialize($_POST['picture_informations']));
170      break;
171    }
172  }
173
174  // updating configuration if no error found
175  if (count($page['errors']) == 0)
176  {
177    //echo '<pre>'; print_r($_POST); echo '</pre>';
178    $result = pwg_query('SELECT param FROM '.CONFIG_TABLE);
179    while ($row = pwg_db_fetch_assoc($result))
180    {
181      if (isset($_POST[$row['param']]))
182      {
183        $value = $_POST[$row['param']];
184
185        if ('gallery_title' == $row['param'])
186        {
187          if (!$conf['allow_html_descriptions'])
188          {
189            $value = strip_tags($value);
190          }
191        }
192
193        $query = '
194UPDATE '.CONFIG_TABLE.'
195SET value = \''. str_replace("\'", "''", $value).'\'
196WHERE param = \''.$row['param'].'\'
197;';
198        pwg_query($query);
199      }
200    }
201    array_push($page['infos'], l10n('Information data registered in database'));
202  }
203
204  //------------------------------------------------------ $conf reinitialization
205  load_conf_from_db();
206}
207
208//----------------------------------------------------- template initialization
209$template->set_filename('config', 'configuration.tpl');
210
211// TabSheet
212$tabsheet = new tabsheet();
213// TabSheet initialization
214$tabsheet->add('main', l10n('Main'), $conf_link.'main');
215$tabsheet->add('display', l10n('Display'), $conf_link.'display');
216$tabsheet->add('history', l10n('History'), $conf_link.'history');
217$tabsheet->add('comments', l10n('Comments'), $conf_link.'comments');
218$tabsheet->add('default', l10n('Guest Settings'), $conf_link.'default');
219// TabSheet selection
220$tabsheet->select($page['section']);
221// Assign tabsheet to template
222$tabsheet->assign();
223
224$action = get_root_url().'admin.php?page=configuration';
225$action.= '&amp;section='.$page['section'];
226
227$template->assign(
228  array(
229    'U_HELP' => get_root_url().'admin/popuphelp.php?page=configuration',
230    'F_ACTION'=>$action
231    ));
232
233switch ($page['section'])
234{
235  case 'main' :
236  {
237    $template->assign(
238      'main',
239      array(
240        'CONF_GALLERY_TITLE' => htmlspecialchars($conf['gallery_title']),
241        'CONF_PAGE_BANNER' => htmlspecialchars($conf['page_banner']),
242        'CONF_GALLERY_URL' => $conf['gallery_url'],
243        'week_starts_on_options' => array(
244          'sunday' => $lang['day'][0],
245          'monday' => $lang['day'][1],
246          ),
247        'week_starts_on_options_selected' => $conf['week_starts_on'],
248        ));
249
250    foreach ($main_checkboxes as $checkbox)
251    {
252      $template->append(
253          'main',
254          array(
255            $checkbox => $conf[$checkbox]
256            ),
257          true
258        );
259    }
260    break;
261  }
262  case 'history' :
263  {
264    //Necessary for merge_block_vars
265    foreach ($history_checkboxes as $checkbox)
266    {
267      $template->append(
268          'history',
269          array(
270            $checkbox => $conf[$checkbox]
271            ),
272          true
273        );
274    }
275    break;
276  }
277  case 'comments' :
278  {
279    $template->assign(
280      'comments',
281      array(
282        'NB_COMMENTS_PAGE'=>$conf['nb_comment_page'],
283        ));
284
285    foreach ($comments_checkboxes as $checkbox)
286    {
287      $template->append(
288          'comments',
289          array(
290            $checkbox => $conf[$checkbox]
291            ),
292          true
293        );
294    }
295    break;
296  }
297  case 'default' :
298  {
299    $edit_user = build_user($conf['guest_id'], false);
300    include_once(PHPWG_ROOT_PATH.'profile.php');
301
302    $errors = array();
303    if (save_profile_from_post($edit_user, $errors))
304    {
305      // Reload user
306      $edit_user = build_user($conf['guest_id'], false);
307      array_push($page['infos'], l10n('Information data registered in database'));
308    }
309    $page['errors'] = array_merge($page['errors'], $errors);
310
311    load_profile_in_template(
312      $action,
313      '',
314      $edit_user
315      );
316    $template->assign('default', array());
317    break;
318  }
319  case 'display' :
320  {
321    foreach ($display_checkboxes as $checkbox)
322    {
323      $template->append(
324          'display',
325          array(
326            $checkbox => $conf[$checkbox]
327            ),
328          true
329        );
330    }
331    $template->append(
332        'display',
333        array(
334          'picture_informations' => unserialize($conf['picture_informations'])
335          ),
336        true
337      );
338    break;
339  }
340}
341
342//----------------------------------------------------------- sending html code
343$template->assign_var_from_handle('ADMIN_CONTENT', 'config');
344?>
Note: See TracBrowser for help on using the repository browser.