<?php
session_start();

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

$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 = "";
$outgoingUrl = "";
$requestTimeOut = 30;
$itemId = 0;
$buttonLabel = "Ajouter";

$res = $dba->getSCCTicketDetailById($itemId);

$guceModuleres = $dba->getGUCEModules(0);
$callreasonres = $dba->getSCCCallReasonDetails(0);
$customerTypeRes = $dba->getSCCCustomerType(0);
$cmpList = $dba->getSCCCCompanyList(0);

$customerDtls = $dba->getSCCCustomerDetailsByNumber($res['from_callerid_v']);

$calldata = $dba->getSCCLastCallByMsisdn($res['from_callerid_v']);

$tHistory = $dba->getSCCTicketHistory($res['caller_ticket_id']);

$priority = $dba->getSCCPriorities(0);

$refreshEnable = 1;

$kresult = $dba->getSCCKnownledgeBase(0);
/*
  if(count($customerDtls) == 1 ){
  // Customer found renaming data;
  $firstName = $customerDtls[0]['first_name_v'];
  $lastName = $customerDtls[0]['last_name_v'];
  $company = $customerDtls[0]['location_v']."[".$customerDtls[0]['company_id_n']."]";
  $email = $customerDtls[0]['email_id_v'];
  $profession = $customerDtls[0]['email_id_v'];

  }



  $firstName = $res['first_name_v'];
  $lastName = $res['last_name_v'];
  $company = $res['location_v'];
  $email = $res['email_id_v'];
  $profession = $res['email_id_v'];
 * 
 */
if (count($customerDtls) == 1) {
    // Customer found renaming data;
    $firstName = $customerDtls[0]['first_name_v'];
    $lastName = $customerDtls[0]['last_name_v'];
    $company = $customerDtls[0]['location_v'] . "[" . $customerDtls[0]['company_id_n'] . "]";
    $email = $customerDtls[0]['email_id_v'];
    $profession = $customerDtls[0]['email_id_v'];
}

$firstName = $res['first_name_v'];
$lastName = $res['last_name_v'];
$company = $res['location_v'];
$email = $res['email_id_v'];
$profession = $res['email_id_v'];
?>


<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>Créer un ticket</h4>
                        </a>
                    </div>
                </div>
                <div class="panel-body">

                    <table id="stdTicketForm" width="100%" >

                        <tr>
                            <td width="40%">

                                <form action="<?php echo $currentBaseDir; ?>/exec_add_std_ticket.php" method="post" enctype="multipart/form-data"  id="campaignFrm"  toDiv="<?php echo $toDiv; ?>" returnPage="<?php echo $rPage; ?>" onsubmit="return false;">
                                    <div class="form-row">
                                        <div class="form-group col-md-4">
                                            <label ></label>
                                            <h4 class="svam-ticket-nb" > <input type="hidden" name="csrId" id="csrId" value="<?php echo $res['caller_ticket_id']; ?>" /><input type="hidden" name="operationId" id="operationId" value="1" /></h4>
                                        </div>
                                        <div class="form-group col-md-4">
                                            <label ></label>
                                            <h4 style="color:green; font-weight: bold; font-size: 20px" ></h4>
                                        </div>
                                        <div class="form-group col-md-4">
                                            <label >N° Appelant :</label>
                                            <h3><input type="text" class="form-control" id="callerId" name="callerId" value="<?php echo $res['from_callerid_v']; ?>">  <input type="hidden" name="callId" id="callId" value="<?php echo $_REQUEST['item']; ?>" /></h3>
                                        </div>
                                    </div>

                                    <div class="form-row">
                                        <div class="form-group col-md-6">
                                            <label for="firstName">Nom</label>
                                            <input type="text" class="form-control" id="firstName" name="firstName" value="<?php echo $firstName; ?>">
                                        </div>
                                        <div class="form-group col-md-6">
                                            <label for="lastName">Pr&eacute;noms</label>
                                            <input type="text" class="form-control" id="lastName" name="lastName" value="<?php echo $lastName; ?>">
                                        </div>
                                    </div>
                                    <div class="form-row">   
                                        <div class="form-group col-md-4">
                                            <label for="company">Société</label> 
                                            <input type="text" class="form-control" id="company" name="company" value="<?php echo $company; ?>">
                                            <!--
                                             <select id="company" name="company" class="form-control">
                                              <option value="-1" selected>- Veuillez selectionner une option -</option>
