public function validation($data, $files)
 {
     global $DB;
     $errors = parent::validation($data, $files);
     // If you enable sharing, you must enter an idnumber.
     if (!empty($data['enablesharing']) && empty($data['cmidnumber'])) {
         $errors['cmidnumber'] = get_string('error_noidnumber', 'subpage');
     }
     // If you turn off sharing, there must be no shared pages using it.
     if (empty($data['enablesharing']) && !empty($this->_instance)) {
         if ($DB->get_field('modules', 'id', array('name' => 'sharedsubpage'))) {
             // Check if there is a shared subpage...
             if ($DB->record_exists('sharedsubpage', array('subpageid' => $this->_instance))) {
                 $errors['enablesharing'] = get_string('error_sharingused', 'subpage');
             }
         }
     }
     // ID numbers must be unique, systemwide.
     if (!empty($data['cmidnumber'])) {
         // Except obviously on this existing course-module (if it does exist).
         $except = -1;
         if (!empty($data['coursemodule'])) {
             $except = $data['coursemodule'];
         }
         if ($DB->record_exists_sql('SELECT 1 FROM {course_modules} WHERE idnumber = ? AND id <> ?', array($data['cmidnumber'], $except))) {
             $errors['cmidnumber'] = get_string('error_duplicateidnumber', 'subpage');
         }
     }
     return $errors;
 }
Exemple #2
0
    function validation($data, $files) {
        global $USER;

        if ($errors = parent::validation($data, $files)) {
            return $errors;
        }

        $usercontext = get_context_instance(CONTEXT_USER, $USER->id);
        $fs = get_file_storage();

        if (!$files = $fs->get_area_files($usercontext->id, 'user', 'draft', $data['package'], 'id', false)) {
            if (!$this->current->instance) {
                $errors['package'] = get_string('required');
                return $errors;
            }
        } else {
            $file = reset($files);
            if ($file->get_mimetype() != 'application/zip') {
                $errors['package'] = get_string('invalidfiletype', 'error', '', $file);
                // better delete current file, it is not usable anyway
                $fs->delete_area_files($usercontext->id, 'user', 'draft', $data['package']);
            }
        }

        return $errors;
    }
 /**
  * Load in existing data as form defaults. Usually new entry defaults are stored directly in
  * form definition (new entry form); this function is used to load in data where values
  * already exist and data is being edited (edit entry form).
  *
  * @see: /course/moodleform.php
  */
 function set_data($default_values)
 {
     if (is_object($default_values)) {
         $default_values = (array) $default_values;
     }
     $default_values['details']['text'] = $default_values['intro'];
     parent::set_data($default_values);
 }
 function get_data()
 {
     $data = parent::get_data();
     if (!$data) {
         return false;
     }
     return $data;
 }
 public function validation($data, $files)
 {
     $errors = parent::validation($data, $files);
     if (count($errors) == 0) {
         return true;
     } else {
         return $errors;
     }
 }
Exemple #6
0
 function validation($data, $files)
 {
     $errors = parent::validation($data, $files);
     // Completion: Automatic on-view completion can not work together with
     // "display inline" option
     if (empty($errors['completion']) && array_key_exists('completion', $data) && $data['completion'] == COMPLETION_TRACKING_AUTOMATIC && !empty($data['completionview']) && $data['display'] == FOLDER_DISPLAY_INLINE) {
         $errors['completion'] = get_string('noautocompletioninline', 'mod_folder');
     }
     return $errors;
 }
 function validation($data, $files)
 {
     global $COURSE;
     $errors = parent::validation($data, $files);
     $mform =& $this->_form;
     $maxmembers = $data['maxmembers'];
     if ($maxmembers < 0) {
         $errors['maxmembers'] = get_string('error');
     }
     return $errors;
 }
 function validation($data, $files)
 {
     $errors = parent::validation($data, $files);
     // Disabled this feature because client wants to be able to paste
     // URLs with spaces and only have them trimed just before the page
     // is redirected.
     //        if(!ezproxy_has_protocol($data['serverurl'])) {
     //            $errors['serverurl'] = get_string('missingprotocol', 'ezproxy');
     //        }
     return $errors;
 }
 function get_data()
 {
     $data = parent::get_data();
     if (!$data) {
         return false;
     }
     if (!isset($data->usecoursegroups)) {
         $data->usecoursegroups = 0;
     }
     return $data;
 }
 function get_data()
 {
     $data = parent::get_data();
     if (!$data) {
         return false;
     }
     // Set up completion section even if checkbox is not ticked
     if (empty($data->completionsection)) {
         $data->completionsection = 0;
     }
     return $data;
 }
