<?php
// +-------------------------------------------------+
// © 2002-2004 PMB Services / www.sigb.net pmb@sigb.net et contributeurs (voir www.sigb.net)
// +-------------------------------------------------+
// $Id: integrity.php,v 1.1.2.3 2026/01/27 13:41:18 rtigero Exp $


$base_path = ".";
$base_noheader = 1;
$base_nocheck = 1;
$base_nobody = 1;
$base_nosession = 1;

require_once($base_path . '/includes/init.inc.php');

use Pmb\Digitalsignature\Library\ApiSignature;
use Pmb\Digitalsignature\Models\CertificateModel;

global $action, $signature_id;
$cert_id = intval($cert_id);

$certificateModel = new CertificateModel($cert_id);
$certificate = $certificateModel->getSettings();

if (empty($certificate->url) || empty($certificate->token)) {
    return;
}

switch ($action) {
    case "check":
        /*global $hashFile;

        $file = file_get_contents($hashFile["tmp_name"]);
        $signAPI = new ApiSignature($certificate->url, $certificate->token);

        print json_encode($signAPI->check_integrity($hashFile["name"], $file));*/
        break;
    case "get_hash":
        global $type;

        if (! in_array($type, ["back", "opac"])) {
            break;
        }

        $signAPI = new ApiSignature($certificate->url, $certificate->token);
        header("Content-Type: application/json; charset=utf-8");
        print $signAPI->get_hash($type);
        break;

    default:
        break;
}
