chat.ajax.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 = $_REQUEST['to'];
  16. $message = $_REQUEST['message'];
  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;