Changeset 26 for trunk/profile.php


Ignore:
Timestamp:
Jul 21, 2003, 9:47:14 PM (21 years ago)
Author:
z0rglub
Message:

* empty log message *

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/profile.php

    r17 r26  
    2929check_cat_id( $_GET['cat'] );
    3030//------------------------------------------------------ update & customization
    31 $infos = array( 'nb_image_line', 'nb_line_page', 'theme', 'language',
     31$infos = array( 'nb_image_line', 'nb_line_page', 'language',
    3232                'maxwidth', 'maxheight', 'expand', 'show_nb_comments',
    3333                'short_period', 'long_period', 'template', 'mail_address' );
     
    3636//    - on teste si chacune des variables est passée en argument à la page
    3737//    - ce qui signifie que l'on doit venir de la page de personnalisation
    38 $error = array();
     38$errors = array();
    3939if ( isset( $_POST['submit'] ) )
    4040{
    41   $i = 0;
    42   if ( $_POST['maxwidth'] != '' )
    43   {
    44     if ( !ereg( "^[0-9]{2,}$", $_POST['maxwidth'] )
    45          || $_POST['maxwidth'] < 50 )
    46     {
    47       $error[$i++] = $lang['err_maxwidth'];
    48     }
    49   }
    50   if ( $_POST['maxheight'] != '' )
    51   {
    52     if ( !ereg( "^[0-9]{2,}$", $_POST['maxheight'] )
    53          || $_POST['maxheight'] < 50 )
    54     {
    55       $error[$i++] = $lang['err_maxheight'];
    56     }
    57   }
    58   // les période doivent être des entiers, il représentent des nombres de jours
    59   if ( !ereg( "^[0-9]*$", $_POST['short_period'] )
    60        || !ereg("^[0-9]*$", $_POST['long_period'] ) )
    61   {
    62     $error[$i++] = $lang['err_periods'];
     41  $int_pattern = '/^\d+$/';
     42  if ( $_POST['maxwidth'] != ''
     43       and ( !preg_match( $int_pattern, $_POST['maxwidth'] )
     44             or $_POST['maxwidth'] < 50 ) )
     45  {
     46    array_push( $errors, $lang['err_maxwidth'] );
     47  }
     48  if ( $_POST['maxheight']
     49       and ( !preg_match( $int_pattern, $_POST['maxheight'] )
     50             or $_POST['maxheight'] < 50 ) )
     51  {
     52    array_push( $errors, $lang['err_maxheight'] );
     53  }
     54  // periods must be integer values, they represents number of days
     55  if ( !preg_match( $int_pattern, $_POST['short_period'] )
     56       or !preg_match( $int_pattern, $_POST['long_period'] ) )
     57  {
     58    array_push( $errors, $lang['err_periods'] );
    6359  }
    6460  else
    6561  {
    66     // la période longue doit être supérieure à la période courte
     62    // long period must be longer than short period
    6763    if ( $_POST['long_period'] <= $_POST['short_period']
    68          || $_POST['short_period'] <= 0 )
    69     {
    70       $error[$i++] = $lang['err_periods_2'];
    71     }
    72   }
    73   // le mail doit être conforme à qqch du type : nom@serveur.com
    74   if( $_POST['mail_address'] != ""
    75       && !ereg( "([_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)+)",
    76                 $_POST['mail_address'] ) )
    77   {
    78     $error[$i++] = $lang['reg_err_mail_address'];
     64         or $_POST['short_period'] <= 0 )
     65    {
     66      array_push( $errors, $lang['err_periods_2'] );
     67    }
     68  }
     69  $mail_error = validate_mail_address( $_POST['mail_address'] );
     70  if ( $mail_error != '' )
     71  {
     72    array_push( $errors, $mail_error );
    7973  }
    8074  if ( $_POST['use_new_pwd'] == 1 )
    8175  {
    82     // on vérifie que le password rentré correspond bien
    83     // à la confirmation faite par l'utilisateur
     76    // password must be the same as its confirmation
    8477    if ( $_POST['password'] != $_POST['passwordConf'] )
    8578    {
    86       $error[$i++] = $lang['reg_err_pass'];
     79      array_push( $errors, $lang['reg_err_pass'] );
    8780    }
    8881  }
    8982
    90   if ( sizeof( $error ) == 0 )
    91   {
    92     $tab_theme = explode( ' - ', $_POST['theme'] );
    93     $_POST['theme'] = $tab_theme[0].'/'.$tab_theme[1];
    94 
    95     $query = 'update '.PREFIX_TABLE.'users';
    96     $query.= ' set';
    97     for ( $i = 0; $i < sizeof( $infos ); $i++ )
    98     {
    99       if ( $i > 0 )
    100       {
    101         $query.= ',';
    102       }
    103       else
    104       {
    105         $query.= ' ';
    106       }
    107       $query.= $infos[$i];
     83  if ( count( $errors ) == 0 )
     84  {
     85    $query = 'UPDATE '.PREFIX_TABLE.'users';
     86    $query.= ' SET ';
     87    foreach ( $infos as $i => $info ) {
     88      if ( $i > 0 ) $query.= ',';
     89      $query.= $info;
    10890      $query.= ' = ';
    109       if ( $_POST[$infos[$i]] == '' )
    110       {
    111         $query.= 'NULL';
    112       }
    113       else
    114       {
    115         $query.= "'".$_POST[$infos[$i]]."'";
    116       }
    117     }
    118     $query.= ' where id = '.$user['id'];
     91      if ( $_POST[$info] == '' ) $query.= 'NULL';
     92      else                       $query.= "'".$_POST[$info]."'";
     93    }
     94    $query.= ' WHERE id = '.$user['id'];
    11995    $query.= ';';
    12096    mysql_query( $query );
     
    12298    if ( $_POST['use_new_pwd'] == 1 )
    12399    {
    124       $query = 'update '.PREFIX_TABLE.'users';
    125       $query.= " set password = '".md5( $_POST['password'] )."'";
    126       $query.= ' where id = '.$user['id'];
     100      $query = 'UPDATE '.PREFIX_TABLE.'users';
     101      $query.= " SET password = '".md5( $_POST['password'] )."'";
     102      $query.= ' WHERE id = '.$user['id'];
    127103      $query.= ';';
    128104      mysql_query( $query );
    129       echo '<br />'.$query;
    130105    }
    131106    // redirection
     
    133108    if ( $page['cat'] == 'search' )
    134109    {
    135       $url.= '&search='.$_GET['search'].'&amp;mode='.$_GET['mode'];
     110      $url.= '&search='.$_GET['search'].'&mode='.$_GET['mode'];
    136111    }
    137112    $url = add_session_id( $url, true );
     
    157132$vtp->setGlobalVar( $handle, 'form_action', add_session_id( $url ) );
    158133//-------------------------------------------------------------- errors display
    159 if ( sizeof( $error ) != 0 )
     134if ( count( $errors ) != 0 )
    160135{
    161136  $vtp->addSession( $handle, 'errors' );
    162   for ( $i = 0; $i < sizeof( $error ); $i++ )
    163   {
     137  foreach ( $errors as $error ) {
    164138    $vtp->addSession( $handle, 'li' );
    165     $vtp->setVar( $handle, 'li.li', $error[$i] );
     139    $vtp->setVar( $handle, 'li.li', $error );
    166140    $vtp->closeSession( $handle, 'li' );
    167141  }
     
    221195    $vtp->setVar( $handle, 'option.option', $option[$i] );
    222196    if ( $option[$i] == $user['template'] )
    223     {
    224       $vtp->setVar( $handle, 'option.selected', ' selected="selected"' );
    225     }
    226     $vtp->closeSession( $handle, 'option' );
    227   }
    228   $vtp->closeSession( $handle, 'select' );
    229   $vtp->closeSession( $handle, 'line' );
    230 }
    231 //----------------------------------------------------------------------- theme
    232 if ( in_array( 'theme', $infos ) )
    233 {
    234   $vtp->addSession( $handle, 'line' );
    235   $vtp->setVar( $handle, 'line.name', $lang['customize_theme'] );
    236   $vtp->addSession( $handle, 'select' );
    237   $vtp->setVar( $handle, 'select.name', 'theme' );
    238   $option = get_themes( './theme/' );
    239   for ( $i = 0; $i < sizeof( $option ); $i++ )
    240   {
    241     $vtp->addSession( $handle, 'option' );
    242     $vtp->setVar( $handle, 'option.option', $option[$i] );
    243     if ( $option[$i] == str_replace( '/', ' - ', $user['theme'] ) )
    244197    {
    245198      $vtp->setVar( $handle, 'option.selected', ' selected="selected"' );
Note: See TracChangeset for help on using the changeset viewer.