First step to SCORM2004, new communication subsystem
[moodle.git] / mod / scorm / validate.php
CommitLineData
2a0407b7 1<?php // $Id$
2
3 require_once("../../config.php");
4 require_once("lib.php");
5
6 require_login();
7
92a489eb 8
2a0407b7 9 $reference = clean_param($_GET["reference"], PARAM_PATH);
10 $courseid = $_GET["id"];
11 $datadir = '';
2a0407b7 12 if (isset($_GET["datadir"])) {
13 $datadir = $_GET["datadir"];
14 }
92a489eb 15
16 $scormid = 0;
17 $launch = 0;
2a0407b7 18 $result = '';
2a0407b7 19 $errorlogs = '';
92a489eb 20 if (isset($_GET["instance"])) {
21 $scormid = $_GET["instance"];
22 $launch = 1;
23 $fp = fopen($CFG->dataroot.'/'.$courseid.'/'.$reference,"r");
24 $fstat = fstat($fp);
25 fclose($fp);
26 if ($scorm = get_record("scorm","id",$scormid)) {
27 if ((($scorm->timemodified < $fstat["mtime"]) && ($scorm->reference == $reference)) || ($scorm->reference != $reference)) {
28 // This is a new package
29 $launch = 0;
30 } else {
31 // Old package already validated
32 $result = 'found';
33 }
34 }
35 }
36 if ($launch == 0) {
37 //
38 // Package must be validated
39 //
40
41 // Create a temporary directory to unzip package and validate imsmanifest
42 $tempdir = '';
43 $scormdir = '';
44 if ($scormdir = make_upload_directory("$courseid/$CFG->moddata/scorm")) {
45 if ($tempdir = scorm_datadir($scormdir, $datadir)) {
46 copy ("$CFG->dataroot/$courseid/$reference", $tempdir."/".basename($reference));
47 unzip_file($tempdir."/".basename($reference), $tempdir, false);
48 $result = scorm_validate($tempdir."/imsmanifest.xml");
49 } else {
50 $result = "packagedir";
51 }
52 } else {
53 $result = "datadir";
54 }
55 if (($result != "regular") && ($result != "found")) {
56 // Generate error log string
57 $result = get_string($result,'scorm');
58 if ($CFG->scorm_validate == 'domxml') {
59 foreach ($errors as $error) {
60 $errorlogs .= get_string($error->type,"scorm",$error->data) . ".\n";
61 }
62 }
63 if (is_dir($tempdir)) {
64 // Delete files and temporary directory
65 scorm_delete_files($tempdir);
66 } else {
67 // Delete package file
68 unlink ($tempdir."/".basename($reference));
2a0407b7 69 }
2a0407b7 70 } else {
92a489eb 71 $datadir = substr($tempdir,strlen($scormdir));
2a0407b7 72 }
73 }
74 //
75 // Print validation result
76 //
77 echo $result . "\n";
78 echo $launch . "\n";
2a0407b7 79 echo $datadir . "\n";
80 if ($errorlogs != '') {
81 echo $errorlogs;
82 }
83?>
84