search.php 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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. $ajax_url = api_get_path(WEB_AJAX_PATH).'message.ajax.php';
  9. api_block_anonymous_users();
  10. if (api_get_setting('social.allow_social_tool') != 'true') {
  11. api_not_allowed();
  12. }
  13. $this_section = SECTION_SOCIAL;
  14. $tool_name = get_lang('Search');
  15. $user_id = api_get_user_id();
  16. $interbreadcrumb[] = array('url' => 'profile.php', 'name' => get_lang('SocialNetwork'));
  17. $query = isset($_GET['q']) ? Security::remove_XSS($_GET['q']): null;
  18. $query_search_type = isset($_GET['search_type']) && in_array($_GET['search_type'], array('0','1','2')) ? $_GET['search_type'] : null;
  19. $extra_fields = UserManager::get_extra_filtrable_fields();
  20. $query_vars = array('q' => $query, 'search_type' => $query_search_type);
  21. if (!empty($extra_fields)) {
  22. foreach ($extra_fields as $extra_field) {
  23. $field_name = 'field_' . $extra_field['variable'];
  24. if (isset($_GET[$field_name]) && $_GET[$field_name] != '0') {
  25. $query_vars[$field_name] = $_GET[$field_name];
  26. }
  27. }
  28. }
  29. //Block Social Menu
  30. $social_menu_block = SocialManager::show_social_menu('search');
  31. $block_search = '';
  32. $searchForm = UserManager::get_search_form($query);
  33. $groups = array();
  34. $totalGroups = array();
  35. $users = array();
  36. $totalUsers = array();
  37. $usergroup = new UserGroup();
  38. // I'm searching something
  39. if ($query != '' || ($query_vars['search_type']=='1' && count($query_vars)>2) ) {
  40. $itemPerPage = 8;
  41. if ($_GET['search_type']=='0' || $_GET['search_type']=='1') {
  42. $page = isset($_GET['users_page_nr']) ? intval($_GET['users_page_nr']) : 1;
  43. $totalUsers = UserManager::get_all_user_tags($_GET['q'], 0, 0, $itemPerPage, true);
  44. $from = intval(($page - 1) * $itemPerPage);
  45. // Get users from tags
  46. $users = UserManager::get_all_user_tags($_GET['q'], 0, $from, $itemPerPage);
  47. }
  48. if ($_GET['search_type']=='0' || $_GET['search_type']=='2') {
  49. $pageGroup = isset($_GET['groups_page_nr']) ? intval($_GET['groups_page_nr']) : 1;
  50. // Groups
  51. $fromGroups = intval(($pageGroup - 1) * $itemPerPage);
  52. $totalGroups = count($usergroup->get_all_group_tags($_GET['q'], 0, $itemPerPage, true));
  53. $groups = $usergroup->get_all_group_tags($_GET['q'], $fromGroups);
  54. }
  55. if (empty($users) && empty($groups)) {
  56. Display::addFlash(Display::return_message(get_lang('SorryNoResults')));
  57. }
  58. $results = '<div id="whoisonline">';
  59. if (is_array($users) && count($users) > 0) {
  60. $results .= '<div class="row">';
  61. $buttonClass = 'btn btn-default btn-sm';
  62. foreach ($users as $user) {
  63. $user_info = api_get_user_info($user['id'], true);
  64. $send_inv = '<button class="'.$buttonClass.' disabled "><em class="fa fa-user"></em> '.get_lang('SendInvitation').'</button>';
  65. $relation_type = intval(SocialManager::get_relation_between_contacts(api_get_user_id(), $user_info['user_id']));
  66. $url = api_get_path(WEB_PATH).'main/social/profile.php?u='.$user_info['user_id'];
  67. // Show send invitation icon if they are not friends yet
  68. if ($relation_type != 3 && $relation_type != 4 && $user_info['user_id'] != api_get_user_id()) {
  69. $send_inv = '<a href="#" class="'.$buttonClass.' btn-to-send-invitation" data-send-to="' . $user_info['user_id'] . '">
  70. <em class="fa fa-user"></em> '.get_lang('SendInvitation').'</a>';
  71. }
  72. $sendMesssageUrl = api_get_path(WEB_AJAX_PATH)
  73. . 'user_manager.ajax.php?'
  74. . http_build_query([
  75. 'a' => 'get_user_popup',
  76. 'user_id' => $user_info['user_id']
  77. ]);
  78. $send_msg = Display::toolbarButton(
  79. get_lang('SendMessage'),
  80. $sendMesssageUrl,
  81. 'envelope',
  82. 'default',
  83. [
  84. 'class' => 'ajax btn-sm',
  85. 'data-title' => get_lang('SendMessage')
  86. ]
  87. );
  88. $img = '<img src="'.$user_info['avatar'].'" class="img-responsive img-circle" width="100" height="100">';
  89. if ($user_info['user_is_online']) {
  90. $status_icon = Display::return_icon('online.png', get_lang('OnLine'), null, ICON_SIZE_TINY);
  91. } else {
  92. $status_icon = Display::return_icon('offline.png', get_lang('Disconnected'), null, ICON_SIZE_TINY);
  93. }
  94. if ($user_info['status'] == 5) {
  95. $user_icon = Display::return_icon('user.png', get_lang('Student'), null, ICON_SIZE_TINY);
  96. } else {
  97. $user_icon = Display::return_icon('teacher.png', get_lang('Teacher'), null, ICON_SIZE_TINY);
  98. }
  99. $tag = isset($user['tag']) ? ' <br /><br />'.$user['tag'] : null;
  100. $user_info['complete_name'] = Display::url($user_info['complete_name'], $url);
  101. $invitations = $user['tag'].$send_inv.$send_msg;
  102. $results .= '<div class="col-md-3">
  103. <div class="items-user">
  104. <div class="items-user-avatar">
  105. '.$img.'
  106. </div>
  107. <div class="user-info">
  108. <p>'.$user_info['complete_name'].'</p>
  109. <div class="items-user-status">'.$status_icon.$user_icon.'</div>
  110. <div class="toolbar">
  111. '.$invitations.'
  112. </div>
  113. </div>
  114. </div>
  115. </div>';
  116. }
  117. $results .= '</div>';
  118. }
  119. $results .= '</div>';
  120. $visibility = array(true, true, true, true, true);
  121. $results .= Display::return_sortable_grid(
  122. 'users',
  123. null,
  124. null,
  125. array('hide_navigation' => false, 'per_page' => $itemPerPage),
  126. $query_vars,
  127. false,
  128. $visibility,
  129. true,
  130. array(),
  131. $totalUsers
  132. );
  133. $block_search .= Display::panelCollapse(
  134. get_lang('Users'),
  135. $results,
  136. 'search-friends',
  137. null,
  138. 'friends-acorderon',
  139. 'friends-collapse'
  140. );
  141. $grid_groups = array();
  142. $block_groups = '<div id="whoisonline">';
  143. if (is_array($groups) && count($groups) > 0) {
  144. $block_groups .= '<div class="row">';
  145. foreach ($groups as $group) {
  146. $group['name'] = Security::remove_XSS($group['name'], STUDENT, true);
  147. $group['description'] = Security::remove_XSS($group['description'], STUDENT, true);
  148. $id = $group['id'];
  149. $url_open = '<a href="group_view.php?id='.$id.'">';
  150. $url_close = '</a>';
  151. $name = cut($group['name'], 60, true);
  152. $count_users_group = count($usergroup->get_all_users_by_group($id));
  153. if ($count_users_group == 1) {
  154. $count_users_group = $count_users_group;
  155. } else {
  156. $count_users_group = $count_users_group;
  157. }
  158. $picture = $usergroup->get_picture_group($group['id'], $group['picture'], GROUP_IMAGE_SIZE_ORIGINAL);
  159. //$tags = $usergroup->get_group_tags($group['id']);
  160. $tags = null;
  161. $group['picture'] = '<img class="img-responsive img-circle" src="'.$picture['file'].'" />';
  162. $members = Display::returnFontAwesomeIcon('user') . '( ' .$count_users_group . ' )';
  163. $item_1 = Display::tag('p', $url_open.$name.$url_close);
  164. $block_groups .= '
  165. <div class="col-md-4">
  166. <div class="items-user">
  167. <div class="items-user-avatar">
  168. '.$group['picture'].'
  169. </div>
  170. <div class="user-info">
  171. '.$item_1.'
  172. <p>'.$members.'</p>
  173. <p>' . $group['description'] . '</p>
  174. <p>' . $tags . '</p>
  175. <p>' . $url_open.get_lang('SeeMore') . $url_close . '</p>
  176. </div>
  177. </div>
  178. </div>';
  179. }
  180. $block_groups .= '</div>';
  181. }
  182. $block_groups .= '</div>';
  183. $visibility = array(true, true, true, true, true);
  184. $block_groups .= Display::return_sortable_grid(
  185. 'groups',
  186. null,
  187. $grid_groups,
  188. array('hide_navigation' => false, 'per_page' => $itemPerPage),
  189. $query_vars,
  190. false,
  191. $visibility,
  192. true,
  193. array(),
  194. $totalGroups
  195. );
  196. $block_search .= Display:: panelCollapse(
  197. get_lang('Groups'),
  198. $block_groups,
  199. 'search-groups',
  200. null,
  201. 'groups-acorderon',
  202. 'groups-collapse'
  203. );
  204. }
  205. $tpl = \Chamilo\CoreBundle\Framework\Container::getTwig();
  206. // Block Social Avatar
  207. SocialManager::setSocialUserBlock($tpl, api_get_user_id(), 'search');
  208. $tpl->addGlobal('social_menu_block', $social_menu_block);
  209. $tpl->addGlobal('social_search', $block_search);
  210. $tpl->addGlobal('search_form', $searchForm);
  211. $tpl->addGlobal(
  212. 'invitation_form',
  213. MessageManager::generate_invitation_form('send_invitation')
  214. );
  215. echo $tpl->render('@template_style/social/search.html.twig');