playscormmdset.inc.php 7.4 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 and $drs (Dokeos document root).
  11. *
  12. * @package dokeos.metadata
  13. ==============================================================================
  14. */
  15. // PRELIMS -------------------------------------------------------------------->
  16. if (!isset($scormid)) exit(); if (!isset($drs)) exit();
  17. if (strpos($drs, '//') !== FALSE) exit();
  18. require($drs . 'main/metadata/md_funcs.php');
  19. define('EID_TYPE', 'Scorm');
  20. define('BID', EID_TYPE . '.' . $scormid);
  21. getpar('SID', 'Scorm sub-id', '*');
  22. define('EID_ID', (SID == '*') ? $scormid : $scormid . '.' . SID);
  23. define('EID', EID_TYPE . '.' . EID_ID);
  24. getpar('LFN', 'LanguageFileName', 'md_' . strtolower(EID_TYPE));
  25. getpar('HTT', 'HTML Template Text filename', 'mdp_' . strtolower(EID_TYPE));
  26. getpar('WHF', 'With Header and Footer', '0');
  27. define('DBG', 0); // for template debug info, set to e.g. 10000
  28. getpar('RNG', 'Slide range', '*');
  29. if (RNG == '*' || ($dotdot = strpos(RNG, '..')) === FALSE)
  30. $id_range_first = $id_range_last = '';
  31. else
  32. {
  33. $id_range_first = trim(substr(RNG, 0, $dotdot));
  34. $id_range_last = trim(substr(RNG, $dotdot + 2));
  35. }
  36. $urlp = '?dbg=' . urlencode(DBG);
  37. if (LFN != 'md_' . strtolower(EID_TYPE)) $urlp .= '&lfn=' . urlencode(LFN);
  38. if (HTT != 'mdp_' . strtolower(EID_TYPE)) $urlp .= '&lfn=' . urlencode(HTT);
  39. if (WHF != '0') $urlp .= '&whf=' . urlencode(WHF);
  40. if (RNG != '*') $urlp .= '&rng=' . urlencode(RNG);
  41. // name of the language file that needs to be included
  42. $language_file = LFN;
  43. require($drs . 'main/inc/global.inc.php');
  44. $nameTools = get_lang('Tool');
  45. ($nameTools && get_lang('Sorry'))
  46. or give_up('Language file ' . LFN . " doesn't define 'Tool' and 'Sorry'");
  47. $_course = api_get_course_info(); isset($_course) or give_up(get_lang('Sorry'));
  48. require(api_get_path(LIBRARY_PATH) . 'xmd.lib.php');
  49. require(api_get_path(LIBRARY_PATH) . 'xht.lib.php');
  50. require($drs . 'main/metadata/md_' . strtolower(EID_TYPE) . '.php');
  51. $mdObj = new mdobject($_course, EID_ID);
  52. define('DR', $_SERVER['DOCUMENT_ROOT']);
  53. define('SELF', $_SERVER['PHP_SELF']);
  54. define('DIRECTORY', DR . $self = substr(SELF, 0, strrpos(SELF, '/')));
  55. if (!file_exists(DIRECTORY)) give_up('No such directory: ' . DIRECTORY);
  56. // TEMPLATES FILE ------------------------------------------------------------->
  57. $topdir = strtolower(realpath(DR)); // to stop search for .htt file
  58. if (strpos(strtolower(realpath(DIRECTORY)), $topdir) !== 0)
  59. give_up('Invalid directory: ' . DIRECTORY);
  60. chdir(DIRECTORY);
  61. for ($i = 0; $i < 10; $i++)
  62. if(!file_exists(HTT . '.htt'))
  63. if (strtolower(realpath(getcwd())) == $topdir) {break;}
  64. else chdir('..');
  65. // XML and DB STUFF ----------------------------------------------------------->
  66. $is_allowed_to_edit = isset($_user['user_id']) && $is_courseMember && is_allowed_to_edit();
  67. $mdStore = new mdstore($is_allowed_to_edit);
  68. if (($mdt_rec = $mdStore->mds_get(EID)) === FALSE) // no record, default XML
  69. $mdt = $mdObj->mdo_generate_default_xml_metadata();
  70. else $mdt = $mdt_rec;
  71. $xhtxmldoc = new xmddoc(explode("\n", $mdt));
  72. (!$xhtxmldoc->error) or give_up($xhtxmldoc->error);
  73. if (SID == $id_range_first &&
  74. ($prv = $xhtxmldoc->xmd_select_single_element('previous')) != -1)
  75. $xhtxmldoc->xmd_remove_element($prv);
  76. if (SID == $id_range_last &&
  77. ($nxt = $xhtxmldoc->xmd_select_single_element('next')) != -1)
  78. $xhtxmldoc->xmd_remove_element($nxt);
  79. $before_first = $id_range_first ? TRUE : FALSE; $after_last = FALSE;
  80. foreach ($xhtxmldoc->xmd_select_elements('child') as $chEl)
  81. {
  82. $chId = $xhtxmldoc->attributes[$chEl]['identifier']; // no get_att yet...
  83. if ($after_last ||
  84. ($before_first = $before_first && $chId != $id_range_first))
  85. {
  86. $xhtxmldoc->xmd_remove_element($chEl); continue;
  87. }
  88. if (($mdt_rec = $mdStore->mds_get(BID . '.' . $chId)) === FALSE)
  89. $mdt = $mdObj->mdo_generate_default_xml_metadata();
  90. else $mdt = $mdt_rec;
  91. $xhtxmldocchild = new xmddoc(explode("\n", $mdt));
  92. (!$xhtxmldocchild->error) or give_up($chId . ': ' . $xhtxmldocchild->error);
  93. // make stuff below a parameter? copy some already in importmanifest?
  94. $xhtxmldoc->xmd_copy_foreign_child($xhtxmldocchild,
  95. $xhtxmldocchild->xmd_select_single_element('title'), $chEl);
  96. $xhtxmldoc->xmd_copy_foreign_child($xhtxmldocchild,
  97. $xhtxmldocchild->xmd_select_single_element('resource'), $chEl);
  98. $after_last = $after_last || $chId == $id_range_last;
  99. }
  100. $xhtDoc = define_htt(HTT . '.htt', $urlp, $_course['path']);
  101. $xhtDoc->xht_xmldoc = $xhtxmldoc;
  102. $xhtDoc->xht_param['mdt'] = $xhtxmldoc->xmd_xml();
  103. // GENERATE OUTPUT ------------------------------------------------------------>
  104. foreach (explode("\n", $xhtDoc->htt_array['HTTP']) as $httpXtra)
  105. if ($httpXtra) $httpHeadXtra[] = $httpXtra;
  106. $xhtDoc->xht_get_lang = 'get_lang';
  107. function resource_for($e) {return $e;} // dummy, '=/' not used here
  108. $xhtDoc->xht_resource = 'resource_for';
  109. $htmlHeadXtra[] = $xhtDoc->xht_fill_template('HEAD');
  110. // $mdObj->mdo_add_breadcrump_nav(); // see 'md_' . EID_TYPE . '.php'
  111. $noPHP_SELF = TRUE; // in breadcrumps
  112. if (WHF != '0') Display::display_header($nameTools);
  113. else
  114. {
  115. header('Content-Type: text/html; charset='. $charset); $document_language = 'en';
  116. if ( isset($httpHeadXtra) && $httpHeadXtra )
  117. {
  118. foreach($httpHeadXtra as $thisHttpHead)
  119. {
  120. header($thisHttpHead);
  121. }
  122. }
  123. ?>
  124. <!DOCTYPE html
  125. PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  126. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  127. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $document_language; ?>" lang="<?php echo $document_language; ?>">
  128. <head>
  129. <title>Scorm package
  130. </title>
  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);
  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>