source: trunk/admin/configuration.php @ 5293

Last change on this file since 5293 was 5293, checked in by patdenice, 14 years ago

Feature 1533: Change "General" by "Options" in Configuration menu.
Change "Default Display" tab by "Guest Settings" tab.
Add display tab in Configuration/Option menu.

Allow to activate/deactivate a lot of display features:

On main page:
# Display only recently posted images
# Sort order
# Display all elements in all sub-categories
# Display a calendar by posted date
# Display a calendar by creation date
# Slideshow

On photo page:
# Show file metadata
# slideshow
# Add this image to your favorites
# Navigation Bar
# Navigation Thumbnails

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