Exemplo n.º 1
0
 public function validation($data, $files)
 {
     $errors = parent::validation($data, $files);
     $errors += parent::validate_custom_fields($data, 'cluster');
     return $errors;
 }
Exemplo n.º 2
0
 public function validation($data, $files)
 {
     $errors = parent::validation($data, $files);
     if (!empty($data['timetocomplete'])) {
         if (!datedelta::validate($data['timetocomplete'])) {
             $errors['timetocomplete'] = get_string('error_not_timeformat', 'local_elisprogram');
         } else {
             $datedelta = new datedelta($data['timetocomplete']);
             if ($datedelta->is_zero() || !$datedelta->getDateString()) {
                 $errors['timetocomplete'] = get_string('error_invalid_timeperiod', 'local_elisprogram');
             }
         }
     }
     if (!empty($data['frequency'])) {
         if (!datedelta::validate($data['frequency'])) {
             $errors['frequency'] = get_string('error_not_timeformat', 'local_elisprogram');
         } else {
             $datedelta = new datedelta($data['frequency']);
             if ($datedelta->is_zero() || !$datedelta->getDateString()) {
                 $errors['frequency'] = get_string('error_invalid_timeperiod', 'local_elisprogram');
             }
         }
     }
     if (!empty($data['idnumber'])) {
         if (!$this->check_unique(curriculum::TABLE, 'idnumber', $data['idnumber'], $data['id'])) {
             $errors['idnumber'] = get_string('badidnumber', 'local_elisprogram');
         }
     }
     $errors += parent::validate_custom_fields($data, 'curriculum');
     return $errors;
 }
Exemplo n.º 3
0
 /**
  *  make sure the start time is before the end time and the start date is before the end date for the class
  * @param array $data
  * @param mixed $files
  * @return array
  */
 function validation($data, $files)
 {
     global $CURMAN;
     $errors = parent::validation($data, $files);
     if ($CURMAN->db->record_exists_select(CLSTABLE, "idnumber = '{$data['idnumber']}'" . ($data['id'] ? " AND id != {$data['id']}" : ''))) {
         $errors['idnumber'] = get_string('idnumber_already_used', 'block_curr_admin');
     }
     if ($data['starttime'] > $data['endtime']) {
         $errors['starttime'] = get_string('error_duration', 'block_curr_admin');
     }
     if (!empty($data['startdate']) && !empty($data['enddate']) && !empty($data['disablestart']) && !empty($data['disableend'])) {
         if ($data['startdate'] > $data['enddate']) {
             $errors['start'] = get_string('error_date_range', 'block_curr_admin');
         }
     }
     if (!empty($this->_customdata['obj']) && !empty($this->_customdata['obj']->maxstudents)) {
         if ($data['maxstudents'] < $this->_customdata['obj']->maxstudents && $data['maxstudents'] < student::count_enroled($this->_customdata['obj']->id)) {
             $context = get_context_instance(CONTEXT_SYSTEM);
             if (!has_capability('block/curr_admin:overrideclasslimit', $context)) {
                 $errors['maxstudents'] = get_string('error_n_overenrol', 'block_curr_admin');
             }
         }
     }
     return $errors;
 }
Exemplo n.º 4
0
 /**
  *  make sure the start time is before the end time and the start date is before the end date for the class
  * @param array $data
  * @param mixed $files
  * @return array
  */
 function validation($data, $files)
 {
     global $CURMAN;
     $errors = parent::validation($data, $files);
     if ($CURMAN->db->record_exists_select(TRACKTABLE, "idnumber = '{$data['idnumber']}'")) {
         $errors['idnumber'] = get_string('idnumber_already_used', 'block_curr_admin');
     }
     if (!empty($data['startdate']) && !empty($data['enddate']) && !empty($data['disablestart']) && !empty($data['disableend'])) {
         if ($data['startdate'] > $data['enddate']) {
             $errors['startdate'] = get_string('error_date_range', 'block_curr_admin');
         }
     }
     return $errors;
 }
