index.php 6.6 KB

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