chat.ajax.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Responses to AJAX calls
  5. */
  6. $_dont_save_user_course_access = true;
  7. $action = isset($_GET['action']) ? $_GET['action'] : null;
  8. if (api_is_anonymous()) {
  9. exit;
  10. }
  11. if (api_get_setting('allow_global_chat') == 'false') {
  12. exit;
  13. }
  14. $to_user_id = isset($_GET['to']) ? $_GET['to'] : null;
  15. $message = isset($_GET['message']) ? $_GET['message'] : null;
  16. if (!isset($_SESSION['chatHistory'])) {
  17. $_SESSION['chatHistory'] = array();
  18. }
  19. if (!isset($_SESSION['openChatBoxes'])) {
  20. $_SESSION['openChatBoxes'] = array();
  21. }
  22. $chat = new Chat();
  23. if ($chat->is_chat_blocked_by_exercises()) {
  24. // Disconnect the user
  25. $chat->set_user_status(0);
  26. exit;
  27. }
  28. switch ($action) {
  29. case 'chatheartbeat':
  30. $chat->heartbeat();
  31. break;
  32. case 'closechat':
  33. $chat->close();
  34. break;
  35. case 'sendchat':
  36. $chat->send(api_get_user_id(), $to_user_id, $message);
  37. break;
  38. case 'startchatsession':
  39. $chat->start_session();
  40. break;
  41. case 'set_status':
  42. $status = isset($_REQUEST['status']) ? intval($_REQUEST['status']) : 0;
  43. $chat->set_user_status($status);
  44. break;
  45. default:
  46. echo '';
  47. }
  48. exit;