changed all the POST with option/required_param functions
[moodle.git] / mod / scorm / validate.php
CommitLineData
2a0407b7 1<?php // $Id$
2
7b873234 3 require_once("../../config.php");
4 require_once("lib.php");
2a0407b7 5
7b873234 6 $courseid = required_param('id', '', PARAM_INT); // Course Module ID, or
7 $reference = required_param('reference', '', PARAM_PATH); // Package path
8 $scormid = optional_param('instance', '', PARAM_INT); // scorm ID
1daed920 9
7b873234 10 require_login($course->id, false, $cm);
11
12if (confirm_sesskey() && !empty($courseid)) {
92a489eb 13 $launch = 0;
7b873234 14 $validation = new stdClass();
15 if (empty($reference)) {
16 $launch = -1;
17 $validation->result = "packagefile";
18 }
19 if (!empty($scormid)) {
20 //
21 // SCORM Update
22 //
9633a423 23 if (is_file($CFG->dataroot.'/'.$courseid.'/'.$reference)) {
24 $fp = fopen($CFG->dataroot.'/'.$courseid.'/'.$reference,"r");
25 $fstat = fstat($fp);
26 fclose($fp);
27 if ($scorm = get_record("scorm","id",$scormid)) {
28 $launch = $scorm->launch;
29 if ((($scorm->timemodified < $fstat["mtime"]) && ($scorm->reference == $reference)) || ($scorm->reference != $reference)) {
30 // This is a new package
31 $launch = 0;
32 } else {
33 // Old package already validated
34 $validation->result = 'found';
35 if (strpos($scorm->version,'AICC') !== false) {
36 $validation->pkgtype = 'AICC';
37 } else {
38 $validation->pkgtype = 'SCORM';
39 }
40 }
41 } else {
42 $validation->result = 'badinstance';
43 $launch = -1;
44 }
45 } else {
46 $validation->result = 'badreference';
47 $launch = -1;
5e5b6b7f 48 }
5e5b6b7f 49 }
f55a672e 50 //$launch = 0;
92a489eb 51 if ($launch == 0) {
9633a423 52 //
53 // Package must be validated
54 //
55
88f75516 56 // Create a temporary directory to unzip package and validate package
92a489eb 57 $tempdir = '';
58 $scormdir = '';
9633a423 59 if ($scormdir = make_upload_directory("$courseid/$CFG->moddata/scorm")) {
60 if ($tempdir = scorm_datadir($scormdir)) {
61 copy ("$CFG->dataroot/$courseid/$reference", $tempdir."/".basename($reference));
62 $ext = strtolower(substr(basename($reference),strrpos(basename($reference),'.')));
63 if (($ext == '.zip') || ($ext == '.pif')) {
64 unzip_file($tempdir."/".basename($reference), $tempdir, false);
65 unlink ($tempdir."/".basename($reference));
66 $validation = scorm_validate($tempdir);
67 } else {
68 $validation->result = "packagefile";
69 }
70 } else {
71 $validation->result = "packagedir";
72 }
5e5b6b7f 73 } else {
9633a423 74 $validation->result = "datadir";
5e5b6b7f 75 }
9633a423 76 if (($validation->result != "regular") && ($validation->result != "found")) {
77 $validation->result = get_string($validation->result,'scorm');
92a489eb 78 if (is_dir($tempdir)) {
79 // Delete files and temporary directory
80 scorm_delete_files($tempdir);
2a0407b7 81 }
2a0407b7 82 } else {
92a489eb 83 $datadir = substr($tempdir,strlen($scormdir));
2a0407b7 84 }
85 }
86 //
87 // Print validation result
88 //
9633a423 89 echo 'result=' . $validation->result . "\n";
88f75516 90 echo 'launch=' . $launch . "\n";
91 if (isset($validation->pkgtype)) {
9633a423 92 echo 'pkgtype=' . $validation->pkgtype . "\n";
88f75516 93 }
94 if (isset($datadir)) {
9633a423 95 echo 'datadir=' . $datadir . "\n";
2a0407b7 96 }
88f75516 97 if (isset($validation->errors[1])) {
9633a423 98 echo 'errorlogs='."\n";
99 foreach($validation->errors as $error) {
100 echo get_string($error->type,"scorm",$error->data) . "\n";
101 }
5e5b6b7f 102 }
1daed920 103} else {
9633a423 104 echo 'result=' . get_string('badrequest','scorm') . "\n";
1daed920 105}
2a0407b7 106?>