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 = '
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 . "
" . $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 = ' abian TVwuW57u0^ abian-5567 1 1 5567
?fecha_hora? 0
14 ' . $matricula . ' 12 ' . $matricula . ' 1 1 ?latitud? ?longitud?
'; $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); ?>