<?php

if (isset($_SERVER['HTTP_ORIGIN'])) {
    header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
    header('Access-Control-Allow-Credentials: true');
    header('Access-Control-Max-Age: 86400'); // cache for 1 day
}

include 'conn.php';
//Select data from database

include 'funciones.php';

session_start();

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $data = json_decode(file_get_contents("php://input"), true);
    //print_r($data);
    //print_r( json_encode($data));

}

$books = $data;

//echo ' hola '. $books["database"] ;

$_SESSION['database'] = $books["database"];

$hoynow = getdate();

$timeStamp = $hoynow["year"] . "-" . $hoynow["mon"] . "-" . $hoynow["mday"] . " " . $hoynow["hours"] . ":" . $hoynow["minutes"] . ":" . $hoynow["seconds"];

logs($timeStamp);

$SQLupdate1 = "delete from   " . $_SESSION['database'] . ".toma_inv  where status=1 and nodoc='3'";

logs($SQLupdate1);

if ($connection->query($SQLupdate1) === true) {

    $result = (object) array(
        'success' => 'true',
        'registro' => 1,
        'msg' => "Borrado correctamente",
    );
    print_r(json_encode($result));

} else {

    $result = (object) array(
        'success' => 'false',
        'registro' => 0,
        'msg' => "Error Borrado",
    );
    print_r(json_encode($result));

}

@mysqli_close($connection);
?>
