search.php 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.social
  5. *
  6. * @author Julio Montoya <gugli100@gmail.com>
  7. */
  8. $cidReset = true;
  9. require_once __DIR__.'/../inc/global.inc.php';
  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[] = [
  18. 'url' => api_get_path(WEB_CODE_PATH).'social/profile.php',
  19. 'name' => get_lang('Social network'),
  20. ];
  21. $query = isset($_GET['q']) ? Security::remove_XSS($_GET['q']) : null;
  22. $queryNoFilter = isset($_GET['q']) ? $_GET['q'] : null;
  23. $query_search_type = isset($_GET['search_type']) && in_array($_GET['search_type'], ['0', '1', '2']) ? $_GET['search_type'] : null;
  24. $extra_fields = UserManager::getExtraFilterableFields();
  25. $query_vars = ['q' => $query, 'search_type' => $query_search_type];
  26. if (!empty($extra_fields)) {
  27. foreach ($extra_fields as $extra_field) {
  28. $field_name = 'field_'.$extra_field['variable'];
  29. if (isset($_GET[$field_name]) && $_GET[$field_name] != '0') {
  30. $query_vars[$field_name] = $_GET[$field_name];
  31. }
  32. }
  33. }
  34. //Block Social Menu
  35. $social_menu_block = SocialManager::show_social_menu('search');
  36. $block_search = '';
  37. $searchForm = UserManager::get_search_form($queryNoFilter);
  38. $groups = [];
  39. $totalGroups = [];
  40. $users = [];
  41. $totalUsers = [];
  42. $usergroup = new UserGroup();
  43. // I'm searching something
  44. if ($query != '' || ($query_vars['search_type'] == '1' && count($query_vars) > 2)) {
  45. $itemPerPage = 6;
  46. if ($_GET['search_type'] == '0' || $_GET['search_type'] == '1') {
  47. $page = isset($_GET['users_page_nr']) ? intval($_GET['users_page_nr']) : 1;
  48. $totalUsers = UserManager::get_all_user_tags(
  49. $_GET['q'],
  50. 0,
  51. 0,
  52. $itemPerPage,
  53. true
  54. );
  55. $from = intval(($page - 1) * $itemPerPage);
  56. // Get users from tags
  57. $users = UserManager::get_all_user_tags($_GET['q'], 0, $from, $itemPerPage);
  58. }
  59. if ($_GET['search_type'] == '0' || $_GET['search_type'] == '2') {
  60. $pageGroup = isset($_GET['groups_page_nr']) ? intval($_GET['groups_page_nr']) : 1;
  61. // Groups
  62. $fromGroups = intval(($pageGroup - 1) * $itemPerPage);
  63. $totalGroups = count($usergroup->get_all_group_tags($_GET['q'], 0, $itemPerPage, true));
  64. $groups = $usergroup->get_all_group_tags($_GET['q'], $fromGroups);
  65. }
  66. if (empty($users) && empty($groups)) {
  67. Display::addFlash(Display::return_message(get_lang('Sorry no results')));
  68. }
  69. $results = '<div id="whoisonline">';
  70. if (is_array($users) && count($users) > 0) {
  71. $results .= '<div class="row">';
  72. $buttonClass = 'btn btn-default btn-sm';
  73. foreach ($users as $user) {
  74. $user_info = api_get_user_info($user['id'], true);
  75. $sendInvitation = '<button class="'.$buttonClass.' disabled ">
  76. <em class="fa fa-user"></em> '.get_lang('Send invitation').'</button>';
  77. $relation_type = SocialManager::get_relation_between_contacts(api_get_user_id(), $user_info['user_id']);
  78. $url = api_get_path(WEB_PATH).'main/social/profile.php?u='.$user_info['user_id'];
  79. // Show send invitation icon if they are not friends yet
  80. if ($relation_type != 3 && $relation_type != 4 && $user_info['user_id'] != api_get_user_id()) {
  81. $sendInvitation = '<a href="#" class="'.$buttonClass.' btn-to-send-invitation" data-send-to="'.$user_info['user_id'].'">
  82. <em class="fa fa-user"></em> '.get_lang('Send invitation').'</a>';
  83. }
  84. $sendMessageUrl = api_get_path(WEB_AJAX_PATH).'user_manager.ajax.php?'.http_build_query([
  85. 'a' => 'get_user_popup',
  86. 'user_id' => $user_info['user_id'],
  87. ]);
  88. $sendMessage = Display::toolbarButton(
  89. get_lang('Send message'),
  90. $sendMessageUrl,
  91. 'envelope',
  92. 'default',
  93. [
  94. 'class' => 'ajax btn-sm',
  95. 'data-title' => get_lang('Send message'),
  96. ]
  97. );
  98. if (!empty($user_info['user_is_online'])) {
  99. $status_icon = Display::return_icon('online.png', get_lang('Online'), null, ICON_SIZE_TINY);
  100. } else {
  101. $status_icon = Display::return_icon('offline.png', get_lang('Disconnected'), null, ICON_SIZE_TINY);
  102. }
  103. if ($user_info['status'] == 5) {
  104. $user_icon = Display::return_icon('user.png', get_lang('Learner'), null, ICON_SIZE_TINY);
  105. } else {
  106. $user_icon = Display::return_icon('teacher.png', get_lang('Trainer'), null, ICON_SIZE_TINY);
  107. }
  108. $user_info['complete_name'] = Display::url($user_info['complete_name'], $url);
  109. $invitations = $sendInvitation.$sendMessage;
  110. $results .= Display::getUserCard(
  111. $user_info,
  112. $status_icon.$user_icon,
  113. $invitations
  114. );
  115. }
  116. $results .= '</div>';
  117. }
  118. $results .= '</div>';
  119. $visibility = [true, true, true, true, true];
  120. if (!empty($users)) {
  121. $results .= Display::return_sortable_grid(
  122. 'users',
  123. null,
  124. null,
  125. ['hide_navigation' => false, 'per_page' => $itemPerPage],
  126. $query_vars,
  127. false,
  128. $visibility,
  129. true,
  130. [],
  131. $totalUsers
  132. );
  133. $block_search .= Display::panelCollapse(
  134. get_lang('Users'),
  135. $results,
  136. 'search-friends',
  137. null,
  138. 'friends-accordion',
  139. 'friends-collapse'
  140. );
  141. }
  142. $grid_groups = [];
  143. $block_groups = '<div id="whoisonline">';
  144. if (is_array($groups) && count($groups) > 0) {
  145. $block_groups .= '<div class="row">';
  146. foreach ($groups as $group) {
  147. $group['name'] = Security::remove_XSS($group['name'], STUDENT, true);
  148. $group['description'] = Security::remove_XSS($group['description'], STUDENT, true);
  149. $id = $group['id'];
  150. $url_open = '<a href="group_view.php?id='.$id.'">';
  151. $url_close = '</a>';
  152. $name = cut($group['name'], 60, true);
  153. $count_users_group = count($usergroup->get_all_users_by_group($id));
  154. if ($count_users_group == 1) {
  155. $count_users_group = $count_users_group;
  156. } else {
  157. $count_users_group = $count_users_group;
  158. }
  159. $picture = $usergroup->get_picture_group(
  160. $group['id'],
  161. $group['picture'],
  162. GROUP_IMAGE_SIZE_ORIGINAL
  163. );
  164. $tags = null;
  165. $group['picture'] = '<img class="img-responsive img-circle" src="'.$picture['file'].'" />';
  166. $members = Display::returnFontAwesomeIcon('user').'( '.$count_users_group.' )';
  167. $item_1 = Display::tag('p', $url_open.$name.$url_close);
  168. $block_groups .= '
  169. <div class="col-md-4">
  170. <div class="items-user">
  171. <div class="items-user-avatar">
  172. '.$group['picture'].'
  173. </div>
  174. <div class="user-info">
  175. '.$item_1.'
  176. <p>'.$members.'</p>
  177. <p>'.$group['description'].'</p>
  178. <p>'.$tags.'</p>
  179. <p>'.$url_open.get_lang('See more').$url_close.'</p>
  180. </div>
  181. </div>
  182. </div>';
  183. }
  184. $block_groups .= '</div>';
  185. }
  186. $block_groups .= '</div>';
  187. $visibility = [true, true, true, true, true];
  188. if (!empty($groups)) {
  189. $block_groups .= Display::return_sortable_grid(
  190. 'groups',
  191. null,
  192. $grid_groups,
  193. ['hide_navigation' => false, 'per_page' => $itemPerPage],
  194. $query_vars,
  195. false,
  196. $visibility,
  197. true,
  198. [],
  199. $totalGroups
  200. );
  201. $block_search .= Display:: panelCollapse(
  202. get_lang('Groups'),
  203. $block_groups,
  204. 'search-groups',
  205. null,
  206. 'groups-accordion',
  207. 'groups-collapse'
  208. );
  209. }
  210. }
  211. $tpl = new Template($tool_name);
  212. // Block Social Avatar
  213. SocialManager::setSocialUserBlock($tpl, api_get_user_id(), 'search');
  214. $tpl->assign('social_menu_block', $social_menu_block);
  215. $tpl->assign('social_search', $block_search);
  216. $tpl->assign('search_form', $searchForm);
  217. $formModalTpl = new Template();
  218. $formModalTpl->assign('invitation_form', MessageManager::generate_invitation_form());
  219. $template = $formModalTpl->get_template('social/form_modals.tpl');
  220. $formModals = $formModalTpl->fetch($template);
  221. $tpl->assign('form_modals', $formModals);
  222. $social_layout = $tpl->get_template('social/search.tpl');
  223. $tpl->display($social_layout);