Index: mod/scorm/view.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/scorm/view.php,v
retrieving revision 1.56.2.4
diff -u -r1.56.2.4 view.php
--- mod/scorm/view.php	6 Aug 2008 05:06:00 -0000	1.56.2.4
+++ mod/scorm/view.php	28 Nov 2008 07:52:00 -0000
@@ -83,6 +83,20 @@
     // Print the main part of the page
     print_heading(format_string($scorm->name));
     print_box(format_text($scorm->summary), 'generalbox', 'intro');
-    scorm_view_display($USER, $scorm, 'view.php?id='.$cm->id, $cm);
+    
+    $scormopen = true;
+    $timenow = time();
+    if ($scorm->timeclose !=0) {
+        if ($scorm->timeopen > $timenow) {
+            print_simple_box(get_string("notopenyet", "scorm", userdate($scorm->timeopen)), "center");
+            $scormopen = false;
+        } else if ($timenow > $scorm->timeclose) {
+            print_simple_box(get_string("expired", "scorm", userdate($scorm->timeclose)), "center");
+            $scormopen = false;
+        }
+    }
+    if ($scormopen) {
+        scorm_view_display($USER, $scorm, 'view.php?id='.$cm->id, $cm);
+    }
     print_footer($course);
 ?>
Index: mod/scorm/player.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/scorm/player.php,v
retrieving revision 1.34.2.9
diff -u -r1.34.2.9 player.php
--- mod/scorm/player.php	14 Nov 2008 00:14:50 -0000	1.34.2.9
+++ mod/scorm/player.php	28 Nov 2008 07:52:00 -0000
@@ -67,7 +67,32 @@
         print_header($pagetitle, $course->fullname, $navigation,
                  '', '', true, update_module_button($cm->id, $course->id, $strscorm), '', false);
         notice(get_string("activityiscurrentlyhidden"));
+        print_footer($course);
+        die;
     }
+
+    //check if scorm closed
+    $timenow = time();
+    if ($scorm->timeclose !=0) {
+        if ($scorm->timeopen > $timenow) {
+            $navlinks[] = array('name' => format_string($scorm->name,true), 'link' => "view.php?id=$cm->id", 'type' => 'activityinstance');
+            $navigation = build_navigation($navlinks);
+            print_header($pagetitle, $course->fullname, $navigation,
+                     '', '', true, update_module_button($cm->id, $course->id, $strscorm), '', false);
+            print_simple_box(get_string("notopenyet", "scorm", userdate($scorm->timeopen)), "center");
+            print_footer($course);
+            die;
+        } else if ($timenow > $scorm->timeclose) {
+            $navlinks[] = array('name' => format_string($scorm->name,true), 'link' => "view.php?id=$cm->id", 'type' => 'activityinstance');
+            $navigation = build_navigation($navlinks);
+            print_header($pagetitle, $course->fullname, $navigation,
+                     '', '', true, update_module_button($cm->id, $course->id, $strscorm), '', false);
+            print_simple_box(get_string("expired", "scorm", userdate($scorm->timeclose)), "center");
+            print_footer($course);
+            die;
+        }
+    }
+
     //
     // TOC processing
     //
Index: mod/scorm/mod_form.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/scorm/mod_form.php,v
retrieving revision 1.11.2.10
diff -u -r1.11.2.10 mod_form.php
--- mod/scorm/mod_form.php	14 Nov 2008 00:14:50 -0000	1.11.2.10
+++ mod/scorm/mod_form.php	28 Nov 2008 07:52:00 -0000
@@ -40,6 +40,19 @@
         $mform->setHelpButton('reference',array('package', get_string('package', 'scorm'), 'scorm'));
 
 //-------------------------------------------------------------------------------
+// Time restrictions
+        $mform->addElement('header', 'timerestricthdr', get_string('timerestrict', 'scorm'));
+        $mform->addElement('checkbox', 'timerestrict', get_string('timerestrict', 'scorm'));
+        $mform->setHelpButton('timerestrict', array("timerestrict", get_string("timerestrict","scorm"), "scorm"));
+
+
+        $mform->addElement('date_time_selector', 'timeopen', get_string("scormopen", "scorm"));
+        $mform->disabledIf('timeopen', 'timerestrict');
+
+        $mform->addElement('date_time_selector', 'timeclose', get_string("scormclose", "scorm"));
+        $mform->disabledIf('timeclose', 'timerestrict');
+
+//-------------------------------------------------------------------------------
 // Other Settings
         $mform->addElement('header', 'advanced', get_string('othersettings', 'form'));
 
