chat.ajax.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Responses to AJAX calls
  5. */
  6. $_dont_save_user_course_access = true;
  7. require_once '../global.inc.php';
  8. $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null;
  9. if (api_is_anonymous()) {
  10. exit;
  11. }
  12. // Course Chat
  13. if ($action == 'preview') {
  14. require_once api_get_path(SYS_PATH).'vendor/autoload.php';
  15. require_once api_get_path(SYS_CODE_PATH).'chat/chat_functions.lib.php';
  16. echo saveMessage(
  17. $_REQUEST['message'],
  18. api_get_user_id(),
  19. api_get_course_info(),
  20. api_get_session_id(),
  21. api_get_group_id(),
  22. true
  23. );
  24. }
  25. if (api_get_setting('allow_global_chat') == 'false') {
  26. exit;
  27. }
  28. $to_user_id = isset($_REQUEST['to']) ? $_REQUEST['to'] : null;
  29. $message = isset($_REQUEST['message']) ? $_REQUEST['message'] : null;
  30. if (!isset($_SESSION['chatHistory'])) {
  31. $_SESSION['chatHistory'] = array();
  32. }
  33. if (!isset($_SESSION['openChatBoxes'])) {
  34. $_SESSION['openChatBoxes'] = array();
  35. }
  36. $chat = new Chat();
  37. if ($chat->is_chat_blocked_by_exercises()) {
  38. //Disconnecting the user
  39. $chat->set_user_status(0);
  40. exit;
  41. }
  42. switch ($action) {
  43. case 'chatheartbeat':
  44. $chat->heartbeat();
  45. break;
  46. case 'closechat':
  47. $chat->close();
  48. break;
  49. case 'sendchat':
  50. $chat->send(api_get_user_id(), $to_user_id, $message);
  51. break;
  52. case 'startchatsession':
  53. $chat->start_session();
  54. break;
  55. case 'set_status':
  56. $status = isset($_REQUEST['status']) ? intval($_REQUEST['status']) : 0;
  57. $chat->set_user_status($status);
  58. break;
  59. default:
  60. echo '';
  61. }
  62. exit;