source: trunk/admin/configuration.php @ 2339

Last change on this file since 2339 was 2325, checked in by rub, 16 years ago

Resolved issue 0000823: Enhance upload functionalities

First commit, others will be follow.
Not hesitate to change my translations.

Add upload configuration tabsheet (move and add configuration)
Change and add define for access level
Can show upload link every time
Can restrict access upload.class.php
Can choice category on upload page
Add upload class not use for the moment
Review quickly and temporary style of upload.tpl

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 8.3 KB
RevLine 
[362]1<?php
2// +-----------------------------------------------------------------------+
[2297]3// | Piwigo - a PHP based picture gallery                                  |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008      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// +-----------------------------------------------------------------------+
[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',
[1617]54   );
55
[1884]56$history_checkboxes = array(
57    'log',
58    'history_admin',
59    'history_guest'
60   );
61
[2325]62$upload_checkboxes = array(
63    'upload_link_everytime',
64    'email_admin_on_picture_uploaded',
65   );
66
[1617]67$comments_checkboxes = array(
68    'comments_forall',
69    'comments_validation',
70    'email_admin_on_comment',
71    'email_admin_on_comment_validation',
72  );
73
[2]74//------------------------------ verification and registration of modifications
[1571]75if (isset($_POST['submit']) and !is_adviser())
[2]76{
[21]77  $int_pattern = '/^\d+$/';
[1926]78
[512]79  switch ($page['section'])
[2]80  {
[1894]81    case 'main' :
[130]82    {
[1044]83      if ( !url_is_remote($_POST['gallery_url']) )
84      {
[2201]85        array_push($page['errors'], l10n('conf_gallery_url_error'));
[1044]86      }
[1894]87      foreach( $main_checkboxes as $checkbox)
[1617]88      {
89        $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
90      }
[512]91      break;
[130]92    }
[1884]93    case 'history' :
94    {
95      foreach( $history_checkboxes as $checkbox)
96      {
97        $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
98      }
99      break;
100    }
[512]101    case 'comments' :
102    {
103      // the number of comments per page must be an integer between 5 and 50
104      // included
105      if (!preg_match($int_pattern, $_POST['nb_comment_page'])
106           or $_POST['nb_comment_page'] < 5
107           or $_POST['nb_comment_page'] > 50)
108      {
[2201]109        array_push($page['errors'], l10n('conf_nb_comment_page_error'));
[512]110      }
[1617]111      foreach( $comments_checkboxes as $checkbox)
112      {
113        $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
114      }
[512]115      break;
116    }
[2325]117    case 'upload' :
118    {
119      foreach( $upload_checkboxes as $checkbox)
120      {
121        $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
122      }
123      break;
124    }
[512]125    case 'default' :
126    {
[1926]127      // Never go here
[512]128      break;
129    }
[2]130  }
[1071]131
[528]132  // updating configuration if no error found
[792]133  if (count($page['errors']) == 0)
[345]134  {
[1565]135    //echo '<pre>'; print_r($_POST); echo '</pre>';
[1748]136    $result = pwg_query('SELECT param FROM '.CONFIG_TABLE);
[512]137    while ($row = mysql_fetch_array($result))
138    {
139      if (isset($_POST[$row['param']]))
140      {
[882]141        $value = $_POST[$row['param']];
[1071]142
143        if ('gallery_title' == $row['param'])
[882]144        {
145          if (!$conf['allow_html_descriptions'])
146          {
147            $value = strip_tags($value);
148          }
149        }
[1071]150
[528]151        $query = '
152UPDATE '.CONFIG_TABLE.'
[1926]153SET value = \''. str_replace("\'", "''", $value).'\'
154WHERE param = \''.$row['param'].'\'
[528]155;';
[587]156        pwg_query($query);
[512]157      }
158    }
[2201]159    array_push($page['infos'], l10n('conf_confirmation'));
[345]160  }
[527]161
[1748]162  //------------------------------------------------------ $conf reinitialization
163  load_conf_from_db();
[1565]164}
165
[512]166//----------------------------------------------------- template initialization
[1881]167$template->set_filename('config', 'admin/configuration.tpl');
[512]168
[2226]169// TabSheet
170$tabsheet = new tabsheet();
[1881]171// TabSheet initialization
[2226]172$tabsheet->add('main', l10n('conf_main_title'), $conf_link.'main');
173$tabsheet->add('history', l10n('conf_history_title'), $conf_link.'history');
174$tabsheet->add('comments', l10n('conf_comments_title'), $conf_link.'comments');
[2325]175$tabsheet->add('upload', l10n('conf_upload_title'), $conf_link.'upload');
[2226]176$tabsheet->add('default', l10n('conf_display'), $conf_link.'default');
177// TabSheet selection
178$tabsheet->select($page['section']);
[1881]179// Assign tabsheet to template
[2226]180$tabsheet->assign();
[1881]181
[2249]182$action = get_root_url().'admin.php?page=configuration';
[528]183$action.= '&amp;section='.$page['section'];
[21]184
[2288]185$template->assign(
[528]186  array(
[2249]187    'U_HELP' => get_root_url().'popuphelp.php?page=configuration',
[1004]188    'F_ACTION'=>$action
[528]189    ));
190
[527]191switch ($page['section'])
[528]192{
[1894]193  case 'main' :
[2]194  {
[2249]195    $template->assign(
[1894]196      'main',
[528]197      array(
[2021]198        'CONF_GALLERY_TITLE' => htmlspecialchars($conf['gallery_title']),
199        'CONF_PAGE_BANNER' => htmlspecialchars($conf['page_banner']),
[1044]200        'CONF_GALLERY_URL' => $conf['gallery_url'],
[528]201        ));
[1617]202
[2325]203    foreach ($main_checkboxes as $checkbox)
[1617]204    {
[2249]205      $template->append(
[1894]206          'main',
[1617]207          array(
[2249]208            $checkbox => $conf[$checkbox]
209            ),
210          true
[1617]211        );
212    }
[528]213    break;
214  }
[1884]215  case 'history' :
216  {
217    //Necessary for merge_block_vars
[2325]218    foreach ($history_checkboxes as $checkbox)
[1884]219    {
[2249]220      $template->append(
[1884]221          'history',
222          array(
[2249]223            $checkbox => $conf[$checkbox]
224            ),
225          true
[1884]226        );
227    }
228    break;
229  }
[528]230  case 'comments' :
231  {
[2249]232    $template->assign(
[528]233      'comments',
234      array(
235        'NB_COMMENTS_PAGE'=>$conf['nb_comment_page'],
236        ));
[1617]237
[2325]238    foreach ($comments_checkboxes as $checkbox)
[1617]239    {
[2249]240      $template->append(
[1617]241          'comments',
242          array(
[2249]243            $checkbox => $conf[$checkbox]
244            ),
245          true
[1617]246        );
247    }
[528]248    break;
249  }
[2325]250  case 'upload' :
251  {
252    $template->assign(
253      'upload',
254      array(
255        'upload_user_access_options'=> get_user_access_level_html_options(ACCESS_GUEST),
256        'upload_user_access_options_selected' => array($conf['upload_user_access'])
257        )
258      );
259    //Necessary for merge_block_vars
260    foreach ($upload_checkboxes as $checkbox)
261    {
262      $template->append(
263          'upload',
264          array(
265            $checkbox => $conf[$checkbox]
266            ),
267          true
268        );
269    }
270    break;
271  }
[528]272  case 'default' :
273  {
[1926]274    $edit_user = build_user($conf['default_user_id'], false);
275    include_once(PHPWG_ROOT_PATH.'profile.php');
[1071]276
[1926]277    $errors = array();
278    if ( !is_adviser() )
[858]279    {
[1926]280      if (save_profile_from_post($edit_user, $errors))
[858]281      {
[1926]282        // Reload user
283        $edit_user = build_user($conf['default_user_id'], false);
[2201]284        array_push($page['infos'], l10n('conf_confirmation'));
[858]285      }
286    }
[1926]287    $page['errors'] = array_merge($page['errors'], $errors);
[541]288
[1926]289    load_profile_in_template(
290      $action,
291      '',
292      $edit_user
293      );
[2249]294    $template->assign('default', array());
[528]295    break;
296  }
297}
[1926]298
[2]299//----------------------------------------------------------- sending html code
[393]300$template->assign_var_from_handle('ADMIN_CONTENT', 'config');
[362]301?>
Note: See TracBrowser for help on using the repository browser.