search.php 9.0 KB

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