From b4d8351ee706aeae699a28a88c08aef49e09c64e Mon Sep 17 00:00:00 2001 From: Cristian Fasanando Date: Thu, 4 Dec 2008 23:49:14 +0100 Subject: [PATCH] [svn r17075] Fixed bug in user fields, not displayed the default value in profile and add user, and you could modify this values (See FS#3307) --- documentation/changelog.html | 5 ++-- main/admin/user_add.php | 49 ++++++++++++++++++++++++++++++-- main/inc/lib/usermanager.lib.php | 38 ++++++++++++++----------- 3 files changed, 70 insertions(+), 22 deletions(-) diff --git a/documentation/changelog.html b/documentation/changelog.html index 5e21084d0a..d0bc097a06 100644 --- a/documentation/changelog.html +++ b/documentation/changelog.html @@ -94,9 +94,10 @@
  • Fixed bug whereby the repeated agenda items in groups were visible to all (FS#3095)
  • Fixed bug whereby e-mails sent did not have the standard syntax (SVN#16708)
  • Fixed bug whereby an empty institution name gave a useless output in the header (SVN#16710)
  • -
  • Fixed bug whereby questions ordering was broken when deleting one question in the middle (SVN#16879)
  • +
  • Fixed bug whereby questions ordering was broken when deleting one question in the middle (SVN#16879)
  • +
  • Fixed bug in user fields, not displayed the default value in profile and add user, and you could modify this values
  • Fixed bug in link (see FS#3306)
  • -
  • Improved display of human resource manager option (see FS#3304)
  • +
  • Improved display of human resource manager option (see FS#3304)

  • CSS changes

    diff --git a/main/admin/user_add.php b/main/admin/user_add.php index e3aff4c762..45a06209ad 100644 --- a/main/admin/user_add.php +++ b/main/admin/user_add.php @@ -1,4 +1,4 @@ -addGroup($group, 'max_member_group', null, '', false); $form->addElement('radio','active',get_lang('ActiveAccount'),get_lang('Active'),1); $form->addElement('radio','active','',get_lang('Inactive'),0); - - // EXTRA FIELDS $extra = UserManager::get_extra_fields(0,50,5,'ASC'); +$extra_data = UserManager::get_extra_user_data(0,true); foreach($extra as $id => $field_details) { switch($field_details[2]) @@ -241,6 +240,49 @@ foreach($extra as $id => $field_details) $form->addElement('datepicker', 'extra_'.$field_details[1], $field_details[3]); $form->applyFilter('theme', 'trim'); break; + case USER_FIELD_TYPE_DOUBLE_SELECT: + foreach ($field_details[8] as $key=>$element) + { + if ($element[2][0] == '*') + { + $values['*'][$element[0]] = str_replace('*','',$element[2]); + } + else + { + $values[0][$element[0]] = $element[2]; + } + } + + $group=''; + $group[] =& HTML_QuickForm::createElement('select', 'extra_'.$field_details[1],'',$values[0],''); + $group[] =& HTML_QuickForm::createElement('select', 'extra_'.$field_details[1].'*','',$values['*'],''); + $form->addGroup($group, 'extra_'.$field_details[1], $field_details[3], ' '); + if ($field_details[7] == 0) $form->freeze('extra_'.$field_details[1]); + + // recoding the selected values for double : if the user has selected certain values, we have to assign them to the correct select form + if (key_exists('extra_'.$field_details[1], $extra_data)) + { + // exploding all the selected values (of both select forms) + $selected_values = explode(';',$extra_data['extra_'.$field_details[1]]); + $extra_data['extra_'.$field_details[1]] =array(); + + // looping through the selected values and assigning the selected values to either the first or second select form + foreach ($selected_values as $key=>$selected_value) + { + if (key_exists($selected_value,$values[0])) + { + $extra_data['extra_'.$field_details[1]]['extra_'.$field_details[1]] = $selected_value; + } + else + { + $extra_data['extra_'.$field_details[1]]['extra_'.$field_details[1].'*'] = $selected_value; + } + } + } + break; + case USER_FIELD_TYPE_DIVIDER: + $form->addElement('static',$field_details[1], '
    '.$field_details[3].''); + break; } } @@ -258,6 +300,7 @@ $defaults['expiration_date']['F']=date('m',$time); $defaults['expiration_date']['Y']=date('Y',$time); $defaults['radio_expiration_date'] = 0; $defaults['status'] = STUDENT; +$defaults = array_merge($defaults,$extra_data); $form->setDefaults($defaults); // Submit button $form->addElement('submit', 'submit', get_lang('Add')); diff --git a/main/inc/lib/usermanager.lib.php b/main/inc/lib/usermanager.lib.php index 1725d7e478..74b22b7863 100644 --- a/main/inc/lib/usermanager.lib.php +++ b/main/inc/lib/usermanager.lib.php @@ -1,4 +1,4 @@ -$rowf['id'], 1=>$rowf['field_variable'], @@ -893,10 +894,11 @@ class UserManager 2=>(empty($rowo['option_display_text'])?'':$rowo['option_display_text']), 3=>$rowo['option_order'] ); - } + } } } } + return $fields; } @@ -1087,26 +1089,20 @@ class UserManager field_display_text = '".Database::escape_string($fieldtitle)."', field_default_value = '".Database::escape_string($fielddefault)."', tms = FROM_UNIXTIME($time) - WHERE field_id = '".Database::escape_string($fieldid)."'"; - //$result = api_sql_query($sql,__FILE__,__LINE__); + WHERE id = '".Database::escape_string($fieldid)."'"; + $result = api_sql_query($sql,__FILE__,__LINE__); // we create an array with all the options (will be used later in the script) - if($fieldtype == USER_FIELD_TYPE_DOUBLE_SELECT) - { + if ($fieldtype == USER_FIELD_TYPE_DOUBLE_SELECT) { $twolist = explode('|', $fieldoptions); $counter = 0; - foreach ($twolist as $individual_list) - { + foreach ($twolist as $individual_list) { $splitted_individual_list = split(';',$individual_list); - foreach ($splitted_individual_list as $individual_list_option) - { + foreach ($splitted_individual_list as $individual_list_option) { //echo 'counter:'.$counter; - if ($counter == 0) - { + if ($counter == 0) { $list[] = trim($individual_list_option); - } - else - { + } else { $list[] = str_repeat('*',$counter).trim($individual_list_option); } } @@ -1122,6 +1118,7 @@ class UserManager // Remove all the field options (and also the choices of the user) that are NOT in the new list of options $sql = "SELECT * FROM $table_field_options WHERE option_value NOT IN ('".implode("','", $list)."') AND field_id = '".Database::escape_string($fieldid)."'"; $result = api_sql_query($sql,__FILE__,__LINE__); + $return['deleted_options'] = 0; while ($row = Database::fetch_array($result)) { // deleting the option @@ -1145,7 +1142,6 @@ class UserManager { $key = array_search(trim($row['option_display_text']),$list); unset($list[$key]); - echo 'unset '.$key.$list[$key]; } } @@ -1210,14 +1206,22 @@ class UserManager " AND user_id=".$user_id; $resu = api_sql_query($sqlu,__FILE__,__LINE__); $fval = ''; + // get default value + $sql_df = "SELECT field_default_value as fval_df " . + " FROM $t_uf " . + " WHERE id=".$row['id']; + $res_df = api_sql_query($sql_df,__FILE__,__LINE__); if(Database::num_rows($resu)>0) { - $rowu = Database::fetch_array($resu); + $rowu = Database::fetch_array($resu); $fval = $rowu['fval']; if($row['type'] == USER_FIELD_TYPE_SELECT_MULTIPLE) { $fval = split(';',$rowu['fval']); } + } else { + $row_df = Database::fetch_array($res_df); + $fval = $row_df['fval_df']; } if($prefix) {