@@ -211,6 +224,11 @@
         if (isset($default_values['instance'])) {
             $default_values['datadir'] = $default_values['instance'];
         }
+        if (empty($default_values['timeopen'])) {
+            $default_values['timerestrict'] = 0;
+        } else {
+            $default_values['timerestrict'] = 1;
+        }
     }
 
     function validation($data, $files) {
Index: mod/scorm/loadSCO.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/scorm/loadSCO.php,v
retrieving revision 1.33.4.8
diff -u -r1.33.4.8 loadSCO.php
--- mod/scorm/loadSCO.php	28 Nov 2008 06:49:49 -0000	1.33.4.8
+++ mod/scorm/loadSCO.php	28 Nov 2008 07:52:00 -0000
@@ -33,6 +33,17 @@
     }
 
     require_login($course->id, false, $cm);
+    
+    //check if scorm closed
+    $timenow = time();
+    if ($scorm->timeclose !=0) {
+        if ($scorm->timeopen > $timenow) {
+            error(get_string("notopenyet", "scorm", userdate($scorm->timeopen)));
+        } else if ($timenow > $scorm->timeclose) {
+            error(get_string("expired", "scorm", userdate($scorm->timeclose)));
+        }
+    }
+    
     if (!empty($scoid)) {
     //
     // Direct SCO request
Index: mod/scorm/version.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/scorm/version.php,v
retrieving revision 1.53.2.3
diff -u -r1.53.2.3 version.php
--- mod/scorm/version.php	1 Aug 2008 04:30:45 -0000	1.53.2.3
+++ mod/scorm/version.php	28 Nov 2008 07:52:00 -0000
@@ -10,7 +10,7 @@
 //       catch up now, so until 27th October please only increment in very tiny steps 
 //       in HEAD, until we get past that date..
 
-$module->version  = 2007110501;   // The (date) version of this module
+$module->version  = 2007110502;   // The (date) version of this module
 $module->requires = 2007101509;   // The version of Moodle that is required
 $module->cron     = 300;            // How often should cron check this module (seconds)?
 
Index: mod/scorm/lib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/scorm/lib.php,v
retrieving revision 1.87.2.13
diff -u -r1.87.2.13 lib.php
--- mod/scorm/lib.php	14 Nov 2008 00:14:50 -0000	1.87.2.13
+++ mod/scorm/lib.php	28 Nov 2008 07:52:00 -0000
@@ -15,6 +15,11 @@
 
     require_once('locallib.php');
 
+    if (empty($scorm->timerestrict)) {
+        $scorm->timeopen = 0;
+        $scorm->timeclose = 0;
+    }
+
     if (($packagedata = scorm_check_package($scorm)) != null) {
         $scorm->pkgtype = $packagedata->pkgtype;
         $scorm->datadir = $packagedata->datadir;
@@ -82,6 +87,11 @@
 
     require_once('locallib.php');
 
+    if (empty($scorm->timerestrict)) {
+        $scorm->timeopen = 0;
+        $scorm->timeclose = 0;
+    }
+
     $scorm->parse = 0;
     if (($packagedata = scorm_check_package($scorm)) != null) {
         $scorm->pkgtype = $packagedata->pkgtype;
Index: mod/scorm/db/upgrade.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/scorm/db/upgrade.php,v
retrieving revision 1.13.2.3
diff -u -r1.13.2.3 upgrade.php
--- mod/scorm/db/upgrade.php	1 Aug 2008 04:30:45 -0000	1.13.2.3
+++ mod/scorm/db/upgrade.php	28 Nov 2008 07:52:00 -0000
@@ -302,7 +302,19 @@
             $result = $result && add_field($table, $field);
         }
     }
-    
+    if ($result && $oldversion < 2007110502) {
+        $table = new XMLDBTable('scorm');
+        $field = new XMLDBField('timeopen');
+        if (!field_exists($table, $field)) {
+            $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'height');
+            $result = $result && add_field($table, $field);
+        }
+        $field = new XMLDBField('timeclose');
+        if (!field_exists($table, $field)) {
+            $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'timeopen');
+            $result = $result && add_field($table, $field);
+        }
+    }
     
 //===== 1.9.0 upgrade line ======//
 
