<?php
header("refresh: 30;");
date_default_timezone_set('America/Bogota');
include('../config/database.php');
$metodo=$_SERVER['REQUEST_METHOD'];
if($metodo=='GET'){
    if(isset($_GET['lista'])){
        $query = mysqli_query($mysqli, "SELECT * FROM fotos_guia WHERE id_fotos > '23892' AND estado=0 AND (foto1 != '' || foto2 != '' || foto3 != '') LIMIT 20") or die('Error en la consulta'. mysqli_error($mysqli));
        
        $json = array(); 
        while($row = mysqli_fetch_array($query)){
            $id = $row['id_fotos']; 
            $f1 = $row['foto1'];
            $f2 = $row['foto2'];
            $f3 = $row['foto3'];
            if($f1 != ''){
                $url = 'http://141.148.135.189/soportes/datos_logitrack.php';
                $postData = '{
                  "id" : "'.$id.'",
                  "foto": "'.$f1.'"
                }';
                
                $curl = curl_init($url);
                curl_setopt($curl, CURLOPT_POST, true);
                curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
                curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
                $result = curl_exec($curl);
                curl_close($curl);
                $urlf1 = $result;
                $update = mysqli_query($mysqli, "UPDATE fotos_guia SET estado = '1', foto1='$urlf1' WHERE id_fotos = $id") or die('Error en la consulta'. mysqli_error($mysqli));
            }
            if($f2 != ''){
                $url = 'http://141.148.135.189/soportes/datos_logitrack.php';
                $postData = '{
                  "id" : "'.$id.'",
                  "foto": "'.$f2.'"
                }';
                
                $curl = curl_init($url);
                curl_setopt($curl, CURLOPT_POST, true);
                curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
                curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
                $result = curl_exec($curl);
                curl_close($curl);
                $urlf2 = $result;
                $update = mysqli_query($mysqli, "UPDATE fotos_guia SET estado = '1', foto2='$urlf2' WHERE id_fotos = $id") or die('Error en la consulta'. mysqli_error($mysqli));
            }
            if($f3 != ''){
                $url = 'http://141.148.135.189/soportes/datos_logitrack.php';
                $postData = '{
                  "id" : "'.$id.'",
                  "foto": "'.$f3.'"
                }';
                
                $curl = curl_init($url);
                curl_setopt($curl, CURLOPT_POST, true);
                curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
                curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
                $result = curl_exec($curl);
                curl_close($curl);
                $urlf3 = $result;
                $update = mysqli_query($mysqli, "UPDATE fotos_guia SET estado = '1', foto3='$urlf3' WHERE id_fotos = $id") or die('Error en la consulta'. mysqli_error($mysqli));
            }
           echo "Se cargo la foto:".$id.'<br>';     
        }
    }
    if(isset($_GET['f1'])){
        $id = $_GET['f1'];
        $query = mysqli_query($mysqli, "SELECT * FROM fotos_guia WHERE id_fotos='$id'") or die('Error en la consulta'. mysqli_error($mysqli));
        $row = mysqli_fetch_array($query);
        $foto1 = $row['foto1'];
        //$update = mysqli_query($mysqli, "UPDATE fotos_guia SET estado = '1', foto1='$foto1' WHERE id_fotos = $id") or die('Error en la consulta'. mysqli_error($mysqli));
        echo $foto1;
    }
    
    if(isset($_GET['f2'])){
        $id = $_GET['f2'];
        $foto2 = $_GET['foto2'];
        $update = mysqli_query($mysqli, "UPDATE fotos_guia SET estado = '1', foto2='$foto2' WHERE id_fotos = $id") or die('Error en la consulta'. mysqli_error($mysqli));
        echo "Hecho2";
    }
    
    if(isset($_GET['f3'])){
        $id = $_GET['f3'];
        $foto3 = $_GET['foto3'];
        $update = mysqli_query($mysqli, "UPDATE fotos_guia SET estado = '1', foto3='$foto3' WHERE id_fotos = $id") or die('Error en la consulta'. mysqli_error($mysqli));
        echo "Hecho3";
    }
}
        