source: trunk/admin/configuration.php @ 5304

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

Feature 1533: Allow activation or deactivation of download icon.
Add display configuration for picture properties.

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