New styles added
[moodle.git] / mod / scorm / details.php
CommitLineData
d1290cec 1<?php // $Id$
98ca59f6 2
3 require_once("../../config.php");
4 require_once("lib.php");
5
6 require_login();
7 if ($form = data_submitted($destination)) {
8
9 if (! $course = get_record("course", "id", $form->course)) {
10 error("This course doesn't exist");
11 }
12
13 require_login($course->id);
14
15 if (!isteacher($course->id)) {
16 error("You can't modify this course!");
17 }
18
19 $strediting = get_string("validateascorm", "scorm");
20 $strname = get_string("name");
21
f950af3c 22 print_header_simple("$strediting", "$strediting",
23 "$strediting");
98ca59f6 24
25 if (!$form->name or !$form->reference or !$form->summary) {
26 error(get_string("filloutallfields"), $_SERVER["HTTP_REFERER"]);
27 }
f950af3c 28
29 //
30 // Create a temporary directory to unzip package and validate imsmanifest
31 //
e23ef951 32
f950af3c 33 $coursedir = "$CFG->dataroot/$course->id";
a45de11f 34 $form->reference = clean_param($form->reference, PARAM_PATH);
35
f950af3c 36 if ($scormdir = make_upload_directory("$course->id/$CFG->moddata/scorm")) {
59c71f4b 37 if ($tempdir = scorm_datadir($scormdir, $form->datadir)) {
38 copy ("$coursedir/$form->reference", $tempdir."/".basename($form->reference));
1da35f29 39 unzip_file($tempdir."/".basename($form->reference), $tempdir, false);
59c71f4b 40 $result = scorm_validate($tempdir."/imsmanifest.xml");
41 } else {
42 $result = "packagedir";
43 }
f950af3c 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);
59c71f4b 59 } else {
60 //
f950af3c 61 // Delete package file
62 //
59c71f4b 63 unlink ($tempdir."/".basename($form->reference));
64 if ($form->mode == "update") {
f950af3c 65 $fp = fopen($coursedir."/".$form->reference,"r");
59c71f4b 66 $fstat = fstat($fp);
67 fclose($fp);
68 if (get_field("scorm","timemodified","id",$form->instance) < $fstat["mtime"]) {
69 $form->launch = 0;
f950af3c 70 }
f950af3c 71 }
59c71f4b 72 }
73 //
74 // Print validation result
75 //
f1c1d2f1 76 print_simple_box_start('center');
59c71f4b 77 echo "<table cellpadding=\"5\" align=\"center\">\n";
caf261b0 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";
59c71f4b 80 if ($errorlogs != '') {
81 $lines = round(count($errors)/4);
82 if ($lines < 5) {
83 $lines = 5;
84 }
caf261b0 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";
59c71f4b 86 }
87 if (($form->mode == "update") && ($form->launch == 0) && (get_records("scorm_sco_users","scormid",$form->instance))) {
caf261b0 88 echo " <tr><td align=\"center\" colspan=\"2\" nowrap=\"nowrap\"><b>".get_string("trackingloose","scorm")."</b></td></tr>\n";
59c71f4b 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 }
f950af3c 101 echo "<form name=\"theform\" method=\"post\" action=\"$form->destination\">\n";
102
103 //$form->popup = $CFG->scorm_popup;
104 $strnewwindow = get_string("newwindow", "scorm");
59c71f4b 105 $strnewwindowopen = get_string("newwindowopen", "scorm");
f950af3c 106 foreach ($SCORM_WINDOW_OPTIONS as $optionname) {
107 $stringname = "str$optionname";
108 $$stringname = get_string("new$optionname", "scorm");
109 $window->$optionname = "";
110 $jsoption[] = "\"$optionname\"";
59c71f4b 111 }
112 $alljsoptions = implode(",", $jsoption);
f950af3c 113
59c71f4b 114 if ($form->instance) { // Re-editing
f950af3c 115 if ($form->popup == "") {
59c71f4b 116 $newwindow = ""; // Disable the new window
117 foreach ($SCORM_WINDOW_OPTIONS as $optionname) {
118 $defaultvalue = "scorm_popup$optionname";
119 $window->$optionname = $CFG->$defaultvalue;
f950af3c 120 }
121 } else {
59c71f4b 122 $newwindow = "checked";
123 $rawoptions = explode(',', $form->popup);
124 foreach ($rawoptions as $rawoption) {
f950af3c 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 }
59c71f4b 135 }
f950af3c 136 }
59c71f4b 137 } else {
138 foreach ($SCORM_WINDOW_OPTIONS as $optionname) {
139 $defaultvalue = "scorm_popup$optionname";
140 $window->$optionname = $CFG->$defaultvalue;
f950af3c 141 }
142 $newwindow = $CFG->scorm_popup;
59c71f4b 143 }
98ca59f6 144?>
f950af3c 145 <table cellpadding="5" align="center">
59c71f4b 146 <tr valign="top">
caf261b0 147 <td align="right"><b><?php print_string("grademethod", "scorm") ?>:</b></td>
f950af3c 148 <td>
59c71f4b 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 ?>
f950af3c 157 </td>
59c71f4b 158 </tr>
159 <tr valign="top">
caf261b0 160 <td align="right"><b><?php print_string("maximumgrade") ?>:</b></td>
f950af3c 161 <td>
59c71f4b 162 <?php
163 for ($i=100; $i>=1; $i--) {
f950af3c 164 $grades[$i] = $i;
59c71f4b 165 }
1a12b1f1 166
59c71f4b 167 choose_from_menu($grades, "maxgrade", "$form->maxgrade", "");
168 helpbutton("maxgrade", get_string("maximumgrade"), "scorm");
169 ?>
f950af3c 170 </td>
59c71f4b 171 </tr>
172 <tr valign="top">
caf261b0 173 <td align="right"><b><?php print_string("autocontinue","scorm") ?>:</b></td>
59c71f4b 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">
d1290cec 184 <td align="right" nowrap="nowrap">
caf261b0 185 <b><?php p($strnewwindow) ?>:</b>
76d35423 186 </td>
187 <td>
839f2456 188 <script type="text/javascript">
76d35423 189 var subitems = [<?php echo $alljsoptions; ?>];
190
191 function autowindow() {
59c71f4b 192 if (document.theform.newwindow.checked) {
76d35423 193 document.theform.auto.disabled=true;
59c71f4b 194 } else {
76d35423 195 document.theform.auto.disabled=false;
59c71f4b 196 }
76d35423 197 }
b98eebbf 198
199 <?php
59c71f4b 200 if ($newwindow == "checked") {
b98eebbf 201 echo "document.theform.auto.disabled=true;\n";
59c71f4b 202 $newwindow = "checked='checked'";
203 }
b98eebbf 204 ?>
76d35423 205 </script>
d1290cec 206 <input name="setnewwindow" type="hidden" value="1" />
59c71f4b 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>
76d35423 210 <?php
59c71f4b 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";
76d35423 222 }
b98eebbf 223 ?>
76d35423 224
d1290cec 225 <input name="hwidth" type="hidden" value="0" />
caf261b0 226 <input name="width" type="text" size="4" value="<?php p($window->width) ?>" alt="width" /> <?php p($strwidth) ?><br />
d1290cec 227 <input name="hheight" type="hidden" value="0" />
caf261b0 228 <input name="height" type="text" size="4" value="<?php p($window->height) ?>" alt="height" /> <?php p($strheight) ?><br />
59c71f4b 229 <?php
76d35423 230 if (!$newwindow) {
caf261b0 231 echo "<script type=\"text/javascript\">\n<!--\n";
b98eebbf 232 echo "\tlockoptions('theform','newwindow', subitems);";
233 echo "\n-->\n</script>";
76d35423 234 }
235 ?>
59c71f4b 236 </li></ul>
76d35423 237 </td>
59c71f4b 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) ?>" />
18d20603 246 <input type="hidden" name="sesskey" value="<?php p($form->sesskey) ?>" />
59c71f4b 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>
478ef449 258<?php
f950af3c 259 } else {
98ca59f6 260?>
59c71f4b 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>
478ef449 264<?php
59c71f4b 265 }
266 print_simple_box_end();
98ca59f6 267 print_footer($course);
268 } else {
59c71f4b 269 error("This script was called incorrectly");
98ca59f6 270 }
271?>