chat_hidden.php 4.2 KB

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