<?php
include_once (ROOT . FOLDER_CORE . '/auth.php'); 
if ($auth == 1) {
    $cli_user = $_SERVER["HTTP_CLIENT_ID"];
    if (isset($_POST["doc_fichero"])) {
        $coding_file = $_POST["doc_fichero"];
        if (isset($_POST["doc_name"])) {
            if (isset($_POST["doc_size"])) {
                include_once ('servAddDoc_uploadDoc.php');
            }else {
                $data[] = array ( 
                    "status" => "NOT OK",
                    "message" => "error : doc_size is missing"
                );
            }
        }else {
            $data[] = array ( 
                "status" => "NOT OK",
                "message" => "error : doc_name is missing"
            );
        }                       
    }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;
            if (isset($_POST["doc_name"])) {
                if (isset($_POST["doc_size"])) {
                    include_once ('servAddDoc_uploadDoc.php');
                }else {
                    $data[] = array ( 
                        "status" => "NOT OK",
                        "message" => "error : doc_size is missing"
                    );
                }
            }else {
                $data[] = array ( 
                    "status" => "NOT OK",
                    "message" => "error : doc_name is missing"
                );
            }
        }else {
            $data[] = array ( 
                "status" => $file_json[0]->file,
                "message" => "error : doc_fichero_json is missing"
            );
        }        
    }else {
        $data[] = array ( 
            "status" => "NOT OK",
            "message" => "error : doc_fichero is missing"
        );
    }
    header("Content-type: application/json; charset=utf-8");
    echo json_encode($data);
}elseif ($auth == 0) {
    $data = array();
    $data[] = array ( 
        "code" => "unauthorized_client",
        "message" => "Invalid authorization token"
    );
    header("Content-type: application/json; charset=utf-8");
    echo json_encode($data);
}
?>