playscormmdset.inc.php 7.5 KB

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