chat.ajax.php 1.1 KB

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