searchit.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php //$id: $
  2. /**
  3. * This script is the main client script. It calls the search server to get an XML document that
  4. * represents the list of results to the term searched.
  5. * It parses the XML document, checks user permissions and displays a set of results in a nice
  6. * format.
  7. * @package chamilo.plugin.search
  8. * @author Yannick Warnier <yannick.warnier@beeznest.com>
  9. */
  10. /**
  11. * Variables
  12. */
  13. require_once('../../../main/inc/global.inc.php');
  14. require ('filter_user.lib.php');
  15. require ('client.conf.php');
  16. api_block_anonymous_users();
  17. $htmlHeadXtra[] = '<link rel="stylesheet" type="text/css" href="search.css" />';
  18. $start_time = time();
  19. $xml_file = $server_url.'?'.$_SERVER['QUERY_STRING'];
  20. //if(!$doc = xmldocfile($xml_file)){
  21. $results = simplexml_load_file($xml_file);
  22. if($results === false)
  23. {
  24. $res = array();
  25. }
  26. else
  27. {
  28. //$doc->load($xml_file);
  29. $subTotals = array();
  30. $lasttag = '';
  31. $myindex = 0;
  32. $level = 0;
  33. //$root = $doc->root();
  34. //$root = $doc->documentElement;
  35. $my_query = $results->query;
  36. $my_search_info = $results->search_info;
  37. $my_search_term = $results->search_term;
  38. $my_num_found = $results->num_found;
  39. $my_search_time = $results->search_time;
  40. $elementCount = 1;
  41. }
  42. /**
  43. * This function is just a display helper.
  44. * @param integer Result ID
  45. * @param string Result title
  46. * @param string Result URL
  47. * @param string Short excerpt of the result document
  48. * @param string Date
  49. * @param string Rating
  50. */
  51. function result_output($id,$title,$url='',$excerpt='',$date='',$rating=''){
  52. if(empty($id) OR empty($title)){return false;}
  53. $title = urldecode($title);
  54. $title = preg_replace('/\?cidReq=.*$/','',$title);
  55. $excerpt = preg_replace('/<hl>\s*(<hl>)?/','<div class="highlight">',$excerpt);
  56. $excerpt = preg_replace('/<\/hl>\s*(<\/hl>)?/','</div> ',$excerpt);
  57. $excerpt = stripslashes($excerpt);
  58. $string = "<div class='result'>\n" .
  59. "<div class='title'>$id. <a href='$url'>$title</a> - $date - $rating</div>\n" .
  60. "<div class='description'>$excerpt</div>\n" .
  61. "</div>\n";
  62. //$string = "$id. <a href='$url'>$title</a> - $date<br/><i>$excerpt</i><br/><br/>";
  63. return $string;
  64. }
  65. include('../../../main/inc/header.inc.php');
  66. ?>
  67. <form method="get" action="<?php echo $search_url; ?>"><input
  68. type="hidden" name="ps" value="1000"/><input
  69. type="hidden" name="o" value="0"/><input
  70. type="hidden" name="m" value="any"/><input
  71. type="hidden" name="wm" value="sub"/><input
  72. type="hidden" name="wf" value="2221"/><input
  73. type="hidden" name="s" value="RDP"/><input
  74. type="hidden" name="sy" value="1"/><input
  75. type="text" name="q" value="<?php echo urldecode($my_query);?>" size="10" style="margin: 4px 6px; border: 1px solid #B6BB8C; color:#4D4F3A; height: 15px;padding:0px;"><input
  76. type="submit" name="submit" value="<?php echo $lang_search_button; ?>" style="margin: 4px 6px; border: 1px solid #B6BB8C; color:#4D4F3A; height:17px;vertical-align:top;padding:0px"></form>
  77. <?php
  78. $i = 1;
  79. $to_print = '';
  80. foreach($results->result as $res){
  81. if(access_check($res->result_du)){
  82. $to_print .= result_output($i,api_convert_encoding(urldecode($res->result_dt),$charset,'utf-8'),$res->result_du,api_html_entity_decode(urldecode($res->result_de)),api_htmlentities(urldecode($res->result_dm)),$res->result_dr);
  83. $i++;
  84. }
  85. }
  86. //TODO check if a time and number of results is defined
  87. $i--;
  88. if($to_print != ''){
  89. //$time = $res['search_time'] + (time() - $start_time);
  90. //echo "<div class='search_info'>".$i.' '.$lang_search_found.' '.$time." $lang_seconds</div><br/>\n";
  91. echo "<div class='search_info'>".$i.' '.$lang_search_found."</div><br/>\n";
  92. echo $to_print;
  93. }else{
  94. echo "<div class='search_info'>".$lang_no_result_found."</div><br/>\n";
  95. }
  96. include('../../../main/inc/footer.inc.php');
  97. ?>