Exemplo n.º 5
0
 /**
  *  make sure the start time is before the end time and the start date is before the end date for the class
  * @param array $data
  * @param mixed $files
  * @return array
  */
 function validation($data, $files)
 {
     $errors = parent::validation($data, $files);
     if (!empty($data['idnumber'])) {
         if (!$this->check_unique(track::TABLE, 'idnumber', $data['idnumber'], $data['id'])) {
             $errors['idnumber'] = get_string('badidnumber', 'local_elisprogram');
         }
     }
     if (!empty($data['startdate']) && !empty($data['enddate']) && !empty($data['disablestart']) && !empty($data['disableend'])) {
         if ($data['startdate'] > $data['enddate']) {
             $errors['startdate'] = get_string('error_date_range', 'local_elisprogram');
         }
     }
     $errors += parent::validate_custom_fields($data, 'track');
     return $errors;
 }
Exemplo n.º 6
0
 function validation($data, $files)
 {
     global $CFG, $CURMAN;
     $errors = parent::validation($data, $files);
     // Use a default for 'id' if we're doing an add
     if (!$data['id']) {
         $data['id'] = 0;
     }
     if (!empty($data['username'])) {
         if (!$this->check_unique(USRTABLE, 'username', $data['username'], $data['id'])) {
             $errors['username_group'] = get_string('badusername', 'block_curr_admin');
         }
     } else {
         if (!$data['id'] && empty($data['id_same_user'])) {
             $errors['username_group'] = get_string('required');
         }
     }
     if (!empty($data['idnumber'])) {
         if (!$this->check_unique(USRTABLE, 'idnumber', $data['idnumber'], $data['id'])) {
             $errors['idnumber'] = get_string('badidnumber', 'block_curr_admin');
         }
     }
     // Validate the supplied email addresses as best we can...
     if (!empty($data['email'])) {
         if (!$this->check_unique(USRTABLE, 'email', $data['email'], $data['id'])) {
             $errors['email'] = get_string('emailexists');
         }
     }
     if (!empty($data['email2'])) {
         if (!$this->check_unique(USRTABLE, 'email', $data['email2'], $data['id'])) {
             $errors['email2'] = get_string('emailexists');
         }
     }
     if (!empty($data['contactemail'])) {
         if (!$this->check_unique(USRTABLE, 'email', $data['contactemail'], $data['id'])) {
             $errors['contactemail'] = get_string('emailexists');
         }
     }
     // validate custom profile fields
     $fields = field::get_for_context_level(context_level_base::get_custom_context_level('user', 'block_curr_admin'));
     $fields = $fields ? $fields : array();
     if ($data['id']) {
         $context = get_context_instance(context_level_base::get_custom_context_level('user', 'block_curr_admin'), $data['id']);
         $contextid = $context->id;
     } else {
         $contextid = 0;
     }
     foreach ($fields as $field) {
         $field = new field($field);
         $key = "field_{$field->shortname}";
         if ($field->multivalued) {
             $manual = new field_owner($field->owners['manual']);
             $fielddata = isset($data[$key]) ? $data[$key] : array();
             if ($manual->param_required) {
                 if (empty($fielddata)) {
                     $errors[$key] = get_string('required');
                 } else {
                     if (!empty($manual->param_options)) {
                         $options = explode("\n", $manual->param_options);
                         array_walk($options, 'trim_cr');
                         // TBD: defined below
                         foreach ($fielddata as $entry) {
                             if (!in_array($entry, $options)) {
                                 $errors[$key] = get_string('required');
                                 break;
                             }
                         }
                     }
                 }
             }
             if (!isset($errors[$key]) && $field->forceunique && $contextid) {
                 $where = "contextid != {$contextid} AND fieldid = {$field->id}";
                 if ($recs = get_records_select($field->data_table(), $where, 'contextid, data')) {
                     $curcontext = -1;
                     $vals = null;
                     foreach ($recs as $rec) {
                         if ($curcontext != $rec->contextid) {
                             if (!empty($vals)) {
                                 $adif = array_diff($vals, $fielddata);
                                 if (empty($adif)) {
                                     $errors[$key] = get_string('valuealreadyused');
                                     // TBD^^^ "[These/This combination of] values already uesd!"
                                     $vals = null;
                                     break;
                                 }
                             }
                             $curcontext = $rec->contextid;
                             $vals = array();
                         }
                         $vals[] = $rec->data;
                     }
                     if (!empty($vals)) {
                         $adif = array_diff($vals, $fielddata);
                         if (empty($adif)) {
                             $errors[$key] = get_string('valuealreadyused');
                             // TBD^^^ "[These/This combination of] values already uesd!"
                         }
                     }
                 }
             }
         } else {
             if ($field->forceunique) {
                 // NON-MULTIVALUED case
                 $fielddata = $CURMAN->db->get_record($field->data_table(), 'fieldid', $field->id, 'data', $data[$key]);
                 //print_object($fielddata);
                 if ($fielddata && $fielddata->contextid != $contextid) {
                     $errors[$key] = get_string('valuealreadyused');
                 }
             }
         }
     }
     return $errors;
 }