Exemple #11
0
 /**
  * Return submitted data if properly submitted or returns NULL if validation fails or
  * if there is no submitted data.
  *
  * @return stdClass submitted data; NULL if not valid or not submitted or cancelled
  */
 public function get_data()
 {
     $data = parent::get_data();
     if (!$data) {
         return false;
     }
     if (!empty($data->completionunlocked)) {
         // Turn off completion settings if the checkboxes aren't ticked.
         $autocompletion = !empty($data->completion) && $data->completion == COMPLETION_TRACKING_AUTOMATIC;
         if (!$autocompletion || empty($data->completionsubmit)) {
             $data->completionsubmit = 0;
         }
     }
     return $data;
 }
 public function definition_after_data()
 {
     parent::definition_after_data();
     $mform = $this->_form;
     if ($id = $mform->getElementValue('update')) {
         $dta = $mform->getElementValue('open');
         $dt = mktime($dta['hour'][0], $dta['minute'][0], 0, $dta['month'][0], $dta['day'][0], $dta['year'][0]);
         if ($dt < time()) {
             $el = $mform->createElement('static', 'openlabel', 'Open', date("D d/m/Y H:i", $dt));
             $mform->insertElementBefore($el, 'open');
             $mform->removeElement('open');
             $mform->addElement('hidden', 'opendt', $dt);
         }
     }
 }
Exemple #13
0
 function validation($data, $files)
 {
     $errors = parent::validation($data, $files);
     // Validating entered NeuroK course url.
     if (!empty($data['url'])) {
         $testurl = $data['url'];
         if (preg_match('|^https:|i', $testurl)) {
             if (!preg_match('|' . NEUROKBASEURL . '|i', $testurl)) {
                 $errors['url'] = get_string('invalidurl', 'neurok');
             }
         } else {
             $errors['url'] = get_string('invalidurl', 'neurok');
         }
     }
     return $errors;
 }
 function get_data()
 {
     $data = parent::get_data();
     if (!$data) {
         return false;
     }
     if (!empty($data->completionunlocked)) {
         // Turn off completion settings if the checkboxes aren't ticked
         $autocompletion = !empty($data->completion) && $data->completion == COMPLETION_TRACKING_AUTOMATIC;
         if (empty($data->completionentriesenabled) || !$autocompletion) {
             $data->completionentries = 0;
         }
     }
     return $data;
 }
 /**
  * Perform minimal validation on the settings form
  * @param array $data
  * @param array $files
  */
 public function validation($data, $files)
 {
     $errors = parent::validation($data, $files);
     if ($data['allowsubmissionsfromdate'] && $data['duedate']) {
         if ($data['allowsubmissionsfromdate'] > $data['duedate']) {
             $errors['duedate'] = get_string('duedatevalidation', 'publication');
         }
     }
     if ($data['duedate'] && $data['cutoffdate']) {
         if ($data['duedate'] > $data['cutoffdate']) {
             $errors['cutoffdate'] = get_string('cutoffdatevalidation', 'publication');
         }
     }
     if ($data['allowsubmissionsfromdate'] && $data['cutoffdate']) {
         if ($data['allowsubmissionsfromdate'] > $data['cutoffdate']) {
             $errors['cutoffdate'] = get_string('cutoffdatefromdatevalidation', 'publication');
         }
     }
     if ($data['mode'] == PUBLICATION_MODE_IMPORT) {
         if ($data['importfrom'] == "0") {
             $errors['importfrom'] = get_string('importfrom_err', 'publication');
         }
     }
     return $errors;
 }
