public function toIMS($path) { $lesson_entries = eF_getTableData("content", "id, name, data", "lessons_ID=" . $this->lesson['id'] . " and ctg_type = 'theory' and active=1"); $cur_dir = getcwd(); chdir(G_LESSONSPATH . $this->lesson['id'] . '/'); $filelist = eF_getDirContents(); chdir($cur_dir); create_manifest($this->lesson['id'], $lesson_entries, $filelist, $path); //create the EfrontLesson.xml $str = '<?xml version="1.0" encoding="UTF-8"?><efrontlesson>'; //write out the glossary $glossary = ef_getTableData("glossary", "*", "lessons_ID=" . $this->lesson['id']); if (sizeof($glossary) > 0) { $str .= '<glossary>'; for ($i = 0; $i < sizeof($glossary); $i++) { $str .= '<word>'; $str .= '<name>' . $glossary[$i]['name'] . '</name>'; $str .= '<info>' . $glossary[$i]['info'] . '</info>'; $str .= '<type>' . $glossary[$i]['type'] . '</type>'; $str .= '<active>' . $glossary[$i]['active'] . '</active>'; $str .= '</word>'; } $str .= '</glossary>'; } //write out the lesson conditions $conditions = ef_getTableData("lesson_conditions", "*", "lessons_ID=" . $this->lesson['id']); if (sizeof($conditions) > 0) { $str .= '<conditions>'; for ($i = 0; $i < sizeof($conditions); $i++) { $str .= '<condition>'; $str .= '<type>' . $conditions[$i]['type'] . '</type>'; $str .= '<options>' . $conditions[$i]['options'] . '</options>'; $str .= '<relation>' . $conditions[$i]['relation'] . '</relation>'; $str .= '</condition>'; } $str .= '</conditions>'; } //write out the rules $rules = ef_getTableData("rules r, content c", "r.*", "c.id = r.content_ID and c.lessons_ID=" . $this->lesson['id']); if (sizeof($rules) > 0) { $str .= '<rules>'; for ($i = 0; $i < sizeof($rules); $i++) { $str .= "<rule>"; $str .= "<content_id>" . $rules[$i]['content_ID'] . "</content_id>"; $str .= "<rule_content_id>" . $rules[$i]['rule_content_ID'] . "</rule_content_id>"; $str .= "<rule_type>" . $rules[$i]['rule_type'] . "</rule_type>"; $str .= "<rule_option>" . $rules[$i]['rule_option'] . "</rule_option>"; $str .= '</rule>'; } $str .= '</rules>'; } //write out the questions $questions = ef_getTableData("questions q, content c", "q.*", "q.content_id = c.id and c.lessons_id=" . $this->lesson['id'] . ""); if (sizeof($questions) > 0) { $str .= "<questions>"; for ($i = 0; $i < sizeof($questions); $i++) { $str .= "<question>"; $str .= "<refid>q" . $questions[$i]['id'] . "</refid>"; $str .= "<type>" . $questions[$i]['type'] . "</type>"; $str .= "<difficulty>" . $questions[$i]['difficulty'] . "</difficulty>"; $str .= "<options>" . $questions[$i]['options'] . "</options>"; $str .= "<answer>" . $questions[$i]['answer'] . "</answer>"; $str .= "<explanation>" . $questions[$i]['explanation'] . "</explanation>"; $str .= "</question>"; } $str .= "</questions>"; } //write out the tests $tests = ef_getTableData("tests t, content c", "t.*", "t.content_id = c.id and c.lessons_id=" . $this->lesson['id'] . ""); if (sizeof($tests) > 0) { $str .= "<tests>"; for ($i = 0; $i < sizeof($tests); $i++) { $str .= "<test>"; $str .= "<refid>t" . $tests[$i]['id'] . "</refid>"; $str .= "<duration>" . $tests[$i]['duration'] . "</duration>"; $str .= "<redoable>" . $tests[$i]['redoable'] . "</redoable>"; $str .= "<onebyone>" . $tests[$i]['onebyone'] . "</onebyone>"; $str .= "<answers>" . $tests[$i]['answers'] . "</answers>"; $str .= "<shuffle_questions>" . $tests[$i]['shuffle_questions'] . "</shuffle_questions>"; $str .= "<shuffle_answers>" . $tests[$i]['shuffle_answers'] . "</shuffle_answers>"; $str .= "<given_answers>" . $tests[$i]['given_answers'] . "</given_answers>"; $questions = ef_getTableData("tests_to_questions", "*", "tests_ID = " . $tests[$i]['id']); $str .= "<questions>"; for ($j = 0; $j < sizeof($questions); $j++) { $str .= "<question>"; $str .= "<refid>q" . $questions[$j]['questions_ID'] . "</refid>"; $str .= "<weight>" . $questions[$j]['weight'] . "</weight>"; $str .= "<previous>q" . $questions[$j]['previous_question_ID'] . "</previous>"; $str .= "</question>"; } $str .= "</questions>"; $str .= "</test>"; } $str .= "</tests>"; } $str .= '</efrontlesson>'; if ($fp = fopen($path . "/lesson" . $this->lesson['id'] . "/eFrontLesson.xml", "wb")) { fwrite($fp, $str); } fclose($fp); chdir($path . "/lesson" . $this->lesson['id']); $d = dir("."); $entries = array(); while (false !== ($entry = $d->read())) { if ($entry != "." & $entry != "..") { array_push($entries, $entry); } } $d->close(); $zip = new Archive_zip($path . "/lesson" . $this->lesson['id'] . ".tar.gz"); $zip->create($entries); chdir($cur_dir); deldir($path . "/lesson" . $this->lesson['id']); }
function create_push_package() { global $certificate_path, $certificate_password; // Create a temporary directory in which to assemble the push package $package_dir = 'pushPackage' . time(); if (!mkdir($package_dir)) { unlink($package_dir); die; } copy_raw_push_package_files($package_dir); create_manifest($package_dir); create_signature($package_dir, $certificate_path, $certificate_password); $package_path = package_raw_data($package_dir); return $package_path; }
if (!is_dir(IMS_FOLDER)) { mkdir(IMS_FOLDER, 0755); } $ims_filename = "ims_lesson" . $lessons_id . ".zip"; if (is_file(IMS_FOLDER . "/" . $ims_filename)) { unlink(IMS_FOLDER . "/" . $ims_filename); } $lessons_id = $currentLesson->lesson['id']; try { $filesystem = new FileSystemTree($currentLesson->getDirectory()); foreach (new EfrontNodeFilterIterator(new RecursiveIteratorIterator($filesystem->tree, RecursiveIteratorIterator::SELF_FIRST)) as $key => $value) { $value instanceof EfrontDirectory ? $filelist[] = preg_replace("#" . $currentLesson->getDirectory() . "#", "", $key) . '/' : ($filelist[] = preg_replace("#" . $currentLesson->getDirectory() . "#", "", $key)); } $lesson_entries = eF_getTableData("content", "id,name,data", "lessons_ID=" . $lessons_id . " and ctg_type!='tests' and active=1"); require_once "ims_tools.php"; create_manifest($lessons_id, $lesson_entries, $filelist, IMS_FOLDER); $imsDirectory = new EfrontDirectory(IMS_FOLDER . "/lesson" . $lessons_id . "/"); $compressedFile = $imsDirectory->compress(false, false, true); $imsDirectory->delete(); $smarty->assign("T_IMS_EXPORT_FILE", $compressedFile); $smarty->assign("T_MESSAGE", _SUCCESSFULLYEXPORTEDIMSFILE); $smarty->assign("T_MESSAGE_TYPE", "success"); } catch (Exception $e) { $smarty->assign("T_EXCEPTION_TRACE", $e->getTraceAsString()); $message = _SOMEPROBLEMEMERGED . ': ' . $e->getMessage() . ' (' . $e->getCode() . ') <a href = "javascript:void(0)" onclick = "eF_js_showDivPopup(event, \'' . _ERRORDETAILS . '\', 2, \'error_details\')">' . _MOREINFO . '</a>'; $message_type = "failure"; } } $renderer = new HTML_QuickForm_Renderer_ArraySmarty($smarty); $form->accept($renderer); $smarty->assign('T_EXPORT_IMS_FORM', $renderer->toArray());
<?php // Add the correct Content-Type for the cache manifest header('Content-Type: text/cache-manifest'); // Write the first line echo "CACHE MANIFEST\n"; // Initialize the $hashes string function create_manifest($folder) { $hashes = ""; $dir = new RecursiveDirectoryIterator($folder); // Iterate through all the files/folders in the current directory foreach (new RecursiveIteratorIterator($dir) as $file) { $info = pathinfo($file); // If the object is a file // and it's not called manifest.php (this file), // and it's not a dotfile, add it to the list if ($file->IsFile() && $file != "./manifest.php" && substr($file->getFilename(), 0, 1) != ".") { // Replace spaces with %20 or it will break echo str_replace(' ', '%20', $file) . "\n"; // Add this file's hash to the $hashes string $hashes .= md5_file($file); echo "# Hash: " . md5($hashes) . "\n"; } } } create_manifest(".");