f2bc1f59c5f22a504cfb40a3c10879a48752e99d
[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         //
33         $coursedir = "$CFG->dataroot/$course->id";
35         if ($scormdir = make_upload_directory("$course->id/$CFG->moddata/scorm")) {
36             if ($tempdir = scorm_datadir($scormdir, $form->datadir)) {
37                 copy ("$coursedir/$form->reference", $tempdir."/".basename($form->reference));
38                 if (empty($CFG->unzip)) {    // Use built-in php-based unzip function
39                     include_once($CFG->dirroot.'/lib/pclzip/pclzip.lib.php');
40                     $archive = new PclZip($tempdir."/".basename($form->reference));
41                     if (!$list = $archive->extract($tempdir)) {
42                         error($archive->errorInfo(true));
43                     }
44                 } else {
45                     $command = "cd $tempdir; $CFG->unzip -o ".basename($form->reference)." 2>&1";
46                     exec($command);
47                 }
48                 $result = scorm_validate($tempdir."/imsmanifest.xml");
49             } else {
50                 $result = "packagedir";
51             }
52         } else {
53             $result = "datadir";
54         }
55         
56         if ($result != "regular") {
57             //
58             // Delete files and temporary directory
59             //
60             if (is_dir($tempdir))
61                 scorm_delete_files($tempdir);
62         } else {
63             //
64             // Delete package file
65             //
66             unlink ($tempdir."/".basename($form->reference));
67             if ($form->mode == "update") {
68                 $fp = fopen($coursedir."/".$form->reference,"r");
69                 $fstat = fstat($fp);
70                 fclose($fp);
71                 if (get_field("scorm","timemodified","id",$form->instance) < $fstat["mtime"])
72                     $form->launch = 0;
73             }
74         }
75         //
76         // Print validation result
77         //
78         print_simple_box_start("center", "", "$THEME->cellheading");
79         echo "<table cellpadding=\"5\" align=\"center\">\n";
80         echo "    <tr><td align=\"right\" nowrap><p><b>$strname:</b></p></td><td><p>$form->name</p></a></td></tr>\n";
81         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";
82         if (($form->mode == "update") && ($form->launch == 0) && (get_records("scorm_sco_users","scormid",$form->instance)))
83             echo "    <tr><td align=\"center\" colspan=\"2\" nowrap><p><b>".get_string("trackingloose","scorm")."</b></p></td></tr>\n";
84         echo "</table>\n";
85         if ($result == "regular") {
86             if (empty($form->auto)) {
87                 $form->auto = "";
88             }
89             echo "<form name=\"theform\" method=\"post\" action=\"$form->destination\">\n";
90             
91             $form->popup = $CFG->scorm_popup;
92             $strnewwindow     = get_string("newwindow", "scorm");
93             $strnewwindowopen = get_string("newwindowopen", "scorm");
94             foreach ($SCORM_WINDOW_OPTIONS as $optionname) {
95                 $stringname = "str$optionname";
96                 $$stringname = get_string("new$optionname", "scorm");
97                 $window->$optionname = "";
98                 $jsoption[] = "\"$optionname\"";
99             }
100             $alljsoptions = implode(",", $jsoption);
102             if ($form->instance) {     // Re-editing
103                 if ($form->popup == "") {
104                     $newwindow = "";   // Disable the new window
105                 } else {
106                     $newwindow = "checked";
107                     $rawoptions = explode(',', $form->popup); 
108                     foreach ($rawoptions as $rawoption) {
109                         $option = explode('=', trim($rawoption));
110                         if ((option != 'location') && (option != 'menubar') && (option != 'toolbar')) {
111                             $optionname = $option[0];
112                             $optionvalue = $option[1];
113                             if ($optionname == "height" or $optionname == "width") {
114                                 $window->$optionname = $optionvalue;
115                             } else if ($optionvalue) {
116                                 $window->$optionname = "checked";
117                             }
118                         }
119                     }
120                 }
121             } else {
122                 foreach ($SCORM_WINDOW_OPTIONS as $optionname) {
123                     $defaultvalue = "scorm_popup$optionname";
124                     $window->$optionname = $CFG->$defaultvalue;
125                 }
126                 $newwindow = $CFG->scorm_popup;
127             }
128             
129 ?>
130         <table cellpadding="5" align="center">
131           <tr valign=top>
132             <td align=right><p><b><?php print_string("autocontinue","scorm") ?>:</b></p></td>
133             <td>
134             <?php
135                 $options[]=get_string("no");
136                 $options[]=get_string("yes");
137                 choose_from_menu ($options, "auto", $form->auto);
138             ?>
139             </td>
140           </tr>
141           <tr valign="top">
142             <td align="right" nowrap>
143                 <p><b><?php p($strnewwindow) ?></b></p>
144             </td>
145             <td>
146                 <script>
147                     var subitems = [<?php echo $alljsoptions; ?>];
148                     
149                     function autowindow() {
150                         if (document.theform.newwindow.checked) 
151                             document.theform.auto.disabled=true;
152                         else
153                             document.theform.auto.disabled=false;
154                     }
155                 </script>
156                 <input name="setnewwindow" type=hidden value=1>
157                 <input name="newwindow" type=checkbox value=1 <?php p($newwindow) ?> 
158                         onclick="autowindow();return lockoptions('theform','newwindow', subitems);"> 
159                 <?php p($strnewwindowopen) ?>
160                 <ul>
161                 <?php
162                     foreach ($window as $name => $value) {
163                         if ($name == "height" or $name == "width") {
164                             continue;
165                         }
166                         echo "\t\t<input name=\"h$name\" type=hidden value=0>\n";
167                         echo "\t\t<input name=\"$name\" type=checkbox value=1 ".$window->$name."> ";
168                         $stringname = "str$name";
169                         echo $$stringname."<br />\n";
170                      }
171                  ?>
173                  <input name="hwidth" type=hidden value=0>
174                  <input name="width" type=text size=4 value="<?php p($window->width) ?>">
175                  <?php p($strwidth) ?><br />
177                  <input name="hheight" type=hidden value=0>
178                  <input name="height" type=text size=4 value="<?php p($window->height) ?>">
179                  <?php p($strheight) ?><br />
180                  <?php
181                      if (!$newwindow) {
182                          echo "<script>";
183                          echo "lockoptions('theform','newwindow', subitems);";
184                          echo "</script>";
185                      }
186                  ?>
187                  </ul>
188                  </p>
189              </td>
190            </tr>
191         </table>
192         <input type="hidden" name="reference"   value="<?php p($form->reference) ?>">
193         <input type="hidden" name="datadir"     value="<?php p(substr($tempdir,strlen($scormdir))) ?>">
194         <input type="hidden" name="summary"     value="<?php p($form->summary) ?>">
195         <input type="hidden" name="name"        value="<?php p($form->name) ?>">
196         <input type="hidden" name="launch"      value="<?php p($form->launch) ?>">
197         <input type="hidden" name="course"      value="<?php p($form->course) ?>">
198         <input type="hidden" name="coursemodule"        value="<?php p($form->coursemodule) ?>">
199         <input type="hidden" name="section"     value="<?php p($form->section) ?>">
200         <input type="hidden" name="module"      value="<?php p($form->module) ?>">
201         <input type="hidden" name="modulename"  value="<?php p($form->modulename) ?>">
202         <input type="hidden" name="instance"    value="<?php p($form->instance) ?>">
203         <input type="hidden" name="mode"        value="<?php p($form->mode) ?>">
204         <center>
205             <input type="submit" value="<?php print_string("savechanges") ?>">
206             <input type="submit" name=cancel value="<?php print_string("cancel") ?>">
207         </center>
208         </form>
209 <?php
210         } else {
211 ?>
212         <center>
213            <input type="button" value="<?php print_string("continue") ?>" onClick="document.location='<?php echo $CFG->wwwroot ?>/course/view.php?id=<?php echo $course->id ?>';">
214         </center>
215 <?php
216         }
217         print_simple_box_end();
218         print_footer($course);
219     } else {
220            error("This script was called incorrectly");
221     }
222 ?>