<?php
require_once 'auth.php';

$conn = new mysqli("localhost","root","","tradelicense");

if($conn->connect_error){
    die("Connection Failed: ".$conn->connect_error);
}

$search = "";

if(isset($_GET['search'])){
    $search = $conn->real_escape_string($_GET['search']);

    $sql = "SELECT * FROM details
            WHERE license_id LIKE '%$search%'
            OR license_no LIKE '%$search%'
            OR owner_name_english LIKE '%$search%'
            ORDER BY id DESC";
}else{
    $sql = "SELECT * FROM details ORDER BY id DESC";
}

$result = $conn->query($sql);
?>
<!DOCTYPE html>
<html lang="en">
<head>

<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>All Licenses</title>

<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css" rel="stylesheet">

<style>

body{
    background:#f4f7fc;
}

.sidebar{
    position:fixed;
    width:260px;
    height:100vh;
    background:linear-gradient(135deg,#0f172a,#1e293b);
}

.sidebar .logo{
    color:#fff;
    text-align:center;
    padding:20px;
    border-bottom:1px solid rgba(255,255,255,.1);
}

.sidebar a{
    display:block;
    padding:14px 20px;
    color:#cbd5e1;
    text-decoration:none;
}

.sidebar a:hover,
.sidebar a.active{
    background:#2563eb;
    color:#fff;
}

.main{
    margin-left:260px;
    padding:25px;
}

.topbar{
    background:#fff;
    padding:15px 20px;
    border-radius:15px;
    box-shadow:0 2px 10px rgba(0,0,0,.08);
    margin-bottom:20px;
}

.table-box{
    background:#fff;
    border-radius:15px;
    padding:20px;
    box-shadow:0 2px 10px rgba(0,0,0,.08);
}

</style>

</head>
<body>

<div class="sidebar">

    <div class="logo">
        <h4>LICENSE PANEL</h4>
    </div>

    <a href="dashboard.php">
        <i class="fas fa-home"></i> Dashboard
    </a>

    <a href="up.php">
        <i class="fas fa-plus-circle"></i> Add License
    </a>

    <a href="search.php">
        <i class="fas fa-search"></i> Search
    </a>

    <a href="license_list.php" class="active">
        <i class="fas fa-list"></i> All Licenses
    </a>

    <a href="logout.php">
        <i class="fas fa-sign-out-alt"></i> Logout
    </a>

</div>

<div class="main">

    <div class="topbar">
        <h3>All Licenses</h3>
    </div>

    <div class="table-box">

        <form method="GET" class="mb-3">
            <div class="row">

                <div class="col-md-10">
                    <input
                        type="text"
                        name="search"
                        class="form-control"
                        placeholder="Search License..."
                        value="<?= htmlspecialchars($search) ?>">
                </div>

                <div class="col-md-2">
                    <button class="btn btn-primary w-100">
                        Search
                    </button>
                </div>

            </div>
        </form>

        <div class="table-responsive">

        <table class="table table-bordered table-hover">

            <thead class="table-dark">
            <tr>

                <th>ID</th>
                <th>License No</th>
                <th>License ID</th>
                <th>Owner</th>
                <th>Phone</th>
                <th>Expiry</th>
                <th>Action</th>

            </tr>
            </thead>

            <tbody>

            <?php
            if($result && $result->num_rows > 0){

                while($row = $result->fetch_assoc()){
            ?>

            <tr>

                <td><?= $row['lic_id']; ?></td>

                <td><?= $row['license_no']; ?></td>

                <td><?= $row['license_id']; ?></td>

                <td><?= $row['owner_name_english']; ?></td>

                <td><?= $row['phone_number']; ?></td>

                <td><?= $row['expiry_date']; ?></td>

                <td>

                    <a href="print_license.php?Id=<?= $row['lic_id']; ?>"
                       class="btn btn-success btn-sm">

                        View

                    </a>

                  <a href="up.php?edit=<?= $row['id']; ?>" class="btn btn-warning btn-sm"> Edit </a>


                    <a href="delete_license.php?id=<?= $row['id']; ?>"
   class="btn btn-danger btn-sm"
   onclick="return confirm('Delete this license?')">
   Delete
</a>

                    </a>

                </td>

            </tr>

            <?php
                }
            }else{
            ?>

            <tr>
                <td colspan="7" class="text-center">
                    No Data Found
                </td>
            </tr>

            <?php } ?>

            </tbody>

        </table>

        </div>

    </div>

</div>

</body>
</html>
```
