<?php include("conn.php");
$page='Customer Feedback';?>
<!DOCTYPE html>
<html lang="en">
<?php include("common/head.php")?>

<body>
<?php include("common/menu.php")?>
<!---side nav bar end-->
<?php include("common/tittle.php")?>
            <!--Main body Start-->
            <div id="accordions" class="col-sm-12  mt-2">
  
                <!--search section end-->
                <!--Orders start-->

                <!--order-items-->
                <!--order-items-one-->
            
                   <!--order-items-two-->
 
<div class="action">

<?php
   $sql2="select * from cfeedback where rating=5  ";
   $result2 = mysqli_query($conn,$sql2)or die( mysqli_error($conn));
   $exe = mysqli_num_rows($result2) ;

   $sql2="select * from cfeedback where rating=4  ";
   $result2 = mysqli_query($conn,$sql2)or die( mysqli_error($conn));
   $good = mysqli_num_rows($result2) ;

   $sql2="select * from cfeedback where rating=3  ";
   $result2 = mysqli_query($conn,$sql2)or die( mysqli_error($conn));
   $fair = mysqli_num_rows($result2) ;

   $sql2="select * from cfeedback where rating=2  ";
   $result2 = mysqli_query($conn,$sql2)or die( mysqli_error($conn));
   $poor = mysqli_num_rows($result2) ;

   $sql2="select * from cfeedback where rating=1  ";
   $result2 = mysqli_query($conn,$sql2)or die( mysqli_error($conn));
   $very_poor = mysqli_num_rows($result2) ;

   $total_rating=$exe+$good+$fair+$poor+$very_poor;

   $total_exe=$exe/$total_rating*100;

   $total_good=$good/$total_rating*100;

   $total_fair=$fair/$total_rating*100;

   $total_poor=$poor/$total_rating*100;

   $total_very_poor=$very_poor/$total_rating*100;

?>

<h5 class="text-center text-uppercase">Customer Feedbacks</h5>
<button class="btn btn-success m-1">Excellent <b><?php echo round($total_exe,1)?>%</b></button>
  <button class="btn btn-primary m-1">Good <b><?php echo round($total_good,1)?>%</b></button>
  <button class="btn btn-info m-1">Fair  <b><?php echo round($total_fair,1)?>%</b></button>
  <button class="btn btn-secondary m-1">Poor <b><?php echo round($total_poor,1)?>%</b></button>
  <button class="btn btn-warning m-1">Very Poor <b><?php echo round($total_very_poor,1)?>%</b></button>
</div>
               <!--order-items-three-->
               <div   style="overflow: scroll; height:100vh;" class="orders " >
             
                <table id="example_table" class="table-customer table-striped   w-100 table-bordered">
                        <thead>
                        <tr>
                            <th>Id</th>
                            <th>Customer name</th>
                            <th>Contact</th>
                            <th>Message</th>
                            <th>Rating</th>
                            <th>Date</th>
                        </tr>
                        </thead>
                        <tbody>
                        <?php

$sql2="SELECT * FROM currency ";
$result2 = mysqli_query($conn,$sql2)or die( mysqli_error($conn));
$row2=mysqli_fetch_array($result2) ;
$currency=$row2['curency'];

$sql="select * from cfeedback  ";
$result = mysqli_query($conn,$sql)or die( mysqli_error($conn));
while ($row=mysqli_fetch_array($result)) {
  $id=$row['id'];
 $customer_id=$row['customerid'];
   $orderid=$row['orderid'];
   $message=$row['massage'];
   $status=$row['status'];
   $rating=$row['rating'];
   $date=$row['date'];
   
if($rating==5){
    $check1='orange';
     $check2='orange';
     $check3='orange';
     $check4='orange';
     $check5='orange';
}
elseif($rating==4){
    $check1='orange';
     $check2='orange';
     $check3='orange';
     $check4='orange';
     $check5='';
}
elseif($rating==3){
    $check1='orange';
     $check2='orange';
     $check3='orange';
     $check4='';
     $check5='';
}
elseif($rating==2){
    $check1='orange';
     $check2='orange';
     $check3='';
     $check4='';
     $check5='';
}
elseif($rating==1){
    $check1='orange';
     $check2='';
     $check3='';
     $check4='';
     $check5='';
}
else{
    $check1='';
     $check2='';
     $check3='';
     $check4='';
     $check5='';
}

   $real_id=substr($orderid,-2);
$ord = sprintf('%03d',$real_id);   

 $sql1="select * from customers where customer_id='$customer_id' ";
              $result1 = mysqli_query($conn,$sql1)or die( mysqli_error($conn));
              $row1=mysqli_fetch_array($result1);

              if(empty($row1)){
                $fname='';
              $contact=''; 
              }
              else{
                $fname=$row1['fname'];
                $contact=$row1['number'];
              }
             
         
             
     
$link="print_receipt?p=online_history&item=".urlencode(base64_encode($data));
?>
                        <tr>
                            <td>#<?php echo $ord ?></td>
                            <td><?php echo $fname ?></td>                           
                            <td><?php echo $contact ?></td>
                            <td><?php echo $message ?></td>
                            <td><span style="color:<?php echo $check1 ?>" class="fa fa-star "></span>
                               <span  style="color:<?php echo $check2 ?>"class="fa fa-star "></span>
                               <span  style="color:<?php echo $check3 ?>"class="fa fa-star "></span>
                                  <span  style="color:<?php echo $check4 ?>" class="fa fa-star"></span>
                          <span  style="color:<?php echo $check5 ?>" class="fa fa-star"></span></td>
                            <td><?php echo $date ?></td>

                            

                           


                        </tr>
                        <?php } ?>
                        <thead>
                        <th>Id</th>
                            <th>Customer name</th>
                            <th>Contact</th>
                            <th>Message</th>
                            <th>Rating</th>
                            <th>Date</th>

                    </tbody>
                    </table>


            </div>

          


       <!--modal delete-->
