source: trunk/admin/configuration.php @ 12930

Last change on this file since 12930 was 12922, checked in by mistic100, 12 years ago

update Piwigo headers to 2012, last change before the expected (or not) apocalypse

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