<?php
$_req = "UPDATE BIBLIOTECA_ELEMENTOS ";
$_set = "SET PAPELERA = 0, MODIFICACION = now()";
$doc_id = $bd_conn->real_escape_string($_POST["doc_id"]);
$_where = " WHERE CLAVE = '" . $doc_id . "' ";
foreach ($_POST as $key => $value) {
    $value = $bd_conn->real_escape_string($value);
    switch ($key) {
        case 'doc_name':
            $_set .= ", NOMBRE = '" . $value . "'"; 
            break;
        case 'doc_size':
            $_set .= ", TAMANO = '" . $value . "'"; 
            break;
    }
}
$status_datos = queryUpdate($bd_conn, $_req, $_set, $_where);
if (isset($_POST["doc_fichero"])) {
    $coding_file = $_POST["doc_fichero"];
    include ("IncludeUpdateDocFichero.php");
}elseif (isset($_POST["doc_fichero_json"])) {
    $file_json = json_decode($_POST["doc_fichero_json"]);
    if (isset($file_json[0]->file)) {
        $coding_file = $file_json[0]->file;
        include ("IncludeUpdateDocFichero.php");
    }else {
        $data[] = array ( 
            "status" => "NOT OK",
            "message" => "error : doc update but doc_fichero_json is missing"
        );
    }
}
if ($status_datos === 1 OR $status_fichero == 1) {
    $data[] = array ( 
        "status" => "OK",
        "message" => "success : update doc success"
    );
}else{
    $data[] = array ( 
        "status" => "NOT OK",
        "message" => "error : update doc error"
    );
}
//FUNCIONES================================================================
function queryUpdate($bd, $_req, $_set, $_where)
{
    $query = $_req . $_set . $_where;
    mysqli_query($bd, $query);
    return mysqli_affected_rows($bd);
}
?>