Exemplo n.º 7
0
 public function validation($data, $files)
 {
     $errors = parent::validation($data, $files);
     if (!empty($data['timetocomplete'])) {
         $datedelta = new datedelta($data['timetocomplete']);
         if (!$datedelta->getDateString()) {
             $errors['timetocomplete'] = get_string('error_not_timeformat', 'block_curr_admin');
         }
     }
     if (!empty($data['frequency'])) {
         $datedelta = new datedelta($data['frequency']);
         if (!$datedelta->getDateString()) {
             $errors['frequency'] = get_string('error_not_durrationformat', 'block_curr_admin');
         }
     }
     return $errors;
 }
Exemplo n.º 8
0
 /**
  *  make sure the start time is before the end time and the start date is before the end date for the class
  * @param array $data
  * @param mixed $files
  * @return array
  */
 function validation($data, $files)
 {
     global $DB;
     $errors = parent::validation($data, $files);
     $sql = 'idnumber = ?';
     $params = array($data['idnumber']);
     if ($data['id']) {
         $sql .= ' AND id != ?';
         $params[] = $data['id'];
     }
     if ($DB->record_exists_select(pmclass::TABLE, $sql, $params)) {
         $errors['idnumber'] = get_string('idnumber_already_used', 'local_elisprogram');
     }
     if (isset($data['starttime']) && isset($data['endtime'])) {
         if ($data['starttime'] > $data['endtime']) {
             $errors['starttime'] = get_string('error_duration', 'local_elisprogram');
         }
         if (!empty($data['startdate']) && !empty($data['enddate']) && !empty($data['disablestart']) && !empty($data['disableend'])) {
             if ($data['startdate'] > $data['enddate']) {
                 $errors['start'] = get_string('error_date_range', 'local_elisprogram');
             }
         }
     }
     if (!empty($this->_customdata['obj']) && !empty($this->_customdata['obj']->maxstudents)) {
         if ($data['maxstudents'] < $this->_customdata['obj']->maxstudents && $data['maxstudents'] < student::count_enroled($this->_customdata['obj']->id)) {
             $context = context_system::instance();
             if (!has_capability('local/elisprogram:overrideclasslimit', $context)) {
                 $errors['maxstudents'] = get_string('error_n_overenrol', 'local_elisprogram');
             }
         }
     }
     $errors += parent::validate_custom_fields($data, 'class');
     return $errors;
 }
