<?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");

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


$channelName = "";
$description = "";
$systemId = "";
$password = "";
$host = "";
$port = "0";
$systemType = 1;
$serviceType = 1;
$charset = 1;
$mode = 1;
$srcTon = 2;
$dstTon = 2;
$srcNpi = 2;
$dstNpi = 2;
$sendThrPut = 10;
$enquireLinkDelay = 30;
$reconnectDelay = 10;
$msgIdType = 1;

$itemId = 0;
$buttonLabel = "Ajouter";

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

    $channelName = $res[0]['channel_name_v'];
    $description = $res[0]['desc_v'];
    $systemId = $res[0]['system_id_v'];
    $password = $res[0]['system_password_v'];
    $host = $res[0]['host_name_v'];
    $port = $res[0]['send_port_n'];
    $systemType = $res[0]['system_type_v'];
    $serviceType = $res[0]['service_type_v'];
    $charset = $res[0]['alt_charset_n'];
    $mode = $res[0]['bind_type_n'];
    $srcTon = $res[0]['src_ton_n'];
    $dstTon = $res[0]['dst_ton_n'];
    $srcNpi = $res[0]['src_npi_n'];
    $dstNpi = $res[0]['dst_npi_n'];
    $sendThrPut = $res[0]['dlvrd_thrput_n'];
    $enquireLinkDelay = $res[0]['enquire_link_int_n'];
    $reconnectDelay = $res[0]['reconnect_delay_n'];
    $msgIdType = $res[0]['msgid_type_n'];



    $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 compte SMPP 3.4</h4>
                        </a>
                    </div>
                </div>
                <div class="panel-body">

                    <form action="<?php echo $currentBaseDir; ?>/exec_add_edit_smpp_account.php"  method="post" onsubmit="return false;">
                        <div class="col-sm-6" >
                            <div class="form-group">
                                <label>Identifiant du service</label>
                                <input type="text" class="form-control" id="channelName" required name="channelName" value="<?php echo $channelName; ?>">
                                <input type="hidden" name="channelId"  id="channelId" value="<?php echo $_REQUEST['chId']; ?>">
                                <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>Identifiant système </label>
                                <input type="text" class="form-control" id="systemId" name="systemId" required value="<?php echo $systemId; ?>">
                            </div>
                            <div class="form-group">
                                <label>Password Système</label>
                                <input type="password" class="form-control" id="password" name="password" required value="<?php echo $password; ?>">
                            </div>

                            <div class="form-group">
                                <label>Serveur </label>
                                <input type="text" class="form-control" id="host" name="host" required value="<?php echo $host; ?>">
                            </div>
                            <div class="form-group">
                                <label>Port </label>
                                <input type="text" class="form-control" id="port" name="port" required value="<?php echo $port; ?>">
                            </div>





                            <div class="form-group">
                                <label>Type de système</label>
                                <select name="systemType" id="systemType" class="form-control">
                                    <option value="1" <?php if ($systemType == 1) { ?>  selected="selected" <?php } ?>>VMA</option>
                                    <option value="2" <?php if ($systemType == 2) { ?>  selected="selected" <?php } ?>>VMS</option>
                                    <option value="3" <?php if ($systemType == 3) { ?>  selected="selected" <?php } ?>>OTA</option>

                                </select>
                            </div>

                            <div class="form-group">
                                <label>Type de service</label>
                                <select name="serviceType" id="serviceType" class="form-control">
                                    <option value="1" <?php if ($serviceType == 1) { ?>  selected="selected" <?php } ?>>VMA</option>
                                    <option value="2" <?php if ($serviceType == 2) { ?>  selected="selected" <?php } ?>>VMS</option>
                                    <option value="3" <?php if ($serviceType == 3) { ?>  selected="selected" <?php } ?>>OTA</option>
                                    <option value="4" <?php if ($serviceType == 4) { ?>  selected="selected" <?php } ?>>VMN</option>
                                    <option value="5" <?php if ($serviceType == 5) { ?>  selected="selected" <?php } ?>>CMT</option>
                                    <option value="6" <?php if ($serviceType == 6) { ?>  selected="selected" <?php } ?>>CPT</option>
                                    <option value="7" <?php if ($serviceType == 7) { ?>  selected="selected" <?php } ?>>CBS</option>
                                    <option value="8" <?php if ($serviceType == 8) { ?>  selected="selected" <?php } ?>>GUTS</option>
                                </select>
                            </div>

                            <div class="form-group">
                                <label>Jeu de caractère</label>
                                <select name="charset" id="charset" class="form-control">
                                    <option value="1" <?php if ($charset == 1) { ?>  selected="selected" <?php } ?>>GSM 7bits</option>
                                    <option value="2" <?php if ($charset == 2) { ?>  selected="selected" <?php } ?>>GSM 8bits</option>
                                    <option value="3" <?php if ($charset == 3) { ?>  selected="selected" <?php } ?>>ISO-8859-1</option>
                                    <option value="4" <?php if ($charset == 4) { ?>  selected="selected" <?php } ?>>UCS 2</option>
                                    <option value="5" <?php if ($charset == 5) { ?>  selected="selected" <?php } ?>>UTF-8</option>

                                </select>
                            </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 class="form-group">
                                <label>Mode de connexion</label>
                                <select name="mode" id="mode" class="form-control">
                                    <option value="1" <?php if ($mode == 1) { ?>  selected="selected" <?php } ?>>Bidirectionnel</option>
                                    <option value="2" <?php if ($mode == 2) { ?>  selected="selected" <?php } ?>>Transmetteur</option>
                                    <option value="3" <?php if ($mode == 3) { ?>  selected="selected" <?php } ?>>Récepteur</option>

                                </select>
                            </div>


                            <div class="form-group">
                                <label>Source TON</label>
                                <select name="srcTon" id="srcTon" class="form-control"> 
                                    <option value="0" <?php if ($srcTon == 0) { ?>  selected="selected" <?php } ?> >0</option>
                                    <option value="1" <?php if ($srcTon == 1) { ?>  selected="selected" <?php } ?>>1</option>
                                    <option value="2" <?php if ($srcTon == 2) { ?>  selected="selected" <?php } ?> >2</option>
                                    <option value="3" <?php if ($srcTon == 3) { ?>  selected="selected" <?php } ?>>3</option>
                                    <option value="4" <?php if ($srcTon == 4) { ?>  selected="selected" <?php } ?>>4</option>
                                    <option value="5" <?php if ($srcTon == 5) { ?>  selected="selected" <?php } ?>>5</option>
                                    <option value="6" <?php if ($srcTon == 6) { ?>  selected="selected" <?php } ?>>6</option>
                                </select> 
                            </div>

                            <div class="form-group">
                                <label>Source NPI</label>
                                <select name="srcNpi" id="srcNpi" class="form-control"> 
                                    <option value="0" <?php if ($srcNpi == 0) { ?>  selected="selected" <?php } ?>>0</option>
                                    <option value="1" <?php if ($srcNpi == 1) { ?>  selected="selected" <?php } ?>  >1</option>
                                    <option value="3" <?php if ($srcNpi == 3) { ?>  selected="selected" <?php } ?>>3</option>
                                    <option value="4" <?php if ($srcNpi == 4) { ?>  selected="selected" <?php } ?>>4</option>
                                    <option value="6" <?php if ($srcNpi == 6) { ?>  selected="selected" <?php } ?>>6</option>
                                    <option value="8" <?php if ($srcNpi == 8) { ?>  selected="selected" <?php } ?>>8</option>
                                    <option value="9" <?php if ($srcNpi == 9) { ?>  selected="selected" <?php } ?>>9</option>
                                    <option value="10" <?php if ($srcNpi == 10) { ?>  selected="selected" <?php } ?>>10</option>
                                    <option value="13" <?php if ($srcNpi == 13) { ?>  selected="selected" <?php } ?>>13</option>
                                    <option value="18" <?php if ($srcNpi == 18) { ?>  selected="selected" <?php } ?>>18</option>
                                </select> 
                            </div>

                            <div class="form-group">
                                <label>Destination TON</label>
                                <select name="dstTon" id="dstTon" class="form-control"> 
                                    <option value="0" <?php if ($dstTon == 0) { ?>  selected="selected" <?php } ?> >0</option>
                                    <option value="1" <?php if ($dstTon == 1) { ?>  selected="selected" <?php } ?>>1</option>
                                    <option value="2" <?php if ($dstTon == 2) { ?>  selected="selected" <?php } ?> >2</option>
                                    <option value="3" <?php if ($dstTon == 3) { ?>  selected="selected" <?php } ?>>3</option>
                                    <option value="4" <?php if ($dstTon == 4) { ?>  selected="selected" <?php } ?>>4</option>
                                    <option value="5" <?php if ($dstTon == 5) { ?>  selected="selected" <?php } ?>>5</option>
                                    <option value="6" <?php if ($dstTon == 6) { ?>  selected="selected" <?php } ?>>6</option>
                                </select>
                            </div>

                            <div class="form-group">
                                <label>Destination NPI</label>
                                <select name="dstNpi" id="dstNpi" class="form-control"> 
                                    <option value="0" <?php if ($dstNpi == 0) { ?>  selected="selected" <?php } ?>>0</option>
                                    <option value="1" <?php if ($dstNpi == 1) { ?>  selected="selected" <?php } ?>  >1</option>
                                    <option value="3" <?php if ($dstNpi == 3) { ?>  selected="selected" <?php } ?>>3</option>
                                    <option value="4" <?php if ($dstNpi == 4) { ?>  selected="selected" <?php } ?>>4</option>
                                    <option value="6" <?php if ($dstNpi == 6) { ?>  selected="selected" <?php } ?>>6</option>
                                    <option value="8" <?php if ($dstNpi == 8) { ?>  selected="selected" <?php } ?>>8</option>
                                    <option value="9" <?php if ($dstNpi == 9) { ?>  selected="selected" <?php } ?>>9</option>
                                    <option value="10" <?php if ($dstNpi == 10) { ?>  selected="selected" <?php } ?>>10</option>
                                    <option value="13" <?php if ($dstNpi == 13) { ?>  selected="selected" <?php } ?>>13</option>
                                    <option value="18" <?php if ($dstNpi == 18) { ?>  selected="selected" <?php } ?>>18</option>
                                </select>
                            </div>


                            <div class="form-group">
                                <label>Débit </label>
                                <input type="text" class="form-control" id="sendThrPut" name="sendThrPut" required value="<?php echo $sendThrPut; ?>">
                            </div>
                            <div class="form-group">
                                <label>Délai EnquireLink (Sec) </label>
                                <input type="text" class="form-control" id="enquireLinkDelay" name="enquireLinkDelay" required value="<?php echo $enquireLinkDelay; ?>">
                            </div>

                            <div class="form-group">
                                <label>Délai de reconnexion (Sec) </label>
                                <input type="text" class="form-control" id="reconnectDelay" name="reconnectDelay" required value="<?php echo $reconnectDelay; ?>">
                            </div>


                            <div class="form-group">
                                <label>Type d'identifiant de message</label>
                                <select name="msgIdType" id="msgIdType" class="form-control">
                                    <option value="0" <?php if ($msgIdType == 0) { ?>  selected="selected" <?php } ?>>Décimal, Décimal</option>
                                    <option value="1" <?php if ($msgIdType == 1) { ?>  selected="selected" <?php } ?>>Décimal, Hexadécimal</option>
                                    <option value="2" <?php if ($msgIdType == 2) { ?>  selected="selected" <?php } ?>>Hexadécimal, Décimal</option>
                                    <option value="3" <?php if ($msgIdType == 3) { ?>  selected="selected" <?php } ?>>Hexadécimal, Hexadécimal</option>

                                </select>
                            </div>






                        </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 () {


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

            $("#userId").load("<?php echo $currentBaseDir; ?>/get_available_agents.php?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>