lp_list_search.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <?php
  2. /* For licensing terms, see /dokeos_license.txt */
  3. /**
  4. * Script to draw the results from a query
  5. * @package: dokeos.learnpath
  6. * @author: Diego Escalante Urrelo <diegoe@gmail.com>
  7. * @author: Marco Antonio Villegas Vega <marvil07@gmail.com>
  8. */
  9. require api_get_path(LIBRARY_PATH).'search/search_widget.php';
  10. require api_get_path(LIBRARY_PATH).'search/DokeosQuery.php';
  11. require_once api_get_path(LIBRARY_PATH).'search/IndexableChunk.class.php';
  12. require_once api_get_path(LIBRARY_PATH).'/specific_fields_manager.lib.php';
  13. $htmlHeadXtra[] = '<link rel="stylesheet" type="text/css" href="'. api_get_path(WEB_PATH) .'main/newscorm/lp_list_search.css" />';
  14. event_access_tool(TOOL_SEARCH);
  15. if (isset($_SESSION['gradebook'])){
  16. $gradebook= $_SESSION['gradebook'];
  17. }
  18. if (!empty($gradebook) && $gradebook=='view') {
  19. $interbreadcrumb[]= array (
  20. 'url' => '../gradebook/'.$_SESSION['gradebook_dest'],
  21. 'name' => get_lang('Gradebook')
  22. );
  23. }
  24. $interbreadcrumb[]= array ("url"=>"./index.php", "name"=> get_lang(ucfirst(TOOL_SEARCH)));
  25. search_widget_prepare(&$htmlHeadXtra);
  26. Display::display_header(null,'Path');
  27. if (api_get_setting('search_enabled') !== 'true') {
  28. Display::display_error_message(get_lang('SearchFeatureNotEnabledComment'));
  29. } else {
  30. if (!empty($_GET['action'])) {
  31. search_widget_show($_GET['action']);
  32. } else {
  33. search_widget_show();
  34. }
  35. }
  36. // initialize
  37. $op = 'or';
  38. if (!empty($_REQUEST['operator']) && in_array($op, array('or','and'))) {
  39. $op = $_REQUEST['operator'];
  40. }
  41. $query = stripslashes(htmlspecialchars_decode($_REQUEST['query'], ENT_QUOTES));
  42. $mode = 'default';
  43. if (in_array($_GET['mode'], array('gallery', 'default'))) {
  44. $mode = $_GET['mode'];
  45. }
  46. $term_array = array();
  47. $specific_fields = get_specific_field_list();
  48. foreach ($specific_fields as $specific_field) {
  49. if (!empty($_REQUEST[ 'sf_'. $specific_field['code'] ])) {
  50. $values = $_REQUEST[ 'sf_'. $specific_field['code'] ];
  51. if (in_array('__all__', $values)) {
  52. $sf_terms_for_code = xapian_get_all_terms(1000, $specific_field['code']);
  53. foreach ($sf_terms_for_code as $term) {
  54. if (!empty($term)) {
  55. $term_array[] = dokeos_get_boolean_query($term['name']); //here name includes prefix
  56. }
  57. }
  58. } else {
  59. foreach ($values as $term) {
  60. if (!empty($term)) {
  61. $prefix = $specific_field['code'];
  62. $term_array[] = dokeos_get_boolean_query($prefix . $term);
  63. }
  64. }
  65. }
  66. }
  67. }
  68. // get right group of terms to show on multiple select
  69. $fixed_queries = array();
  70. $course_filter = NULL;
  71. if ( ($cid=api_get_course_id()) != -1 ) {
  72. // results only from actual course
  73. $course_filter = dokeos_get_boolean_query(XAPIAN_PREFIX_COURSEID . $cid);
  74. }
  75. if (count($term_array)) {
  76. $fixed_queries = dokeos_join_queries($term_array, null, $op);
  77. if ($course_filter != NULL) {
  78. $fixed_queries = dokeos_join_queries($fixed_queries, $course_filter, 'and');
  79. }
  80. } else {
  81. if (!empty($query)) {
  82. $fixed_queries = array($course_filter);
  83. }
  84. }
  85. list($count, $results) = dokeos_query_query(api_convert_encoding($query,'UTF-8',$charset), 0, 1000, $fixed_queries);
  86. // prepare blocks to show
  87. $blocks = array();
  88. if ($count > 0) {
  89. foreach ($results as $result) {
  90. // Fill the result array
  91. if (empty($result['thumbnail'])) {
  92. $result['thumbnail'] = '../img/no_document_thumb.jpg';
  93. }
  94. if (!empty($result['url'])) {
  95. $a_prefix = '<a href="'.$result['url'].'">';
  96. $a_sufix = '</a>';
  97. } else {
  98. $a_prefix = '';
  99. $a_sufix = '';
  100. }
  101. if ($mode == 'gallery') {
  102. $title = $a_prefix.str_replace('_',' ',$result['title']). $a_sufix;
  103. $blocks[] = array(
  104. $a_prefix .'<img src="'.$result['thumbnail'].'" />'. $a_sufix .'<br />'.$title.'<br />'.$result['author'],
  105. );
  106. } else {
  107. $title = '<div style="text-align:left;">'. $a_prefix . $result['title']. $a_sufix .(!empty($result['author'])?$result['author']:'').'<div>';
  108. $blocks[] = array(
  109. $title,
  110. );
  111. }
  112. }
  113. }
  114. // show results
  115. if (count($blocks) > 0) {
  116. $s = new SortableTableFromArray($blocks);
  117. $s->display_mode = $mode;//default
  118. $s->display_mode_params = 3;
  119. $s->per_page = 9;
  120. $additional_parameters = array(
  121. 'mode' => $mode,
  122. 'action' => 'search',
  123. 'query' => $_REQUEST['query'],
  124. );
  125. $get_params = '';
  126. foreach ($specific_fields as $specific_field) {
  127. if (isset($_REQUEST[ 'sf_'. $specific_field['code'] ])) {
  128. $values = $_REQUEST[ 'sf_'. $specific_field['code'] ];
  129. $additional_parameters[ 'sf_'. $specific_field['code'] ] = $values;
  130. foreach ( $values as $value ) {
  131. $get_params .= '&sf_' . $specific_field['code'] .'[]='. $value;
  132. }
  133. $get_params .= '&';
  134. }
  135. }
  136. $additional_parameters['operator'] = $op;
  137. $s->additional_parameters = $additional_parameters;
  138. if ($mode == 'default') {
  139. $s->set_header(0, get_lang(ucfirst(TOOL_SEARCH)));
  140. }
  141. $search_link = '<a href="%ssearch/index.php?mode=%s&action=search&query=%s%s">';
  142. $mode_selector = '<div id="mode-selector">';
  143. $mode_selector .= sprintf($search_link, api_get_path(WEB_CODE_PATH), 'gallery', $_REQUEST['query'], $get_params);
  144. $mode_selector .= '<img src="../img/'. (($mode=='gallery')?'ButtonGallOn':'ButtonGallOff') .'.png" /></a>';
  145. $mode_selector .= sprintf($search_link, api_get_path(WEB_CODE_PATH), 'default', $_REQUEST['query'], $get_params);
  146. $mode_selector .= '<img src="../img/'.(($mode=='default')?'ButtonListOn':'ButtonListOff').'.png" /></a>';
  147. $mode_selector .= '</div>';
  148. echo '<div id="search-results-container">';
  149. echo $mode_selector;
  150. $s->display();
  151. echo '</div>';
  152. }
  153. Display::display_footer();
  154. ?>