1 | <?php |
---|
2 | |
---|
3 | require_once('violetUtil.class.php'); |
---|
4 | date_default_timezone_set("Asia/Ho_Chi_Minh"); |
---|
5 | createPackage(); |
---|
6 | |
---|
7 | function createHtmlFile($type, $scVer, $appName, $path) |
---|
8 | { |
---|
9 | if ($type==3) $html = file_get_contents(VIOLET_APP_DIR."/Support/Scorm/Scorm{$scVer}/Scorm.html"); |
---|
10 | else $html = file_get_contents(VIOLET_APP_DIR.'/Frame/Player.html'); |
---|
11 | $html = str_replace('{Application Title}', $appName, $html); |
---|
12 | file_put_contents($path.'Index.html', $html); |
---|
13 | } |
---|
14 | |
---|
15 | function createManifestFile($scVer, $appName, $title, $orgXml, $resList, $path) |
---|
16 | { |
---|
17 | for ($i = 0; $i < count($resList); $i++) $resList[$i] = '<file href="'.$resList[$i].'" />'; |
---|
18 | $key = array( |
---|
19 | '{Application Title}', '{Lesson Title}', '{Lesson Organization}', '{Resources List}', |
---|
20 | '{MANIFEST UUID}', '{ORGANIZATION UUID}', '{ITEM UUID}', '{RESOURCE UUID}'); |
---|
21 | $replace = array( |
---|
22 | $appName, $title, $orgXml, join("\r\n ", $resList), |
---|
23 | 'MANIFEST-01', 'ORGANIZATION-01', 'ITEM-01', 'RESOURCE-01'); |
---|
24 | |
---|
25 | $scorm = file_get_contents(VIOLET_APP_DIR."/Support/Scorm/Scorm{$scVer}/imsmanifest.xml"); |
---|
26 | $scorm = str_replace($key, $replace, $scorm); |
---|
27 | file_put_contents($path.'imsmanifest.xml', $scorm); |
---|
28 | } |
---|
29 | |
---|
30 | function createPackage() |
---|
31 | { |
---|
32 | $userId = $_REQUEST['userid']; |
---|
33 | $appName = $_REQUEST['name']; |
---|
34 | $type = $_REQUEST['type']; |
---|
35 | $dataNum = $_REQUEST['dataNum']; |
---|
36 | $commonNum = $_REQUEST['commonNum']; |
---|
37 | $fileList = $_REQUEST['fileList']; |
---|
38 | if ($type == 1) $player = $_REQUEST['packagePlayer']; |
---|
39 | if ($type == 3) { |
---|
40 | $scVer = $_REQUEST['scormVersion']; |
---|
41 | $scTitle = $_REQUEST['scormTitle']; |
---|
42 | $scOrgXml = $_REQUEST['scormOrgData']; |
---|
43 | } |
---|
44 | $content = $_REQUEST['dataXml']; |
---|
45 | |
---|
46 | $fileList = explode(',', $fileList); |
---|
47 | $packFileList = array(); |
---|
48 | $errList = array(); |
---|
49 | |
---|
50 | // create package dir and create scenario file |
---|
51 | $timeStamp = date('YmdHis'); |
---|
52 | $dest = violetUtil::getTempPath('packages')."/Package_{$timeStamp}_{$userId}_{$appName}/"; |
---|
53 | if (file_exists($dest)) return; |
---|
54 | mkdir($dest, 0777, true); |
---|
55 | if ($commonNum > 0) mkdir($dest.'Common', 0777); |
---|
56 | if ($dataNum > 0) mkdir($dest.'Data', 0777); |
---|
57 | file_put_contents($dest.'Scenario.xvl', $content); |
---|
58 | |
---|
59 | // copy player file |
---|
60 | if ($type == 1) { // EXE for Win, Mac and Linux |
---|
61 | $dotPos = strrpos($player, '.'); |
---|
62 | if ($dotPos === false) $ext = ''; |
---|
63 | else $ext = substr($player, $dotPos); |
---|
64 | $playerSrc = VIOLET_APP_DIR.'/Frame/'.$player; |
---|
65 | if ($ext != '.zip') { |
---|
66 | $playerDst = $dest.$appName.$ext; |
---|
67 | copy($playerSrc, $playerDst); |
---|
68 | if ($ext == '') chmod($playerDst, 0755); |
---|
69 | } else { |
---|
70 | $playerDst = $dest.$appName.'.app'; |
---|
71 | violetUtil::Unzip($playerSrc, $playerDst); |
---|
72 | chmod($playerDst.'/Contents/MacOS/Flash Player', 0755); |
---|
73 | } |
---|
74 | } |
---|
75 | else { // HTML + SWF for web base |
---|
76 | createHtmlFile($type, ($type==3? $scVer: ""), $appName, $dest); |
---|
77 | copy(VIOLET_APP_DIR.'/Frame/Player.swf', $dest.'Player.swf'); |
---|
78 | array_push($packFileList, "Index.html"); |
---|
79 | array_push($packFileList, "Player.swf"); |
---|
80 | array_push($packFileList, "Scenario.xvl"); |
---|
81 | } |
---|
82 | |
---|
83 | // copy list of data files + common files |
---|
84 | for ($i = 0; $i < count($fileList); $i += 2) { |
---|
85 | $data = file_get_contents(str_replace(' ', '%20', $fileList[$i])); |
---|
86 | if (!$data) array_push($errList, $fileList[$i]); |
---|
87 | else { |
---|
88 | file_put_contents($dest.$fileList[$i+1], $data); |
---|
89 | array_push($packFileList, $fileList[$i+1]); |
---|
90 | } |
---|
91 | } |
---|
92 | |
---|
93 | // create imsmanifest.xml and copy SCORM files |
---|
94 | if ($type == 3) { |
---|
95 | createManifestFile($scVer, $appName, $scTitle, $scOrgXml, $packFileList, $dest); |
---|
96 | $src = VIOLET_APP_DIR."/Support/Scorm/Scorm$scVer/"; |
---|
97 | violetUtil::copyAllFile('*.xsd', $src, $dest); |
---|
98 | violetUtil::copyAllFile('*.dtd', $src, $dest); |
---|
99 | } |
---|
100 | |
---|
101 | // create zip package |
---|
102 | $zipFileName = substr($dest, 0, -1).'.zip'; |
---|
103 | violetUtil::createZip($dest, $zipFileName); |
---|
104 | violetUtil::cleanDirectory($dest); |
---|
105 | |
---|
106 | echo "<url id='$timeStamp' />"; |
---|
107 | } |
---|