<?
	$data = json_decode(file_get_contents("php://input"), true);	
	$loc = $data;
       
        $mysqli = new mysqli('10.118.144.75', 'external', 'mYREbJG0E1lW', 'gpsimple');   
        //$mysqli = new mysqli('192.168.1.127','root','Stech..,','gpsimple'); 
        $q1  = "SELECT user,password,empresa, id_empresa, id_grupo 
                FROM st_user_proveedor where user='".$loc['user']."' and password='".$loc['password']."' and empresa='".$loc['empresa']."'";
	$r1 = mysqli_query($mysqli, $q1);

        if($row1 = mysqli_fetch_row($r1)){	
                $id_empresa = $row1[3];
                $id_grupo = $row1[4];
               	
		$q3 = "SELECT gs_objects.plate_number,
                                SUBSTRING(gs_objects.model,1,locate('/',gs_objects.model)-1) as 'marca',
                                SUBSTRING(gs_objects.model,locate('/',gs_objects.model)+1,LENGTH(gs_objects.model)) as 'modelo',
                                gs_objects.lat,
                                gs_objects.lng,
                                gs_objects.dt_tracker,
                                gs_objects.speed,
                                gs_objects.angle 
                                FROM gs_objects,gs_user_objects
                                WHERE gs_user_objects.user_id = ".$id_empresa ."
                                AND gs_user_objects.group_id = ".$id_grupo ."
                                AND  gs_user_objects.imei = gs_objects.imei";        


             	$r3 = mysqli_query($mysqli, $q3);
                $i = 0;
                while($row3 = mysqli_fetch_assoc($r3)){
                        $result[$i++] = array(  'Pat'           => $row3['plate_number'],
                                                'Mar'           => $row3['marca'],
                                                'Mod'           => $row3['modelo'],
                                                'lat'           => $row3['lat'],
                                                'lng'           => $row3['lng'],
                                                'dt_tracker'    => $row3['dt_tracker'],
                                                'speed'         => $row3['speed'],
                                                'angle'         => $row3['angle']);  
                }
	}else{
		$result = array("status" => "Usuario o password invalida");				
	}
               
        header('Content-type: application/json');
	if($i == 0) {
		$result = array("status" => "Sin Datos");
	}      

	echo json_encode($result);  

?>
