source: branches/2.1/admin/configuration.php @ 9545

Last change on this file since 9545 was 9545, checked in by patdenice, 13 years ago

merge r9544 form trunk to branch 2.1
bug:2212
Update header message when gallery is locked or unlocked.

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