chat.ajax.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. if (api_get_setting('allow_global_chat') == 'false') {
  13. exit;
  14. }
  15. $to_user_id = isset($_REQUEST['to']) ? $_REQUEST['to'] : null;
  16. $message = isset($_REQUEST['message']) ? $_REQUEST['message'] : null;
  17. if (!isset($_SESSION['chatHistory'])) {
  18. $_SESSION['chatHistory'] = array();
  19. }
  20. if (!isset($_SESSION['openChatBoxes'])) {
  21. $_SESSION['openChatBoxes'] = array();
  22. }
  23. $chat = new Chat();
  24. if ($chat->is_chat_blocked_by_exercises()) {
  25. //Desconnecting the user
  26. $chat->set_user_status(0);
  27. exit;
  28. }
  29. switch ($action) {
  30. case 'chatheartbeat':
  31. $chat->heartbeat();
  32. break;
  33. case 'closechat':
  34. $chat->close();
  35. break;
  36. case 'sendchat':
  37. $chat->send(api_get_user_id(), $to_user_id, $message);
  38. break;
  39. case 'startchatsession':
  40. $chat->start_session();
  41. break;
  42. case 'set_status':
  43. $status = isset($_REQUEST['status']) ? intval($_REQUEST['status']) : 0;
  44. $chat->set_user_status($status);
  45. break;
  46. default:
  47. echo '';
  48. }
  49. exit;