online.inc.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. <?php
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004-2005 Dokeos S.A.
  6. Copyright (c) Istvan Mandak
  7. For a full list of contributors, see "credits.txt".
  8. The full license can be read in "license.txt".
  9. This program is free software; you can redistribute it and/or
  10. modify it under the terms of the GNU General Public License
  11. as published by the Free Software Foundation; either version 2
  12. of the License, or (at your option) any later version.
  13. See the GNU General Public License for more details.
  14. Contact address: Dokeos, 44 rue des palais, B-1030 Brussels, Belgium
  15. Mail: info@dokeos.com
  16. ==============================================================================
  17. */
  18. /**
  19. ==============================================================================
  20. * Code library for showing Who is online
  21. *
  22. * @author Istvan Mandak, principal author
  23. * @author Denes Nagy, principal author
  24. * @author Bart Mollet
  25. * @author Roan Embrechts, cleaning and bugfixing
  26. * @package dokeos.whoisonline
  27. ==============================================================================
  28. */
  29. function LoginCheck($uid,$statsDbName)
  30. {
  31. global $_course;
  32. $online_table = Database::get_statistic_table(STATISTIC_TRACK_E_ONLINE_TABLE);
  33. if ($uid!="")
  34. {
  35. LoginDelete($uid,$statsDbName);
  36. $login_ip = $_SERVER['REMOTE_ADDR'];
  37. $reallyNow = time();
  38. $login_date = date("Y-m-d H:i:s",$reallyNow);
  39. // if the $_course array exists this means we are in a course and we have to store this in the who's online table also
  40. // to have the x users in this course feature working
  41. if ($_course)
  42. {
  43. $query = "INSERT INTO ".$online_table ." (login_id,login_user_id,login_date,login_ip, course) VALUES ($uid,$uid,'$login_date','$login_ip', '".$_course['id']."')";
  44. }
  45. else
  46. {
  47. $query = "INSERT INTO ".$online_table ." (login_id,login_user_id,login_date,login_ip) VALUES ($uid,$uid,'$login_date','$login_ip')";
  48. }
  49. @api_sql_query($query,__FILE__,__LINE__);
  50. }
  51. }
  52. function LoginDelete($uid,$statsDbName)
  53. {
  54. $online_table = Database::get_statistic_table(STATISTIC_TRACK_E_ONLINE_TABLE);
  55. $query = "DELETE FROM ".$online_table ." WHERE login_user_id = '$uid'";
  56. @api_sql_query($query,__FILE__,__LINE__);
  57. }
  58. /**
  59. * @todo remove parameter $statsDbName which is no longer necessary
  60. */
  61. function WhoIsOnline($uid,$statsDbName,$valid)
  62. {
  63. $track_online_table = Database::get_statistic_table(STATISTIC_TRACK_E_ONLINE_TABLE);
  64. $query = "SELECT login_user_id,login_date FROM ".$track_online_table ." WHERE DATE_ADD(login_date,INTERVAL $valid MINUTE) >= NOW() ";
  65. $result = @api_sql_query($query,__FILE__,__LINE__);
  66. if (count($result)>0)
  67. {
  68. $rtime = time();
  69. $rdate = date("Y-m-d H:i:s",$rtime);
  70. $validtime = mktime(date("H"),date("i")-$valid,date("s"),date("m"),date("d"),date("Y"));
  71. $rarray = array();
  72. while(list($login_user_id,$login_date)= mysql_fetch_row($result))
  73. {
  74. $barray = array();
  75. array_push($barray,$login_user_id);
  76. array_push($barray,$login_date);
  77. // YYYY-MM-DD HH:MM:SS, db date format
  78. $hour = substr($login_date,11,2);
  79. $minute = substr($login_date,14,2);
  80. $secund = substr($login_date,17,2);
  81. $month = substr($login_date,5,2);
  82. $day = substr($login_date,8,2);
  83. $year = substr($login_date,0,4);
  84. // db timestamp
  85. $dbtime = mktime($hour,$minute,$secund,$month,$day,$year);
  86. if ($dbtime>$validtime)
  87. {
  88. array_push($rarray,$barray);
  89. }
  90. //echo $dbtime.":".$rtime.">".$validtime."<BR>";
  91. //echo "$login_user_id.":".$login_date.";";
  92. }
  93. return $rarray;
  94. }
  95. else
  96. {
  97. return false;
  98. }
  99. }
  100. function GetFullUserName($uid)
  101. {
  102. $user_table = Database::get_main_table(MAIN_USER_TABLE);
  103. $query = "SELECT `firstname`,`lastname` FROM ".$user_table." WHERE `user_id`='$uid'";
  104. $result = @api_sql_query($query,__FILE__,__LINE__);
  105. if (count($result)>0)
  106. {
  107. $str = "";
  108. while(list($firstname,$lastname)= mysql_fetch_array($result))
  109. {
  110. $str = $lastname."&nbsp;".$firstname;
  111. return $str;
  112. }
  113. }
  114. }
  115. function GetURL($path)
  116. {
  117. $str = "";
  118. $url = explode('/',$path);
  119. for($i=0;$i < sizeof($url)-2; $i++)
  120. {
  121. if($i==sizeof($url)-3)
  122. {$str = $str.$url[$i]; }
  123. else
  124. {
  125. $str = $str.$url[$i]."/";
  126. }
  127. }
  128. return $str;
  129. }
  130. // picture?
  131. function IsValidUser($uid)
  132. {
  133. $user_table = Database::get_main_table(MAIN_USER_TABLE);
  134. $query = "SELECT `picture_uri` FROM ".$user_table." WHERE `user_id`='$uid'";
  135. $result = @api_sql_query($query,__FILE__,__LINE__);
  136. if (count($result)>0)
  137. {
  138. while(list($picture_uri)= mysql_fetch_array($result))
  139. {
  140. if (count($picture_uri)>0)
  141. {
  142. return true;
  143. }
  144. else
  145. {
  146. return false;
  147. }
  148. }
  149. }
  150. else
  151. {
  152. return false;
  153. }
  154. }
  155. function ClearURL($path)
  156. {
  157. $url = explode('?id=',$path);
  158. return $url[0];
  159. }
  160. function chatcall() {
  161. global $_uid, $_cid;
  162. if (!$_uid)
  163. {
  164. return (false);
  165. }
  166. $track_user_table = Database::get_main_table(MAIN_USER_TABLE);
  167. $sql="select chatcall_user_id, chatcall_date from $track_user_table where ( user_id = $_uid )";
  168. $result=api_sql_query($sql,__FILE__,__LINE__);
  169. $row=mysql_fetch_array($result);
  170. $login_date=$row['chatcall_date'];
  171. $hour = substr($login_date,11,2);
  172. $minute = substr($login_date,14,2);
  173. $secund = substr($login_date,17,2);
  174. $month = substr($login_date,5,2);
  175. $day = substr($login_date,8,2);
  176. $year = substr($login_date,0,4);
  177. $calltime = mktime($hour,$minute,$secund,$month,$day,$year);
  178. $time = time();
  179. $time = date("Y-m-d H:i:s", $time);
  180. $minute_passed=5; //within this limit, the chat call request is valid
  181. $limittime = mktime(date("H"),date("i")-$minute_passed,date("s"),date("m"),date("d"),date("Y"));
  182. if (($row['chatcall_user_id']) and ($calltime>$limittime)) {
  183. $webpath=api_get_path(WEB_CODE_PATH);
  184. $message=get_lang('YouWereCalled').' : '.GetFullUserName($row['chatcall_user_id'],'').'<br>'.get_lang('DoYouAccept')
  185. ."<p>"
  186. ."<a href=\"".$webpath."chat/chat.php?cidReq=".$_cid."&origin=whoisonlinejoin\">"
  187. . get_lang("Yes")
  188. ."</a>"
  189. ."&nbsp;&nbsp;|&nbsp;&nbsp;"
  190. ."<a href=\"".api_get_path('WEB_PATH')."webchatdeny.php\">"
  191. . get_lang("No")
  192. ."</a>"
  193. ."</p>";
  194. return($message);
  195. }
  196. else
  197. {
  198. return(false);
  199. }
  200. }
  201. /**
  202. * Returns a list (array) of users who are online and in this course.
  203. */
  204. function who_is_online_in_this_course($uid, $valid, $coursecode)
  205. {
  206. $track_online_table = Database::get_statistic_table(STATISTIC_TRACK_E_ONLINE_TABLE);
  207. $query = "SELECT login_user_id,login_date FROM ".$track_online_table ." WHERE course='".$coursecode."' AND DATE_ADD(login_date,INTERVAL $valid MINUTE) >= NOW() ";
  208. $result = api_sql_query($query,__FILE__,__LINE__);
  209. if (count($result)>0)
  210. {
  211. $rtime = time();
  212. $rdate = date("Y-m-d H:i:s",$rtime);
  213. $validtime = mktime(date("H"),date("i")-$valid,date("s"),date("m"),date("d"),date("Y"));
  214. $rarray = array();
  215. while(list($login_user_id,$login_date)= mysql_fetch_row($result))
  216. {
  217. $barray = array();
  218. array_push($barray,$login_user_id);
  219. array_push($barray,$login_date);
  220. // YYYY-MM-DD HH:MM:SS, db date format
  221. $hour = substr($login_date,11,2);
  222. $minute = substr($login_date,14,2);
  223. $secund = substr($login_date,17,2);
  224. $month = substr($login_date,5,2);
  225. $day = substr($login_date,8,2);
  226. $year = substr($login_date,0,4);
  227. // db timestamp
  228. $dbtime = mktime($hour,$minute,$secund,$month,$day,$year);
  229. if ($dbtime >= $validtime)
  230. {
  231. array_push($rarray,$barray);
  232. }
  233. //echo $dbtime.":".$rtime.">".$validtime."<BR>";
  234. //echo "$login_user_id.":".$login_date.";";
  235. }
  236. return $rarray;
  237. }
  238. else
  239. {
  240. return false;
  241. }
  242. }
  243. ?>