Exemple #16
0
 function validation($data, $files)
 {
     global $USER;
     $errors = parent::validation($data, $files);
     $usercontext = context_user::instance($USER->id);
     $fs = get_file_storage();
     if (!($files = $fs->get_area_files($usercontext->id, 'user', 'draft', $data['files'], 'sortorder, id', false))) {
         $errors['files'] = get_string('required');
         return $errors;
     }
     if (count($files) == 1) {
         // no need to select main file if only one picked
         return $errors;
     } else {
         if (count($files) > 1) {
             $mainfile = false;
             foreach ($files as $file) {
                 if ($file->get_sortorder() == 1) {
                     $mainfile = true;
                     break;
                 }
             }
             // set a default main file
             if (!$mainfile) {
                 $file = reset($files);
                 file_set_sortorder($file->get_contextid(), $file->get_component(), $file->get_filearea(), $file->get_itemid(), $file->get_filepath(), $file->get_filename(), 1);
             }
         }
     }
     return $errors;
 }
 public function validation($data, $files)
 {
     $current_activity =& $this->current;
     $errors = parent::validation($data, $files);
     if ($data['timeavailable'] != 0 && $data['timedue'] != 0 && $data['timedue'] < $data['timeavailable']) {
         $errors['timedue'] = get_string('bbbduetimeoverstartingtime', 'bigbluebuttonbn');
     }
     return $errors;
 }
Exemple #18
0
 public function get_data()
 {
     $data = parent::get_data();
     if (!$data) {
         return false;
     }
     // Turn off completion setting if the checkbox is not ticked.
     if (!empty($data->completionunlocked)) {
         $autocompletion = !empty($data->completion) && $data->completion == COMPLETION_TRACKING_AUTOMATIC;
         if (empty($data->completiontimespentenabled) || !$autocompletion) {
             $data->completiontimespent = 0;
         }
     }
     return $data;
 }
 public function validation($data, $files)
 {
     $current_activity =& $this->current;
     $errors = parent::validation($data, $files);
     if ($current_activity->section > 0) {
         //This is not a general activity, it is part of a week, so it can have schedule
         // Check open and close times are consistent.
         if ($data['timeavailable'] != 0 && $data['timedue'] != 0 && $data['timedue'] < $data['timeavailable']) {
             $errors['timedue'] = get_string('bbbduetimeoverstartingtime', 'bigbluebuttonbn');
         }
     }
     return $errors;
 }
 /**
  * Some basic validation
  *
  * @param $data
  * @param $files
  * @return array
  */
 public function validation($data, $files)
 {
     $errors = parent::validation($data, $files);
     // Check that the required time entered is valid
     if (!is_number($data['requiredtime']) || $data['requiredtime'] < 0) {
         $errors['requiredtime'] = get_string('requiredtimenotvalid', 'certificate');
     }
     return $errors;
 }
 public function get_data($slashed = true)
 {
     $data = parent::get_data($slashed);
     if (!$data) {
         return false;
     }
     // Convert completionstatusrequired to a proper integer, if any.
     $total = 0;
     if (isset($data->completionstatusrequired) && is_array($data->completionstatusrequired)) {
         foreach (array_keys($data->completionstatusrequired) as $state) {
             $total |= $state;
         }
         $data->completionstatusrequired = $total;
     }
     if (!empty($data->completionunlocked)) {
         // Turn off completion settings if the checkboxes aren't ticked.
         $autocompletion = isset($data->completion) && $data->completion == COMPLETION_TRACKING_AUTOMATIC;
         if (!(isset($data->completionstatusrequired) && $autocompletion)) {
             $data->completionstatusrequired = null;
         }
         // Else do nothing: completionstatusrequired has been already converted
         //             into a correct integer representation.
         if (!empty($data->completionscoredisabled) || !$autocompletion) {
             $data->completionscorerequired = null;
         }
     }
     return $data;
 }
Exemple #22
0
 /**
  * Enforce validation rules here
  *
  * @param array $data array of ("fieldname"=>value) of submitted data
  * @param array $files array of uploaded files "element_name"=>tmp_file_path
  * @return array
  **/
 public function validation($data, $files)
 {
     $errors = parent::validation($data, $files);
     // Check open and close times are consistent.
     if ($data['timeopen'] && $data['timeclose'] && $data['timeclose'] < $data['timeopen']) {
         $errors['timeclose'] = get_string('closebeforeopen', 'choice');
     }
     return $errors;
 }
