Merge branch 'master_MDL-28579' of git://github.com/danmarsden/moodle
authorDamyon Wiese <damyon@moodle.com>
Wed, 4 Sep 2013 01:00:48 +0000 (09:00 +0800)
committerDamyon Wiese <damyon@moodle.com>
Wed, 4 Sep 2013 01:00:48 +0000 (09:00 +0800)
mod/scorm/lang/en/scorm.php
mod/scorm/lib.php
mod/scorm/locallib.php
mod/scorm/mod_form.php

index 9d370e5..240d91a 100644 (file)
@@ -330,6 +330,7 @@ $string['typelocal'] = 'Uploaded package';
 $string['typelocalsync'] = 'Downloaded package';
 $string['unziperror'] = 'An error occurs during package unzip';
 $string['updatefreq'] = 'Auto-update frequency';
+$string['updatefreq_error'] = 'Auto-update frequency can only be set when the package file is hosted externally';
 $string['updatefreq_help'] = 'This allows the external package to be automatically downloaded and updated';
 $string['updatefreqdesc'] = 'This preference sets the default auto-update frequency of an activity';
 $string['validateascorm'] = 'Validate a package';
index 02da6c9..8f487a2 100644 (file)
@@ -113,20 +113,24 @@ function scorm_add_instance($scorm, $mform=null) {
 
     $id = $DB->insert_record('scorm', $scorm);
 
-    /// update course module record - from now on this instance properly exists and all function may be used
+    // Update course module record - from now on this instance properly exists and all function may be used.
     $DB->set_field('course_modules', 'instance', $id, array('id'=>$cmid));
 
-    /// reload scorm instance
+    // Reload scorm instance.
     $record = $DB->get_record('scorm', array('id'=>$id));
 
-    /// store the package and verify
+    // Store the package and verify.
     if ($record->scormtype === SCORM_TYPE_LOCAL) {
-        if ($mform) {
-            $filename = $mform->get_new_filename('packagefile');
+        if ($data = $mform->get_data()) {
+            $fs = get_file_storage();
+            $fs->delete_area_files($context->id, 'mod_scorm', 'package');
+            file_save_draft_area_files($data->packagefile, $context->id, 'mod_scorm', 'package',
+                0, array('subdirs' => 0, 'maxfiles' => 1));
+            // Get filename of zip that was uploaded.
+            $files = $fs->get_area_files($context->id, 'mod_scorm', 'package', 0, '', false);
+            $file = reset($files);
+            $filename = $file->get_filename();
             if ($filename !== false) {
-                $fs = get_file_storage();
-                $fs->delete_area_files($context->id, 'mod_scorm', 'package');
-                $mform->save_stored_file('packagefile', $context->id, 'mod_scorm', 'package', 0, '/', $filename);
                 $record->reference = $filename;
             }
         }
@@ -142,10 +146,10 @@ function scorm_add_instance($scorm, $mform=null) {
         return false;
     }
 
-    // save reference
+    // Save reference.
     $DB->update_record('scorm', $record);
 
-    /// extra fields required in grade related functions
+    // Extra fields required in grade related functions.
     $record->course     = $courseid;
     $record->cmidnumber = $cmidnumber;
     $record->cmid       = $cmid;
@@ -193,13 +197,17 @@ function scorm_update_instance($scorm, $mform=null) {
     $context = context_module::instance($cmid);
 
     if ($scorm->scormtype === SCORM_TYPE_LOCAL) {
-        if ($mform) {
-            $filename = $mform->get_new_filename('packagefile');
+        if ($data = $mform->get_data()) {
+            $fs = get_file_storage();
+            $fs->delete_area_files($context->id, 'mod_scorm', 'package');
+            file_save_draft_area_files($data->packagefile, $context->id, 'mod_scorm', 'package',
+                0, array('subdirs' => 0, 'maxfiles' => 1));
+            // Get filename of zip that was uploaded.
+            $files = $fs->get_area_files($context->id, 'mod_scorm', 'package', 0, '', false);
+            $file = reset($files);
+            $filename = $file->get_filename();
             if ($filename !== false) {
                 $scorm->reference = $filename;
-                $fs = get_file_storage();
-                $fs->delete_area_files($context->id, 'mod_scorm', 'package');
-                $mform->save_stored_file('packagefile', $context->id, 'mod_scorm', 'package', 0, '/', $filename);
             }
         }
 
@@ -511,9 +519,9 @@ function scorm_cron () {
     require_once($CFG->dirroot.'/mod/scorm/locallib.php');
 
     $sitetimezone = $CFG->timezone;
-    /// Now see if there are any scorm updates to be done
+    // Now see if there are any scorm updates to be done.
 
-    if (!isset($CFG->scorm_updatetimelast)) {    // To catch the first time
+    if (!isset($CFG->scorm_updatetimelast)) {    // To catch the first time.
         set_config('scorm_updatetimelast', 0);
     }
 
@@ -524,17 +532,17 @@ function scorm_cron () {
 
         set_config('scorm_updatetimelast', $timenow);
 
-        mtrace('Updating scorm packages which require daily update');//We are updating
+        mtrace('Updating scorm packages which require daily update');// We are updating.
 
-        $scormsupdate = $DB->get_records_select('scorm', 'updatefreq = ? AND scormtype <> ?', array(SCORM_UPDATE_EVERYDAY, SCORM_TYPE_LOCAL));
+        $scormsupdate = $DB->get_records('scorm', array('updatefreq' => SCORM_UPDATE_EVERYDAY));
         foreach ($scormsupdate as $scormupdate) {
             scorm_parse($scormupdate, true);
         }
 
-        //now clear out AICC session table with old session data
-        $cfg_scorm = get_config('scorm');
-        if (!empty($cfg_scorm->allowaicchacp)) {
-            $expiretime = time() - ($cfg_scorm->aicchacpkeepsessiondata*24*60*60);
+        // Now clear out AICC session table with old session data.
+        $cfgscorm = get_config('scorm');
+        if (!empty($cfgscorm->allowaicchacp)) {
+            $expiretime = time() - ($cfgscorm->aicchacpkeepsessiondata*24*60*60);
             $DB->delete_records_select('scorm_aicc_session', 'timemodified < ?', array($expiretime));
         }
     }
@@ -1331,6 +1339,9 @@ function scorm_set_completion($scorm, $userid, $completionstate = COMPLETION_COM
 function scorm_validate_package($file) {
     $packer = get_file_packer('application/zip');
     $errors = array();
+    if ($file->is_external_file()) { // Get zip file so we can check it is correct.
+        $file->import_external_file_contents();
+    }
     $filelist = $file->list_files($packer);
 
     if (!is_array($filelist)) {
@@ -1358,4 +1369,4 @@ function scorm_validate_package($file) {
         }
     }
     return $errors;
-}
\ No newline at end of file
+}
index 561da6f..7c8c43a 100644 (file)
@@ -204,6 +204,9 @@ function scorm_parse($scorm, $full) {
 
         if ($scorm->scormtype === SCORM_TYPE_LOCAL) {
             if ($packagefile = $fs->get_file($context->id, 'mod_scorm', 'package', 0, '/', $scorm->reference)) {
+                if ($packagefile->is_external_file()) { // Get zip file so we can check it is correct.
+                    $packagefile->import_external_file_contents();
+                }
                 $newhash = $packagefile->get_contenthash();
             } else {
                 $newhash = null;
index 8826c86..99d9d87 100644 (file)
@@ -15,7 +15,7 @@
 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
 
 if (!defined('MOODLE_INTERNAL')) {
-    die('Direct access to this script is forbidden.');    ///  It must be included from a Moodle page
+    die('Direct access to this script is forbidden.');    //  It must be included from a Moodle page.
 }
 
 require_once($CFG->dirroot.'/course/moodleform_mod.php');
@@ -23,16 +23,16 @@ require_once($CFG->dirroot.'/mod/scorm/locallib.php');
 
 class mod_scorm_mod_form extends moodleform_mod {
 
-    function definition() {
+    public function definition() {
         global $CFG, $COURSE, $OUTPUT;
-        $cfg_scorm = get_config('scorm');
+        $cfgscorm = get_config('scorm');
 
         $mform = $this->_form;
 
         if (!$CFG->slasharguments) {
             $mform->addElement('static', '', '', $OUTPUT->notification(get_string('slashargs', 'scorm'), 'notifyproblem'));
         }
-        //-------------------------------------------------------------------------------
+
         $mform->addElement('header', 'general', get_string('general', 'form'));
 
         // Name.
@@ -55,15 +55,15 @@ class mod_scorm_mod_form extends moodleform_mod {
         // Scorm types.
         $scormtypes = array(SCORM_TYPE_LOCAL => get_string('typelocal', 'scorm'));
 
-        if ($cfg_scorm->allowtypeexternal) {
+        if ($cfgscorm->allowtypeexternal) {
             $scormtypes[SCORM_TYPE_EXTERNAL] = get_string('typeexternal', 'scorm');
         }
 
-        if ($cfg_scorm->allowtypelocalsync) {
+        if ($cfgscorm->allowtypelocalsync) {
             $scormtypes[SCORM_TYPE_LOCALSYNC] = get_string('typelocalsync', 'scorm');
         }
 
-        if ($cfg_scorm->allowtypeexternalaicc) {
+        if ($cfgscorm->allowtypeexternalaicc) {
             $scormtypes[SCORM_TYPE_AICCURL] = get_string('typeaiccurl', 'scorm');
         }
 
@@ -81,20 +81,20 @@ class mod_scorm_mod_form extends moodleform_mod {
             $mform->setType('scormtype', PARAM_ALPHA);
         }
 
-        if (count($scormtypes) > 1) {
-            // Update packages timing.
-            $mform->addElement('select', 'updatefreq', get_string('updatefreq', 'scorm'), scorm_get_updatefreq_array());
-            $mform->setType('updatefreq', PARAM_INT);
-            $mform->setDefault('updatefreq', $cfg_scorm->updatefreq);
-            $mform->addHelpButton('updatefreq', 'updatefreq', 'scorm');
-            $mform->disabledIf('updatefreq', 'scormtype', 'eq', SCORM_TYPE_LOCAL);
-        } else {
-            $mform->addElement('hidden', 'updatefreq', 0);
-            $mform->setType('updatefreq', PARAM_INT);
-        }
+        // Update packages timing.
+        $mform->addElement('select', 'updatefreq', get_string('updatefreq', 'scorm'), scorm_get_updatefreq_array());
+        $mform->setType('updatefreq', PARAM_INT);
+        $mform->setDefault('updatefreq', $cfgscorm->updatefreq);
+        $mform->addHelpButton('updatefreq', 'updatefreq', 'scorm');
 
         // New local package upload.
-        $mform->addElement('filepicker', 'packagefile', get_string('package', 'scorm'));
+        $filemanageroptions = array();
+        $filemanageroptions['accepted_types'] = array('.zip');
+        $filemanageroptions['maxbytes'] = 0;
+        $filemanageroptions['maxfiles'] = 1;
+        $filemanageroptions['subdirs'] = 0;
+
+        $mform->addElement('filemanager', 'packagefile', get_string('package', 'scorm'), null, $filemanageroptions);
         $mform->addHelpButton('packagefile', 'package', 'scorm');
         $mform->disabledIf('packagefile', 'scormtype', 'noteq', SCORM_TYPE_LOCAL);
 
@@ -103,21 +103,21 @@ class mod_scorm_mod_form extends moodleform_mod {
 
         // Framed / Popup Window.
         $mform->addElement('select', 'popup', get_string('display', 'scorm'), scorm_get_popup_display_array());
-        $mform->setDefault('popup', $cfg_scorm->popup);
-        $mform->setAdvanced('popup', $cfg_scorm->popup_adv);
+        $mform->setDefault('popup', $cfgscorm->popup);
+        $mform->setAdvanced('popup', $cfgscorm->popup_adv);
 
         // Width.
         $mform->addElement('text', 'width', get_string('width', 'scorm'), 'maxlength="5" size="5"');
-        $mform->setDefault('width', $cfg_scorm->framewidth);
+        $mform->setDefault('width', $cfgscorm->framewidth);
         $mform->setType('width', PARAM_INT);
-        $mform->setAdvanced('width', $cfg_scorm->framewidth_adv);
+        $mform->setAdvanced('width', $cfgscorm->framewidth_adv);
         $mform->disabledIf('width', 'popup', 'eq', 0);
 
         // Height.
         $mform->addElement('text', 'height', get_string('height', 'scorm'), 'maxlength="5" size="5"');
-        $mform->setDefault('height', $cfg_scorm->frameheight);
+        $mform->setDefault('height', $cfgscorm->frameheight);
         $mform->setType('height', PARAM_INT);
-        $mform->setAdvanced('height', $cfg_scorm->frameheight_adv);
+        $mform->setAdvanced('height', $cfgscorm->frameheight_adv);
         $mform->disabledIf('height', 'popup', 'eq', 0);
 
         // Window Options.
@@ -128,51 +128,52 @@ class mod_scorm_mod_form extends moodleform_mod {
         }
         $mform->addGroup($winoptgrp, 'winoptgrp', get_string('options', 'scorm'), '<br />', false);
         $mform->disabledIf('winoptgrp', 'popup', 'eq', 0);
-        $mform->setAdvanced('winoptgrp', $cfg_scorm->winoptgrp_adv);
+        $mform->setAdvanced('winoptgrp', $cfgscorm->winoptgrp_adv);
 
         // Skip view page.
         $skipviewoptions = scorm_get_skip_view_array();
         if ($COURSE->format == 'singleactivity') { // Remove option that would cause a constant redirect.
             unset($skipviewoptions[SCORM_SKIPVIEW_ALWAYS]);
-            if ($cfg_scorm->skipview == SCORM_SKIPVIEW_ALWAYS) {
-                $cfg_scorm->skipview = SCORM_SKIPVIEW_FIRST;
+            if ($cfgscorm->skipview == SCORM_SKIPVIEW_ALWAYS) {
+                $cfgscorm->skipview = SCORM_SKIPVIEW_FIRST;
             }
         }
         $mform->addElement('select', 'skipview', get_string('skipview', 'scorm'), $skipviewoptions);
         $mform->addHelpButton('skipview', 'skipview', 'scorm');
-        $mform->setDefault('skipview', $cfg_scorm->skipview);
-        $mform->setAdvanced('skipview', $cfg_scorm->skipview_adv);
+        $mform->setDefault('skipview', $cfgscorm->skipview);
+        $mform->setAdvanced('skipview', $cfgscorm->skipview_adv);
 
         // Hide Browse.
         $mform->addElement('selectyesno', 'hidebrowse', get_string('hidebrowse', 'scorm'));
         $mform->addHelpButton('hidebrowse', 'hidebrowse', 'scorm');
-        $mform->setDefault('hidebrowse', $cfg_scorm->hidebrowse);
-        $mform->setAdvanced('hidebrowse', $cfg_scorm->hidebrowse_adv);
+        $mform->setDefault('hidebrowse', $cfgscorm->hidebrowse);
+        $mform->setAdvanced('hidebrowse', $cfgscorm->hidebrowse_adv);
 
         // Display course structure.
         $mform->addElement('selectyesno', 'displaycoursestructure', get_string('displaycoursestructure', 'scorm'));
         $mform->addHelpButton('displaycoursestructure', 'displaycoursestructure', 'scorm');
-        $mform->setDefault('displaycoursestructure', $cfg_scorm->displaycoursestructure);
-        $mform->setAdvanced('displaycoursestructure', $cfg_scorm->displaycoursestructure_adv);
+        $mform->setDefault('displaycoursestructure', $cfgscorm->displaycoursestructure);
+        $mform->setAdvanced('displaycoursestructure', $cfgscorm->displaycoursestructure_adv);
 
         // Toc display.
         $mform->addElement('select', 'hidetoc', get_string('hidetoc', 'scorm'), scorm_get_hidetoc_array());
         $mform->addHelpButton('hidetoc', 'hidetoc', 'scorm');
-        $mform->setDefault('hidetoc', $cfg_scorm->hidetoc);
-        $mform->setAdvanced('hidetoc', $cfg_scorm->hidetoc_adv);
+        $mform->setDefault('hidetoc', $cfgscorm->hidetoc);
+        $mform->setAdvanced('hidetoc', $cfgscorm->hidetoc_adv);
         $mform->disabledIf('hidetoc', 'scormtype', 'eq', SCORM_TYPE_AICCURL);
 
         // Hide Navigation panel.
         $mform->addElement('selectyesno', 'hidenav', get_string('hidenav', 'scorm'));
-        $mform->setDefault('hidenav', $cfg_scorm->hidenav);
-        $mform->setAdvanced('hidenav', $cfg_scorm->hidenav_adv);
+        $mform->setDefault('hidenav', $cfgscorm->hidenav);
+        $mform->setAdvanced('hidenav', $cfgscorm->hidenav_adv);
         $mform->disabledIf('hidenav', 'hidetoc', 'noteq', 0);
 
         // Display attempt status.
-        $mform->addElement('select', 'displayattemptstatus', get_string('displayattemptstatus', 'scorm'), scorm_get_attemptstatus_array());
+        $mform->addElement('select', 'displayattemptstatus', get_string('displayattemptstatus', 'scorm'),
+                           scorm_get_attemptstatus_array());
         $mform->addHelpButton('displayattemptstatus', 'displayattemptstatus', 'scorm');
-        $mform->setDefault('displayattemptstatus', $cfg_scorm->displayattemptstatus);
-        $mform->setAdvanced('displayattemptstatus', $cfg_scorm->displayattemptstatus_adv);
+        $mform->setDefault('displayattemptstatus', $cfgscorm->displayattemptstatus);
+        $mform->setAdvanced('displayattemptstatus', $cfgscorm->displayattemptstatus_adv);
 
         // Availability.
         $mform->addElement('header', 'availability', get_string('availability'));
@@ -180,21 +181,20 @@ class mod_scorm_mod_form extends moodleform_mod {
         $mform->addElement('date_time_selector', 'timeopen', get_string("scormopen", "scorm"), array('optional' => true));
         $mform->addElement('date_time_selector', 'timeclose', get_string("scormclose", "scorm"), array('optional' => true));
 
-        //-------------------------------------------------------------------------------
         // Grade Settings.
         $mform->addElement('header', 'gradesettings', get_string('grade'));
 
         // Grade Method.
         $mform->addElement('select', 'grademethod', get_string('grademethod', 'scorm'), scorm_get_grade_method_array());
         $mform->addHelpButton('grademethod', 'grademethod', 'scorm');
-        $mform->setDefault('grademethod', $cfg_scorm->grademethod);
+        $mform->setDefault('grademethod', $cfgscorm->grademethod);
 
         // Maximum Grade.
         for ($i=0; $i<=100; $i++) {
             $grades[$i] = "$i";
         }
         $mform->addElement('select', 'maxgrade', get_string('maximumgrade'), $grades);
-        $mform->setDefault('maxgrade', $cfg_scorm->maxgrade);
+        $mform->setDefault('maxgrade', $cfgscorm->maxgrade);
         $mform->disabledIf('maxgrade', 'grademethod', 'eq', GRADESCOES);
 
         // Attempts management.
@@ -203,23 +203,23 @@ class mod_scorm_mod_form extends moodleform_mod {
         // Max Attempts.
         $mform->addElement('select', 'maxattempt', get_string('maximumattempts', 'scorm'), scorm_get_attempts_array());
         $mform->addHelpButton('maxattempt', 'maximumattempts', 'scorm');
-        $mform->setDefault('maxattempt', $cfg_scorm->maxattempt);
+        $mform->setDefault('maxattempt', $cfgscorm->maxattempt);
 
         // What Grade.
         $mform->addElement('select', 'whatgrade', get_string('whatgrade', 'scorm'),  scorm_get_what_grade_array());
         $mform->disabledIf('whatgrade', 'maxattempt', 'eq', 1);
         $mform->addHelpButton('whatgrade', 'whatgrade', 'scorm');
-        $mform->setDefault('whatgrade', $cfg_scorm->whatgrade);
+        $mform->setDefault('whatgrade', $cfgscorm->whatgrade);
 
         // Force new attempt.
         $mform->addElement('selectyesno', 'forcenewattempt', get_string('forcenewattempt', 'scorm'));
         $mform->addHelpButton('forcenewattempt', 'forcenewattempt', 'scorm');
-        $mform->setDefault('forcenewattempt', $cfg_scorm->forcenewattempt);
+        $mform->setDefault('forcenewattempt', $cfgscorm->forcenewattempt);
 
         // Last attempt lock - lock the enter button after the last available attempt has been made.
         $mform->addElement('selectyesno', 'lastattemptlock', get_string('lastattemptlock', 'scorm'));
         $mform->addHelpButton('lastattemptlock', 'lastattemptlock', 'scorm');
-        $mform->setDefault('lastattemptlock', $cfg_scorm->lastattemptlock);
+        $mform->setDefault('lastattemptlock', $cfgscorm->lastattemptlock);
 
         // Compatibility settings.
         $mform->addElement('header', 'compatibilitysettingshdr', get_string('compatibilitysettings', 'scorm'));
@@ -227,14 +227,13 @@ class mod_scorm_mod_form extends moodleform_mod {
         // Force completed.
         $mform->addElement('selectyesno', 'forcecompleted', get_string('forcecompleted', 'scorm'));
         $mform->addHelpButton('forcecompleted', 'forcecompleted', 'scorm');
-        $mform->setDefault('forcecompleted', $cfg_scorm->forcecompleted);
+        $mform->setDefault('forcecompleted', $cfgscorm->forcecompleted);
 
         // Autocontinue.
         $mform->addElement('selectyesno', 'auto', get_string('autocontinue', 'scorm'));
         $mform->addHelpButton('auto', 'autocontinue', 'scorm');
-        $mform->setDefault('auto', $cfg_scorm->auto);
+        $mform->setDefault('auto', $cfgscorm->auto);
 
-        //-------------------------------------------------------------------------------
         // Hidden Settings.
         $mform->addElement('hidden', 'datadir', null);
         $mform->setType('datadir', PARAM_RAW);
@@ -247,101 +246,113 @@ class mod_scorm_mod_form extends moodleform_mod {
         $mform->addElement('hidden', 'redirecturl', null);
         $mform->setType('redirecturl', PARAM_RAW);
 
-        //-------------------------------------------------------------------------------
         $this->standard_coursemodule_elements();
-        //-------------------------------------------------------------------------------
+
         // Buttons.
         $this->add_action_buttons();
     }
 
-    function data_preprocessing(&$default_values) {
+    public function data_preprocessing(&$defaultvalues) {
         global $COURSE;
 
-        if (isset($default_values['popup']) && ($default_values['popup'] == 1) && isset($default_values['options'])) {
-            if (!empty($default_values['options'])) {
-                $options = explode(',', $default_values['options']);
+        if (isset($defaultvalues['popup']) && ($defaultvalues['popup'] == 1) && isset($defaultvalues['options'])) {
+            if (!empty($defaultvalues['options'])) {
+                $options = explode(',', $defaultvalues['options']);
                 foreach ($options as $option) {
                     list($element, $value) = explode('=', $option);
                     $element = trim($element);
-                    $default_values[$element] = trim($value);
+                    $defaultvalues[$element] = trim($value);
                 }
             }
         }
-        if (isset($default_values['grademethod'])) {
-            $default_values['grademethod'] = intval($default_values['grademethod']);
+        if (isset($defaultvalues['grademethod'])) {
+            $defaultvalues['grademethod'] = intval($defaultvalues['grademethod']);
         }
-        if (isset($default_values['width']) && (strpos($default_values['width'], '%') === false) && ($default_values['width'] <= 100)) {
-            $default_values['width'] .= '%';
+        if (isset($defaultvalues['width']) && (strpos($defaultvalues['width'], '%') === false)
+                                           && ($defaultvalues['width'] <= 100)) {
+            $defaultvalues['width'] .= '%';
         }
-        if (isset($default_values['width']) && (strpos($default_values['height'], '%') === false) && ($default_values['height'] <= 100)) {
-            $default_values['height'] .= '%';
+        if (isset($defaultvalues['width']) && (strpos($defaultvalues['height'], '%') === false)
+                                           && ($defaultvalues['height'] <= 100)) {
+            $defaultvalues['height'] .= '%';
         }
         $scorms = get_all_instances_in_course('scorm', $COURSE);
         $coursescorm = current($scorms);
 
         $draftitemid = file_get_submitted_draft_itemid('packagefile');
-        file_prepare_draft_area($draftitemid, $this->context->id, 'mod_scorm', 'package', 0);
-        $default_values['packagefile'] = $draftitemid;
+        file_prepare_draft_area($draftitemid, $this->context->id, 'mod_scorm', 'package', 0,
+            array('subdirs' => 0, 'maxfiles' => 1));
+        $defaultvalues['packagefile'] = $draftitemid;
 
-        if (($COURSE->format == 'singleactivity') && ((count($scorms) == 0) || ($default_values['instance'] == $coursescorm->id))) {
-            $default_values['redirect'] = 'yes';
-            $default_values['redirecturl'] = '../course/view.php?id='.$default_values['course'];
+        if (($COURSE->format == 'singleactivity') && ((count($scorms) == 0) || ($defaultvalues['instance'] == $coursescorm->id))) {
+            $defaultvalues['redirect'] = 'yes';
+            $defaultvalues['redirecturl'] = '../course/view.php?id='.$defaultvalues['course'];
         } else {
-            $default_values['redirect'] = 'no';
-            $default_values['redirecturl'] = '../mod/scorm/view.php?id='.$default_values['coursemodule'];
+            $defaultvalues['redirect'] = 'no';
+            $defaultvalues['redirecturl'] = '../mod/scorm/view.php?id='.$defaultvalues['coursemodule'];
         }
-        if (isset($default_values['version'])) {
-            $default_values['pkgtype'] = (substr($default_values['version'], 0, 5) == 'SCORM') ? 'scorm':'aicc';
+        if (isset($defaultvalues['version'])) {
+            $defaultvalues['pkgtype'] = (substr($defaultvalues['version'], 0, 5) == 'SCORM') ? 'scorm':'aicc';
         }
-        if (isset($default_values['instance'])) {
-            $default_values['datadir'] = $default_values['instance'];
+        if (isset($defaultvalues['instance'])) {
+            $defaultvalues['datadir'] = $defaultvalues['instance'];
         }
-        if (empty($default_values['timeopen'])) {
-            $default_values['timeopen'] = 0;
+        if (empty($defaultvalues['timeopen'])) {
+            $defaultvalues['timeopen'] = 0;
         }
-        if (empty($default_values['timeclose'])) {
-            $default_values['timeclose'] = 0;
+        if (empty($defaultvalues['timeclose'])) {
+            $defaultvalues['timeclose'] = 0;
         }
 
         // Set some completion default data.
-        if (!empty($default_values['completionstatusrequired']) && !is_array($default_values['completionstatusrequired'])) {
+        if (!empty($defaultvalues['completionstatusrequired']) && !is_array($defaultvalues['completionstatusrequired'])) {
             // Unpack values.
             $cvalues = array();
             foreach (scorm_status_options() as $key => $value) {
-                if (($default_values['completionstatusrequired'] & $key) == $key) {
+                if (($defaultvalues['completionstatusrequired'] & $key) == $key) {
                     $cvalues[$key] = 1;
                 }
             }
 
-            $default_values['completionstatusrequired'] = $cvalues;
+            $defaultvalues['completionstatusrequired'] = $cvalues;
         }
 
-        if (!isset($default_values['completionscorerequired']) || !strlen($default_values['completionscorerequired'])) {
-            $default_values['completionscoredisabled'] = 1;
+        if (!isset($defaultvalues['completionscorerequired']) || !strlen($defaultvalues['completionscorerequired'])) {
+            $defaultvalues['completionscoredisabled'] = 1;
         }
 
     }
 
-    function validation($data, $files) {
-        global $CFG;
+    public function validation($data, $files) {
+        global $CFG, $USER;
         $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'])) {
+            if (empty($data['packagefile'])) {
                 $errors['packagefile'] = get_string('required');
 
             } else {
-                $files = $this->get_draft_files('packagefile');
+                $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');
+                }
                 $errors = array_merge($errors, scorm_validate_package($file));
             }
 
@@ -390,34 +401,34 @@ class mod_scorm_mod_form extends moodleform_mod {
     }
 
     // Need to translate the "options" and "reference" field.
-    function set_data($default_values) {
-        $default_values = (array)$default_values;
+    public function set_data($defaultvalues) {
+        $defaultvalues = (array)$defaultvalues;
 
-        if (isset($default_values['scormtype']) and isset($default_values['reference'])) {
-            switch ($default_values['scormtype']) {
+        if (isset($defaultvalues['scormtype']) and isset($defaultvalues['reference'])) {
+            switch ($defaultvalues['scormtype']) {
                 case SCORM_TYPE_LOCALSYNC :
                 case SCORM_TYPE_EXTERNAL:
                 case SCORM_TYPE_AICCURL:
-                    $default_values['packageurl'] = $default_values['reference'];
+                    $defaultvalues['packageurl'] = $defaultvalues['reference'];
             }
         }
-        unset($default_values['reference']);
+        unset($defaultvalues['reference']);
 
-        if (!empty($default_values['options'])) {
-            $options = explode(',', $default_values['options']);
+        if (!empty($defaultvalues['options'])) {
+            $options = explode(',', $defaultvalues['options']);
             foreach ($options as $option) {
                 $opt = explode('=', $option);
                 if (isset($opt[1])) {
-                    $default_values[$opt[0]] = $opt[1];
+                    $defaultvalues[$opt[0]] = $opt[1];
                 }
             }
         }
 
-        $this->data_preprocessing($default_values);
-        parent::set_data($default_values);
+        $this->data_preprocessing($defaultvalues);
+        parent::set_data($defaultvalues);
     }
 
-    function add_completion_rules() {
+    public function add_completion_rules() {
         $mform =& $this->_form;
         $items = array();