<?php
// Initialize the session
session_start();
// Check if the user is logged in, if not then redirect him to login page
if(!isset($_SESSION["loggedin"]) || $_SESSION["loggedin"] !== true){
    header("location: login.php");
    exit;
}
// Include PHP Cutext
require_once "../assets/php/cuttext.php";
?>
<!DOCTYPE html>
<html lang="en-us">

<head>
    <title>SYSDesk - Ticket achive</title>
    <meta charset="UTF-8">
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="shortcut icon" type="image/x-icon" href="../assets/favicon.ico" />
    <link href="https://fonts.googleapis.com/css?family=Roboto:400,100,100italic,300,300italic,400italic,500,500italic,700italic,700,900,900italic" rel="stylesheet">
    <!-- STYLESHEETS -->
    <style type="text/css">
            [fuse-cloak],
            .fuse-cloak {
                display: none !important;
            }
        </style>
    <!-- Icons.css -->
    <link type="text/css" rel="stylesheet" href="../assets/icons/fuse-icon-font/style.css">
    <!-- Animate.css -->
    <link type="text/css" rel="stylesheet" href="../assets/node_modules/animate.css/animate.min.css">




    <!-- Perfect Scrollbar -->
    <link type="text/css" rel="stylesheet" href="../assets/node_modules/perfect-scrollbar/css/perfect-scrollbar.css" />
    <!-- Fuse Html -->
    <link type="text/css" rel="stylesheet" href="../assets/fuse-html/fuse-html.min.css" />
    <!-- Main CSS -->
    <link type="text/css" rel="stylesheet" href="../assets/css/main.css">
	<!-- Custom CSS -->
	<link type="text/css" rel="stylesheet" href="../assets/css/custom.css">
    <!-- / STYLESHEETS -->

    <!-- JAVASCRIPT -->
    <!-- jQuery -->
    <script type="text/javascript" src="../assets/node_modules/jquery/dist/jquery.min.js"></script>
    <!-- Mobile Detect -->
    <script type="text/javascript" src="../assets/node_modules/mobile-detect/mobile-detect.min.js"></script>
    <!-- Perfect Scrollbar -->
    <script type="text/javascript" src="../assets/node_modules/perfect-scrollbar/dist/perfect-scrollbar.min.js"></script>
    <!-- Popper.js -->
    <script type="text/javascript" src="../assets/node_modules/popper.js/dist/umd/popper.min.js"></script>
    <!-- Bootstrap -->
    <script type="text/javascript" src="../assets/node_modules/bootstrap/dist/js/bootstrap.min.js"></script>



    <!-- Data tables -->
    <script type="text/javascript" src="../assets/node_modules/datatables.net/js/jquery.dataTables.js"></script>
    <script type="text/javascript" src="../assets/node_modules/datatables-responsive/js/dataTables.responsive.js"></script>

    








    <!-- Fuse Html -->
    <script type="text/javascript" src="../assets/fuse-html/fuse-html.min.js"></script>
    <!-- Main JS -->
    <script type="text/javascript" src="../assets/js/main.js"></script>
    <!-- / JAVASCRIPT -->
