index.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <?php /* <!-- Dokeos metadata/index.php -->
  2. <!-- 2005/05/19 -->
  3. <!-- Copyright (C) 2005 rene.haentjens@UGent.be - see metadata/md_funcs.php -->
  4. */
  5. /**
  6. ==============================================================================
  7. * Dokeos Metadata: view/edit metadata of a Dokeos course object
  8. *
  9. * URL parameters:
  10. * - eid= entry-id = object-id = type.identifier, e.g. 'Document.12';
  11. * - lfn= filename of a language file, default= 'md_' + type, e.g. 'md_doc';
  12. * - htt= HTML template file (same dir as script), default= same as lfn;
  13. * - dbg= debuginfo start number, e.g. 10000
  14. *
  15. * @package dokeos.metadata
  16. ==============================================================================
  17. */
  18. // PRELIMS -------------------------------------------------------------------->
  19. require("md_funcs.php");
  20. getpar('EID', 'Entry IDentifier'); // e.g. 'Document.12' or 'Scorm.xx'
  21. if (!($dotpos = strpos(EID, '.'))) give_up('No . in ' . EID);
  22. define('EID_TYPE', substr(EID, 0, $dotpos)); // e.g. 'Document' or 'Scorm'
  23. require('md_' . strtolower(EID_TYPE) . '.php');
  24. define('EID_ID', substr(EID, $dotpos + 1)); // e.g. '12'
  25. getpar('LFN', 'LanguageFileName', 'md_' . strtolower(EID_TYPE));
  26. getpar('HTT', 'HTML Template Text filename', LFN);
  27. getpar('DBG', 'Debug number', '0');
  28. $urlp = '?eid=' . urlencode(EID);
  29. if (LFN != 'md_' . strtolower(EID_TYPE)) $urlp .= '&lfn=' . urlencode(LFN);
  30. if (HTT != LFN) $urlp .= '&htt=' . urlencode(HTT);
  31. if (DBG) $urlp .= '&dbg=' . urlencode(DBG);
  32. // name of the language file that needs to be included
  33. $language_file = LFN;
  34. require("../inc/global.inc.php");
  35. $this_section=SECTION_COURSES;
  36. $nameTools = get_lang('Tool');
  37. ($nameTools && get_lang('Sorry'))
  38. or give_up('Language file ' . LFN . " doesn't define 'Tool' and 'Sorry'");
  39. $_course = api_get_course_info(); isset($_course) or give_up(get_lang('Sorry'));
  40. require(api_get_path(LIBRARY_PATH) . 'xmd.lib.php');
  41. require(api_get_path(LIBRARY_PATH) . 'xht.lib.php');
  42. $mdObj = new mdobject($_course, EID_ID); // see 'md_' . EID_TYPE . '.php'
  43. // Construct assoclist $langLangs from language table ------------------------->
  44. $result = api_sql_query("SELECT isocode FROM " .
  45. Database :: get_main_table(TABLE_MAIN_LANGUAGE) .
  46. " WHERE available='1' ORDER BY isocode ASC", __FILE__, __LINE__);
  47. $sep = ":"; $langLangs = $sep . "xx" . $sep . "xx";
  48. while ($row = mysql_fetch_array($result))
  49. if (($isocode = $row['isocode']))
  50. $langLangs .= ",, " . $isocode . $sep . $isocode;
  51. // XML and DB STUFF ----------------------------------------------------------->
  52. $is_allowed_to_edit = isset($_user['user_id']) && $is_courseMember && is_allowed_to_edit();
  53. $mdStore = new mdstore($is_allowed_to_edit);
  54. if (($mdt_rec = $mdStore->mds_get(EID)) === FALSE) // no record, default XML
  55. $mdt = $mdObj->mdo_generate_default_xml_metadata();
  56. else $mdt = $mdt_rec;
  57. $xhtxmldoc = new xmddoc(explode("\n", $mdt));
  58. $httfile = ($xhtxmldoc->error) ? 'md_editxml.htt' : HTT . '.htt';
  59. if (!$xhtxmldoc->error && $mdt_rec !== FALSE &&
  60. method_exists($mdObj, 'mdo_override'))
  61. $mdt = $mdObj->mdo_override($xhtxmldoc);
  62. $xhtDoc = define_htt($httfile, $urlp, $_course['path']);
  63. define('HSH', md5($mdt . LFN . $nameTools . get_lang('Sorry') . $httfile .
  64. implode('{}', $xhtDoc->htt_array))); // cached HTML depends on LFN+HTT
  65. $xhtDoc->xht_param['traceinfo'] = $xhtxmldoc->error;
  66. $xhtDoc->xht_param['dbrecord'] = $mdt_rec !== FALSE ? 'TRUE' : '';
  67. $xhtDoc->xht_xmldoc = $xhtxmldoc;
  68. if ($is_allowed_to_edit) $xhtDoc->xht_param['isallowedtoedit'] = 'TRUE';
  69. if ($is_allowed_to_edit && isset($_POST['mda'])) // MD updates to Doc and DB
  70. {
  71. $mdt = $mdStore->mds_update_xml_and_mdt($mdObj, $xhtDoc->xht_xmldoc,
  72. get_magic_quotes_gpc() ? stripslashes($_POST['mda']) : $_POST['mda'],
  73. EID, $xhtDoc->xht_param['traceinfo'], $mdt_rec !== FALSE);
  74. if ($mdt_rec !== FALSE)
  75. {
  76. if (strpos($xhtDoc->xht_param['traceinfo'], 'DELETE') !== FALSE)
  77. $xhtDoc->xht_param['dbrecord'] = '';
  78. }
  79. else if (strpos($xhtDoc->xht_param['traceinfo'], 'INSERT') !== FALSE)
  80. $xhtDoc->xht_param['dbrecord'] = 'TRUE';
  81. if (method_exists($mdObj, 'mdo_storeback'))
  82. $mdObj->mdo_storeback($xhtDoc->xht_xmldoc);
  83. $mdt_rec = FALSE; // cached HTML obsolete, must re-apply templates
  84. }
  85. elseif ($is_allowed_to_edit && $_POST['mdt']) // md_editxml.htt
  86. {
  87. $mdStore->mds_put(EID,
  88. get_magic_quotes_gpc() ? stripslashes($_POST['mdt']) : $_POST['mdt'],
  89. 'mdxmltext', '?');
  90. $mdStore->mds_put(EID, HSH, 'md5');
  91. $xhtDoc->xht_param['dbrecord'] = 'TRUE';
  92. $mdt = ''; $xhtDoc->xht_param['traceinfo'] = get_lang('PressAgain');
  93. $mdt_rec = FALSE; // cached HTML obsolete, must re-apply templates
  94. }
  95. $xhtDoc->xht_param['mdt'] = $mdt;
  96. define('CACHE_IS_VALID', isset($mdt_rec) && $mdt_rec !== FALSE &&
  97. HSH && HSH == $mdStore->mds_get(EID, 'md5'));
  98. function md_part($part, $newtext) // callback from template (HTML cache in DB)
  99. {
  100. global $mdStore;
  101. if ($newtext === FALSE)
  102. {
  103. if (!CACHE_IS_VALID) return FALSE;
  104. return '<!-- ' . $part . ' -->' . $mdStore->mds_get(EID, $part);
  105. }
  106. else
  107. {
  108. $mdStore->mds_put(EID, HSH, 'md5');
  109. $mdStore->mds_put(EID, $newtext, $part);
  110. return $newtext;
  111. }
  112. }
  113. function md_part1($newtext) { return md_part('htmlcache1', $newtext); }
  114. function md_part2($newtext) { return md_part('htmlcache2', $newtext); }
  115. function md_indexabletext($newtext) { return md_part('indexabletext', $newtext); }
  116. // GENERATE OUTPUT ------------------------------------------------------------>
  117. foreach (explode("\n", $xhtDoc->htt_array['HTTP']) as $httpXtra)
  118. if ($httpXtra) $httpHeadXtra[] = $httpXtra;
  119. $xhtDoc->xht_get_lang = 'get_lang';
  120. function resource_for($e) {return $e;} // dummy, '=/' not used here
  121. $xhtDoc->xht_resource = 'resource_for';
  122. $htmlHeadXtra[] = $xhtDoc->xht_fill_template('HEAD');
  123. $mdObj->mdo_add_breadcrump_nav(); // see 'md_' . EID_TYPE . '.php'
  124. $noPHP_SELF = TRUE; // in breadcrumps
  125. Display::display_header($nameTools); echo "\n";
  126. $xhtDoc->xht_dbgn = DBG; // for template debug info, set to e.g. 10000
  127. if (($ti = $xhtDoc->xht_param['traceinfo'])) $xhtDoc->xht_param['traceinfo'] =
  128. '<h5>Trace information</h5>' . htmlspecialchars($ti);
  129. echo $xhtDoc->xht_fill_template('METADATA'), "\n";
  130. if ($xhtDoc->xht_dbgn) echo $xhtDoc->xht_dbgo;
  131. Display::display_footer();
  132. ?>