importmanifest.php 26 KB

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