<?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']);

$sccModuleres = $dba->getSCCModules(0);
//$callreasonres = $dba->getSCCCallReasonDetails(0);

$callreasonres = $dba->getSCCCallReasonByFormId($res['char_field_10'], 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']);


//appel des nouveau champs
//$mgfciSupInfo = $dba->getSCCMugefciSupInfoPrestataire($tHistory['ticket_number_v']);

$mgfciSupInfo = $dba->getSCCMugefciSupInfoPrestataire($res['caller_ticket_id']);

//var_dump($mgfciSupInfo);
$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>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_incoming_reclamation_prestataire.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 >Code fournisseur :</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 du prestataire</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">Agent de réception</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">Raison sociale :</label> 
                                            <input type="text" class="form-control" id="company" name="company" value="<?php echo $company; ?>">

                                        </div>
                                        <div class="form-group col-md-4">
                                            <label for="mobileNumber">Téléphone</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 class="form-row">
                                    <div class="form-group col-md-12">
                                            <label for="incident">Période de l’incident</label>
                                            <textarea id="incident" name="incident" class="form-control" cols="5" rows="3"><?php echo $mgfciSupInfo[0]['incident_v']; ?></textarea>
                                        </div>
                                        

                                    </div>


                                    </div>

                                    <div class="form-row">
                                    <div class="form-group col-md-12">
                                            <label for="objet">Objet</label>
                                            <textarea id="objet" name="objet" class="form-control" cols="5" rows="3"><?php echo $mgfciSupInfo[0]['objet_v']; ?></textarea>
                                        </div>
                                        

                                    </div>

                                    <div class="form-row">

                                    <div class="form-group col-md-12">
                                        <label for="callReasonType">Motif</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="csrDetails">DESCRIPTION DE LA PLAINTE OU RÉCLAMATION</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">ANALYSE DES CAUSES</label>
                                            <textarea id="csrComment" name="csrComment" class="form-control" cols="5" rows="3"><?php echo $dbres[0]['comment_v']; ?></textarea>
                                        </div>

                                    </div>

                                    <div class="form-row">

                                <div class="form-group col-md-12">
                                    <label for="analysePlainte">ANALYSE DE LA PLAINTE OU RÉCLAMATION</label>
                                    <textarea id="analysePlainte" name="analysePlainte" class="form-control" cols="5" rows="3"><?php echo $mgfciSupInfo[0]['analysePlainte_v']; ?></textarea>
                                </div>

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

                                <div class="form-group  col-md-12">
                                
                                    <label for="decision">DÉCISION</label>
                                    <textarea id="decision" name="decision" class="form-control" cols="5" rows="3"><?php echo $mgfciSupInfo[0]['decision_v']; ?></textarea>
                                </div>

                                </div>


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

                                        <?php
                                        if ($res['status_n'] == -1) {
                                            ?>

                                            <button type="submit" class="btn btn-primary" id="save" >Enregistrer</button>  

                                        <?php } elseif ($res['status_n'] == 2) { ?>


                                            <button type="submit" class="btn btn-primary" id="save" >Enregistrer</button> <button type="button" class="btn btn-primary" data-href="<?php echo $currentBaseDir; ?>/transfer_ticket.php?item=<?php echo $res['item_id_n']; ?>&ticketId=<?php echo $res['caller_ticket_id']; ?>&toDiv=<?php echo $toDiv; ?>&rPage=<?php echo $currentBaseDir . "/scc_my_calls.php"; ?>"  title="Assigner le ticket" id="trAssignee">Assigner</button> <button type="button" class="btn btn-danger" data-href="<?php echo $currentBaseDir; ?>/close_incoming_reclamation_prestataire.php?item=<?php echo $res['item_id_n']; ?>&ticketId=<?php echo $res['caller_ticket_id']; ?>&toDiv=<?php echo $toDiv; ?>&rPage=<?php echo $currentBaseDir . "/scc_my_calls.php"; ?>&cancelPage=<?php echo $_SERVER['PHP_SELF']; ?>"  id="closeTicketOld">Clôturer</button> 

                                        <?php } elseif ($res['status_n'] == 11) { ?>

                                            <button type="submit" class="btn btn-primary" id="save" >Enregistrer</button>                           

                                        <?php } ?>



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




                                    </div>




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

                                    <h4><strong style="color: #400040">Base de connaissances</strong></h4>
                                    <div>
                                        <div>
                                            <table id="knowledgeBase" class="table-responsive" width="100%" >
                                                <thead>
                                                    <tr style="font-style: italic" >
                                                        <th  width="3" align="left"></th>
                                                        <th width="100" align="left">Date de création</th>
                                                        <th width="100" align="left">Titre</th>
                                                        <th width="200" align="left">Corps</th>
                                                        <th width="100" align="left">Pièce jointe</th>
                                                        <th width="100" align="left">Créé par</th>
                                                        <th width="100" align="left">Modifié par</th>
                                                    </tr>
                                                </thead>
                                                <tbody>
                                                    <?php
                                                    $cmpt = 1;

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




                                                        <tr>
                                                            <td><a href="#"  onclick="view_ticket_details('<?php echo $currentBaseDir; ?>/view_knownledge.php?opId=1&item=<?php echo $kresult[$i]['item_id_n']; ?>')"   title="Voir" class="cus-application-view-list" ></a></td>

                                                            <td align="left"><?php echo $kresult[$i]['creation_datetime_d']; ?></td>
                                                            <td align="left"><?php echo $kresult[$i]['article_title_v']; ?></td>
                                                            <td align="left"><?php echo substr($kresult[$i]['article_body_v'], 0, 30) . '..'; ?></td>
                                                            <td align="left"><?php
                                                                if (strlen($kresult[$i]['attachment_path_v']) > 0) {

                                                                    echo '<a href="' . $kresult[$i]['attachment_path_v'] . '" >Ouvrir</a>';
                                                                }
                                                                ?></td>
                                                            <td align="left"><?php echo $kresult[$i]['user_name_v']; ?></td>
                                                            <td align="left"><?php echo $kresult[$i]['last_update_d']; ?></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">
    
    
    $('#closeTicket').on('click', function(e){
	document.getElementById('actionType').value = 3;
   $(this).parents('form').submit() ;
});

    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 $_SERVER['PHP_SELF']; ?>?rPage=<?php echo $rPage; ?>&item=<?php echo $res['item_id_n']; ?>");
                                                    }
                                                }

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


                                });



                                $('#closeTicketOld').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