search.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.social
  5. * @author Julio Montoya <gugli100@gmail.com>
  6. */
  7. $cidReset = true;
  8. require_once '../inc/global.inc.php';
  9. require_once api_get_path(LIBRARY_PATH).'magpierss/rss_fetch.inc';
  10. $ajax_url = api_get_path(WEB_AJAX_PATH).'message.ajax.php';
  11. api_block_anonymous_users();
  12. if (api_get_setting('allow_social_tool') != 'true') {
  13. api_not_allowed();
  14. }
  15. $this_section = SECTION_SOCIAL;
  16. $tool_name = get_lang('Search');
  17. $interbreadcrumb[] = array('url' => 'profile.php', 'name' => get_lang('SocialNetwork'));
  18. $query = isset($_GET['q']) ? Security::remove_XSS($_GET['q']): null;
  19. $query_search_type = isset($_GET['search_type']) && in_array($_GET['search_type'], array('0','1','2')) ? $_GET['search_type'] : null;
  20. $extra_fields = UserManager::get_extra_filtrable_fields();
  21. $query_vars = array('q' => $query, 'search_type' => $query_search_type);
  22. if (!empty($extra_fields)) {
  23. foreach ($extra_fields as $extra_field) {
  24. $field_name = 'field_' . $extra_field['variable'];
  25. if (isset($_GET[$field_name]) && $_GET[$field_name] != '0') {
  26. $query_vars[$field_name] = $_GET[$field_name];
  27. }
  28. }
  29. }
  30. //Block Social Menu
  31. $social_menu_block = SocialManager::show_social_menu('search');
  32. $social_right_content = '';
  33. $searchForm = UserManager::get_search_form($query);
  34. $groups = array();
  35. $totalGroups = array();
  36. $users = array();
  37. $totalUsers = array();
  38. $usergroup = new UserGroup();
  39. // I'm searching something
  40. if ($query != '' || ($query_vars['search_type']=='1' && count($query_vars)>2) ) {
  41. $itemPerPage = 9;
  42. if ($_GET['search_type']=='0' || $_GET['search_type']=='1') {
  43. $page = isset($_GET['users_page_nr']) ? intval($_GET['users_page_nr']) : 1;
  44. $totalUsers = UserManager::get_all_user_tags($_GET['q'], 0, 0, $itemPerPage, true);
  45. $from = intval(($page - 1) * $itemPerPage);
  46. // Get users from tags
  47. $users = UserManager::get_all_user_tags($_GET['q'], 0, $from, $itemPerPage);
  48. }
  49. if ($_GET['search_type']=='0' || $_GET['search_type']=='2') {
  50. $pageGroup = isset($_GET['groups_page_nr']) ? intval($_GET['groups_page_nr']) : 1;
  51. // Groups
  52. $fromGroups = intval(($pageGroup - 1) * $itemPerPage);
  53. $totalGroups = count($usergroup->get_all_group_tags($_GET['q'], 0, $itemPerPage, true));
  54. $groups = $usergroup->get_all_group_tags($_GET['q'], $fromGroups);
  55. }
  56. if (empty($users) && empty($groups)) {
  57. Display::addFlash(Display::return_message(get_lang('SorryNoResults')));
  58. }
  59. $results = '<div id="online_grid_container">';
  60. if (is_array($users) && count($users) > 0) {
  61. $results .= Display::page_subheader(get_lang('Users'));
  62. $results .= '<div class="row">';
  63. $buttonClass = 'btn btn-default btn-sm';
  64. foreach ($users as $user) {
  65. $send_inv = '<button class="'.$buttonClass.' disabled "><i class="fa fa-user"></i> '.get_lang('SendInvitation').'</button>';
  66. $relation_type = intval(SocialManager::get_relation_between_contacts(api_get_user_id(), $user['user_id']));
  67. $user_info = api_get_user_info($user['user_id'], true);
  68. $url = api_get_path(WEB_PATH).'main/social/profile.php?u='.$user['user_id'];
  69. // Show send invitation icon if they are not friends yet
  70. if ($relation_type != 3 && $relation_type != 4 && $user['user_id'] != api_get_user_id()) {
  71. $send_inv = '<a href="#" class="'.$buttonClass.' btn-to-send-invitation" data-send-to="' . $user['user_id'] . '">
  72. <i class="fa fa-user"></i> '.get_lang('SendInvitation').'</a>';
  73. }
  74. $sendMesssageUrl = api_get_path(WEB_AJAX_PATH)
  75. . 'user_manager.ajax.php?'
  76. . http_build_query([
  77. 'a' => 'get_user_popup',
  78. 'user_id' => $user['user_id']
  79. ]);
  80. $send_msg = Display::toolbarButton(
  81. get_lang('SendMessage'),
  82. $sendMesssageUrl,
  83. 'envelope',
  84. 'default',
  85. [
  86. 'class' => 'ajax btn-sm',
  87. 'data-title' => get_lang('SendMessage')
  88. ]
  89. );
  90. $img = '<img src="'.$user_info['avatar'].'" width="100" height="100">';
  91. if ($user_info['user_is_online']) {
  92. $status_icon = Display::span('', array('class' => 'online_user_in_text'));
  93. } else {
  94. $status_icon = Display::span('', array('class' => 'offline_user_in_text'));
  95. }
  96. $tag = isset($user['tag']) ? ' <br /><br />'.$user['tag'] : null;
  97. $user_info['complete_name'] = Display::url($status_icon.$user_info['complete_name'], $url);
  98. $invitations = $user['tag'].$send_inv.$send_msg;
  99. $results .= '<div class="col-md-4">
  100. <div class="card">
  101. <canvas class="header-bg" width="250" height="70" id="header-blur"></canvas>
  102. <div class="avatar">
  103. '.$img.'
  104. </div>
  105. <div class="content">
  106. '.$user_info['complete_name'].'
  107. <div class="btn-group">
  108. '.$invitations.'
  109. </div>
  110. </div>
  111. </div>
  112. </div>';
  113. }
  114. $results .= '</div></div>';
  115. $social_right_content .= $results;
  116. }
  117. $visibility = array(true, true, true, true, true);
  118. $social_right_content .= Display::return_sortable_grid(
  119. 'users',
  120. null,
  121. null,
  122. array('hide_navigation' => false, 'per_page' => $itemPerPage),
  123. $query_vars,
  124. false,
  125. $visibility,
  126. true,
  127. array(),
  128. $totalUsers
  129. );
  130. $grid_groups = array();
  131. if (is_array($groups) && count($groups) > 0) {
  132. $social_right_content .= '<div class="row">';
  133. $social_right_content .= Display::page_subheader(get_lang('Groups'));
  134. foreach ($groups as $group) {
  135. $group['name'] = Security::remove_XSS($group['name'], STUDENT, true);
  136. $group['description'] = Security::remove_XSS($group['description'], STUDENT, true);
  137. $id = $group['id'];
  138. $url_open = '<a class="btn btn-default" href="group_view.php?id='.$id.'">';
  139. $url_close = '</a>';
  140. $name = cut($group['name'], 60, true);
  141. $count_users_group = count($usergroup->get_all_users_by_group($id));
  142. if ($count_users_group == 1) {
  143. $count_users_group = $count_users_group.' '.get_lang('Member');
  144. } else {
  145. $count_users_group = $count_users_group.' '.get_lang('Members');
  146. }
  147. $picture = $usergroup->get_picture_group($group['id'], $group['picture'], GROUP_IMAGE_SIZE_ORIGINAL);
  148. //$tags = $usergroup->get_group_tags($group['id']);
  149. $tags = null;
  150. $group['picture'] = '<img src="'.$picture['file'].'" />';
  151. $members = Display::span($count_users_group);
  152. $item_1 = Display::tag('h3', $url_open.$name.$url_close).$members;
  153. $social_right_content .= '
  154. <div class="col-md-4">
  155. <div class="card">
  156. <div class="avatar">
  157. '.$group['picture'].'
  158. </div>
  159. <div class="content">
  160. '.$item_1.'
  161. <p>'.$group['description'].'</p>
  162. <p>'.$tags.'</p>
  163. <p>'.$url_open.get_lang('SeeMore').$url_close.'</p>
  164. </div>
  165. </div>
  166. </div>';
  167. }
  168. $social_right_content .= '</ul></div></div>';
  169. }
  170. $visibility = array(true, true, true, true, true);
  171. $social_right_content .= Display::return_sortable_grid(
  172. 'groups',
  173. null,
  174. $grid_groups,
  175. array('hide_navigation' => false, 'per_page' => $itemPerPage),
  176. $query_vars,
  177. false,
  178. $visibility,
  179. true,
  180. array(),
  181. $totalGroups
  182. );
  183. }
  184. $tpl = new Template($tool_name);
  185. // Block Social Avatar
  186. SocialManager::setSocialUserBlock($tpl, $user_id, 'search');
  187. $tpl->assign('social_menu_block', $social_menu_block);
  188. $tpl->assign('social_right_content', $social_right_content);
  189. $tpl->assign('search_form', $searchForm);
  190. $formModalTpl = new Template();
  191. $formModalTpl->assign('messageForm', MessageManager::generate_message_form('send_message'));
  192. $formModalTpl->assign('invitationForm', MessageManager::generate_invitation_form('send_invitation'));
  193. $formModals = $formModalTpl->fetch('default/social/form_modals.tpl');
  194. $tpl->assign('formModals', $formModals);
  195. $social_layout = $tpl->get_template('social/search.tpl');
  196. $tpl->display($social_layout);