コード例 #1
0
 /**
  * return content for mass enrolment page.
  */
 public function page_mass_enrol()
 {
     global $CFG, $USER;
     require_once $CFG->libdir . '/csvlib.class.php';
     require_once $CFG->dirroot . '/local/mass_enroll/mass_enroll_form.php';
     require_once $CFG->dirroot . '/local/mass_enroll/lib.php';
     $course = $this->page->course;
     $context = $this->page->context;
     $mform = new mass_enroll_form(new moodle_url($CFG->wwwroot . '/local/mass_enroll/mass_enroll.php'), array('course' => $course, 'context' => $context));
     $currenttab = 'mass_enroll';
     $out = '';
     $strinscriptions = get_string('mass_enroll', '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_enroll($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_enrolment_subject', 'local_mass_enroll', $CFG->wwwroot), get_string('mail_enrolment', '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_enroll', 'local_mass_enroll', 'icon', get_string('mass_enroll', 'local_mass_enroll'));
     $out .= $this->box(get_string('mass_enroll_info', 'local_mass_enroll'), 'center');
     $out .= $mform->render();
     $out .= $this->footer($course);
     return $out;
 }
コード例 #2
0
$PAGE->set_pagelayout('incourse');
$PAGE->set_url('/local/mass_enroll/mass_enroll.php', array('id'=>$id));

$strinscriptions = get_string('mass_enroll', 'local_mass_enroll');

$PAGE->set_title($course->fullname . ': ' . $strinscriptions);
$PAGE->set_heading($course->fullname . ': ' . $strinscriptions);

echo $OUTPUT->header();

$mform = new mass_enroll_form($CFG->wwwroot . '/local/mass_enroll/mass_enroll.php', array (
	'course' => $course,
	'context' => $context
));

if ($mform->is_cancelled()) {
    redirect(new moodle_url('/local/costcenter/courses.php'));
} 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);