Ejemplo n.º 1
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;
    }
Ejemplo n.º 2
0
 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;
 }
Ejemplo n.º 3
0
 function validation($data, $files)
 {
     global $CFG;
     $errors = parent::validation($data, $files);
     if (empty($data['h5pfile'])) {
         $errors['h5pfile'] = get_string('required');
         return $errors;
     }
     $files = $this->get_draft_files('h5pfile');
     if (count($files) < 1) {
         $errors['h5pfile'] = get_string('required');
         return $errors;
     }
     $file = reset($files);
     $interface = hvp_get_instance('interface');
     $path = $CFG->dirroot . '/mod/hvp/files/tmp/' . uniqid('hvp-');
     $interface->getUploadedH5pFolderPath($path);
     $path .= '.h5p';
     $interface->getUploadedH5pPath($path);
     $file->copy_content_to($path);
     $h5pValidator = hvp_get_instance('validator');
     if (!$h5pValidator->isValidPackage()) {
         $errors['h5pfile'] = get_string('noth5pfile', 'hvp');
     }
     return $errors;
 }
Ejemplo n.º 4
0
 public function validation($data, $files)
 {
     $errors = parent::validation($data, $files);
     if (count($errors) == 0) {
         return true;
     } else {
         return $errors;
     }
 }
Ejemplo n.º 5
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;
 }
Ejemplo n.º 6
0
 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;
 }
Ejemplo n.º 7
0
 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;
 }
Ejemplo n.º 8
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['timeavailablefrom'] && $data['timeavailableto'] && $data['timeavailableto'] < $data['timeavailablefrom']) {
         $errors['timeavailableto'] = get_string('availabletodatevalidation', 'data');
     }
     if ($data['timeviewfrom'] && $data['timeviewto'] && $data['timeviewto'] < $data['timeviewfrom']) {
         $errors['timeviewto'] = get_string('viewtodatevalidation', 'data');
     }
     return $errors;
 }
Ejemplo n.º 9
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;
 }
Ejemplo n.º 10
0
 /**
  * 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;
 }
Ejemplo n.º 11
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;
 }
Ejemplo n.º 12
0
 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;
 }
Ejemplo n.º 13
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;
 }
Ejemplo n.º 14
0
    function validation($data, $files) {
        global $CFG;
        $errors = parent::validation($data, $files);

        $type = $data['scormtype'];

        if ($type === SCORM_TYPE_LOCAL) {
            if (!empty($data['update'])) {
                //ok, not required

            } else if (empty($data['packagefile'])) {
                $errors['packagefile'] = get_string('required');

            } else {
                $files = $this->get_draft_files('packagefile');
                if (count($files)<1) {
                    $errors['packagefile'] = get_string('required');
                    return $errors;
                }
                $file = reset($files);
                $filename = $CFG->tempdir.'/scormimport/scrom_'.time();
                make_temp_directory('scormimport');
                $file->copy_content_to($filename);

                $packer = get_file_packer('application/zip');

                $filelist = $packer->list_files($filename);
                if (!is_array($filelist)) {
                    $errors['packagefile'] = 'Incorrect file package - not an archive'; //TODO: localise
                } else {
                    $manifestpresent = false;
                    $aiccfound       = false;
                    foreach ($filelist as $info) {
                        if ($info->pathname == 'imsmanifest.xml') {
                            $manifestpresent = true;
                            break;
                        }
                        if (preg_match('/\.cst$/', $info->pathname)) {
                            $aiccfound = true;
                            break;
                        }
                    }
                    if (!$manifestpresent and !$aiccfound) {
                        $errors['packagefile'] = 'Incorrect file package - missing imsmanifest.xml or AICC structure'; //TODO: localise
                    }
                }
                unlink($filename);
            }

        } else if ($type === SCORM_TYPE_EXTERNAL) {
            $reference = $data['packageurl'];
            // Syntax check.
            if (!preg_match('/(http:\/\/|https:\/\/|www).*\/imsmanifest.xml$/i', $reference)) {
                $errors['packageurl'] = get_string('invalidurl', 'scorm');
            } else {
                // Availability check.
                $result = scorm_check_url($reference);
                if (is_string($result)) {
                    $errors['packageurl'] = $result;
                }
            }

        } else if ($type === 'packageurl') {
            $reference = $data['reference'];
            // Syntax check.
            if (!preg_match('/(http:\/\/|https:\/\/|www).*(\.zip|\.pif)$/i', $reference)) {
                $errors['packageurl'] = get_string('invalidurl', 'scorm');
            } else {
                // Availability check.
                $result = scorm_check_url($reference);
                if (is_string($result)) {
                    $errors['packageurl'] = $result;
                }
            }

        } else if ($type === SCORM_TYPE_IMSREPOSITORY) {
            $reference = $data['packageurl'];
            if (stripos($reference, '#') !== 0) {
                $errors['packageurl'] = get_string('invalidurl', 'scorm');
            }

        } else if ($type === SCORM_TYPE_AICCURL) {
            $reference = $data['packageurl'];
            // Syntax check.
            if (!preg_match('/(http:\/\/|https:\/\/|www).*/', $reference)) {
                $errors['packageurl'] = get_string('invalidurl', 'scorm');
            } else {
                // Availability check.
                $result = scorm_check_url($reference);
                if (is_string($result)) {
                    $errors['packageurl'] = $result;
                }
            }

        }

        return $errors;
    }
