<html>
  <header>
    <title>TEST PACS </title>
  </header>
<body>

  <h1>TEST PACS Gmed<br/></h1>
<?php

/**
 * si vanno a vedere gli studi che sono stati mandati a OrtHanc (status 202)
 * e si controlla che che i JOB siano andati a buon fine
 * questo applicativo gira con un crontab
 *
 * @copyright Gmed Srl
 * @author Sciarrone Riccardo <riccardos@gmed.it>
 */

set_time_limit(3600);
ini_set('max_execution_time', 3600); //3600 secondi = 60 minuti

include_once './conf/config.inc.php';
include_once './include/basic_function.php';
include_once './include/elsol_function.php';
include_once './include/kxa_function.php';

include_once './include/elsol_function.php';
include_once './include/dcm_function.php';

include_once './vendor/autoload.php';


//error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
error_reporting(E_ALL);


if( !isset($_GET['debug']) || IsNull($_GET['debug']) || $_GET['debug'] != 'gMeD' ){
    die("AH AH AH");
}

$GLOBALS['dbg'] = true;

//echo "POST:<br/><pre>" . print_r( $_POST, true ) . "</pre><br/>";

$curl = "";
if( isset($_POST["PACS_call"]) && $_POST["PACS_call"] != "" ){
    // c'è da fare la chiamata
    $url = orthanc_url . $_POST["PACS_url"];
    $post_fields = $_POST["PACS_post_fields"];

    // call_orthanc($url, $type = "GENERIC", $single_value = FALSE, $custom_request = 'GET', $post_fields = "{}", $check_error_in_resp = TRUE, $response_to_log = TRUE, $curl_debug = FALSE)
    $curl = call_orthanc($url, "TEST", $_POST["PACS_single_value"], $_POST["PACS_call"], $post_fields, $_POST["PACS_check_error_in_resp"], false, true);
}

?>

  <form id="PACS_form" name="PACS_form" method="post" action="?debug=gMeD">

    Tipo di chiamata:
    <select name="PACS_call">
      <option value="GET" <?php echo $_POST["PACS_call"] == "GET" ? "selected='selected'" : ""; ?> >GET</option>
      <option value="POST" <?php echo $_POST["PACS_call"] == "POST" ? "selected='selected'" : ""; ?> >POST</option>
    </select>
    <br/>

    URL:
    <input type="text" name="PACS_url" style="width: 60%;" value="<?php echo $_POST["PACS_url"]; ?>"/>
    <br/>

    Post fields:
    <textarea name="PACS_post_fields" rows="20" cols="100"><?php echo $_POST["PACS_post_fields"]; ?></textarea>
    <br/>

    Single Value:
    <select name="PACS_single_value">
      <option value="TRUE" <?php echo $_POST["PACS_single_value"] == "TRUE" ? "selected='selected'" : ""; ?> >YES</option>
      <option value="FALSE" <?php echo $_POST["PACS_single_value"] == "FALSE" ? "selected='selected'" : ""; ?> >NO</option>
    </select>
    <br/>

    Check Error:
    <select name="PACS_check_error_in_resp">
      <option value="TRUE" <?php echo $_POST["PACS_check_error_in_resp"] == "TRUE" ? "selected='selected'" : ""; ?> >YES</option>
      <option value="FALSE" <?php echo $_POST["PACS_check_error_in_resp"] == "FALSE" ? "selected='selected'" : ""; ?> >NO</option>
    </select>
    <br/>

    <input type="submit" value="Submit">
  </form>

  <br/>

  <hr/>

  <div style="color: white; background-color: black;">
    <br/>
    <pre><?php var_dump($curl);  ?></pre>
    </br>
  </div>

  <hr/>

</body>
</html>
