Skip to content

Commit

Permalink
MDL-14053, include custom profile fields when export user info, see t…
Browse files Browse the repository at this point in the history
…racker, merged from MOODLE_19_STABLE
  • Loading branch information
dongsheng committed Apr 23, 2008
1 parent 6f76816 commit c79106c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 11 deletions.
10 changes: 7 additions & 3 deletions admin/uploaduser.php
Expand Up @@ -66,9 +66,13 @@
$bulknurl = $CFG->wwwroot.'/'.$CFG->admin.'/user/user_bulk.php';

// array of all valid fields for validation
$STD_FIELDS = array('firstname', 'lastname', 'username', 'email', 'city', 'country', 'lang', 'auth', 'timezone', 'mailformat', 'maildisplay', 'maildigest', 'htmleditor',
'ajax', 'autosubscribe', 'mnethostid', 'institution', 'department', 'idnumber', 'icq', 'phone1', 'phone2', 'address', 'url', 'description',
'oldusername', 'emailstop', 'deleted', 'password');
$STD_FIELDS = array('id', 'firstname', 'lastname', 'username', 'email',
'city', 'country', 'lang', 'auth', 'timezone', 'mailformat',
'maildisplay', 'maildigest', 'htmleditor', 'ajax', 'autosubscribe',
'mnethostid', 'institution', 'department', 'idnumber', 'skype',
'msn', 'aim', 'yahoo', 'icq', 'phone1', 'phone2', 'address',
'url', 'description', 'oldusername', 'emailstop', 'deleted',
'password');

$PRF_FIELDS = array();

Expand Down
38 changes: 30 additions & 8 deletions admin/user/user_bulk_download.php
Expand Up @@ -17,16 +17,31 @@
redirect($return);
}


if ($format) {
$fields = array('id' => 'id',
'username' => get_string('username'),
'email' => get_string('email'),
'firstname' => get_string('firstname'),
'lastname' => get_string('lastname'),
'idnumber' => get_string('idnumber'),
'city' => get_string('city'),
'country' => get_string('country'));
'username' => 'username',
'email' => 'email',
'firstname' => 'firstname',
'lastname' => 'lastname',
'idnumber' => 'idnumber',
'institution' => 'institution',
'department' => 'department',
'phone1' => 'phone1',
'phone2' => 'phone2',
'city' => 'city',
'url' => 'url',
'icq' => 'icq',
'skype' => 'skype',
'aim' => 'aim',
'yahoo' => 'yahoo',
'msn' => 'msn',
'country' => 'country');

if ($extrafields = get_records_select('user_info_field')) {
foreach ($extrafields as $n=>$v){
$fields['profile_field_'.$v->shortname] = 'profile_field_'.$v->name;
}
}

switch ($format) {
case 'csv' : user_download_csv($fields);
Expand Down Expand Up @@ -56,6 +71,7 @@ function user_download_ods($fields) {
global $CFG, $SESSION;

require_once("$CFG->libdir/odslib.class.php");
require_once($CFG->dirroot.'/user/profile/lib.php');

$filename = clean_filename(get_string('users').'.ods');

Expand All @@ -77,6 +93,7 @@ function user_download_ods($fields) {
continue;
}
$col = 0;
profile_load_data($user);
foreach ($fields as $field=>$unused) {
$worksheet[0]->write($row, $col, $user->$field);
$col++;
Expand All @@ -92,6 +109,7 @@ function user_download_xls($fields) {
global $CFG, $SESSION;

require_once("$CFG->libdir/excellib.class.php");
require_once($CFG->dirroot.'/user/profile/lib.php');

$filename = clean_filename(get_string('users').'.xls');

Expand All @@ -113,6 +131,7 @@ function user_download_xls($fields) {
continue;
}
$col = 0;
profile_load_data($user);
foreach ($fields as $field=>$unused) {
$worksheet[0]->write($row, $col, $user->$field);
$col++;
Expand All @@ -126,6 +145,8 @@ function user_download_xls($fields) {

function user_download_csv($fields) {
global $CFG, $SESSION;

require_once($CFG->dirroot.'/user/profile/lib.php');

$filename = clean_filename(get_string('users').'.csv');

Expand All @@ -149,6 +170,7 @@ function user_download_csv($fields) {
if (!$user = get_record('user', 'id', $userid)) {
continue;
}
profile_load_data($user);
foreach ($fields as $field=>$unused) {
$row[] = str_replace($delimiter, $encdelim, $user->$field);
}
Expand Down

0 comments on commit c79106c

Please sign in to comment.