<?php
session_start();

$pageSequence = $_SESSION['sequence'];
$toDiv = "contentZone" . $pageSequence;
$resultZoneDiv = "resultZone" . $pageSequence;
$tableZone = "#tableZone" . $pageSequence;
$_SESSION['sequence']++;

$currentBaseDir = dirname($_SERVER['PHP_SELF']);
include($_SESSION['basedir'] . "veriflog.php");
include($_SESSION['basedir'] . "core.php");

$itemId = 0;
$svaTool = new svaTool();
$rPage = $_REQUEST['rPage'];
$rDiv = $_REQUEST['rDiv'];
if (isset($_REQUEST['opId'])) {
    $opId = $_REQUEST['opId'];
}

if (isset($_REQUEST['itemId'])) {
    $itemId = $_REQUEST['itemId'];
}



$ivrName = "";
$description = "";
$ivrData = "";
$buttonLabel = "Ajouter";

if ($opId > 0) {
    $itemId = $_REQUEST['item'];
    $res = $dba->getSCCIVRList($itemId);

    $ivrName = $res[0]['ivr_name_v'];
    $description = $res[0]['ivr_desc_v'];
    $ivrData = $res[0]['ivr_data_v'];
    $buttonLabel = "Modifier";
}
?>


<style type="text/css">

    /* Style the form */
    #regForm {
        background-color: #ffffff;
        margin: 5px auto;
        padding: 40px;
        width: 80%;
        min-width: 300px;
    }

    /* Style the input fields */
    input {
        padding: 10px;
        width: 50%;
        font-size: 17px;
        font-family: Raleway;
        border: 1px solid #aaaaaa;
    }

    textarea {
        padding: 10px;
        width: 50%;
        font-size: 17px;
        font-family: Raleway;
        border: 1px solid #aaaaaa;
    }

    /* Mark input boxes that gets an error on validation: */
    input.invalid {
        background-color: #ffdddd;
    }

    /* Hide all steps by default: */
    .tab {
        display: none;
    }

    /* Make circles that indicate the steps of the form: */
    .step {
        height: 15px;
        width: 15px;
        margin: 0 2px;
        background-color: #bbbbbb;
        border: none;
        border-radius: 50%;
        display: inline-block;
        opacity: 0.5;
    }

    /* Mark the active step: */
    .step.active {
        opacity: 1;
    }

    /* Mark the steps that are finished and valid: */
    .step.finish {
        background-color: #04AA6D;
    }

    .moduleId323 {
        background-color:#E9F2FE
    }


</style>
<section class="content" >
    <div class="row">
        <div class="col-sm-12">
            <div class="panel panel-bd lobidrag">
                <div class="panel-heading">
                    <div class="btn-group" id="buttonexport">
                        <a href="#">
                            <h4>Ajouter/Modifier un SVI</h4>
                        </a>
                    </div>
                </div>
                <div class="panel-body">

                    <form id="regForm" action="<?php echo $currentBaseDir; ?>/exec_add_edit_ivr.php"  method="post" onsubmit="return false;">
                        <div class="col-sm-6" >
                            <div class="form-group">
                                <label>Identifiant</label>
                                <input type="text" class="form-control" id="ivrName" required name="ivrName" value="<?php echo $ivrName; ?>">
                                <input type="hidden" name="opId"  id="opId" value="<?php echo $opId; ?>">
                                <input type="hidden" name="itemId"  id="itemId" value="<?php echo $itemId; ?>">






                            </div>

                            <div class="form-group">
                                <label>Description</label>
                                <textarea id="description" name="description" class="form-control" ><?php echo $description; ?></textarea>
                            </div>

                            <div class="form-group">
                                <label>Détails</label>
                                <textarea id="description" name="ivrData" class="form-control" cols="4" rows="5" ><?php echo $ivrData; ?></textarea>
                            </div>





                            <div class="reset-button">
                                <button   type="submit" class="btn addition"><?php echo $buttonLabel; ?></button>  <button type="button" class="btn close-btn" >Fermer</button>
                            </div>

                        </div>
                        <div class="col-sm-6" >

                        </div>


                    </form>


                </div>
            </div>
        </div>
    </div>


</section>





<script type="text/javascript">

    $(".close-btn").on('click', function () {
        // create the backdrop and wait for next modal to be triggered
        // $('body').modalmanager('loading');
        $('#loader').loading({
            message: "Chargement...",
            theme: 'dark'

        });

        $("#content-wrapper").load("<?php echo $rPage; ?>");
        $('#loader').loading('stop');

    });


    $(document).ready(function () {


        $("#dstType").change(function () {

            $("#dstEntity").load("<?php echo $currentBaseDir; ?>/get_entity_list.php?chId=<?php echo $channelType; ?>&id=" + $(this).val());

        });



        $('form').on("submit", function (event) {

            var toDiv = $("form").attr('toDiv');
            var rpage = $("form").attr('returnPage');

            $.post($(this).attr("action"), $(this).serialize(), function (data) {

                var obj = jQuery.parseJSON(data);

                if (obj.errorCode == 0) {

                    //alert( obj.errorMessage );

                    //    $.alert( obj.errorMessage );

                    $.confirm({
                        icon: 'glyphicon glyphicon-ok',
                        title: 'RESULTAT',
                        content: obj.errorMessage,
                        type: 'green',
                        typeAnimated: true,
                        buttons: {
                            confirm: {
                                text: 'OK',
                                action: function () {
                                    $("#content-wrapper").load("<?php echo $rPage; ?>");
                                }

                            }


                        }

                    });
                    //  alert(data);


                } else {


                    $.alert({
                        icon: 'glyphicon glyphicon-warning-sign',
                        title: 'RESULTAT',
                        content: obj.errorMessage,
                        type: 'red',
                        typeAnimated: true
                    });

                    // $.alert( obj.errorMessage );
                }

            });
            // return false; // prevent normal submit


            event.preventDefault();

            /*
             var postData = $(this).serializeArray();
             var formURL = $(this).attr("action");
             
             $.ajax({
             url: formURL,
             type: "POST",
             data: postData,
             success: function(data, textStatus, jqXHR) {
             
             alert("Processing the form...");
             
             },
             error: function(jqXHR, status, error) {
             console.log(status + ": " + error);
             }
             });
             event.preventDefault(); */
        });



    });



</script>

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