Ignore:
Timestamp:
Sep 20, 2004, 12:26:41 AM (20 years ago)
Author:
gweltas
Message:
  • dispatch of configuration
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/configuration.php

    r517 r527  
    2626// +-----------------------------------------------------------------------+
    2727
    28 if (!defined('PHPWG_ROOT_PATH'))
    29 {
    30   die ("Hacking attempt!");
    31 }
    32 include_once(PHPWG_ROOT_PATH.'admin/include/isadmin.inc.php');
     28if( !defined("PHPWG_ROOT_PATH") )
     29{
     30        die ("Hacking attempt!");
     31}
     32
     33include_once( PHPWG_ROOT_PATH.'admin/include/isadmin.inc.php' );
    3334//-------------------------------------------------------- sections definitions
    3435if (!isset($_GET['section']))
     
    4142}
    4243
    43 // templates for fields definitions
    44 $true_false = array('type' => 'radio',
    45                     'options' => array('true' => $lang['yes'],
    46                                        'false' => $lang['no']));
    47 $textfield = array('type' => 'textfield');
    48 
    49 $nb_image_row = array();
    50 foreach ($conf['nb_image_row'] as $value)
    51 {
    52   $nb_image_row[$value] = $value;
    53 }
    54 
    55 $nb_row_page = array();
    56 foreach ($conf['nb_row_page'] as $value)
    57 {
    58   $nb_row_page[$value] = $value;
    59 }
    60 
    61 $sections = array(
    62   'general' => array(
    63     'mail_webmaster' => $textfield,
    64     'prefix_thumbnail' => $textfield,
    65     'access' => array('type' => 'radio',
    66                       'options' => array(
    67                         'free' => $lang['conf_general_access_1'],
    68                         'restricted' => $lang['conf_general_access_2'])),
    69     'log' => $true_false,
    70     'mail_notification' => $true_false,
    71    ),
    72   'comments' => array(
    73     'show_comments' => $true_false,
    74     'comments_forall' => $true_false,
    75     'nb_comment_page' => array('type' => 'textfield','size' => 2),
    76     'comments_validation' => $true_false
    77    ),
    78   'default' => array(
    79     'default_language' => array('type' => 'select',
    80                                 'options' => get_languages()),
    81     'nb_image_line' => array('type' => 'radio','options' => $nb_image_row),
    82     'nb_line_page' => array('type' => 'radio','options' => $nb_row_page),
    83     'default_template' => array('type' => 'select',
    84                                 'options' => get_templates()),
    85     'recent_period' => array('type' => 'textfield','size' => 3),
    86     'auto_expand' => $true_false,
    87     'show_nb_comments' => $true_false
    88    ),
    89   'upload' => array(
    90     'upload_available' => $true_false,
    91     'upload_maxfilesize' => array('type' => 'textfield','size' => 4),
    92     'upload_maxwidth' => array('type' => 'textfield','size' => 4),
    93     'upload_maxheight' => array('type' => 'textfield','size' => 4),
    94     'upload_maxwidth_thumbnail' => array('type' => 'textfield','size' => 4),
    95     'upload_maxheight_thumbnail' => array('type' => 'textfield','size' => 4)
    96    ),
    97   'session' => array(
    98     'authorize_cookies' => $true_false,
    99     'session_time' => array('type' => 'textfield','size' => 2),
    100     'session_id_size' => array('type' => 'textfield','size' => 2)
    101    ),
    102   'metadata' => array(
    103     'use_exif' => $true_false,
    104     'use_iptc' => $true_false,
    105     'show_exif' => $true_false,
    106     'show_iptc' => $true_false
    107    )
    108  );
    10944//------------------------------------------------------ $conf reinitialization
    11045$result = mysql_query('SELECT param,value FROM '.CONFIG_TABLE);
     
    11449  // if the parameter is present in $_POST array (if a form is submited), we
    11550  // override it with the submited value
    116   if (isset($_POST[$row['param']]))
     51  if (isset($_POST[$row['param']]) && !isset($_POST['reset']))
    11752  {
    11853    $conf[$row['param']] = $_POST[$row['param']];
    11954  }
    120 }
     55}                                         
    12156//------------------------------ verification and registration of modifications
    12257$errors = array();
    12358if (isset($_POST['submit']))
    12459{
    125 //   echo '<pre>';
    126 //   print_r($_POST);
    127 //   echo '</pre>';
    128  
    12960  $int_pattern = '/^\d+$/';
    13061  switch ($page['section'])
     
    13566      if (!preg_match('/^[\w-]*$/', $_POST['prefix_thumbnail']))
    13667      {
    137         array_push($errors, $lang['conf_general_prefix_thumbnail_error']);
     68        array_push($errors, $lang['conf_prefix_thumbnail_error']);
    13869      }
    13970      // mail must be formatted as follows : name@server.com
     
    14172      if (!preg_match($pattern, $_POST['mail_webmaster']))
    14273      {
    143         array_push($errors, $lang['conf_general_mail_webmaster_error']);
     74        array_push($errors, $lang['conf_mail_webmaster_error']);
    14475      }
    14576      break;
     
    15384           or $_POST['nb_comment_page'] > 50)
    15485      {
    155         array_push($errors, $lang['conf_comments_nb_comment_page_error']);
     86        array_push($errors, $lang['conf_nb_comment_page_error']);
    15687      }
    15788      break;
     
    16394          or $_POST['recent_period'] <= 0)
    16495      {
    165         array_push($errors, $lang['conf_default_recent_period_error']);
     96        array_push($errors, $lang['periods_error']);
    16697      }
    16798      break;
     
    174105          or $_POST['upload_maxfilesize'] > 1000)
    175106      {
    176         array_push($errors, $lang['conf_upload_upload_maxfilesize_error']);
     107        array_push($errors, $lang['conf_upload_maxfilesize_error']);
    177108      }
    178109     
     
    186117          or $_POST[$field] < 10)
    187118        {
    188           array_push($errors, $lang['conf_upload_'.$field.'_error']);
     119          array_push($errors, $lang['conf_'.$field.'_error']);
    189120        }
    190121      }
     
    198129          or $_POST['session_id_size'] > 50)
    199130      {
    200         array_push($errors, $lang['conf_session_session_id_size_error']);
     131        array_push($errors, $lang['conf_session_size_error']);
    201132      }
    202133      // session_time must be an integer between 5 and 60, in minutes
     
    205136          or $_POST['session_time'] > 60)
    206137      {
    207         array_push($errors, $lang['conf_session_session_time_error']);
     138        array_push($errors, $lang['conf_session_time_error']);
    208139      }
    209140      break;
     
    219150      if (isset($_POST[$row['param']]))
    220151      {
    221         $query = '
    222 UPDATE '.CONFIG_TABLE.'
    223   SET value = \''. str_replace("\'", "''", $_POST[$row['param']]).'\'
    224   WHERE param = \''.$row['param'].'\'
    225 ;';
     152        $query = 'UPDATE '.CONFIG_TABLE.
     153                  ' SET value = \''. str_replace("\'", "''", $_POST[$row['param']]).
     154                  '\' WHERE param = \''.$row['param'].'\';';
    226155        mysql_query($query);
    227156      }
     
    229158  }
    230159}
     160
    231161//----------------------------------------------------- template initialization
    232 $template->set_filenames(array('config'=>'admin/configuration.tpl'));
    233 
    234 $action = PHPWG_ROOT_PATH.'admin.php?page=configuration';
    235 $action.= '&amp;section='.$page['section'];
    236 
    237 $template->assign_vars(
    238   array(
    239     'L_CONFIRM'=>$lang['conf_confirmation'],
    240     'L_SUBMIT'=>$lang['submit'],
    241     'F_ACTION'=>add_session_id($action)
    242    )
    243  );
    244 
    245 $base_url = PHPWG_ROOT_PATH.'admin.php?page=configuration&amp;section=';
    246 foreach (array_keys($sections) as $section)
    247 {
    248   if ($section == $page['section'])
    249   {
    250     $class = 'opened';
    251   }
    252   else
    253   {
    254     $class = '';
    255   }
     162$template->set_filenames( array('config'=>'admin/configuration.tpl') );
     163
     164$template->assign_vars(array( 
     165  'L_CONFIRM'=>$lang['conf_confirmation'],
     166  'L_YES'=>$lang['yes'],
     167  'L_NO'=>$lang['no'],
     168  'L_SUBMIT'=>$lang['submit'],
     169  'L_RESET'=>$lang['reset'],
    256170 
    257   $template->assign_block_vars(
    258     'confmenu_item',
    259     array(
    260       'CLASS' => $class,
    261       'URL' => add_session_id($base_url.$section),
    262       'NAME' => $lang['conf_'.$section.'_title']
    263      ));
    264 }
    265 
    266 $fields = $sections[$page['section']];
    267 foreach ($fields as $field_name => $field)
    268 {
    269   $template->assign_block_vars(
    270     'line',
    271     array(
    272       'NAME' => $lang['conf_'.$page['section'].'_'.$field_name],
    273       'INFO' => $lang['conf_'.$page['section'].'_'.$field_name.'_info']
    274      ));
    275   if ($field['type'] == 'textfield')
    276   {
    277     if (isset($field['size']))
    278     {
    279       $size = $field['size'];
    280     }
    281     else
    282     {
    283       $size = '';
    284     }
    285    
    286     $template->assign_block_vars(
    287       'line.textfield',
    288       array(
    289         'NAME' => $field_name,
    290         'VALUE' => $conf[$field_name],
    291         'SIZE' => $size
    292        ));
    293   }
    294   else if ($field['type'] == 'radio')
    295   {
    296     foreach ($field['options'] as $option_value => $option)
    297     {
    298       if ($conf[$field_name] == $option_value)
    299       {
    300         $checked = 'checked="checked"';
    301       }
    302       else
    303       {
    304         $checked = '';
    305       }
    306      
    307       $template->assign_block_vars(
    308         'line.radio',
    309         array(
    310           'NAME' => $field_name,
    311           'VALUE' => $option_value,
    312           'CHECKED' => $checked,
    313           'OPTION' => $option
    314          ));
    315     }
    316   }
    317   else if ($field['type'] == 'select')
    318   {
    319     $template->assign_block_vars(
    320       'line.select',
    321       array(
    322         'NAME' => $field_name
    323        ));
    324     foreach ($field['options'] as $option_value => $option)
    325     {
    326       if ($conf[$field_name] == $option_value)
    327       {
    328         $selected = 'selected="selected"';
    329       }
    330       else
    331       {
    332         $selected = '';
    333       }
    334      
    335       $template->assign_block_vars(
    336         'line.select.select_option',
    337         array(
    338           'VALUE' => $option_value,
    339           'SELECTED' => $selected,
    340           'OPTION' => $option
    341          ));
    342     }
    343   }
    344 }
     171  'F_ACTION'=>add_session_id(PHPWG_ROOT_PATH.'admin.php?page=configuration&amp;section='.$page['section'])
     172  ));
     173
     174switch ($page['section'])
     175  {
     176    case 'general' :
     177    {
     178      $access_free = ($conf['access']=='free')?'checked="checked"':'';
     179          $access_restricted = ($conf['access']=='restricted')?'checked="checked"':'';
     180      $history_yes = ($conf['log']=='true')?'checked="checked"':'';
     181          $history_no  = ($conf['log']=='false')?'checked="checked"':'';
     182          $notif_yes = ($conf['mail_notification']=='true')?'checked="checked"':'';
     183          $notif_no = ($conf['mail_notification']=='false')?'checked="checked"':'';
     184
     185          $template->assign_block_vars('general',array(
     186            'L_CONF_TITLE'=>$lang['conf_general_title'],
     187                'L_CONF_MAIL'=>$lang['conf_mail_webmaster'],
     188                'L_CONF_MAIL_INFO'=>$lang['conf_mail_webmaster_info'],
     189                'L_CONF_TN_PREFIX'=>$lang['conf_prefix'],
     190                'L_CONF_TN_PREFIX_INFO'=>$lang['conf_prefix_info'],
     191                'L_CONF_ACCESS'=>$lang['conf_access'],
     192                'L_CONF_ACCESS_INFO'=>$lang['conf_access_info'],
     193                'L_CONF_ACCESS_FREE'=>$lang['free'],
     194                'L_CONF_ACCESS_RESTRICTED'=>$lang['restricted'],
     195                'L_CONF_HISTORY'=>$lang['history'],
     196                'L_CONF_HISTORY_INFO'=>$lang['conf_log_info'],
     197                'L_CONF_NOTIFICATION'=>$lang['conf_notification'],
     198                'L_CONF_NOTIFICATION_INFO'=>$lang['conf_notification_info'],
     199               
     200                'ADMIN_MAIL'=>$conf['mail_webmaster'],
     201                'THUMBNAIL_PREFIX'=>$conf['prefix_thumbnail'],
     202                'ACCESS_FREE'=>$access_free,
     203                'ACCESS_RESTRICTED'=>$access_restricted,
     204                'HISTORY_YES'=>$history_yes,
     205                'HISTORY_NO'=>$history_no,
     206                'NOTIFICATION_YES'=>$notif_yes,
     207                'NOTIFICATION_NO'=>$notif_no
     208          ));
     209          break;
     210        }
     211        case 'comments' :
     212    {
     213          $show_yes = ($conf['show_comments']=='true')?'checked="checked"':'';
     214          $show_no = ($conf['show_comments']=='false')?'checked="checked"':'';
     215      $all_yes = ($conf['comments_forall']=='true')?'checked="checked"':'';
     216          $all_no  = ($conf['comments_forall']=='false')?'checked="checked"':'';
     217          $validate_yes = ($conf['comments_validation']=='true')?'checked="checked"':'';
     218          $validate_no = ($conf['comments_validation']=='false')?'checked="checked"':'';
     219
     220          $template->assign_block_vars('comments',array(
     221            'L_CONF_TITLE'=>$lang['conf_comments_title'],
     222                'L_CONF_SHOW_COMMENTS'=>$lang['conf_show_comments'],
     223                'L_CONF_SHOW_COMMENTS_INFO'=>$lang['conf_show_comments_info'],
     224                'L_CONF_COMMENTS_ALL'=>$lang['conf_comments_forall'],
     225                'L_CONF_COMMENTS_ALL_INFO'=>$lang['conf_comments_forall_info'],
     226                'L_CONF_NB_COMMENTS_PAGE'=>$lang['conf_nb_comment_page'],
     227                'L_CONF_NB_COMMENTS_PAGE_INFO'=>$lang['conf_nb_comment_page'],
     228                'L_CONF_VALIDATE'=>$lang['conf_comments_validation'],
     229                'L_CONF_VALIDATE_INFO'=>$lang['conf_comments_validation_info'],
     230                               
     231                'NB_COMMENTS_PAGE'=>$conf['nb_comment_page'],
     232                'SHOW_COMMENTS_YES'=>$show_yes,
     233                'SHOW_COMMENTS_NO'=>$show_no,
     234                'COMMENTS_ALL_YES'=>$all_yes,
     235                'COMMENTS_ALL_NO'=>$all_no,
     236                'VALIDATE_YES'=>$validate_yes,
     237                'VALIDATE_NO'=>$validate_no
     238          ));
     239          break;
     240        }
     241        case 'default' :
     242    {
     243          $show_yes = ($conf['show_nb_comments']=='true')?'checked="checked"':'';
     244          $show_no = ($conf['show_nb_comments']=='false')?'checked="checked"':'';
     245      $expand_yes = ($conf['auto_expand']=='true')?'checked="checked"':'';
     246          $expand_no  = ($conf['auto_expand']=='false')?'checked="checked"':'';
     247
     248          $template->assign_block_vars('default',array(
     249            'L_CONF_TITLE'=>$lang['conf_default_title'],
     250                'L_CONF_LANG'=>$lang['language'],
     251                'L_CONF_LANG_INFO'=>$lang['conf_default_language_info'],
     252                'L_NB_IMAGE_LINE'=>$lang['nb_image_per_row'],
     253                'L_NB_IMAGE_LINE_INFO'=>$lang['conf_nb_image_line_info'],
     254                'L_NB_ROW_PAGE'=>$lang['nb_row_per_page'],
     255                'L_NB_ROW_PAGE_INFO'=>$lang['conf_nb_line_page_info'],
     256                'L_CONF_STYLE'=>$lang['theme'],
     257                'L_CONF_STYLE_INFO'=>$lang['conf_default_theme_info'],
     258                'L_CONF_RECENT'=>$lang['recent_period'],
     259                'L_CONF_RECENT_INFO'=>$lang['conf_recent_period_info'],
     260                'L_CONF_EXPAND'=>$lang['auto_expand'],
     261                'L_CONF_EXPAND_INFO'=>$lang['conf_default_expand_info'],
     262                'L_NB_COMMENTS'=>$lang['show_nb_comments'],
     263                'L_NB_COMMENTS_INFO'=>$lang['conf_show_nb_comments_info'],
     264 
     265                'CONF_LANG_SELECT'=>language_select($conf['default_language'], 'default_language'),
     266                'NB_IMAGE_LINE'=>$conf['nb_image_line'],
     267                'NB_ROW_PAGE'=>$conf['nb_line_page'],
     268                'CONF_STYLE_SELECT'=>style_select($conf['default_template'], 'default_template'),
     269                'CONF_RECENT'=>$conf['recent_period'],
     270                'NB_COMMENTS_PAGE'=>$conf['nb_comment_page'],
     271                'EXPAND_YES'=>$expand_yes,
     272                'EXPAND_NO'=>$expand_no,
     273                'SHOW_COMMENTS_YES'=>$show_yes,
     274                'SHOW_COMMENTS_NO'=>$show_no
     275          ));
     276          break;
     277        }
     278        case 'upload' :
     279    {
     280          $upload_yes = ($conf['upload_available']=='true')?'checked="checked"':'';
     281          $upload_no = ($conf['upload_available']=='false')?'checked="checked"':'';
     282         
     283          $template->assign_block_vars('upload',array(
     284            'L_CONF_TITLE'=>$lang['conf_upload_title'],
     285                'L_CONF_UPLOAD'=>$lang['conf_authorize_upload'],
     286                'L_CONF_UPLOAD_INFO'=>$lang['conf_authorize_upload_info'],
     287                'L_CONF_MAXSIZE'=>$lang['conf_upload_maxfilesize'],
     288                'L_CONF_MAXSIZE_INFO'=>$lang['conf_upload_maxfilesize_info'],
     289                'L_CONF_MAXWIDTH'=>$lang['conf_upload_maxwidth'],
     290                'L_CONF_MAXWIDTH_INFO'=>$lang['conf_upload_maxwidth_info'],
     291                'L_CONF_MAXHEIGHT'=>$lang['conf_upload_maxheight'],
     292                'L_CONF_MAXHEIGHT_INFO'=>$lang['conf_upload_maxheight_info'],
     293                'L_CONF_TN_MAXWIDTH'=>$lang['conf_upload_tn_maxwidth'],
     294                'L_CONF_TN_MAXWIDTH_INFO'=>$lang['conf_upload_tn_maxwidth_info'],
     295                'L_CONF_TN_MAXHEIGHT'=>$lang['conf_upload_tn_maxheight'],
     296                'L_CONF_TN_MAXHEIGHT_INFO'=>$lang['conf_upload_tn_maxheight_info'],
     297                               
     298                'UPLOAD_MAXSIZE'=>$conf['upload_maxfilesize'],
     299                'UPLOAD_MAXWIDTH'=>$conf['upload_maxwidth'],
     300                'UPLOAD_MAXHEIGHT'=>$conf['upload_maxheight'],
     301                'TN_UPLOAD_MAXWIDTH'=>$conf['upload_maxwidth_thumbnail'],
     302                'TN_UPLOAD_MAXHEIGHT'=>$conf['upload_maxheight_thumbnail'],
     303                'UPLOAD_YES'=>$upload_yes,
     304                'UPLOAD_NO'=>$upload_no
     305          ));
     306          break;
     307        }
     308        case 'session' :
     309    {
     310          $cookie_yes = ($conf['upload_available']=='true')?'checked="checked"':'';
     311          $cookie_no = ($conf['upload_available']=='false')?'checked="checked"':'';
     312         
     313          $template->assign_block_vars('session',array(
     314            'L_CONF_TITLE'=>$lang['conf_session_title'],
     315                'L_CONF_COOKIE'=>$lang['conf_cookies'],
     316                'L_CONF_COOKIE_INFO'=>$lang['conf_cookies_info'],
     317                'L_SESSION_LENGTH'=>$lang['conf_session_time'],
     318                'L_SESSION_LENGTH_INFO'=>$lang['conf_session_time_info'],
     319                'L_SESSION_ID_SIZE'=>$lang['conf_session_size'],
     320                'L_SESSION_ID_SIZE_INFO'=>$lang['conf_session_size_info'],
     321
     322                'SESSION_LENGTH'=>$conf['session_time'],
     323                'SESSION_ID_SIZE'=>$conf['session_id_size'],
     324                'COOKIE_YES'=>$cookie_yes,
     325                'COOKIE_NO'=>$cookie_no
     326          ));
     327          break;
     328        }
     329        case 'metadata' :
     330    {
     331          $exif_yes = ($conf['use_exif']=='true')?'checked="checked"':'';
     332          $exif_no = ($conf['use_exif']=='false')?'checked="checked"':'';
     333          $iptc_yes = ($conf['use_iptc']=='true')?'checked="checked"':'';
     334          $iptc_no = ($conf['use_iptc']=='false')?'checked="checked"':'';
     335          $show_exif_yes = ($conf['show_exif']=='true')?'checked="checked"':'';
     336          $show_exif_no = ($conf['show_exif']=='false')?'checked="checked"':'';
     337          $show_iptc_yes = ($conf['show_iptc']=='true')?'checked="checked"':'';
     338          $show_iptc_no = ($conf['show_iptc']=='false')?'checked="checked"':'';
     339         
     340          $template->assign_block_vars('metadata',array(
     341            'L_CONF_TITLE'=>$lang['conf_metadata_title'],
     342                'L_CONF_EXIF'=>$lang['conf_use_exif'],
     343                'L_CONF_EXIF_INFO'=>$lang['conf_use_exif_info'],
     344                'L_CONF_IPTC'=>$lang['conf_use_iptc'],
     345                'L_CONF_IPTC_INFO'=>$lang['conf_use_iptc_info'],
     346                'L_CONF_SHOW_EXIF'=>$lang['conf_show_exif'],
     347                'L_CONF_SHOW_EXIF_INFO'=>$lang['conf_show_exif_info'],
     348                'L_CONF_SHOW_IPTC'=>$lang['conf_show_iptc'],
     349                'L_CONF_SHOW_IPTC_INFO'=>$lang['conf_show_iptc_info'],
     350
     351                'USE_EXIF_YES'=>$exif_yes,
     352                'USE_EXIF_NO'=>$exif_no,
     353                'USE_IPTC_YES'=>$iptc_yes,
     354                'USE_IPTC_NO'=>$iptc_no,
     355                'SHOW_EXIF_YES'=>$show_exif_yes,
     356                'SHOW_EXIF_NO'=>$show_exif_no,
     357                'SHOW_IPTC_YES'=>$show_iptc_yes,
     358                'SHOW_IPTC_NO'=>$show_iptc_no
     359          ));
     360          break;
     361        }
     362  }
    345363//-------------------------------------------------------------- errors display
    346 if (count($errors) != 0)
     364if ( sizeof( $errors ) != 0 )
    347365{
    348366  $template->assign_block_vars('errors',array());
    349   foreach ($errors as $error)
    350   {
    351     $template->assign_block_vars('errors.error',array('ERROR'=>$error));
    352   }
    353 }
    354 else if (isset($_POST['submit']))
     367  for ( $i = 0; $i < sizeof( $errors ); $i++ )
     368  {
     369    $template->assign_block_vars('errors.error',array('ERROR'=>$errors[$i]));
     370  }
     371}
     372elseif ( isset( $_POST['submit'] ) )
    355373{
    356374  $template->assign_block_vars('confirmation' ,array());
Note: See TracChangeset for help on using the changeset viewer.