importmanifest.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  1. <?php /* <!-- Dokeos metadata/importmanifest.php -->
  2. <!-- 2006/12/15 -->
  3. <!-- Copyright (C) 2006 rene.haentjens@UGent.be - see metadata/md_funcs.php -->
  4. */
  5. /**
  6. ==============================================================================
  7. * Dokeos Metadata: create and manage table entries for SCORM package
  8. *
  9. * @package dokeos.metadata
  10. ==============================================================================
  11. */
  12. // PRELIMS -------------------------------------------------------------------->
  13. $getpostvars = array('sdisub','workWith','sdi','smo'); require('md_funcs.php');
  14. define('EID_TYPE', 'Scorm'); define('TPLEN', strlen(EID_TYPE) + 1);
  15. require('md_' . strtolower(EID_TYPE) . '.php');
  16. // name of the language file that needs to be included
  17. $language_file = 'md_' . strtolower(EID_TYPE);
  18. include('../inc/global.inc.php');
  19. $nameTools = get_lang('Tool');
  20. if (!isset($sdisub)) $sdisub = '';
  21. $sdisub = substr(ereg_replace("[^0-9A-Za-z]", "", $sdisub), 0, 4);
  22. // $sdisub is for split manifests - Scorm.NNN.$sdisub_xxx e.g. Scorm.3.1979_12
  23. define('MFFNAME', 'imsmanifest'); define('MFFDEXT', '.xml');
  24. define('HTF', 'mdp_scorm.htt');
  25. $regs = array();
  26. ($nameTools && get_lang('Sorry')) or give_up(
  27. 'Language file ' . $language_file . " doesn't define 'Tool' and 'Sorry'");
  28. $_course = api_get_course_info(); isset($_course) or give_up(get_lang('Sorry'));
  29. $is_allowed_to_edit = isset($_user['user_id']) && $is_courseMember && is_allowed_to_edit();
  30. if (!$is_allowed_to_edit) give_up(get_lang('Denied'));
  31. $baseWorkDir = get_course_path() . ($courseDir = $_course['path'] . '/scorm');
  32. $mdStore = new mdstore($is_allowed_to_edit); // create table if needed
  33. require(api_get_path(LIBRARY_PATH) . 'xmd.lib.php');
  34. require(api_get_path(LIBRARY_PATH) . 'xht.lib.php');
  35. require(api_get_path(LIBRARY_PATH) . 'fileManage.lib.php');
  36. require('md_phpdig.php');
  37. // SET CURRENT SCORM DIRECTORY - HEADER --------------------------------------->
  38. if (isset($workWith)) // explicit in URL, or selected at bottom of screen
  39. {
  40. $scormdocument = Database::get_course_table(TABLE_LP_MAIN);
  41. $sql = "SELECT id FROM $scormdocument WHERE path='". Database::escape_string(api_substr($workWith,1)) . "' OR path='". Database::escape_string(substr($workWith,1)) . "/.'";
  42. $result = Database::query($sql, __FILE__, __LINE__);
  43. if (Database::num_rows($result) == 1)
  44. {
  45. if (($row = Database::fetch_array($result)))
  46. {
  47. $sdi = $row['id'];
  48. }
  49. }
  50. }
  51. if (isset($sdi) && is_numeric($sdi) && $sdi > 0 && $sdi == (int) $sdi)
  52. {
  53. $mdObj = new mdobject($_course, $sdi); $workWith = $mdObj->mdo_path;
  54. $hdrInfo = ' ' . get_lang('WorkOn') . ' ' .
  55. ($workWith ? htmlspecialchars($workWith, ENT_QUOTES, $charset) . ', ' : '') .
  56. 'SD-id= ' . htmlspecialchars($sdi, ENT_QUOTES, $charset) .
  57. ($sdisub ? ' (' . htmlspecialchars($sdisub, ENT_QUOTES, $charset) . ')' : '');
  58. }
  59. else
  60. {
  61. unset($sdi); $mdObj = new mdobject($_course, 0);
  62. if ($workWith) $hdrInfo = ' (' . htmlspecialchars($workWith, ENT_QUOTES, $charset) .
  63. ': ' . get_lang('NotInDB') . ')'; unset($workWith);
  64. }
  65. define('UZYX', 'UZYX'); // magic word to repeat for all $sdisub
  66. if (($sdiall = ($sdisub == UZYX)))
  67. {
  68. $sdisub = ''; $sdiall = array();
  69. if (($dh = opendir($baseWorkDir . $workWith)))
  70. {
  71. while (FALSE !== ($file = readdir($dh)))
  72. if (ereg('^'.MFFNAME.'(.+)\\'.MFFDEXT .'$', $file, $regs))
  73. $sdiall[] = $regs[1];
  74. closedir($dh);
  75. }
  76. sort($sdiall);
  77. }
  78. $originalHdrInfo = $hdrInfo;
  79. function slurpmanifest()
  80. {
  81. global $baseWorkDir, $workWith, $sdisub, $mfContents, $xht_doc;
  82. $fmff = $baseWorkDir .'/'. $workWith . '/' . MFFNAME . $sdisub . MFFDEXT;
  83. if (file_exists($fmff))
  84. {
  85. if (($mfContents = @fgc($fmff)))
  86. {
  87. set_time_limit(120); // for analyzing the manifest file
  88. $xht_doc = new xmddoc(explode("\n", $mfContents));
  89. if (!$xht_doc->error) return ''; // keeping $mfContents and $xht_doc
  90. unset($mfContents);
  91. return get_lang('ManifestSyntax') . ' ' . htmlspecialchars($xht_doc->error, ENT_QUOTES, $charset);
  92. }
  93. else
  94. {
  95. return get_lang('EmptyManifest');
  96. }
  97. }
  98. else
  99. {
  100. return get_lang('NoManifest');
  101. }
  102. }
  103. if (isset($workWith)) // now checked to be a valid path in scormdocument
  104. {
  105. if ($mdObj->mdo_filetype == 'folder') // a folder with a manifest?
  106. {
  107. if (($errmsg = slurpmanifest())) $hdrInfo .= ' ' . $errmsg;
  108. }
  109. else
  110. {
  111. $hdrInfo .= ' ' . get_lang('NotFolder'); unset($sdi);
  112. }
  113. }
  114. $mdObj->mdo_add_breadcrump_nav(); // see 'md_' . EID_TYPE . '.php'
  115. if (isset($sdi)) $interbreadcrumb[]= array(
  116. 'url' => api_get_self() . '?sdi=' . urlencode($sdi) .
  117. ($sdisub ? '&sdisub=' . urlencode($sdisub) :
  118. ($sdiall ? '&sdisub='.UZYX : '')),
  119. 'name'=> get_lang('Continue') . ' ' . $sdi .
  120. ($sdisub ? ' (' . $sdisub . ')' : ($sdiall ? ' ('.UZYX.')' : '')));
  121. $htmlHeadXtra[] = '
  122. <link rel="stylesheet" type="text/css" href="md_styles.css">
  123. <script type="text/javascript" src="md_script.js"></script>
  124. ';
  125. Display::display_header($nameTools);
  126. // OPERATIONS ----------------------------------------------------------------->
  127. if (isset($smo)) echo '<h3>', $smo, '</h3>', "\n"; // selected manifest op
  128. if (isset($smo))
  129. if ($smo == get_lang('UploadMff'))
  130. {
  131. if (is_uploaded_file($filespec = $_FILES['import_file']['tmp_name']) &&
  132. filesize($filespec) && ($myFile = @fopen($filespec, 'r')))
  133. {
  134. fclose($myFile);
  135. if (move_uploaded_file($filespec,
  136. $baseWorkDir . $workWith . '/' . MFFNAME . $sdisub . MFFDEXT))
  137. {
  138. echo get_lang('MffOk'); $hdrInfo = $originalHdrInfo;
  139. if (($errmsg = slurpmanifest())) $hdrInfo .= ' ' . $errmsg;
  140. }
  141. else echo get_lang('MffNotOk');
  142. }
  143. else echo get_lang('MffFileNotFound');
  144. }
  145. elseif ($smo == get_lang('UploadHtt'))
  146. {
  147. $filespec = $_FILES['import_file']['tmp_name'];
  148. if (is_uploaded_file($filespec) && filesize($filespec) && ($myFile = @fopen($filespec, 'r')))
  149. {
  150. fclose($myFile);
  151. $htt_file = $baseWorkDir .'/'. $workWith . '/' . HTF;
  152. if (move_uploaded_file($filespec,$htt_file))
  153. {
  154. echo get_lang('HttOk');
  155. }
  156. else
  157. {
  158. echo get_lang('HttNotOk');
  159. }
  160. }
  161. else
  162. {
  163. echo get_lang('HttFileNotFound');
  164. }
  165. }
  166. elseif ($smo == get_lang('RemoveHtt'))
  167. {
  168. @unlink($fhtf = $baseWorkDir . $workWith . '/' . HTF);
  169. if (file_exists($fhtf))
  170. echo get_lang('HttRmvNotOk');
  171. else echo get_lang('HttRmvOk');
  172. }
  173. elseif ($smo == get_lang('Import'))
  174. {
  175. define('TREETOP', 'organizations/organization');
  176. define('TITLE', 'title');
  177. define('SUBITEM', 'item');
  178. define('IDENTIF', 'identifier');
  179. define('ITEMID', '@'.IDENTIF);
  180. define('SUBIT', SUBITEM.'/'.ITEMID);
  181. define('RESOURCE', 'resources/resource');
  182. define('WHERE', ITEMID);
  183. define('ISITEM', '@identifierref');
  184. define('HREF', 'href');
  185. define('WEBF', '@'.HREF);
  186. define('FILE', 'file');
  187. define('THUMB', FILE.'[1]/'.WEBF);
  188. function resource_for($elem)
  189. {
  190. global $xht_doc;
  191. $resForItem = $xht_doc->xmd_select_elements_where(RESOURCE,
  192. WHERE, $xht_doc->xmd_value(ISITEM, $elem));
  193. return (count($resForItem) == 0) ? -1 : $resForItem[0];
  194. }
  195. function store_md_and_traverse_subitems($mfdocId, $level, $counter,
  196. $contextElem, $treeElem, $parentElem)
  197. {
  198. global $_user, $xht_doc, $mdStore, $mdObj, $sdisub;
  199. // $contextElem -> @identifier, metadata/lom
  200. // $treeElem -> title, items
  201. $itemId = $xht_doc->xmd_value(ITEMID, $contextElem);
  202. if ($sdisub && $level == 1 && $sdisub != $itemId) return;
  203. // <item level=... number=... identifier=...>:
  204. // <title>...</title>
  205. // <parent identifier=... /> <previous ... /> <next ... />
  206. // <child identifier=... /> <child identifier=... /> ...
  207. // <resource href=...>
  208. // <file href=... /> <file href=... /> ...
  209. // </resource>
  210. // <metadata>...</metadata>
  211. // </item>
  212. set_time_limit(30); // again 30 seconds from here on...
  213. $mddoc = new xmddoc('<item/>'); // version, name ?
  214. $mddoc->xmd_set_attribute(0, 'level', $level, FALSE);
  215. $mddoc->xmd_set_attribute(0, 'number', $counter, FALSE);
  216. $mddoc->xmd_set_attribute(0, IDENTIF, $itemId, FALSE);
  217. if ($level == 0)
  218. {
  219. $mddoc->xmd_set_attribute(0, 'created', date('Y/m/d H:i:s'), FALSE);
  220. $mddoc->xmd_set_attribute(0, 'by', $_user['user_id'], FALSE);
  221. }
  222. $mddoc->xmd_add_text_element(TITLE,
  223. $xht_doc->xmd_value(TITLE, $treeElem));
  224. if (($ppnId = $xht_doc->xmd_value(ITEMID, $parentElem))) $mddoc->
  225. xmd_add_element('parent', 0, array(IDENTIF => $ppnId));
  226. if (($ppnId = $xht_doc->xmd_value('-'.SUBIT, $treeElem))) $mddoc->
  227. xmd_add_element('previous', 0, array(IDENTIF => $ppnId));
  228. if (($ppnId = $xht_doc->xmd_value('+'.SUBIT, $treeElem))) $mddoc->
  229. xmd_add_element('next', 0, array(IDENTIF => $ppnId));
  230. if (($srcElem = resource_for($treeElem)) > 0)
  231. {
  232. // change stuff below to xmd_copy_foreign_child ?
  233. $resElem = $mddoc->xmd_add_element('resource', 0,
  234. array(HREF => $xht_doc->xmd_value(WEBF, $srcElem)));
  235. foreach ($xht_doc->xmd_select_elements(FILE, $srcElem) as $fileElem)
  236. $mddoc->xmd_add_element(FILE, $resElem,
  237. array(HREF => $xht_doc->xmd_value(WEBF, $fileElem)));
  238. }
  239. $mddoc->xmd_copy_foreign_child($xht_doc,
  240. $xht_doc->xmd_select_single_element('metadata', $contextElem));
  241. foreach ($xht_doc->xmd_select_elements(SUBITEM, $treeElem) as $subElem)
  242. $mddoc->xmd_add_element('child', 0,
  243. array(IDENTIF => $xht_doc->xmd_value(ITEMID, $subElem)));
  244. $mdt = $mddoc->xmd_xml();
  245. $xhtDoc = $mdObj->mdo_define_htt();
  246. $xhtDoc->xht_xmldoc = $mddoc; // $xhtDoc->xht_param['xxx'] = 'yyy';
  247. $mdStore->mds_put($eid = EID_TYPE . '.' . $mfdocId . '.' . $itemId,
  248. $mdt, 'mdxmltext', '?');
  249. $mdStore->mds_put($eid, $ixt =
  250. $xhtDoc->xht_fill_template('INDEXABLETEXT'), 'indexabletext');
  251. if ($level == 0) // store a copy as 'Scorm.nnn'
  252. {
  253. $mdStore->mds_put(EID_TYPE . '.' . $mfdocId, $mdt, 'mdxmltext', '?');
  254. $mdStore->mds_put(EID_TYPE . '.' . $mfdocId, $ixt, 'indexabletext');
  255. }
  256. echo $level <= 1 ? '<br />'.$level.'/ ' : ' ', htmlspecialchars($itemId, ENT_QUOTES, $charset);
  257. flush(); $loopctr = 0;
  258. foreach ($xht_doc->xmd_select_elements(SUBITEM, $treeElem) as $subElem)
  259. {
  260. store_md_and_traverse_subitems($mfdocId, $level + 1, ++$loopctr,
  261. $subElem, $subElem, $contextElem);
  262. // note: replacing this recursion by queue+loop makes it slower!
  263. }
  264. }
  265. function content_for_index_php($scid)
  266. {
  267. // 'if {}' and 'else {}' are string literals spanning several lines
  268. return '<?php' .
  269. '
  270. // This PHP file has been generated by metadata/importmanifest.php
  271. if (isset($_GET["th"]) && ($th = str_replace("..", "",
  272. get_magic_quotes_gpc() ? stripslashes($_GET["th"]) : $_GET["th"])))
  273. {
  274. if (strtolower(substr($th, -4)) != ".jpg") exit; // other ext?
  275. $thf = $_SERVER["PHP_SELF"];
  276. if(!is_file($thf = $_SERVER["DOCUMENT_ROOT"] .
  277. substr($thf, 0, strrpos($thf, "/")) . "/" . $th)) exit;
  278. header("Content-disposition: filename=".basename($th));
  279. header("Content-Type: image/jpeg");
  280. header("Expires: ".gmdate("D, d M Y H:i:s",time()+10)." GMT");
  281. header("Last-Modified: ".gmdate("D, d M Y H:i:s",time()+10)." GMT");
  282. $fp = fopen($thf, "rb"); fpassthru($fp); fclose($fp);
  283. }
  284. '
  285. . str_replace('<SYS_PATH-placeholder>', api_get_path(SYS_PATH),
  286. str_replace('<scid>', $scid, // 2 * replace in $drs-line below
  287. '
  288. else
  289. {
  290. $drs = "<SYS_PATH-placeholder>"; $scormid = "<scid>";
  291. require($drs. "main/metadata/playscormmdset.inc.php");
  292. }
  293. ' )) . '?' . '>';
  294. }
  295. if ($mfContents)
  296. {
  297. if ($sdiall)
  298. {
  299. foreach ($sdiall as $sdisub)
  300. {
  301. if (($errmsg = slurpmanifest()))
  302. echo '? ', $sdisub, ': ', $errmsg, '<br>';
  303. else
  304. store_md_and_traverse_subitems($sdi, 0, 1, 0,
  305. $xht_doc->xmd_select_single_element(TREETOP), -1);
  306. }
  307. $sdisub = '';
  308. }
  309. else // just once, slurpmanifest() has already been done
  310. store_md_and_traverse_subitems($sdi, 0, 1, 0,
  311. $xht_doc->xmd_select_single_element(TREETOP), -1);
  312. $playIt = $baseWorkDir .'/'. $workWith . '/index.php';
  313. $fileHandler = @fopen($playIt, 'w');
  314. @fwrite($fileHandler, content_for_index_php($sdi));
  315. @fclose($fileHandler);
  316. echo '<br>', htmlspecialchars($workWith, ENT_QUOTES, $charset);
  317. if (file_exists($playIt)) echo '/index.php ',
  318. htmlspecialchars(date('Y/m/d H:i:s', filemtime($playIt)), ENT_QUOTES, $charset);
  319. }
  320. }
  321. elseif ($smo == get_lang('Remove') && $sdisub)
  322. {
  323. $screm = EID_TYPE . '.' . $sdi . '.' . $sdisub;
  324. $mdStore->mds_delete_offspring($screm, '\_'); // SQL LIKE underscore
  325. echo htmlspecialchars($screm . '_*: ' . Database::affected_rows(), ENT_QUOTES, $charset), '<br />';
  326. }
  327. elseif ($smo == get_lang('Remove')) // remove all, regardless of $sdiall
  328. {
  329. $mdStore->mds_delete($screm = EID_TYPE . '.' . $sdi);
  330. echo htmlspecialchars($screm . ': ' . Database::affected_rows(), ENT_QUOTES, $charset), '<br />';
  331. $mdStore->mds_delete_offspring($screm);
  332. echo htmlspecialchars($screm . '.*: ' . Database::affected_rows(), ENT_QUOTES, $charset), '<br /><br />',
  333. '<b>' . get_lang('AllRemovedFor') . ' ' . $screm . '</b><br />';
  334. }
  335. elseif ($smo == get_lang('Index') && file_exists($phpDigIncCn) &&
  336. ereg('^http://([^/]+)/(.+)/index\.php$', $mdObj->mdo_url, $regs))
  337. {
  338. $result = $mdStore->mds_get_many('eid,mdxmltext,indexabletext',
  339. "eid LIKE '" . EID_TYPE . "." . $sdi .
  340. ($sdisub ? "." . $sdisub . "\_%'" : ".%'") .
  341. ($sdiall ? "" : " AND NOT INSTR(eid,'_')")); // SQL LIKE underscore
  342. while ($row = Database::fetch_array($result)) // load indexabletexts in memory
  343. {
  344. // URL: index.php[?sid=xxx[&thumb=yyy]] (file[1]/@href: pptslnnn_t.jpg)
  345. $th = ''; $indtxt = $row['indexabletext'];
  346. if (($fh = strpos($rx = $row['mdxmltext'], 'file href="')) !== FALSE)
  347. if (($cq = strpos($rx, '"', $fh += 11)) !== FALSE)
  348. if (ereg('^pptsl[0-9]+_t\.jpg$', $thwf = substr($rx, $fh, $cq - $fh)))
  349. $th = '&thumb=' . urlencode($thwf);
  350. if ($th == '' && ($sclvl = strpos($indtxt, 'scorm-level-')) !== FALSE)
  351. $th = '&thumb=scorm-level-' . $indtxt{$sclvl + 12} . '.jpg';
  352. $idt[($dotpos = strpos($ri = $row['eid'], '.', TPLEN)) !== FALSE ?
  353. ('index.php?sid=' . urlencode(substr($ri, $dotpos+1)) . $th) :
  354. 'index.php'] = $indtxt;
  355. }
  356. require($phpDigIncCn); // switch to PhpDig DB
  357. if (($site_id = remove_engine_entries('http://' . $regs[1] .'/', $path =
  358. $regs[2] . '/', $sdisub ? 'index.php?sid=' . $sdisub . '_' : '')))
  359. {
  360. echo '<table>', "\n";
  361. foreach ($idt as $url => $text)
  362. {
  363. set_time_limit(30); // again 30 seconds from here on...
  364. index_words($site_id, $path, $url,
  365. get_first_words($text, $path, $url), get_keywords($text));
  366. }
  367. echo '</table>', "\n";
  368. }
  369. // possible enhancement: UPDATE spider record for still existing pages
  370. if(isset($db)) mysql_select_db($_configuration['main_database'], $db); // back to Dokeos
  371. }
  372. elseif ($smo == get_lang('Index'))
  373. {
  374. echo 'Problem! PhpDig connect.php has gone or else URL "' .
  375. htmlspecialchars($mdObj->mdo_url, ENT_QUOTES, $charset) .
  376. '" is not like "http://xxxx/yyy.../zzz/index.php"';
  377. }
  378. // STATISTICS ----------------------------------------------------------------->
  379. echo '<h3>', get_lang('Statistics'), '</h3>', "\n";
  380. $result = $mdStore->mds_get_many('eid', "eid LIKE '" . EID_TYPE . ".%'");
  381. echo get_lang('TotalMDEs'), Database::num_rows($result), "\n";
  382. while ($row = Database::fetch_array($result))
  383. {
  384. $eid_id = substr($eid = $row['eid'], TPLEN);
  385. if (($dotpos = strpos($eid_id, '.')))
  386. $eid_id = substr($eid_id, 0, $dotpos);
  387. else
  388. $mdtmain[$eid_id] = $mdStore->mds_get($eid);
  389. $perId[$eid_id] = ($pi = $perId[$eid_id]) ? $pi + 1 : 1;
  390. }
  391. if (isset($sdi))
  392. {
  393. $mdo = new mdobject($_course, $sdi);
  394. echo '<br />', htmlspecialchars($mdo->mdo_path, ENT_QUOTES, $charset), ', SD-id ', $sdi, ': ',
  395. ($perId[$sdi] ? $perId[$sdi] : '0'), ' ',
  396. ($mdtmain[$sdi] ? '- <span class="lbs" onClick="' .
  397. "makeWindow('index.php?eid=" . EID_TYPE . '.' .$sdi . "', '', '')\">" .
  398. get_lang('MainMD') . '</span>' : ''), "\n";
  399. }
  400. if (count($perId))
  401. {
  402. foreach ($perId as $id => $number)
  403. {
  404. $mdo = new mdobject($_course, $id);
  405. if (!($pth = $mdo->mdo_path))
  406. {
  407. $pth = $mdtmain[$id]; // fetch something simple without parsing
  408. if ($ttopen = strpos($pth, '<title>'))
  409. if ($ttclose = strpos($pth, '</title>', $ttopen))
  410. $pth = ' ' . api_html_entity_decode
  411. (substr($pth, $ttopen+7, $ttclose-$ttopen-7), ENT_QUOTES, $charset);
  412. else $pth = ' ' . substr($pth, $ttopen+7, 30);
  413. else $pth = ' ' . substr($pth, 0, 30);
  414. }
  415. $pathId[$pth] = $id;
  416. }
  417. echo '<br><br><table>', "\n"; ksort($pathId); $wwl = strlen($workWith);
  418. foreach ($pathId as $pth => $id) if ($wwl == 0 ||
  419. ($wwl < strlen($pth) && substr($pth, 0, $wwl) == $workWith))
  420. {
  421. $tmfdt = file_exists($tfmff = $baseWorkDir . $pth . '/' . MFFNAME . $sdisub . MFFDEXT) ?
  422. date('Y/m/d H:i:s', filemtime($tfmff)) : '-';
  423. echo '<tr><td>', htmlspecialchars($tmfdt, ENT_QUOTES, $charset), '</td>',
  424. '<td>', htmlspecialchars($pth, ENT_QUOTES, $charset),
  425. '</td><td align="right">(SD-id ', $id,
  426. '):</td><td align="right">', $perId[$id], '</td></tr>', "\n";
  427. }
  428. echo '</table>', "\n";
  429. }
  430. if ($mfContents)
  431. {
  432. echo $workWith, '/', MFFNAME . $sdisub . MFFDEXT, ': ',
  433. htmlspecialchars(date('Y/m/d H:i:s', filemtime($fmff)), ENT_QUOTES, $charset) , ", \n",
  434. substr_count($mfContents, "\n") + 1,
  435. ' ' . get_lang('Lines') . '.', "\n";
  436. if (!$sdisub && ($dh = opendir($baseWorkDir . $workWith)))
  437. {
  438. $nsplit = array();
  439. while (FALSE !== ($file = readdir($dh)))
  440. if (ereg('^'.MFFNAME.'(.+)\\'.MFFDEXT .'$', $file, $regs))
  441. {
  442. $nsplit []= $regs[1];
  443. }
  444. closedir($dh);
  445. if (count($nsplit))
  446. {
  447. echo '<br>', get_lang('SplitData'); sort($nsplit);
  448. foreach ($nsplit as $ns)
  449. {
  450. $result = $mdStore->mds_get_many('eid', "eid LIKE '" .
  451. EID_TYPE . "." . $sdi . "." . $ns . "\_%'");
  452. $nns = Database::num_rows($result);
  453. echo $ns, $nns ? '_ ' . $nns : '', '; ';
  454. }
  455. echo '<br>';
  456. }
  457. }
  458. }
  459. if (file_exists($baseWorkDir . $workWith . '/index.php'))
  460. echo "<span class=\"lbs\" onClick=\"makeWindow('" .
  461. $mdObj->mdo_url . "', '', '')\">" . get_lang('Play'), '</span>', "\n";
  462. if (file_exists($fhtf = $baseWorkDir . $workWith . '/' . HTF))
  463. echo '<br>', $workWith, '/', HTF, ': ',
  464. htmlspecialchars(date('Y/m/d H:i:s', filemtime($fhtf)), ENT_QUOTES, $charset) , "\n";
  465. // SELECT & FOOTER ------------------------------------------------------------>
  466. if ($mfContents || $xht_doc->error)
  467. {
  468. echo '<h3>', get_lang('UploadMff'), "</h3>\n\n",
  469. '<form action="' .api_get_self(). '?sdi=' . urlencode($sdi) .
  470. ($sdisub ? '&sdisub=' . urlencode($sdisub) : ($sdiall ? '&sdisub='.UZYX : '')) .
  471. '" enctype="multipart/form-data" method="post">', "\n",
  472. '<input type="hidden" name="MAX_FILE_SIZE" value="32768">', "\n",
  473. '<input type="file" name="import_file" size="30">', "\n",
  474. '<input type="submit" name="smo" value="', get_lang('UploadMff'),
  475. '">' . "\n</form>\n";
  476. }
  477. echo '<h3>', get_lang('UploadHtt'), file_exists($fhtf) ?
  478. (' + ' . get_lang('RemoveHtt')) : '', "</h3>\n\n",
  479. '<form action="' .api_get_self(). '?sdi=' . urlencode($sdi) .
  480. ($sdisub ? '&sdisub=' . urlencode($sdisub) : ($sdiall ? '&sdisub='.UZYX : '')) .
  481. '" enctype="multipart/form-data" method="post">', "\n",
  482. '<input type="hidden" name="MAX_FILE_SIZE" value="32768">', "\n",
  483. '<input type="file" name="import_file" size="30">', "\n",
  484. '<input type="submit" name="smo" value="', get_lang('UploadHtt'), '">';
  485. if (file_exists($fhtf)) echo
  486. '<input type="submit" name="smo" value="', get_lang('RemoveHtt'), '">';
  487. echo "\n</form>\n";
  488. echo '<h3>', $nameTools, $hdrInfo, '</h3>', "\n";
  489. if ($mfContents || $perId[$sdi]) // buttons for manifest operations
  490. {
  491. echo '<form action="' .api_get_self(). '?sdi=' . urlencode($sdi) .
  492. ($sdisub ? '&sdisub=' . urlencode($sdisub) : ($sdiall ? '&sdisub='.UZYX : '')) .
  493. '" method="post">', "\n";
  494. if ($mfContents) echo
  495. '<input type="submit" name="smo" value="', get_lang('Import'), '">', "\n";
  496. if ($perId[$sdi]) echo
  497. '<input type="submit" name="smo" value="', get_lang('Remove'), '">', "\n";
  498. if ($mfContents && $perId[$sdi] && file_exists($phpDigIncCn)) echo
  499. '<input type="submit" name="smo" value="', get_lang('Index'), '">', "\n";
  500. echo
  501. '</form>', "\n";
  502. }
  503. else
  504. {
  505. echo '(', get_lang('NonePossible'), '...)';
  506. }
  507. function showSelectForm($label, $specifics)
  508. {
  509. echo '<tr><td align="right" class="alternativeBgDark">', "\n",
  510. '<form action="', api_get_self(), '" method="post">', "\n",
  511. get_lang($label), ' :', "\n", $specifics, "\n",
  512. '<input type="submit" value="', ' '.get_lang('Ok').' ', '" />', "\n",
  513. '</form></td></tr>', "\n";
  514. }
  515. echo '<h3>', get_lang('OrElse'), '</h3>', "\n<table>\n";
  516. $specifics = '<select name="workWith">' . "\n" .
  517. '<option value="" style="color:#999999">' . get_lang('Root') . "</option>\n";
  518. if (($dirList = index_and_sort_dir($baseWorkDir))) // fileManage.lib
  519. {
  520. $someDirs = array();
  521. foreach ($dirList as $pathValue)
  522. $someDirs[$pathValue] = file_exists($pathValue. '/'. MFFNAME. MFFDEXT);
  523. foreach ($someDirs as $pathValue => $mfExists) if ($mfExists)
  524. {
  525. while (($i = strrpos($pathValue, '/')))
  526. {
  527. $pathValue = substr($pathValue, 0, $i);
  528. if (!array_key_exists($pathValue, $someDirs)) break;
  529. $someDirs[$pathValue] = TRUE;
  530. }
  531. }
  532. $bwdL = strlen($baseWorkDir);
  533. foreach ($someDirs as $pathValue => $mfExists) if ($mfExists)
  534. {
  535. $pathValue = substr($pathValue, $bwdL);
  536. $specifics .= '<option value="' . $pathValue . '"' .
  537. ($pathValue == $workWith ? ' selected' : '') . '>' .
  538. str_repeat('&nbsp;&nbsp;', substr_count($pathValue, '/')) . '>' .
  539. basename($pathValue) . '</option>' . "\n";
  540. }
  541. }
  542. showSelectForm('WorkWith', $specifics . '</select>');
  543. showSelectForm('SDI',
  544. '<input type="text" size="5" name="sdi" value="' .
  545. htmlspecialchars($sdi) . '" />' .
  546. '(<input type="text" size="4" name="sdisub" value="' .
  547. ($sdiall ? UZYX : htmlspecialchars($sdisub, ENT_QUOTES, $charset)) . '" />)' . "\n");
  548. echo '</table>', "\n";
  549. Display::display_footer();
  550. ?>