<?php
session_start();
require_once 'class.admin.php';

include_once ('session.php');
if(!isset($_SESSION['email'])){
	
header("Location: login.php");

exit(); 
}
$user_home = new USER();


$stmt = $user_home->runQuery("SELECT * FROM ticket ORDER BY id DESC LIMIT 200");
$stmt->execute();

?>


 <?php
include 'dbconnect.php';

$sql = "SELECT * FROM account ORDER BY id";
$sql1 = "SELECT * FROM ticket ";
$sql2 = "SELECT * FROM transfer";
$sql3 = "SELECT * FROM account WHERE verify ='N' ORDER BY id DESC LIMIT 200";


if ($result = mysqli_query($connection, $sql)) {
    // Return the number of rows in result set
    $rowcount = mysqli_num_rows($result);

    // Free result set
    mysqli_free_result($result);

    if ($result1 = mysqli_query($connection, $sql1)) {
        // Return the number of rows in result set
        $rowcount1 = mysqli_num_rows($result1);

        // Free result set
        mysqli_free_result($result1);

        if ($result2 = mysqli_query($connection, $sql2)) {
            // Return the number of rows in result set
            $rowcount2 = mysqli_num_rows($result2);

            // Free result set
            mysqli_free_result($result2);

            if ($result3 = mysqli_query($connection, $sql3)) {
                // Return the number of rows in result set
                $rowcount3 = mysqli_num_rows($result3);

                // Free result set
                mysqli_free_result($result3);
            }
        }
    }
}