<?php for ($i = 0; $i < count($cmpList); $i++) { ?>
                                                                      <option value="<?php echo $cmpList[$i]['company_id_n']; ?>" <?php if ($res['company_name_v'] == $cmpList[$i]['company_id_n']) { ?> selected="selected" <?php } ?> ><?php echo $cmpList[$i]['company_name_v']; ?></option>
<?php } ?>
                                            </select>
                                            -->
                                        </div>
                                        <div class="form-group col-md-4">
                                            <label for="mobileNumber">Contact</label>
                                            <input type="tel" class="form-control" id="mobileNumber" name="mobileNumber"  value="<?php echo $res['contact_v']; ?>">
                                        </div>

                                        <div class="form-group col-md-4">
                                            <label for="emailId">Email</label>
                                            <input type="email" class="form-control" id="emailId" name="emailId"  value="<?php echo $res['email_id_v']; ?>">  <input type="hidden"  id="actionType" name="actionType"  value="2">
                                        </div>
                                    </div>

                                    <div class="form-row">



                                    </div>

                                    <div class="form-row">

                                        <div class="form-group col-md-12">
                                            <label for="customerType">Statut Usager</label>
                                            <select id="customerType" name="customerType" class="form-control">
                                                <option value="-1" selected>- Veuillez selectionner une option -</option>
<?php for ($i = 0; $i < count($customerTypeRes); $i++) { ?>
                                                    <option value="<?php echo $customerTypeRes[$i]['type_id_n']; ?>" <?php if ($res['char_field_6'] == $customerTypeRes[$i]['type_id_n']) { ?> selected="selected" <?php } ?> ><?php echo $customerTypeRes[$i]['type_v']; ?></option>
<?php } ?>
                                            </select>
                                        </div>

                                    </div>

                                    <div class="form-row">

                                        <div class="form-group col-md-12">
                                            <label for="callModule">Liste des modules</label>
                                            <select id="callModule" name="callModule" class="form-control" >
                                                <option value="-1" selected>- Veuillez selectionner une option -</option>
<?php for ($i = 0; $i < count($guceModuleres); $i++) { ?>
                                                    <option value="<?php echo $guceModuleres[$i]['motif_id_n']; ?>" <?php if ($res['reason_category_n'] == $guceModuleres[$i]['motif_id_n']) { ?> selected="selected" <?php } ?> ><?php echo $guceModuleres[$i]['motif_name_v']; ?></option>
<?php } ?>
                                            </select>
                                        </div>

                                    </div>

                                    <div class="form-row">

                                        <div class="form-group col-md-12">
                                            <label for="submodule">Sous modules</label>
                                            <select id="submodule" name="submodule" class="form-control">
                                                <option value="-1" > -- Aucun --</option>
<?php
if ($res['char_field_3'] != "" && $res['char_field_3'] != "-1") {

    $smRes = $dba->getSubMobuleById($res['char_field_3']);
    ?>
                                                    <option value="<?php echo $smRes[0]['motif_id_n']; ?>" selected="selected" > <?php echo $smRes[0]['motif_name_v']; ?></option>

                                                <?php } ?>

                                            </select>
                                        </div>

                                    </div>



                                    <div class="form-row">

                                        <div class="form-group col-md-12">
                                            <label for="callReasonType">Motif d'appel</label>
                                            <select id="callReasonType" name="callReasonType" class="form-control" >
                                                <option value="-1" selected>- Veuillez selectionner une option -</option>
<?php for ($i = 0; $i < count($callreasonres); $i++) { ?>
                                                    <option value="<?php echo $callreasonres[$i]['motif_id_n']; ?>" <?php if ($res['reason_n'] == $callreasonres[$i]['motif_id_n']) { ?> selected="selected" <?php } ?> ><?php echo $callreasonres[$i]['motif_name_v']; ?></option>
<?php } ?>
                                            </select>
                                        </div>

                                    </div>

                                    <div class="form-row">

                                        <div class="form-group col-md-12">
                                            <label for="callprority">Priorité</label>
                                            <select id="callprority" name="callprority" class="form-control">
                                                <option value="-1" selected>- Veuillez selectionner une option -</option>
