source: trunk/admin/configuration.php @ 13001

Last change on this file since 13001 was 13001, checked in by plg, 12 years ago

bug 2558 fixed: instead of locking the gallery with a simple checkbox among
configuration options, "lock gallery" becomes a maintenance action, with a
confirmation on popup.

  • Property svn:eol-style set to LF
File size: 13.9 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based photo gallery                                    |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2012 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/functions_upload.inc.php');
31include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');
32
33// +-----------------------------------------------------------------------+
34// | Check Access and exit when user status is not ok                      |
35// +-----------------------------------------------------------------------+
36check_status(ACCESS_ADMINISTRATOR);
37
38//-------------------------------------------------------- sections definitions
39if (!isset($_GET['section']))
40{
41  $page['section'] = 'main';
42}
43else
44{
45  $page['section'] = $_GET['section'];
46}
47
48$main_checkboxes = array(
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$sizes_checkboxes = array(
58    'original_resize',
59  );
60
61$history_checkboxes = array(
62    'log',
63    'history_admin',
64    'history_guest'
65   );
66
67$comments_checkboxes = array(
68    'activate_comments',
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    'index_new_icon',
87    'picture_metadata_icon',
88    'picture_slideshow_icon',
89    'picture_favorite_icon',
90    'picture_download_icon',
91    'picture_navigation_icons',
92    'picture_navigation_thumb',
93    'picture_menu',
94  );
95
96$display_info_checkboxes = array(
97    'author',
98    'created_on',
99    'posted_on',
100    'dimensions',
101    'file',
102    'filesize',
103    'tags',
104    'categories',
105    'visits',
106    'rating_score',
107    'privacy_level',
108  );
109 
110// image order management
111$sort_fields = array(
112  '' => '',
113  'rank' => l10n('Rank'),
114  'file' => l10n('File name'),
115  'name' => l10n('Photo name'),
116  'date_creation' => l10n('Creation date'),
117  'date_available' => l10n('Post date'),
118  'rating_score' => l10n('Rating score'),
119  'hit' => l10n('Most visited'),
120  'id' => 'Id',
121  );
122
123$sort_directions = array(
124  'ASC' => l10n('ascending'),
125  'DESC' => l10n('descending'),
126  );
127
128//------------------------------ verification and registration of modifications
129if (isset($_POST['submit']))
130{
131  $int_pattern = '/^\d+$/';
132
133  switch ($page['section'])
134  {
135    case 'main' :
136    {     
137      if ( !isset($conf['order_by_custom']) and !isset($conf['order_by_inside_category_custom']) )
138      {
139        if ( !empty($_POST['order_by_field']) )
140        {
141          $order_by = array();
142          $order_by_inside_category = array();
143         
144          for ($i=0; $i<count($_POST['order_by_field']); $i++)
145          {
146            if ( $i >= (count($sort_fields)-1) ) break; // limit to the number of available parameters
147            if ( empty($_POST['order_by_field'][$i]) )
148            {
149              array_push($page['errors'], l10n('No field selected'));
150              break;
151            }
152            else
153            {
154              // there is no rank outside categories
155              if ($_POST['order_by_field'][$i] != 'rank')
156              {
157                $order_by[] = $_POST['order_by_field'][$i].' '.$_POST['order_by_direction'][$i];
158              }
159              $order_by_inside_category[] = $_POST['order_by_field'][$i].' '.$_POST['order_by_direction'][$i];
160            }
161          }
162          // must define a default order_by if user want to order by rank only
163          if ( count($order_by) == 0 )
164          {
165            $order_by = array('id ASC');
166          }
167         
168          $_POST['order_by'] = 'ORDER BY '.implode(', ', $order_by);
169          $_POST['order_by_inside_category'] = 'ORDER BY '.implode(', ', $order_by_inside_category);
170          unset($_POST['order_by_field']);
171        }
172      }
173     
174      foreach( $main_checkboxes as $checkbox)
175      {
176        $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
177      }
178      break;
179    }
180    case 'sizes' :
181    {
182      $fields = array(
183        'original_resize',
184        'original_resize_maxwidth',
185        'original_resize_maxheight',
186        'original_resize_quality',
187        );
188
189      $updates = array();
190     
191      foreach ($fields as $field)
192      {
193        $value = !empty($_POST[$field]) ? $_POST[$field] : null;
194        $form_values[$field] = $value;
195        $updates[$field] = $value;
196      }
197
198      save_upload_form_config($updates, $page['errors']);
199 
200      if (count($page['errors']) == 0)
201      {
202        array_push(
203          $page['infos'],
204          l10n('Your configuration settings are saved')
205          );
206      }
207
208      break;
209    }
210    case 'history' :
211    {
212      foreach( $history_checkboxes as $checkbox)
213      {
214        $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
215      }
216      break;
217    }
218    case 'comments' :
219    {
220      // the number of comments per page must be an integer between 5 and 50
221      // included
222      if (!preg_match($int_pattern, $_POST['nb_comment_page'])
223           or $_POST['nb_comment_page'] < 5
224           or $_POST['nb_comment_page'] > 50)
225      {
226        array_push($page['errors'], l10n('The number of comments a page must be between 5 and 50 included.'));
227      }
228      foreach( $comments_checkboxes as $checkbox)
229      {
230        $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
231      }
232      break;
233    }
234    case 'default' :
235    {
236      // Never go here
237      break;
238    }
239    case 'display' :
240    {
241      foreach( $display_checkboxes as $checkbox)
242      {
243        $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
244      }
245      foreach( $display_info_checkboxes as $checkbox)
246      {
247        $_POST['picture_informations'][$checkbox] =
248          empty($_POST['picture_informations'][$checkbox])? false : true;
249      }
250      $_POST['picture_informations'] = addslashes(serialize($_POST['picture_informations']));
251      break;
252    }
253  }
254
255  // updating configuration if no error found
256  if ('sizes' != $page['section'] and count($page['errors']) == 0)
257  {
258    //echo '<pre>'; print_r($_POST); echo '</pre>';
259    $result = pwg_query('SELECT param FROM '.CONFIG_TABLE);
260    while ($row = pwg_db_fetch_assoc($result))
261    {
262      if (isset($_POST[$row['param']]))
263      {
264        $value = $_POST[$row['param']];
265
266        if ('gallery_title' == $row['param'])
267        {
268          if (!$conf['allow_html_descriptions'])
269          {
270            $value = strip_tags($value);
271          }
272        }
273
274        $query = '
275UPDATE '.CONFIG_TABLE.'
276SET value = \''. str_replace("\'", "''", $value).'\'
277WHERE param = \''.$row['param'].'\'
278;';
279        pwg_query($query);
280      }
281    }
282    array_push($page['infos'], l10n('Information data registered in database'));
283  }
284
285  //------------------------------------------------------ $conf reinitialization
286  load_conf_from_db();
287}
288
289//----------------------------------------------------- template initialization
290$template->set_filename('config', 'configuration.tpl');
291
292// TabSheet
293$tabsheet = new tabsheet();
294// TabSheet initialization
295$tabsheet->add('main', l10n('Main'), $conf_link.'main');
296$tabsheet->add('sizes', l10n('Photo Sizes'), $conf_link.'sizes');
297$tabsheet->add('display', l10n('Display'), $conf_link.'display');
298$tabsheet->add('history', l10n('History'), $conf_link.'history');
299$tabsheet->add('comments', l10n('Comments'), $conf_link.'comments');
300$tabsheet->add('default', l10n('Guest Settings'), $conf_link.'default');
301// TabSheet selection
302$tabsheet->select($page['section']);
303// Assign tabsheet to template
304$tabsheet->assign();
305
306$action = get_root_url().'admin.php?page=configuration';
307$action.= '&amp;section='.$page['section'];
308
309$template->assign(
310  array(
311    'U_HELP' => get_root_url().'admin/popuphelp.php?page=configuration',
312    'F_ACTION'=>$action
313    ));
314
315switch ($page['section'])
316{
317  case 'main' :
318  {   
319   
320    function order_by_is_local()
321    {
322      @include(PHPWG_ROOT_PATH. 'local/config/config.inc.php');
323      if (isset($conf['local_dir_site']))
324      {
325        @include(PHPWG_ROOT_PATH.PWG_LOCAL_DIR. 'config/config.inc.php');
326      }
327     
328      return isset($conf['order_by']) or isset($conf['order_by_inside_category']);
329    }
330   
331    if (order_by_is_local())
332    {
333      array_push($page['warnings'], l10n('You have specified <i>$conf[\'order_by\']</i> in your local configuration file, this parameter in deprecated, please remove it or rename it into <i>$conf[\'order_by_custom\']</i> !'));
334    }
335   
336    if ( isset($conf['order_by_custom']) or isset($conf['order_by_inside_category_custom']) )
337    {
338      $order_by = array(array(
339        'FIELD' => '',   
340        'DIRECTION' => 'ASC', 
341        ));
342       
343      $template->assign('ORDER_BY_IS_CUSTOM', true);
344    }
345    else
346    {
347      $out = array();
348      $order_by = trim($conf['order_by_inside_category']);
349      $order_by = str_replace('ORDER BY ', null, $order_by);
350      $order_by = explode(', ', $order_by);
351      foreach ($order_by as $field)
352      {
353        $field= explode(' ', $field);
354        $out[] = array(
355          'FIELD' => $field[0],   
356          'DIRECTION' => $field[1],   
357        );
358      }
359      $order_by = $out;
360    }
361 
362    $template->assign(
363      'main',
364      array(
365        'CONF_GALLERY_TITLE' => htmlspecialchars($conf['gallery_title']),
366        'CONF_PAGE_BANNER' => htmlspecialchars($conf['page_banner']),
367        'week_starts_on_options' => array(
368          'sunday' => $lang['day'][0],
369          'monday' => $lang['day'][1],
370          ),
371        'week_starts_on_options_selected' => $conf['week_starts_on'],
372        'order_by' => $order_by,
373        'order_field_options' => $sort_fields,
374        'order_direction_options' => $sort_directions,
375        )
376      );
377
378    foreach ($main_checkboxes as $checkbox)
379    {
380      $template->append(
381          'main',
382          array(
383            $checkbox => $conf[$checkbox]
384            ),
385          true
386        );
387    }
388    break;
389  }
390  case 'history' :
391  {
392    //Necessary for merge_block_vars
393    foreach ($history_checkboxes as $checkbox)
394    {
395      $template->append(
396          'history',
397          array(
398            $checkbox => $conf[$checkbox]
399            ),
400          true
401        );
402    }
403    break;
404  }
405  case 'comments' :
406  {
407    $template->assign(
408      'comments',
409      array(
410        'NB_COMMENTS_PAGE'=>$conf['nb_comment_page'],
411        'comments_order'=>$conf['comments_order'],
412        'comments_order_options'=> $sort_directions
413        )
414      );
415
416    foreach ($comments_checkboxes as $checkbox)
417    {
418      $template->append(
419          'comments',
420          array(
421            $checkbox => $conf[$checkbox]
422            ),
423          true
424        );
425    }
426    break;
427  }
428  case 'default' :
429  {
430    $edit_user = build_user($conf['guest_id'], false);
431    include_once(PHPWG_ROOT_PATH.'profile.php');
432
433    $errors = array();
434    if (save_profile_from_post($edit_user, $errors))
435    {
436      // Reload user
437      $edit_user = build_user($conf['guest_id'], false);
438      array_push($page['infos'], l10n('Information data registered in database'));
439    }
440    $page['errors'] = array_merge($page['errors'], $errors);
441
442    load_profile_in_template(
443      $action,
444      '',
445      $edit_user
446      );
447    $template->assign('default', array());
448    break;
449  }
450  case 'display' :
451  {
452    foreach ($display_checkboxes as $checkbox)
453    {
454      $template->append(
455          'display',
456          array(
457            $checkbox => $conf[$checkbox]
458            ),
459          true
460        );
461    }
462    $template->append(
463        'display',
464        array(
465          'picture_informations' => unserialize($conf['picture_informations'])
466          ),
467        true
468      );
469    break;
470  }
471  case 'sizes' :
472  {
473    $template->assign(
474      'sizes',
475      array(
476        'original_resize_maxwidth' => $conf['original_resize_maxwidth'],
477        'original_resize_maxheight' => $conf['original_resize_maxheight'],
478        'original_resize_quality' => $conf['original_resize_quality'],
479        )
480      );
481   
482    foreach ($sizes_checkboxes as $checkbox)
483    {
484      $template->append(
485        'sizes',
486        array(
487          $checkbox => $conf[$checkbox]
488          ),
489        true
490        );
491    }
492
493    break;
494  }
495}
496
497//----------------------------------------------------------- sending html code
498$template->assign_var_from_handle('ADMIN_CONTENT', 'config');
499?>
Note: See TracBrowser for help on using the repository browser.