importmanifest.php 24 KB

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