"; $response = array(); if($redis->exists('itgc_locationsupd')) { //echo $sess_userid.'----'.$gps_latitude.'-----'.$gps_longitude;die; if($redis_geopoi_data=get_geoPoi($sess_userid.':geopois',$gps_longitude,$gps_latitude,'500000','m',$redis)) { //echo $sess_userid.'-hi-'.$gps_latitude.'-hello--'.$gps_longitude;die; $redis_poi_km = round($redis_geopoi_data[0][1]/1000,0).' Km From '; // poi km redis $redis_poi_name = str_replace(' ','_',$redis_geopoi_data[0][0]);//get redis poi name $KMFromNearPOI = str_replace(' ','_',$redis_geopoi_data[0][0]);//get redis poi name $KMFromNearPOI = $redis_poi_km.' '.$KMFromNearPOI; $redis_poi_hset = json_decode(getPoi($sess_userid,$redis_poi_name,$redis)); // function to get stored poi data redis // check if the vehicle is inside the poi if($redis_geopoi_data[0][1] <= $redis_poi_hset->radius) { // if inside the poi get the poi name $LocationName = $redis_geopoi_data[0][0]; // redis poiname $KMFromNearPOI = 'INSIDE POI'; $redis_poi_km =''; $response['LocationName'] = $LocationName; $response['KMFromNearPOI'] = $KMFromNearPOI; } else{ // if the out of poi get the vehine locaiton name redis geodata $get_data = get_geoData('itgc_locationsupd',$gps_longitude,$gps_latitude,'5000','m',$redis); $LocationName = str_replace('_',' ',$get_data[0][0]);// redis location name $lat = $get_data[0][2][1]; // getting lat redis $lng = $get_data[0][2][0]; // getting lng redis $LocationName = (!empty($LocationName))? $LocationName.' ('.$gps_latitude.','.$gps_longitude.')':$gps_longitude.','.$gps_latitude; $response['LocationName'] = $LocationName; $response['KMFromNearPOI'] = ''; // $LocationName = 'redis locatio'; } } else { //echo $sess_userid.'----'.$gps_latitude.'-----'.$gps_longitude;die; // if the out of poi get the vehine locaiton name redis geodata $get_data = get_geoData('itgc_locationsupd',$gps_longitude,$gps_latitude,'5000','m',$redis); $LocationName = str_replace('_',' ',$get_data[0][0]);// redis location name $lat = $get_data[0][2][1]; // getting lat redis $lng = $get_data[0][2][0]; // getting lng redis $LocationName = (!empty($LocationName))? $LocationName.' ('.$gps_latitude.','.$gps_longitude.')':$gps_longitude.','.$gps_latitude; $response['LocationName'] = $LocationName; $response['KMFromNearPOI'] = ''; } return $response; } else { return false; // return false if no redis data found } } function getEmpTravelDistancenewspeedDayEnd($phoneNo,$installerid,$branchid,$starttime,$end_time) { //echo 'Phone-'.$phoneNo.',ID-'.$installerid.',LoginId-'.$branchid.',StartTime-'.$starttime.',EndTime-'.$end_time;die; $temp_data_data=array(); $condition = ""; $calcObj = new calculate_distance(); $dbhost = '203.115.101.54'; $dbuser = 'local54'; $dbpass = 'local54098'; $db = 'ecomdriverapp'; $conn = @mysql_connect($dbhost, $dbuser, $dbpass); $selected = @mysql_select_db($db,$conn); mysql_query("DROP TEMPORARY TABLE if EXISTS ecomdriverapp.emp_today_trackingtempapi",$conn); mysql_query("CREATE TEMPORARY TABLE ecomdriverapp.emp_today_trackingtempapi( location_time DATETIME NOT NULL, gps_latitude FLOAT(12,9) NOT NULL, `gps_longitude` FLOAT(12,9) NOT NULL )",$conn); $sql = "insert into ecomdriverapp.emp_today_trackingtempapi(gps_latitude,gps_longitude,location_time) select gps_latitude,gps_longitude,location_time from emp_today_tracking where phone_no='".$phoneNo."' and emp_id='".$installerid."' and location_time>='".$starttime."' and location_time<='".$end_time."' and login_id='".$branchid."' and is_active='1' group by gps_latitude having count(*)=1 order by location_time"; if(mysql_query($sql,$conn)) { $todayTravelData = select_query_sql("select gps_latitude,gps_longitude,location_time from ecomdriverapp.emp_today_trackingtempapi group by gps_longitude having count(*)=1 order by location_time", ""); } $distance = 0; $totalDistance = 0; $kmindividual=0; //echo ""; //echo "KK"; for($ep=1;$epcalc_distance($PointArray); $Duration= dateDifference($todayTravelData[$ep]['location_time'],$todayTravelData[$ep-1]['location_time']); $DurationHr=$Duration/60; $SPEED=round($distance/$DurationHr); $totalDistanceok = $totalDistanceok + $distance; if($SPEED<60 && $SPEED>4) { $arr = array( 'gps_latitude' => $todayTravelData[$ep]['gps_latitude'], 'gps_longitude' => $todayTravelData[$ep]['gps_longitude'] ); array_push($temp_data_data, $arr); } } //echo "
"; for($ipi=1;$ipicalc_distance($PointArray); $totalDistance = $totalDistance + $distance12; } //return $totalDistance ."##".$totalDistanceok; return $totalDistance; } function getEmpTravelDistanceDayEnd($phoneNo,$installerid,$branchid) { $condition = ""; $db_name="ecomdriverapp"; $calcObj = new calculate_distance(); $todayTravelData = db__select("select * from $db_name.emp_today_tracking where phone_no='".$phoneNo."' and emp_id='".$installerid."' and Date_of_journey='".date("Y-m-d")."' and login_id='".$branchid."' and is_active='1' and (transtype!='WALKING' && transtype!='STILL' ) order by location_time ",$condition); $distance = 0; $totalDistance = 0; for($ep=1;$epcalc_distance($PointArray); $Duration= dateDifference($todayTravelData[$ep]['location_time'],$todayTravelData[$ep-1]['location_time']); $Duration=$Duration+1; ###### Sum of distance############ if ($distance >= $Duration ) { $distance = 0; $totalDistance = $totalDistance + $distance; } else { $totalDistance = $totalDistance + $distance; } } } return $totalDistance; } class master { private $Obj; function __construct() { $this->Obj = new MyClass(); } function dateDifference($date1, $date2) { $datetime1 = strtotime($date1); $datetime2 = strtotime( $date2); $interval = abs($datetime2 - $datetime1); $minutes = $interval / 60; return $minutes; } function checkvehno($groupid,$vehicleNo) { $condition = ""; $db_name="matrix"; //echo "SELECT * from group_services where sys_Service_id = '".$vehicleNo."' and sys_group_id='".$groupid."' AND active = 1";die; $this->data=db__select_staging62("SELECT * from group_services where sys_Service_id = '".$vehicleNo."' and sys_group_id='".$groupid."' AND active = 1", $condition); return $this->data; } function getAlertsCountdata($groupid,$vehicleNo,$reqtype='') { $condition = ""; $db_name="matrix"; //echo $reqtype;die; $ExtraQuery = ""; if($vehicleNo!='') { $ExtraQuery .= " AND gtrac_alert.veh_id = '".$vehicleNo."'"; } if($reqtype!='') { $ExtraQuery .= " AND gtrac_alert.alert_msg = '".$reqtype."'"; } if($reqtype!='' && $vehicleNo!='') { $this->data=db__select_staging("SELECT alert_type,vehicleno,sys_service_id,msg,gps_latitude,gps_longitude,sent_at AS datetime FROM alert_bank WHERE group_id = '".$groupid."' AND sys_service_id = '".$vehicleNo."' AND alert_type = '".$reqtype."' ORDER BY created_at desc", $condition); } elseif($vehicleNo!='') { $this->data=db__select_staging("SELECT sys_service_id,alert_type,COUNT(id) AS alertcount, CASE when COUNT(id) > 100 then 'notworking' ELSE 'working' END AS device_status FROM alert_bank WHERE group_id = '".$groupid."' and sys_service_id = '".$vehicleNo."' AND sys_service_id != 0 GROUP BY sys_service_id, alert_type", $condition); } else { $this->data=db__select_staging("SELECT sys_service_id,alert_type,COUNT(id) AS alertcount, CASE when COUNT(id) > 100 then 'notworking' ELSE 'working' END AS device_status FROM alert_bank WHERE group_id = '".$groupid."' AND sys_service_id != 0 GROUP BY sys_service_id, alert_type", $condition); } //echo count($this->data);die; return $this->data; } function getUserAlertsType($groupid,$userid) { $condition = ""; $db_name="matrix"; //echo "SELECT SetAlertType FROM alert_managements WHERE (user_Id = ".$userid." OR Parent_user_Id = ".$userid.") AND `status` = '1' GROUP BY SetAlertType";die; if($groupid!='') { //return "SELECT SetAlertType FROM alert_managements WHERE (user_Id = ".$userid." OR Parent_user_Id = ".$userid.") AND `status` = '1' GROUP BY SetAlertType"; $this->data=db__select_staging("SELECT SetAlertType FROM alert_management.alert_managements WHERE (user_Id = ".$userid." OR Parent_user_Id = ".$userid.") AND `status` = '1' GROUP BY SetAlertType", $condition); } else { $this->data= array(); } return $this->data; } function getUsers($user_id) { $condition = ""; $db_name="matrix"; $ExtraQuery = ""; if($user_id!='') { $this->data=db__select_staging62("SELECT users.id as user_id,mobile_app_token matrix.users WHERE users.id='".$user_id."' and users.sys_active=1", $condition); } else { $this->data= array(); } return $this->data; } function getAlertsforpopups($groupid) { $condition = ""; $db_name="matrix"; if($groupid!='') { //$this->data=db__select_staging("SELECT id as alert_id,alert_type,vehicleno,sys_service_id,msg,sent_at AS `datetime` , '1' AS alertcount FROM alert_bank WHERE group_id = '".$groupid."' AND popup_status = 0 ORDER BY created_at DESC", $condition); $this->data=db__select_staging("SELECT id as alert_id,alert_type,vehicleno,sys_service_id,msg,created_at AS `datetime` , '1' AS alertcount,issue,gps_time FROM alert_bank WHERE group_id = '".$groupid."' AND (remark is null or remark='') and created_at BETWEEN (NOW() - INTERVAL 2 DAY) AND NOW() ORDER BY created_at DESC limit 2000", $condition); } else { $this->data= array(); } return $this->data; } function getAlertsforpopupsall($groupid) { $condition = ""; $db_name="matrix"; if($groupid!='') { $this->data=db__select_staging("SELECT id as alert_id,alert_type,vehicleno,sys_service_id,msg,sent_at AS `datetime` , '1' AS alertcount,remark,created_at,issue,gps_time FROM alert_bank WHERE group_id = '".$groupid."' AND (remark is not null or remark!='') ORDER BY created_at DESC", $condition); } else { $this->data= array(); } return $this->data; } function getSubusers($user_id) { $condition = ""; $db_name="matrix"; $ExtraQuery = ""; if($user_id!='') { $this->data=db__select_staging62("SELECT users.id as user_id,users.sys_username,users.fullname,users.sys_added_date,group_users.sys_group_id,users.sys_parent_user FROM matrix.users LEFT JOIN group_users ON users.id = group_users.sys_user_id WHERE (users.sys_parent_user='".$user_id."' or users.id='".$user_id."') and users.sys_active=1 ORDER BY users.fullname", $condition); } else { $this->data= array(); } return $this->data; } function getALLvhl($group_id) { $condition = ""; $db_name="matrix"; $ExtraQuery = ""; if($group_id!='') { $this->data=db__select_staging62("SELECT veh_reg,services.id from group_services left join services on group_services.sys_service_id=services.id where sys_group_id='".$group_id."' and active=1 ORDER BY veh_reg", $condition); } else { $this->data= array(); } return $this->data; } function getAlerts($groupid,$fromdate,$todate,$veh_no,$alerttype) { $condition = ""; $db_name="matrix"; $ExtraQuery = ""; if($veh_no>0 && $veh_no!='') { $ExtraQuery .= " AND sys_service_id = '".$veh_no."'"; } if($alerttype!='') { $ExtraQuery .= " AND alert_type = '".$alerttype."'"; } if($groupid!='' && $fromdate !='' && $todate!='') { //echo "SELECT Username,alert_type,vehicleno,`number`,email,msg,remark,issue,sent_at FROM alert_bank WHERE group_id = '".$groupid."' AND DATE(sent_at) >= '".$fromdate."' AND DATE(sent_at) <= '".$todate."' ".$ExtraQuery." ORDER BY created_at DESC";die; $this->data=db__select_staging("SELECT Username,alert_type,vehicleno,`number`,email,msg,remark,issue,sent_at FROM alert_bank WHERE group_id = '".$groupid."' AND DATE(sent_at) >= '".$fromdate."' AND DATE(sent_at) <= '".$todate."' ".$ExtraQuery." ORDER BY created_at DESC", $condition); } else { $this->data= array(); } return $this->data; } function getAllhistorycountAlerts() { $condition = ""; $db_name="matrix"; $this->data=db__select_staging("SELECT user_id,group_id,Username,alert_type,vehicleno,sys_service_id,`number`,email,COUNT(id) AS alertcount, CASE when COUNT(id) > 10 then 'working' ELSE 'notworking' END AS device_status FROM alert_bank_all WHERE sys_service_id != 0 GROUP BY sys_service_id, alert_type HAVING alertcount > 10 ORDER BY alertcount DESC;", $condition); return $this->data; } function getproximity($lat,$long,$km,$Group_id) { $condition = ""; $db_name="matrix"; $this->data=db__select_staging62("select date_add(gps_time,interval 330 minute) as Datetime,gps_latitude,gps_longitude,des_movement_id,sys_service_id, veh_reg,round(((7912*asin ( sqrt ( power ( sin (( ".$lat."-gps_latitude ) * 0.00872664625997 ), 2 ) + cos( ".$lat." * 0.0174532925) * cos ( gps_latitude*0.0174532925) * power ( sin ((".$long." - gps_longitude ) * 0.00872664625997), 2))))*1.609344)) as distance, case when round(gps_speed*1.609,0)>140 then '0' else round(gps_speed*1.609,0) end as gps_speed from latest_telemetry left join services on latest_telemetry.sys_service_id=services.id where round(((7912*asin ( sqrt ( power ( sin (( ".$lat."-gps_latitude ) * 0.00872664625997 ), 2 ) + cos( ".$lat." * 0.0174532925) * cos ( gps_latitude*0.0174532925) * power ( sin ((".$long." - gps_longitude ) * 0.00872664625997), 2))))*1.609344))<=".$km." and sys_service_id in (select sys_service_id from group_services where sys_group_id in(".$Group_id.") and active=1) order by distance asc;", $condition); //echo count($this->data);die; return $this->data; } function updateAlertsforpopups($groupid,$service_id,$alert_type,$remark,$issue) { $condition = ""; $db_name="matrix"; if($service_id!='' && $groupid!='' && $alert_type!='') { $data1 = array('popup_status' => '1','remark' => $remark,'issue' => $issue); $condition = array('alert_type="'.$alert_type.'"','sys_service_id='.$service_id); // db__update_staging('alert_bank', $data1, $condition); return 1; } else { return 0; } } /** $checkOS = " SELECT created_at FROM alert_bank WHERE sys_service_id = '$sys_service_id' AND alert_type = 'OverSpeed' ORDER BY created_at DESC LIMIT 1"; $osResult = $secondConn->query($checkOS); $osRow = $osResult->fetch_assoc(); if ($osRow) { $lastOS = strtotime($osRow['created_at']); $nowOS = strtotime($newEventTime); // difference in minutes $diffMinutes = ($nowOS - $lastOS) / 60; if ($diffMinutes < 10) { // ? Do NOT send overspeed alert again $payload = [ "bookingNo" => $bookingNo, // using veh_no as booking reference "sosButtonEvent" => [ "carNo" => null, "eventDateTime" => [ "eventDateTime" => null, "receive" => null ], "lat" => 0.0, "log" => 0.0, "locationName" => null ], "carStoppageEvent" => [ "carNo" => null, "startIdleTime" => null, "endIdleTime" => null, "duration" => null, "lat" => null, "log" => null, "locationName" => null ], "carSpeedEvent" => [ "carNo" => $vehNo, "eventDateTime" => [ "eventDateTime" => date('Y-m-d\TH:i:s', strtotime($row['lastspeedupdate'])), "receive" => date('Y-m-d\TH:i:s', strtotime($row['lastspeedupdate'])) ], "lat" => $row['gps_latitude'], "log" => $row['gps_longitude'], "locationName" => "", "carSpeed" => $row['gps_speed'], "carSpeedThreshold" => "20" ] ]; echo json_encode($payload, JSON_UNESCAPED_SLASHES); $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => 'https://mis.ecoserp.in/api/Events/pushdata', CURLOPT_RETURNTRANSFER => true, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_SSL_VERIFYHOST => 2, CURLOPT_SSL_VERIFYPEER => true, CURLOPT_POSTFIELDS => json_encode($payload), CURLOPT_HTTPHEADER => array( 'Content-Type: application/json', 'Authorization: Bearer ' . $token ), )); echo $response = curl_exec($curl); curl_close($curl); $vehicleno = $vehNo; $speed = $row['speed']; $lat = $row['gps_latitude']; $lon = $row['gps_longitude']; $msgTime = $newEventTime; $msgOS = "Speed Exception Alert : This Veh no $vehicleno is moving at the speed of " . "$speed which is above the normal speed of 20 kmph Loc: ($lat, $lon)."; $insertOS = " INSERT INTO alert_bank ( user_id, group_id, Username, alert_type, vehicleno, sys_service_id, speed, gps_latitude, gps_longitude, aws_msg_id, number, email, msg, remark, issue, created_at, sent_at, status, popup_status, email_status, sms_status ) VALUES ( 6258, 6173, 'ecogpsall', 'OverSpeed', '$vehicleno', '$sys_service_id', '$speed', '$lat', '$lon', '$awsMsgId', '$numbers', '$emails', '$msgOS', NULL, NULL, '$msgTime', '$msgTime', 0, 0, 1, 0 )"; $secondConn->query($insertOS); SELECT * FROM your_table WHERE created_at BETWEEN (NOW() - INTERVAL 2 DAY) AND NOW(); * Function: insertAlertForPopups * --------------------------------------- * Inserts a new alert record into the 'alert_bank' table. * * @param int $user_id - ID of the user who triggered the alert * @param int $group_id - Group ID to which the user belongs * @param string $username - Username of the person triggering alert * @param string $alert_type - Type of alert (e.g., Overspeed, Geofence) * @param string $vehicleno - Vehicle number * @param int $sys_service_id - System service ID (vehicle service identifier) * @param float $speed - Current vehicle speed * @param float $gps_latitude - GPS latitude coordinate * @param float $gps_longitude - GPS longitude coordinate * @param string $aws_msg_id - AWS message ID (if applicable) * @param string $number - Contact number for SMS alert * @param string $email - Email for alert * @param string $msg - Message content of the alert * @param string $remark - Remark or comment * @param string $issue - Issue description or category * @param string $created_at - Timestamp of creation * @param string $sent_at - Timestamp when alert was sent * @param string $status - Overall status (e.g., 'pending', 'sent') * @param string $popup_status - Popup status flag ('0' or '1') * @param string $email_status - Email status ('0' or '1') * @param string $sms_status - SMS status ('0' or '1') * * @return int 1 on success, 0 on failure */ function insertAlertForPopups( $user_id, $group_id, $username, $alert_type, $vehicleno, $sys_service_id, $speed, $gps_latitude, $gps_longitude, $aws_msg_id, $number, $email, $msg, $remark, $issue, $created_at, $sent_at, $status, $popup_status, $email_status, $sms_status ) { // Assuming you already have a mysqli connection established $conn = new mysqli("203.115.101.54", "local54", "local54098", "alert_management"); if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $stmt = $conn->prepare(" INSERT INTO alert_bank ( user_id, group_id, Username, alert_type, vehicleno, sys_service_id, speed, gps_latitude, gps_longitude, aws_msg_id, number, email, msg, remark, issue, created_at, sent_at, status, popup_status, email_status, sms_status ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) "); if (!$stmt) { die("Prepare failed: " . $conn->error); } $stmt->bind_param( "iissssddsssssssssssss", $user_id, $group_id, $username, $alert_type, $vehicleno, $sys_service_id, $speed, $gps_latitude, $gps_longitude, $aws_msg_id, $number, $email, $msg, $remark, $issue, $created_at, $sent_at, $status, $popup_status, $email_status, $sms_status ); $result = $stmt->execute(); // Manually construct the query string for debugging/logging (optional) $query_string = sprintf( "INSERT INTO alert_bank ( user_id, group_id, Username, alert_type, vehicleno, sys_service_id, speed, gps_latitude, gps_longitude, aws_msg_id, number, email, msg, remark, issue, created_at, sent_at, status, popup_status, email_status, sms_status ) VALUES (%d, %d, '%s', '%s', '%s', '%s', %.2f, %.6f, %.6f, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')", $user_id, $group_id, $conn->real_escape_string($username), $conn->real_escape_string($alert_type), $conn->real_escape_string($vehicleno), $conn->real_escape_string($sys_service_id), $speed, $gps_latitude, $gps_longitude, $conn->real_escape_string($aws_msg_id), $conn->real_escape_string($number), $conn->real_escape_string($email), $conn->real_escape_string($msg), $conn->real_escape_string($remark), $conn->real_escape_string($issue), $conn->real_escape_string($created_at), $conn->real_escape_string($sent_at), $conn->real_escape_string($status), $conn->real_escape_string($popup_status), $conn->real_escape_string($email_status), $conn->real_escape_string($sms_status) ); $stmt->close(); $conn->close(); if ($result) { // Return last query for logging/debugging return 1; } else { return 0; } } function addsubusers($groupid,$userid,$name,$username,$password,$email,$phone,$action) { global $mysqlimatrix62; $condition = ""; $db_name="matrix"; $currtime = date('Y-m-d H:i:s'); $sqlusers3 = db__select_staging62("SELECT * FROM users WHERE sys_username = '".$username."' ", $condition); //echo count($sqlusers3);die; if(count($sqlusers3)==0) { //echo "INSERT INTO matrix.users (fullname, sys_username, sys_password, mobile_number, email_address, address,postcode, sys_active,sys_parent_user) VALUES ('$name','$username','$password','$phone','$email','','',1,'".$userid."')";die; $sqlusers = db__select_staging62("INSERT INTO matrix.users (fullname, sys_username, sys_password, mobile_number, email_address, address,postcode, sys_active,sys_parent_user) VALUES ('$name','$username','$password','$phone','$email','','',1,'".$userid."')", $condition); $sqlusers1 = db__select_staging62("SELECT id FROM matrix.users WHERE users.sys_parent_user = '".$userid."' AND users.sys_username = '".$username."' ", $condition); $lastuser_id = $sqlusers1[0]['id']; $sqlusers2 = db__select_staging62("INSERT INTO matrix.group (name, sys_user_id, sys_parent_group_id, icon, active, sys_modified, sys_created) VALUES('$name','$lastuser_id','".$groupid."','',1,'$currtime','$currtime')", $condition); $sqlusers3 = db__select_staging62("SELECT id FROM matrix.group WHERE sys_user_id = '".$lastuser_id."' AND sys_parent_group_id = '".$groupid."' ", $condition); $lastgroup_id = $sqlusers3[0]['id']; db__select_staging62("INSERT INTO matrix.group_users (sys_user_id, sys_group_id, active, sys_modified) VALUES ('$lastuser_id','$lastgroup_id',1,'$currtime')", $condition); if($lastgroup_id) { return 1; } else { return 0; } } else { return 2; } } function editsubusers($userid,$name,$username,$password,$email,$phone,$action) { global $mysqlimatrix62; $condition = ""; $db_name="matrix"; $currtime = date('Y-m-d H:i:s'); $data1 = array('fullname' => $name,'sys_username' => $username,'sys_password' => $password,'mobile_number' => $phone,'email_address' => $email); $condition = array('id="'.$userid.'"'); //db__update_staging_62('users', $data1, $condition); //echo "UPDATE users set fullname='".$name."', sys_username='".$username."', sys_password='".$password."', mobile_number='".$phone."', email_address='".$email."' WHERE id='".$userid."' ";die; db__select_staging62("UPDATE users set fullname='".$name."', sys_username='".$username."', sys_password='".$password."', mobile_number='".$phone."', email_address='".$email."' WHERE id='".$userid."' ", $condition); return 1; } function deletesubuser($userid) { global $mysqlimatrix62; $condition = ""; $db_name="matrix"; $currtime = date('Y-m-d H:i:s'); $status = (int)0; //mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); // $data1 = array('sys_active' => 0); // $condition = array('id="'.$userid.'"'); //echo "UPDATE matrix.users SET sys_active = 0 where id='".$userid."' ";die; //$deactive = db__select_staging62("UPDATE matrix.users SET sys_active = 0 where id='".$userid."' ", $condition); //$deactive = db__update_staging_62('users', $data1, $condition); $success_update = $mysqlimatrix62->prepare("UPDATE matrix.users SET users.sys_active=0 WHERE id = ?"); $success_update->bind_param("s", $userid); $result = $success_update->execute(); $success_update->close(); return 1; /*if($deactive) { return 1; } else { return 0; }*/ } function mapvehiclestosubusers ($user_id,$selectBox2_id) { global $mysqlimatrix62; $condition = ""; $db_name="matrix"; $currtime = date('Y-m-d H:i:s'); $group_id = array(); $status = 1; $sqlusers = db__select_staging62("SELECT sys_group_id FROM matrix.group_users where sys_user_id='".$user_id."' and active=1 ", $condition); $sub_group_id = $sqlusers[0]['sys_group_id']; //print_r($selectBox2_id);die; //echo $sub_group_id;die; //$sqlusers = db__select_staging62("DELETE FROM matrix.group_services WHERE sys_group_id='".$sub_group_id."' ", $condition); $data1 = array('active' => 0); $condition = array('sys_group_id="'.$sub_group_id.'"'); //$aa = db__update_staging_62('group_services', $data1, $condition); db__select_staging62("UPDATE group_services set active=0 WHERE sys_group_id='".$sub_group_id."' ", $condition); //echo $aa;die; for($j=0;$j0) { $sqlusers2 = db__select_staging62("SELECT sys_service_id,sys_group_id FROM matrix.group_services where sys_group_id='".$sub_group_id."' and sys_service_id='".$select_vehID."' ", $condition); if(count($sqlusers2)>0) { //echo 1; $data2 = array('active' => 1); $condition1 = array('sys_group_id="'.$sub_group_id.'"','sys_service_id='.$select_vehID.''); //db__update_staging_62('group_services', $data2, $condition1); db__select_staging62("UPDATE group_services set active=1 WHERE sys_group_id='".$sub_group_id."' AND sys_service_id='".$select_vehID."' ", $condition); } else { //echo 2; $sqlusers1 = db__select_staging62("INSERT INTO matrix.group_services (sys_service_id, sys_group_id, active, sys_modified) VALUES('".$select_vehID."','".$sub_group_id."',$status,'".$currtime."')", $condition); } } } //die; if($sqlusers2) { return 1; } else { return 1; } } function dismissAllPopAlerts($groupid) { $condition = ""; $db_name="matrix"; if($groupid!='') { $data1 = array('popup_status' => '1'); $condition = array('group_id='.$groupid.''); db__update_staging('alert_bank', $data1, $condition); return 1; } else { return 0; } } function activeDeactiveAlerts($groupid,$user_id,$alert_id,$alert_status) { global $mysqli235; $condition = ""; $db_name="matrix"; if($groupid!='') { //$data1 = array('status' => $alert_status); //$condition = array('SetAlertType="'.$alert_id.'"','group_Id='.$groupid.'','user_Id='.$user_id.''); //db__update_staging('alert_managements', $data1, $condition); $success_update = $mysqli235->prepare("UPDATE alert_managements SET status=? WHERE id = ? "); $success_update->bind_param("ss",$alert_status,$alert_id); $result = $success_update->execute(); //echo("Statement failed: ". $success_update->error . "
"); $success_update->close(); return 1; } else { return 0; } } function activeDeactiveAlertsall($groupid,$user_id,$alert_status) { global $mysqli235; $condition = ""; $db_name="matrix"; if($groupid!='') { //$data1 = array('status' => $alert_status); //$condition = array('group_Id='.$groupid.'','user_Id='.$user_id.''); //db__update_staging('alert_managements', $data1, $condition); $success_update = $mysqli235->prepare("UPDATE alert_managements SET status=? WHERE user_Id = ? OR Parent_user_Id = ? "); $success_update->bind_param("sss", $alert_status,$user_id,$user_id); $result = $success_update->execute(); //echo("Statement failed: ". $success_update->error . "
"); $success_update->close(); return 1; } else { return 0; } } function getMonthlyTotalKM($vehListId,$fromdate,$todate) { $condition = ""; $db_name="matrix"; $orderBy=""; $this->data=db__select_staging51("select Total_KM,DateOf_journey from matrix.consolidate where sys_service_id in (".$vehListId.") and DateOf_journey >= '".$fromdate."' and DateOf_journey <= '".$todate."'", $condition); return $this->data; } function getMonthlyTotalKMAll($vehListId,$fromdate,$todate) { $condition = ""; $db_name="matrix"; $orderBy=""; $this->data=db__select_staging51("select round(sum(Total_KM)) as Total_KM, DateOf_journey from matrix.consolidate where sys_service_id in (".$vehListId.") and DateOf_journey >= '".$fromdate."' and DateOf_journey <= '".$todate."' group by DateOf_journey", $condition); return $this->data; } function getYearlyTotalKM($vehListId,$fromdate,$todate) { $condition = ""; $db_name="matrix"; $orderBy=""; $this->data=db__select_staging51("select round(sum(Total_KM)) as Total_KM, DATE_FORMAT(DateOf_journey,'%b-%Y') AS monthyear from consolidate where sys_service_id in (".$vehListId.") and DateOf_journey >= '".$fromdate."' and DateOf_journey <= '".$todate."' group by DATE_FORMAT(DateOf_journey, '%b-%Y') order by DateOf_journey", $condition); return $this->data; } function getYearlyTotalKMAll($vehListId,$fromdate,$todate) { $condition = ""; $db_name="matrix"; $orderBy=""; $this->data=db__select_staging51("select round(sum(Total_KM)) as Total_KM, DATE_FORMAT(DateOf_journey,'%b-%Y') AS monthyear from consolidate where sys_service_id in (".$vehListId.") and DateOf_journey >= '".$fromdate."' and DateOf_journey <= '".$todate."' group by DATE_FORMAT(DateOf_journey, '%b-%Y') order by DateOf_journey ", $condition); return $this->data; } function getMovemetData($userid,$groupid,$vehicleList,$dateStart,$dateEnd) { $condition = ""; $db_name="matrix"; $orderBy=""; $wherespeed=""; $speedcheck = 140; $Diagnostic11 = array(); $obj = new MyClass(); //echo 11;die; if (((((strtotime($dateEnd)) - (strtotime($dateStart))) / 3600) / 31) > 300) { $dateEnd = date('Y-m-d H:i', (strtotime($dateStart)) + ((3600 * 31 * 300) - 1)); } $objDbManager = new DbManager(); $dbArray = $objDbManager->returnDbArray($dateStart, $dateEnd); /*if ($diff_of_minutes != "") { $goupbymin = $diff_of_minutes * 60; $ExtraQry1 = " and gps_fix=1 GROUP BY (UNIX_TIMESTAMP(gps_time)) DIV " . $goupbymin; } else { //$ExtraQry1 = " group by gps_time "; $ExtraQry1 = " and gps_fix=1 GROUP BY (UNIX_TIMESTAMP(gps_time)) DIV 60"; }*/ $ExtraQry1 = " and gps_fix=1 GROUP BY (UNIX_TIMESTAMP(gps_time)) DIV 60"; $start_date = date("Y-m-d H:i:s", strtotime('-330 minutes', strtotime($dateStart))); $end_date = date("Y-m-d H:i:s", strtotime('-330 minutes', strtotime($dateEnd))); $veh_id=$vehicleList; //echo $veh_id;die; for($countYear=0;$countYear".$speedcheck." then '0' else round(gps_speed*1.609,0) end as gps_speed1,geo_street,geo_town,geo_country, geo_postcode, jny_distance, jny_duration, case when tel_ignition=true then true else false end as aconoff, case when tel_panic=true then true else false end as tel_panic, jny_idle_time,case when tel_poweralert=false then false else true end as tel_poweralert, case when tel_input_1=true then true else false end as tel_input_1, case when tel_input_0=true then true else false end as tel_input_0,tel_voltage, case when tel_input_2=true then true else false end as tel_input_2,tel_temperature,tel_fuel,case when tel_input_3=true then true else false end as tel_input_3 from ".$dbArray[$countYear].".telemetry_new where sys_service_id=".$veh_id." and CONCAT(gps_date,' ',gps_time) >= '".$start_date."' and CONCAT(gps_date,' ',gps_time) <= '".$end_date."' ", $condition); $navData[]=db__select_staging51("select sys_proc_time,tel_rfid,CONCAT(gps_date,' ',gps_time) as gps_time,id,sys_msg_type, gps_latitude,main_powervoltage,tel_odometer, gps_longitude, case when round(gps_speed*1.609,0)>".$speedcheck." then '0' else round(gps_speed*1.609,0) end as gps_speed1,geo_street,geo_town,geo_country, geo_postcode, jny_distance, jny_duration, case when tel_ignition=true then true else false end as aconoff, case when tel_panic=true then true else false end as tel_panic, jny_idle_time,case when tel_poweralert=false then false else true end as tel_poweralert, case when tel_input_1=true then true else false end as tel_input_1, case when tel_input_0=true then true else false end as tel_input_0,tel_voltage, case when tel_input_2=true then true else false end as tel_input_2,tel_temperature,tel_fuel,case when tel_input_3=true then true else false end as tel_input_3 from ".$dbArray[$countYear].".telemetry_new_15 where sys_service_id=".$veh_id." and CONCAT(gps_date,' ',gps_time) >= '".$start_date."' and CONCAT(gps_date,' ',gps_time) <= '".$end_date."' ", $condition); $navData[]=db__select_staging51("select sys_proc_time,tel_rfid,CONCAT(gps_date,' ',gps_time) as gps_time,id,sys_msg_type, gps_latitude,main_powervoltage,tel_odometer, gps_longitude, case when round(gps_speed*1.609,0)>".$speedcheck." then '0' else round(gps_speed*1.609,0) end as gps_speed1,geo_street,geo_town,geo_country, geo_postcode, jny_distance, jny_duration, case when tel_ignition=true then true else false end as aconoff, case when tel_panic=true then true else false end as tel_panic, jny_idle_time,case when tel_poweralert=false then false else true end as tel_poweralert, case when tel_input_1=true then true else false end as tel_input_1, case when tel_input_0=true then true else false end as tel_input_0,tel_voltage, case when tel_input_2=true then true else false end as tel_input_2,tel_temperature,tel_fuel,case when tel_input_3=true then true else false end as tel_input_3 from ".$dbArray[$countYear].".telemetry_idle where telemetry_idle.sys_proc_host!='TRACKINGEXPERTS_94' and sys_service_id=".$veh_id." and CONCAT(gps_date,' ',gps_time) >= '".$start_date."' and CONCAT(gps_date,' ',gps_time) <= '".$end_date."' ", $condition); if($dbArray[$countYear]=="matrix") { $navData[]=db__select_staging62("select sys_proc_time,tel_rfid,gps_time as gps_time,id,sys_msg_type, gps_latitude,main_powervoltage,tel_odometer, gps_longitude, case when round(gps_speed*1.609,0)>".$speedcheck." then '0' else round(gps_speed*1.609,0) end as gps_speed1,geo_street,geo_town,geo_country, geo_postcode, jny_distance, jny_duration, case when tel_ignition=true then true else false end as aconoff, case when tel_panic=true then true else false end as tel_panic, jny_idle_time,case when tel_poweralert=false then false else true end as tel_poweralert, case when tel_input_1=true then true else false end as tel_input_1, case when tel_input_0=true then true else false end as tel_input_0,tel_voltage, case when tel_input_2=true then true else false end as tel_input_2,tel_temperature,tel_fuel,case when tel_input_3=true then true else false end as tel_input_3 from ".$dbArray[$countYear].".today_ideal where sys_service_id=".$veh_id." and sys_proc_host!='TRACKINGEXPERTS_94' and gps_time>'".$start_date."' and gps_time<='".$end_date."' ", $condition); $navData[]=db__select_staging62("select sys_proc_time,tel_rfid,gps_time as gps_time,id,sys_msg_type, gps_latitude,main_powervoltage,tel_odometer, gps_longitude, case when round(gps_speed*1.609,0)>".$speedcheck." then '0' else round(gps_speed*1.609,0) end as gps_speed1,geo_street,geo_town,geo_country, geo_postcode, jny_distance, jny_duration, case when tel_ignition=true then true else false end as aconoff, case when tel_panic=true then true else false end as tel_panic, jny_idle_time,case when tel_poweralert=false then false else true end as tel_poweralert, case when tel_input_1=true then true else false end as tel_input_1, case when tel_input_0=true then true else false end as tel_input_0,tel_voltage, case when tel_input_2=true then true else false end as tel_input_2,tel_temperature,tel_fuel,case when tel_input_3=true then true else false end as tel_input_3 from ".$dbArray[$countYear].".today_speed where sys_service_id=".$veh_id." and gps_time>'".$start_date."' and gps_time<='".$end_date."' ". $wherespeed." ", $condition); $navData[]=db__select_staging62("select sys_proc_time,tel_rfid,gps_time as gps_time,id,sys_msg_type, gps_latitude,main_powervoltage,tel_odometer, gps_longitude, case when round(gps_speed*1.609,0)>".$speedcheck." then '0' else round(gps_speed*1.609,0) end as gps_speed1,geo_street,geo_town,geo_country, geo_postcode, jny_distance, jny_duration, case when tel_ignition=true then true else false end as aconoff, case when tel_panic=true then true else false end as tel_panic, jny_idle_time,case when tel_poweralert=false then false else true end as tel_poweralert, case when tel_input_1=true then true else false end as tel_input_1, case when tel_input_0=true then true else false end as tel_input_0,tel_voltage, case when tel_input_2=true then true else false end as tel_input_2,tel_temperature,tel_fuel,case when tel_input_3=true then true else false end as tel_input_3 from ".$dbArray[$countYear].".today_ideal_".date("d")."_a where sys_service_id=".$veh_id." and sys_proc_host!='TRACKINGEXPERTS_94' and gps_time>'".$start_date."' and gps_time<='".$end_date."' ", $condition); $navData[]=db__select_staging62("select sys_proc_time,tel_rfid,gps_time as gps_time,id,sys_msg_type, gps_latitude,main_powervoltage,tel_odometer, gps_longitude, case when round(gps_speed*1.609,0)>".$speedcheck." then '0' else round(gps_speed*1.609,0) end as gps_speed1,geo_street,geo_town,geo_country, geo_postcode, jny_distance, jny_duration, case when tel_ignition=true then true else false end as aconoff, case when tel_panic=true then true else false end as tel_panic, jny_idle_time,case when tel_poweralert=false then false else true end as tel_poweralert, case when tel_input_1=true then true else false end as tel_input_1, case when tel_input_0=true then true else false end as tel_input_0,tel_voltage, case when tel_input_2=true then true else false end as tel_input_2,tel_temperature,tel_fuel,case when tel_input_3=true then true else false end as tel_input_3 from ".$dbArray[$countYear].".today_speed_".date("d")."_a where sys_service_id=".$veh_id." and gps_time>'".$start_date."' and gps_time<='".$end_date."' ". $wherespeed." ", $condition); $navData[]=db__select_staging62("select sys_proc_time,tel_rfid,gps_time as gps_time,id,sys_msg_type, gps_latitude,main_powervoltage,tel_odometer, gps_longitude, case when round(gps_speed*1.609,0)>".$speedcheck." then '0' else round(gps_speed*1.609,0) end as gps_speed1,geo_street,geo_town,geo_country, geo_postcode, jny_distance, jny_duration, case when tel_ignition=true then true else false end as aconoff, case when tel_panic=true then true else false end as tel_panic, jny_idle_time,case when tel_poweralert=false then false else true end as tel_poweralert, case when tel_input_1=true then true else false end as tel_input_1, case when tel_input_0=true then true else false end as tel_input_0,tel_voltage, case when tel_input_2=true then true else false end as tel_input_2,tel_temperature,tel_fuel,case when tel_input_3=true then true else false end as tel_input_3 from matrix.telemetry where sys_service_id=".$veh_id." and gps_time>'".$start_date."' and gps_time<='".$end_date."' ". $wherespeed." ", $condition); } } $data1 = array(); for ($countNavData = 0; $countNavData < count($navData); $countNavData++) { if (is_array($navData[$countNavData])) { $data1 = array_merge($data1, $navData[$countNavData]); } } //print_r($data1);die; $obj1 = new MyClass(); $data2 = $obj1->array_msort($data1, array( 'gps_time' => SORT_ASC )); $Diagnosticdatatable = array(); foreach ($data2 as $val) { $Diagnosticdatatable[] = $val; } $no = 0; $Odometer = 0; $calcObj = new calculate_distance(); $status = ''; $Diagnostic = array(); $totalDistance = 0; $Comarerow = 0; $Comarerowstatus = false; $sr = 0; $lastodometer = 0; $total_running_hr = 0; $total_idle_hr = 0; $calcObj = new calculate_distance(); $running = false; $stop = false; $Mergediagnosticarray = array(); $Diagnostic = array(); $totalDistance = 0; $Comarerow = 0; $Comarerowstatus = false; $_SESSION['KM_for']=5; if($groupid!="54964") { for ($dd = 1; $dd < count($Diagnosticdatatable); $dd++) { if ($Comarerowstatus == false) { $Comarerow = $dd-1; } $timeFirst = strtotime($Diagnosticdatatable[$Comarerow]['gps_time']); $timeSecond = strtotime($Diagnosticdatatable[$dd]['gps_time']); $differenceInSeconds = $timeSecond - $timeFirst; $differenceInSeconds=$differenceInSeconds + 180; $Duration=$obj->dateDifferenceSecond($Diagnosticdatatable[$dd]['gps_time'],$Diagnosticdatatable[$Comarerow]['gps_time']); $DiffMintoCHk=$Duration+3; $ActualKMruninmeter=$differenceInSeconds*15; $PointArray[0]['lat']=$Diagnosticdatatable[$dd]['gps_latitude']; $PointArray[0]['long']=$Diagnosticdatatable[$dd]['gps_longitude']; $PointArray[1]['lat']=$Diagnosticdatatable[$Comarerow]['gps_latitude']; $PointArray[1]['long']=$Diagnosticdatatable[$Comarerow]['gps_longitude']; $distance = $calcObj->calc_distance($PointArray); $distanceinmeter= $distance*1000; // echo $Diagnosticdatatable[$Comarerow]['gps_time'];echo "---";echo $Diagnosticdatatable[$dd]['gps_time']; echo "---";echo $distance;echo "
"; if($distance<2500 && $ActualKMruninmeter>$distanceinmeter) { $Comarerowstatus = false; $Diagnosticroweach = array( 'id' => $Diagnosticdatatable[$dd]['id'], 'gps_time' => $Diagnosticdatatable[$dd]['gps_time'], 'sys_proc_time' => $Diagnosticdatatable[$dd]['sys_proc_time'], 'sys_msg_type' => $Diagnosticdatatable[$dd]['sys_msg_type'], 'gps_latitude' => $Diagnosticdatatable[$dd]['gps_latitude'], 'main_powervoltage' => $Diagnosticdatatable[$dd]['main_powervoltage'], 'gps_longitude' => $Diagnosticdatatable[$dd]['gps_longitude'], //'gps_speed' => $Diagnosticdatatable[$dd]['gps_speed'], 'gps_speed1' => $Diagnosticdatatable[$dd]['gps_speed1'], 'geo_street' => $Diagnosticdatatable[$dd]['geo_street'], 'geo_town' => $Diagnosticdatatable[$dd]['geo_town'], 'geo_country' => $Diagnosticdatatable[$dd]['geo_country'], 'jny_distance' => $Diagnosticdatatable[$dd]['jny_distance'], 'jny_duration' => $Diagnosticdatatable[$dd]['jny_duration'], 'aconoff' => $Diagnosticdatatable[$dd]['aconoff'], 'tel_panic' => $Diagnosticdatatable[$dd]['tel_panic'], 'jny_idle_time' => $Diagnosticdatatable[$dd]['jny_idle_time'], 'tel_poweralert' => $Diagnosticdatatable[$dd]['tel_poweralert'], 'tel_input_1' => $Diagnosticdatatable[$dd]['tel_input_1'], 'tel_input_0' => $Diagnosticdatatable[$dd]['tel_input_0'], 'tel_input_2' => $Diagnosticdatatable[$dd]['tel_input_2'], 'tel_temperature' => $Diagnosticdatatable[$dd]['tel_temperature'], 'tel_fuel' => $Diagnosticdatatable[$dd]['tel_fuel'], //'gps_orientation' => $Diagnosticdatatable[$dd]['gps_orientation'], 'tel_odometer' => $Diagnosticdatatable[$dd]['tel_odometer'], 'tel_rfid' => $Diagnosticdatatable[$dd]['tel_rfid'], //'tel_rawlog' => $Diagnosticdatatable[$dd]['tel_rawlog'] ); array_push($Diagnostic, $Diagnosticroweach); } else { $dd=$dd+1; $Comarerowstatus = true; } } } else { $Diagnostic=$Diagnosticdatatable; } for ($i = 0; $i < count($Diagnostic); $i++) { $distance = 0; $local_time = date("Y-m-d H:i:s", strtotime($speedcheck . ' minutes', strtotime($Diagnostic[$i]['gps_time']))); $minutes = date("i", strtotime($Diagnostic[$i]['gps_time'])); if($i>=1) { $minutes_1 = date("i", strtotime($Diagnostic[$i-1]['gps_time'])); } else { $minutes_1 = ""; } if ($local_time >= $dateStart) { if ($local_time <= $dateEnd) { $Date = date("Y-m-d H:i:s", strtotime($speedcheck . ' minutes', strtotime($Diagnostic[$i]['gps_time']))); if($i==0) { $firstDate = date("Y-m-d H:i:s", strtotime($speedcheck . ' minutes', strtotime($Diagnostic[$i]['gps_time']))); } else { $firstDate = date("Y-m-d H:i:s", strtotime($speedcheck . ' minutes', strtotime($Diagnostic[$i-1]['gps_time']))); } $PointArray[0]['lat'] = $Diagnostic[$i]['gps_latitude']; $PointArray[0]['long'] = $Diagnostic[$i]['gps_longitude']; if($i>=1) { $PointArray[1]['lat'] = $Diagnostic[$i - 1]['gps_latitude']; $PointArray[1]['long'] = $Diagnostic[$i - 1]['gps_longitude']; } else { $PointArray[1]['lat'] = ''; $PointArray[1]['long'] = ''; } if ($PointArray[1]['lat'] != "") { $distance = $calcObj->calc_distance($PointArray); } $checkKm=1000; //echo $Diagnostic[$i]['gps_time'].",".$Diagnostic[$i-1]['gps_time']; // echo "
"; $Duration=0; if($i>=1) { $Duration=$obj->dateDifference($Diagnostic[$i]['gps_time'],$Diagnostic[$i-1]['gps_time']); } $Duration=$Duration+5; //if ($distance >= $Duration ) { if ($distance >= $checkKm) { $distance=0; // echo ";;;". $distance ; //} } $Odometer = $Odometer + $distance; /*if(round($Diagnostic[$i]['gps_speed1'],2)>5) { $Diagnostic[$i]['tel_input_0'] = 1; }else{ $Diagnostic[$i]['tel_input_0'] = 0; }*/ // if($Diagnostic[$i]['gps_speed']>5) // { // $Diagnostic[$i]['tel_input_0']=1; // } if($Diagnostic[$i]['tel_input_0']==0) { //$Diagnostic[$i]['gps_speed']=0; } $no = $no + 1; $Timediff = $obj->dateDifferenceSecond($firstDate, $Date); $getMinute = $Timediff/60; if($Diagnostic[$i]['tel_input_0']==true) { $status = 'Ignition On'; } elseif($Diagnostic[$i]['tel_input_0']==false) { $status = 'Ignition off'; } else { $status = '--'; } //$status =$Diagnostic[$i]['tel_input_0']; if($Diagnostic[$i]['aconoff']==1) { $ACstatus = 'AC On'; } elseif($Diagnostic[$i]['aconoff']==0) { $ACstatus = 'AC off'; } else { $ACstatus = '--'; } /*$TimeTakeninsec = $obj->dateDifferenceSecond($Diagnostic[$i]['gps_time'],$Diagnostic[$i-1]['gps_time']); $speedDifference=$Diagnostic[$i]['gps_speed']-$Diagnostic[$i-1]['gps_speed']; if($speedDifference>60 ) { if($TimeTakeninsec>600) { $Showspeed=$Diagnostic[$i-1]['gps_speed']; } else { $Showspeed=$Diagnostic[$i]['gps_speed']; } } else { $Showspeed=$Diagnostic[$i]['gps_speed']; } */ $Showspeed=$Diagnostic[$i]['gps_speed1']; /*$html.=''.$sr.' '.$Diagnostic[$i]['gps_time'].' '.$Diagnostic[$i]['gps_speed'].' '.$location_data.' ';*/ if($Diagnostic[$i]['gps_speed1']>140) { $Showspeed=0; } /*if(in_array($_SESSION['sys_group_id'], $SppedclientGt) || in_array($_SESSION['sys_group_id_parent'], $SppedclientGt)) { if($Diagnostic[$i]['gps_speed']>70) { $Showspeed=0; } }*/ // if($Diagnostic[$i-1]['gps_speed1']==$Diagnostic[$i]['gps_speed1']) // { // //$Showspeed=0; // } $EngineSta="Engine OFF"; if($Diagnostic[$i]['jny_distance']>0) { $EngineSta="Engine ON"; } $startlocation = ''; /*if($report_location == "Show_Location") {*/ /*if($redis_data = getRedisLocation($userid,$Diagnostic[$i]["gps_latitude"],$Diagnostic[$i]["gps_longitude"],$redis)) { $startlocation = $redis_data['LocationName']; //$KMFromNearPOI = $redis_data['KMFromNearPOI']; } else { $startlocation = ''; }*/ /*} else { $startlocation = ''; }*/ $Diagnosticroweach_fin = array( 'id' => $Diagnostic[$i]['id'], 'Date' => $Date, 'sys_proc_time' => $Diagnostic[$i]['sys_proc_time'], 'gps_time' => $Diagnostic[$i]['gps_time'], 'distance' => $distance, 'Odometer' => $Odometer, 'gps_speed1' => round($Diagnostic[$i]['gps_speed1'],2), 'ACstatus' => $ACstatus, 'startlocation' => $startlocation, //'Distancetoempty' => $Distancetoempty, 'gps_latitude' => $Diagnostic[$i]['gps_latitude'], 'gps_longitude' => $Diagnostic[$i]['gps_longitude'], //'status' => $Diagnostic[$i]['status'], //'EngineSta' => $Diagnostic[$i]['EngineSta'], 'tel_odometer' => $Diagnostic[$i]['tel_odometer'], ); array_push($Diagnostic11, $Diagnosticroweach_fin); } } } //echo "
";print_r($Diagnostic11);die;

 		return $Diagnostic11;
    }

