chat_hidden.php 3.9 KB

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