search.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. <?php
  2. /**
  3. * Chamilo phpdig/search.php
  4. * 2006/12/14
  5. * @copyright 2006 rene.haentjens@UGent.be - see metadata/md_funcs.php
  6. * @package chamilo.metadata
  7. */
  8. /*
  9. --------------------------------------------------------------------------------
  10. PhpDig Version 1.8.6 is provided WITHOUT warranty under the GNU/GPL license.
  11. See the LICENSE file for more information about the GNU/GPL license.
  12. Contributors are listed in the CREDITS and CHANGELOG files in this package.
  13. Developer from inception to and including PhpDig v.1.6.2: Antoine Bajolet
  14. Developer from PhpDig v.1.6.3 to and including current version: Charter
  15. Copyright (C) 2001 - 2003, Antoine Bajolet, http://www.toiletoine.net/
  16. Copyright (C) 2003 - current, Charter, http://www.phpdig.net/
  17. Contributors hold Copyright (C) to their code submissions.
  18. Do NOT edit or remove this copyright or licence information upon redistribution.
  19. If you modify code and redistribute, you may ADD your copyright to this notice.
  20. --------------------------------------------------------------------------------
  21. */
  22. /**
  23. * Chamilo Metadata: search Chamilo course objects via PhpDig 1.8.6
  24. * customized search.php 1.8.6 for Chamilo 1.6 assumes $template == "array"
  25. */
  26. // name of the language file that needs to be included
  27. $language_file = "md_mix";
  28. include('../../../main/inc/global.inc.php');
  29. if (! $is_allowed_in_course) api_not_allowed();
  30. // start of part copied (with some changes) from standard PhpDig search.php
  31. $relative_script_path = '.';
  32. $no_connect = 0;
  33. if (is_file("$relative_script_path/includes/config.php")) {
  34. include "$relative_script_path/includes/config.php";
  35. }
  36. else {
  37. die("Cannot find config.php file.\n");
  38. }
  39. if (is_file("$relative_script_path/libs/search_function.php")) {
  40. include "$relative_script_path/libs/search_function.php";
  41. }
  42. else {
  43. die("Cannot find PhpDig search_function.php file.\n");
  44. }
  45. // extract vars
  46. extract(phpdigHttpVars(
  47. array('query_string'=>'string',
  48. 'mdsc'=>'string', 'kwdswere_string'=>'string', // Dokeos
  49. 'refine'=>'integer',
  50. 'refine_url'=>'string',
  51. 'site'=>'string', // set to integer later
  52. 'limite'=>'integer',
  53. 'option'=>'string',
  54. 'lim_start'=>'integer',
  55. 'browse'=>'integer',
  56. 'path'=>'string'
  57. )
  58. ),EXTR_SKIP);
  59. $adlog_flag = 0;
  60. $rssdf = "";
  61. // end of part copied (with some changes) from standard PhpDig search.php
  62. // Course keywords
  63. $_course = api_get_course_info(); $ckw = $_course['path'] . '/CourseKwds.js';
  64. define('KEYWORDS_CACHE', api_get_path(SYS_COURSE_PATH) . $ckw);
  65. if (file_exists(KEYWORDS_CACHE)) $kcdt =
  66. htmlspecialchars(date('Y/m/d H:i:s', filemtime(KEYWORDS_CACHE)));
  67. $keywordscache = $kcdt ?
  68. '<script type="text/javascript" src="' . api_get_path(WEB_COURSE_PATH) . $ckw . '"></script>' .
  69. '<br /><small><i>(CourseKwds cache: ' . $kcdt . ')</i></small>' : '';
  70. // Dokeos header
  71. $nameTools = get_lang('Search');
  72. $htmlHeadXtra[] = '<link rel="stylesheet" type="text/css" href="../../../main/metadata/md_styles.css">';
  73. $htmlHeadXtra[] = '<script type="text/javascript" src="../../../main/metadata/md_script.js"></script>';
  74. $htmlHeadXtra[] = '
  75. <script type="text/javascript">
  76. /* <![CDATA[ */
  77. function mdscSet(s)
  78. {
  79. var mdsc = getObj("mdsc");
  80. if (!mdsc) { alert("? Form does not contain mdsc"); return false; }
  81. mdsc.value = s; return true;
  82. }
  83. function checkEnter(ev)
  84. {
  85. if (!ev) ev = window.event;
  86. if (ev.altKey) {alert(document.getElementById("kwds_string").value); return;}
  87. if (ev.keyCode == 13)
  88. {
  89. document.getElementById("kwdswere_string").value =
  90. document.getElementById("kwds_string").value;
  91. if (prepSearch(ev)) getObj("form_submit").form.submit();
  92. }
  93. }
  94. /* ]]> */
  95. </script>';
  96. Display::display_header($nameTools); echo "\n";
  97. echo '<table width="100%"><tr><td><h3>', get_lang('Search'), '</h3></td>',
  98. '<td align="right"><a href="http://www.phpdig.net"><img src="phpdig_powered_2.gif"/></a></td></tr></table>';
  99. // Store new extra criteria (course manager only, see below), or execute
  100. // PhpDig Search and echo result message + table with results + pages bar
  101. if (!$query_string) $query_string = trim($mdsc);
  102. $ckwcdt = file_exists($ckwc = KEYWORDS_CACHE . 'c') ?
  103. date('Y/m/d H:i:s', filemtime($ckwc)) : '?'; $pkwc = '';
  104. if (substr($query_string, 0, 2) == '<>' && api_is_allowed_to_edit())
  105. {
  106. if ($ckwcdt{0} != '?')
  107. {
  108. $fckwc = fopen($ckwc, 'rb'); $pkwc = fread($fckwc, filesize($ckwc));
  109. fclose($fckwc); unset($fckwc);
  110. }
  111. if(($fckwc = fopen($ckwc, 'wb')))
  112. {
  113. fwrite($fckwc, $query_string); fclose($fckwc); unset($fckwc);
  114. $ckwcdt = file_exists($ckwc) ?
  115. date('Y/m/d H:i:s', filemtime($ckwc)) : '? Write Error';
  116. }
  117. else $ckwcdt = '? Open Error';
  118. $phpdigSearchResults = array('result_message' => $ckw . 'c: ' . $ckwcdt,
  119. 'pages_bar' => '', 'results' => array());
  120. }
  121. else
  122. {
  123. $phpdigSearchResults = phpdigSearch($id_connect, $query_string, $option,
  124. $refine, $refine_url, $lim_start, $limite, $browse, $site, $path,
  125. $relative_script_path, $template, $adlog_flag, $rssdf, $template_demo);
  126. }
  127. $result_message = ''; $hits = 11;
  128. if ($result_message = $phpdigSearchResults['result_message'])
  129. if (($cspos = strpos($result_message, ', ')) !== FALSE)
  130. if (($sppos = strpos($result_message, ' ', $cspos += 2)) !== FALSE)
  131. if (is_numeric($total = substr($result_message, $cspos, $sppos-$cspos)))
  132. $hits = (int) $total;
  133. if (!($pages_bar = $phpdigSearchResults['pages_bar'])) $hits = 0;
  134. if ($result_message == phpdigMsg('noresults')) $result_message .= ' '.phpdigMsg('on').' "'.htmlspecialchars($query_string,ENT_QUOTES).'"';
  135. echo $result_message, '<br><br><table border="1">', "\n";
  136. if ($phpdigSearchResults['results']) foreach ($phpdigSearchResults['results'] as $searchResult)
  137. {
  138. $url = $searchResult['complete_path'];
  139. if (ereg("/[^?/]*\\?.*thumb=", $url))
  140. {
  141. // direct URL: $thumburl = ereg_replace("/[^?/]*\\?.*thumb=", "/", $url);
  142. $thumburl = ereg_replace("\\?.*thumb=", "?th=", $url); // via index.php
  143. }
  144. else
  145. {
  146. $thumburl = "tpl_img/link.gif";
  147. }
  148. echo '<tr><td align="center"><a target="_blank" href="', $url, '"><img src="', $thumburl,
  149. '"/></a></td><td><a target="_blank" href="', $url, '">', $searchResult['link_title'],
  150. '</a><br>', $searchResult['text'], '</td></tr>', "\n";
  151. }
  152. echo '</table><br>';
  153. if ($result_message && ($hits > 10))
  154. echo "Results page ", str_replace('?template_demo=',
  155. '?kwdswere_string=' . urlencode($kwdswere_string), $pages_bar), '<br><br>';
  156. /* Extra criteria: A course manager can define and edit them in the TEXTAREA.
  157. If he types in something as in the example below, and clicks 'Go', the new
  158. criteria are stored and the old ones are displayed. So it is easy to
  159. restore the old ones. To confirm the new ones, empty the TEXTAREA.
  160. <>This selection empties extra criteria
  161. <searchword>Label
  162. <keyword-kw>Descriptive text
  163. */
  164. $tdhtm = '';
  165. function tdhtm($xc)
  166. {
  167. $eol = '<br/>'; if ($xc{0} == '<') $xc = substr($xc, 1);
  168. if (($eov = strpos($xc, '>')) === FALSE)
  169. $value = $label = $xc;
  170. else
  171. {
  172. $value = substr($xc, 0, $eov); $label = substr($xc, $eov+1);
  173. if (($eot = strpos($label, '<')) !== FALSE)
  174. {
  175. $eol = substr($label, $eot); $label = substr($label, 0, $eot);
  176. }
  177. }
  178. return '<input type="radio" name="xc" onclick="mdscSet(' . "'" .
  179. htmlspecialchars($value) . "'" . ')">' .
  180. htmlspecialchars($label) . '</input>' . $eol;
  181. }
  182. if ($ckwcdt{0} != '?') // there is a file with extra criteria
  183. {
  184. $fckwc = fopen($ckwc, 'rb');
  185. foreach (explode("\n", fread($fckwc, filesize($ckwc))) as $xc)
  186. $tdhtm .= "\n" . tdhtm($xc);
  187. fclose($fckwc); unset($fckwc);
  188. }
  189. // Search criteria form and keywords tree
  190. ?>
  191. <div onMouseUp="if ((kw = pU_clicked(event))) pU_select(kw); else pU_hide();">
  192. <input type="text" id="kwds_string" class="kwl" onKeyUp="takeTypeIn(this, 150, -100, '60%'); checkEnter(event); return true;"/>
  193. <form action="<?php echo api_get_self()?>" method="post">
  194. <table>
  195. <tr>
  196. <td><?php echo $tdhtm, '&nbsp;'; ?>
  197. </td>
  198. <td>
  199. <?php if (api_is_allowed_to_edit())
  200. echo '<textarea name="mdsc" id="mdsc" rows="10" cols="60">', htmlspecialchars($pkwc), '</textarea>';
  201. else echo '<textarea name="mdsc" id="mdsc" class="dvc"> </textarea>';
  202. ?>
  203. </td>
  204. <td>
  205. <input type="hidden" id="kwdswere_string" name="kwdswere_string"/>
  206. <input type="submit" id="form_submit" onClick="document.getElementById('kwdswere_string').value = document.getElementById('kwds_string').value; return prepSearch(event);" value="<?php echo phpdigMsg('go')?>"/>
  207. </td>
  208. </tr>
  209. </table>
  210. <div id="popup" noWrap="1" class="pup">
  211. Working...
  212. </div>
  213. </form>
  214. <div>
  215. </div>
  216. <div noWrap="1" id="maindiv">
  217. <?php if ($keywordscache == '') { ?> &#xa0; <?php } else { ?>
  218. <input type="checkbox" id="restricttokwds">Keywords-restrictive search<br>
  219. <input type="button" class="btn" value="+" onClick="if (this.value == '+') deselectAll(event, this); openOrClose(this);"/>
  220. <input type="button" class="btm" id="btnOpenOrCloseAll" value="++" onClick="openOrCloseAll(this);"/>
  221. <input type="button" class="btn" value="?" onClick="openOrCloseHelp(this)"/>
  222. &#xa0;<?php echo get_lang('ClickKw'), $keywordscache; } ?>
  223. </div>
  224. <div id='moreHelp' class='dvc'>
  225. <?php echo get_lang('KwHelp')?>
  226. </div>
  227. </div><!-- onMouseUp -->
  228. <?php
  229. /***** Example inserting in own domain (not used here)
  230. * PhpDig installed at: http://www.domain.com/phpdig/
  231. * Want search page at: http://www.domain.com/search.php
  232. * Copy http://www.domain.com/phpdig/search.php to http://www.domain.com/search.php
  233. * Copy http://www.domain.com/phpdig/clickstats.php to http://www.domain.com/clickstats.php
  234. * Set $relative_script_path = './phpdig'; in search.php, clickstats.php, and function_phpdig_form.php
  235. * Add ($relative_script_path != "./phpdig") && to if statement
  236. *****/
  237. echo "\n"; Display::display_footer();
  238. ?>