search.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <?php
  2. /* See license terms in /license.txt */
  3. /**
  4. * Chamilo metadata/search.php
  5. * 2005/09/20
  6. * @copyright 2005 rene.haentjens@UGent.be - see metadata/md_funcs.php
  7. * @package chamilo.metadata
  8. */
  9. /**
  10. * Chamilo Metadata: search Chamilo course objects via their metadata
  11. * URL parameters:
  12. * - type= type, must be 'Mix' (currently: Document + Scorm + Link)
  13. * - lfn= filename of a language file, e.g. 'md_doc', default= 'md_' + type;
  14. * - htt= HTML template file (same dir as script), default= 'mds_' + type.
  15. */
  16. // PRELIMS -------------------------------------------------------------------->
  17. require("md_funcs.php");
  18. getpar('TYPE', 'e.g. Mix', 'Mix'); // note: only 'Mix' is currently working
  19. require('md_' . strtolower(TYPE) . '.php');
  20. getpar('LFN', 'LanguageFileName', 'md_' . strtolower(TYPE));
  21. getpar('HTT', 'HTML Template Text filename', 'mds_' . strtolower(TYPE));
  22. getpar('DBG', 'Debug number', '0'); // set to e.g. 10000 for debuginfo
  23. $urlp = '?type='. urlencode(TYPE);
  24. if (LFN != 'md_' . strtolower(TYPE)) $urlp .= '&lfn=' . urlencode(LFN);
  25. if (HTT != 'mds_' . strtolower(TYPE)) $urlp .= '&htt=' . urlencode(HTT);
  26. if (DBG) $urlp .= '&dbg=' . urlencode(DBG);
  27. // name of the language file that needs to be included
  28. $language_file = LFN; require("../inc/global.inc.php");
  29. $this_section=SECTION_COURSES;
  30. $nameTools = get_lang('Tool');
  31. ($nameTools && get_lang('Sorry'))
  32. or give_up('Language file ' . LFN . " doesn't define 'Tool' and 'Sorry'");
  33. $_course = api_get_course_info(); isset($_course) or give_up(get_lang('Sorry'));
  34. require(api_get_path(LIBRARY_PATH) . 'xmd.lib.php');
  35. require(api_get_path(LIBRARY_PATH) . 'xht.lib.php');
  36. $xhtDoc = define_htt(HTT . '.htt', $urlp, $_course['path']);
  37. $xhtDoc->xht_param['type'] = TYPE;
  38. $xhtDoc->xht_param['index'] =
  39. str_replace('/search.php', '/index.php', api_get_self());
  40. // XML and DB STUFF ----------------------------------------------------------->
  41. $mdStore = new mdstore(FALSE); // no create DB table from search
  42. $xhtDoc->xht_get_lang = 'get_lang'; $xhtDoc->xht_xmldoc = new xmddoc('');
  43. if ($xhtDoc->xht_xmldoc->error) give_up($xhtDoc->xht_xmldoc->error);
  44. ($mdt = $xhtDoc->xht_fill_template('DEFAULT'.TYPE))
  45. or give_up('No template DEFAULT' . TYPE);
  46. $xhtDoc->xht_xmldoc = new xmddoc(explode("\n", $mdt));
  47. if ($xhtDoc->xht_xmldoc->error) give_up($xhtDoc->xht_xmldoc->error);
  48. $xmlDoc = new xmddoc(''); if ($xmlDoc->error) give_up($xmlDoc->error);
  49. if (isset($_POST['mdsc'])) // Search criteria
  50. {
  51. $mdsc = str_replace("\r", "\n", str_replace("\r\n", "\n",
  52. get_magic_quotes_gpc() ? stripslashes($_POST['mdsc']) : $_POST['mdsc']));
  53. foreach (explode("\n", $mdsc) as $word) if (($word = trim($word)))
  54. {
  55. $words .= ", " . $word;
  56. $where .= " AND indexabletext " . ($word{0} != '-' ?
  57. ("LIKE '%".addslashes($word)."%'") :
  58. ("NOT LIKE '%".addslashes(substr($word, 1))."%'"));
  59. }
  60. if ($where)
  61. {
  62. $whereclause = substr($where, 5); // remove first " AND "
  63. $xhtDoc->xht_xmldoc->xmd_add_text_element('query', $whereclause);
  64. $xhtDoc->xht_param['traceinfo'] = substr($words, 2);
  65. $result = $mdStore->mds_get_many('eid,mdxmltext', $whereclause);
  66. while (($myrow = @Database::fetch_array($result)))
  67. {
  68. // not quite a real manifest, but very much like one...
  69. $eid = $myrow['eid']; $xmlDoc = new xmddoc($myrow['mdxmltext']);
  70. if ($xmlDoc->error) give_up('Entry '.$eid . ': ' . $xmlDoc->error);
  71. $mdObj = new mdobject($_course, $eid); // md_mix.php
  72. $xhtDoc->xht_xmldoc->xmd_copy_foreign_child($xmlDoc);
  73. $newItem = $xhtDoc->xht_xmldoc->
  74. xmd_select_single_element('item[-1]');
  75. $xhtDoc->xht_xmldoc->xmd_set_attribute($newItem, 'eid', $eid);
  76. $xhtDoc->xht_xmldoc->xmd_set_attribute($newItem, 'url',
  77. $mdObj->mdo_url);
  78. if ($mdObj->mdo_type == 'Scorm')
  79. $xhtDoc->xht_xmldoc->xmd_set_attribute($newItem, 'brl',
  80. $mdObj->mdo_base_url);
  81. }
  82. }
  83. }
  84. function check_is_thumb($p) // escape function, see mds_mix.htt
  85. {
  86. global $xhtDoc; if ($p !== FALSE) return ''; // should not happen
  87. if (!ereg('^pptsl[0-9]+_t\.jpg$', $xhtDoc->xht_param['thumb']))
  88. $xhtDoc->xht_param['thumb'] = '';
  89. return '';
  90. }
  91. // GENERATE OUTPUT ------------------------------------------------------------>
  92. foreach (explode("\n", $xhtDoc->htt_array['HTTP']) as $httpXtra)
  93. if ($httpXtra) $httpHeadXtra[] = $httpXtra;
  94. $xhtDoc->xht_get_lang = 'get_lang';
  95. function resource_for($e) {return $e;} // dummy, '=/' not used here
  96. $xhtDoc->xht_resource = 'resource_for';
  97. $xhtDoc->xht_param['kwdswere_string'] = $_POST['kwdswere_string'];
  98. $htmlHeadXtra[] = $xhtDoc->xht_fill_template('HEAD');
  99. // $noPHP_SELF = TRUE; // in breadcrumps
  100. Display::display_header($nameTools);
  101. $xhtDoc->xht_dbgn = DBG; // for template debug info, set to e.g. 10000
  102. if (($ti = $xhtDoc->xht_param['traceinfo'])) $xhtDoc->xht_param['traceinfo'] =
  103. '<b>' . get_lang('Search') . '</b>: ' . htmlspecialchars($ti, ENT_QUOTES, $charset);
  104. echo $xhtDoc->xht_fill_template('MDSEARCH'), "\n";
  105. if ($xhtDoc->xht_dbgn) echo $xhtDoc->xht_dbgo;
  106. Display::display_footer();
  107. ?>