message.ajax.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Responses to AJAX calls
  5. */
  6. require_once '../global.inc.php';
  7. $action = $_GET['a'];
  8. switch ($action) {
  9. case 'send_message':
  10. $subject = isset($_REQUEST['subject']) ? trim($_REQUEST['subject']) : null;
  11. $messageContent = isset($_REQUEST['content']) ? trim($_REQUEST['content']) : null;
  12. if (empty($subject) || empty($messageContent)) {
  13. echo Display::display_error_message(get_lang('ErrorSendingMessage'));
  14. exit;
  15. }
  16. $result = MessageManager::send_message($_REQUEST['user_id'], $subject, $messageContent);
  17. if ($result) {
  18. echo Display::display_confirmation_message(get_lang('MessageHasBeenSent'));
  19. } else {
  20. echo Display::display_error_message(get_lang('ErrorSendingMessage'));
  21. }
  22. break;
  23. case 'send_invitation':
  24. $subject = isset($_REQUEST['subject']) ? trim($_REQUEST['subject']) : null;
  25. $invitationContent = isset($_REQUEST['content']) ? trim($_REQUEST['content']) : null;
  26. SocialManager::send_invitation_friend_user($_REQUEST['user_id'], $subject, $invitationContent);
  27. break;
  28. case 'find_users':
  29. if (api_is_anonymous()) {
  30. echo '';
  31. break;
  32. }
  33. $track_online_table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ONLINE);
  34. $tbl_my_user = Database::get_main_table(TABLE_MAIN_USER);
  35. $tbl_my_user_friend = Database::get_main_table(TABLE_MAIN_USER_REL_USER);
  36. $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
  37. $tbl_access_url_rel_user = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
  38. $search = Database::escape_string($_REQUEST['tag']);
  39. $access_url_id = api_get_multiple_access_url() == 'true' ? api_get_current_access_url_id() : 1;
  40. $user_id = api_get_user_id();
  41. $is_western_name_order = api_is_western_name_order();
  42. $likeCondition = " AND (firstname LIKE '%$search%' OR lastname LIKE '%$search%' OR email LIKE '%$search%') ";
  43. if (api_get_setting('allow_social_tool')=='true' && api_get_setting('allow_message_tool') == 'true') {
  44. // All users
  45. if (api_get_setting('allow_send_message_to_all_platform_users') == 'true' || api_is_platform_admin() ) {
  46. if ($access_url_id != 0) {
  47. $sql = "SELECT DISTINCT u.user_id as id, u.firstname, u.lastname, u.email
  48. FROM $tbl_user u LEFT JOIN $tbl_access_url_rel_user r ON u.user_id = r.user_id
  49. WHERE
  50. u.status <> 6 AND
  51. u.user_id <> $user_id AND
  52. r.access_url_id = $access_url_id
  53. $likeCondition ";
  54. } else {
  55. $sql = "SELECT DISTINCT u.user_id as id, u.firstname, u.lastname, u.email
  56. FROM $tbl_user u
  57. WHERE
  58. u.status <> 6 AND
  59. u.user_id <> $user_id
  60. $likeCondition ";
  61. }
  62. } else {
  63. //only my contacts
  64. if ($access_url_id != 0) {
  65. $sql = "SELECT DISTINCT u.user_id as id, u.firstname, u.lastname, u.email
  66. FROM $tbl_access_url_rel_user r, $tbl_my_user_friend uf
  67. INNER JOIN $tbl_my_user AS u
  68. ON uf.friend_user_id = u.user_id
  69. WHERE
  70. u.status <> 6 AND
  71. relation_type NOT IN(".USER_RELATION_TYPE_DELETED.", ".USER_RELATION_TYPE_RRHH.") AND
  72. uf.user_id = $user_id AND
  73. friend_user_id <> $user_id AND
  74. u.user_id = r.user_id AND
  75. r.access_url_id = $access_url_id
  76. $likeCondition";
  77. } else {
  78. $sql = "SELECT DISTINCT u.user_id as id, u.firstname, u.lastname, u.email
  79. FROM $tbl_my_user_friend uf
  80. INNER JOIN $tbl_my_user AS u
  81. ON uf.friend_user_id = u.user_id
  82. WHERE
  83. u.status <> 6 AND
  84. relation_type NOT IN(".USER_RELATION_TYPE_DELETED.", ".USER_RELATION_TYPE_RRHH.") AND
  85. uf.user_id = $user_id AND
  86. friend_user_id <> $user_id
  87. $likeCondition";
  88. }
  89. }
  90. } elseif (api_get_setting('allow_social_tool')=='false' && api_get_setting('allow_message_tool')=='true') {
  91. if (api_get_setting('allow_send_message_to_all_platform_users') == 'true') {
  92. $sql = "SELECT DISTINCT u.user_id as id, u.firstname, u.lastname, u.email
  93. FROM $tbl_user u LEFT JOIN $tbl_access_url_rel_user r ON u.user_id = r.user_id
  94. WHERE
  95. u.status <> 6 AND
  96. u.user_id <> $user_id AND
  97. r.access_url_id = $access_url_id
  98. $likeCondition ";
  99. } else {
  100. $time_limit = api_get_setting('time_limit_whosonline');
  101. $online_time = time() - $time_limit*60;
  102. $limit_date = api_get_utc_datetime($online_time);
  103. $sql = "SELECT SELECT DISTINCT u.user_id as id, u.firstname, u.lastname, u.email
  104. FROM $tbl_my_user u INNER JOIN $track_online_table t
  105. ON u.user_id=t.login_user_id
  106. WHERE login_date >= '".$limit_date."' AND
  107. $likeCondition";
  108. }
  109. }
  110. $sql .=' LIMIT 20';
  111. $result = Database::query($sql);
  112. $showEmail = api_get_setting('show_email_addresses');
  113. $return = array();
  114. if (Database::num_rows($result) > 0) {
  115. while ($row = Database::fetch_array($result, 'ASSOC')) {
  116. $name = api_get_person_name($row['firstname'], $row['lastname']);
  117. if ($showEmail == 'true') {
  118. $name .= ' ('.$row['email'].')';
  119. }
  120. $return[] = array(
  121. 'caption' => $name,
  122. 'value' => $row['id']
  123. );
  124. }
  125. }
  126. echo json_encode($return);
  127. break;
  128. default:
  129. echo '';
  130. }
  131. exit;