dokeos-whoisonline
[ class tree: dokeos-whoisonline ] [ index: dokeos-whoisonline ] [ all elements ]

Source for file online.inc.php

Documentation is available at online.inc.php

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

Documentation generated on Thu, 12 Jun 2008 14:08:14 -0500 by phpDocumentor 1.4.1