source: trunk/admin/configuration.php @ 8728

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

Happy new year 2011

Change "Piwigo - a PHP based picture gallery" into "Piwigo - a PHP based photo gallery"

  • Property svn:eol-style set to LF
File size: 9.2 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based photo gallery                                    |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2011 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    'allow_user_customization',
55   );
56
57$history_checkboxes = array(
58    'log',
59    'history_admin',
60    'history_guest'
61   );
62
63$comments_checkboxes = array(
64    'comments_forall',
65    'comments_validation',
66    'email_admin_on_comment',
67    'email_admin_on_comment_validation',
68    'user_can_delete_comment',
69    'user_can_edit_comment',
70    'email_admin_on_comment_edition',
71    'email_admin_on_comment_deletion'
72  );
73
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',
81    'picture_metadata_icon',
82    'picture_slideshow_icon',
83    'picture_favorite_icon',
84    'picture_download_icon',
85    'picture_navigation_icons',
86    'picture_navigation_thumb',
87  );
88
89$display_info_checkboxes = array(
90    'author',
91    'created_on',
92    'posted_on',
93    'dimensions',
94    'file',
95    'filesize',
96    'tags',
97    'categories',
98    'visits',
99    'average_rate',
100    'privacy_level',
101  );
102
103//------------------------------ verification and registration of modifications
104if (isset($_POST['submit']))
105{
106  $int_pattern = '/^\d+$/';
107
108  switch ($page['section'])
109  {
110    case 'main' :
111    {
112      foreach( $main_checkboxes as $checkbox)
113      {
114        $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
115      }
116      break;
117    }
118    case 'history' :
119    {
120      foreach( $history_checkboxes as $checkbox)
121      {
122        $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
123      }
124      break;
125    }
126    case 'comments' :
127    {
128      // the number of comments per page must be an integer between 5 and 50
129      // included
130      if (!preg_match($int_pattern, $_POST['nb_comment_page'])
131           or $_POST['nb_comment_page'] < 5
132           or $_POST['nb_comment_page'] > 50)
133      {
134        array_push($page['errors'], l10n('The number of comments a page must be between 5 and 50 included.'));
135      }
136      foreach( $comments_checkboxes as $checkbox)
137      {
138        $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
139      }
140      break;
141    }
142    case 'default' :
143    {
144      // Never go here
145      break;
146    }
147    case 'display' :
148    {
149      foreach( $display_checkboxes as $checkbox)
150      {
151        $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
152      }
153      foreach( $display_info_checkboxes as $checkbox)
154      {
155        $_POST['picture_informations'][$checkbox] =
156          empty($_POST['picture_informations'][$checkbox])? false : true;
157      }
158      $_POST['picture_informations'] = addslashes(serialize($_POST['picture_informations']));
159      break;
160    }
161  }
162
163  // updating configuration if no error found
164  if (count($page['errors']) == 0)
165  {
166    //echo '<pre>'; print_r($_POST); echo '</pre>';
167    $result = pwg_query('SELECT param FROM '.CONFIG_TABLE);
168    while ($row = pwg_db_fetch_assoc($result))
169    {
170      if (isset($_POST[$row['param']]))
171      {
172        $value = $_POST[$row['param']];
173
174        if ('gallery_title' == $row['param'])
175        {
176          if (!$conf['allow_html_descriptions'])
177          {
178            $value = strip_tags($value);
179          }
180        }
181
182        $query = '
183UPDATE '.CONFIG_TABLE.'
184SET value = \''. str_replace("\'", "''", $value).'\'
185WHERE param = \''.$row['param'].'\'
186;';
187        pwg_query($query);
188      }
189    }
190    array_push($page['infos'], l10n('Information data registered in database'));
191  }
192
193  //------------------------------------------------------ $conf reinitialization
194  load_conf_from_db();
195}
196
197//----------------------------------------------------- template initialization
198$template->set_filename('config', 'configuration.tpl');
199
200// TabSheet
201$tabsheet = new tabsheet();
202// TabSheet initialization
203$tabsheet->add('main', l10n('Main'), $conf_link.'main');
204$tabsheet->add('display', l10n('Display'), $conf_link.'display');
205$tabsheet->add('history', l10n('History'), $conf_link.'history');
206$tabsheet->add('comments', l10n('Comments'), $conf_link.'comments');
207$tabsheet->add('default', l10n('Guest Settings'), $conf_link.'default');
208// TabSheet selection
209$tabsheet->select($page['section']);
210// Assign tabsheet to template
211$tabsheet->assign();
212
213$action = get_root_url().'admin.php?page=configuration';
214$action.= '&amp;section='.$page['section'];
215
216$template->assign(
217  array(
218    'U_HELP' => get_root_url().'admin/popuphelp.php?page=configuration',
219    'F_ACTION'=>$action
220    ));
221
222switch ($page['section'])
223{
224  case 'main' :
225  {
226    $template->assign(
227      'main',
228      array(
229        'CONF_GALLERY_TITLE' => htmlspecialchars($conf['gallery_title']),
230        'CONF_PAGE_BANNER' => htmlspecialchars($conf['page_banner']),
231        'CONF_GALLERY_URL' => $conf['gallery_url'],
232        'week_starts_on_options' => array(
233          'sunday' => $lang['day'][0],
234          'monday' => $lang['day'][1],
235          ),
236        'week_starts_on_options_selected' => $conf['week_starts_on'],
237        ));
238
239    foreach ($main_checkboxes as $checkbox)
240    {
241      $template->append(
242          'main',
243          array(
244            $checkbox => $conf[$checkbox]
245            ),
246          true
247        );
248    }
249    break;
250  }
251  case 'history' :
252  {
253    //Necessary for merge_block_vars
254    foreach ($history_checkboxes as $checkbox)
255    {
256      $template->append(
257          'history',
258          array(
259            $checkbox => $conf[$checkbox]
260            ),
261          true
262        );
263    }
264    break;
265  }
266  case 'comments' :
267  {
268    $template->assign(
269      'comments',
270      array(
271        'NB_COMMENTS_PAGE'=>$conf['nb_comment_page'],
272        ));
273
274    foreach ($comments_checkboxes as $checkbox)
275    {
276      $template->append(
277          'comments',
278          array(
279            $checkbox => $conf[$checkbox]
280            ),
281          true
282        );
283    }
284    break;
285  }
286  case 'default' :
287  {
288    $edit_user = build_user($conf['guest_id'], false);
289    include_once(PHPWG_ROOT_PATH.'profile.php');
290
291    $errors = array();
292    if (save_profile_from_post($edit_user, $errors))
293    {
294      // Reload user
295      $edit_user = build_user($conf['guest_id'], false);
296      array_push($page['infos'], l10n('Information data registered in database'));
297    }
298    $page['errors'] = array_merge($page['errors'], $errors);
299
300    load_profile_in_template(
301      $action,
302      '',
303      $edit_user
304      );
305    $template->assign('default', array());
306    break;
307  }
308  case 'display' :
309  {
310    foreach ($display_checkboxes as $checkbox)
311    {
312      $template->append(
313          'display',
314          array(
315            $checkbox => $conf[$checkbox]
316            ),
317          true
318        );
319    }
320    $template->append(
321        'display',
322        array(
323          'picture_informations' => unserialize($conf['picture_informations'])
324          ),
325        true
326      );
327    break;
328  }
329}
330
331//----------------------------------------------------------- sending html code
332$template->assign_var_from_handle('ADMIN_CONTENT', 'config');
333?>
Note: See TracBrowser for help on using the repository browser.