Putting SCORM into maintree CVS, to make it easier to test.
[moodle.git] / mod / scorm / details.php
1 <?PHP // $Id$
3     require_once("../../config.php");
4     require_once("lib.php");
6     require_login();
7     if ($form = data_submitted($destination)) { 
9         if (! $course = get_record("course", "id", $form->course)) {
10             error("This course doesn't exist");
11         }
13         require_login($course->id);
15         if (!isteacher($course->id)) {
16             error("You can't modify this course!");
17         }
19         $strediting = get_string("validateascorm", "scorm");
20         $strname = get_string("name");
22         print_header("$course->shortname: $strediting", "$course->shortname: $strediting",
23                       "<A HREF=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</A> -> $strediting");
25         if (!$form->name or !$form->reference or !$form->summary) {
26             error(get_string("filloutallfields"), $_SERVER["HTTP_REFERER"]);
27         }
28         
29         //
30         // Create a temporary directory to unzip package and validate imsmanifest
31         //
32         $basedir = $CFG->dataroot."/".$course->id;
33         $scormdir = "/moddata/scorm";   
34         if (scorm_mkdirs($basedir.$scormdir)) {
35             if ($tempdir = scorm_datadir($basedir.$scormdir, $form->datadir)) {
36                 copy ($basedir."/".$form->reference, $tempdir."/".basename($form->reference));
37                 if (empty($CFG->unzip)) {    // Use built-in php-based unzip function
38                     include_once($CFG->dirroot.'/lib/pclzip/pclzip.lib.php');
39                     $archive = new PclZip($tempdir."/".basename($form->reference));
40                     if (!$list = $archive->extract($tempdir)) {
41                         error($archive->errorInfo(true));
42                     }
43                 } else {
44                     $command = "cd $tempdir; $CFG->unzip -o ".basename($form->reference)." 2>&1";
45                     exec($command);
46                 }
47                 $result = scorm_validate($tempdir."/imsmanifest.xml");
48             } else {
49                 $result = "packagedir";
50             }
51         } else {
52             $result = "datadir";
53         }
54         
55         if ($result != "regular") {
56             //
57             // Delete files and temporary directory
58             //
59             if (is_dir($tempdir))
60                 scorm_delete_files($tempdir);
61         } else {
62             //
63             // Delete package file
64             //
65             unlink ($tempdir."/".basename($form->reference));
66             if ($form->mode == "update") {
67                 $fp = fopen($basedir."/".$form->reference,"r");
68                 $fstat = fstat($fp);
69                 fclose($fp);
70                 if (get_field("scorm","timemodified","id",$form->instance) < $fstat["mtime"])
71                     $form->launch = 0;
72             }
73         }
74         //
75         // Print validation result
76         //
77         print_simple_box_start("center", "", "$THEME->cellheading");
78         echo "<table cellpadding=\"5\" align=\"center\">\n";
79         echo "    <tr><td align=\"right\" nowrap><p><b>$strname:</b></p></td><td><p>$form->name</p></a></td></tr>\n";
80         echo "    <tr><td align=\"right\" nowrap><p><b>".get_string("validation","scorm").":</b></p></td><td><p>".get_string($result,"scorm")."</p></a></td></tr>\n";
81         if (($form->mode == "update") && ($form->launch == 0) && (get_records("scorm_sco_user","scormid",$form->instance)))
82             echo "    <tr><td align=\"center\" colspan=\"2\" nowrap><p><b>".get_string("trackingloose","scorm")."</b></p></td></tr>\n";
83         echo "</table>\n";
84         if ($result == "regular") {
85             echo "<form name=\"theform\" method=\"post\" $onsubmit action=\"$form->destination\">\n";
86 ?>
87         <input type="hidden" name="reference"   value="<?php p($form->reference) ?>">
88         <input type="hidden" name="datadir"     value="<?php p(substr($tempdir,strlen($basedir)+strlen($scormdir))) ?>">
89         <input type="hidden" name="summary"     value="<?php p($form->summary) ?>">
90         <input type="hidden" name="auto"        value="<?php p($form->auto) ?>">
91         <input type="hidden" name="name"        value="<?php p($form->name) ?>">
92         <input type="hidden" name="launch"      value="<?php p($form->launch) ?>">
93         <input type="hidden" name="course"      value="<?php p($form->course) ?>">
94         <input type="hidden" name="coursemodule"        value="<?php p($form->coursemodule) ?>">
95         <input type="hidden" name="section"     value="<?php p($form->section) ?>">
96         <input type="hidden" name="module"      value="<?php p($form->module) ?>">
97         <input type="hidden" name="modulename"  value="<?php p($form->modulename) ?>">
98         <input type="hidden" name="instance"    value="<?php p($form->instance) ?>">
99         <input type="hidden" name="mode"        value="<?php p($form->mode) ?>">
100         <center>
101             <input type="submit" value="<?php print_string("savechanges") ?>">
102             <input type="submit" name=cancel value="<?php print_string("cancel") ?>">
103         </center>
104         </form>
105 <?
106         } else {
107 ?>
108         <center>
109            <input type="button" value="<?php print_string("continue") ?>" onClick="document.location='<?php echo $CFG->wwwroot ?>/course/view.php?id=<?php echo $course->id ?>';">
110         </center>
111 <?
112         }
113         print_simple_box_end();
114         print_footer($course);
115     } else {
116            error("This script was called incorrectly");
117     }
118 ?>