function validation($data, $files)
 {
     global $DB, $CFG, $COURSE;
     $errors = parent::validation($data, $files);
     require_once "{$CFG->dirroot}/enrol/jwc/locallib.php";
     $jwc = new jwc_helper();
     $errormsg = '';
     if (!$jwc->get_all_courses($data['coursenumber'], get_config('enrol_jwc', 'semester'), $errormsg)) {
         $errors['coursenumber'] = '在教务处查询此课程编号出错:' . $errormsg;
     }
     if ($DB->record_exists('enrol', array('enrol' => 'jwc', 'courseid' => $COURSE->id, 'customchar1' => $data['coursenumber']))) {
         $errors['coursenumber'] = '本课程已有一个教务处同步选课实例使用此课程编号';
     }
     return $errors;
 }
예제 #2
0
require_once $CFG->libdir . '/clilib.php';
// cli only functions
require_once "{$CFG->dirroot}/enrol/jwc/locallib.php";
$longoptions = array('xkid' => true);
$shortoptions = array('x' => 'xkid');
list($options, $unrecognized) = cli_get_params($longoptions, $shortoptions);
if (empty($unrecognized)) {
    $help = "Debug enrol jwc\n\nExample:\n\$sudo -u www-data /usr/bin/php enrol/jwc/cli/debug.php COURSE_NUMBER\n\$sudo -u www-data /usr/bin/php enrol/jwc/cli/debug.php -x xkid\n";
    echo $help;
    die;
}
$jwc = new jwc_helper();
$jwc_enrol = enrol_get_plugin('jwc');
if ($options['xkid']) {
    foreach ($unrecognized as $xkid) {
        $students = $jwc->get_all_students($xkid, $return_msg);
        foreach ($students as $student) {
            // print_r can not enum xml object
            $userid = $DB->get_field('user', 'id', array('auth' => 'cas', 'username' => $student->code, 'lastname' => $student->name));
            mtrace("{$student->code}\t{$student->name}\t[{$userid}]");
        }
        mtrace('Total: ' . count($students));
        mtrace($return_msg);
    }
} else {
    foreach ($unrecognized as $course_number) {
        $courses = $jwc->get_all_courses($course_number, $jwc_enrol->get_config('semester'), $return_msg);
        print_r($courses);
        mtrace($return_msg);
    }
}
예제 #3
0
 /**
  * Validates course edit form data
  *
  * @param object $instance enrol instance or null if does not exist yet
  * @param array $data
  * @param object $context context of existing course or parent category if course does not exist
  * @return array errors array
  */
 public function course_edit_validation($instance, array $data, $context)
 {
     global $CFG;
     $errors = array();
     if (!empty($data['idnumber'])) {
         require_once "{$CFG->dirroot}/enrol/jwc/locallib.php";
         $jwc = new jwc_helper();
         $errormsg = '';
         if (!$jwc->get_all_courses($data['idnumber'], $this->get_config('semester'), $errormsg)) {
             $errors['idnumber'] = '在教务处查询此课程编号出错:' . $errormsg . '(留空可跳过此检查)';
         }
     }
     return $errors;
 }