playscormmdset.inc.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <?php
  2. /**
  3. * Chamilo metadata/playscormmdset.inc.php
  4. * 2005/11/16
  5. * Copyright (C) 2005 rene.haentjens@UGent.be - see metadata/md_funcs.php
  6. * @package chamilo.metadata
  7. */
  8. /**
  9. * Chamilo Metadata: include file for accessing Scorm metadata
  10. * This script is to be included from /coursedir/scorm/dir.../index.php,
  11. * after setting $scormid (Chamilo document root).
  12. */
  13. // PRELIMS -------------------------------------------------------------------->
  14. if (!isset($scormid)) exit();
  15. define('EID_TYPE', 'Scorm');
  16. define('BID', EID_TYPE . '.' . $scormid);
  17. getpar('SID', 'Scorm sub-id', '*');
  18. define('EID_ID', (SID == '*') ? $scormid : $scormid . '.' . SID);
  19. define('EID', EID_TYPE . '.' . EID_ID);
  20. getpar('LFN', 'LanguageFileName', 'md_' . strtolower(EID_TYPE));
  21. getpar('HTT', 'HTML Template Text filename', 'mdp_' . strtolower(EID_TYPE));
  22. getpar('WHF', 'With Header and Footer', '0');
  23. define('DBG', 0); // for template debug info, set to e.g. 10000
  24. getpar('RNG', 'Slide range', '*');
  25. if (RNG == '*' || ($dotdot = strpos(RNG, '..')) === FALSE)
  26. $id_range_first = $id_range_last = '';
  27. else
  28. {
  29. $id_range_first = trim(substr(RNG, 0, $dotdot));
  30. $id_range_last = trim(substr(RNG, $dotdot + 2));
  31. }
  32. $urlp = '?dbg=' . urlencode(DBG);
  33. if (LFN != 'md_' . strtolower(EID_TYPE)) $urlp .= '&lfn=' . urlencode(LFN);
  34. if (HTT != 'mdp_' . strtolower(EID_TYPE)) $urlp .= '&lfn=' . urlencode(HTT);
  35. if (WHF != '0') $urlp .= '&whf=' . urlencode(WHF);
  36. if (RNG != '*') $urlp .= '&rng=' . urlencode(RNG);
  37. // name of the language file that needs to be included
  38. $language_file = LFN;
  39. require('../inc/global.inc.php');
  40. $nameTools = get_lang('Tool');
  41. require(api_get_path(SYS_CODE_PATH) . 'metadata/md_funcs.php');
  42. ($nameTools && get_lang('Sorry'))
  43. or give_up('Language file ' . LFN . " doesn't define 'Tool' and 'Sorry'");
  44. $_course = api_get_course_info(); isset($_course) or give_up(get_lang('Sorry'));
  45. require(api_get_path(LIBRARY_PATH) . 'xmd.lib.php');
  46. require(api_get_path(LIBRARY_PATH) . 'xht.lib.php');
  47. require(api_get_path(SYS_CODE_PATH) . 'metadata/md_' . strtolower(EID_TYPE) . '.php');
  48. $mdObj = new mdobject($_course, EID_ID);
  49. define('DR', $_SERVER['DOCUMENT_ROOT']);
  50. define('SELF', api_get_self());
  51. define('DIRECTORY', DR . $self = substr(SELF, 0, strrpos(SELF, '/')));
  52. if (!file_exists(DIRECTORY)) give_up('No such directory: ' . DIRECTORY);
  53. // TEMPLATES FILE ------------------------------------------------------------->
  54. $topdir = strtolower(realpath(DR)); // to stop search for .htt file
  55. if (strpos(strtolower(realpath(DIRECTORY)), $topdir) !== 0)
  56. give_up('Invalid directory: ' . DIRECTORY);
  57. chdir(DIRECTORY);
  58. for ($i = 0; $i < 10; $i++)
  59. if(!file_exists(HTT . '.htt'))
  60. if (strtolower(realpath(getcwd())) == $topdir) {break;}
  61. else chdir('..');
  62. // XML and DB STUFF ----------------------------------------------------------->
  63. $is_allowed_to_edit = isset($_user['user_id']) && $is_courseMember && api_is_allowed_to_edit();
  64. $mdStore = new mdstore($is_allowed_to_edit);
  65. if (($mdt_rec = $mdStore->mds_get(EID)) === FALSE) // no record, default XML
  66. $mdt = $mdObj->mdo_generate_default_xml_metadata();
  67. else $mdt = $mdt_rec;
  68. $xhtxmldoc = new xmddoc(explode("\n", $mdt));
  69. (!$xhtxmldoc->error) or give_up($xhtxmldoc->error);
  70. if (SID == $id_range_first &&
  71. ($prv = $xhtxmldoc->xmd_select_single_element('previous')) != -1)
  72. $xhtxmldoc->xmd_remove_element($prv);
  73. if (SID == $id_range_last &&
  74. ($nxt = $xhtxmldoc->xmd_select_single_element('next')) != -1)
  75. $xhtxmldoc->xmd_remove_element($nxt);
  76. $before_first = $id_range_first ? TRUE : FALSE; $after_last = FALSE;
  77. foreach ($xhtxmldoc->xmd_select_elements('child') as $chEl)
  78. {
  79. $chId = $xhtxmldoc->attributes[$chEl]['identifier']; // no get_att yet...
  80. if ($after_last ||
  81. ($before_first = $before_first && $chId != $id_range_first))
  82. {
  83. $xhtxmldoc->xmd_remove_element($chEl); continue;
  84. }
  85. if (($mdt_rec = $mdStore->mds_get(BID . '.' . $chId)) === FALSE)
  86. $mdt = $mdObj->mdo_generate_default_xml_metadata();
  87. else $mdt = $mdt_rec;
  88. $xhtxmldocchild = new xmddoc(explode("\n", $mdt));
  89. (!$xhtxmldocchild->error) or give_up($chId . ': ' . $xhtxmldocchild->error);
  90. // make stuff below a parameter? copy some already in importmanifest?
  91. $xhtxmldoc->xmd_copy_foreign_child($xhtxmldocchild,
  92. $xhtxmldocchild->xmd_select_single_element('title'), $chEl);
  93. $xhtxmldoc->xmd_copy_foreign_child($xhtxmldocchild,
  94. $xhtxmldocchild->xmd_select_single_element('resource'), $chEl);
  95. $after_last = $after_last || $chId == $id_range_last;
  96. }
  97. $xhtDoc = define_htt(HTT . '.htt', $urlp, $_course['path']);
  98. $xhtDoc->xht_xmldoc = $xhtxmldoc;
  99. $xhtDoc->xht_param['mdt'] = $xhtxmldoc->xmd_xml();
  100. // GENERATE OUTPUT ------------------------------------------------------------>
  101. foreach (explode("\n", $xhtDoc->htt_array['HTTP']) as $httpXtra)
  102. if ($httpXtra) $httpHeadXtra[] = $httpXtra;
  103. $xhtDoc->xht_get_lang = 'get_lang';
  104. function resource_for($e) {return $e;} // dummy, '=/' not used here
  105. $xhtDoc->xht_resource = 'resource_for';
  106. $htmlHeadXtra[] = $xhtDoc->xht_fill_template('HEAD');
  107. // $mdObj->mdo_add_breadcrump_nav(); // see 'md_' . EID_TYPE . '.php'
  108. $noPHP_SELF = TRUE; // in breadcrumps
  109. if (WHF != '0') Display::display_header($nameTools);
  110. else
  111. {
  112. header('Content-Type: text/html; charset='. $charset); $document_language = 'en';
  113. if ( isset($httpHeadXtra) && $httpHeadXtra )
  114. {
  115. foreach($httpHeadXtra as $thisHttpHead)
  116. {
  117. header($thisHttpHead);
  118. }
  119. }
  120. ?>
  121. <!DOCTYPE html
  122. PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  123. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  124. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $document_language; ?>" lang="<?php echo $document_language; ?>">
  125. <head>
  126. <title>Scorm package
  127. </title>
  128. <meta http-equiv="Content-Type" content="text/html; charset=<?php echo $charset; ?>">
  129. <link rel="stylesheet" href="<?php echo api_get_path(WEB_CODE_PATH); ?>css/default.css" type="text/css" media="screen,projection" />
  130. <style type="text/css" media="screen, projection">
  131. /*<![CDATA[*/
  132. @import "<?php echo api_get_path(WEB_CODE_PATH); ?>css/default.css";
  133. /*]]>*/
  134. </style>
  135. <?php
  136. if ( isset($htmlHeadXtra) && $htmlHeadXtra )
  137. {
  138. foreach($htmlHeadXtra as $this_html_head)
  139. {
  140. echo($this_html_head);
  141. }
  142. }
  143. ?>
  144. </head>
  145. <body dir="<?php echo $text_dir; ?>">
  146. <!-- #outerframe container to control some general layout of all pages -->
  147. <div id="outerframe">
  148. <?php
  149. }
  150. echo "\n";
  151. $xhtDoc->xht_dbgn = DBG; // for template debug info, set to e.g. 10000
  152. if (($ti = $xhtDoc->xht_param['traceinfo'])) $xhtDoc->xht_param['traceinfo'] =
  153. '<h5>Trace information</h5>' . htmlspecialchars($ti, ENT_QUOTES, $charset);
  154. echo $xhtDoc->xht_fill_template('METADATA'), "\n";
  155. if ($xhtDoc->xht_dbgn) echo $xhtDoc->xht_dbgo;
  156. if (WHF != '0')
  157. {
  158. Display::display_footer();
  159. exit;
  160. }
  161. ?>
  162. <div class="clear">&nbsp;</div> <!-- 'clearing' div to make sure that footer stays below the main and right column sections -->
  163. </div> <!-- end of #outerframe opened in header.inc.php -->
  164. </body>
  165. </html>