search.php 5.5 KB

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