source: trunk/admin/configuration.php @ 13840

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

feature 2586: add capitals to sort labels on admin

  • Property svn:eol-style set to LF
File size: 13.3 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$comments_order = array(
128  'ASC' => l10n('Show oldest comments first'),
129  'DESC' => l10n('Show latest comments first'),
130  );
131
132
133//------------------------------ verification and registration of modifications
134if (isset($_POST['submit']))
135{
136  $int_pattern = '/^\d+$/';
137
138  switch ($page['section'])
139  {
140    case 'main' :
141    {     
142      if ( !isset($conf['order_by_custom']) and !isset($conf['order_by_inside_category_custom']) )
143      {
144        if ( !empty($_POST['order_by']) )
145        {         
146          // limit to the number of available parameters
147          $order_by = $order_by_inside_category = array_slice($_POST['order_by'], 0, ceil(count($sort_fields)/2));
148         
149          // there is no rank outside categories
150          unset($order_by[ array_search('rank ASC', $order_by) ]);
151         
152          // must define a default order_by if user want to order by rank only
153          if ( count($order_by) == 0 )
154          {
155            $order_by = array('id ASC');
156          }
157         
158          $_POST['order_by'] = 'ORDER BY '.implode(', ', $order_by);
159          $_POST['order_by_inside_category'] = 'ORDER BY '.implode(', ', $order_by_inside_category);
160        }
161        else
162        {
163          array_push($page['errors'], l10n('No field selected'));
164        }
165      }
166     
167      foreach( $main_checkboxes as $checkbox)
168      {
169        $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
170      }
171      break;
172    }
173    case 'sizes' :
174    {
175      $fields = array(
176        'original_resize',
177        'original_resize_maxwidth',
178        'original_resize_maxheight',
179        'original_resize_quality',
180        );
181
182      $updates = array();
183     
184      foreach ($fields as $field)
185      {
186        $value = !empty($_POST[$field]) ? $_POST[$field] : null;
187        $form_values[$field] = $value;
188        $updates[$field] = $value;
189      }
190
191      save_upload_form_config($updates, $page['errors']);
192 
193      if (count($page['errors']) == 0)
194      {
195        array_push(
196          $page['infos'],
197          l10n('Your configuration settings are saved')
198          );
199      }
200
201      break;
202    }
203    case 'comments' :
204    {
205      // the number of comments per page must be an integer between 5 and 50
206      // included
207      if (!preg_match($int_pattern, $_POST['nb_comment_page'])
208           or $_POST['nb_comment_page'] < 5
209           or $_POST['nb_comment_page'] > 50)
210      {
211        array_push($page['errors'], l10n('The number of comments a page must be between 5 and 50 included.'));
212      }
213      foreach( $comments_checkboxes as $checkbox)
214      {
215        $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
216      }
217      break;
218    }
219    case 'default' :
220    {
221      // Never go here
222      break;
223    }
224    case 'display' :
225    {
226      foreach( $display_checkboxes as $checkbox)
227      {
228        $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
229      }
230      foreach( $display_info_checkboxes as $checkbox)
231      {
232        $_POST['picture_informations'][$checkbox] =
233          empty($_POST['picture_informations'][$checkbox])? false : true;
234      }
235      $_POST['picture_informations'] = addslashes(serialize($_POST['picture_informations']));
236      break;
237    }
238  }
239
240  // updating configuration if no error found
241  if ('sizes' != $page['section'] and count($page['errors']) == 0)
242  {
243    //echo '<pre>'; print_r($_POST); echo '</pre>';
244    $result = pwg_query('SELECT param FROM '.CONFIG_TABLE);
245    while ($row = pwg_db_fetch_assoc($result))
246    {
247      if (isset($_POST[$row['param']]))
248      {
249        $value = $_POST[$row['param']];
250
251        if ('gallery_title' == $row['param'])
252        {
253          if (!$conf['allow_html_descriptions'])
254          {
255            $value = strip_tags($value);
256          }
257        }
258
259        $query = '
260UPDATE '.CONFIG_TABLE.'
261SET value = \''. str_replace("\'", "''", $value).'\'
262WHERE param = \''.$row['param'].'\'
263;';
264        pwg_query($query);
265      }
266    }
267    array_push($page['infos'], l10n('Information data registered in database'));
268  }
269
270  //------------------------------------------------------ $conf reinitialization
271  load_conf_from_db();
272}
273
274//----------------------------------------------------- template initialization
275$template->set_filename('config', 'configuration.tpl');
276
277// TabSheet
278$tabsheet = new tabsheet();
279// TabSheet initialization
280$tabsheet->add('main', l10n('Main'), $conf_link.'main');
281$tabsheet->add('sizes', l10n('Photo sizes'), $conf_link.'sizes');
282$tabsheet->add('display', l10n('Display'), $conf_link.'display');
283$tabsheet->add('comments', l10n('Comments'), $conf_link.'comments');
284$tabsheet->add('default', l10n('Guest Settings'), $conf_link.'default');
285// TabSheet selection
286$tabsheet->select($page['section']);
287// Assign tabsheet to template
288$tabsheet->assign();
289
290$action = get_root_url().'admin.php?page=configuration';
291$action.= '&amp;section='.$page['section'];
292
293$template->assign(
294  array(
295    'U_HELP' => get_root_url().'admin/popuphelp.php?page=configuration',
296    'F_ACTION'=>$action
297    ));
298
299switch ($page['section'])
300{
301  case 'main' :
302  {   
303   
304    function order_by_is_local()
305    {
306      @include(PHPWG_ROOT_PATH. 'local/config/config.inc.php');
307      if (isset($conf['local_dir_site']))
308      {
309        @include(PHPWG_ROOT_PATH.PWG_LOCAL_DIR. 'config/config.inc.php');
310      }
311     
312      return isset($conf['order_by']) or isset($conf['order_by_inside_category']);
313    }
314   
315    if (order_by_is_local())
316    {
317      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> !'));
318    }
319   
320    if ( isset($conf['order_by_custom']) or isset($conf['order_by_inside_category_custom']) )
321    {
322      $order_by = array('');
323      $template->assign('ORDER_BY_IS_CUSTOM', true);
324    }
325    else
326    {
327      $out = array();
328      $order_by = trim($conf['order_by_inside_category']);
329      $order_by = str_replace('ORDER BY ', null, $order_by);
330      $order_by = explode(', ', $order_by);
331    }
332 
333    $template->assign(
334      'main',
335      array(
336        'CONF_GALLERY_TITLE' => htmlspecialchars($conf['gallery_title']),
337        'CONF_PAGE_BANNER' => htmlspecialchars($conf['page_banner']),
338        'week_starts_on_options' => array(
339          'sunday' => $lang['day'][0],
340          'monday' => $lang['day'][1],
341          ),
342        'week_starts_on_options_selected' => $conf['week_starts_on'],
343        'order_by' => $order_by,
344        'order_by_options' => $sort_fields,
345        )
346      );
347
348    foreach ($main_checkboxes as $checkbox)
349    {
350      $template->append(
351          'main',
352          array(
353            $checkbox => $conf[$checkbox]
354            ),
355          true
356        );
357    }
358    break;
359  }
360  case 'comments' :
361  {
362    $template->assign(
363      'comments',
364      array(
365        'NB_COMMENTS_PAGE'=>$conf['nb_comment_page'],
366        'comments_order'=>$conf['comments_order'],
367        'comments_order_options'=> $comments_order
368        )
369      );
370
371    foreach ($comments_checkboxes as $checkbox)
372    {
373      $template->append(
374          'comments',
375          array(
376            $checkbox => $conf[$checkbox]
377            ),
378          true
379        );
380    }
381    break;
382  }
383  case 'default' :
384  {
385    $edit_user = build_user($conf['guest_id'], false);
386    include_once(PHPWG_ROOT_PATH.'profile.php');
387
388    $errors = array();
389    if (save_profile_from_post($edit_user, $errors))
390    {
391      // Reload user
392      $edit_user = build_user($conf['guest_id'], false);
393      array_push($page['infos'], l10n('Information data registered in database'));
394    }
395    $page['errors'] = array_merge($page['errors'], $errors);
396
397    load_profile_in_template(
398      $action,
399      '',
400      $edit_user
401      );
402    $template->assign('default', array());
403    break;
404  }
405  case 'display' :
406  {
407    foreach ($display_checkboxes as $checkbox)
408    {
409      $template->append(
410          'display',
411          array(
412            $checkbox => $conf[$checkbox]
413            ),
414          true
415        );
416    }
417    $template->append(
418        'display',
419        array(
420          'picture_informations' => unserialize($conf['picture_informations'])
421          ),
422        true
423      );
424    break;
425  }
426  case 'sizes' :
427  {
428    $template->assign(
429      'sizes',
430      array(
431        'original_resize_maxwidth' => $conf['original_resize_maxwidth'],
432        'original_resize_maxheight' => $conf['original_resize_maxheight'],
433        'original_resize_quality' => $conf['original_resize_quality'],
434        )
435      );
436   
437    foreach ($sizes_checkboxes as $checkbox)
438    {
439      $template->append(
440        'sizes',
441        array(
442          $checkbox => $conf[$checkbox]
443          ),
444        true
445        );
446    }
447
448    break;
449  }
450}
451
452//----------------------------------------------------------- sending html code
453$template->assign_var_from_handle('ADMIN_CONTENT', 'config');
454?>
Note: See TracBrowser for help on using the repository browser.