source: trunk/admin/configuration.php @ 12344

Last change on this file since 12344 was 11978, checked in by plg, 13 years ago

feature 2413 added: move gallery_url configuration parameter from database to
local configuration file.

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