source: trunk/admin/configuration.php @ 13115

Last change on this file since 13115 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
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    'log',
56    'history_admin',
57    'history_guest',
58   );
59
60$sizes_checkboxes = array(
61    'original_resize',
62  );
63
64$comments_checkboxes = array(
65    'activate_comments',
66    'comments_forall',
67    'comments_validation',
68    'email_admin_on_comment',
69    'email_admin_on_comment_validation',
70    'user_can_delete_comment',
71    'user_can_edit_comment',
72    'email_admin_on_comment_edition',
73    'email_admin_on_comment_deletion'
74  );
75
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',
83    'index_new_icon',
84    'picture_metadata_icon',
85    'picture_slideshow_icon',
86    'picture_favorite_icon',
87    'picture_download_icon',
88    'picture_navigation_icons',
89    'picture_navigation_thumb',
90    'picture_menu',
91  );
92
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',
103    'rating_score',
104    'privacy_level',
105  );
106 
107// image order management
108$sort_fields = array(
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'),
125  );
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']) )
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));
143         
144          // there is no rank outside categories
145          unset($order_by[ array_search('rank ASC', $order_by) ]);
146         
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         
153          $_POST['order_by'] = 'ORDER BY '.implode(', ', $order_by);
154          $_POST['order_by_inside_category'] = 'ORDER BY '.implode(', ', $order_by_inside_category);
155        }
156        else
157        {
158          array_push($page['errors'], l10n('No field selected'));
159        }
160      }
161     
162      foreach( $main_checkboxes as $checkbox)
163      {
164        $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
165      }
166      break;
167    }
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    }
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      {
206        array_push($page['errors'], l10n('The number of comments a page must be between 5 and 50 included.'));
207      }
208      foreach( $comments_checkboxes as $checkbox)
209      {
210        $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
211      }
212      break;
213    }
214    case 'default' :
215    {
216      // Never go here
217      break;
218    }
219    case 'display' :
220    {
221      foreach( $display_checkboxes as $checkbox)
222      {
223        $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
224      }
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']));
231      break;
232    }
233  }
234
235  // updating configuration if no error found
236  if ('sizes' != $page['section'] and count($page['errors']) == 0)
237  {
238    //echo '<pre>'; print_r($_POST); echo '</pre>';
239    $result = pwg_query('SELECT param FROM '.CONFIG_TABLE);
240    while ($row = pwg_db_fetch_assoc($result))
241    {
242      if (isset($_POST[$row['param']]))
243      {
244        $value = $_POST[$row['param']];
245
246        if ('gallery_title' == $row['param'])
247        {
248          if (!$conf['allow_html_descriptions'])
249          {
250            $value = strip_tags($value);
251          }
252        }
253
254        $query = '
255UPDATE '.CONFIG_TABLE.'
256SET value = \''. str_replace("\'", "''", $value).'\'
257WHERE param = \''.$row['param'].'\'
258;';
259        pwg_query($query);
260      }
261    }
262    array_push($page['infos'], l10n('Information data registered in database'));
263  }
264
265  //------------------------------------------------------ $conf reinitialization
266  load_conf_from_db();
267}
268
269//----------------------------------------------------- template initialization
270$template->set_filename('config', 'configuration.tpl');
271
272// TabSheet
273$tabsheet = new tabsheet();
274// TabSheet initialization
275$tabsheet->add('main', l10n('Main'), $conf_link.'main');
276$tabsheet->add('sizes', l10n('Photo sizes'), $conf_link.'sizes');
277$tabsheet->add('display', l10n('Display'), $conf_link.'display');
278$tabsheet->add('comments', l10n('Comments'), $conf_link.'comments');
279$tabsheet->add('default', l10n('Guest Settings'), $conf_link.'default');
280// TabSheet selection
281$tabsheet->select($page['section']);
282// Assign tabsheet to template
283$tabsheet->assign();
284
285$action = get_root_url().'admin.php?page=configuration';
286$action.= '&amp;section='.$page['section'];
287
288$template->assign(
289  array(
290    'U_HELP' => get_root_url().'admin/popuphelp.php?page=configuration',
291    'F_ACTION'=>$action
292    ));
293
294switch ($page['section'])
295{
296  case 'main' :
297  {   
298   
299    function order_by_is_local()
300    {
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']);
308    }
309   
310    if (order_by_is_local())
311    {
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> !'));
313    }
314   
315    if ( isset($conf['order_by_custom']) or isset($conf['order_by_inside_category_custom']) )
316    {
317      $order_by = array('');
318      $template->assign('ORDER_BY_IS_CUSTOM', true);
319    }
320    else
321    {
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);
326    }
327 
328    $template->assign(
329      'main',
330      array(
331        'CONF_GALLERY_TITLE' => htmlspecialchars($conf['gallery_title']),
332        'CONF_PAGE_BANNER' => htmlspecialchars($conf['page_banner']),
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'],
338        'order_by' => $order_by,
339        'order_by_options' => $sort_fields,
340        )
341      );
342
343    foreach ($main_checkboxes as $checkbox)
344    {
345      $template->append(
346          'main',
347          array(
348            $checkbox => $conf[$checkbox]
349            ),
350          true
351        );
352    }
353    break;
354  }
355  case 'comments' :
356  {
357    $template->assign(
358      'comments',
359      array(
360        'NB_COMMENTS_PAGE'=>$conf['nb_comment_page'],
361        'comments_order'=>$conf['comments_order'],
362        'comments_order_options'=> $sort_directions
363        )
364      );
365
366    foreach ($comments_checkboxes as $checkbox)
367    {
368      $template->append(
369          'comments',
370          array(
371            $checkbox => $conf[$checkbox]
372            ),
373          true
374        );
375    }
376    break;
377  }
378  case 'default' :
379  {
380    $edit_user = build_user($conf['guest_id'], false);
381    include_once(PHPWG_ROOT_PATH.'profile.php');
382
383    $errors = array();
384    if (save_profile_from_post($edit_user, $errors))
385    {
386      // Reload user
387      $edit_user = build_user($conf['guest_id'], false);
388      array_push($page['infos'], l10n('Information data registered in database'));
389    }
390    $page['errors'] = array_merge($page['errors'], $errors);
391
392    load_profile_in_template(
393      $action,
394      '',
395      $edit_user
396      );
397    $template->assign('default', array());
398    break;
399  }
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    }
412    $template->append(
413        'display',
414        array(
415          'picture_informations' => unserialize($conf['picture_informations'])
416          ),
417        true
418      );
419    break;
420  }
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  }
445}
446
447//----------------------------------------------------------- sending html code
448$template->assign_var_from_handle('ADMIN_CONTENT', 'config');
449?>
Note: See TracBrowser for help on using the repository browser.