Changeset 4003


Ignore:
Timestamp:
Oct 9, 2009, 10:47:33 AM (11 years ago)
Author:
patdenice
Message:

Issue 1079: re-refactoring of code ;-)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/profile.php

    r4001 r4003  
    4141  trigger_action('loc_begin_profile');
    4242
    43   // Reset to default (Guest) custom settings
     43// Reset to default (Guest) custom settings
    4444  if (isset($_POST['reset_to_default']))
    4545  {
    46     global $conf;
     46    // mass_updates function
     47    include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
     48
     49    $fields = array(
     50      'nb_image_line', 'nb_line_page', 'maxwidth', 'maxheight', 'expand',
     51      'show_nb_comments', 'show_nb_hits', 'recent_period', 'show_nb_hits'
     52      );
     53
    4754    // Get the Guest custom settings
    4855    $query = '
    49 SELECT * FROM '.USER_INFOS_TABLE.'
    50 WHERE user_id = '.$conf['default_user_id'].
    51 ';';
    52 
     56SELECT '.implode(',', $fields).'
     57  FROM '.USER_INFOS_TABLE.'
     58  WHERE user_id = '.$conf['default_user_id'].'
     59;';
    5360    $result = pwg_query($query);
    54    
    55     $cache['default_user'] = mysql_fetch_assoc($result);
    56    
    57     $default_user = array();
    58    
    59     foreach ($cache['default_user'] as $name => $value)
    60     {
    61       // If the field is true or false, the variable is transformed into a
    62       // boolean value.
    63       if ($value == 'true' or $value == 'false')
    64       {
    65         $default_user[$name] = get_boolean($value);
    66       }
    67       else
    68       {
    69         $default_user[$name] = $value;
    70       }
    71     }
    72     // Changing $userdata array values with default ones       
    73     $userdata_params = array('nb_image_line', 'nb_line_page',
    74                               'maxwidth', 'maxheight', 'expand',
    75                               'show_nb_comments', 'show_nb_hits');
    76     foreach ($userdata_params as $key)     
    77     {
    78       $userdata[$key] = $default_user[$key];
    79       $_POST[$key] = $userdata[$key];
    80     }
    81   }     
     61    $default_user = mysql_fetch_assoc($result);
     62    $userdata = array_merge($userdata, $default_user);
     63
     64    mass_updates(
     65      USER_INFOS_TABLE,
     66      array('primary' => array('user_id'), 'update' => $fields),
     67      array($userdata)
     68      );
     69  }
     70
    8271  save_profile_from_post($userdata, $errors);
    8372
Note: See TracChangeset for help on using the changeset viewer.