source: trunk/admin/configuration.php @ 394

Last change on this file since 394 was 394, checked in by gweltas, 20 years ago
  • Template migration
  • Admin Control Panel migration
  • Category management
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 14.9 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// |                           configuration.php                           |
4// +-----------------------------------------------------------------------+
5// | application   : PhpWebGallery <http://phpwebgallery.net>              |
6// | branch        : BSF (Best So Far)                                     |
7// +-----------------------------------------------------------------------+
8// | file          : $RCSfile$
9// | last update   : $Date: 2004-03-26 17:08:09 +0000 (Fri, 26 Mar 2004) $
10// | last modifier : $Author: gweltas $
11// | revision      : $Revision: 394 $
12// +-----------------------------------------------------------------------+
13// | This program is free software; you can redistribute it and/or modify  |
14// | it under the terms of the GNU General Public License as published by  |
15// | the Free Software Foundation                                          |
16// |                                                                       |
17// | This program is distributed in the hope that it will be useful, but   |
18// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
19// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
20// | General Public License for more details.                              |
21// |                                                                       |
22// | You should have received a copy of the GNU General Public License     |
23// | along with this program; if not, write to the Free Software           |
24// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
25// | USA.                                                                  |
26// +-----------------------------------------------------------------------+
27
28if( !defined("PHPWG_ROOT_PATH") )
29{
30        die ("Hacking attempt!");
31}
32
33include_once( PHPWG_ROOT_PATH.'admin/include/isadmin.inc.php' );
34       
35$Caracs = array("¥" => "Y", "µ" => "u", "À" => "A", "Á" => "A", 
36                "Â" => "A", "Ã" => "A", "Ä" => "A", "Å" => "A", 
37                "Æ" => "A", "Ç" => "C", "È" => "E", "É" => "E", 
38                "Ê" => "E", "Ë" => "E", "Ì" => "I", "Í" => "I", 
39                "Î" => "I", "Ï" => "I", "Ð" => "D", "Ñ" => "N", 
40                "Ò" => "O", "Ó" => "O", "Ô" => "O", "Õ" => "O", 
41                "Ö" => "O", "Ø" => "O", "Ù" => "U", "Ú" => "U", 
42                "Û" => "U", "Ü" => "U", "Ý" => "Y", "ß" => "s", 
43                "à" => "a", "á" => "a", "â" => "a", "ã" => "a", 
44                "ä" => "a", "å" => "a", "æ" => "a", "ç" => "c", 
45                "è" => "e", "é" => "e", "ê" => "e", "ë" => "e", 
46                "ì" => "i", "í" => "i", "î" => "i", "ï" => "i", 
47                "ð" => "o", "ñ" => "n", "ò" => "o", "ó" => "o", 
48                "ô" => "o", "õ" => "o", "ö" => "o", "ø" => "o", 
49                "ù" => "u", "ú" => "u", "û" => "u", "ü" => "u", 
50                "ý" => "y", "ÿ" => "y");
51//------------------------------ verification and registration of modifications
52$error = array();
53if ( isset( $_POST['submit'] ) )
54{
55  $int_pattern = '/^\d+$/';
56  // deletion of site as asked
57  $site_deleted = false;
58  $query = 'SELECT id';
59  $query.= ' FROM '.SITES_TABLE;
60  $query.= " WHERE galleries_url <> './galleries/';";
61  $result = mysql_query( $query );
62  while ( $row = mysql_fetch_array( $result ) )
63  {
64    $site = 'delete_site_'.$row['id'];
65    if ( $_POST[$site] == 1 )
66    {
67      delete_site( $row['id'] );
68      $site_deleted = true;
69    }
70  }
71  // if any picture of this site were linked to another categories, we have
72  // to update the informations of those categories. To make it simple, we
73  // just update all the categories
74  if ( $site_deleted )
75  {
76    update_category( 'all' );
77    synchronize_all_users();
78  }
79  // thumbnail prefix must not contain accentuated characters
80  $old_prefix = $_POST['prefix_thumbnail'];
81  $prefix = strtr( $_POST['prefix_thumbnail'], $Caracs );
82  if ( $old_prefix != $prefix )
83  {
84    array_push( $error, $lang['conf_err_prefixe'] );
85  }
86  // mail must be formatted as follows : name@server.com
87  $pattern = '/^[\w-]+(\.[\w-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)+$/';
88  if ( !preg_match( $pattern, $_POST['mail_webmaster'] ) )
89  {
90    array_push( $error, $lang['conf_err_mail'] );
91  }
92  // periods must be integer values, they represents number of days
93  if ( !preg_match( $int_pattern, $_POST['short_period'] )
94       or !preg_match( $int_pattern, $_POST['long_period'] ) )
95  {
96    array_push( $error, $lang['err_periods'] );
97  }
98  else
99  {
100    // long period must be longer than short period
101    if ( $_POST['long_period'] <= $_POST['short_period']
102         or $_POST['short_period'] <= 0 )
103    {
104      array_push( $error, $lang['err_periods_2'] );
105    }
106  }
107  // session_id size must be an integer between 4 and 50
108  if ( !preg_match( $int_pattern, $_POST['session_id_size'] )
109       or $_POST['session_id_size'] < 4
110       or $_POST['session_id_size'] > 50 )
111  {
112    array_push( $error, $lang['conf_err_sid_size'] );
113  }
114  // session_time must be an integer between 5 and 60, in minutes
115  if ( !preg_match( $int_pattern, $_POST['session_time'] )
116       or $_POST['session_time'] < 5
117       or $_POST['session_time'] > 60 )
118  {
119    array_push( $error, $lang['conf_err_sid_time'] );
120  }
121  // the number of comments per page must be an integer between 5 and 50
122  // included
123  if ( !preg_match( $int_pattern, $_POST['nb_comment_page'] )
124       or $_POST['nb_comment_page'] < 5
125       or $_POST['nb_comment_page'] > 50 )
126  {
127    array_push( $error, $lang['conf_err_comment_number'] );
128  }
129  // the maximum upload filesize must be an integer between 10 and 1000
130  if ( !preg_match( $int_pattern, $_POST['upload_maxfilesize'] )
131       or $_POST['upload_maxfilesize'] < 10
132       or $_POST['upload_maxfilesize'] > 1000 )
133  {
134    array_push( $error, $lang['conf_err_upload_maxfilesize'] );
135  }
136  // the maximum width of uploaded pictures must be an integer superior to
137  // 10
138  if ( !preg_match( $int_pattern, $_POST['upload_maxwidth'] )
139       or $_POST['upload_maxwidth'] < 10 )
140  {
141    array_push( $error, $lang['conf_err_upload_maxwidth'] );
142  }
143  // the maximum height  of uploaded pictures must be an integer superior to
144  // 10
145  if ( !preg_match( $int_pattern, $_POST['upload_maxheight'] )
146       or $_POST['upload_maxheight'] < 10 )
147  {
148    array_push( $error, $lang['conf_err_upload_maxheight'] );
149  }
150  // the maximum width of uploaded thumbnails must be an integer superior to
151  // 10
152  if ( !preg_match( $int_pattern, $_POST['upload_maxwidth_thumbnail'] )
153       or $_POST['upload_maxwidth_thumbnail'] < 10 )
154  {
155    array_push( $error, $lang['conf_err_upload_maxwidth_thumbnail'] );
156  }
157  // the maximum width of uploaded thumbnails must be an integer superior to
158  // 10
159  if ( !preg_match( $int_pattern, $_POST['upload_maxheight_thumbnail'] )
160       or $_POST['upload_maxheight_thumbnail'] < 10 )
161  {
162    array_push( $error, $lang['conf_err_upload_maxheight_thumbnail'] );
163  }
164
165/*  if ( $_POST['maxwidth'] != ''
166       and ( !preg_match( $int_pattern, $_POST['maxwidth'] )
167             or $_POST['maxwidth'] < 50 ) )
168  {
169    array_push( $error, $lang['err_maxwidth'] );
170  }
171  if ( $_POST['maxheight']
172       and ( !preg_match( $int_pattern, $_POST['maxheight'] )
173             or $_POST['maxheight'] < 50 ) )
174  {
175    array_push( $error, $lang['err_maxheight'] );
176  }*/
177  // updating configuraiton if no error found
178  if ( count( $error ) == 0 )
179  {
180    $result = mysql_query( "SELECT * FROM ".CONFIG_TABLE );
181    while ( $row = mysql_fetch_array( $result ) )
182        {
183          $config_name = $row['param'];
184          $conf[$config_name] = ( isset($_POST[$config_name]) ) ? $_POST[$config_name] : $row['value'];
185      if ( isset( $_POST[$config_name] ) )
186      {
187        $query = 'UPDATE '.CONFIG_TABLE;
188        $query.= " SET value = '". str_replace("\'", "''", $conf[$config_name]) ;
189        $query.= "' WHERE param = '$config_name'";
190        mysql_query( $query );
191      }
192    }
193  }
194}
195
196$access = ($conf['access']=='free')?'ACCESS_FREE':'ACCESS_RESTRICTED'; 
197$log = ($conf['log']=='true')?'HISTORY_YES':'HISTORY_NO'; 
198$mail_notif = ($conf['mail_notification']=='true')?'MAIL_NOTIFICATION_YES':'MAIL_NOTIFICATION_NO'; 
199$show_comments = ($conf['show_comments']=='true')?'SHOW_COMMENTS_YES':'SHOW_COMMENTS_NO';
200$comments_all = ($conf['comments_forall']=='true')?'COMMENTS_ALL_YES':'COMMENTS_ALL_NO';
201$comments_validation = ($conf['comments_validation']=='true')?'VALIDATE_COMMENTS_YES':'VALIDATE_COMMENTS_NO';
202$expand = ($conf['auto_expand']=='true')?'EXPAND_TREE_YES':'EXPAND_TREE_NO';
203$nb_comments = ($conf['show_nb_comments']=='true')?'NB_COMMENTS_YES':'NB_COMMENTS_NO';
204$upload = ($conf['upload_available']=='true')?'UPLOAD_YES':'UPLOAD_NO';
205$cookie = ($conf['authorize_cookies']=='true')?'COOKIE_YES':'COOKIE_NO';
206
207//----------------------------------------------------- template initialization
208$template->set_filenames( array('config'=>'admin/configuration.tpl') );
209
210$template->assign_vars(array(
211  'ADMIN_NAME'=>$conf['webmaster'],
212  'ADMIN_MAIL'=>$conf['mail_webmaster'],
213  'THUMBNAIL_PREFIX'=>$conf['prefix_thumbnail'],
214  'NB_COMMENTS_PAGE'=>$conf['nb_comment_page'],
215  'LANG_SELECT'=>language_select($conf['default_lang'], 'default_lang'),
216  'NB_IMAGE_LINE'=>$conf['nb_image_line'],
217  'NB_ROW_PAGE'=>$conf['nb_line_page'],
218  'STYLE_SELECT'=>style_select($conf['default_style'], 'default_style'),
219  'SHORT_PERIOD'=>$conf['short_period'],
220  'LONG_PERIOD'=>$conf['long_period'],
221  'UPLOAD_MAXSIZE'=>$conf['upload_maxfilesize'],
222  'UPLOAD_MAXWIDTH'=>$conf['upload_maxwidth'],
223  'UPLOAD_MAXHEIGHT'=>$conf['upload_maxheight'],
224  'TN_UPLOAD_MAXWIDTH'=>$conf['upload_maxwidth_thumbnail'],
225  'TN_UPLOAD_MAXHEIGHT'=>$conf['upload_maxheight_thumbnail'],
226  'SESSION_LENGTH'=>$conf['session_time'],
227  'SESSION_ID_SIZE'=>$conf['session_id_size'],
228 
229  $access=>'checked="checked"',
230  $log=>'checked="checked"',
231  $mail_notif=>'checked="checked"',
232  $show_comments=>'checked="checked"',
233  $comments_all=>'checked="checked"',
234  $comments_validation=>'checked="checked"',
235  $expand=>'checked="checked"',
236  $nb_comments=>'checked="checked"',
237  $upload=>'checked="checked"',
238  $cookie=>'checked="checked"',
239 
240  'L_CONFIRM'=>$lang['conf_confirmation'],
241  'L_CONF_GENERAL'=>$lang['conf_general_title'],
242  'L_ADMIN_NAME'=>$lang['conf_general_webmaster'],
243  'L_ADMIN_NAME_INFO'=>$lang['conf_general_webmaster_info'],
244  'L_ADMIN_MAIL'=>$lang['conf_general_mail'],
245  'L_ADMIN_MAIL_INFO'=>$lang['conf_general_mail_info'],
246  'L_THUMBNAIL_PREFIX'=>$lang['conf_general_prefix'],
247  'L_THUMBNAIL_PREFIX_INFO'=>$lang['conf_general_prefix_info'],
248  'L_ACCESS'=>$lang['conf_general_access'],
249  'L_ACCESS_INFO'=>$lang['conf_general_access_info'],
250  'L_ACCESS_FREE'=>$lang['conf_general_access_1'],
251  'L_ACCESS_RESTRICTED'=>$lang['conf_general_access_2'],
252  'L_CONF_HISTORY'=>$lang['history'],
253  'L_CONF_HISTORY_INFO'=>$lang['conf_general_log_info'],
254  'L_MAIL_NOTIFICATION'=>$lang['conf_general_mail_notification'],
255  'L_MAIL_NOTIFICATION_INFO'=>$lang['conf_general_mail_notification_info'],
256  'L_CONF_COMMENTS'=>$lang['conf_comments_title'],
257  'L_SHOW_COMMENTS'=>$lang['conf_comments_show_comments'],
258  'L_SHOW_COMMENTS_INFO'=>$lang['conf_comments_show_comments_info'],
259  'L_COMMENTS_ALL'=>$lang['conf_comments_forall'],
260  'L_COMMENTS_ALL_INFO'=>$lang['conf_comments_forall_info'],
261  'L_NB_COMMENTS_PAGE'=>$lang['conf_comments_comments_number'],
262  'L_NB_COMMENTS_PAGE_INFO'=>$lang['conf_comments_comments_number_info'],
263  'L_VALIDATE_COMMENTS'=>$lang['conf_comments_validation'],
264  'L_VALIDATE_COMMENTS_INFO'=>$lang['conf_comments_validation_info'],
265  'L_ABILITIES_SETTINGS'=>$lang['conf_default_title'],
266  'L_LANG_SELECT'=>$lang['customize_language'],
267  'L_LANG_SELECT_INFO'=>$lang['conf_default_language_info'],
268  'L_NB_IMAGE_LINE'=>$lang['customize_nb_image_per_row'],
269  'L_NB_IMAGE_LINE_INFO'=>$lang['conf_default_nb_image_per_row_info'],
270  'L_NB_ROW_PAGE'=>$lang['customize_nb_row_per_page'],
271  'L_NB_ROW_PAGE_INFO'=>$lang['conf_default_nb_row_per_page_info'],
272  'L_STYLE_SELECT'=>$lang['customize_theme'],
273  'L_STYLE_SELECT_INFO'=>$lang['conf_default_theme_info'],
274  'L_SHORT_PERIOD'=>$lang['customize_short_period'],
275  'L_SHORT_PERIOD_INFO'=>$lang['conf_default_short_period_info'],
276  'L_LONG_PERIOD'=>$lang['customize_long_period'],
277  'L_LONG_PERIOD_INFO'=>$lang['conf_default_long_period_info'],
278  'L_EXPAND_TREE'=>$lang['customize_expand'],
279  'L_EXPAND_TREE_INFO'=>$lang['conf_default_expand_info'],
280  'L_NB_COMMENTS'=>$lang['customize_show_nb_comments'],
281  'L_NB_COMMENTS_INFO'=>$lang['conf_default_show_nb_comments_info'],
282  'L_AUTH_UPLOAD'=>$lang['conf_upload_available'],
283  'L_AUTH_UPLOAD_INFO'=>$lang['conf_upload_available_info'],
284  'L_CONF_UPLOAD'=>$lang['conf_upload_title'],
285  'L_UPLOAD_MAXSIZE'=>$lang['conf_upload_maxfilesize'],
286  'L_UPLOAD_MAXSIZE_INFO'=>$lang['conf_upload_maxfilesize_info'],
287  'L_UPLOAD_MAXWIDTH'=>$lang['conf_upload_maxwidth'],
288  'L_UPLOAD_MAXWIDTH_INFO'=>$lang['conf_upload_maxwidth_info'],
289  'L_UPLOAD_MAXHEIGHT'=>$lang['conf_upload_maxheight'],
290  'L_UPLOAD_MAXHEIGHT_INFO'=>$lang['conf_upload_maxheight_info'],
291  'L_TN_UPLOAD_MAXWIDTH'=>$lang['conf_upload_maxwidth_thumbnail'],
292  'L_TN_UPLOAD_MAXWIDTH_INFO'=>$lang['conf_upload_maxwidth_thumbnail_info'],
293  'L_TN_UPLOAD_MAXHEIGHT'=>$lang['conf_upload_maxheight_thumbnail'],
294  'L_TN_UPLOAD_MAXHEIGHT_INFO'=>$lang['conf_upload_maxheight_thumbnail'],
295  'L_CONF_SESSION'=>$lang['conf_session_title'],
296  'L_COOKIE'=>$lang['conf_session_cookie'],
297  'L_COOKIE_INFO'=>$lang['conf_session_cookie_info'],
298  'L_SESSION_LENGTH'=>$lang['conf_session_time'],
299  'L_SESSION_LENGTH_INFO'=>$lang['conf_session_time_info'],
300  'L_SESSION_ID_SIZE'=>$lang['conf_session_size'],
301  'L_SESSION_ID_SIZE_INFO'=>$lang['conf_session_size_info'],
302  'L_YES'=>$lang['yes'],
303  'L_NO'=>$lang['no'],
304  'L_SUBMIT'=>$lang['submit'],
305 
306  'F_ACTION'=>add_session_id(PHPWG_ROOT_PATH.'admin.php?page=configuration')
307  ));
308
309//-------------------------------------------------------------- errors display
310if ( sizeof( $error ) != 0 )
311{
312  $template->assign_block_vars('errors',array());
313  for ( $i = 0; $i < sizeof( $error ); $i++ )
314  {
315    $template->assign_block_vars('errors.error',array('ERROR'=>$error[$i]));
316  }
317}
318elseif ( isset( $_POST['submit'] ) )
319{
320  $template->assign_block_vars('confirmation' ,array());
321}
322//------------------------------------------------ remote sites administration
323$query = 'select id,galleries_url';
324$query.= ' from '.SITES_TABLE;
325$query.= " where galleries_url <> './galleries/';";
326$result = mysql_query( $query );
327if ( mysql_num_rows( $result ) > 0 )
328{
329  $vtp->addSession( $sub, 'remote_sites' );
330  $i = 0;
331  while ( $row = mysql_fetch_array( $result ) )
332  {
333    $vtp->addSession( $sub, 'site' );
334    $vtp->setVar( $sub, 'site.url', $row['galleries_url'] );
335    $vtp->setVar( $sub, 'site.id', $row['id'] );
336    if ( $i == 0 )
337    {
338      $vtp->addSession( $sub, 'rowspan' );
339      $vtp->setVar( $sub, 'rowspan.nb_sites', mysql_num_rows( $result ) );
340      $vtp->closeSession( $sub, 'rowspan' );
341    }
342    $vtp->closeSession( $sub, 'site' );
343    $i++;
344  }
345  $vtp->closeSession( $sub, 'remote_sites' );
346}
347//----------------------------------------------------------- sending html code
348$template->assign_var_from_handle('ADMIN_CONTENT', 'config');
349?>
Note: See TracBrowser for help on using the repository browser.