chat_functions.lib.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004-2008 Dokeos SPRL
  6. Copyright (c) 2003 Ghent University (UGent)
  7. Copyright (c) 2001 Universite catholique de Louvain (UCL)
  8. Copyright (c) various contributors
  9. For a full list of contributors, see "credits.txt".
  10. The full license can be read in "license.txt".
  11. This program is free software; you can redistribute it and/or
  12. modify it under the terms of the GNU General Public License
  13. as published by the Free Software Foundation; either version 2
  14. of the License, or (at your option) any later version.
  15. See the GNU General Public License for more details.
  16. Contact address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium
  17. Mail: info@dokeos.com
  18. ==============================================================================
  19. */
  20. /**
  21. * @author isaac flores paz
  22. * @param integer
  23. * @return void
  24. */
  25. function exit_of_chat ($user_id) {
  26. $list_course=array();
  27. $list_course=CourseManager::get_courses_list_by_user_id($user_id);
  28. foreach($list_course as $courses) {
  29. $response=user_connected_in_chat($user_id,$courses['db_name']);
  30. if ($response===true) {
  31. $tbl_chat_connected = Database::get_course_chat_connected_table($courses['db_name']);;
  32. $sql='DELETE FROM '.$tbl_chat_connected.' WHERE user_id='.$user_id;
  33. api_sql_query($sql,__FILE__,__LINE__);
  34. }
  35. }
  36. }
  37. /**
  38. * @author isaac flores paz
  39. * @param integer the user id
  40. * @param string the database name
  41. * @return boolean
  42. */
  43. function user_connected_in_chat ($user_id,$database_name) {
  44. $tbl_chat_connected = Database::get_course_chat_connected_table($database_name);
  45. $sql='SELECT COUNT(*) AS count FROM '.$tbl_chat_connected .' c WHERE user_id='.$user_id;
  46. $result = api_sql_query($sql,__FILE__,__LINE__);
  47. $count = Database::fetch_array($result,'ASSOC');
  48. if (1==$count['count']) {
  49. return true;
  50. } else {
  51. return false;
  52. }
  53. }
  54. /**
  55. * @param void
  56. * @return void
  57. */
  58. function disconnect_user_of_chat () {
  59. $list_info_user_in_chat = array();
  60. $list_info_user_in_chat = users_list_in_chat ();
  61. $cd_date = date('Y-m-d',time());
  62. $cdate_h = date('H',time());
  63. $cdate_m = date('i',time());
  64. $cdate_s = date('s',time());
  65. $cd_count_time_seconds=$cdate_h*3600 + $cdate_m*60 + $cdate_s;
  66. foreach ($list_info_user_in_chat as $list_info_user) {
  67. $date_db_date = date('Y-m-d',strtotime($list_info_user['last_connection']));
  68. $date_db_h = date('H',strtotime($list_info_user['last_connection']));
  69. $date_db_m = date('i',strtotime($list_info_user['last_connection']));
  70. $date_db_s = date('s',strtotime($list_info_user['last_connection']));
  71. $date_count_time_seconds=$date_db_h*3600 + $date_db_m*60 + $date_db_s;
  72. if ($cd_date==$date_db_date) {
  73. if (($cd_count_time_seconds - $date_count_time_seconds)>10) {
  74. $tbl_chat_connected = Database::get_course_chat_connected_table();
  75. $sql='DELETE FROM '.$tbl_chat_connected.' WHERE user_id='.$list_info_user['user_id'];
  76. api_sql_query($sql,__FILE__,__LINE__);
  77. }
  78. }
  79. }
  80. }
  81. /**
  82. * @param void
  83. * @return array user list in chat
  84. */
  85. function users_list_in_chat () {
  86. $list_users_in_chat=array();
  87. $tbl_chat_connected = Database::get_course_chat_connected_table();
  88. $sql='SELECT user_id,last_connection FROM '.$tbl_chat_connected.' ;';
  89. $result=api_sql_query($sql,__FILE__,__LINE__);
  90. while ($row = Database::fetch_array($result,'ASSOC')) {
  91. $list_users_in_chat[]=$row;
  92. }
  93. return $list_users_in_chat;
  94. }
  95. ?>