Ejemplo n.º 15
0
 function validation($data, $files)
 {
     $errors = parent::validation($data, $files);
     $groupIDs = explode(';', $data['serializedselectedgroups']);
     $groupIDs = array_diff($groupIDs, array(''));
     if (array_key_exists('multipleenrollmentspossible', $data) && $data['multipleenrollmentspossible'] === '1') {
         if (count($groupIDs) < 1) {
             $errors['serializedselectedgroups'] = get_string('fillinatleastoneoption', 'choicegroup');
         }
     } else {
         if (count($groupIDs) < 2) {
             $errors['serializedselectedgroups'] = get_string('fillinatleasttwooptions', 'choicegroup');
         }
     }
     return $errors;
 }
Ejemplo n.º 16
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['usepassword']) && empty($data['password'])) {
         $errors['password'] = get_string('emptypassword', 'lesson');
     }
     return $errors;
 }
Ejemplo n.º 17
0
 /**
  * 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;
 }
 /**
  * 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['instance'] == 0) {
         // Check that the passed type is valid.
         if (!isset($data['type']) || !\mod_webexactivity\meeting::is_valid_type($data['type'], $this->context)) {
             $errors['type'] = get_string('invalidtype', 'webexactivity');
         }
     }
     return $errors;
 }
Ejemplo n.º 19
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;
 }
Ejemplo n.º 20
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;
 }
Ejemplo n.º 21
0
 public function validation($data, $files)
 {
     $errors = parent::validation($data, $files);
     // Check open and close times are consistent.
     if ($data['timeopen'] != 0 && $data['timeclose'] != 0 && $data['timeclose'] < $data['timeopen']) {
         $errors['timeclose'] = get_string('closebeforeopen', 'quiz');
     }
     // Check that the grace period is not too short.
     if ($data['overduehandling'] == 'graceperiod') {
         $graceperiodmin = get_config('quiz', 'graceperiodmin');
         if ($data['graceperiod'] <= $graceperiodmin) {
             $errors['graceperiod'] = get_string('graceperiodtoosmall', 'quiz', format_time($graceperiodmin));
         }
     }
     // Check the boundary value is a number or a percentage, and in range.
     $i = 0;
     while (!empty($data['feedbackboundaries'][$i])) {
         $boundary = trim($data['feedbackboundaries'][$i]);
         if (strlen($boundary) > 0) {
             if ($boundary[strlen($boundary) - 1] == '%') {
                 $boundary = trim(substr($boundary, 0, -1));
                 if (is_numeric($boundary)) {
                     $boundary = $boundary * $data['grade'] / 100.0;
                 } else {
                     $errors["feedbackboundaries[{$i}]"] = get_string('feedbackerrorboundaryformat', 'quiz', $i + 1);
                 }
             } else {
                 if (!is_numeric($boundary)) {
                     $errors["feedbackboundaries[{$i}]"] = get_string('feedbackerrorboundaryformat', 'quiz', $i + 1);
                 }
             }
         }
         if (is_numeric($boundary) && $boundary <= 0 || $boundary >= $data['grade']) {
             $errors["feedbackboundaries[{$i}]"] = get_string('feedbackerrorboundaryoutofrange', 'quiz', $i + 1);
         }
         if (is_numeric($boundary) && $i > 0 && $boundary >= $data['feedbackboundaries'][$i - 1]) {
             $errors["feedbackboundaries[{$i}]"] = get_string('feedbackerrororder', 'quiz', $i + 1);
         }
         $data['feedbackboundaries'][$i] = $boundary;
         $i += 1;
     }
     $numboundaries = $i;
     // Check there is nothing in the remaining unused fields.
     if (!empty($data['feedbackboundaries'])) {
         for ($i = $numboundaries; $i < count($data['feedbackboundaries']); $i += 1) {
             if (!empty($data['feedbackboundaries'][$i]) && trim($data['feedbackboundaries'][$i]) != '') {
                 $errors["feedbackboundaries[{$i}]"] = get_string('feedbackerrorjunkinboundary', 'quiz', $i + 1);
             }
         }
     }
     for ($i = $numboundaries + 1; $i < count($data['feedbacktext']); $i += 1) {
         if (!empty($data['feedbacktext'][$i]['text']) && trim($data['feedbacktext'][$i]['text']) != '') {
             $errors["feedbacktext[{$i}]"] = get_string('feedbackerrorjunkinfeedback', 'quiz', $i + 1);
         }
     }
     // Any other rule plugins.
     $errors = quiz_access_manager::validate_settings_form_fields($errors, $data, $files, $this);
     return $errors;
 }
Ejemplo n.º 22
0
 function validation($data)
 {
     $errors = parent::validation($data);
     if ($errors === true) {
         $errors = array();
     }
     $validate = scorm_validate($data);
     if (!$validate->result) {
         $errors = $errors + $validate->errors;
     }
     if (count($errors) == 0) {
         return true;
     } else {
         return $errors;
     }
 }
Ejemplo n.º 23
0
 public function validation($data, $files)
 {
     $errors = parent::validation($data, $files);
     // Check open and close times are consistent.
     if ($data['timeopen'] != 0 && $data['timeclose'] != 0 && $data['timeclose'] < $data['timeopen']) {
         $errors['timeclose'] = get_string('closebeforeopen', 'quiz');
     }
     // Check the boundary value is a number or a percentage, and in range.
     $i = 0;
     while (!empty($data['feedbackboundaries'][$i])) {
         $boundary = trim($data['feedbackboundaries'][$i]);
         if (strlen($boundary) > 0 && $boundary[strlen($boundary) - 1] == '%') {
             $boundary = trim(substr($boundary, 0, -1));
             if (is_numeric($boundary)) {
                 $boundary = $boundary * $data['grade'] / 100.0;
             } else {
                 $errors["feedbackboundaries[{$i}]"] = get_string('feedbackerrorboundaryformat', 'quiz', $i + 1);
             }
         }
         if (is_numeric($boundary) && $boundary <= 0 || $boundary >= $data['grade']) {
             $errors["feedbackboundaries[{$i}]"] = get_string('feedbackerrorboundaryoutofrange', 'quiz', $i + 1);
         }
         if (is_numeric($boundary) && $i > 0 && $boundary >= $data['feedbackboundaries'][$i - 1]) {
             $errors["feedbackboundaries[{$i}]"] = get_string('feedbackerrororder', 'quiz', $i + 1);
         }
         $data['feedbackboundaries'][$i] = $boundary;
         $i += 1;
     }
     $numboundaries = $i;
     // Check there is nothing in the remaining unused fields.
     if (!empty($data['feedbackboundaries'])) {
         for ($i = $numboundaries; $i < count($data['feedbackboundaries']); $i += 1) {
             if (!empty($data['feedbackboundaries'][$i]) && trim($data['feedbackboundaries'][$i]) != '') {
                 $errors["feedbackboundaries[{$i}]"] = get_string('feedbackerrorjunkinboundary', 'quiz', $i + 1);
             }
         }
     }
     for ($i = $numboundaries + 1; $i < count($data['feedbacktext']); $i += 1) {
         if (!empty($data['feedbacktext'][$i]['text']) && trim($data['feedbacktext'][$i]['text']) != '') {
             $errors["feedbacktext[{$i}]"] = get_string('feedbackerrorjunkinfeedback', 'quiz', $i + 1);
         }
     }
     return $errors;
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 25
0
 function validation($data, $files)
 {
     $errors = parent::validation($data, $files);
     $type = $data['scormtype'];
     if ($type === SCORM_TYPE_LOCAL) {
         if (!empty($data['update'])) {
             //ok, not required
         } else {
             if (empty($files['packagefile'])) {
                 $errors['packagefile'] = get_string('required');
             } else {
                 $packer = get_file_packer('application/zip');
                 $filelist = $packer->list_files($files['packagefile']);
                 if (!is_array($filelist)) {
                     $errors['packagefile'] = 'Incorrect file package - not an archive';
                     //TODO: localise
                 } else {
                     $manifestpresent = false;
                     $aiccfound = false;
                     foreach ($filelist as $info) {
                         if ($info->pathname == 'imsmanifest.xml') {
                             $manifestpresent = true;
                             break;
                         }
                         if (preg_match('/\\.cst$/', $info->pathname)) {
                             $aiccfound = true;
                             break;
                         }
                     }
                     if (!$manifestpresent and !$aiccfound) {
                         $errors['packagefile'] = 'Incorrect file package - missing imsmanifest.xml or AICC structure';
                         //TODO: localise
                     }
                 }
             }
         }
     } else {
         if ($type === SCORM_TYPE_EXTERNAL) {
             $reference = $data['packageurl'];
             if (!preg_match('/(http:\\/\\/|https:\\/\\/|www).*\\/imsmanifest.xml$/i', $reference)) {
                 $errors['packageurl'] = get_string('required');
                 // TODO: improve help
             }
         } else {
             if ($type === 'packageurl') {
                 $reference = $data['reference'];
                 if (!preg_match('/(http:\\/\\/|https:\\/\\/|www).*(\\.zip|\\.pif)$/i', $reference)) {
                     $errors['packageurl'] = get_string('required');
                     // TODO: improve help
                 }
             } else {
                 if ($type === SCORM_TYPE_IMSREPOSITORY) {
                     $reference = $data['packageurl'];
                     if (stripos($reference, '#') !== 0) {
                         $errors['packageurl'] = get_string('required');
                     }
                 }
             }
         }
     }
     return $errors;
 }
Ejemplo n.º 26
0
 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;
 }
Ejemplo n.º 27
0
 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;
 }
Ejemplo n.º 28
0
 public function validation($data, $files)
 {
     global $USER;
     $errors = parent::validation($data, $files);
     // Check open and close times are consistent.
     if ($data['timeavailable'] != 0 && $data['timedue'] != 0 && $data['timedue'] < $data['timeavailable']) {
         $errors['timedue'] = get_string('closebeforeopen', 'jclic');
     }
     $type = $data['filetype'];
     if ($type === JCLIC_FILE_TYPE_LOCAL) {
         $usercontext = context_user::instance($USER->id);
         $fs = get_file_storage();
         if (!($files = $fs->get_area_files($usercontext->id, 'user', 'draft', $data['jclicfile'], 'sortorder, id', false))) {
             $errors['jclicfile'] = get_string('required');
         } else {
             $file = reset($files);
             $filename = $file->get_filename();
             if (!jclic_is_valid_file($filename)) {
                 $errors['jclicfile'] = get_string('invalidjclicfile', 'jclic');
             }
         }
     } else {
         if ($type === JCLIC_FILE_TYPE_EXTERNAL) {
             $reference = $data['url'];
             if (!jclic_is_valid_external_url($reference)) {
                 $errors['url'] = get_string('invalidurl', 'jclic');
             }
         }
     }
     return $errors;
 }
Ejemplo n.º 29
0
 public function validation($data, $files)
 {
     global $CFG, $USER;
     $errors = parent::validation($data, $files);
     $type = $data['scormtype'];
     if ($type === SCORM_TYPE_LOCAL) {
         if (empty($data['packagefile'])) {
             $errors['packagefile'] = get_string('required');
         } else {
             $draftitemid = file_get_submitted_draft_itemid('packagefile');
             file_prepare_draft_area($draftitemid, $this->context->id, 'mod_scorm', 'packagefilecheck', null, array('subdirs' => 0, 'maxfiles' => 1));
             // Get file from users draft area.
             $usercontext = context_user::instance($USER->id);
             $fs = get_file_storage();
             $files = $fs->get_area_files($usercontext->id, 'user', 'draft', $draftitemid, 'id', false);
             if (count($files) < 1) {
                 $errors['packagefile'] = get_string('required');
                 return $errors;
             }
             $file = reset($files);
             if (!$file->is_external_file() && !empty($data['updatefreq'])) {
                 // Make sure updatefreq is not set if using normal local file.
                 $errors['updatefreq'] = get_string('updatefreq_error', 'mod_scorm');
             }
             if (strtolower($file->get_filename()) == 'imsmanifest.xml') {
                 if (!$file->is_external_file()) {
                     $errors['packagefile'] = get_string('aliasonly', 'mod_scorm');
                 } else {
                     $repository = repository::get_repository_by_id($file->get_repository_id(), context_system::instance());
                     if (!$repository->supports_relative_file()) {
                         $errors['packagefile'] = get_string('repositorynotsupported', 'mod_scorm');
                     }
                 }
             } else {
                 if (strtolower(substr($file->get_filename(), -3)) == 'xml') {
                     $errors['packagefile'] = get_string('invalidmanifestname', 'mod_scorm');
                 } else {
                     // Validate this SCORM package.
                     $errors = array_merge($errors, scorm_validate_package($file));
                 }
             }
         }
     } else {
         if ($type === SCORM_TYPE_EXTERNAL) {
             $reference = $data['packageurl'];
             // Syntax check.
             if (!preg_match('/(http:\\/\\/|https:\\/\\/|www).*\\/imsmanifest.xml$/i', $reference)) {
                 $errors['packageurl'] = get_string('invalidurl', 'scorm');
             } else {
                 // Availability check.
                 $result = scorm_check_url($reference);
                 if (is_string($result)) {
                     $errors['packageurl'] = $result;
                 }
             }
         } else {
             if ($type === 'packageurl') {
                 $reference = $data['reference'];
                 // Syntax check.
                 if (!preg_match('/(http:\\/\\/|https:\\/\\/|www).*(\\.zip|\\.pif)$/i', $reference)) {
                     $errors['packageurl'] = get_string('invalidurl', 'scorm');
                 } else {
                     // Availability check.
                     $result = scorm_check_url($reference);
                     if (is_string($result)) {
                         $errors['packageurl'] = $result;
                     }
                 }
             } else {
                 if ($type === SCORM_TYPE_AICCURL) {
                     $reference = $data['packageurl'];
                     // Syntax check.
                     if (!preg_match('/(http:\\/\\/|https:\\/\\/|www).*/', $reference)) {
                         $errors['packageurl'] = get_string('invalidurl', 'scorm');
                     } else {
                         // Availability check.
                         $result = scorm_check_url($reference);
                         if (is_string($result)) {
                             $errors['packageurl'] = $result;
                         }
                     }
                 }
             }
         }
     }
     return $errors;
 }
Ejemplo n.º 30
0
    public function validation($data, $files) {
        $errors = parent::validation($data, $files);

        // Check open and close times are consistent.
        if ($data['opentime'] != 0 && $data['closetime'] != 0 &&
                $data['closetime'] < $data['opentime']) {
            $errors['closetime'] = get_string('closebeforeopen', 'virtualclass');
        }
        if ($data['opentime'] != 0 && $data['closetime'] == 0) {
            $errors['closetime'] = get_string('closenotset', 'virtualclass');
        }
        if ($data['opentime'] != 0 && $data['closetime'] != 0 &&
                $data['closetime'] == $data['opentime']) {
            $errors['closetime'] = get_string('closesameopen', 'virtualclass');
        }
        return $errors;
    }