source: trunk/admin/configuration.php @ 12879

Last change on this file since 12879 was 12879, checked in by plg, 12 years ago

feature 2548, multiple size:

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