Fixed some popup window problems (some still fixing)
[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);
101             
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[0] != 'location') && ($option[0] != 'menubar') && ($option[0] != 'toolbar')) {
111                             $optionname = $option[0];
112                             $optionvalue = $option[1];
113                             if ($optionname == "height" or $optionname == "width") {
114                                 $window->$optionname = $optionvalue;
115                             } else if ($optionvalue == 1) {
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                     
156                     <?php
157                         if ($newwindow == "checked")
158                             echo "document.theform.auto.disabled=true;\n";
159                     ?>
160                 </script>
161                 <input name="setnewwindow" type=hidden value=1 />
162                 <input name="newwindow" type=checkbox value=1 <?php p($newwindow) ?> onclick="autowindow();return lockoptions('theform','newwindow', subitems);" /> 
163                 <?php p($strnewwindowopen) ?>
164                 <ul>
165                 <?php
166                     foreach ($window as $name => $value) {
167                         if ($name == "height" or $name == "width") {
168                             continue;
169                         }
170                         echo "\t\t<input name=\"h$name\" type=\"hidden\" value=\"0\" />\n";
171                         echo "\t\t<input name=\"$name\" type=\"checkbox\" value=\"1\" ".$window->$name." /> ";
172                         $stringname = "str$name";
173                         echo $$stringname."<br />\n";
174                      }
175                 ?>
177                 <input name="hwidth" type=hidden value="0" />
178                 <input name="width" type=text size=4 value="<?php p($window->width) ?>" /> <?php p($strwidth) ?><br />
179                 <input name="hheight" type=hidden value="0" />
180                 <input name="height" type=text size=4 value="<?php p($window->height) ?>" /> <?php p($strheight) ?><br />
181                  <?php
182                      if (!$newwindow) {
183                          echo "<script>\n<!--\n";
184                          echo "\tlockoptions('theform','newwindow', subitems);";
185                          echo "\n-->\n</script>";
186                      }
187                  ?>
188                  </ul>
189                  </p>
190              </td>
191            </tr>
192         </table>
193         <input type="hidden" name="reference"   value="<?php p($form->reference) ?>" />
194         <input type="hidden" name="datadir"     value="<?php p(substr($tempdir,strlen($scormdir))) ?>" />
195         <input type="hidden" name="summary"     value="<?php p($form->summary) ?>" />
196         <input type="hidden" name="name"        value="<?php p($form->name) ?>" />
197         <input type="hidden" name="launch"      value="<?php p($form->launch) ?>" />
198         <input type="hidden" name="course"      value="<?php p($form->course) ?>" />
199         <input type="hidden" name="coursemodule"        value="<?php p($form->coursemodule) ?>" />
200         <input type="hidden" name="section"     value="<?php p($form->section) ?>" />
201         <input type="hidden" name="module"      value="<?php p($form->module) ?>" />
202         <input type="hidden" name="modulename"  value="<?php p($form->modulename) ?>" />
203         <input type="hidden" name="instance"    value="<?php p($form->instance) ?>" />
204         <input type="hidden" name="mode"        value="<?php p($form->mode) ?>" />
205         <div align="center">
206             <input type="submit" value="<?php print_string("savechanges") ?>" />
207             <input type="submit" name=cancel value="<?php print_string("cancel") ?>" />
208         </div>
209         </form>
210 <?php
211         } else {
212 ?>
213         <center>
214            <input type="button" value="<?php print_string("continue") ?>" onClick="document.location='<?php echo $CFG->wwwroot ?>/course/view.php?id=<?php echo $course->id ?>';">
215         </center>
216 <?php
217         }
218         print_simple_box_end();
219         print_footer($course);
220     } else {
221            error("This script was called incorrectly");
222     }
223 ?>