function getAuthUser($username)
	{
	    $condition = "";
		$db_name="alert_management";

		$userarray = db__select("SELECT * FROM matrix.users WHERE users.sys_active = 1 AND (users.sys_parent_user IN (6347) OR users.id IN (6347)) AND users.sys_username = '".$username."' ", $condition);

		if(count($userarray)>0) {
			return 1;
		} else {
	    	return 0;
		}
	}

	function getAuthEmails($email,$username)
	{
	    $condition = "";
		$db_name="alert_management";

		$userarray = db__select_staging("SELECT * FROM auth_emails WHERE ms_email = '".$email."' and username = '".$username."' AND STATUS = 1 ", $condition);

		if(count($userarray)>0) {
			return 1;
		} else {
	    	return 0;
		}
	}

	


	function getAllVehiclesIds($Group_id)
	{
	    $condition = "";
		$db_name="matrix";

	    $this->data=db__select_staging62("SELECT sys_Service_id FROM group_services WHERE sys_group_id=".$Group_id." AND `active` = 1;", $condition);

	    //echo count($this->data);die;		
	    return $this->data;
	}

	function getevents($userid)
	{
	    $condition = "";
		$db_name="alert_management";


		$userarray = $this->data=db__select_staging("SELECT id,`name`,title,image,logo,popup_image,header_image,`status` FROM `events` WHERE `status` = 1 AND user_id = ".$userid." order by id desc limit 1", $condition);

		if(count($userarray)>0) {
			$this->data = $userarray;
		} else {
	    	$this->data=db__select_staging("SELECT id,`name`,title,image,logo,popup_image,header_image,`status` FROM `events` WHERE NOW() BETWEEN `from_date` AND `to_date` AND `status` = 1 order by id desc limit 1", $condition);
		}
	    //echo count($this->data);die;
	    return $this->data;
	}
	function getuserevents($userid,$token,$event_id)
	{
	    $condition = "";
		$db_name="alert_management";
		//echo "SELECT id,last_date FROM events_track WHERE event_id = ".$event_id." AND userid = ".$userid." AND groupid = ".$token." ";die;

	    $this->data=db__select_staging("SELECT id,last_date FROM events_track WHERE event_id = ".$event_id." AND userid = ".$userid." AND groupid = ".$token." ", $condition);

	    //echo count($this->data);die;
	    return $this->data;
	}

	 function getVehiclealerts($token,$vehiclesid,$alert_type)
	{
	    $condition = "";
		$db_name="alert_management";

		$queryextra = "";

		if($vehiclesid!='') {
			$queryextra .= " AND sra.sys_service_id = '".$vehiclesid."' ";
		}
		if($alert_type!='') {
			$queryextra .= " AND sra.alert_type = '".$alert_type."' ";
		}

		$sql = "SELECT sra.id,sra.sys_service_id,sra.alert_type,sra.service_document_date,sra.gap_service_document_date,sra.service_km,sra.sys_group_id,sra.alert_message,sra.active,sra.email,sra.mobile,sra.sms,sra.next_service_km,sra.service_gap_km, s.veh_reg, s.veh_cubic_capacity as odometer, s.overspeed_lastchk as odometer_lastdate FROM service_renewal_alerts AS sra LEFT JOIN services s ON s.id = sra.sys_service_id WHERE sra.sys_group_id='".$token."' and sra.active = 1 ".$queryextra." ORDER BY id";

		$data = db__select_staging62($sql, $condition);

		//print_r($data);die;

		if(count($data)>0) {
			return $data;
		} else {
	    	return 0;
		}
	}


}
?>