</head>
<body class="layout layout-vertical layout-left-navigation layout-below-toolbar layout-below-footer">
    <main>
        <div id="wrapper">
            <aside id="aside" class="aside aside-left" data-fuse-bar="aside" data-fuse-bar-media-step="md" data-fuse-bar-position="left">
                <div class="aside-content bg-primary-700 text-auto">
                    <div class="aside-toolbar">
                        <div class="logo">
                            <span class="logo-icon icon-desktop-mac"></span>
                            <p class="logo-text texttoolbar">SYSDesk</p>
                        </div>
                        <button id="toggle-fold-aside-button" type="button" class="btn btn-icon d-none d-lg-block" data-fuse-aside-toggle-fold>
                            <i class="icon icon-backburger"></i>
                        </button>
                    </div>
                    <ul class="nav flex-column custom-scrollbar" id="sidenav" data-children=".nav-item">
                        <li class="nav-item">
                            <a class="nav-link ripple " href="systems.php" data-url="index.html">
                                <i class="icon s-4 icon-desktop-tower"></i>
                                <span>Systems</span>
                            </a>
                        </li>
						<li class="nav-item">
                            <a class="nav-link ripple" href="tickets.php">
                                <i class="icon s-4 icon-message-bulleted"></i>
                                <span>Tickets</span>
                            </a>
                        </li>

                        <li class="nav-item" role="tab" id="heading-ecommerce">

                            <a class="nav-link ripple with-arrow collapsed" data-toggle="collapse" data-target="#collapse-ecommerce" href="#" aria-expanded="false" aria-controls="collapse-ecommerce">

                                <i class="icon s-4 icon-settings"></i>

                                <span>Settings</span>
                            </a>
                            <ul id="collapse-ecommerce" class='collapse ' role="tabpanel" aria-labelledby="heading-ecommerce" data-children=".nav-item">

                                <li class="nav-item">
                                    <a class="nav-link ripple " href="users.php" data-url="index.html">

                                        <span>Users</span>
                                    </a>
                                </li>
                                 <li class="nav-item">
                                    <a class="nav-link ripple " href="reset-password.php">

                                        <span>Reset Password</span>
                                    </a>
                                </li>
                                <li class="nav-item">
                                    <a class="nav-link ripple " href="other-settings.php" data-url="index.html">

                                        <span>Other settings</span>
                                    </a>
                                </li>
                            </ul>
                        </li>
                    </ul>
                </div>
            </aside>
            <div class="content-wrapper">
                <nav id="toolbar" class="bg-white">
                    <div class="row no-gutters align-items-center flex-nowrap">
                        <div class="col">
                            <div class="row no-gutters align-items-center flex-nowrap">
                                <button type="button" class="toggle-aside-button btn btn-icon d-block d-lg-none fuse-ripple-ready" data-fuse-bar-toggle="aside">
                                    <i class="icon icon-menu"></i>
                                </button>
                                <div class="toolbar-separator d-block d-lg-none"></div>
                            </div>
                        </div>
                        <div class="col-auto">
                            <div class="row no-gutters align-items-center justify-content-end">
							<a href="logout.php" class="logintoolbar ripple icon row align-items-center no-gutters px-2 px-sm-4" role="button" id="logintoolbar" aria-haspopup="true" aria-expanded="false">Logout</a>
                            </div>
                        </div>
                    </div>
                </nav>
					   <div class="content custom-scrollbar">
						<div class="page-layout simple full-width">
						 <div class="page-content-wrapper">
						 
						 
						  <!-- CONTENT -->
						         <div class="clearfix" style="padding:20px;">
                        <a data-toggle='tooltip' data-original-title='Back' href="tickets.php" class="btn btn-secondary btn-fab"><i class="icon-arrow-left"></i></a>
                        <h2 class="pull-right">Ticket archive</h2>
                    </div>
               <body>
    <div class="wrapper">
        <div class="container-fluid">
            <div class="row">
                <div class="col-md-12">
                    <?php
                    // Include config file
                    require_once "../assets/php/config.php";
                    
                    // Attempt select query execution
                    $sql = "SELECT * FROM tickets_arch";
                    if($result = mysqli_query($link, $sql)){
                        if(mysqli_num_rows($result) > 0){
                            echo "<table class='table table-bordered table-striped'>";
                                echo "<thead>";
                                    echo "<tr>";
                                        echo "<th>#</th>";
                                        echo "<th>sysID</th>";
                                        echo "<th>Location</th>";
                                        echo "<th>Request Type</th>";
                                        echo "<th>Request by</th>";
                                        echo "<th>Reason</th>";
                                        echo "<th>Date/Time</th>";
                                    echo "</tr>";
                                echo "</thead>";
                                echo "<tbody>";
                                while($row = mysqli_fetch_array($result)){
                                    echo "<tr>";
                                        echo "<td>" . $row['id'] . "</td>";
                                        echo "<td><a class='sysIDticket' href='view-system.php?sysID=". $row['sysID'] ."' title='View system' data-toggle='tooltip'>" . $row['sysID'] . "</a></td>";
                                        echo "<td>" . $row['location'] . "</td>";
                                        echo "<td>" . $row['requestype'] . "</td>";
                                        echo "<td>" . $row['rusername'] . "</td>";
                                        echo "<td>" . cutText($row['reason'], 50)."</td>";
                                        echo "<td>" . $row['time'] . "</td>";
                                        echo "<td>";
                                            echo "<a class='crud' href='view-achivedticket.php?id=". $row['id'] ."' title='View ticket' data-toggle='tooltip'><span class='icons icon-eye'></span></a>";
                                            echo "<a class='crud' href='delete-achivedticket.php?id=". $row['id'] ."' title='Delete ticket' data-toggle='tooltip'><span class='icons icon-trash'></span></a>";
                                        echo "</td>";
                                    echo "</tr>";
                                }
                                echo "</tbody>";                            
                            echo "</table>";
                            // Free result set
                            mysqli_free_result($result);
                        } else{
                            echo "<p class='lead'><em>No tickets were found.</em></p>";
                        }
                    } else{
                        echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
                    }
 
                    // Close connection
                    mysqli_close($link);
                    ?>
                </div>
            </div>        
        </div>
    </div>
						  </div>
						  <!-- / CONTENT -->
						  
						  
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </main>
</body>

</html>