<?php
session_start();
$pageSequence = $_SESSION['sequence'];
$toDiv = "contentZone" . $pageSequence;
$resultZoneDiv = "resultZone" . $pageSequence;
$_SESSION['sequence']++;
//echo  dirname(__FILE__);  
//echo $_SERVER['DOCUMENT_ROOT'] . "   ".dirname(__FILE__)."  ".str_replace($_SERVER['DOCUMENT_ROOT'],"",dirname(__FILE__)) . " SELF :" .$_SERVER['PHP_SELF']  ;
$toDiv = $_REQUEST['toDiv'];
$rpage = $_REQUEST['rpage'];
$cancelPage = $_REQUEST['cancelPage']; 
$currentBaseDir = dirname($_SERVER['PHP_SELF']);
include($_SESSION['basedir'] . "core.php");

//$res = $dba->getSCCTicketDetailById($_REQUEST['item']) ;
$ticketId = $_REQUEST['ticketId'];
$item = $_REQUEST['item'];
$rPage = $_REQUEST['rPage'];
$rDiv = $_REQUEST['rDiv'];
$res = $dba->getAssigneeProfileById($_SESSION['right'])
?>

<style>
    /*  LOADER_SKF CSS  */
    .loader_skf {
    visibility:hidden;
    width: 33px;
    height: 33px;
    border: 5px solid black;
    border-bottom-color: transparent;
    border-radius: 50%;
    display: inline-block;
    box-sizing: border-box;
    animation: rotation 1s linear infinite;
    margin-left: 400px;
    margin-top:15px;
    }

    @keyframes rotation {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
    } 
    

</style>

<form action="<?php echo $currentBaseDir; ?>/exec_close_ticket_reclamation.php" method="post" enctype="multipart/form-data" id="campaignFrm" toDiv="<?php echo $toDiv; ?>" returnPage="<?php echo $_SERVER['PHP_SELF']; ?>" onsubmit="return false;">
    <div class="form-row">
        <div class="form-group col-md-12">
            <label for="assigneeProfile"><h3>Clôturer le ticket <strong><?php echo $ticketId; ?></strong></h3></label>
        </div>

        <div class="form-group col-md-12">
            <label for="comment"><h3>Commentaire <strong></h3></label>
            <textarea id="comment" name="comment" class="form-control" cols="5" rows="3"></textarea>
            <input type="hidden" name="ticketId" id="ticketId" value="<?php echo $ticketId; ?>" />
        </div>

        <div class="mb-3" style="margin-bottom:15px">
            <label for="fileInput" class="form-label">Joindre un fichier</label>
            <input type="file" class="form-control" id="fileInput" name="file">
        </div>

        <button type="submit" class="btn btn-primary" id="assign">Clôturer</button>
        <button type="button" class="btn close-btn" data-dismiss="modal">Fermer</button>
        <span class="loader_skf" id="loader_skf"></span>
    </div>
</form>

</form>


<script type="text/javascript">
    var classLOADER = document.getElementById('loader_skf');
    var $modal = $('#myModal');

    $('form').on("submit", function (event) {
    const form = this;
    const formData = new FormData(form);
    const toDiv = $(form).attr('toDiv');
    const rpage = $(form).attr('returnPage');

    fetch($(form).attr("action"), {
        method: "POST",
        body: formData
    })
        .then(response => response.json())
        .then(data => {
            if (data.errorCode === 0) {
                classLOADER.style.visibility = 'visible';
                setTimeout(() => {
                    classLOADER.style.visibility = 'hidden';
                }, 2000);

                $('#assign').hide();
                $.alert({
                    icon: 'glyphicon glyphicon-ok',
                    title: 'RESULTAT',
                    content: data.errorMessage,
                    type: 'green',
                    typeAnimated: true
                });
            } else {
                $.alert({
                    icon: 'glyphicon glyphicon-warning-sign',
                    title: 'RESULTAT',
                    content: data.errorMessage,
                    type: 'red',
                    typeAnimated: true
                });
            }
        })
        .catch(error => {
            console.error(error);
            $.alert({
                icon: 'glyphicon glyphicon-warning-sign',
                title: 'ERREUR',
                content: 'Une erreur est survenue lors de la soumission.',
                type: 'red',
                typeAnimated: true
            });
        });

    event.preventDefault();
});

</script>

<link rel="stylesheet" href="css/jquery-confirm.min.css">
<script src="js/jquery-confirm.min.js"></script>