Exemplo n.º 9
0
 function validation($data, $files)
 {
     global $CFG, $DB;
     $errors = parent::validation($data, $files);
     // Use a default for 'id' if we're doing an add
     if (!$data['id']) {
         $data['id'] = 0;
     }
     if (!empty($data['username'])) {
         if (!$this->check_unique(user::TABLE, 'username', $data['username'], $data['id'])) {
             $errors['username_group'] = get_string('badusername', 'local_elisprogram');
         }
     } else {
         if (!$data['id'] && empty($data['id_same_user'])) {
             $errors['username_group'] = get_string('required');
         }
     }
     if (!empty($data['idnumber'])) {
         if (!$this->check_unique(user::TABLE, 'idnumber', $data['idnumber'], $data['id'])) {
             $errors['idnumber'] = get_string('badidnumber', 'local_elisprogram');
         } else {
             //make sure we don't set up an idnumber that is related to a non-linked Moodle user
             require_once elispm::lib('data/usermoodle.class.php');
             if (!($muserid = $DB->get_field(usermoodle::TABLE, 'muserid', array('cuserid' => $data['id'])))) {
                 $muserid = 0;
             }
             if (!$this->check_unique('user', 'idnumber', $data['idnumber'], $muserid)) {
                 $errors['idnumber'] = get_string('badidnumbermoodle', 'local_elisprogram');
             }
         }
     }
     // Validate the supplied email addresses as best we can...
     if (!empty($data['email'])) {
         if (!$this->check_unique(user::TABLE, 'email', $data['email'], $data['id'])) {
             $errors['email'] = get_string('emailexists');
         }
     }
     if (!empty($data['email2'])) {
         if (!$this->check_unique(user::TABLE, 'email', $data['email2'], $data['id'])) {
             $errors['email2'] = get_string('emailexists');
         }
     }
     if (!empty($data['contactemail'])) {
         if (!$this->check_unique(user::TABLE, 'email', $data['contactemail'], $data['id'])) {
             $errors['contactemail'] = get_string('emailexists');
         }
     }
     $errors += parent::validate_custom_fields($data, 'user');
     return $errors;
 }
Exemplo n.º 10
0
 /**
  * Validation function, validates the form.
  *
  * @param array $data  The form data
  * @param array $files The form files
  * @return array An array of error strings.
  */
 public function validation($data, $files)
 {
     $errors = parent::validation($data, $files);
     $actiontype = ACTION_TYPE_TRACK;
     if (!empty($data['result_type_id'])) {
         $actiontype = $data['result_type_id'];
     }
     $errors = array_merge($errors, $this->validate_fold($actiontype, $data));
     return $errors;
 }
Exemplo n.º 11
0
 function validation($data, $files)
 {
     global $CURMAN;
     $errors = parent::validation($data, $files);
     if ($CURMAN->db->record_exists_select(CRSTABLE, "idnumber = '{$data['idnumber']}'" . ($data['id'] ? " AND id != {$data['id']}" : ''))) {
         $errors['idnumber'] = get_string('idnumber_already_used', 'block_curr_admin');
     }
     return $errors;
 }
Exemplo n.º 12
0
 /**
  * Completion form validation method
  *
  * @param array $data array of ("fieldname"=>value) of submitted data
  * @param array $files array of uploaded files "element_name"=>tmp_file_path
  * @uses  $DB
  * @return array associative array of error messages, indexed by form element
  */
 function validation($data, $files)
 {
     global $DB;
     $errors = parent::validation($data, $files);
     $course = $this->_customdata['course'];
     $params = array($course->id, $data['idnumber']);
     $sql = 'courseid = ? AND idnumber = ?';
     if (!empty($data['elemid'])) {
         $sql .= ' AND id != ?';
         $params[] = $data['elemid'];
     }
     if ($DB->record_exists_select(coursecompletion::TABLE, $sql, $params)) {
         $errors['idnumber'] = get_string('idnumber_already_used', 'local_elisprogram');
     }
     return $errors;
 }
Exemplo n.º 13
0
 function validation($data, $files)
 {
     $errors = parent::validation($data, $files);
     if (intval($data['catalog_collapse_count']) <= 0) {
         $errors['catalog_collapse_count'] = get_string('error_catalog_collapse_count', 'block_curr_admin');
     }
     if (intval($data['num_block_icons']) <= 0) {
         $errors['num_block_icons'] = get_string('error_num_block_icons', 'block_curr_admin');
     }
     return $errors;
 }