mUser class

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
class mUser
{
function __construct()
{
//empty construct
}
function isOnline($login)
{
global $DB;
$table_name='monitoring_result';
$login=trim($login);
$date=date("d.m.Y");
$nowtime=date("H:i:s");
self::isUser($login);
$a=$DB->Query("SELECT * FROM $table_name WHERE DATE='".$date."' and USER='".$login."' ORDER BY ID DESC LIMIT 1")->GetNext();
if($a["ID"])
{
$nowtime=date("H:i:s");
$last_time=$a["END"];
$diff=strtotime($nowtime)-strtotime($last_time);
$interval=intval(COption::GetOptionString("micros.monitoring", "checkFrequency"));
if(!$interval) $interval=30;
//echo "<pre>";print_r($diff);echo"</pre>";
if(intval($diff)<($interval+10))//if in time
{
$DB->Query("UPDATE $table_name SET END='".$nowtime."' WHERE ID='".$a["ID"]."'");
}else
{
$DB->Query("INSERT INTO $table_name (ID, USER, DATE, BEGIN, END, UF_DATE) VALUES ('', '".$login."', '".$date."', '".$nowtime."', '".$nowtime."', '".date("Y-m-d H:i:s", strtotime($date))."')" );
}
}else
{
$DB->Query("INSERT INTO $table_name (ID, USER, DATE, BEGIN, END, UF_DATE) VALUES ('', '".$login."', '".$date."', '".$nowtime."', '".$nowtime."', '".date("Y-m-d H:i:s", strtotime($date))."')" );
}
self::ShowResult("success");
}
function isUser($login)
{
if($login)
{
if(!$inf=$GLOBALS["USER"]->GetList($by="id", $order="desc", array("LOGIN"=>$login, "ACTIVE"=>"Y"), array("FIELDS"=>array("ID")))->Fetch())
{
self::ShowResult("error", "Employee login ".$login." is not found",false, 404);
}
}else
{
self::ShowResult("error", "Employee login ".$login." is not found", false, 404);
}
}
function ShowResult($status, $str="", $result=array(), $code=200)
{
$response=array();
if($status) $response["status"]=$status;
if($str) $response["message"]=$GLOBALS["APPLICATION"]->ConvertCharset($str, LANG_CHARSET, "UTF-8");
if($result) $response["result"]=$GLOBALS["APPLICATION"]->ConvertCharsetArray($result, LANG_CHARSET, "UTF-8");
$response["statusCode"]=$code;
$GLOBALS["APPLICATION"]->RestartBuffer();
echo json_encode($response);
exit();
}
//get User status
function GetActiveUsers()
{
$table_name='monitoring_result';
$interval=intval(COption::GetOptionString("micros.monitoring", "checkFrequency"));
$date=date("d.m.Y");
$time=date("H:i:s");
//
$max=date("H:i:s", (strtotime($time)-$interval-10));
$q="SELECT * FROM $table_name WHERE DATE='".$date."' AND END > '".$max."'";
$query=$GLOBALS["DB"]->Query($q);
$arResult=array();
while($result=$query->GetNext(false, false))
{
$arResult[$result["USER"]]=$result;
}
return $arResult;
}
///get User report by date
function GetReport($login, $date)
{
$filter="";
if(is_array($date))
{
$filter.=" (USER='".trim($login)."') AND (UF_DATE >= '".date("Y-m-d H:i:s", strtotime($date["from"]))."' AND UF_DATE <= '".date("Y-m-d H:i:s", strtotime($date["to"]))."') ";
}
else
{
$filter.=" (USER='".trim($login)."') AND (UF_DATE = '".date("Y-m-d H:i:s", strtotime($date))."') ";
}
global $DB;
$table_name='monitoring_result';
$login=trim($login);
$sql="SELECT * FROM $table_name WHERE ".$filter." ORDER BY ID ASC";
$query=$DB->Query($sql);
$result=array();
while($res=$query->GetNext())
{
//echo "<pre>";print_r($res);echo"</pre>";
$result[$res["DATE"]][]=$res;
}
if($result){
$report=new DoReport($result);
return $report->ShowReport();
}
else
return false;
}
function MigDate(){
global $DB;
$a=$DB->Query("SELECT * FROM monitoring_result");
while($b=$a->GetNext(false, false))
{
//echo "<pre>";print_r($b);echo"</pre>";
//$date=date("Y-m-d H:i:s", strtotime($b["DATE"]));
//echo "<pre>";print_r($date);echo"</pre>";
//$DB->Query("UPDATE monitoring_result SET UF_DATE='".$date."' WHERE ID='".$b['ID']."'");
}
}
}