chat_hidden.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Hidden frame that refreshes the visible frames when a modification occurs
  5. *
  6. * @author Olivier Brouckaert
  7. * @package chamilo.chat
  8. */
  9. use ChamiloSession as Session;
  10. define('FRAME', 'hidden');
  11. //require_once '../inc/global.inc.php';
  12. require_once 'chat_functions.lib.php';
  13. $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
  14. $tbl_chat_connected = Database::get_course_table(TABLE_CHAT_CONNECTED);
  15. $userId = api_get_user_id();
  16. $course_id = api_get_course_int_id();
  17. $query = "SELECT username FROM $tbl_user WHERE user_id='".$userId."'";
  18. $result = Database::query($query);
  19. list($pseudo_user) = Database::fetch_row($result);
  20. $isAllowed = !(empty($pseudo_user) || !$_cid);
  21. $isMaster = (bool)api_is_course_admin();
  22. $date_now = date('Y-m-d');
  23. $group_id = api_get_group_id();
  24. $session_id = api_get_session_id();
  25. $session_condition = api_get_session_condition($session_id);
  26. $group_condition = " AND to_group_id = '$group_id'";
  27. $extra_condition = '';
  28. if (!empty($group_id)) {
  29. $extra_condition = $group_condition;
  30. } else {
  31. $extra_condition = $session_condition;
  32. }
  33. $extra_condition.= " AND c_id = $course_id";
  34. // get chat path
  35. $chat_path = '';
  36. $document_path = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
  37. if (!empty($group_id)) {
  38. $group_info = GroupManager :: get_group_properties($group_id);
  39. $chat_path = $document_path.$group_info['directory'].'/chat_files/';
  40. } else {
  41. $chat_path = $document_path.'/chat_files/';
  42. }
  43. // get chat file
  44. $basename_chat = '';
  45. if (!empty($group_id)) {
  46. $basename_chat = 'messages-'.$date_now.'_gid-'.$group_id;
  47. } elseif (!empty($session_id)) {
  48. $basename_chat = 'messages-'.$date_now.'_sid-'.$session_id;
  49. } else {
  50. $basename_chat = 'messages-'.$date_now;
  51. }
  52. $chat_size_old = isset($_POST['chat_size_old']) ? intval($_POST['chat_size_old']) : null;
  53. $file = $chat_path.$basename_chat.'.log.html';
  54. $chat_size_new = 0;
  55. if (file_exists($file)) {
  56. $chat_size_new = filesize($file);
  57. }
  58. $sql = "SELECT user_id FROM $tbl_chat_connected
  59. WHERE user_id='".$userId."' $extra_condition";
  60. $result = Database::query($sql);
  61. // The user_id exists so we must do an UPDATE and not a INSERT
  62. $current_time = api_get_utc_datetime();
  63. if (Database::num_rows($result) == 0) {
  64. $query = "INSERT INTO $tbl_chat_connected(c_id, user_id, last_connection,session_id,to_group_id)
  65. VALUES($course_id, '".$userId."','$current_time','$session_id','$group_id')";
  66. Database::query($query);
  67. $id = Database::insert_id();
  68. if ($id) {
  69. $sql = "UPDATE $tbl_chat_connected SET id = iid WHERE iid = $id";
  70. Database::query($sql);
  71. }
  72. } else {
  73. $query = "UPDATE $tbl_chat_connected SET
  74. last_connection='".$current_time."'
  75. WHERE c_id = $course_id AND user_id='".$userId."' AND session_id='$session_id' AND to_group_id='$group_id'";
  76. Database::query($query);
  77. }
  78. $query = "SELECT COUNT(user_id) FROM $tbl_chat_connected
  79. WHERE last_connection>'".date('Y-m-d H:i:s',time()-60*5)."' $extra_condition";
  80. $result = Database::query($query);
  81. $connected_old = isset($_POST['connected_old']) ? intval($_POST['connected_old']) : null;
  82. list($connected_new) = Database::fetch_row($result);
  83. /*disconnected user of chat*/
  84. disconnect_user_of_chat();
  85. require 'header_frame.inc.php';
  86. ?>
  87. <form name="formHidden" method="post" action="<?php echo api_get_self().'?'.api_get_cidreq(); ?>">
  88. <input type="hidden" name="chat_size_old" value="<?php echo $chat_size_new; ?>">
  89. <input type="hidden" name="connected_old" value="<?php echo $connected_new; ?>">
  90. </form>
  91. <?php
  92. $origin = Session::read('origin');
  93. if ($origin == 'whoisonline') {
  94. //check if our target has denied our request or not
  95. $talk_to = Session::read('target');
  96. $track_user_table = Database::get_main_table(TABLE_MAIN_USER);
  97. $sql = "select chatcall_text from $track_user_table where ( user_id = $talk_to )";
  98. $result = Database::query($sql);
  99. $row = Database::fetch_array($result);
  100. if ($row['chatcall_text'] == 'DENIED') {
  101. echo "<script language=\"javascript\" type=\"text/javascript\"> alert('".get_lang('ChatDenied')."'); </script>";
  102. $sql = "update $track_user_table set chatcall_user_id = '', chatcall_date = '', chatcall_text='' WHERE (user_id = $talk_to)";
  103. $result = Database::query($sql);
  104. }
  105. }
  106. require 'footer_frame.inc.php';