<?php for ($i = 0; $i < count($priority); $i++) { ?>
                                                    <option value="<?php echo $priority[$i]['priority_id_n']; ?>" <?php if ($res['char_field_4'] == $priority[$i]['priority_id_n']) { ?> selected="selected" <?php } ?> ><?php echo $priority[$i]['short_desc_v']; ?></option>
<?php } ?>
                                            </select>
                                        </div>

                                    </div>


                                    <div class="form-row">

                                        <div class="form-group col-md-12">
                                            <label for="callType">Canal d'échange</label>
                                            <select id="callType" name="callType" class="form-control">
                                                <option value="Appel" <?php if ($res['char_field_5'] == "Appel") { ?> selected="selected" <?php } ?>  >Appel</option>
                                                <option value="SMS" <?php if ($res['char_field_5'] == "SMS") { ?> selected="selected" <?php } ?>  >SMS</option>
                                                <option value="Mail" <?php if ($res['char_field_5'] == "Mail") { ?> selected="selected" <?php } ?>  >Mail</option>
                                                <option value="IM" <?php if ($res['char_field_5'] == "IM") { ?> selected="selected" <?php } ?>  >Instant Messaging</option>

                                            </select>
                                        </div>

                                    </div>

                                    <div class="form-row">

                                        <div class="form-group col-md-12">
                                            <label for="csrDetails">Description de la requête client</label>
                                            <textarea id="csrDetails" name="csrDetails" class="form-control" cols="5" rows="3"><?php echo $res['ticket_reason_desc_v']; ?></textarea>
                                        </div>

                                    </div>
                                    <div class="form-row">

                                        <div class="form-group  col-md-12">
<?php
$dbres = $dba->getTicketCommentsByTicketId($res['caller_ticket_id']);
?>
                                            <label for="csrComment">Commentaire du conseiller client</label>
                                            <textarea id="csrComment" name="csrComment" class="form-control" cols="5" rows="3"></textarea>
                                        </div>

                                    </div>

                                       <div class="form-group  col-md-12">

                    

                    <button type="submit" class="btn btn-primary" id="save" >Créer</button>  
                     
                   
                        
                    
                    <button type="button" class="btn close-btn" data-dismiss="modal">Fermer</button>
                    
                    


                </div>




                                </form>



                            </td>






                            
                        </tr>


                    </table>


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


</section>





<script type="text/javascript" src="js/jquery.loading.min.js"></script>
<div id="loader" ></div>

<script>
                                    $(function () {
                                        $("#<?php echo $accordion; ?>").accordion();
                                    });
</script>

<script type="text/javascript">

    var $modal = $('#myModal');
    var $myLargeModal = $('#myLargeModal');




    $('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 );

                $.alert({
                    icon: 'glyphicon glyphicon-ok',
                    title: 'RESULTAT',
                    content: obj.errorMessage,
                    type: 'green',
                    typeAnimated: true
                    ,
                    buttons: {
                        "Ok": function () {
                            $("#content-wrapper").load("<?php echo $currentBaseDir; ?>/edit_std_incoming_ticket.php?rPage=<?php echo $rPage; ?>&item="+obj.item);
                                                    }
                                                }

                });
                //  alert(data);
                //  $("#" + toDiv).load(rpage);
                // $('#loader').hide();

            } 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(); */
    });


    $(".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');

    });



</script>

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


<script type="text/javascript" src="js/jquery.loading.min.js"></script>



<script type="text/javascript">






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

        });
        var dataURL = $(this).attr('data-href');
        var modalTitle = $(this).attr('title');
        $('.modal-title').html(modalTitle);
        $('#loader').loading('stop');
        $('.modal-body').load(dataURL, function () {
            $modal.modal({
                backdrop: 'static',
                keyboard: false
            });
        });


    });




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

        });
        var dataURL = $(this).attr('data-href');
        var modalTitle = $(this).attr('title');
        $('.modal-title').html(modalTitle);
        $('#loader').loading('stop');
        $('.modal-body').load(dataURL, function () {
            $modal.modal({
                backdrop: 'static',
                keyboard: false
            });
        });


    });



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

        });
        var dataURL = $(this).attr('data-href');
        var modalTitle = $(this).attr('title');
        $('.modal-title').html(modalTitle);
        $('#loader').loading('stop');
        $('.modal-body').load(dataURL, function () {
            $modal.modal({
                backdrop: 'static',
                keyboard: false
            });
        });


    });









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

        $("#submodule").load("<?php echo $currentBaseDir; ?>/get_module_menu_dtls.php?id=" + $(this).val());

    });


</script>

<script type="text/javascript">
                $(function () {

                    //autocomplete
                    $("#company").autocomplete({
                        source: "<?php echo $currentBaseDir; ?>/companysearch.php"
                    });
                });</script>
<script type="text/javascript" src="js/jquery.loading.min.js"></script>
<link rel="stylesheet" href="css/jquery-confirm.min.css">
<script src="js/jquery-confirm.min.js