New styles added
[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_simple("$strediting", "$strediting",
23                       "$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";
34     $form->reference = clean_param($form->reference, PARAM_PATH);
35     
36     if ($scormdir = make_upload_directory("$course->id/$CFG->moddata/scorm")) {
37         if ($tempdir = scorm_datadir($scormdir, $form->datadir)) {
38             copy ("$coursedir/$form->reference", $tempdir."/".basename($form->reference));
39             unzip_file($tempdir."/".basename($form->reference), $tempdir, false);
40             $result = scorm_validate($tempdir."/imsmanifest.xml");
41         } else {
42             $result = "packagedir";
43         }
44     } else {
45         $result = "datadir";
46     }
47     $errorlogs = '';
48     if (($result != "regular") && ($result != "found")) {
49         if ($CFG->scorm_validate == 'domxml') {
50             foreach ($errors as $error) {
51                 $errorlogs .= get_string($error->type,"scorm",$error->data) . ".\n";
52             }
53         }
54         //
55         // Delete files and temporary directory
56         //
57         if (is_dir($tempdir))
58             scorm_delete_files($tempdir);
59         } else {
60         //
61         // Delete package file
62         //
63         unlink ($tempdir."/".basename($form->reference));
64         if ($form->mode == "update") {
65             $fp = fopen($coursedir."/".$form->reference,"r");
66             $fstat = fstat($fp);
67             fclose($fp);
68             if (get_field("scorm","timemodified","id",$form->instance) < $fstat["mtime"]) {
69                 $form->launch = 0;
70             }
71         }
72     }
73     //
74     // Print validation result
75     //
76     print_simple_box_start('center');
77     echo "<table cellpadding=\"5\" align=\"center\">\n";
78     echo "    <tr><td align=\"right\" nowrap=\"nowrap\"><b>$strname:</b></td><td>$form->name</td></tr>\n";
79     echo "    <tr><td align=\"right\" nowrap=\"nowrap\"><b>".get_string("validation","scorm").":</b></td><td>".get_string($result,"scorm")."</td></tr>\n";
80     if ($errorlogs != '') {
81         $lines = round(count($errors)/4);
82         if ($lines < 5) {
83             $lines = 5;
84         }
85         echo "    <tr><td align=\"right\" nowrap=\"nowrap\"><b>".get_string("errorlogs","scorm").":</b></td><td><textarea rows=\"".$lines."\" cols=\"30\" readonly>".$errorlogs."</textarea></a></td></tr>\n";
86     }
87     if (($form->mode == "update") && ($form->launch == 0) && (get_records("scorm_sco_users","scormid",$form->instance))) {
88         echo "    <tr><td align=\"center\" colspan=\"2\" nowrap=\"nowrap\"><b>".get_string("trackingloose","scorm")."</b></td></tr>\n";
89     }
90     echo "</table>\n";
91     if (($result == "regular") || ($result == "found")) {
92         if (empty($form->auto)) {
93             $form->auto = "";
94         }
95         if (empty($form->maxgrade)) {
96             $form->maxgrade = "";
97         }
98         if (empty($form->grademethod)) {
99             $form->grademethod = "0";
100         }
101         echo "<form name=\"theform\" method=\"post\" action=\"$form->destination\">\n";
102         
103         //$form->popup = $CFG->scorm_popup;
104         $strnewwindow     = get_string("newwindow", "scorm");
105         $strnewwindowopen = get_string("newwindowopen", "scorm");
106         foreach ($SCORM_WINDOW_OPTIONS as $optionname) {
107             $stringname = "str$optionname";
108             $$stringname = get_string("new$optionname", "scorm");
109             $window->$optionname = "";
110             $jsoption[] = "\"$optionname\"";
111         }
112         $alljsoptions = implode(",", $jsoption);
113         
114         if ($form->instance) {     // Re-editing
115             if ($form->popup == "") {
116                 $newwindow = "";   // Disable the new window
117                 foreach ($SCORM_WINDOW_OPTIONS as $optionname) {
118                     $defaultvalue = "scorm_popup$optionname";
119                     $window->$optionname = $CFG->$defaultvalue;
120                 }
121             } else {
122                 $newwindow = "checked";
123                 $rawoptions = explode(',', $form->popup); 
124                 foreach ($rawoptions as $rawoption) {
125                     $option = explode('=', trim($rawoption));
126                     if (($option[0] != 'location') && ($option[0] != 'menubar') && ($option[0] != 'toolbar')) {
127                         $optionname = $option[0];
128                         $optionvalue = $option[1];
129                         if ($optionname == "height" or $optionname == "width") {
130                             $window->$optionname = $optionvalue;
131                         } else if ($optionvalue == 1) {
132                             $window->$optionname = "checked";
133                         }
134                     }
135                 }
136             }
137         } else {
138             foreach ($SCORM_WINDOW_OPTIONS as $optionname) {
139                 $defaultvalue = "scorm_popup$optionname";
140                 $window->$optionname = $CFG->$defaultvalue;
141             }
142             $newwindow = $CFG->scorm_popup;
143         }    
144 ?>
145     <table cellpadding="5" align="center">
146         <tr valign="top">
147             <td align="right"><b><?php print_string("grademethod", "scorm") ?>:</b></td>
148             <td>
149             <?php
150                 $options = array();
151                 $options[0] = get_string("gradescoes", "scorm");
152                 $options[1] = get_string("gradehighest", "scorm");
153                 $options[2] = get_string("gradeaverage", "scorm");
154                 choose_from_menu($SCORM_GRADE_METHOD, "grademethod", "$form->grademethod", "");
155                 helpbutton("grademethod", get_string("grademethod","scorm"), "scorm");
156             ?>
157             </td>
158         </tr>
159         <tr valign="top">
160             <td align="right"><b><?php print_string("maximumgrade") ?>:</b></td>
161             <td>
162             <?php
163                 for ($i=100; $i>=1; $i--) {
164                     $grades[$i] = $i;
165                 }
167                 choose_from_menu($grades, "maxgrade", "$form->maxgrade", "");
168                 helpbutton("maxgrade", get_string("maximumgrade"), "scorm");
169             ?>
170             </td>
171         </tr>
172         <tr valign="top">
173             <td align="right"><b><?php print_string("autocontinue","scorm") ?>:</b></td>
174             <td>
175             <?php
176                 $options = array();
177                 $options[0]=get_string("no");
178                 $options[1]=get_string("yes");
179                 choose_from_menu ($options, "auto", $form->auto);
180             ?>
181             </td>
182         </tr>
183         <tr valign="top">
184             <td align="right" nowrap="nowrap">
185                 <b><?php p($strnewwindow) ?>:</b>
186             </td>
187             <td>
188                 <script type="text/javascript">
189                     var subitems = [<?php echo $alljsoptions; ?>];
190                     
191                     function autowindow() {
192                         if (document.theform.newwindow.checked) {
193                             document.theform.auto.disabled=true;
194                         } else {
195                             document.theform.auto.disabled=false;
196                         }
197                     }
198                     
199                     <?php
200                         if ($newwindow == "checked") {
201                             echo "document.theform.auto.disabled=true;\n";
202                             $newwindow = "checked='checked'";
203                         }
204                     ?>
205                 </script>
206                 <input name="setnewwindow" type="hidden" value="1" />
207                 <input name="newwindow" type="checkbox" value="1" onclick="autowindow();return lockoptions('theform','newwindow', subitems);" <?php echo $newwindow ?> /> 
208                 <?php echo $strnewwindowopen."\n"; ?>
209                 <ul style='list-style-type:none;'><li>
210                 <?php
211                      foreach ($window as $name => $value) {
212                          if ($name == "height" or $name == "width") {
213                              continue;
214                          }
215                          echo "\t\t<input name=\"h$name\" type=\"hidden\" value=\"0\" />\n";
216                          if ($window->$name == 'checked') {
217                              $window->$name = 'checked="checked"';
218                          }
219                          echo "\t\t<input name=\"$name\" type=\"checkbox\" value=\"1\" ".$window->$name." /> ";
220                          $stringname = "str$name";
221                          echo $$stringname."<br />\n";
222                      }
223                 ?>
225                 <input name="hwidth" type="hidden" value="0" />
226                 <input name="width" type="text" size="4" value="<?php p($window->width) ?>" alt="width" /> <?php p($strwidth) ?><br />
227                 <input name="hheight" type="hidden" value="0" />
228                 <input name="height" type="text" size="4" value="<?php p($window->height) ?>" alt="height" /> <?php p($strheight) ?><br />
229                 <?php
230                      if (!$newwindow) {
231                          echo "<script type=\"text/javascript\">\n<!--\n";
232                          echo "\tlockoptions('theform','newwindow', subitems);";
233                          echo "\n-->\n</script>";
234                      }
235                  ?>
236                  </li></ul>
237              </td>
238          </tr>
239       </table>
240       <input type="hidden" name="reference"   value="<?php p($form->reference) ?>" />
241       <input type="hidden" name="datadir" value="<?php p(substr($tempdir,strlen($scormdir))) ?>" />
242       <input type="hidden" name="summary" value="<?php p($form->summary) ?>" />
243       <input type="hidden" name="name"    value="<?php p($form->name) ?>" />
244       <input type="hidden" name="launch"  value="<?php p($form->launch) ?>" />
245       <input type="hidden" name="course"  value="<?php p($form->course) ?>" />
246       <input type="hidden" name="sesskey" value="<?php p($form->sesskey) ?>" />
247       <input type="hidden" name="coursemodule"    value="<?php p($form->coursemodule) ?>" />
248       <input type="hidden" name="section" value="<?php p($form->section) ?>" />
249       <input type="hidden" name="module"  value="<?php p($form->module) ?>" />
250       <input type="hidden" name="modulename"  value="<?php p($form->modulename) ?>" />
251       <input type="hidden" name="instance"    value="<?php p($form->instance) ?>" />
252       <input type="hidden" name="mode"    value="<?php p($form->mode) ?>" />
253       <div align="center">
254           <input type="submit" value="<?php print_string("savechanges") ?>" />
255           <input type="submit" name="cancel" value="<?php print_string("cancel") ?>" />
256       </div>
257   </form>
258 <?php
259         } else {
260 ?>
261   <div align="center">
262       <input type="button" value="<?php print_string("continue") ?>" onclick="document.location='<?php echo $CFG->wwwroot ?>/course/view.php?id=<?php echo $course->id ?>';" />
263   </div>
264 <?php
265         }
266         print_simple_box_end();
267         print_footer($course);
268     } else {
269         error("This script was called incorrectly");
270     }
271 ?>