public function getContentPackage() { // build the manifest $manifest = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?> <manifest xmlns="http://www.imsglobal.org/xsd/imscp_v1p1" xmlns:imsmd="' . NS_IMSMD . '" xmlns:imsqti="' . NS_IMSQTI . '" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.imsglobal.org/xsd/imscp_v1p1 imscp_v1p1.xsd http://www.imsglobal.org/xsd/imsmd_v1p2 imsmd_v1p2p4.xsd http://www.imsglobal.org/xsd/imsqti_v2p1 http://www.imsglobal.org/xsd/imsqti_v2p1.xsd" /> '); $manifest->addAttribute("identifier", $this->getMID()); // organizations element $manifest->addChild("organizations"); // resources element $rs = $manifest->addChild("resources"); $r = $rs->addChild("resource"); $r->addAttribute("identifier", $this->getQTIID()); $r->addAttribute("type", "imsqti_item_xmlv2p1"); $r->addAttribute("href", "{$this->getTitleFS()}.xml"); $md = $r->addChild("metadata"); // resource qti metadata $qmd = $md->addChild("qtiMetadata", null, NS_IMSQTI); $qmd->addChild("timeDependent", "false", NS_IMSQTI); foreach ($this->interactionTypes() as $it) { $qmd->addChild("interactionType", $it, NS_IMSQTI); } $qmd->addChild("feedbackType", is_null($this->data("feedback")) ? "none" : "nonadaptive", NS_IMSQTI); $qmd->addChild("solutionAvailable", "true", NS_IMSQTI); // resource LOM metadata $lom = $md->addChild("lom", null, NS_IMSMD); $g = $lom->addChild("general", null, NS_IMSMD); $g->addChild("title", null, NS_IMSMD)->addChild("langstring", $this->data("data"), NS_IMSMD); if (!is_null($this->data("description"))) { $g->addChild("description", null, NS_IMSMD)->addChild("langstring", $this->data("description"), NS_IMSMD); } foreach ($this->getKeywords() as $keyword) { $g->addChild("keyword", null, NS_IMSMD)->addChild("langstring", $keyword, NS_IMSMD); } // file element $r->addChild("file")->addAttribute("href", "{$this->getTitleFS()}.xml"); // make temporary zip archive $zip = new ZipArchive(); $filename = "/tmp/" . uniqid("zip"); if ($zip->open($filename, ZIPARCHIVE::CREATE) !== true) { servererror("couldn't make zip file"); } $zip->addFromString("imsmanifest.xml", simplexml_indented_string($manifest)); $zip->addFromString("{$this->getTitleFS()}.xml", $this->getQTIIndentedString()); $zip->close(); // slurp contents $zipcontents = file_get_contents($filename); // delete the temporary zip archive unlink($filename); // return the zip contents as a binary string return $zipcontents; }
public function postLogic() { // get login details if we don't already have them if (!$this->haveLogin()) { $this->postLogin(); return; } // clear errors $this->errors = array(); // check input if (!isset($_POST["collection"])) { $this->errors[] = "No collection specified"; $this->getLogic(); return; } // get content package $zipcontents = $this->ai->getContentPackage(); // build EP3 XML $ep3 = new SimpleXMLElement('<?xml version="1.0" encoding="utf-8"?> <eprints> <eprint xmlns="http://eprints.org/ep2/data/2.0"/> </eprints> '); $ep3->eprint->addChild("type", "share"); $ep3->eprint->addChild("metadata_visibility", "show"); $ep3->eprint->addChild("title", $this->ai->data("title")); $ep3->eprint->addChild("abstract", $this->ai->data("description")); if (strpos($_POST["collection"], "/sword-app/deposit/archive") !== false) { $ep3->eprint->addChild("visible", "world_public"); //for Edshare <2 $ep3->eprint->addChild("viewing_perms", "world_public"); //for Edshare 2 } $keywords = $this->ai->getKeywords(); if (!empty($keywords)) { $kw = $ep3->eprint->addChild("keywords"); foreach ($keywords as $keyword) { $kw->addChild("item", $keyword); } } $doc = $ep3->eprint->addChild("documents")->addChild("document"); $doc->addChild("format", "application/zip"); $doc->addChild("security", "public"); $doc->addChild("main", $this->ai->getTitleFS() . ".zip"); $file = $doc->addChild("files")->addChild("file"); $file->addChild("filename", $this->ai->getTitleFS() . ".zip"); $file->addChild("filesize", strlen($zipcontents)); $file->addChild("data", base64_encode($zipcontents))->addAttribute("encoding", "base64"); $curl = curl_init(); curl_setopt_array($curl, array(CURLOPT_URL => $_POST["collection"], CURLOPT_POST => true, CURLOPT_HEADER => true, CURLOPT_USERPWD => $_SESSION[SESSION_PREFIX . "diea_username"] . ":" . $_SESSION[SESSION_PREFIX . "diea_password"], CURLOPT_RETURNTRANSFER => true, CURLOPT_POSTFIELDS => simplexml_indented_string($ep3), CURLOPT_HTTPHEADER => array("Content-Type: application/xml", "X-Packaging: http://eprints.org/ep2/data/2.0", "Expect: "))); $response = curl_exec($curl); $responseinfo = curl_getinfo($curl); $code = $responseinfo["http_code"]; $headers = response_headers($response); $body = response_body($response); switch ($code) { case 401: unset($_SESSION[SESSION_PREFIX . "diea_username"], $_SESSION[SESSION_PREFIX . "diea_password"]); $this->errors[] = "There was an authorization problem" . (isset($headers["X-Error-Code"]) ? ": " . $headers["X-Error-Code"] : ""); $this->getLogic(); return; case 201: // parse XML response $xml = simplexml_load_string($body); $eprintid = (int) $xml->id; $treatment = null; foreach ($xml->children("http://purl.org/net/sword/") as $child) { if ($child->getName() == "treatment") { $treatment = (string) $child; break; } } // show "deposited" message and give link to the share $GLOBALS["title"] = "Item deposited in Edshare"; include "htmlheader.php"; ?> <h2>Item deposited in Edshare</h2> <?php if (!is_null($treatment)) { ?> <p>Edshare returned the following information:</p> <p><blockquote><?php echo htmlspecialchars($treatment); ?> </blockquote></p> <?php } ?> <?php if (strpos($_POST["collection"], "/sword-app/deposit/archive") === false) { ?> <p> The item is not yet live in the repository. As the owner you can still <a href="http://<?php echo DIEA_EDSHARE_HOST; ?> /cgi/users/home?screen=EPrint::Summary&eprintid=<?php echo $eprintid; ?> ">view it</a> or <a href="http://<?php echo DIEA_EDSHARE_HOST; ?> /cgi/users/home?screen=EPrint::EdShare::Edit&eprintid=<?php echo $eprintid; ?> ">edit it</a> (including setting it live) in Edshare. </p> <p> Once the item is live it'll be visible to the world at the following address. <br> <tt>http://<?php echo DIEA_EDSHARE_HOST; ?> /<?php echo $eprintid; ?> </tt> </p> <?php } else { ?> <p> The item is now live in Edshare and you and others can view it at the following address. <br> <tt><a href="http://<?php echo DIEA_EDSHARE_HOST; ?> /<?php echo $eprintid; ?> ">http://<?php echo DIEA_EDSHARE_HOST; ?> /<?php echo $eprintid; ?> </a></tt> </p> <?php } ?> <?php include "htmlfooter.php"; break; default: $this->errors[] = "Unexpected response: " . $responseinfo["http_code"] . ". Response headers follow:"; foreach ($headers as $k => $v) { $this->errors[] = "{$k}: {$v}"; } $this->getLogic(); return; } }
function deposititem() { $args = func_get_args(); // collect data switch (count($args)) { case 1: if (!$args[0] instanceof QTIAssessmentItem) { throw new Exception("with one argument, expected QTIAssessmentItem"); } $identifier = $args[0]->getQTIID(); $title = $args[0]->data("title"); $description = $args[0]->data("description"); $xml = $args[0]->getQTIIndentedString(); $keywords = $args[0]->getKeywords(); break; case 2: if ($args[0] instanceof SimpleXMLElement) { $sxml = $args[0]; $xml = simplexml_indented_string($args[0]); } else { if (is_string($args[0])) { $sxml = simplexml_load_string($args[0]); $xml = $args[0]; } else { throw new Exception("With two arguments expected SimpleXML element or XML string as first"); } } $identifier = (string) $sxml["identifier"]; $title = (string) $sxml["title"]; if (!is_array($args[1])) { throw new Exception("With two arguments expected metadata array as second"); } $description = isset($args[1]["description"]) ? $args[1]["description"] : ""; $keywords = isset($args[1]["keywords"]) ? $args[1]["keywords"] : array(); break; default: throw new Exception("expected one or two arguments"); } db()->exec("BEGIN TRANSACTION;"); // update or insert if (itemexists($identifier)) { // update item db()->exec("\n\t\t\tDELETE FROM keywords WHERE item='" . db()->escapeString($identifier) . "';\n\t\t\tUPDATE items SET\n\t\t\t\tmodified=" . time() . ",\n\t\t\t\ttitle='" . db()->escapeString($title) . "',\n\t\t\t\tdescription='" . db()->escapeString($description) . "',\n\t\t\t\txml='" . db()->escapeString($xml) . "'\n\t\t\tWHERE identifier='" . db()->escapeString($identifier) . "';\n\t\t"); // add a comment to the item to show it has been updated db()->exec("\n\t\t\tINSERT INTO comments VALUES (\n\t\t\t\t'" . db()->escapeString(username()) . "',\n\t\t\t\t'" . db()->escapeString($identifier) . "',\n\t\t\t\t'" . db()->escapeString("Automatic comment: this item has been updated") . "',\n\t\t\t\t" . time() . "\n\t\t\t);\n\t\t"); } else { // new item -- insert it db()->exec("\n\t\t\tINSERT INTO items VALUES (\n\t\t\t\t'" . db()->escapeString($identifier) . "',\n\t\t\t\t" . time() . ",\n\t\t\t\tNULL,\n\t\t\t\t'" . db()->escapeString(username()) . "',\n\t\t\t\t'" . db()->escapeString($title) . "',\n\t\t\t\t'" . db()->escapeString($description) . "',\n\t\t\t\t'" . db()->escapeString($xml) . "'\n\t\t\t);\n\t\t"); } // add keywords foreach ($keywords as $keyword) { db()->exec("\n\t\t\tINSERT INTO keywords VALUES (\n\t\t\t\t'" . db()->escapeString($identifier) . "',\n\t\t\t\t'" . db()->escapeString($keyword) . "'\n\t\t\t);\n\t\t"); } // commit changes db()->exec("COMMIT;"); }
<ul class="pagination centre"> <li><a href="<?php echo SITEROOT_WEB; ?> ?page=playItem&action=startover">Start over</a></li> </ul> <?php if ($response !== false) { ?> <h3>Score</h3> <div class="score"> <?php $score = "-"; if (isset($_POST["submit"])) { echo "<!-- Response and outcome variables XML:\n" . simplexml_indented_string($xml->vars) . "\n-->\n"; foreach ($xml->vars->OutcomeVars->param as $param) { if ((string) $param["identifier"] == "SCORE") { $score = (string) $param; break; } } } echo $score; ?> </div> <h3>About this item</h3> <ul id="aboutlist"> <li class="hidden">Identifier: <span id="qtiid"><?php echo htmlspecialchars($item["identifier"]);