source: trunk/admin/configuration.php @ 12831

Last change on this file since 12831 was 12782, checked in by mistic100, 12 years ago

bug:1711 sort photos by name

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