search.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.social
  5. * @author Julio Montoya <gugli100@gmail.com>
  6. */
  7. /**
  8. * Initialization
  9. */
  10. // name of the language file that needs to be included
  11. $language_file = array('registration', 'admin', 'userInfo');
  12. $cidReset = true;
  13. require_once '../inc/global.inc.php';
  14. require_once api_get_path(LIBRARY_PATH).'group_portal_manager.lib.php';
  15. require_once api_get_path(LIBRARY_PATH).'magpierss/rss_fetch.inc';
  16. $ajax_url = api_get_path(WEB_AJAX_PATH).'message.ajax.php';
  17. api_block_anonymous_users();
  18. $htmlHeadXtra[] = '<script>
  19. function checkLength( o, n, min, max ) {
  20. if ( o.val().length > max || o.val().length < min ) {
  21. o.addClass( "ui-state-error" );
  22. //updateTips( "Length of " + n + " must be between " + min + " and " + max + "." );
  23. return false;
  24. } else {
  25. return true;
  26. }
  27. }
  28. function send_message_to_user(user_id) {
  29. var subject = $( "#subject_id" );
  30. var content = $( "#content_id" );
  31. $("#send_message_form").show();
  32. $("#send_message_div").dialog({
  33. modal:true,
  34. height:350,
  35. buttons: {
  36. "'.addslashes(get_lang('Sent')).'": function() {
  37. var bValid = true;
  38. bValid = bValid && checkLength( subject, "subject", 1, 255 );
  39. bValid = bValid && checkLength( content, "content", 1, 255 );
  40. if (bValid) {
  41. var url = "'.$ajax_url.'?a=send_message&user_id="+user_id;
  42. var params = $("#send_message_form").serialize();
  43. $.ajax({
  44. url: url+"&"+params,
  45. success:function(data) {
  46. $("#message_ajax_reponse").attr("class", "");
  47. $("#message_ajax_reponse").html(data);
  48. $("#message_ajax_reponse").show();
  49. $("#send_message_div").dialog({ buttons:{}});
  50. $("#send_message_form").hide();
  51. $("#send_message_div").dialog("close");
  52. $("#subject_id").val("");
  53. $("#content_id").val("");
  54. }
  55. });
  56. }
  57. },
  58. },
  59. close: function() {
  60. }
  61. });
  62. $("#send_message_div").dialog("open");
  63. //prevent the browser to follow the link
  64. }
  65. function send_invitation_to_user(user_id) {
  66. var content = $( "#content_invitation_id" );
  67. $("#send_invitation_form").show();
  68. $("#send_invitation_div").dialog({
  69. modal:true,
  70. buttons: {
  71. "'.addslashes(get_lang('SendInvitation')).'": function() {
  72. var bValid = true;
  73. bValid = bValid && checkLength( content, "content", 1, 255 );
  74. if (bValid) {
  75. var url = "'.$ajax_url.'?a=send_invitation&user_id="+user_id;
  76. var params = $("#send_invitation_form").serialize();
  77. $.ajax({
  78. url: url+"&"+params,
  79. success:function(data) {
  80. $("#message_ajax_reponse").attr("class", "");
  81. $("#message_ajax_reponse").html(data);
  82. $("#message_ajax_reponse").show();
  83. $("#send_invitation_div").dialog({ buttons:{}});
  84. $("#send_invitation_form").hide();
  85. $("#send_invitation_div").dialog("close");
  86. $("#content_invitation_id").val("");
  87. }
  88. });
  89. }
  90. },
  91. },
  92. close: function() {
  93. }
  94. });
  95. $("#send_invitation_div").dialog("open");
  96. //prevent the browser to follow the link
  97. }
  98. $(document).ready(function (){
  99. $("input#id_btn_send_invitation").bind("click", function(){
  100. if (confirm("'.get_lang('SendMessageInvitation', '').'")) {
  101. $("#form_register_friend").submit();
  102. }
  103. });
  104. $("#send_message_div").dialog({
  105. autoOpen: false,
  106. modal : false,
  107. width : 550,
  108. height : 300
  109. });
  110. $("#send_invitation_div").dialog({
  111. autoOpen: false,
  112. modal : false,
  113. width : 550,
  114. height : 300
  115. });
  116. });
  117. </script>';
  118. if (api_get_setting('allow_social_tool') != 'true') {
  119. api_not_allowed();
  120. }
  121. $this_section = SECTION_SOCIAL;
  122. $tool_name = get_lang('Search');
  123. $interbreadcrumb[] = array('url' => 'profile.php', 'name' => get_lang('SocialNetwork'));
  124. $query = isset($_GET['q']) ? $_GET['q'] : null;
  125. $query_vars = array('q' => $query);
  126. $social_left_content = SocialManager::show_social_menu('search');
  127. $social_right_content = '<div class="span9">'.UserManager::get_search_form($query).'</div>';
  128. // I'm searching something
  129. if ($query != '') {
  130. $itemPerPage = 9;
  131. $page = isset($_GET['users_page_nr']) ? intval($_GET['users_page_nr']) : 1;
  132. $totalUsers = UserManager::get_all_user_tags($_GET['q'], 0, 0, $itemPerPage, true);
  133. $from = intval(($page - 1) * $itemPerPage);
  134. // Get users from tags
  135. $users = UserManager::get_all_user_tags($_GET['q'], 0, $from, $itemPerPage);
  136. $pageGroup = isset($_GET['groups_page_nr']) ? intval($_GET['groups_page_nr']) : 1;
  137. // Groups
  138. $fromGroups = intval(($pageGroup - 1) * $itemPerPage);
  139. $totalGroups = GroupPortalManager::get_all_group_tags($_GET['q'], 0, $itemPerPage, true);
  140. $groups = GroupPortalManager::get_all_group_tags($_GET['q'], $fromGroups, $itemPerPage);
  141. if (empty($users) && empty($groups)) {
  142. $social_right_content .= get_lang('SorryNoResults');
  143. }
  144. $results = '<div id="online_grid_container"><div class="span9">';
  145. if (is_array($users) && count($users) > 0) {
  146. $results .= Display::page_subheader(get_lang('Users'));
  147. $results .= '<ul class="thumbnails">';
  148. foreach ($users as $user) {
  149. $send_inv = '<button class="btn btn-mini disabled "><i class="icon-user"></i> '.get_lang('SendInvitation').'</button><br /><br />';
  150. $relation_type = intval(SocialManager::get_relation_between_contacts(api_get_user_id(), $user['user_id']));
  151. $user_info = api_get_user_info($user['user_id'], true);
  152. $url = api_get_path(WEB_PATH).'main/social/profile.php?u='.$user['user_id'];
  153. // Show send invitation icon if they are not friends yet
  154. if ($relation_type != 3 && $relation_type != 4 && $user['user_id'] != api_get_user_id()) {
  155. $send_inv = '<a href="javascript:void(0);" onclick="javascript:send_invitation_to_user(\''.$user['user_id'].'\');"/>
  156. <button class="btn btn-mini"><i class="icon-user"></i> '.get_lang('SendInvitation').'</button></a><br /><br />';
  157. }
  158. $send_msg = '<a href="javascript:void(0);" onclick="javascript:send_message_to_user(\''.$user['user_id'].'\');"/>
  159. <button class="btn btn-mini"><i class="icon-envelope"></i> '.get_lang('SendMessage').'</button></a>';
  160. if (empty($user['picture_uri'])) {
  161. $picture['file'] = api_get_path(WEB_CODE_PATH).'img/unknown.jpg';
  162. $img = '<img src="'.$picture['file'].'">';
  163. } else {
  164. $picture = UserManager::get_picture_user(
  165. $user['user_id'],
  166. $user['picture_uri'],
  167. 50,
  168. USER_IMAGE_SIZE_ORIGINAL
  169. );
  170. $img = '<img src="'.$picture['file'].'" width="100" height="100">';
  171. }
  172. if ($user_info['user_is_online']) {
  173. $status_icon = Display::span('', array('class' => 'online_user_in_text'));
  174. } else {
  175. $status_icon = Display::span('', array('class' => 'offline_user_in_text'));
  176. }
  177. $tag = isset($user['tag']) ? ' <br /><br />'.$user['tag'] : null;
  178. $user_info['complete_name'] = Display::url($status_icon.$user_info['complete_name'], $url);
  179. $invitations = $user['tag'].$send_inv.$send_msg;
  180. $results .= '<li class="span3">
  181. <div class="">
  182. <div class="row-fluid">
  183. <div class="span12">
  184. '.$user_info['complete_name'].'
  185. </div>
  186. <div class="span4">
  187. <div class="media">
  188. '.$img.'
  189. </div>
  190. </div>
  191. <div class="span5">
  192. <div class="media">
  193. '.$invitations.'
  194. </div>
  195. </div>
  196. </div>
  197. </div>
  198. </li>';
  199. }
  200. $results .= '</ul></div></div>';
  201. $social_right_content .= $results;
  202. }
  203. $visibility = array(true, true, true, true, true);
  204. $social_right_content .= Display::return_sortable_grid(
  205. 'users',
  206. null,
  207. null,
  208. array('hide_navigation' => false, 'per_page' => $itemPerPage),
  209. $query_vars,
  210. false,
  211. $visibility,
  212. true,
  213. array(),
  214. $totalUsers
  215. );
  216. $grid_groups = array();
  217. if (is_array($groups) && count($groups) > 0) {
  218. $social_right_content .= '<div class="span9">';
  219. $social_right_content .= Display::page_subheader(get_lang('Groups'));
  220. $social_right_content .= '<ul class="thumbnails">';
  221. foreach ($groups as $group) {
  222. $group['name'] = Security::remove_XSS($group['name'], STUDENT, true);
  223. $group['description'] = Security::remove_XSS($group['description'], STUDENT, true);
  224. $id = $group['id'];
  225. $url_open = '<a href="groups.php?id='.$id.'">';
  226. $url_close = '</a>';
  227. $name = cut($group['name'], 60, true);
  228. $count_users_group = count(GroupPortalManager::get_all_users_by_group($id));
  229. if ($count_users_group == 1) {
  230. $count_users_group = $count_users_group.' '.get_lang('Member');
  231. } else {
  232. $count_users_group = $count_users_group.' '.get_lang('Members');
  233. }
  234. $picture = GroupPortalManager::get_picture_group($group['id'], $group['picture_uri'], 80);
  235. $tags = GroupPortalManager::get_group_tags($group['id']);
  236. $group['picture_uri'] = '<img src="'.$picture['file'].'" width="50" />';
  237. $item_0 = Display::div($group['picture_uri']);
  238. $members = Display::span($count_users_group);
  239. $item_1 = Display::tag('h3', $url_open.$name.$url_close).$members;
  240. $social_right_content .= '
  241. <li class="span8">
  242. <div class="row-fluid">
  243. <div class="span1">
  244. <div class="media">
  245. '.$item_0.'
  246. </div>
  247. </div>
  248. <div class="span6">
  249. '.$item_1.'
  250. <p>'.$group['description'].'</p>
  251. <p>'.$tags.'</p>
  252. <p>'.$url_open.get_lang('SeeMore').$url_close.'</p>
  253. </div>
  254. </div>
  255. </li>';
  256. }
  257. $social_right_content .= '</ul></div></div>';
  258. }
  259. $visibility = array(true, true, true, true, true);
  260. $social_right_content .= Display::return_sortable_grid(
  261. 'groups',
  262. null,
  263. $grid_groups,
  264. array('hide_navigation' => false, 'per_page' => $itemPerPage),
  265. $query_vars,
  266. false,
  267. $visibility,
  268. true,
  269. array(),
  270. $totalGroups
  271. );
  272. }
  273. $social_right_content .= MessageManager::generate_message_form('send_message');
  274. $social_right_content .= MessageManager::generate_invitation_form('send_invitation');
  275. $tpl = new Template($tool_name);
  276. $tpl->assign('social_left_content', $social_left_content);
  277. $tpl->assign('social_right_content', $social_right_content);
  278. $social_layout = $tpl->get_template('layout/social_layout.tpl');
  279. $tpl->display($social_layout);