Index: mod/scorm/db/install.xml
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/scorm/db/install.xml,v
retrieving revision 1.7.2.1
diff -u -r1.7.2.1 install.xml
--- mod/scorm/db/install.xml	1 Aug 2008 04:30:45 -0000	1.7.2.1
+++ mod/scorm/db/install.xml	28 Nov 2008 07:52:00 -0000
@@ -27,8 +27,10 @@
         <FIELD NAME="popup" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="auto" NEXT="options"/>
         <FIELD NAME="options" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="popup" NEXT="width"/>
         <FIELD NAME="width" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="100" SEQUENCE="false" ENUM="false" PREVIOUS="options" NEXT="height"/>
-        <FIELD NAME="height" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="600" SEQUENCE="false" ENUM="false" PREVIOUS="width" NEXT="timemodified"/>
-        <FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="height"/>
+        <FIELD NAME="height" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="600" SEQUENCE="false" ENUM="false" PREVIOUS="width" NEXT="timeopen"/>
+        <FIELD NAME="timeopen" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="height" NEXT="timeclose"/>
+        <FIELD NAME="timeclose" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="timeopen" NEXT="timemodified"/>
+        <FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="timeclose"/>
       </FIELDS>
       <KEYS>
         <KEY NAME="primary" TYPE="primary" FIELDS="id" />
Index: lang/en_utf8/scorm.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lang/en_utf8/scorm.php,v
retrieving revision 1.18.4.10
diff -u -r1.18.4.10 scorm.php
--- lang/en_utf8/scorm.php	14 Nov 2008 00:14:50 -0000	1.18.4.10
+++ lang/en_utf8/scorm.php	28 Nov 2008 07:51:59 -0000
@@ -42,6 +42,7 @@
 $string['exit'] = 'Exit course';
 $string['exitactivity'] = 'Exit activity';
 $string['expcoll'] = 'Expand/Collide';
+$string['expired'] = 'Sorry, this activity closed on $a and is no longer available';
 $string['external']= 'Update external packages timing';
 $string['failed'] = 'Failed';
 $string['firstaccess'] = 'First access';
@@ -102,6 +103,7 @@
 $string['noscriptnoscorm'] = 'Your browser does not support javascript or it has javascript support disabled. This SCORM package may not play or save data correctly.';
 $string['not_corr_type'] = 'Type mismatch for tag $a->tag';
 $string['notattempted'] = 'Not attempted';
+$string['notopenyet'] = 'Sorry, this activity is not available until $a';
 $string['objectives'] = 'Objectives';
 $string['onchanges']= 'Whenever it changes';
 $string['organization'] = 'Organization';
@@ -132,6 +134,8 @@
 $string['scorm:skipview'] = 'Skip overview';
 $string['scorm:viewreport'] = 'View reports';
 $string['scorm:viewscores'] = 'View scores';
+$string['scormclose'] = 'Until';
+$string['scormopen'] = 'Open';
 $string['scormcourse'] = 'Learning Course';
 $string['scrollbars'] = 'Allow the window to be scrolled';
 $string['sided'] = 'On the left side';
@@ -147,6 +151,7 @@
 $string['syntax'] = 'Syntax error';
 $string['tag_error'] = 'Unknown tag ($a->tag) with this content: $a->value';
 $string['time'] = 'Time';
+$string['timerestrict'] = 'Restrict answering to this time period';
 $string['title'] = 'Title';
 $string['too_many_attributes'] = 'Tag $a->tag has too many attributes';
 $string['too_many_children'] = 'Tag $a->tag has too many children';
Index: lang/en_utf8/help/scorm/timerestrict.html
===================================================================
RCS file: lang/en_utf8/help/scorm/timerestrict.html
diff -N lang/en_utf8/help/scorm/timerestrict.html
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ lang/en_utf8/help/scorm/timerestrict.html	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,8 @@
+<h1>Restrict times</h1>
+
+<p>This setting allows you to define a time window within which 
+   participants are allowed to attempt a SCORM.</p>
+
+<p>To set an open-ended close date just set the time very far in the future.</p>
+
+<p>If you don't need this at all then uncheck the box.</p>

