/**
  * return content for mass unenrolment page.
  */
 public function page_mass_unenrol()
 {
     global $CFG, $USER;
     require_once $CFG->libdir . '/csvlib.class.php';
     require_once $CFG->dirroot . '/local/mass_enroll/mass_unenroll_form.php';
     require_once $CFG->dirroot . '/local/mass_enroll/lib.php';
     $course = $this->page->course;
     $context = $this->page->context;
     $mform = new mass_unenroll_form(new moodle_url($CFG->wwwroot . '/local/mass_enroll/mass_unenroll.php'), array('course' => $course, 'context' => $context));
     $currenttab = 'mass_unenroll';
     $out = '';
     $strinscriptions = get_string('mass_unenroll', 'local_mass_enroll');
     if ($mform->is_cancelled()) {
         redirect(new moodle_url('/course/view.php', array('id' => $course->id)));
     } else {
         if ($data = $mform->get_data(false)) {
             $content = $mform->get_file_content('attachment');
             $iid = csv_import_reader::get_new_iid('uploaduser');
             $cir = new csv_import_reader($iid, 'uploaduser');
             $readcount = $cir->load_csv_content($content, $data->encoding, $data->delimiter_name);
             unset($content);
             $returnurl = $this->page->url;
             if ($readcount === false) {
                 print_error('csvloaderror', '', $returnurl);
             } else {
                 if ($readcount == 0) {
                     print_error('csvemptyfile', 'error', $returnurl);
                 }
             }
             $result = mass_unenroll($cir, $course, $context, $data);
             $cir->close();
             $cir->cleanup(false);
             // Only currently uploaded CSV file.
             if ($data->mailreport) {
                 $a = new stdClass();
                 $a->course = $course->fullname;
                 $a->report = $result;
                 email_to_user($USER, $USER, get_string('mail_unenrolment_subject', 'local_mass_enroll', $CFG->wwwroot), get_string('mail_unenrolment', 'local_mass_enroll', $a));
                 $result .= "\n" . get_string('email_sent', 'local_mass_enroll', $USER->email);
             }
             $out .= $this->header();
             $out .= $this->get_tabs($context, $currenttab, array('id' => $course->id));
             $out .= $this->heading($strinscriptions);
             $out .= $this->box(nl2br($result), 'center');
             $out .= $this->continue_button($this->page->url);
             // Back to this page.
             $out .= $this->footer($course);
             return $out;
         }
     }
     $out .= $this->header();
     $out .= $this->get_tabs($context, $currenttab, array('id' => $course->id));
     $out .= $this->heading_with_help($strinscriptions, 'mass_unenroll', 'local_mass_enroll', 'icon', get_string('mass_unenroll', 'local_mass_enroll'));
     $out .= $this->box(get_string('mass_unenroll_info', 'local_mass_enroll'), 'center');
     $out .= $mform->render();
     $out .= $this->footer($course);
     return $out;
 }
}
/// Security and access check
require_course_login($course);
$context = context_course::instance($course->id);
require_capability('local/mass_enroll:unenrol', $context);
/// Start making page
$PAGE->set_pagelayout('incourse');
$PAGE->set_url('/local/mass_enroll/mass_unenroll.php', array('id' => $id));
$strinscriptions = get_string('mass_unenroll', 'local_mass_enroll');
$PAGE->set_title($course->fullname . ': ' . $strinscriptions);
$PAGE->set_heading($course->fullname . ': ' . $strinscriptions);
echo $OUTPUT->header();
// Add tabs
$currenttab = 'mass_unenroll';
require 'tabs.php';
$mform = new mass_unenroll_form($CFG->wwwroot . '/local/mass_enroll/mass_unenroll.php', array('course' => $course, 'context' => $context));
if ($mform->is_cancelled()) {
    redirect(new moodle_url('/course/view.php', array('id' => $id)));
} else {
    if ($data = $mform->get_data(false)) {
        // no magic quotes
        echo $OUTPUT->heading($strinscriptions);
        $iid = csv_import_reader::get_new_iid('uploaduser');
        $cir = new csv_import_reader($iid, 'uploaduser');
        $content = $mform->get_file_content('attachment');
        $readcount = $cir->load_csv_content($content, $data->encoding, $data->delimiter_name);
        unset($content);
        if ($readcount === false) {
            print_error('csvloaderror', '', $returnurl);
        } else {
            if ($readcount == 0) {