<?php

if(session_status() != PHP_SESSION_ACTIVE)
{

if (isset($_SERVER['HTTPS']) &&
        ($_SERVER['HTTPS'] == 'on' || $_SERVER['HTTPS'] == 1) ||
        isset($_SERVER['HTTP_X_FORWARDED_PROTO']) &&
        $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') {
            session_set_cookie_params(["samesite" => "None", 'Secure' => true]);
           
    }
    
    session_name('__OxaProc-PHPSESSID');
    session_start();
}
if (isset($_SERVER['HTTPS']) &&
($_SERVER['HTTPS'] == 'on' || $_SERVER['HTTPS'] == 1) ||
isset($_SERVER['HTTP_X_FORWARDED_PROTO']) &&
$_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') {
    
     $http = 'https://';
}else
{
     $http = 'http://';
}


if(isset($_SERVER['HTTP_REFERER']) && substr($_SERVER['HTTP_REFERER'], - 10) ===  '/diags.php')
{
     if($_SESSION['_brokernumber'] == 1)
     {
          $broker ='';
     }
     else
     {
          $broker =$_SESSION['_brokernumber'];
     }
     
     $token = hash('sha256', jddayofweek(cal_to_jd(CAL_GREGORIAN, date("m"),date("d"), date("Y")) , 1 ).'&'.date("d"));

     $file_headers = @get_headers($http.$_SERVER['HTTP_HOST'].'/OXAMPROC'.$broker.'_WEB/FR/Diags.awp?token='.$token);

     if($file_headers[0] != 'HTTP/1.1 404 Not Found') 
     {
        $url = $http.$_SERVER['HTTP_HOST'].'/OXAMPROC'.$broker.'_WEB/FR/Diags.awp?token='.$token;

        echo "<iframe src='$url' style='height:100%;width:100%'></iframe>";
     
     }
     else
     {
         echo "il n'y a pas de diags pour : ".$http.$_SERVER['HTTP_HOST'].'/OXAMPROC'.$broker.'_WEB/FR/Diags.awp?token='.$token;
     }
}