source: trunk/admin/configuration.php @ 2325

Last change on this file since 2325 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
Line 
1<?php
2// +-----------------------------------------------------------------------+
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// +-----------------------------------------------------------------------+
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/tabsheet.class.php');
31
32// +-----------------------------------------------------------------------+
33// | Check Access and exit when user status is not ok                      |
34// +-----------------------------------------------------------------------+
35check_status(ACCESS_ADMINISTRATOR);
36
37//-------------------------------------------------------- sections definitions
38if (!isset($_GET['section']))
39{
40  $page['section'] = 'main';
41}
42else
43{
44  $page['section'] = $_GET['section'];
45}
46
47$main_checkboxes = array(
48    'gallery_locked',
49    'allow_user_registration',
50    'obligatory_user_mail_address',
51    'rate',
52    'rate_anonymous',
53    'email_admin_on_new_user',
54   );
55
56$history_checkboxes = array(
57    'log',
58    'history_admin',
59    'history_guest'
60   );
61
62$upload_checkboxes = array(
63    'upload_link_everytime',
64    'email_admin_on_picture_uploaded',
65   );
66
67$comments_checkboxes = array(
68    'comments_forall',
69    'comments_validation',
70    'email_admin_on_comment',
71    'email_admin_on_comment_validation',
72  );
73
74//------------------------------ verification and registration of modifications
75if (isset($_POST['submit']) and !is_adviser())
76{
77  $int_pattern = '/^\d+$/';
78
79  switch ($page['section'])
80  {
81    case 'main' :
82    {
83      if ( !url_is_remote($_POST['gallery_url']) )
84      {
85        array_push($page['errors'], l10n('conf_gallery_url_error'));
86      }
87      foreach( $main_checkboxes as $checkbox)
88      {
89        $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
90      }
91      break;
92    }
93    case 'history' :
94    {
95      foreach( $history_checkboxes as $checkbox)
96      {
97        $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
98      }
99      break;
100    }
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      {
109        array_push($page['errors'], l10n('conf_nb_comment_page_error'));
110      }
111      foreach( $comments_checkboxes as $checkbox)
112      {
113        $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
114      }
115      break;
116    }
117    case 'upload' :
118    {
119      foreach( $upload_checkboxes as $checkbox)
120      {
121        $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
122      }
123      break;
124    }
125    case 'default' :
126    {
127      // Never go here
128      break;
129    }
130  }
131
132  // updating configuration if no error found
133  if (count($page['errors']) == 0)
134  {
135    //echo '<pre>'; print_r($_POST); echo '</pre>';
136    $result = pwg_query('SELECT param FROM '.CONFIG_TABLE);
137    while ($row = mysql_fetch_array($result))
138    {
139      if (isset($_POST[$row['param']]))
140      {
141        $value = $_POST[$row['param']];
142
143        if ('gallery_title' == $row['param'])
144        {
145          if (!$conf['allow_html_descriptions'])
146          {
147            $value = strip_tags($value);
148          }
149        }
150
151        $query = '
152UPDATE '.CONFIG_TABLE.'
153SET value = \''. str_replace("\'", "''", $value).'\'
154WHERE param = \''.$row['param'].'\'
155;';
156        pwg_query($query);
157      }
158    }
159    array_push($page['infos'], l10n('conf_confirmation'));
160  }
161
162  //------------------------------------------------------ $conf reinitialization
163  load_conf_from_db();
164}
165
166//----------------------------------------------------- template initialization
167$template->set_filename('config', 'admin/configuration.tpl');
168
169// TabSheet
170$tabsheet = new tabsheet();
171// TabSheet initialization
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');
175$tabsheet->add('upload', l10n('conf_upload_title'), $conf_link.'upload');
176$tabsheet->add('default', l10n('conf_display'), $conf_link.'default');
177// TabSheet selection
178$tabsheet->select($page['section']);
179// Assign tabsheet to template
180$tabsheet->assign();
181
182$action = get_root_url().'admin.php?page=configuration';
183$action.= '&amp;section='.$page['section'];
184
185$template->assign(
186  array(
187    'U_HELP' => get_root_url().'popuphelp.php?page=configuration',
188    'F_ACTION'=>$action
189    ));
190
191switch ($page['section'])
192{
193  case 'main' :
194  {
195    $template->assign(
196      'main',
197      array(
198        'CONF_GALLERY_TITLE' => htmlspecialchars($conf['gallery_title']),
199        'CONF_PAGE_BANNER' => htmlspecialchars($conf['page_banner']),
200        'CONF_GALLERY_URL' => $conf['gallery_url'],
201        ));
202
203    foreach ($main_checkboxes as $checkbox)
204    {
205      $template->append(
206          'main',
207          array(
208            $checkbox => $conf[$checkbox]
209            ),
210          true
211        );
212    }
213    break;
214  }
215  case 'history' :
216  {
217    //Necessary for merge_block_vars
218    foreach ($history_checkboxes as $checkbox)
219    {
220      $template->append(
221          'history',
222          array(
223            $checkbox => $conf[$checkbox]
224            ),
225          true
226        );
227    }
228    break;
229  }
230  case 'comments' :
231  {
232    $template->assign(
233      'comments',
234      array(
235        'NB_COMMENTS_PAGE'=>$conf['nb_comment_page'],
236        ));
237
238    foreach ($comments_checkboxes as $checkbox)
239    {
240      $template->append(
241          'comments',
242          array(
243            $checkbox => $conf[$checkbox]
244            ),
245          true
246        );
247    }
248    break;
249  }
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  }
272  case 'default' :
273  {
274    $edit_user = build_user($conf['default_user_id'], false);
275    include_once(PHPWG_ROOT_PATH.'profile.php');
276
277    $errors = array();
278    if ( !is_adviser() )
279    {
280      if (save_profile_from_post($edit_user, $errors))
281      {
282        // Reload user
283        $edit_user = build_user($conf['default_user_id'], false);
284        array_push($page['infos'], l10n('conf_confirmation'));
285      }
286    }
287    $page['errors'] = array_merge($page['errors'], $errors);
288
289    load_profile_in_template(
290      $action,
291      '',
292      $edit_user
293      );
294    $template->assign('default', array());
295    break;
296  }
297}
298
299//----------------------------------------------------------- sending html code
300$template->assign_var_from_handle('ADMIN_CONTENT', 'config');
301?>
Note: See TracBrowser for help on using the repository browser.