index.php 6.3 KB

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