------------------------------------------------------------------------------*/ $errors = array(); $warnings = array(); $messages = array(); if (isset($_POST["uploaditem"])) { $output = handleupload($errors, $warnings, $messages); if ($output !== false) { list($xml, $metadata) = $output; if (validateQTI($xml, $errors, $warnings, $messages)) { $xml = simplexml_load_string($xml); // get data from QTI $identifier = (string) $xml["identifier"]; $title = (string) $xml["title"]; // see if an item with this identifier already exists in the // database $exists = itemexists($identifier); if ($exists && itemowner($identifier) != username()) { $errors[] = "The item you are trying to upload was already uploaded by a different user. You should clone it so it gets a new identifier and then try again."; } else { deposititem($xml, $metadata); if (!authoredineqiat($xml)) { $warnings[] = "This item was not authored in Eqiat. The item will still be playable but Eqiat may not be able to import it for editing."; } // collect any warnings and messages $thingstosay = array(); if (!empty($warnings)) { $thingstosay[] = "warnings"; } if (!empty($messages)) { $thingstosay[] = "messages"; }
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;"); }
(c) 2010 JISC-funded EASiHE project, University of Southampton Licensed under the Creative Commons 'Attribution non-commercial share alike' licence -- see the LICENCE file for more details ------------------------------------------------------------------------------*/ requirelogin(); if (!isset($_REQUEST["qtiid"])) { redirect("eqiat/"); } $ai = QTIAssessmentItem::fromQTIID($_REQUEST["qtiid"]); if (!$ai) { badrequest("No QTI found in session data for specified QTI ID"); } if (!$ai->getQTI() || count($ai->getErrors())) { badrequest("Specified QTI item is unfinished or has errors"); } if (($exists = itemexists($ai->getQTIID())) && itemowner($ai->getQTIID()) != username()) { badrequest("The item you are trying to deposit was already uploaded by a different user. You should clone it so it gets a new identifier and then try again."); } deposititem($ai); // remove from session memory to remove from Eqiat view $ai->sessionRemove(); $title = "Item " . ($exists ? "updated" : "deposited"); include "htmlheader.php"; ?> <h2><?php echo htmlspecialchars($title); ?> </h2> <p>The item "<?php echo htmlspecialchars($ai->data("title")); ?>