public function postLogic() { $ai = QTIAssessmentItem::fromQTIID($_REQUEST["qtiid"]); // clone the item $ai = clone $ai; // update the modified time and set new identifiers $ai->setQTIID(null); $ai->setMID(); $ai->sessionStore(); // take the user to the main menu with the cloned item highlighted redirect(SITEROOT_WEB . "#item_" . $ai->getQTIID()); }
public function get_RCode() { $code = ""; $next = $this->get_next_TestSection(); $next_counter = $next != null ? $next->counter : 0; $end_of_loop = $this->is_end_of_loop(); $loop = null; $loop_vals = null; if ($end_of_loop) { $loop = $this->get_section_loop(); $loop_vals = $loop->get_values(); $next_counter = $loop->counter; } $vals = $this->get_values(); switch ($this->TestSectionType_id) { case DS_TestSectionType::START: $test = Test::from_mysql_id($this->Test_id); if ($test == null) { return sprintf("stop('Invalid test id: %s in section #%s')", $this->Test_id, $this->counter); } $code = sprintf("\n print('Starting test with id: %s')\n CONCERTO_TEST_ID <<- %s\n return(%d)\n ", $this->Test_id, $this->Test_id, $next_counter); break; case DS_TestSectionType::END: $code = sprintf("\n update.session.status(%d) \n update.session.counter(%d)\n return(%d)\n ", TestSession::TEST_SESSION_STATUS_COMPLETED, $next_counter, $next_counter); break; case DS_TestSectionType::CUSTOM: $cs = CustomSection::from_mysql_id($vals[0]); if ($cs == null) { return sprintf("stop('Invalid custom section #%s')", $this->counter); } $parameters = $cs->get_parameter_CustomSectionVariables(); $returns = $cs->get_return_CustomSectionVariables(); $code = ""; foreach ($parameters as $param) { $val = $param->name; for ($j = 0; $j < $vals[1] * 2; $j = $j + 2) { if ($vals[3 + $j] == $param->name && isset($vals[3 + $j + 1]) && $vals[3 + $j + 1] != "") { $val = $vals[3 + $j + 1]; break; } } $code .= sprintf("\n %s <- %s\n ", $param->name, $val); } $code .= $cs->code; foreach ($returns as $ret) { $val = $ret->name; for ($j = 0; $j < $vals[2] * 2; $j = $j + 2) { if ($vals[3 + $vals[1] * 2 + $j] == $ret->name && isset($vals[3 + $vals[1] * 2 + $j]) && $vals[3 + $vals[1] * 2 + $j] != "") { $val = $vals[3 + $vals[1] * 2 + $j + 1]; break; } } $code .= sprintf("\n %s <<- %s\n ", $val, $ret->name); } $code .= sprintf("\n return(%d)\n ", $this->end == 0 ? $next_counter : -2); break; case DS_TestSectionType::R_CODE: $code = sprintf("\n %s\n return(%d)\n ", $vals[0], $this->end == 0 ? $next_counter : -2); break; case DS_TestSectionType::LOWER_LEVEL_R_CODE: $code = sprintf("\n %s\n ", $vals[0]); break; case DS_TestSectionType::QTI_INITIALIZATION: $ai = QTIAssessmentItem::from_mysql_id($vals[0]); if ($ai == null) { return sprintf("stop('Invalid QTI assessment item id: %s in section #%s')", $vals[0], $this->counter); } $map = QTIAssessmentItem::get_mapped_variables($this->id); $result = $ai->validate($map, null, $this->id); if (json_decode($result)->result != 0) { return sprintf("stop('Validation failed on QTI assessment item id: %s in section #%s')", $vals[0], $this->counter); } $qtir = $ai->get_QTI_ini_R_code($map, $this->id); $code = sprintf("\n %s\n return(%d)\n ", $qtir, $this->end == 0 ? $next_counter : -2); break; case DS_TestSectionType::QTI_RESPONSE_PROCESSING: $ts = TestSection::from_property(array("counter" => $vals[0], "Test_id" => $this->Test_id), false); if ($ts == null) { return sprintf("stop('Invalid test section id: %s in section #%s')", $vals[0], $this->counter); } $tsvals = $ts->get_values(); $ai = QTIAssessmentItem::from_mysql_id($tsvals[0]); if ($ai == null) { return sprintf("stop('Invalid QTI assessment item id: %s in section #%s')", $tsvals[0], $this->counter); } $map = QTIAssessmentItem::get_mapped_variables($ts->id); $result = $ai->validate($map, null, $ts->id); if (json_decode($result)->result != 0) { return sprintf("stop('Validation failed on QTI assessment item id: %s in section #%s')", $tsvals[0], $this->counter); } $qtir = $ai->get_response_processing_R_code(); $code = sprintf("\n %s\n return(%d)\n ", $qtir, $this->end == 0 ? $next_counter : -2); break; case DS_TestSectionType::LOAD_HTML_TEMPLATE: $template_id = $vals[0]; $template = Template::from_mysql_id($template_id); if ($template == null) { return sprintf("stop('Invalid template id: %s in section #%s')", $template_id, $this->counter); } $code = sprintf("\n update.session.template_id(%d)\n if(!exists('TIME_LIMIT')) TIME_LIMIT <<- 0\n update.session.time_limit(TIME_LIMIT)\n update.session.status(%d)\n update.session.counter(%d)\n update.session.template_testsection_id(%d)\n update.session.HTML(%d,%d,%d)\n update.session.effects('%s','%s','%s','%s')\n return(%d)\n ", $template_id, TestSession::TEST_SESSION_STATUS_TEMPLATE, $next_counter, $this->id, $this->Test_id, $this->id, $template_id, addcslashes($template->effect_show, "'"), addcslashes($template->effect_hide, "'"), addcslashes($template->effect_show_options, "'"), addcslashes($template->effect_hide_options, "'"), $this->end == 0 ? -1 : -2); break; case DS_TestSectionType::GO_TO: $code = ""; foreach ($this->get_parent_loops_counters() as $loop) { $target = TestSection::from_property(array("Test_id" => $this->Test_id, "counter" => $vals[0]), false); if ($target != null) { $target_loops = $target->get_parent_loops_counters(); if (!in_array($loop, $target_loops)) { $code .= sprintf("\n %s <<- FALSE\n ", TestSection::build_for_initialization_variable($this->Test_id, $loop)); } } } $code .= sprintf("\n return(%d)\n ", $vals[0] == 0 ? $next_counter : $vals[0]); break; case DS_TestSectionType::IF_STATEMENT: $contents = TestSection::from_property(array("Test_id" => $this->Test_id, "parent_counter" => $this->counter)); $is_empty = count($contents) == 0; $code = ""; $next_not_child = $this->get_next_not_child_TestSection(); $next_not_child_counter = $next_not_child->counter; if ($end_of_loop) { $next_not_child_counter = $next_counter; } else { $is_end_of_loop = $this->is_end_of_loop(false); if ($is_end_of_loop) { $parent_loop = $this->get_section_loop(); if ($parent_loop != null) { $next_not_child_counter = $parent_loop->counter; } } } if ($is_empty) { $code .= sprintf("\n return(%d)\n ", $next_not_child_counter); break; } $additional_conds = ""; $i = 3; while (isset($vals[$i])) { $additional_conds .= sprintf("%s %s %s %s", $vals[$i], $vals[$i + 1], $vals[$i + 2], $vals[$i + 3]); $i += 4; } $code .= sprintf("\n if(%s %s %s %s) {\n return(%d)\n }\n else {\n return(%d)\n }\n ", $vals[0], $vals[1], $vals[2], $additional_conds, $next->counter, $next_not_child_counter); break; case DS_TestSectionType::TEST: $test = Test::from_mysql_id($vals[0]); if ($test == null) { return sprintf("stop('Invalid test id: %s in section #%s')", $vals[0], $this->counter); } else { $code = sprintf("\n CONCERTO_TEST_ID <<- %s\n ", $test->id); $parameters = $test->get_parameter_TestVariables(); $params_code = ""; $returns = $test->get_return_TestVariables(); $returns_code = ""; foreach ($parameters as $param) { $val = $param->name; for ($j = 0; $j < $vals[1] * 2; $j = $j + 2) { if ($vals[3 + $j] == $param->name && isset($vals[3 + $j + 1]) && $vals[3 + $j + 1] != "") { $val = $vals[3 + $j + 1]; break; } } $params_code .= sprintf("\n %s <- %s\n ", $param->name, $val); } foreach ($returns as $ret) { $val = $ret->name; for ($j = 0; $j < $vals[2] * 2; $j = $j + 2) { if ($vals[3 + $vals[1] * 2 + $j] == $ret->name && isset($vals[3 + $vals[1] * 2 + $j]) && $vals[3 + $vals[1] * 2 + $j] != "") { $val = $vals[3 + $vals[1] * 2 + $j + 1]; break; } } $returns_code .= sprintf("\n %s <<- %s\n ", $val, $ret->name); } $code .= sprintf("\n %s\n ", $params_code); $sections = TestSection::from_property(array("Test_id" => $test->id)); foreach ($sections as $section) { if ($section->TestSectionType_id != DS_TestSectionType::END) { $code .= $section->get_RFunction(); } else { $end_code = sprintf("\n CONCERTO_TEST_ID <<- %s\n %s\n return(%d)\n ", $this->Test_id, $returns_code, $next_counter); $code .= sprintf("\n %s <<- function(){\n print('Start of section with index: %s')\n %s\n }\n ", 'CONCERTO_Test' . $vals[0] . 'Section2', 2, $end_code); } } $code .= "\n return(1)\n "; } break; case DS_TestSectionType::LOOP: $contents = TestSection::from_property(array("Test_id" => $this->Test_id, "parent_counter" => $this->counter)); $is_empty = count($contents) == 0; $next_not_child = $this->get_next_not_child_TestSection(); $next_not_child_counter = $next_not_child->counter; if ($end_of_loop) { $next_not_child_counter = $next_counter; } else { $is_end_of_loop = $this->is_end_of_loop(false); if ($is_end_of_loop) { $parent_loop = $this->get_section_loop(); if ($parent_loop != null) { $next_not_child_counter = $parent_loop->counter; } } } $code = ""; if ($is_empty) { $code .= sprintf("\n return(%d)\n ", $next_not_child_counter); break; } if ($vals[0] == 1) { $code = sprintf("\n if(%s %s %s) {\n return(%d)\n }\n else {\n return(%d)\n }\n ", $vals[1], $vals[2], $vals[3], $next->counter, $next_not_child_counter); } else { $code = sprintf("\n if(exists('%s') && %s) {\n %s <<- %s + as.numeric(%s)\n }\n else {\n %s <<- TRUE\n %s <<- as.numeric(%s)\n }\n if(%s %s %s) {\n return(%d)\n }\n else {\n %s <<- FALSE\n return(%d)\n }\n ", $this->get_for_initialization_variable(), $this->get_for_initialization_variable(), $vals[1], $vals[1], $vals[5], $this->get_for_initialization_variable(), $vals[1], $vals[4], $vals[1], $vals[2], $vals[3], $next->counter, $this->get_for_initialization_variable(), $next_not_child_counter); } break; case DS_TestSectionType::FOR_LOOP: $contents = TestSection::from_property(array("Test_id" => $this->Test_id, "parent_counter" => $this->counter)); $is_empty = count($contents) == 0; $next_not_child = $this->get_next_not_child_TestSection(); $next_not_child_counter = $next_not_child->counter; if ($end_of_loop) { $next_not_child_counter = $next_counter; } else { $is_end_of_loop = $this->is_end_of_loop(false); if ($is_end_of_loop) { $parent_loop = $this->get_section_loop(); if ($parent_loop != null) { $next_not_child_counter = $parent_loop->counter; } } } $code = ""; if ($is_empty) { $code .= sprintf("\n return(%d)\n ", $next_not_child_counter); break; } $code = sprintf("\n if(exists('%s') && %s) {\n %s <<- %s + 1\n }\n else {\n %s <<- TRUE\n %s <<- 1\n }\n\n CONCERTO_TEMP_FOR_INDEX <- 1\n \n for(CONCERTO_TEMP_FOR_VALUE in %s){\n if(CONCERTO_TEMP_FOR_INDEX==%s){\n %s <<- CONCERTO_TEMP_FOR_VALUE\n return(%d)\n break\n }\n CONCERTO_TEMP_FOR_INDEX <- CONCERTO_TEMP_FOR_INDEX+1\n }\n \n %s <<- FALSE\n return(%d)\n ", $this->get_for_initialization_variable(), $this->get_for_initialization_variable(), $this->get_for_index_variable(), $this->get_for_index_variable(), $this->get_for_initialization_variable(), $this->get_for_index_variable(), $vals[1], $this->get_for_index_variable(), $vals[0], $next->counter, $this->get_for_initialization_variable(), $next_not_child_counter); break; case DS_TestSectionType::WHILE_LOOP: $contents = TestSection::from_property(array("Test_id" => $this->Test_id, "parent_counter" => $this->counter)); $is_empty = count($contents) == 0; $next_not_child = $this->get_next_not_child_TestSection(); $next_not_child_counter = $next_not_child->counter; if ($end_of_loop) { $next_not_child_counter = $next_counter; } else { $is_end_of_loop = $this->is_end_of_loop(false); if ($is_end_of_loop) { $parent_loop = $this->get_section_loop(); if ($parent_loop != null) { $next_not_child_counter = $parent_loop->counter; } } } $code = ""; if ($is_empty) { $code .= sprintf("\n return(%d)\n ", $next_not_child_counter); break; } $additional_conds = ""; $i = 3; while (isset($vals[$i])) { $additional_conds .= sprintf("%s %s %s %s", $vals[$i], $vals[$i + 1], $vals[$i + 2], $vals[$i + 3]); $i += 4; } $code = sprintf("\n if(%s %s %s %s) {\n return(%d)\n }\n else {\n return(%d)\n }\n ", $vals[0], $vals[1], $vals[2], $additional_conds, $next->counter, $next_not_child_counter); break; case DS_TestSectionType::TABLE_MOD: $type = $vals[0]; $set_count = $vals[2]; $where_count = $vals[1]; $table = Table::from_mysql_id($vals[3]); if ($table == null) { return sprintf("stop('Invalid table id: %s in section #%s')", $vals[3], $this->counter); } $set = ""; for ($i = 0; $i < $vals[2]; $i++) { $column = TableColumn::from_property(array("Table_id" => $vals[3], "index" => $vals[4 + $i * 2]), false); if ($column == null) { return sprintf("stop('Invalid table column index: %s of table id: %s in section #%s')", $vals[4 + $i * 2], $vals[3], $this->counter); } if ($i > 0) { $set .= ","; } $set .= sprintf("`%s`='\",dbEscapeStrings(CONCERTO_DB_CONNECTION,toString(%s)),\"'", $column->name, $vals[4 + $i * 2 + 1]); } $where = ""; for ($i = 0; $i < $vals[1]; $i++) { $j = 4 + $vals[2] * 2 + $i * 4; $column = TableColumn::from_property(array("Table_id" => $vals[3], "index" => $vals[$j + 1]), false); if ($column == null) { return sprintf("stop('Invalid table column index: %s of table id: %s in section #%s')", $vals[$j + 1], $vals[3], $this->counter); } if ($i > 0) { $where .= sprintf("%s", $vals[$j]); } $where .= sprintf("`%s` %s '\",dbEscapeStrings(CONCERTO_DB_CONNECTION,toString(%s)),\"'", $column->name, $vals[$j + 2], $vals[$j + 3]); } $sql = ""; if ($type == 0) { $sql .= sprintf("INSERT INTO `%s` SET %s", $table->get_table_name(), $set); } if ($type == 1) { $sql .= sprintf("UPDATE `%s` SET %s WHERE %s", $table->get_table_name(), $set, $where); } if ($type == 2) { $sql .= sprintf("DELETE FROM `%s` WHERE %s", $table->get_table_name(), $where); } $code = sprintf(' CONCERTO_SQL <- paste("%s",sep="") CONCERTO_SQL_RESULT <- dbSendQuery(CONCERTO_DB_CONNECTION,CONCERTO_SQL) return(%d) ', $sql, $this->end == 0 ? $next_counter : -2); break; case DS_TestSectionType::SET_VARIABLE: $type = $vals[2]; $columns_count = $vals[0]; $conds_count = $vals[1]; if ($type == 0) { $table = Table::from_mysql_id($vals[5]); if ($table == null) { return sprintf("stop('Invalid table id: %s in section #%s')", $vals[5], $this->counter); } $column = TableColumn::from_property(array("Table_id" => $table->id, "index" => $vals[6]), false); if ($column == null) { return sprintf("stop('Invalid table column index: %s of table id: %s in section #%s')", $vals[6], $table->id, $this->counter); } $sql = sprintf("SELECT `%s`", $column->name); for ($i = 1; $i <= $columns_count; $i++) { $column = TableColumn::from_property(array("Table_id" => $table->id, "index" => $vals[6 + $i]), false); if ($column == null) { return sprintf("stop('Invalid table column index: %s of table id: %s in section #%s')", $vals[6 + $i], $table->id, $this->counter); } $sql .= sprintf(",`%s`", $column->name); } $sql .= sprintf(" FROM `%s` ", $table->get_table_name()); if ($conds_count > 0) { $sql .= sprintf("WHERE "); $j = 7 + $columns_count; for ($i = 1; $i <= $conds_count; $i++) { if ($i > 1) { $link = $vals[$j]; $j++; } else { $j++; } $cond_col = TableColumn::from_property(array("Table_id" => $table->id, "index" => $vals[$j]), false); if ($cond_col == null) { return sprintf("stop('Invalid table column index: %s of table id: %s in section #%s')", $vals[$j], $table->id, $this->counter); } $j++; $operator = $vals[$j]; $j++; $exp = $vals[$j]; $j++; if ($i > 1) { $sql .= sprintf("%s `%s` %s '\",dbEscapeStrings(CONCERTO_DB_CONNECTION,toString(%s)),\"' ", $link, $cond_col->name, $operator, $exp); } else { $sql .= sprintf("`%s` %s '\",dbEscapeStrings(CONCERTO_DB_CONNECTION,toString(%s)),\"' ", $cond_col->name, $operator, $exp); } } } $code = sprintf(' CONCERTO_SQL <- paste("%s",sep="") CONCERTO_SQL_RESULT <- dbSendQuery(CONCERTO_DB_CONNECTION,CONCERTO_SQL) %s <<- fetch(CONCERTO_SQL_RESULT,n=-1) return(%d) ', $sql, $vals[4], $this->end == 0 ? $next_counter : -2); break; } if ($type == 1) { $code = sprintf(' %s <<- { %s } return(%d) ', $vals[4], $vals[3], $this->end == 0 ? $next_counter : -2); break; } } return TestSection::replace_invalid_code($code); }
public static function compare_by_modification_date(QTIAssessmentItem $a, QTIAssessmentItem $b) { return $a->getModified() - $b->getModified(); }
public function available(QTIAssessmentItem $ai) { return $ai->itemOK(); }
public function available(QTIAssessmentItem $ai) { return DIEA_AVAILABLE && $ai->itemOK(); }
<?php /* Concerto Platform - Online Adaptive Testing Platform Copyright (C) 2011-2013, The Psychometrics Centre, Cambridge University This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License, and not any of the later versions. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ if (!isset($ini)) { require_once '../../Ini.php'; $ini = new Ini(); } $logged_user = User::get_logged_user(); if ($logged_user == null) { echo json_encode(array("result" => -1)); exit; } $qti = new QTIAssessmentItem(); echo $qti->validate(null, $_POST['xml']);
public function beforeLogic() { $this->ai = QTIAssessmentItem::fromQTIID($_REQUEST["qtiid"]); $this->aititle = $this->ai->data("title"); }
, <?php echo $_POST['counter']; ?> , Test.getSectionValues(Test.sectionDivToObject($('#divSection_<?php echo $_POST['counter']; ?> '))))"> <option value="0"><<?php echo Language::string(73); ?> ></option> <?php $sql = $logged_user->mysql_list_rights_filter("QTIAssessmentItem", "`name` ASC"); $z = mysql_query($sql); while ($r = mysql_fetch_array($z)) { $t = QTIAssessmentItem::from_mysql_id($r[0]); ?> <option value="<?php echo $t->id; ?> " <?php echo $vals[0] == $t->id ? "selected" : ""; ?> ><?php echo $t->name; ?> ( <?php echo $t->get_system_data(); ?> )</option> <?php
<?php /* * Question Bank */ /*------------------------------------------------------------------------------ (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
<?php /* * Eqiat * Easy QTI Item Authoring Tool */ /*------------------------------------------------------------------------------ (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 ------------------------------------------------------------------------------*/ // get sorted array of items // those which have titles in alphabetical order // then others in identifier order $items = array(); foreach (QTIAssessmentItem::allItems() as $id => $item) { $items[] = $item; } usort($items, array("QTIAssessmentItem", "compare_by_modification_date")); $items = array_reverse($items); ob_start(); ?> $(document).ready(function() { if (window.location.hash.substr(0, 6) == "#item_") $(window.location.hash).addClass("highlight"); }); <?php $GLOBALS["headerjs"] = ob_get_clean() . item_action_js(); include "htmlheader.php"; ?>
public function available(QTIAssessmentItem $ai) { return $ai->getQTI() && !count($ai->getErrors()); }
function compare_item_alpha(QTIAssessmentItem $a, QTIAssessmentItem $b) { return strcasecmp($a->itemTypePrint(), $b->itemTypePrint()); }
public function beforeLogic() { $this->ai = QTIAssessmentItem::fromQTIID($_REQUEST["qtiid"]); }
public function import_XML($xml, $compare = null) { $this->Sharing_id = 1; $xpath = new DOMXPath($xml); $elements = $xpath->query("/export"); foreach ($elements as $element) { if (Ini::$version != $element->getAttribute("version")) { return -5; } } if ($compare == null) { $compare = array("Template" => array(), "Table" => array(), "CustomSection" => array(), "Test" => array(), "QTIAssessmentItem" => array()); } //link templates $logged_user = User::get_logged_user(); $elements = $xpath->query("/export/Template"); foreach ($elements as $element) { $id = $element->getAttribute("id"); $hash = $element->getAttribute("xml_hash"); $compare["Template"][$id] = Template::find_xml_hash($hash); if ($compare["Template"][$id] == 0) { $obj = new Template(); $obj->Owner_id = $logged_user->id; $lid = $obj->import_XML(Template::convert_to_XML_document($element)); $compare["Template"][$id] = $lid; } } //link QTI assessment items $logged_user = User::get_logged_user(); $elements = $xpath->query("/export/QTIAssessmentItem"); foreach ($elements as $element) { $id = $element->getAttribute("id"); $hash = $element->getAttribute("xml_hash"); $compare["QTIAssessmentItem"][$id] = QTIAssessmentItem::find_xml_hash($hash); if ($compare["QTIAssessmentItem"][$id] == 0) { $obj = new QTIAssessmentItem(); $obj->Owner_id = $logged_user->id; $lid = $obj->import_XML(QTIAssessmentItem::convert_to_XML_document($element)); $compare["QTIAssessmentItem"][$id] = $lid; } } //link tables $elements = $xpath->query("/export/Table"); foreach ($elements as $element) { $id = $element->getAttribute("id"); $hash = $element->getAttribute("xml_hash"); $compare["Table"][$id] = Table::find_xml_hash($hash); if ($compare["Table"][$id] == 0) { $obj = new Table(); $obj->Owner_id = $logged_user->id; $lid = $obj->import_XML(Table::convert_to_XML_document($element)); $compare["Table"][$id] = $lid; } } //link custom sections $elements = $xpath->query("/export/CustomSection"); foreach ($elements as $element) { $id = $element->getAttribute("id"); $hash = $element->getAttribute("xml_hash"); $compare["CustomSection"][$id] = CustomSection::find_xml_hash($hash); if ($compare["CustomSection"][$id] == 0) { $obj = new CustomSection(); $obj->Owner_id = $logged_user->id; $lid = $obj->import_XML(CustomSection::convert_to_XML_document($element)); $compare["CustomSection"][$id] = $lid; } } //link tests $elements = $xpath->query("/export/Test"); for ($i = 0; $i < $elements->length - 1; $i++) { $element = $elements->item($i); $id = $element->getAttribute("id"); $hash = $element->getAttribute("xml_hash"); if (!isset($compare["Test"][$id])) { $compare["Test"][$id] = 0; } if ($compare["Test"][$id] == 0) { $obj = new Test(); $obj->Owner_id = $logged_user->id; $lid = $obj->import_XML(CustomSection::convert_to_XML_document($element), $compare); $compare["Test"][$id] = $lid; } } $elements = $xpath->query("/export/Test"); $element = $elements->item($elements->length - 1); $this->xml_hash = $element->getAttribute("xml_hash"); $element_id = $element->getAttribute("id"); if (isset($compare["Test"][$element_id]) && $compare["Test"][$element_id] != 0) { return $compare["Test"][$element_id]; } $children = $element->childNodes; foreach ($children as $child) { switch ($child->nodeName) { case "name": $this->name = $child->nodeValue; break; case "description": $this->description = $child->nodeValue; break; case "open": $this->open = $child->nodeValue; break; case "loader_Template_id": $this->loader_Template_id = $child->nodeValue == 0 ? 0 : $compare["Template"][$child->nodeValue]; break; } } $this->id = $this->mysql_save(); $post = array(); $post["sections"] = array(); $elements = $xpath->query("/export/Test[@id='" . $element_id . "']/TestSections/TestSection"); foreach ($elements as $element) { $test_section = array(); $test_section["value"] = array(); $children = $element->childNodes; foreach ($children as $child) { switch ($child->nodeName) { case "end": $test_section["end"] = $child->nodeValue; break; case "counter": $test_section["counter"] = $child->nodeValue; break; case "TestSectionType_id": $test_section["type"] = $child->nodeValue; break; case "parent_counter": $test_section["parent"] = $child->nodeValue; break; case "TestSectionValues": $ts_child_list = $child->childNodes; foreach ($ts_child_list as $ts_child) { $index = -1; $value = ""; $tsv_vars = $ts_child->childNodes; foreach ($tsv_vars as $tsv_child) { switch ($tsv_child->nodeName) { case "index": $index = $tsv_child->nodeValue; break; case "value": $value = $tsv_child->nodeValue; break; } } if ($index != -1) { $test_section["value"]["v" . $index] = $value; } } break; } } switch ($test_section["type"]) { case 2: if ($test_section["value"]["v0"] == 0) { break; } $value = 0; if (isset($compare["Template"][$test_section["value"]["v0"]])) { $value = $compare["Template"][$test_section["value"]["v0"]]; } $test_section["value"]["v0"] = $value; break; case 13: if ($test_section["value"]["v0"] == 0) { break; } $value = 0; if (isset($compare["QTIAssessmentItem"][$test_section["value"]["v0"]])) { $value = $compare["QTIAssessmentItem"][$test_section["value"]["v0"]]; } $test_section["value"]["v0"] = $value; break; case 11: if ($test_section["value"]["v0"] == 0) { break; } $value = 0; if (isset($compare["Test"][$test_section["value"]["v0"]])) { $value = $compare["Test"][$test_section["value"]["v0"]]; } $test_section["value"]["v0"] = $value; break; case 9: if ($test_section["value"]["v0"] == 0) { break; } $value = 0; if (isset($compare["CustomSection"][$test_section["value"]["v0"]])) { $value = $compare["CustomSection"][$test_section["value"]["v0"]]; } $test_section["value"]["v0"] = $value; break; case 8: if ($test_section["value"]["v3"] == 0) { break; } $value = 0; if (isset($compare["Table"][$test_section["value"]["v3"]])) { $value = $compare["Table"][$test_section["value"]["v3"]]; } $test_section["value"]["v3"] = $value; break; case 5: if ($test_section["value"]["v5"] == 0) { break; } if ($test_section["value"]["v2"] == 0) { $value = 0; if (isset($compare["Table"][$test_section["value"]["v5"]])) { $value = $compare["Table"][$test_section["value"]["v5"]]; } $test_section["value"]["v5"] = $value; } break; } if (count($test_section["value"]) == 0) { $test_section['value'] = "{}"; } array_push($post["sections"], $test_section); } $post['sections'] = json_encode($post['sections']); $post["parameters"] = array(); $elements = $xpath->query("/export/Test[@id='" . $element_id . "']/TestVariables/TestVariable"); foreach ($elements as $element) { $tv = array(); $tv["Test_id"] = $element_id; $children = $element->childNodes; $correct = true; foreach ($children as $child) { switch ($child->nodeName) { case "index": $tv["index"] = $child->nodeValue; break; case "name": $tv["name"] = $child->nodeValue; break; case "description": $tv["description"] = $child->nodeValue; break; case "type": $tv["type"] = $child->nodeValue; if ($tv["type"] != 0) { $correct = false; } break; } } if ($correct) { $tv = json_encode($tv); array_push($post['parameters'], $tv); } } $post["returns"] = array(); $elements = $xpath->query("/export/Test[@id='" . $element_id . "']/TestVariables/TestVariable"); foreach ($elements as $element) { $tv = array(); $tv["Test_id"] = $element_id; $children = $element->childNodes; $correct = true; foreach ($children as $child) { switch ($child->nodeName) { case "index": $tv["index"] = $child->nodeValue; break; case "name": $tv["name"] = $child->nodeValue; break; case "description": $tv["description"] = $child->nodeValue; break; case "type": $tv["type"] = $child->nodeValue; if ($tv["type"] != 1) { $correct = false; } break; } } if ($correct) { $tv = json_encode($tv); array_push($post['returns'], $tv); } } $post["protected"] = array(); $elements = $xpath->query("/export/Test[@id='" . $element_id . "']/TestProtectedVariables/TestProtectedVariable"); foreach ($elements as $element) { $tpv = array(); $tpv["Test_id"] = $element_id; $children = $element->childNodes; $correct = true; foreach ($children as $child) { switch ($child->nodeName) { case "name": $tpv["name"] = $child->nodeValue; break; } } $tpv = json_encode($tpv); array_push($post['protected'], $tpv); } return $this->mysql_save_from_post($post); }
*/ /*------------------------------------------------------------------------------ (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 ------------------------------------------------------------------------------*/ if (!isset($_REQUEST["action"]) || empty($_REQUEST["action"])) { badrequest("no action specified"); } $classname = ucfirst($_REQUEST["action"]) . "Action"; if (!@class_exists($classname) || !is_subclass_of($classname, "ItemAction")) { badrequest("Item action doesn't exist or not implemented"); } $action = new $classname(); if (!isset($_REQUEST["qtiid"])) { badrequest("No QTI ID specified"); } if (!QTIAssessmentItem::fromQTIID($_REQUEST["qtiid"])) { badrequest("No QTI found in session data for specified QTI ID"); } if (!$action->available(QTIAssessmentItem::fromQTIID($_REQUEST["qtiid"]))) { badrequest(ucfirst($action->name()) . " action is not currently available for the specified QTI item"); } $GLOBALS["title"] = $action->description(); $action->beforeLogic(); if (isset($_POST) && !empty($_POST)) { $action->postLogic(); } else { $action->getLogic(); } $action->afterLogic();
public static function calculate_all_xml_hashes() { //Table - calculate xml_hash $sql = sprintf("SELECT `id` FROM `Table`"); $z = mysql_query($sql); while ($r = mysql_fetch_array($z)) { set_time_limit(0); $obj = Table::from_mysql_id($r[0]); $obj->xml_hash = $obj->calculate_xml_hash(); $obj->mysql_save(); } //Template - calculate xml_hash $sql = sprintf("SELECT `id` FROM `Template`"); $z = mysql_query($sql); while ($r = mysql_fetch_array($z)) { set_time_limit(0); $obj = Template::from_mysql_id($r[0]); $obj->xml_hash = $obj->calculate_xml_hash(); $obj->mysql_save(); } //QTIAssessmentItem - calculate xml_hash $sql = sprintf("SELECT `id` FROM `QTIAssessmentItem`"); $z = mysql_query($sql); while ($r = mysql_fetch_array($z)) { set_time_limit(0); $obj = QTIAssessmentItem::from_mysql_id($r[0]); $obj->xml_hash = $obj->calculate_xml_hash(); $obj->mysql_save(); } //Test - calculate xml_hash $sql = sprintf("SELECT `id` FROM `Test`"); $z = mysql_query($sql); while ($r = mysql_fetch_array($z)) { set_time_limit(0); $obj = Test::from_mysql_id($r[0]); $obj->xml_hash = $obj->calculate_xml_hash(); $obj->mysql_save(); } }