source: trunk/admin/configuration.php @ 11285

Last change on this file since 11285 was 11285, checked in by mistic100, 13 years ago

feature:2330 ability to hide the "new" icon for recent photos

  • Property svn:eol-style set to LF
File size: 13.3 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    'index_new_icon',
82    'picture_metadata_icon',
83    'picture_slideshow_icon',
84    'picture_favorite_icon',
85    'picture_download_icon',
86    'picture_navigation_icons',
87    'picture_navigation_thumb',
88    'picture_menu',
89  );
90
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',
101    'average_rate',
102    'privacy_level',
103  );
104 
105$order_options = array(
106    ' ORDER BY date_available DESC, file ASC, id ASC' => 'date_available DESC, file ASC, id ASC',
107    ' ORDER BY file DESC, date_available DESC' => 'file DESC, date_available DESC',
108    'custom' => l10n('Custom'),
109  );
110
111//------------------------------ verification and registration of modifications
112if (isset($_POST['submit']))
113{
114  $int_pattern = '/^\d+$/';
115
116  switch ($page['section'])
117  {
118    case 'main' :
119    {
120      $order_regex = '#^(( *)(id|file|name|date_available|date_creation|hit|average_rate|comment|author|filesize|width|height|high_filesize|high_width|high_height) (ASC|DESC),{1}){1,}$#';
121      // process 'order_by_perso' string
122      if ($_POST['order_by'] == 'custom' AND !empty($_POST['order_by_perso']))
123      {
124        $_POST['order_by'] = str_ireplace(
125          array('order by ', 'asc', 'desc'),
126          array(null, 'ASC', 'DESC'),
127          trim($_POST['order_by_perso'])
128          );
129       
130        if (preg_match($order_regex, $_POST['order_by'].','))
131        {
132          $_POST['order_by'] = ' ORDER BY '.$_POST['order_by'];
133        }
134        else
135        {
136          array_push($page['errors'], l10n('Invalid order string').' &laquo; '.$_POST['order_by'].' &raquo;');
137        }
138      }
139      else if ($_POST['order_by'] == 'custom')
140      {
141        array_push($page['errors'], l10n('Invalid order string'));
142      }
143      // process 'order_by_inside_category_perso' string
144      if ($_POST['order_by_inside_category'] == 'as_order_by')
145      {
146        $_POST['order_by_inside_category'] = $_POST['order_by'];
147      }
148      else if ($_POST['order_by_inside_category'] == 'custom' AND !empty($_POST['order_by_inside_category_perso']))
149      {
150        $_POST['order_by_inside_category'] = str_ireplace(
151          array('order by ', 'asc', 'desc'),
152          array(null, 'ASC', 'DESC'),
153          trim($_POST['order_by_inside_category_perso'])
154          );
155       
156        if (preg_match($order_regex, $_POST['order_by_inside_category'].','))
157        {
158          $_POST['order_by_inside_category'] = ' ORDER BY '.$_POST['order_by_inside_category'];
159        }
160        else
161        {
162          array_push($page['errors'], l10n('Invalid order string').' &laquo; '.$_POST['order_by_inside_category'].' &raquo;');
163        }
164      }
165      else if ($_POST['order_by_inside_category'] == 'custom')
166      {
167        array_push($page['errors'], l10n('Invalid order string'));
168      }
169     
170      if (empty($_POST['gallery_locked']) and $conf['gallery_locked'])
171      {
172        $tpl_var = & $template->get_template_vars('header_msgs');
173        $msg_key = array_search(l10n('The gallery is locked for maintenance. Please, come back later.'), $tpl_var);
174        unset($tpl_var[$msg_key]);
175      }
176      elseif (!empty($_POST['gallery_locked']) and !$conf['gallery_locked'])
177      {
178        $template->append('header_msgs', l10n('The gallery is locked for maintenance. Please, come back later.'));
179      }
180      foreach( $main_checkboxes as $checkbox)
181      {
182        $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
183      }
184      break;
185    }
186    case 'history' :
187    {
188      foreach( $history_checkboxes as $checkbox)
189      {
190        $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
191      }
192      break;
193    }
194    case 'comments' :
195    {
196      // the number of comments per page must be an integer between 5 and 50
197      // included
198      if (!preg_match($int_pattern, $_POST['nb_comment_page'])
199           or $_POST['nb_comment_page'] < 5
200           or $_POST['nb_comment_page'] > 50)
201      {
202        array_push($page['errors'], l10n('The number of comments a page must be between 5 and 50 included.'));
203      }
204      foreach( $comments_checkboxes as $checkbox)
205      {
206        $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
207      }
208      break;
209    }
210    case 'default' :
211    {
212      // Never go here
213      break;
214    }
215    case 'display' :
216    {
217      foreach( $display_checkboxes as $checkbox)
218      {
219        $_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
220      }
221      foreach( $display_info_checkboxes as $checkbox)
222      {
223        $_POST['picture_informations'][$checkbox] =
224          empty($_POST['picture_informations'][$checkbox])? false : true;
225      }
226      $_POST['picture_informations'] = addslashes(serialize($_POST['picture_informations']));
227      break;
228    }
229  }
230
231  // updating configuration if no error found
232  if (count($page['errors']) == 0)
233  {
234    //echo '<pre>'; print_r($_POST); echo '</pre>';
235    $result = pwg_query('SELECT param FROM '.CONFIG_TABLE);
236    while ($row = pwg_db_fetch_assoc($result))
237    {
238      if (isset($_POST[$row['param']]))
239      {
240        $value = $_POST[$row['param']];
241
242        if ('gallery_title' == $row['param'])
243        {
244          if (!$conf['allow_html_descriptions'])
245          {
246            $value = strip_tags($value);
247          }
248        }
249
250        $query = '
251UPDATE '.CONFIG_TABLE.'
252SET value = \''. str_replace("\'", "''", $value).'\'
253WHERE param = \''.$row['param'].'\'
254;';
255        pwg_query($query);
256      }
257    }
258    array_push($page['infos'], l10n('Information data registered in database'));
259  }
260
261  //------------------------------------------------------ $conf reinitialization
262  load_conf_from_db();
263}
264
265//----------------------------------------------------- template initialization
266$template->set_filename('config', 'configuration.tpl');
267
268// TabSheet
269$tabsheet = new tabsheet();
270// TabSheet initialization
271$tabsheet->add('main', l10n('Main'), $conf_link.'main');
272$tabsheet->add('display', l10n('Display'), $conf_link.'display');
273$tabsheet->add('history', l10n('History'), $conf_link.'history');
274$tabsheet->add('comments', l10n('Comments'), $conf_link.'comments');
275$tabsheet->add('default', l10n('Guest Settings'), $conf_link.'default');
276// TabSheet selection
277$tabsheet->select($page['section']);
278// Assign tabsheet to template
279$tabsheet->assign();
280
281$action = get_root_url().'admin.php?page=configuration';
282$action.= '&amp;section='.$page['section'];
283
284$template->assign(
285  array(
286    'U_HELP' => get_root_url().'admin/popuphelp.php?page=configuration',
287    'F_ACTION'=>$action
288    ));
289
290switch ($page['section'])
291{
292  case 'main' :
293  {
294    // process 'order_by' string
295    if (array_key_exists($conf['order_by'], $order_options))
296    {
297      $order_by_selected = $conf['order_by'];
298      $order_by_perso = null;
299    }
300    else
301    {
302      $order_by_selected = 'custom';
303      $order_by_perso = str_replace(' ORDER BY ', null, $conf['order_by']);
304    }
305    // process 'order_by_inside_category' string
306    if ($conf['order_by_inside_category'] == $conf['order_by'])
307    {
308      $order_by_inside_category_selected = 'as_order_by';
309      $order_by_inside_category_perso = null;
310    }
311    else if (array_key_exists($conf['order_by_inside_category'], $order_options))
312    {
313      $order_by_inside_category_selected = $conf['order_by_inside_category'];
314      $order_by_inside_category_perso = null;
315    }
316    else
317    {
318      $order_by_inside_category_selected = 'custom';
319      $order_by_inside_category_perso = str_replace(' ORDER BY ', null, $conf['order_by_inside_category']);
320    }
321     
322    $template->assign(
323      'main',
324      array(
325        'CONF_GALLERY_TITLE' => htmlspecialchars($conf['gallery_title']),
326        'CONF_PAGE_BANNER' => htmlspecialchars($conf['page_banner']),
327        'CONF_GALLERY_URL' => $conf['gallery_url'],
328        'week_starts_on_options' => array(
329          'sunday' => $lang['day'][0],
330          'monday' => $lang['day'][1],
331          ),
332        'week_starts_on_options_selected' => $conf['week_starts_on'],
333        'order_by_options' => $order_options,
334        'order_by_selected' => $order_by_selected,
335        'order_by_perso' => $order_by_perso,
336        'order_by_inside_category_options' => 
337          array_merge(
338            array('as_order_by'=>l10n('As default order')), 
339            $order_options
340            ),
341        'order_by_inside_category_selected' => $order_by_inside_category_selected,
342        'order_by_inside_category_perso' => $order_by_inside_category_perso,
343        ));
344
345    foreach ($main_checkboxes as $checkbox)
346    {
347      $template->append(
348          'main',
349          array(
350            $checkbox => $conf[$checkbox]
351            ),
352          true
353        );
354    }
355    break;
356  }
357  case 'history' :
358  {
359    //Necessary for merge_block_vars
360    foreach ($history_checkboxes as $checkbox)
361    {
362      $template->append(
363          'history',
364          array(
365            $checkbox => $conf[$checkbox]
366            ),
367          true
368        );
369    }
370    break;
371  }
372  case 'comments' :
373  {
374    $template->assign(
375      'comments',
376      array(
377        'NB_COMMENTS_PAGE'=>$conf['nb_comment_page'],
378        ));
379
380    foreach ($comments_checkboxes as $checkbox)
381    {
382      $template->append(
383          'comments',
384          array(
385            $checkbox => $conf[$checkbox]
386            ),
387          true
388        );
389    }
390    break;
391  }
392  case 'default' :
393  {
394    $edit_user = build_user($conf['guest_id'], false);
395    include_once(PHPWG_ROOT_PATH.'profile.php');
396
397    $errors = array();
398    if (save_profile_from_post($edit_user, $errors))
399    {
400      // Reload user
401      $edit_user = build_user($conf['guest_id'], false);
402      array_push($page['infos'], l10n('Information data registered in database'));
403    }
404    $page['errors'] = array_merge($page['errors'], $errors);
405
406    load_profile_in_template(
407      $action,
408      '',
409      $edit_user
410      );
411    $template->assign('default', array());
412    break;
413  }
414  case 'display' :
415  {
416    foreach ($display_checkboxes as $checkbox)
417    {
418      $template->append(
419          'display',
420          array(
421            $checkbox => $conf[$checkbox]
422            ),
423          true
424        );
425    }
426    $template->append(
427        'display',
428        array(
429          'picture_informations' => unserialize($conf['picture_informations'])
430          ),
431        true
432      );
433    break;
434  }
435}
436
437//----------------------------------------------------------- sending html code
438$template->assign_var_from_handle('ADMIN_CONTENT', 'config');
439?>
Note: See TracBrowser for help on using the repository browser.