123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275 |
- <?php
- /*
- ==============================================================================
- Dokeos - elearning and course management software
-
- Copyright (c) 2004-2005 Dokeos S.A.
- Copyright (c) Istvan Mandak
-
- For a full list of contributors, see "credits.txt".
- The full license can be read in "license.txt".
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- as published by the Free Software Foundation; either version 2
- of the License, or (at your option) any later version.
-
- See the GNU General Public License for more details.
-
- Contact address: Dokeos, 44 rue des palais, B-1030 Brussels, Belgium
- Mail: info@dokeos.com
- ==============================================================================
- */
- /**
- ==============================================================================
- * Code library for showing Who is online
- *
- * @author Istvan Mandak, principal author
- * @author Denes Nagy, principal author
- * @author Bart Mollet
- * @author Roan Embrechts, cleaning and bugfixing
- * @package dokeos.whoisonline
- ==============================================================================
- */
- function LoginCheck($uid,$statsDbName)
- {
- global $_course;
-
- $online_table = Database::get_statistic_table(STATISTIC_TRACK_E_ONLINE_TABLE);
- if ($uid!="")
- {
- LoginDelete($uid,$statsDbName);
- $login_ip = $_SERVER['REMOTE_ADDR'];
- $reallyNow = time();
- $login_date = date("Y-m-d H:i:s",$reallyNow);
- // 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
- // to have the x users in this course feature working
- if ($_course)
- {
- $query = "INSERT INTO ".$online_table ." (login_id,login_user_id,login_date,login_ip, course) VALUES ($uid,$uid,'$login_date','$login_ip', '".$_course['id']."')";
- }
- else
- {
- $query = "INSERT INTO ".$online_table ." (login_id,login_user_id,login_date,login_ip) VALUES ($uid,$uid,'$login_date','$login_ip')";
- }
- @api_sql_query($query,__FILE__,__LINE__);
- }
- }
- function LoginDelete($uid,$statsDbName)
- {
- $online_table = Database::get_statistic_table(STATISTIC_TRACK_E_ONLINE_TABLE);
- $query = "DELETE FROM ".$online_table ." WHERE login_user_id = '$uid'";
- @api_sql_query($query,__FILE__,__LINE__);
- }
- /**
- * @todo remove parameter $statsDbName which is no longer necessary
- */
- function WhoIsOnline($uid,$statsDbName,$valid)
- {
- $track_online_table = Database::get_statistic_table(STATISTIC_TRACK_E_ONLINE_TABLE);
- $query = "SELECT login_user_id,login_date FROM ".$track_online_table ." WHERE DATE_ADD(login_date,INTERVAL $valid MINUTE) >= NOW() ";
- $result = @api_sql_query($query,__FILE__,__LINE__);
- if (count($result)>0)
- {
- $rtime = time();
- $rdate = date("Y-m-d H:i:s",$rtime);
- $validtime = mktime(date("H"),date("i")-$valid,date("s"),date("m"),date("d"),date("Y"));
- $rarray = array();
-
- while(list($login_user_id,$login_date)= mysql_fetch_row($result))
- {
- $barray = array();
- array_push($barray,$login_user_id);
- array_push($barray,$login_date);
- // YYYY-MM-DD HH:MM:SS, db date format
- $hour = substr($login_date,11,2);
- $minute = substr($login_date,14,2);
- $secund = substr($login_date,17,2);
- $month = substr($login_date,5,2);
- $day = substr($login_date,8,2);
- $year = substr($login_date,0,4);
- // db timestamp
- $dbtime = mktime($hour,$minute,$secund,$month,$day,$year);
-
- if ($dbtime>$validtime)
- {
- array_push($rarray,$barray);
- }
- //echo $dbtime.":".$rtime.">".$validtime."<BR>";
- //echo "$login_user_id.":".$login_date.";";
- }
- return $rarray;
- }
- else
- {
- return false;
- }
- }
- function GetFullUserName($uid)
- {
- $user_table = Database::get_main_table(MAIN_USER_TABLE);
- $query = "SELECT `firstname`,`lastname` FROM ".$user_table." WHERE `user_id`='$uid'";
- $result = @api_sql_query($query,__FILE__,__LINE__);
- if (count($result)>0)
- {
- $str = "";
- while(list($firstname,$lastname)= mysql_fetch_array($result))
- {
- $str = $lastname." ".$firstname;
- return $str;
- }
-
- }
- }
-
- function GetURL($path)
- {
- $str = "";
- $url = explode('/',$path);
- for($i=0;$i < sizeof($url)-2; $i++)
- {
- if($i==sizeof($url)-3)
- {$str = $str.$url[$i]; }
- else
- {
- $str = $str.$url[$i]."/";
- }
- }
- return $str;
- }
- // picture?
- function IsValidUser($uid)
- {
- $user_table = Database::get_main_table(MAIN_USER_TABLE);
-
- $query = "SELECT `picture_uri` FROM ".$user_table." WHERE `user_id`='$uid'";
- $result = @api_sql_query($query,__FILE__,__LINE__);
-
- if (count($result)>0)
- {
- while(list($picture_uri)= mysql_fetch_array($result))
- {
- if (count($picture_uri)>0)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- }
- else
- {
- return false;
- }
- }
-
- function ClearURL($path)
- {
- $url = explode('?id=',$path);
- return $url[0];
- }
- function chatcall() {
- global $_uid, $_cid;
-
- if (!$_uid)
- {
- return (false);
- }
- $track_user_table = Database::get_main_table(MAIN_USER_TABLE);
- $sql="select chatcall_user_id, chatcall_date from $track_user_table where ( user_id = $_uid )";
- $result=api_sql_query($sql,__FILE__,__LINE__);
- $row=mysql_fetch_array($result);
- $login_date=$row['chatcall_date'];
- $hour = substr($login_date,11,2);
- $minute = substr($login_date,14,2);
- $secund = substr($login_date,17,2);
- $month = substr($login_date,5,2);
- $day = substr($login_date,8,2);
- $year = substr($login_date,0,4);
- $calltime = mktime($hour,$minute,$secund,$month,$day,$year);
- $time = time();
- $time = date("Y-m-d H:i:s", $time);
- $minute_passed=5; //within this limit, the chat call request is valid
- $limittime = mktime(date("H"),date("i")-$minute_passed,date("s"),date("m"),date("d"),date("Y"));
- if (($row['chatcall_user_id']) and ($calltime>$limittime)) {
- $webpath=api_get_path(WEB_CODE_PATH);
- $message=get_lang('YouWereCalled').' : '.GetFullUserName($row['chatcall_user_id'],'').'<br>'.get_lang('DoYouAccept')
- ."<p>"
- ."<a href=\"".$webpath."chat/chat.php?cidReq=".$_cid."&origin=whoisonlinejoin\">"
- . get_lang("Yes")
- ."</a>"
- ." | "
- ."<a href=\"".api_get_path('WEB_PATH')."webchatdeny.php\">"
- . get_lang("No")
- ."</a>"
- ."</p>";
-
- return($message);
- }
- else
- {
- return(false);
- }
- }
- /**
- * Returns a list (array) of users who are online and in this course.
- */
- function who_is_online_in_this_course($uid, $valid, $coursecode)
- {
- $track_online_table = Database::get_statistic_table(STATISTIC_TRACK_E_ONLINE_TABLE);
- $query = "SELECT login_user_id,login_date FROM ".$track_online_table ." WHERE course='".$coursecode."' AND DATE_ADD(login_date,INTERVAL $valid MINUTE) >= NOW() ";
- $result = api_sql_query($query,__FILE__,__LINE__);
- if (count($result)>0)
- {
- $rtime = time();
- $rdate = date("Y-m-d H:i:s",$rtime);
- $validtime = mktime(date("H"),date("i")-$valid,date("s"),date("m"),date("d"),date("Y"));
- $rarray = array();
-
- while(list($login_user_id,$login_date)= mysql_fetch_row($result))
- {
- $barray = array();
- array_push($barray,$login_user_id);
- array_push($barray,$login_date);
- // YYYY-MM-DD HH:MM:SS, db date format
- $hour = substr($login_date,11,2);
- $minute = substr($login_date,14,2);
- $secund = substr($login_date,17,2);
- $month = substr($login_date,5,2);
- $day = substr($login_date,8,2);
- $year = substr($login_date,0,4);
- // db timestamp
- $dbtime = mktime($hour,$minute,$secund,$month,$day,$year);
- if ($dbtime >= $validtime)
- {
- array_push($rarray,$barray);
- }
- //echo $dbtime.":".$rtime.">".$validtime."<BR>";
- //echo "$login_user_id.":".$login_date.";";
- }
- return $rarray;
- }
- else
- {
- return false;
- }
- }
- ?>
|