Exemple #23
0
 /**
  * Validates the form input
  *
  * @param array $data submitted data
  * @param array $files submitted files
  * @return array eventual errors indexed by the field name
  */
 public function validation($data, $files)
 {
     $errors = parent::validation($data, $files);
     // Validate lists of allowed extensions.
     foreach (array('submissionfiletypes', 'overallfeedbackfiletypes') as $fieldname) {
         if (isset($data[$fieldname])) {
             $invalidextensions = workshop::invalid_file_extensions($data[$fieldname], array_keys(core_filetypes::get_types()));
             if ($invalidextensions) {
                 $errors[$fieldname] = get_string('err_unknownfileextension', 'mod_workshop', workshop::clean_file_extensions($invalidextensions));
             }
         }
     }
     // check the phases borders are valid
     if ($data['submissionstart'] > 0 and $data['submissionend'] > 0 and $data['submissionstart'] >= $data['submissionend']) {
         $errors['submissionend'] = get_string('submissionendbeforestart', 'mod_workshop');
     }
     if ($data['assessmentstart'] > 0 and $data['assessmentend'] > 0 and $data['assessmentstart'] >= $data['assessmentend']) {
         $errors['assessmentend'] = get_string('assessmentendbeforestart', 'mod_workshop');
     }
     // check the phases do not overlap
     if (max($data['submissionstart'], $data['submissionend']) > 0 and max($data['assessmentstart'], $data['assessmentend']) > 0) {
         $phasesubmissionend = max($data['submissionstart'], $data['submissionend']);
         $phaseassessmentstart = min($data['assessmentstart'], $data['assessmentend']);
         if ($phaseassessmentstart == 0) {
             $phaseassessmentstart = max($data['assessmentstart'], $data['assessmentend']);
         }
         if ($phasesubmissionend > 0 and $phaseassessmentstart > 0 and $phaseassessmentstart < $phasesubmissionend) {
             foreach (array('submissionend', 'submissionstart', 'assessmentstart', 'assessmentend') as $f) {
                 if ($data[$f] > 0) {
                     $errors[$f] = get_string('phasesoverlap', 'mod_workshop');
                     break;
                 }
             }
         }
     }
     // Check that the submission grade pass is a valid number.
     if (!empty($data['submissiongradepass'])) {
         $submissiongradefloat = unformat_float($data['submissiongradepass'], true);
         if ($submissiongradefloat === false) {
             $errors['submissiongradepass'] = get_string('err_numeric', 'form');
         } else {
             if ($submissiongradefloat > $data['grade']) {
                 $errors['submissiongradepass'] = get_string('gradepassgreaterthangrade', 'grades', $data['grade']);
             }
         }
     }
     // Check that the grade pass is a valid number.
     if (!empty($data['gradinggradepass'])) {
         $gradepassfloat = unformat_float($data['gradinggradepass'], true);
         if ($gradepassfloat === false) {
             $errors['gradinggradepass'] = get_string('err_numeric', 'form');
         } else {
             if ($gradepassfloat > $data['gradinggrade']) {
                 $errors['gradinggradepass'] = get_string('gradepassgreaterthangrade', 'grades', $data['gradinggrade']);
             }
         }
     }
     return $errors;
 }
Exemple #24
0
 /**
  * Enforce validation rules here
  *
  * @param object $data Post data to validate
  * @return array
  **/
 function validation($data, $files)
 {
     $errors = parent::validation($data, $files);
     if (empty($data['maxtime']) and !empty($data['timed'])) {
         $errors['timedgrp'] = get_string('err_numeric', 'form');
     }
     if (!empty($data['usepassword']) && empty($data['password'])) {
         $errors['password'] = get_string('emptypassword', 'lesson');
     }
     return $errors;
 }
