message.ajax.php 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Responses to AJAX calls
  5. */
  6. $language_file = array('messages','userInfo');
  7. require_once '../global.inc.php';
  8. $action = $_GET['a'];
  9. switch ($action) {
  10. case 'send_message':
  11. $result = MessageManager::send_message($_REQUEST['user_id'], $_REQUEST['subject'], $_REQUEST['content']);
  12. if ($result) {
  13. echo Display::display_confirmation_message(get_lang('MessageHasBeenSent'));
  14. } else {
  15. echo Display::display_error_message(get_lang('ErrorSendingMessage'));
  16. }
  17. break;
  18. case 'send_invitation':
  19. SocialManager::send_invitation_friend_user($_REQUEST['user_id'], $_REQUEST['subject'], $_REQUEST['content']);
  20. break;
  21. case 'find_users':
  22. if (api_is_anonymous()) {
  23. echo '';
  24. break;
  25. }
  26. $track_online_table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ONLINE);
  27. $tbl_my_user = Database::get_main_table(TABLE_MAIN_USER);
  28. $tbl_my_user_friend = Database::get_main_table(TABLE_MAIN_USER_REL_USER);
  29. $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
  30. $search = Database::escape_string($_REQUEST['tag']);
  31. $user_id = api_get_user_id();
  32. $is_western_name_order = api_is_western_name_order();
  33. if (api_get_setting('allow_social_tool')=='true' && api_get_setting('allow_message_tool') == 'true') {
  34. //all users
  35. if (api_get_setting('allow_send_message_to_all_platform_users') == 'true' || api_is_platform_admin() ) {
  36. $sql = 'SELECT DISTINCT u.user_id as id, '.($is_western_name_order ? 'concat(u.firstname," ",u.lastname," ","( ",u.email," )")' : 'concat(u.lastname," ",u.firstname," ","( ",u.email," )")').' as name
  37. FROM '.$tbl_user.' u
  38. WHERE u.status <> 6 AND u.user_id <>'.$user_id.' AND '.($is_western_name_order ? 'concat(u.firstname, " ", u.lastname)' : 'concat(u.lastname, " ", u.firstname)').' LIKE CONCAT("%","'.$search.'","%") ';
  39. } else {
  40. //only my contacts
  41. $sql = 'SELECT DISTINCT u.user_id as id, '.($is_western_name_order ? 'concat(u.firstname," ",u.lastname," ","( ",u.email," )")' : 'concat(u.lastname," ",u.firstname," ","( ",u.email," )")').' as name
  42. FROM '.$tbl_my_user_friend.' uf INNER JOIN '.$tbl_my_user.' AS u ON uf.friend_user_id = u.user_id ' .
  43. 'WHERE u.status <> 6 AND relation_type NOT IN('.USER_RELATION_TYPE_DELETED.', '.USER_RELATION_TYPE_RRHH.')
  44. AND uf.user_id = '.$user_id.' AND friend_user_id<>'.$user_id.'
  45. AND '.($is_western_name_order ? 'concat(u.firstname, " ", u.lastname)' : 'concat(u.lastname, " ", u.firstname)').' LIKE CONCAT("%","'.$search.'","%") ';
  46. }
  47. } elseif (api_get_setting('allow_social_tool')=='false' && api_get_setting('allow_message_tool')=='true') {
  48. $time_limit = api_get_setting('time_limit_whosonline');
  49. $online_time = time() - $time_limit*60;
  50. $limit_date = api_get_utc_datetime($online_time);
  51. $sql='SELECT DISTINCT u.user_id as id, '.($is_western_name_order ? 'concat(u.firstname," ",u.lastname," ","( ",u.email," )")' : 'concat(u.lastname," ",u.firstname," ","( ",u.email," )")').' as name
  52. FROM '.$tbl_my_user.' u INNER JOIN '.$track_online_table.' t ON u.user_id=t.login_user_id
  53. WHERE login_date >= "'.$limit_date.'" AND '.($is_western_name_order ? 'concat(u.firstname, " ", u.lastname)' : 'concat(u.lastname, " ", u.firstname)').' LIKE CONCAT("%","'.$search.'","%") ';
  54. }
  55. $sql .=' LIMIT 20';
  56. $result=Database::query($sql);
  57. $return = array();
  58. if (Database::num_rows($result) > 0) {
  59. while ($row = Database::fetch_array($result,'ASSOC')) {
  60. $return[] = array(
  61. 'key' => $row['id'],
  62. 'value' => $row['name']
  63. );
  64. }
  65. }
  66. echo json_encode($return);
  67. break;
  68. default:
  69. echo '';
  70. }
  71. exit;