Ejemplo n.º 1
0
function user_download_xls($fields) {
    $hier = new hierarchy();
    $costcenters = $hier->get_assignedcostcenters();

    global $CFG, $DB;
    require_once("$CFG->libdir/excellib.class.php");
    $filename = clean_filename('Users.xls');
    $workbook = new MoodleExcelWorkbook('-');
    $workbook->send($filename);
    $worksheet = array();
    $worksheet[0] = $workbook->add_worksheet('');
    $col = 0;
    foreach ($fields as $fieldname) {
        $worksheet[0]->write(0, $col, $fieldname);
        $col++;
    }

    $sheetrow = 1;
    $myuser = users::getInstance();

    $users = $DB->get_records_sql("SELECT u.id, u.username, u.email, u.firstname, u.lastname, u.city, u.country,
                                            u.lastaccess, u.confirmed, u.mnethostid, u.suspended FROM {user} u, {local_users} lu
                                            WHERE lu.userid = u.id ");

    foreach ($users as $user) {
        $rid = $myuser->get_rolename($user->id);
        $post = new stdclass();
        $post->firstname = $user->firstname;
        $post->lastname = $user->lastname;
        $post->email = $user->email;

        $post->costcentername = $myuser->get_costcenternames($user);
        $post->roleid = $myuser->get_rolename($user->id);
        $col = 0;
        foreach ($fields as $fieldname) {
            $worksheet[0]->write($sheetrow, $col, $post->$fieldname);
            $col++;
        }
        $sheetrow++;
    }

    $workbook->close();
    die;
}
Ejemplo n.º 2
0
    }
    echo $OUTPUT->footer();
    die;
}

$currentuser = ($user->id == $id);
$context = $usercontext = context_user::instance($id, MUST_EXIST);

$currentcss = '/local/users/css/styles.css';
$PAGE->requires->css($currentcss);

echo $OUTPUT->header();
echo $OUTPUT->heading(fullname($user));

$hierarchy = new hierarchy();
$costcenterlist = $hierarchy->get_assignedcostcenters();
if (is_siteadmin()) {
    $costcenterlist = $hierarchy->get_costcenter_items();
}
$costcenterlist = $hierarchy->get_costcenter_parent($costcenterlist, '', false, false);
$costcenterlist = array_keys($costcenterlist);

list($usql, $params) = $DB->get_in_or_equal($costcenterlist);
$params = array_merge(array($id), $params);

$sql = "SELECT * FROM {local_userdata} WHERE userid = ? AND costcenterid $usql";
$userdata = $DB->get_records_sql($sql, $params); //Assume student enrolled to only one costcenter.

$_count = sizeof($userdata);
$myuser = users::getInstance();