diff --git a/lib/tablelib.php b/lib/tablelib.php index d2ec1e38642..426731560b0 100644 --- a/lib/tablelib.php +++ b/lib/tablelib.php @@ -448,7 +448,8 @@ class flexible_table { if (($sortcol = optional_param($this->request[TABLE_VAR_SORT], '', PARAM_ALPHANUMEXT)) && $this->is_sortable($sortcol) && empty($this->sess->collapse[$sortcol]) && - (isset($this->columns[$sortcol]) || in_array($sortcol, array('firstname', 'lastname')) && isset($this->columns['fullname']))) { + (isset($this->columns[$sortcol]) || in_array($sortcol, get_all_user_name_fields()) + && isset($this->columns['fullname']))) { if (array_key_exists($sortcol, $this->sess->sortby)) { // This key already exists somewhere. Change its sortorder and bring it to the top. @@ -571,7 +572,7 @@ class flexible_table { if (isset($this->columns[$column])) { continue; // This column is OK. } - if (in_array($column, array('firstname', 'lastname')) && + if (in_array($column, get_all_user_name_fields()) && isset($this->columns['fullname'])) { continue; // This column is OK. } @@ -1186,7 +1187,7 @@ class flexible_table { if ($nameformat == 'language') { $nameformat = get_string('fullnamedisplay'); } - $requirednames = order_in_string(array('firstname', 'lastname'), $nameformat); + $requirednames = order_in_string(get_all_user_name_fields(), $nameformat); if (!empty($requirednames)) { if ($this->is_sortable($column)) { diff --git a/user/index.php b/user/index.php index e8875bd16b1..5db6f95ff14 100644 --- a/user/index.php +++ b/user/index.php @@ -410,11 +410,9 @@ list($esql, $params) = get_enrolled_sql($context, null, $currentgroup, true); $joins = array("FROM {user} u"); $wheres = array(); -$extrasql = get_extra_user_fields_sql($context, 'u', '', array( - 'id', 'username', 'firstname', 'lastname', 'email', 'city', 'country', - 'picture', 'lang', 'timezone', 'maildisplay', 'imagealt', 'lastaccess')); - $mainuserfields = user_picture::fields('u', array('username', 'email', 'city', 'country', 'lang', 'timezone', 'maildisplay')); +$alreadyretrievedfields = explode(',', $mainuserfields); +$extrasql = get_extra_user_fields_sql($context, 'u', '', $alreadyretrievedfields); if ($isfrontpage) { $select = "SELECT $mainuserfields, u.lastaccess$extrasql";