<?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($_REQUEST['item']);

$callreasonres = $dba->getSCCCallReasonDetails(0);
$customerTypeRes = $dba->getSCCCustomerType(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;
/*
  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'];
?>
<!DOCTYPE html>
<html lang="en">

    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>.: SVAM - Interface d'administration :.</title>
        <!-- Favicon and touch icons -->
        <link rel="shortcut icon" href="images/logo.png" type="image/x-icon">
        <!-- Start Global Mandatory Style
           =====================================================================-->
        <!-- jquery-ui css -->
        <link href="assets/plugins/jquery-ui-1.12.1/jquery-ui.min.css" rel="stylesheet" type="text/css"/>
        <!-- Bootstrap -->
        <link href="assets/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
        <!-- Bootstrap rtl -->
        <!--<link href="assets/bootstrap-rtl/bootstrap-rtl.min.css" rel="stylesheet" type="text/css"/>-->
        <!-- Lobipanel css -->
        <link href="assets/plugins/lobipanel/lobipanel.min.css" rel="stylesheet" type="text/css"/>
        <!-- Pace css -->
        <link href="assets/plugins/pace/flash.css" rel="stylesheet" type="text/css"/>
        <!-- Font Awesome -->
        <link href="assets/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css"/>
        <!-- Pe-icon -->
        <link href="assets/pe-icon-7-stroke/css/pe-icon-7-stroke.css" rel="stylesheet" type="text/css"/>
        <!-- Themify icons -->
        <link href="assets/themify-icons/themify-icons.css" rel="stylesheet" type="text/css"/>
        <!-- End Global Mandatory Style
           =====================================================================-->
        <!-- Start page Label Plugins 
           =====================================================================-->
        <!-- Emojionearea -->
        <link href="assets/plugins/emojionearea/emojionearea.min.css" rel="stylesheet" type="text/css"/>
        <!-- Monthly css -->
        <link href="assets/plugins/monthly/monthly.css" rel="stylesheet" type="text/css"/>
        <!-- End page Label Plugins 
           =====================================================================-->
        <!-- Start Theme Layout Style
           =====================================================================-->
        <!-- Theme style -->
        <link href="assets/dist/css/stylecrm.css" rel="stylesheet" type="text/css"/>
        <!-- Theme style rtl -->
        <!--<link href="assets/dist/css/stylecrm-rtl.css" rel="stylesheet" type="text/css"/>-->
        <!-- End Theme Layout Style
           =====================================================================-->

        <link href="css/svam.css" rel="stylesheet" type="text/css"/>
        <link rel="stylesheet" href="plugins/datepicker/datepicker3.css">
     <link rel="stylesheet" href="bootstrap/css/bootstrap-datetimepicker.css"> 


        <link rel="stylesheet" href="css/cus-icons.css" />
    </head>

<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>Appel - Modifier 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_edit_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 >N° Ticket : </label>
                                            <h4 class="svam-ticket-nb" ><?php echo $res['caller_ticket_id']; ?> <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 >Statut : </label>
                                            <h4 style="color:green; font-weight: bold; font-size: 20px" ><?php echo $res['description_v']; ?> </h4>
                                        </div>
                                        <div class="form-group col-md-4">
                                            <label >N° Appelant :</label>
                                            <h3><?php echo $res['from_callerid_v']; ?> <input type="hidden" name="callerId" id="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; ?>" disabled="disabled" />
                                        </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; ?>" disabled="disabled" />
                                        </div>
                                    </div>
                                    <div class="form-row">   
                                        <div class="form-group col-md-4">
                                            <label for="company">Adresse</label> 
                                            <input type="text" class="form-control" id="company" name="company" value="<?php echo $company; ?>" disabled="disabled" >
                                            <!--
                                             <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']; ?>" disabled="disabled" />
                                        </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']; ?>" disabled="disabled" />  <input type="hidden"  id="actionType" name="actionType"  value="2" disabled="disabled" />
                                        </div>
                                    </div>

                                    <div class="form-row">



                                    </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" disabled="disabled" >
                                                <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" disabled="disabled" >
                                                <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="csrDetails">Description de la requête client</label>
                                            <textarea id="csrDetails" name="csrDetails" class="form-control" cols="5" rows="3" disabled="disabled"><?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" disabled="disabled"><?php echo $dbres[0]['comment_v']; ?></textarea>
                                        </div>

                                    </div>

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







                                        <button type="button" class="btn close-btn" data-dismiss="modal">Fermer</button>




                                    </div>
                                    
                                     <?php if($res['char_field_5'] == "Appel") { ?>
  <div class="form-row">
  <div class="form-group  col-md-12">
      <label for="downloadSound">Télécharger la conversation </label>
     <div id="downloadSound"> <a href="media/<?php echo $res['char_field_2'].".wav";   ?>"> Télécharger </a>  </div>
    </div>
  </div>
  <?php } ?>




                                </form>



                            </td>






                            <td valign="top" align="center" width="60%">
                                <div id="<?php echo $accordion; ?>">
                                    <h4><strong style="color: #400040">Dernières interactions</strong></h4>
                                    <div>

                                        <table id="lastTicket"  width="100%" class="table table-striped" >
                    <thead>
                        <tr style="font-style: italic" >
                            <th >Date</th>
                            <th >N°Ticket</th>
                            <th >Agent</th>
                            <th >Motif d'appel</th>
                            <th >Description requete</th>
                            <th >Descripton reponse</th>
                            <th >statut</th>

                        </tr>
                    </thead>
                    <tbody>
                    <?php for ($i = 0; $i < count($calldata); $i++) { ?>

                        <tr style="font-style: italic" >
                            <td><?php echo $calldata[$i]['event_datetime_d']; ?></td>
                            <td><?php echo $calldata[$i]['ticket_number_v']; ?></td>
                            <td><?php echo $calldata[$i]['user_name_v']; ?></td>
                            <td><?php echo $calldata[$i]['motif_name_v']; ?></td>
                            <td><?php echo $calldata[$i]['ticket_reason_desc_v']; ?></td>
                            <td><?php echo $calldata[$i]['agent_comment_v']; ?></td> 
                            <td><?php echo $calldata[$i]['description_v']; ?></td>

                        </tr>




                    <?php } ?>

                      </tbody>
                </table>



                                    </div>
                                    <h4><strong style="color: #400040">Historique des actions</strong></h4>
                                    <div>
                                        <div>
                                            <table id="lastActions" class="table-responsive" width="100%" >
                                                <thead>
                                                    <tr style="font-style: italic" >
                                                        <th >Date</th>
                                                        <th >N°Ticket</th>
                                                        <th >Agent</th>
                                                        <th >Profil</th>
                                                        <th >Commentaire</th>
                                                        <th >statut</th>

                                                    </tr>
                                                </thead>
                                                <tbody>

<?php for ($i = 0; $i < count($tHistory); $i++) { ?>

                                                    <tr style="font-style: italic">
                                                        <td><?php echo $tHistory[$i]['event_date']; ?></td>
                                                        <td><?php echo $tHistory[$i]['ticket_number_v']; ?></td>
                                                        <td><?php echo $tHistory[$i]['user_name_v']; ?></td>
                                                        <td><?php echo $tHistory[$i]['profile_name_v']; ?></td>
                                                        <td><?php echo $tHistory[$i]['comment_v']; ?></td> 
                                                        <td><?php echo $tHistory[$i]['description_v']; ?></td>

                                                    </tr>




<?php } ?>

 </tbody>
                                            </table>
                                        </div>
                                    </div>


                                </div>



                            </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

                });
                //  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" src="js/jquery.loading.min.js"></script>
<link rel="stylesheet" href="css/jquery-confirm.min.css">
<script src="js/jquery-confirm.min.js
        
  <script src="assets/plugins/jQuery/jquery-1.12.4.min.js" type="text/javascript"></script>
        <!-- jquery-ui --> 
        <script src="assets/plugins/jquery-ui-1.12.1/jquery-ui.min.js" type="text/javascript"></script>
        <!-- Bootstrap -->
        <script src="assets/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
        <!-- lobipanel -->
        <script src="assets/plugins/lobipanel/lobipanel.min.js" type="text/javascript"></script>
        <!-- Pace js -->
        <script src="assets/plugins/pace/pace.min.js" type="text/javascript"></script>

        <script src="assets/plugins/table-export/tableExport.js" type="text/javascript"></script>
        <script src="assets/plugins/table-export/jquery.base64.js" type="text/javascript"></script>
        <script src="assets/plugins/table-export/html2canvas.js" type="text/javascript"></script>
        <script src="assets/plugins/table-export/sprintf.js" type="text/javascript"></script>
        <script src="assets/plugins/table-export/jspdf.js" type="text/javascript"></script>
        <script src="assets/plugins/table-export/base64.js" type="text/javascript"></script>
        <!-- dataTables js -->
        <script src="assets/plugins/datatables/dataTables.min.js" type="text/javascript"></script>
        <!-- SlimScroll -->
        <script src="assets/plugins/slimScroll/jquery.slimscroll.min.js" type="text/javascript"></script>
        <!-- FastClick -->
        <script src="assets/plugins/fastclick/fastclick.min.js" type="text/javascript"></script>
        <!-- CRMadmin frame -->
        <script src="assets/dist/js/custom.js" type="text/javascript"></script>
        <!-- End Core Plugins
           =====================================================================-->
        <!-- Start Page Lavel Plugins
           =====================================================================-->
        <!-- ChartJs JavaScript -->
        <script src="assets/plugins/chartJs/Chart.min.js" type="text/javascript"></script>
        <!-- Counter js -->
        <script src="assets/plugins/counterup/waypoints.js" type="text/javascript"></script>
        <script src="assets/plugins/counterup/jquery.counterup.min.js" type="text/javascript"></script>
        <!-- Monthly js -->
        <script src="assets/plugins/monthly/monthly.js" type="text/javascript"></script>
        <!-- End Page Lavel Plugins
           =====================================================================-->
        <!-- Start Theme label Script
           =====================================================================-->
        <!-- Dashboard js -->
        <script src="assets/dist/js/dashboard.js" type="text/javascript"></script>
        <!-- End Theme label Script
           =====================================================================-->
        <script type="text/javascript" src="js/svam.js" ></script>


        <script src="assets/plugins/datatables/jquery.dataTables.min.js" type="text/javascript"></script>
        <script src="plugins/datepicker/bootstrap-datepicker.js"></script>
        <script src="plugins/datepicker/locales/bootstrap-datepicker.fr.js"></script>
        
   

       <script src="bootstrap/js/bootstrap-datetimepicker.min.js"></script>
        <script src="bootstrap/js/locales/bootstrap-datetimepicker.fr.js"></script> 
        