source: trunk/admin/configuration.php @ 13087

Last change on this file since 13087 was 13087, checked in by mistic100, 12 years ago

feature 2568: redesigned order_by fields in Admin->Config->Options

  • Property svn:eol-style set to LF
File size: 13.1 KB
RevLine 
[362]1<?php
2// +-----------------------------------------------------------------------+
[8728]3// | Piwigo - a PHP based photo gallery                                    |
[2297]4// +-----------------------------------------------------------------------+
[12922]5// | Copyright(C) 2008-2012 Piwigo Team                  http://piwigo.org |
[2297]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// +-----------------------------------------------------------------------+
[2]23
[527]24if( !defined("PHPWG_ROOT_PATH") )
[393]25{
[1072]26  die ("Hacking attempt!");
[393]27}
[527]28
[1072]29include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
[12879]30include_once(PHPWG_ROOT_PATH.'admin/include/functions_upload.inc.php');
[2226]31include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');
[1072]32
33// +-----------------------------------------------------------------------+
34// | Check Access and exit when user status is not ok                      |
35// +-----------------------------------------------------------------------+
36check_status(ACCESS_ADMINISTRATOR);
37
[512]38//-------------------------------------------------------- sections definitions
39if (!isset($_GET['section']))
40{
[1894]41  $page['section'] = 'main';
[512]42}
43else
44{
45  $page['section'] = $_GET['section'];
46}
[1617]47
[1894]48$main_checkboxes = array(
[2032]49    'allow_user_registration',
50    'obligatory_user_mail_address',
[1920]51    'rate',
52    'rate_anonymous',
[1652]53    'email_admin_on_new_user',
[5328]54    'allow_user_customization',
[13004]55    'log',
56    'history_admin',
57    'history_guest',
[1617]58   );
59
[12879]60$sizes_checkboxes = array(
61    'original_resize',
62  );
63
[1617]64$comments_checkboxes = array(
[12887]65    'activate_comments',
[1617]66    'comments_forall',
67    'comments_validation',
68    'email_admin_on_comment',
69    'email_admin_on_comment_validation',
[3445]70    'user_can_delete_comment',
71    'user_can_edit_comment',
72    'email_admin_on_comment_edition',
73    'email_admin_on_comment_deletion'
[1617]74  );
75
[5293]76$display_checkboxes = array(
77    'menubar_filter_icon',
78    'index_sort_order_input',
79    'index_flat_icon',
80    'index_posted_date_icon',
81    'index_created_date_icon',
82    'index_slideshow_icon',
[11285]83    'index_new_icon',
[5293]84    'picture_metadata_icon',
85    'picture_slideshow_icon',
86    'picture_favorite_icon',
[5618]87    'picture_download_icon',
[5293]88    'picture_navigation_icons',
89    'picture_navigation_thumb',
[10812]90    'picture_menu',
[5293]91  );
92
[5304]93$display_info_checkboxes = array(
94    'author',
95    'created_on',
96    'posted_on',
97    'dimensions',
98    'file',
99    'filesize',
100    'tags',
101    'categories',
102    'visits',
[11893]103    'rating_score',
[5723]104    'privacy_level',
[5304]105  );
[11279]106 
[11587]107// image order management
108$sort_fields = array(
[13087]109  ''                    => '',
110  'file ASC'            => l10n('file name, A &rarr; Z'),
111  'file DESC'           => l10n('file name, Z &rarr; A'),
112  'name ASC'            => l10n('photo title, A &rarr; Z'),
113  'name DESC'           => l10n('photo title, Z &rarr; A'),
114  'date_creation DESC'  => l10n('date created, new &rarr; old'),
115  'date_creation ASC'   => l10n('date created, old &rarr; new'),
116  'date_available DESC' => l10n('date posted, new &rarr; old'),
117  'date_available ASC'  => l10n('date posted, old &rarr; new'),
118  'rating_score DESC'   => l10n('rating score, high &rarr; low'),
119  'rating_score ASC'    => l10n('rating score, low &rarr; high'),
120  'hit DESC'            => l10n('visits, high &rarr; low'),
121  'hit ASC'             => l10n('visits, low &rarr; high'),
122  'id ASC'              => l10n('numeric identifier, 1 &rarr; 9'),
123  'id DESC'             => l10n('numeric identifier, 9 &rarr; 1'),
124  'rank ASC'            => l10n('manual sort order'),
[11279]125  );
[13087]126 
[5304]127
[2]128//------------------------------ verification and registration of modifications
[8126]129if (isset($_POST['submit']))
[2]130{
[21]131  $int_pattern = '/^\d+$/';
[1926]132
[512]133  switch ($page['section'])
[2]134  {
[1894]135    case 'main' :
[11587]136    {     
137      if ( !isset($conf['order_by_custom']) and !isset($conf['order_by_inside_category_custom']) )
[11279]138      {
[13087]139        if ( !empty($_POST['order_by']) )
140        {         
141          // limit to the number of available parameters
142          $order_by = $order_by_inside_category = array_slice($_POST['order_by'], 0, ceil(count($sort_fields)/2));
[12872]143         
[13087]144          // there is no rank outside categories
145          unset($order_by[ array_search('rank ASC', $order_by) ]);
146         
[12872]147          // must define a default order_by if user want to order by rank only
148          if ( count($order_by) == 0 )
149          {
150            $order_by = array('id ASC');
151          }
152         
[11587]153          $_POST['order_by'] = 'ORDER BY '.implode(', ', $order_by);
154          $_POST['order_by_inside_category'] = 'ORDER BY '.implode(', ', $order_by_inside_category);
[11279]155        }
[13087]156        else
157        {
158          array_push($page['errors'], l10n('No field selected'));
159        }
[11279]160      }
161     
[1894]162      foreach( $main_checkboxes as $checkbox)
[1617]163      {
164        $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
165      }
[512]166      break;
[130]167    }
[12879]168    case 'sizes' :
169    {
170      $fields = array(
171        'original_resize',
172        'original_resize_maxwidth',
173        'original_resize_maxheight',
174        'original_resize_quality',
175        );
176
177      $updates = array();
178     
179      foreach ($fields as $field)
180      {
181        $value = !empty($_POST[$field]) ? $_POST[$field] : null;
182        $form_values[$field] = $value;
183        $updates[$field] = $value;
184      }
185
186      save_upload_form_config($updates, $page['errors']);
187 
188      if (count($page['errors']) == 0)
189      {
190        array_push(
191          $page['infos'],
192          l10n('Your configuration settings are saved')
193          );
194      }
195
196      break;
197    }
[512]198    case 'comments' :
199    {
200      // the number of comments per page must be an integer between 5 and 50
201      // included
202      if (!preg_match($int_pattern, $_POST['nb_comment_page'])
203           or $_POST['nb_comment_page'] < 5
204           or $_POST['nb_comment_page'] > 50)
205      {
[5021]206        array_push($page['errors'], l10n('The number of comments a page must be between 5 and 50 included.'));
[512]207      }
[1617]208      foreach( $comments_checkboxes as $checkbox)
209      {
210        $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
211      }
[512]212      break;
213    }
214    case 'default' :
215    {
[1926]216      // Never go here
[512]217      break;
218    }
[5293]219    case 'display' :
220    {
221      foreach( $display_checkboxes as $checkbox)
222      {
223        $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
224      }
[5304]225      foreach( $display_info_checkboxes as $checkbox)
226      {
227        $_POST['picture_informations'][$checkbox] =
228          empty($_POST['picture_informations'][$checkbox])? false : true;
229      }
230      $_POST['picture_informations'] = addslashes(serialize($_POST['picture_informations']));
[5293]231      break;
232    }
[2]233  }
[1071]234
[528]235  // updating configuration if no error found
[12879]236  if ('sizes' != $page['section'] and count($page['errors']) == 0)
[345]237  {
[1565]238    //echo '<pre>'; print_r($_POST); echo '</pre>';
[1748]239    $result = pwg_query('SELECT param FROM '.CONFIG_TABLE);
[4325]240    while ($row = pwg_db_fetch_assoc($result))
[512]241    {
242      if (isset($_POST[$row['param']]))
243      {
[882]244        $value = $_POST[$row['param']];
[1071]245
246        if ('gallery_title' == $row['param'])
[882]247        {
248          if (!$conf['allow_html_descriptions'])
249          {
250            $value = strip_tags($value);
251          }
252        }
[1071]253
[528]254        $query = '
255UPDATE '.CONFIG_TABLE.'
[1926]256SET value = \''. str_replace("\'", "''", $value).'\'
257WHERE param = \''.$row['param'].'\'
[528]258;';
[587]259        pwg_query($query);
[512]260      }
261    }
[5021]262    array_push($page['infos'], l10n('Information data registered in database'));
[345]263  }
[527]264
[1748]265  //------------------------------------------------------ $conf reinitialization
266  load_conf_from_db();
[1565]267}
268
[512]269//----------------------------------------------------- template initialization
[2530]270$template->set_filename('config', 'configuration.tpl');
[512]271
[2226]272// TabSheet
273$tabsheet = new tabsheet();
[1881]274// TabSheet initialization
[5021]275$tabsheet->add('main', l10n('Main'), $conf_link.'main');
[13068]276$tabsheet->add('sizes', l10n('Photo sizes'), $conf_link.'sizes');
[5293]277$tabsheet->add('display', l10n('Display'), $conf_link.'display');
[5021]278$tabsheet->add('comments', l10n('Comments'), $conf_link.'comments');
[5293]279$tabsheet->add('default', l10n('Guest Settings'), $conf_link.'default');
[2226]280// TabSheet selection
281$tabsheet->select($page['section']);
[1881]282// Assign tabsheet to template
[2226]283$tabsheet->assign();
[1881]284
[2249]285$action = get_root_url().'admin.php?page=configuration';
[528]286$action.= '&amp;section='.$page['section'];
[21]287
[2288]288$template->assign(
[528]289  array(
[5920]290    'U_HELP' => get_root_url().'admin/popuphelp.php?page=configuration',
[1004]291    'F_ACTION'=>$action
[528]292    ));
293
[527]294switch ($page['section'])
[528]295{
[1894]296  case 'main' :
[11587]297  {   
298   
299    function order_by_is_local()
[11279]300    {
[11587]301      @include(PHPWG_ROOT_PATH. 'local/config/config.inc.php');
302      if (isset($conf['local_dir_site']))
303      {
304        @include(PHPWG_ROOT_PATH.PWG_LOCAL_DIR. 'config/config.inc.php');
305      }
306     
307      return isset($conf['order_by']) or isset($conf['order_by_inside_category']);
[11279]308    }
[11587]309   
310    if (order_by_is_local())
[11279]311    {
[11587]312      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> !'));
[11279]313    }
[11587]314   
315    if ( isset($conf['order_by_custom']) or isset($conf['order_by_inside_category_custom']) )
[11279]316    {
[13087]317      $order_by = array('');
[11587]318      $template->assign('ORDER_BY_IS_CUSTOM', true);
[11279]319    }
320    else
321    {
[11587]322      $out = array();
323      $order_by = trim($conf['order_by_inside_category']);
324      $order_by = str_replace('ORDER BY ', null, $order_by);
325      $order_by = explode(', ', $order_by);
[11279]326    }
[11587]327 
[2249]328    $template->assign(
[1894]329      'main',
[528]330      array(
[2021]331        'CONF_GALLERY_TITLE' => htmlspecialchars($conf['gallery_title']),
332        'CONF_PAGE_BANNER' => htmlspecialchars($conf['page_banner']),
[8626]333        'week_starts_on_options' => array(
334          'sunday' => $lang['day'][0],
335          'monday' => $lang['day'][1],
336          ),
337        'week_starts_on_options_selected' => $conf['week_starts_on'],
[11587]338        'order_by' => $order_by,
[13087]339        'order_by_options' => $sort_fields,
[11587]340        )
341      );
[1617]342
[2325]343    foreach ($main_checkboxes as $checkbox)
[1617]344    {
[2249]345      $template->append(
[1894]346          'main',
[1617]347          array(
[2249]348            $checkbox => $conf[$checkbox]
349            ),
350          true
[1617]351        );
352    }
[528]353    break;
354  }
355  case 'comments' :
356  {
[2249]357    $template->assign(
[528]358      'comments',
359      array(
360        'NB_COMMENTS_PAGE'=>$conf['nb_comment_page'],
[12894]361        'comments_order'=>$conf['comments_order'],
362        'comments_order_options'=> $sort_directions
363        )
364      );
[1617]365
[2325]366    foreach ($comments_checkboxes as $checkbox)
[1617]367    {
[2249]368      $template->append(
[1617]369          'comments',
370          array(
[2249]371            $checkbox => $conf[$checkbox]
372            ),
373          true
[1617]374        );
375    }
[528]376    break;
377  }
378  case 'default' :
379  {
[5994]380    $edit_user = build_user($conf['guest_id'], false);
[1926]381    include_once(PHPWG_ROOT_PATH.'profile.php');
[1071]382
[1926]383    $errors = array();
[8126]384    if (save_profile_from_post($edit_user, $errors))
[858]385    {
[8126]386      // Reload user
387      $edit_user = build_user($conf['guest_id'], false);
388      array_push($page['infos'], l10n('Information data registered in database'));
[858]389    }
[1926]390    $page['errors'] = array_merge($page['errors'], $errors);
[541]391
[1926]392    load_profile_in_template(
393      $action,
394      '',
395      $edit_user
396      );
[2249]397    $template->assign('default', array());
[528]398    break;
399  }
[5293]400  case 'display' :
401  {
402    foreach ($display_checkboxes as $checkbox)
403    {
404      $template->append(
405          'display',
406          array(
407            $checkbox => $conf[$checkbox]
408            ),
409          true
410        );
411    }
[5304]412    $template->append(
413        'display',
414        array(
415          'picture_informations' => unserialize($conf['picture_informations'])
416          ),
417        true
418      );
[5293]419    break;
420  }
[12879]421  case 'sizes' :
422  {
423    $template->assign(
424      'sizes',
425      array(
426        'original_resize_maxwidth' => $conf['original_resize_maxwidth'],
427        'original_resize_maxheight' => $conf['original_resize_maxheight'],
428        'original_resize_quality' => $conf['original_resize_quality'],
429        )
430      );
431   
432    foreach ($sizes_checkboxes as $checkbox)
433    {
434      $template->append(
435        'sizes',
436        array(
437          $checkbox => $conf[$checkbox]
438          ),
439        true
440        );
441    }
442
443    break;
444  }
[528]445}
[1926]446
[2]447//----------------------------------------------------------- sending html code
[393]448$template->assign_var_from_handle('ADMIN_CONTENT', 'config');
[362]449?>
Note: See TracBrowser for help on using the repository browser.