mysqli_close($connection);
?>
       <?php include 'headeradmin.php'; ?>
 

 <!---begin of Mobile View Here   only from Domain Team-->
 
       <?php include 'menu.php'; ?>
  
  <!---End of Mobile View Here   only from Domain Team-->
  
 
      <script type="text/javascript" src="paginator.js"></script>
        <script type="text/javascript" src="table.js"></script>
     


    <div class="container-fluid mt--1">
     <!-- Table -->
      <div class="row">
        <div class="col">
          <div class="card shadow" >
            <div class="card-header border-0">
              <h3 class="mb-0"><a href=""   class="btn btn-danger">TICKETS OPENED</a></h3>
            </div>
                        <div class="card">
                            <div class="card-body">
                                 <div class="col-md-12 align-self-center">
                        	<section id="content" class="container">
			<h4 class="page-title block-title"> Tickets</h4>
                <div class="block-area" id="tableHover">
                    <h3 class="block-title">View All Opened Tickets</h3>
                    	<?php 
							if(isset($_GET['success']))
								{
									?>
									<div class='alert alert-info'>
										<button class='close' data-dismiss='alert'>&times;</button>
										<strong>Record Deleted Successfully</strong> 
									</div>
									<?php
								}
						?>
			<?php 
							if(isset($_GET['error']))
								{
									?>
									<div class='alert alert-danger'>
										<button class='close' data-dismiss='alert'>&times;</button>
										<strong>Unable to Delete Record</strong> 
									</div>
									<?php
								}
						?>
                    <div class="table-responsive overflow">
                        <table class="table table-bordered table-hover tile">
                            <thead>
		
                                <tr>
                                    <th><b>Ticket Number</b></th>
									<th><b>Sender</b></th>
									<th><b>Subject</b></th>
                                    <th><b>Message</b></th>
                                    <th><b>Date Opened</b></th>
                                    <th><b>Reply</b></th>
                                    <th><b>Delete Ticket</b></th>
                                </tr>
                            </thead>
                            <tbody>
							
			<?php while($row = $stmt->fetch(PDO::FETCH_ASSOC)){?>
                                <tr>
                                    <td><?php echo $row['tc']; ?></td>
                                    <td><?php echo $row['sender_name']; ?></td>
                                    <td><?php echo $row['subject']; ?></td>
                                    <td><?php echo $row['msg']; ?></td>
                                    <td><?php echo $row['date']; ?></td>
                                    <td> <a href="messages.php"><button type="button" class="btn btn-info d-none d-lg-block m-l-15"><i class="fa fa-inbox"></i>REPLY</button></a></td>
                                    <td><a href="dec.php?id=<?php echo $row['id']; ?>" title="Delete Ticket" rel="tooltip" class="btn btn-simple btn-info btn-icon "><i class="fa fa-ban"></i></a></td>
                                    
                                </tr>
                                
        <?php }?>                    </tbody>
                        </table>
                    </div>
                </div>
                
                <hr class="whiter m-t-20" />
			</section>
                
                <!-- ============================================================== -->
                <!-- End Right sidebar -->
                <!-- ============================================================== -->
            </div>
            <!-- ============================================================== -->
            <!-- End Container fluid  -->
            <!-- ============================================================== -->
        </div>
        <!-- ============================================================== -->
        <!-- End Page wrapper  -->
        <!-- ============================================================== -->
        <!-- ============================================================== -->
        <!-- footer -->
        <!-- ============================================================== -->
        
       <?php include 'foot.php'; ?>
        <!-- ============================================================== -->
        <!-- End footer -->
        <!-- ============================================================== -->
    </div></div></div></div></div></div>
    <!-- ============================================================== -->
    <!-- End Wrapper -->
    <!-- ============================================================== -->
    <!-- ============================================================== -->
    <!-- All Jquery -->
    <!-- ============================================================== -->
    <script src="../../dist/assets/node_modules/jquery/jquery-3.2.1.min.js"></script>
    <!-- Bootstrap popper Core JavaScript -->
    <script src="../../dist/assets/node_modules/popper/popper.min.js"></script>
    <script src="../../dist/assets/node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
    <!-- slimscrollbar scrollbar JavaScript -->
    <script src="dist/js/perfect-scrollbar.jquery.min.js"></script>
    <!--Wave Effects -->
    <script src="dist/js/waves.js"></script>
    <!--Menu sidebar -->
    <script src="dist/js/sidebarmenu.js"></script>
    <!--Custom JavaScript -->
    <script src="dist/js/custom.min.js"></script>
    <!-- ============================================================== -->
    <!-- This page plugins -->
    <!-- ============================================================== -->
    <!--morris JavaScript -->
    <script src="../../dist/assets/node_modules/raphael/raphael-min.js"></script>
    <script src="../../dist/assets/node_modules/morrisjs/morris.min.js"></script>
    <script src="../../dist/assets/node_modules/jquery-sparkline/jquery.sparkline.min.js"></script>
    <!-- Popup message jquery -->
    <script src="../../dist/assets/node_modules/toast-master/js/jquery.toast.js"></script>
    <!-- Chart JS -->
    <script src="dist/js/dashboard1.js"></script>
    <script src="../../dist/assets/node_modules/toast-master/js/jquery.toast.js"></script>
    
     <!-- This is data table -->
    <script src="../../dist/assets/node_modules/datatables/jquery.dataTables.min.js"></script>
    <!-- start - This is for export functionality only -->
    <script src="https://cdn.datatables.net/buttons/1.2.2/js/dataTables.buttons.min.js"></script>
    <script src="https://cdn.datatables.net/buttons/1.2.2/js/buttons.flash.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/2.5.0/jszip.min.js"></script>
    <script src="https://cdn.rawgit.com/bpampuch/pdfmake/0.1.18/build/pdfmake.min.js"></script>
    <script src="https://cdn.rawgit.com/bpampuch/pdfmake/0.1.18/build/vfs_fonts.js"></script>
    <script src="https://cdn.datatables.net/buttons/1.2.2/js/buttons.html5.min.js"></script>
    <script src="https://cdn.datatables.net/buttons/1.2.2/js/buttons.print.min.js"></script>
    <!-- end - This is for export functionality only -->
    <script>
    $(document).ready(function() {
        $('#myTable').DataTable();
        $(document).ready(function() {
            var table = $('#example').DataTable({
                "columnDefs": [{
                    "visible": false,
                    "targets": 2
                }],
                "order": [
                    [2, 'asc']
                ],
                "displayLength": 25,
                "drawCallback": function(settings) {
                    var api = this.api();
                    var rows = api.rows({
                        page: 'current'
                    }).nodes();
                    var last = null;
                    api.column(2, {
                        page: 'current'
                    }).data().each(function(group, i) {
                        if (last !== group) {
                            $(rows).eq(i).before('<tr class="group"><td colspan="5">' + group + '</td></tr>');
                            last = group;
                        }
                    });
                }
            });
            // Order by the grouping
            $('#example tbody').on('click', 'tr.group', function() {
                var currentOrder = table.order()[0];
                if (currentOrder[0] === 2 && currentOrder[1] === 'asc') {
                    table.order([2, 'desc']).draw();
                } else {
                    table.order([2, 'asc']).draw();
                }
            });
        });
    });
    $('#example23').DataTable({
        dom: 'Bfrtip',
        buttons: [
            'copy', 'csv', 'excel', 'pdf', 'print'
        ]
    });
    </script>
    
</body>

</html>