191 lines
7.6 KiB
PHP
191 lines
7.6 KiB
PHP
<?php
|
|
header('Access-Control-Allow-Origin: *');
|
|
include("mysql.php");
|
|
|
|
$id_viaje = $_POST['id_viaje'];
|
|
$n_proveedor = $_POST['n_proveedor'];
|
|
$usuario = $_POST['usuario'];
|
|
$id_estado = $_POST['id_estado'];
|
|
$incidencia = $_POST['incidencia'];
|
|
$latitud = $_POST['latitud'];
|
|
$longitud = $_POST['longitud'];
|
|
$nombre = $_POST['nombre'] . '.jpg';
|
|
|
|
if ($nombre == "vacio.jpg") {
|
|
$nombre = NULL;
|
|
}
|
|
|
|
$consulta = "SELECT count(*) from c_cambios_estado where id_viaje='" . $id_viaje . "' and id_estado='" . $id_estado . "' and foto='" . $nombre . "'";
|
|
$rResult2 = mysqli_query($gaSql['link'], $consulta) or fatal_error('MySQL Error: ' . mysqli_errno($gaSql['link']));
|
|
$fila = mysqli_fetch_row($rResult2);
|
|
$duplicado = $fila[0];
|
|
|
|
if ($duplicado > 0) {
|
|
echo json_encode("0");
|
|
die();
|
|
}
|
|
|
|
$sQuery2 = "UPDATE c_viajes SET id_estado = $id_estado, ind_edi_app = 1 WHERE id_viaje = $id_viaje";
|
|
$rResult2 = mysqli_query($gaSql['link'], $sQuery2) or fatal_error('MySQL Error: ' . mysqli_errno($gaSql['link']));
|
|
|
|
$sQuery2 = "INSERT INTO c_cambios_estado (id_viaje, n_proveedor, id_transportista, id_estado, incidencia, latitud, longitud, fecha_y_hora, foto) VALUES ('" . $id_viaje . "','" . $n_proveedor . "','" . $usuario . "','" . $id_estado . "','" . $incidencia . "','" . $latitud . "','" . $longitud . "',NOW(),'" . $nombre . "')";
|
|
$rResult2 = mysqli_query($gaSql['link'], $sQuery2) or fatal_error('MySQL Error: ' . mysqli_errno($gaSql['link']));
|
|
|
|
$consulta = "SELECT id_viaje_padre, id_cliente, cod_viaje from c_viajes where id_viaje='" . $id_viaje . "'";
|
|
$rResult2 = mysqli_query($gaSql['link'], $consulta) or fatal_error('MySQL Error: ' . mysqli_errno($gaSql['link']));
|
|
$fila = mysqli_fetch_row($rResult2);
|
|
$id_viaje_padre = $fila[0];
|
|
$id_cliente = $fila[1];
|
|
$cod_viaje = $fila[2];
|
|
|
|
while ($id_viaje_padre > 0) {
|
|
$consulta = "UPDATE `c_viajes` SET id_estado='" . $id_estado . "', ind_edi_app = 1 where id_viaje='" . $id_viaje_padre . "'";
|
|
$query_res = mysqli_query($gaSql['link'], $consulta);
|
|
|
|
$consulta = "INSERT INTO c_cambios_estado (id_viaje, n_proveedor, id_transportista, id_estado, incidencia, latitud, longitud, fecha_y_hora, foto) VALUES ('" . $id_viaje . "','" . $n_proveedor . "','" . $usuario . "','" . $id_estado . "','" . $incidencia . "','" . $latitud . "','" . $longitud . "',NOW(),'" . $nombre . "')";
|
|
$query_res = mysqli_query($gaSql['link'], $consulta);
|
|
|
|
//vover consultar para ver si se sale del bucle
|
|
$consulta = "SELECT id_viaje_padre, id_cr from c_viajes where id_viaje='" . $id_viaje_padre . "'";
|
|
$rResult2 = mysqli_query($gaSql['link'], $consulta) or fatal_error('MySQL Error: ' . mysqli_errno($gaSql['link']));
|
|
$fila = mysqli_fetch_row($rResult2);
|
|
$id_viaje_padre = $fila[0];
|
|
}
|
|
|
|
$resultado = "0";
|
|
|
|
$consulta = "SELECT html FROM html_correo WHERE id_mensaje = 34";
|
|
$rResult2 = mysqli_query($gaSql['link'], $consulta);
|
|
$fila = mysqli_fetch_row($rResult2);
|
|
$mensaje = $fila[0];
|
|
|
|
$consulta = "SELECT user_smtp_admin, user_smtp_admin, pass_smtp_admin, host_smtp, puerto_smtp, date_format(NOW(), '%Y-%m-%d_%H_%i_%s') as ahora, email_operaciones FROM m_cr WHERE id_cr = $cr";
|
|
$rResult2 = mysqli_query($gaSql['link'], $consulta);
|
|
$fila = mysqli_fetch_row($rResult2);
|
|
$email_operaciones = $fila[0];
|
|
$user_smtp = $fila[1];
|
|
$pass_smtp = $fila[2];
|
|
$host_smtp = $fila[3];
|
|
$puerto_smtp = $fila[4];
|
|
$ahora = $fila[5];
|
|
$email_operaciones = $fila[6];
|
|
|
|
$consulta = "SELECT estado FROM t_viaje_estados WHERE id_estado = $id_estado";
|
|
$rResult2 = mysqli_query($gaSql['link'], $consulta);
|
|
$fila = mysqli_fetch_row($rResult2);
|
|
$estado = $fila[0];
|
|
|
|
if (strlen($user_smtp) > 4 && strlen($pass_smtp) > 4 && strlen($host_smtp) > 4) {
|
|
|
|
$mail = new PHPMailer();
|
|
$mail->IsSMTP();
|
|
$mail->From = $user_smtp;
|
|
$mail->FromName = "Abian Service";
|
|
|
|
$html = '<br>Se ha cambiado el estado del viaje ' . $cod_viaje . ' a ' . $estado . ' mediante la APP';
|
|
|
|
$mail->AddAddress($email_operaciones);
|
|
$mail->SMTPAuth = true;
|
|
$mail->SMTPSecure = 'tls';
|
|
$mail->Host = $host_smtp;
|
|
$mail->Port = $puerto_smtp;
|
|
$mail->Username = $user_smtp;
|
|
$mail->Password = $pass_smtp;
|
|
$mail->CharSet = 'UTF-8';
|
|
$mail->Subject = "Facturas pendientes Abian Service";
|
|
$mail->Body = $mensaje . "<br>" . $html;
|
|
$mail->IsHTML(true);
|
|
$mail->SMTPDebug = 0;
|
|
|
|
if ($mail->Send()) {
|
|
echo json_encode("0");
|
|
} else {
|
|
echo json_encode("Error al enviar el correo");
|
|
}
|
|
|
|
} else {
|
|
echo json_encode("Error al enviar el correo: fallo con usuario/contraseña");
|
|
}
|
|
|
|
if ($id_cliente == 532) {
|
|
$consulta = "SELECT id_tipovehiculo AS matricula FROM c_viajes_proveedor WHERE id_viaje = $id_viaje AND n_proveedor = $n_proveedor";
|
|
$rResult2 = mysqli_query($gaSql['link'], $consulta) or fatal_error('MySQL Error: ' . mysqli_errno($gaSql['link']));
|
|
$fila = mysqli_fetch_row($rResult2);
|
|
$matricula = $fila[0];
|
|
|
|
$xml = '
|
|
<S:Envelope
|
|
xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"
|
|
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
|
|
<SOAP-ENV:Header/>
|
|
<S:Body>
|
|
<ns2:SubmitPosition xmlns="http://schemas.datacontract.org/2004/07/QESE.QFV.Classes.QAP"
|
|
xmlns:ns2="QESE.QFV.QAP" xmlns:ns3="http://schemas.datacontract.org/2004/07/System"
|
|
xmlns:ns4="http://schemas.microsoft.com/2003/10/Serialization/Arrays"
|
|
xmlns:ns5="http://schemas.datacontract.org/2004/07/QESE.QFV.Classes"
|
|
xmlns:ns6="http://schemas.datacontract.org/2004/07/FV.Enums"
|
|
xmlns:ns7="http://schemas.datacontract.org/2004/07/FV.Enums.DriverHours"
|
|
xmlns:ns8="http://schemas.microsoft.com/2003/10/Serialization/">
|
|
<ns2:credentials>
|
|
<Client>abian</Client>
|
|
<Password>TVwuW57u0^</Password>
|
|
<UserName>abian-5567</UserName>
|
|
<Version>1</Version>
|
|
</ns2:credentials>
|
|
<ns2:positions>
|
|
<Position>
|
|
<AssetCategory>1</AssetCategory>
|
|
<CID>5567</CID>
|
|
<CustomerName/>
|
|
<DT>
|
|
<ns3:DateTime>?fecha_hora?</ns3:DateTime>
|
|
<ns3:OffsetMinutes>0</ns3:OffsetMinutes>
|
|
</DT>
|
|
<DeviceType>14</DeviceType>
|
|
<From>' . $matricula . '</From>
|
|
<GatewayMsgId/>
|
|
<IdentifierType>12</IdentifierType>
|
|
<MSISDN>' . $matricula . '</MSISDN>
|
|
<RequestId>1</RequestId>
|
|
<Version>1</Version>
|
|
<Latitude>?latitud?</Latitude>
|
|
<Longitude>?longitud?</Longitude>
|
|
</Position>
|
|
</ns2:positions>
|
|
</ns2:SubmitPosition>
|
|
</S:Body>
|
|
</S:Envelope>';
|
|
|
|
$url = 'https://export.fleetvisor.eu/wsQAP/Positions.svc/ssl';
|
|
$str = date("Y-m-d");
|
|
$strb = date("H:i:s");
|
|
|
|
$fecha_hora = $str . "T" . $strb . "Z";
|
|
|
|
$xml = str_replace("?fecha_hora?", $fecha_hora, $xml);
|
|
$xml = str_replace("?latitud?", $latitud, $xml);
|
|
$xml = str_replace("?longitud?", $longitud, $xml);
|
|
|
|
//echo $xml;
|
|
|
|
$curl = curl_init();
|
|
curl_setopt($curl, CURLOPT_URL, $url);
|
|
curl_setopt($curl, CURLOPT_POST, true);
|
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
|
|
|
$headers = array(
|
|
"Content-Type: text/xml",
|
|
"SOAPAction: QESE.QFV.QAP/PositionsService/SubmitPosition"
|
|
);
|
|
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
|
|
|
|
$data = $xml;
|
|
|
|
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
|
|
|
|
$resp = curl_exec($curl);
|
|
curl_close($curl);
|
|
}
|
|
|
|
echo json_encode($resultado);
|
|
?>
|