delete_directory($dir.$file.'/'); } } else { @unlink($dir.$file); } } } closedir($handle); @rmdir($dir); } } function import($file) { $tmp_file = $file['tmp_name']; $this->dir = $tmp_file."_unzipped/"; if (is_uploaded_file($tmp_file)) { $zip = new ZipArchive; $res = $zip->open($tmp_file); if ($res === TRUE) { $zip->extractTo($this->dir); $zip->close(); $result = $this->readZipContents(); return $result; } } return false; } function readZipContents() { if ($handle = opendir($this->dir)) { $this->setManifestFile(); if ($this->manifest_dom) { $result = $this->readManifestFile(); } /*while (false !== ($f = readdir($handle))) { if (!substr_compare($f, ".xml", -4, 4)) { $fc = file_get_contents($this->dir."/".$f); if (!empty($fc)) { $obj_id = $this->readItemXML($fc); if (!$obj_id) { $success = false; } } } }*/ //closedir($handle); if (is_dir($this->dir)) { $this->delete_directory($this->dir); } return $result; } return false; } function setManifestFile() { if ($handle = opendir($this->dir)) { while (false !== ($f = readdir($handle))) { if (!substr_compare($f, ".xml", -4, 4)) { $fc = file_get_contents($this->dir."/".$f); if (!empty($fc)) { $manifest = $this->isManifestFile($fc); if ($manifest) { $this->manifest_dom = $manifest; break; } } } } closedir($handle); } } function isManifestFile($xml) { global $TeKe; $dom = new DOMDocument(); $dom->loadXML($xml); $dom->preserveWhiteSpace = false; $dom->normalizeDocument(); $manifest = $dom->getElementsByTagName("manifest"); if ($manifest->length != 0) { return $dom; } return false; } function readManifestFile() { $success = true; $dom = $this->manifest_dom; $resources = $dom->getElementsByTagName("resource"); for ($i=0; $i<$resources->length; $i++) { $resource = $resources->item($i); $item_href = $resource->getAttribute("href"); $fc = file_get_contents($this->dir."/".$item_href); if (!empty($fc)) { $obj_id = $this->readItemXML($resource, $fc); if (!$obj_id) { $success = false; } } } return $success; } function readItemXML($resource, $xml) { global $TeKe; $dom = new DOMDocument(); $dom->loadXML($xml); $dom->preserveWhiteSpace = false; $dom->normalizeDocument(); $assessmentItem = $dom->getElementsByTagName("assessmentItem"); //var_dump($assessmentItem->length); if ($assessmentItem->length != 0) { $choiceInteraction = $assessmentItem->item(0)->getElementsByTagName("choiceInteraction"); if ($choiceInteraction->length != 0) { return $this->importChoiceInteraction($resource, $dom); } } return true; } function importChoiceInteraction($resource, $dom) { global $TeKe; $responseDeclaration = $dom->getElementsByTagName("responseDeclaration"); $cardinality = $responseDeclaration->item(0)->getAttribute("cardinality"); if ($cardinality == "single") { $obj = $TeKe->plugin->loadType("multipleChoice"); $obj_id = $obj->buildFromXML($resource, $dom); return $obj_id; } else if ($cardinality == "multiple") { $obj = $TeKe->plugin->loadType("multipleResponse"); $obj_id = $obj->buildFromXML($resource, $dom); return $obj_id; } return false; } } ?>