<!-- Large modal -->
<div id="dataModal1" class="modal fade bd-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
  <div class="modal-dialog modal-lg">
    <div  id="employee_detail1" class="modal-content text-dark">
      
     
    
    </div>
  </div>
</div>

<!-- Large modal -->
<div id="dataModals" class="modal fade bd-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
  <div class="modal-dialog ">
    <div  id="employee_details" class="modal-content text-dark">
      
     
    
    </div>
  </div>
</div>

<!-- Large modal -->
<div id="dataModal" class="modal fade bd-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
  <div class="modal-dialog ">
    <div  id="employee_detail" class="modal-content text-dark">
      
     
    
    </div>
  </div>
</div>

    
                <!--Order end-->
            </div>
            <!--Main body end-->

      
        </div>

    </div>
    
  <!--  isotope plugin cdn  -->
 
    <script src="js/script.js"></script>
     <!-- jQuery js-->
   <!-- jQuery Datatable js -->
   <script src="https://cdn.datatables.net/2.0.5/js/dataTables.js"></script>
     <script src="https://cdn.datatables.net/buttons/3.0.2/js/dataTables.buttons.js"></script>
     <script src="https://cdn.datatables.net/buttons/3.0.2/js/buttons.dataTables.js"></script>
     <script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js"></script>
     <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.2.7/pdfmake.min.js"></script>
     <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.2.7/vfs_fonts.js"></script>
     <script src="https://cdn.datatables.net/buttons/3.0.2/js/buttons.html5.min.js"></script>
     <script src="https://cdn.datatables.net/buttons/3.0.2/js/buttons.print.min.js"></script>

     <script>
      $(document).ready( function () {
        new DataTable('#example_table', {
          columnDefs: [ { type: 'date', 'targets': [3] } ],
          order: [[ 3, 'desc' ]],
            autoFill: true,
            pageLength : 10,
    lengthMenu: [[5, 10, 20, -1], [5, 10, 30, 'Todos']],
    layout: {
        topStart: {
            buttons: ['copy', 'csv', 'excel', 'pdf', 'print']
        }
    }
});
       } );
</script>
     <script>
       $(document).ready(function(){  
      $('.view_datas').click(function(){  
           var employee_ids = $(this).attr("id");  
           $.ajax({  
                url:"order_by_customer_ajax.php",  
                method:"post",  
                data:{employee_ids:employee_ids},  
                success:function(data){  
                     $('#employee_detail1').html(data);  
                     $('#dataModal1').modal("show");  
                }  
           });  
      });  
 });  
</script>
<script>
       $(document).ready(function(){  
      $('.view_datase').click(function(){  
           var employee_ids = $(this).attr("id");  
           $.ajax({  
                url:"delivery_confirmation_ajax.php",  
                method:"post",  
                data:{employee_ids:employee_ids},  
                success:function(data){  
                     $('#employee_details').html(data);  
                     $('#dataModals').modal("show");  
                }  
           });  
      });  
 });  
</script>
<script>
       $(document).ready(function(){  
      $('.view_data').click(function(){  
           var employee_ids = $(this).attr("id");  
           $.ajax({  
                url:"payment_confirmation_ajax.php",  
                method:"post",  
                data:{employee_ids:employee_ids},  
                success:function(data){  
                     $('#employee_detail').html(data);  
                     $('#dataModal').modal("show");  
                }  
           });  
      });  
 });  
</script>
</body>

</html>