source: branches/2.4/admin/configuration.php @ 16926

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

Merged revision(s) 16925 from trunk:
feature 2703: make it easy for plugins to add tabs in admin screens
add a trigger a give an id to each core tabsheets

  • Property svn:eol-style set to LF
File size: 17.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
[13958]39
40check_input_parameter('section', $_GET, false, '/^[a-z]+$/i');
41
[512]42if (!isset($_GET['section']))
43{
[1894]44  $page['section'] = 'main';
[512]45}
46else
47{
48  $page['section'] = $_GET['section'];
49}
[1617]50
[1894]51$main_checkboxes = array(
[2032]52    'allow_user_registration',
53    'obligatory_user_mail_address',
[1920]54    'rate',
55    'rate_anonymous',
[1652]56    'email_admin_on_new_user',
[5328]57    'allow_user_customization',
[13004]58    'log',
59    'history_admin',
60    'history_guest',
[1617]61   );
62
[12879]63$sizes_checkboxes = array(
64    'original_resize',
65  );
66
[1617]67$comments_checkboxes = array(
[12887]68    'activate_comments',
[1617]69    'comments_forall',
70    'comments_validation',
71    'email_admin_on_comment',
72    'email_admin_on_comment_validation',
[3445]73    'user_can_delete_comment',
74    'user_can_edit_comment',
75    'email_admin_on_comment_edition',
76    'email_admin_on_comment_deletion'
[1617]77  );
78
[5293]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',
[11285]86    'index_new_icon',
[5293]87    'picture_metadata_icon',
88    'picture_slideshow_icon',
89    'picture_favorite_icon',
[5618]90    'picture_download_icon',
[5293]91    'picture_navigation_icons',
92    'picture_navigation_thumb',
[10812]93    'picture_menu',
[5293]94  );
95
[5304]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',
[11893]106    'rating_score',
[5723]107    'privacy_level',
[5304]108  );
[11279]109 
[11587]110// image order management
111$sort_fields = array(
[13087]112  ''                    => '',
[13840]113  'file ASC'            => l10n('File name, A &rarr; Z'),
114  'file DESC'           => l10n('File name, Z &rarr; A'),
115  'name ASC'            => l10n('Photo title, A &rarr; Z'),
116  'name DESC'           => l10n('Photo title, Z &rarr; A'),
117  'date_creation DESC'  => l10n('Date created, new &rarr; old'),
118  'date_creation ASC'   => l10n('Date created, old &rarr; new'),
119  'date_available DESC' => l10n('Date posted, new &rarr; old'),
120  'date_available ASC'  => l10n('Date posted, old &rarr; new'),
121  'rating_score DESC'   => l10n('Rating score, high &rarr; low'),
122  'rating_score ASC'    => l10n('Rating score, low &rarr; high'),
123  'hit DESC'            => l10n('Visits, high &rarr; low'),
124  'hit ASC'             => l10n('Visits, low &rarr; high'),
125  'id ASC'              => l10n('Numeric identifier, 1 &rarr; 9'),
126  'id DESC'             => l10n('Numeric identifier, 9 &rarr; 1'),
127  'rank ASC'            => l10n('Manual sort order'),
[11279]128  );
[13087]129 
[13224]130$comments_order = array(
131  'ASC' => l10n('Show oldest comments first'),
[13225]132  'DESC' => l10n('Show latest comments first'),
[13224]133  );
[5304]134
[13224]135
[2]136//------------------------------ verification and registration of modifications
[8126]137if (isset($_POST['submit']))
[2]138{
[21]139  $int_pattern = '/^\d+$/';
[1926]140
[512]141  switch ($page['section'])
[2]142  {
[1894]143    case 'main' :
[11587]144    {     
145      if ( !isset($conf['order_by_custom']) and !isset($conf['order_by_inside_category_custom']) )
[11279]146      {
[13087]147        if ( !empty($_POST['order_by']) )
[15951]148        {
149          foreach ($_POST['order_by'] as $i => $val)
[12872]150          {
[15951]151            if (empty($val)) unset($_POST['order_by'][$i]);
[12872]152          }
[15951]153          if ( !count($_POST['order_by']) )
154          {
155            array_push($page['errors'], l10n('No order field selected'));
156          }
157          else
158          {
159            // limit to the number of available parameters
160            $order_by = $order_by_inside_category = array_slice($_POST['order_by'], 0, ceil(count($sort_fields)/2));
161           
162            // there is no rank outside categories
163            if ( ($i = array_search('rank ASC', $order_by)) !== false)
164            {
165              unset($order_by[$i]);
166            }
167           
168            // must define a default order_by if user want to order by rank only
169            if ( count($order_by) == 0 )
170            {
171              $order_by = array('id ASC');
172            }
173           
174            $_POST['order_by'] = 'ORDER BY '.implode(', ', $order_by);
175            $_POST['order_by_inside_category'] = 'ORDER BY '.implode(', ', $order_by_inside_category);
176          }
[11279]177        }
[13087]178        else
179        {
[15951]180          array_push($page['errors'], l10n('No order field selected'));
[13087]181        }
[11279]182      }
183     
[1894]184      foreach( $main_checkboxes as $checkbox)
[1617]185      {
186        $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
187      }
[512]188      break;
[130]189    }
[14512]190    case 'watermark' :
191    {
192      include(PHPWG_ROOT_PATH.'admin/include/configuration_watermark_process.inc.php');       
193      break;
194    }
[12879]195    case 'sizes' :
196    {
[14221]197      include(PHPWG_ROOT_PATH.'admin/include/configuration_sizes_process.inc.php');       
[12879]198      break;
199    }
[512]200    case 'comments' :
201    {
202      // the number of comments per page must be an integer between 5 and 50
203      // included
204      if (!preg_match($int_pattern, $_POST['nb_comment_page'])
205           or $_POST['nb_comment_page'] < 5
206           or $_POST['nb_comment_page'] > 50)
207      {
[5021]208        array_push($page['errors'], l10n('The number of comments a page must be between 5 and 50 included.'));
[512]209      }
[1617]210      foreach( $comments_checkboxes as $checkbox)
211      {
212        $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
213      }
[512]214      break;
215    }
216    case 'default' :
217    {
[1926]218      // Never go here
[512]219      break;
220    }
[5293]221    case 'display' :
222    {
223      foreach( $display_checkboxes as $checkbox)
224      {
225        $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
226      }
[5304]227      foreach( $display_info_checkboxes as $checkbox)
228      {
229        $_POST['picture_informations'][$checkbox] =
230          empty($_POST['picture_informations'][$checkbox])? false : true;
231      }
232      $_POST['picture_informations'] = addslashes(serialize($_POST['picture_informations']));
[5293]233      break;
234    }
[2]235  }
[1071]236
[528]237  // updating configuration if no error found
[14513]238  if (!in_array($page['section'], array('sizes', 'watermark')) and count($page['errors']) == 0)
[345]239  {
[1565]240    //echo '<pre>'; print_r($_POST); echo '</pre>';
[1748]241    $result = pwg_query('SELECT param FROM '.CONFIG_TABLE);
[4325]242    while ($row = pwg_db_fetch_assoc($result))
[512]243    {
244      if (isset($_POST[$row['param']]))
245      {
[882]246        $value = $_POST[$row['param']];
[1071]247
248        if ('gallery_title' == $row['param'])
[882]249        {
250          if (!$conf['allow_html_descriptions'])
251          {
252            $value = strip_tags($value);
253          }
254        }
[1071]255
[528]256        $query = '
257UPDATE '.CONFIG_TABLE.'
[1926]258SET value = \''. str_replace("\'", "''", $value).'\'
259WHERE param = \''.$row['param'].'\'
[528]260;';
[587]261        pwg_query($query);
[512]262      }
263    }
[5021]264    array_push($page['infos'], l10n('Information data registered in database'));
[345]265  }
[527]266
[1748]267  //------------------------------------------------------ $conf reinitialization
268  load_conf_from_db();
[1565]269}
[14251]270
271// restore default derivatives settings
272if ('sizes' == $page['section'] and isset($_GET['action']) and 'restore_settings' == $_GET['action'])
[14228]273{
274  ImageStdParams::set_and_save( ImageStdParams::get_default_sizes() );
275  pwg_query('DELETE FROM '.CONFIG_TABLE.' WHERE param = \'disabled_derivatives\'');
276  clear_derivative_cache();
[14251]277
278  array_push(
279    $page['infos'],
280    l10n('Your configuration settings are saved')
281    );
[14228]282}
[1565]283
[512]284//----------------------------------------------------- template initialization
[2530]285$template->set_filename('config', 'configuration.tpl');
[512]286
[2226]287// TabSheet
288$tabsheet = new tabsheet();
[16926]289$tabsheet->set_id('configuration');
[1881]290// TabSheet initialization
[5021]291$tabsheet->add('main', l10n('Main'), $conf_link.'main');
[13068]292$tabsheet->add('sizes', l10n('Photo sizes'), $conf_link.'sizes');
[14512]293$tabsheet->add('watermark', l10n('Watermark'), $conf_link.'watermark');
[5293]294$tabsheet->add('display', l10n('Display'), $conf_link.'display');
[5021]295$tabsheet->add('comments', l10n('Comments'), $conf_link.'comments');
[5293]296$tabsheet->add('default', l10n('Guest Settings'), $conf_link.'default');
[2226]297// TabSheet selection
298$tabsheet->select($page['section']);
[1881]299// Assign tabsheet to template
[2226]300$tabsheet->assign();
[1881]301
[2249]302$action = get_root_url().'admin.php?page=configuration';
[528]303$action.= '&amp;section='.$page['section'];
[21]304
[2288]305$template->assign(
[528]306  array(
[5920]307    'U_HELP' => get_root_url().'admin/popuphelp.php?page=configuration',
[1004]308    'F_ACTION'=>$action
[528]309    ));
310
[527]311switch ($page['section'])
[528]312{
[1894]313  case 'main' :
[11587]314  {   
315   
316    function order_by_is_local()
[11279]317    {
[11587]318      @include(PHPWG_ROOT_PATH. 'local/config/config.inc.php');
319      if (isset($conf['local_dir_site']))
320      {
321        @include(PHPWG_ROOT_PATH.PWG_LOCAL_DIR. 'config/config.inc.php');
322      }
323     
324      return isset($conf['order_by']) or isset($conf['order_by_inside_category']);
[11279]325    }
[11587]326   
327    if (order_by_is_local())
[11279]328    {
[11587]329      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]330    }
[11587]331   
332    if ( isset($conf['order_by_custom']) or isset($conf['order_by_inside_category_custom']) )
[11279]333    {
[13087]334      $order_by = array('');
[11587]335      $template->assign('ORDER_BY_IS_CUSTOM', true);
[11279]336    }
337    else
338    {
[11587]339      $out = array();
340      $order_by = trim($conf['order_by_inside_category']);
341      $order_by = str_replace('ORDER BY ', null, $order_by);
342      $order_by = explode(', ', $order_by);
[11279]343    }
[11587]344 
[2249]345    $template->assign(
[1894]346      'main',
[528]347      array(
[2021]348        'CONF_GALLERY_TITLE' => htmlspecialchars($conf['gallery_title']),
349        'CONF_PAGE_BANNER' => htmlspecialchars($conf['page_banner']),
[8626]350        'week_starts_on_options' => array(
351          'sunday' => $lang['day'][0],
352          'monday' => $lang['day'][1],
353          ),
354        'week_starts_on_options_selected' => $conf['week_starts_on'],
[11587]355        'order_by' => $order_by,
[13087]356        'order_by_options' => $sort_fields,
[11587]357        )
358      );
[1617]359
[2325]360    foreach ($main_checkboxes as $checkbox)
[1617]361    {
[2249]362      $template->append(
[1894]363          'main',
[1617]364          array(
[2249]365            $checkbox => $conf[$checkbox]
366            ),
367          true
[1617]368        );
369    }
[528]370    break;
371  }
372  case 'comments' :
373  {
[2249]374    $template->assign(
[528]375      'comments',
376      array(
377        'NB_COMMENTS_PAGE'=>$conf['nb_comment_page'],
[12894]378        'comments_order'=>$conf['comments_order'],
[13224]379        'comments_order_options'=> $comments_order
[12894]380        )
381      );
[1617]382
[2325]383    foreach ($comments_checkboxes as $checkbox)
[1617]384    {
[2249]385      $template->append(
[1617]386          'comments',
387          array(
[2249]388            $checkbox => $conf[$checkbox]
389            ),
390          true
[1617]391        );
392    }
[528]393    break;
394  }
395  case 'default' :
396  {
[5994]397    $edit_user = build_user($conf['guest_id'], false);
[1926]398    include_once(PHPWG_ROOT_PATH.'profile.php');
[1071]399
[1926]400    $errors = array();
[8126]401    if (save_profile_from_post($edit_user, $errors))
[858]402    {
[8126]403      // Reload user
404      $edit_user = build_user($conf['guest_id'], false);
405      array_push($page['infos'], l10n('Information data registered in database'));
[858]406    }
[1926]407    $page['errors'] = array_merge($page['errors'], $errors);
[541]408
[1926]409    load_profile_in_template(
410      $action,
411      '',
412      $edit_user
413      );
[2249]414    $template->assign('default', array());
[528]415    break;
416  }
[5293]417  case 'display' :
418  {
419    foreach ($display_checkboxes as $checkbox)
420    {
421      $template->append(
422          'display',
423          array(
424            $checkbox => $conf[$checkbox]
425            ),
426          true
427        );
428    }
[5304]429    $template->append(
430        'display',
431        array(
432          'picture_informations' => unserialize($conf['picture_informations'])
433          ),
434        true
435      );
[5293]436    break;
437  }
[12879]438  case 'sizes' :
439  {
[14221]440    // we only load the derivatives if it was not already loaded: it occurs
441    // when submitting the form and an error remains
442    if (!isset($page['sizes_loaded_in_tpl']))
[12879]443    {
[14221]444      $template->assign(
[12879]445        'sizes',
446        array(
[14221]447          'original_resize_maxwidth' => $conf['original_resize_maxwidth'],
448          'original_resize_maxheight' => $conf['original_resize_maxheight'],
449          'original_resize_quality' => $conf['original_resize_quality'],
450          )
[12879]451        );
[13883]452     
[14221]453      foreach ($sizes_checkboxes as $checkbox)
[13883]454      {
[14221]455        $template->append(
456          'sizes',
457          array(
458            $checkbox => $conf[$checkbox]
459            ),
460          true
461          );
[13883]462      }
[14221]463     
464      // derivatives = multiple size
465      $enabled = ImageStdParams::get_defined_type_map();
466      $disabled = @unserialize(@$conf['disabled_derivatives']);
467      if ($disabled === false)
[13883]468      {
[14221]469        $disabled = array();
[13883]470      }
[14221]471
472      $tpl_vars = array();
473      foreach(ImageStdParams::get_all_types() as $type)
[13883]474      {
[14221]475        $tpl_var = array();
476       
477        $tpl_var['must_square'] = ($type==IMG_SQUARE ? true : false);
478        $tpl_var['must_enable'] = ($type==IMG_SQUARE || $type==IMG_THUMB)? true : false;
479       
480        if ($params = @$enabled[$type])
[13883]481        {
[14221]482          $tpl_var['enabled'] = true;
[13883]483        }
484        else
485        {
[14221]486          $tpl_var['enabled']=false;
487          $params=@$disabled[$type];
[13883]488        }
[14221]489       
490        if ($params)
491        {
492          list($tpl_var['w'],$tpl_var['h']) = $params->sizing->ideal_size;
493          if ( ($tpl_var['crop'] = round(100*$params->sizing->max_crop)) > 0)
494          {
495            list($tpl_var['minw'],$tpl_var['minh']) = $params->sizing->min_size;
496          }
497          else
498          {
499            $tpl_var['minw'] = $tpl_var['minh'] = "";
500          }
501          $tpl_var['sharpen'] = $params->sharpen;
502        }
503        $tpl_vars[$type]=$tpl_var;
[13883]504      }
[14221]505      $template->assign('derivatives', $tpl_vars);
[14649]506      $template->assign('resize_quality', ImageStdParams::$quality);
[13883]507    }
508
[12879]509    break;
510  }
[14512]511  case 'watermark' :
512  {
513    $watermark_files = array();
514    foreach (glob(PHPWG_ROOT_PATH.'themes/default/watermarks/*.png') as $file)
515    {
516      $watermark_files[] = substr($file, strlen(PHPWG_ROOT_PATH));
517    }
[16168]518    if ( ($glob=glob(PHPWG_ROOT_PATH.PWG_LOCAL_DIR.'watermarks/*.png')) !== false)
[14512]519    {
[16168]520      foreach ($glob as $file)
521      {
522        $watermark_files[] = substr($file, strlen(PHPWG_ROOT_PATH));
523      }
[14512]524    }
525    $watermark_filemap = array( '' => '---' );
526    foreach( $watermark_files as $file)
527    {
528      $display = basename($file);
529      $watermark_filemap[$file] = $display;
530    }
531    $template->assign('watermark_files', $watermark_filemap);
532
[14513]533    if ($template->get_template_vars('watermark') === null)
[14512]534    {
[14513]535      $wm = ImageStdParams::get_watermark();
[14512]536
537      $position = 'custom';
[14513]538      if ($wm->xpos == 0 and $wm->ypos == 0)
539      {
540        $position = 'topleft';
541      }
542      if ($wm->xpos == 100 and $wm->ypos == 0)
543      {
544        $position = 'topright';
545      }
546      if ($wm->xpos == 50 and $wm->ypos == 50)
547      {
548        $position = 'middle';
549      }
550      if ($wm->xpos == 0 and $wm->ypos == 100)
551      {
552        $position = 'bottomleft';
553      }
554      if ($wm->xpos == 100 and $wm->ypos == 100)
555      {
556        $position = 'bottomright';
557      }
558     
559      if ($wm->xrepeat != 0)
560      {
561        $position = 'custom';
562      }
563   
564      $template->assign(
565        'watermark',
566        array(
567          'file' => $wm->file,
568          'minw' => $wm->min_size[0],
569          'minh' => $wm->min_size[1],
570          'xpos' => $wm->xpos,
571          'ypos' => $wm->ypos,
572          'xrepeat' => $wm->xrepeat,
573          'opacity' => $wm->opacity,
574          'position' => $position,
575          )
576        );
[14512]577    }
578   
579    break;
580  }
[528]581}
[1926]582
[2]583//----------------------------------------------------------- sending html code
[393]584$template->assign_var_from_handle('ADMIN_CONTENT', 'config');
[362]585?>
Note: See TracBrowser for help on using the repository browser.