//pr($imsFiles);exit; foreach ($imsFiles as $imsFile) { /* Imports ims package to database */ $imsFolderName = EfrontFile::encode(eFront_basename($imsFile['name'], '.zip')); $imsPath = $currentLesson->getDirectory() . $imsFolderName . '/'; is_dir($imsPath) or mkdir($imsPath, 0755); //pr($imsPath.$imsFile['name']); //try { $imsFile->rename($imsPath . $imsFile['name'], true); //} catch (Exception $e) {pr($e);throw $e;} $fileList = $imsFile->uncompress(false); $imsFile->delete(); $total_fields = array(); $resources = array(); $manifestFile = new EfrontFile($imsPath . 'imsmanifest.xml'); EfrontIMS::import($currentLesson, $manifestFile, $imsFolderName, array('embed_type' => $values['embed_type'], 'popup_parameters' => $values['popup_parameters'])); } eF_redirect("" . basename($_SERVER['PHP_SELF']) . "?ctg=ims&message=" . urlencode(_SUCCESSFULLYIMPORTEDIMSFILE) . "&message_type=success"); } catch (Exception $e) { $smarty->assign("T_EXCEPTION_TRACE", $e->getTraceAsString()); $message = $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_UPLOAD_IMS_FORM', $renderer->toArray()); } catch (Exception $e) { $smarty->assign("T_EXCEPTION_TRACE", $e->getTraceAsString()); $message = $e->getMessage() . ' (' . $e->getCode() . ') <a href = "javascript:void(0)" onclick = "eF_js_showDivPopup(event, \'' . _ERRORDETAILS . '\', 2, \'error_details\')">' . _MOREINFO . '</a>'; $message_type = failure;
/** * * @param unknown_type $file * @return unknown_type */ public static function import($lesson, $manifestFile, $scormFolderName, $parameters) { if ($lesson instanceof EfrontLesson) { $currentLesson = $lesson; } else { $currentLesson = new EfrontLesson($lesson); } $lessons_ID = $currentLesson->lesson['id']; $currentContent = new EfrontContentTree($currentLesson); $manifestXML = file_get_contents($manifestFile['path']); $tagArray = EfrontIMS::parseManifest($manifestXML); /** * Now parse XML file as usual */ foreach ($tagArray as $key => $value) { $fields = array(); switch ($value['tag']) { case 'SCHEMAVERSION': $scormVersion = $value['value']; break; case 'TITLE': $cur = $value['parent_index']; $total_fields[$cur]['name'] = $value['value'] ? $value['value'] : " "; break; case 'ORGANIZATION': $item_key = $key; $total_fields[$key]['lessons_ID'] = $lessons_ID; $total_fields[$key]['timestamp'] = time(); $total_fields[$key]['ctg_type'] = 'theory'; $total_fields[$key]['identifier'] = $value['attributes']['IDENTIFIER']; $total_fields[$key]['active'] = !isset($value['attributes']['ISVISIBLE']) || $value['attributes']['ISVISIBLE'] == 'true' ? 1 : 0; break; case 'ITEM': $item_key = $key; $total_fields[$key]['lessons_ID'] = $lessons_ID; $total_fields[$key]['timestamp'] = time(); $total_fields[$key]['ctg_type'] = 'theory'; $total_fields[$key]['identifier'] = $value['attributes']['IDENTIFIER']; $total_fields[$key]['active'] = !isset($value['attributes']['ISVISIBLE']) || $value['attributes']['ISVISIBLE'] == 'true' ? 1 : 0; $references[$key]['IDENTIFIERREF'] = EfrontIMS::formID($value['attributes']['IDENTIFIERREF']); $references[$key]['PARAMETERS'] = $value['attributes']['PARAMETERS']; break; case 'RESOURCE': $resources[$key] = EfrontIMS::formID($value['attributes']['IDENTIFIER']); break; case 'FILE': $files[$key] = $value['attributes']['HREF']; break; default: break; } } foreach ($references as $key => $value) { $ref = array_search($value['IDENTIFIERREF'], $resources); if ($ref !== false && !is_null($ref)) { /*SCORM 2004: The xml:base attribute provides a relative path offset for the content file(s) contained in the manifest*/ $path_offset = $tagArray[$ref]['attributes']['XML:BASE']; if ($tagArray[$ref]['attributes']['TYPE'] == 'imswl_xmlv1p2') { foreach ($tagArray[$ref]['children'] as $node) { if ($tagArray[$node]['tag'] == 'FILE') { $href = $tagArray[$node]['attributes']['HREF']; //debug(); //pr($currentLesson -> getDirectory()."/".$scormFolderName."/".$path_offset.$href); $data = file_get_contents($currentLesson->getDirectory() . "/" . $scormFolderName . "/" . $path_offset . $href); file_put_contents($currentLesson->getDirectory() . "/" . $scormFolderName . "/" . $path_offset . dirname($href) . '/weblink.html', self::createWebLink($data)); $href = dirname($href) . '/weblink.html'; //exit; //pr($data);exit; } } } else { if (!$tagArray[$ref]['attributes']['HREF']) { foreach ($tagArray[$ref]['children'] as $node) { if ($tagArray[$node]['tag'] == 'FILE') { $href = $tagArray[$node]['attributes']['HREF']; } } } else { $href = $tagArray[$ref]['attributes']['HREF']; } } $data = file_get_contents($currentLesson->getDirectory() . "/" . $scormFolderName . "/" . $path_offset . $href); $primitive_hrefs[$ref] = $path_offset . $href; $path_part[$ref] = dirname($primitive_hrefs[$ref]); foreach ($tagArray[$ref]['children'] as $value2) { if ($tagArray[$value2]['tag'] == 'DEPENDENCY') { $idx = array_search($tagArray[$value2]['attributes']['IDENTIFIERREF'], $resources); foreach ($tagArray[$idx]['children'] as $value3) { if ($tagArray[$value3]['tag'] == 'FILE') { $data = preg_replace("#(\\.\\.\\/(\\w+\\/)*)?" . $tagArray[$value3]['attributes']['HREF'] . "#", $currentLesson->getDirectory() . "/" . $scormFolderName . '/' . $path_part[$ref] . "/\$1" . $tagArray[$value3]['attributes']['HREF'], $data); } } } } if ($parameters['embed_type'] == 'iframe') { $total_fields[$key]['data'] = '<iframe height = "100%" width = "100%" frameborder = "no" name = "scormFrameName" id = "scormFrameID" src = "' . $currentLesson->getDirectoryUrl() . "/" . $scormFolderName . '/' . $primitive_hrefs[$ref] . $value['PARAMETERS'] . '" onload = "if (window.eF_js_setCorrectIframeSize) eF_js_setCorrectIframeSize(); else setIframeSize = true;"></iframe>'; } else { $total_fields[$key]['data'] = ' <div style = "text-align:center;height:300px"> <span>##CLICKTOSTARTUNIT##</span><br/> <input type = "button" value = "##STARTUNIT##" class = "flatButton" onclick = \'window.open("' . $currentLesson->getDirectoryUrl() . "/" . $scormFolderName . '/' . $primitive_hrefs[$ref] . $value['PARAMETERS'] . '", "scormFrameName", "' . $parameters['popup_parameters'] . '")\' > </div>'; } } } //pr($tagArray);exit; $lastUnit = $currentContent->getLastNode(); $lastUnit ? $this_id = $lastUnit['id'] : ($this_id = 0); //$this_id = $tree[sizeof($tree) - 1]['id']; foreach ($total_fields as $key => $value) { if (isset($value['ctg_type']) && $value['name']) { $total_fields[$key]['previous_content_ID'] = $this_id; if (!isset($total_fields[$key]['parent_content_ID'])) { $total_fields[$key]['parent_content_ID'] = 0; } $this_id = eF_insertTableData("content", $total_fields[$key]); //we want to have entry at scorm data even if all values are null $fields_insert[$this_id]['content_ID'] = $this_id; $tagArray[$key]['this_id'] = $this_id; foreach ($tagArray[$key]['children'] as $key2 => $value2) { if (isset($total_fields[$value2])) { $total_fields[$value2]['parent_content_ID'] = $this_id; } } } else { unset($total_fields[$key]); } } //$directory = new EfrontDirectory(G_SCORMPATH); //$directory -> copy(EfrontDirectory :: normalize($currentLesson -> getDirectory()).'/'.$scormFolderName, true); //foreach ($files as $key => $value) { //$newhref = $tagArray[$tagArray[$key]['parent_index']]['attributes']['XML:BASE']; //copy(G_SCORMPATH."/".rtrim($newhref,"/")."/".rtrim($value,"/"), rtrim($currentLesson -> getDirectory(), "/")."/$this_id/".rtrim($newhref,"/")."/".rtrim($value,"/")); //$this_id is put here so we can be sure that the files are put in a unique folder //} foreach ($prerequisites as $key => $value) { foreach ($tagArray as $key2 => $value2) { if (isset($value2['attributes']['IDENTIFIER']) && $value2['attributes']['IDENTIFIER'] == $value) { unset($fields_insert); $fields_insert['users_LOGIN'] = "******"; $fields_insert['content_ID'] = $tagArray[$tagArray[$key]['parent_index']]['this_id']; $fields_insert['rule_type'] = "hasnot_seen"; $fields_insert['rule_content_ID'] = $value2['this_id']; $fields_insert['rule_option'] = 0; eF_insertTableData("rules", $fields_insert); } } } }