Exemple #25
0
 function set_data($default_values)
 {
     $default_values = (array) $default_values;
     if (isset($default_values['scormtype']) and isset($default_values['reference'])) {
         switch ($default_values['scormtype']) {
             case SCORM_TYPE_LOCALSYNC:
             case SCORM_TYPE_EXTERNAL:
             case SCORM_TYPE_IMSREPOSITORY:
                 $default_values['packageurl'] = $default_values['reference'];
         }
     }
     unset($default_values['reference']);
     if (!empty($default_values['options'])) {
         $options = explode(',', $default_values['options']);
         foreach ($options as $option) {
             $opt = explode('=', $option);
             if (isset($opt[1])) {
                 $default_values[$opt[0]] = $opt[1];
             }
         }
     }
     $this->data_preprocessing($default_values);
     parent::set_data($default_values);
 }
Exemple #26
0
 function set_data($default_values)
 {
     $default_values = (array) $default_values;
     if (isset($default_values['url'])) {
         if (jclic_is_valid_external_url($default_values['url'])) {
             $default_values['filetype'] = JCLIC_FILE_TYPE_EXTERNAL;
             $default_values['url'] = $default_values['url'];
         } else {
             $default_values['filetype'] = JCLIC_FILE_TYPE_LOCAL;
             $default_values['jclicfile'] = $default_values['url'];
             unset($default_values['url']);
         }
     }
     $this->data_preprocessing($default_values);
     parent::set_data($default_values);
 }
 function validation($data, $files)
 {
     $errors = parent::validation($data, $files);
     $choices = 0;
     foreach ($data['option'] as $option) {
         if (trim($option) != '') {
             $choices++;
         }
     }
     if ($choices < 1) {
         $errors['option[0]'] = get_string('fillinatleastoneoption', 'choice');
     }
     if ($choices < 2) {
         $errors['option[1]'] = get_string('fillinatleastoneoption', 'choice');
     }
     return $errors;
 }
Exemple #28
0
 function validation($data, $files)
 {
     $errors = parent::validation($data, $files);
     // Validating Entered url, we are looking for obvious problems only,
     // teachers are responsible for testing if it actually works.
     // This is not a security validation!! Teachers are allowed to enter "javascript:alert(666)" for example.
     // NOTE: do not try to explain the difference between URL and URI, people would be only confused...
     if (empty($data['externalurl'])) {
         $errors['externalurl'] = get_string('required');
     } else {
         $url = trim($data['externalurl']);
         if (empty($url)) {
             $errors['externalurl'] = get_string('required');
         } else {
             if (preg_match('|^/|', $url)) {
                 // links relative to server root are ok - no validation necessary
             } else {
                 if (preg_match('|^[a-z]+://|i', $url) or preg_match('|^https?:|i', $url) or preg_match('|^ftp:|i', $url)) {
                     // normal URL
                     if (!url_appears_valid_url($url)) {
                         $errors['externalurl'] = get_string('invalidurl', 'url');
                     }
                 } else {
                     if (preg_match('|^[a-z]+:|i', $url)) {
                         // general URI such as teamspeak, mailto, etc. - it may or may not work in all browsers,
                         // we do not validate these at all, sorry
                     } else {
                         // invalid URI, we try to fix it by adding 'http://' prefix,
                         // relative links are NOT allowed because we display the link on different pages!
                         if (!url_appears_valid_url('http://' . $url)) {
                             $errors['externalurl'] = get_string('invalidurl', 'url');
                         }
                     }
                 }
             }
         }
     }
     return $errors;
 }
Exemple #29
0
    /**
     * Make fields editable or non-editable depending on the administrator choices
     * @see moodleform_mod::definition_after_data()
     */
    public function definition_after_data() {
        parent::definition_after_data();

        //$mform =& $this->_form;
    }
 /**
  * Prepare completion checkboxes when form is displayed
  */
 function data_preprocessing(&$default_values)
 {
     parent::data_preprocessing($default_values);
     // Set up the completion checkboxes which aren't part of standard data.
     // We also make the default value (if you turn on the checkbox) for those
     // numbers to be 1, this will not apply unless checkbox is ticked.
     $default_values['completiontotaldurationenabled'] = !empty($default_values['completiontotaldurationmins']) ? 1 : 0;
     if (empty($default_values['completiontotaldurationmins'])) {
         $default_values['completiontotaldurationmins'] = ATTENDANCEREGISTER_DEFAULT_COMPLETION_TOTAL_DURATION_MINS;
     }
     // ... when more tracked values will be supported, set default value here
 }