global $_course_id; Utility::authenticate(TR_PRIV_ISAUTHOR_OF_CURRENT_COURSE); $testsQuestionsDAO = new TestsQuestionsDAO(); $_letters = array(_AT('A'), _AT('B'), _AT('C'), _AT('D'), _AT('E'), _AT('F'), _AT('G'), _AT('H'), _AT('I'), _AT('J')); if (isset($_GET['submit'])) { header('Location: ' . TR_BASE_HREF . 'tests/question_db.php?_course_id=' . $_course_id); exit; } if (defined('TR_FORCE_GET_FILE') && TR_FORCE_GET_FILE) { $content_base_href = 'get.php/'; } else { $content_base_href = 'content/' . $_SESSION['course_id'] . '/'; } require_once TR_INCLUDE_PATH . 'header.inc.php'; $qids = explode(',', $_GET['qid']); $rows = $testsQuestionsDAO->getByQuestionIDs($qids); ?> <form method="get" action="<?php echo $_SERVER['PHP_SELF']; ?> "> <input type="hidden" name="_course_id" value="<?php echo $_course_id; ?> " /> <div class="input-form"> <?php if (is_array($rows)) { foreach ($rows as $row) { $obj = TestQuestions::getQuestion($row['type']);
/** * Export test questions * @param array an array consist of all the ids of the questions in which we desired to export. */ function test_question_qti_export($question_ids) { global $_course_id; require_once TR_INCLUDE_PATH . 'classes/DAO/CoursesDAO.class.php'; require_once TR_INCLUDE_PATH . 'classes/DAO/TestsQuestionsDAO.class.php'; require_once TR_INCLUDE_PATH . 'classes/zipfile.class.php'; // for zipfile require_once TR_INCLUDE_PATH . 'lib/html_resource_parser.inc.php'; // for get_html_resources() require_once TR_INCLUDE_PATH . 'classes/XML/XML_HTMLSax/XML_HTMLSax.php'; // for XML_HTMLSax global $savant, $db, $languageManager; $coursesDAO = new CoursesDAO(); $course_row = $coursesDAO->get($_course_id); $course_language = $course_row['primary_language']; $courseLanguage =& $languageManager->getLanguage($course_language); $course_language_charset = $courseLanguage->getCharacterSet(); $zipfile = new zipfile(); $zipfile->create_dir('resources/'); // for all the dependency files $resources = array(); $dependencies = array(); asort($question_ids); $testsQuestionsDAO = new TestsQuestionsDAO(); $rows = $testsQuestionsDAO->getByQuestionIDs($question_ids); if (is_array($rows)) { foreach ($rows as $row) { $obj = TestQuestions::getQuestion($row['type']); $local_xml = ''; $local_xml = $obj->exportQTI($row, $course_language_charset, '1.2.1'); $local_dependencies = array(); $text_blob = implode(' ', $row); $local_dependencies = get_html_resources($text_blob); $dependencies = array_merge($dependencies, $local_dependencies); // $resources[] = array('href' => 'question_'.$row['question_id'].'.xml', // 'dependencies' => array_keys($local_dependencies)); $xml = $xml . "\n\n" . $local_xml; } } $xml = trim($xml); //TODO $savant->assign('xml_content', $xml); $savant->assign('title', $row['question']); $xml = $savant->fetch('tests/test_questions/wrapper.tmpl.php'); $xml_filename = 'atutor_questions.xml'; $zipfile->add_file($xml, $xml_filename); // add any dependency files: foreach ($dependencies as $resource => $resource_server_path) { $zipfile->add_file(@file_get_contents($resource_server_path), 'resources/' . $resource, filemtime($resource_server_path)); } // construct the manifest xml // $savant->assign('resources', $resources); $savant->assign('dependencies', array_keys($dependencies)); $savant->assign('encoding', $course_language_charset); $savant->assign('xml_filename', $xml_filename); // $manifest_xml = $savant->fetch('tests/test_questions/manifest_qti_2p1.tmpl.php'); $manifest_xml = $savant->fetch('tests/test_questions/manifest_qti_1p2.tmpl.php'); $zipfile->add_file($manifest_xml, 'imsmanifest.xml'); $zipfile->close(); $filename = str_replace(array(' ', ':'), '_', $course_row['title'] . '-' . _AT('question_database') . '-' . date('Ymd')); $zipfile->send_file($filename); exit; }