<?php
// ====================== track/login.php ======================
session_start();
require_once('dbconnection.php');

$error = "";

if (isset($_POST['login'])) {
    $username = mysqli_real_escape_string($dbcon, $_POST['username']);
    $password = mysqli_real_escape_string($dbcon, $_POST['password']);

    $query = "SELECT * FROM users WHERE username='$username' AND password='$password'";
    $result = mysqli_query($dbcon, $query);

    if (mysqli_num_rows($result) > 0) {
        $row = mysqli_fetch_assoc($result);
        $_SESSION['SESS_MEMBER_ID'] = $row['sno'];
        $_SESSION['SESS_USERNAME']  = $row['username'];
        header("Location: admin.php");
        exit();
    } else {
        $error = "Invalid Username or Password!";
    }
}
?>

<!DOCTYPE html>
<html>
<head>
    <title>Admin Login - Swift Logistics</title>
    <style>
        body {font-family: Arial; background:#f4f4f4; text-align:center; padding:100px;}
        .login-box {width:400px; margin:auto; background:white; padding:40px; border-radius:8px; box-shadow:0 0 15px rgba(0,0,0,0.1);}
        input {width:100%; padding:12px; margin:10px 0; box-sizing:border-box;}
        button {width:100%; padding:12px; background:#0066cc; color:white; border:none; cursor:pointer;}
    </style>
</head>
<body>
    <div class="login-box">
        <h2>Swift Logistics Admin Login</h2>
        <?php if($error) echo "<p style='color:red;'>$error</p>"; ?>
        
        <form method="post">
            <input type="text" name="username" placeholder="Username" required><br>
            <input type="password" name="password" placeholder="Password" required><br>
            <button type="submit" name="login">LOGIN</button>
        </form>
        
        <p><small>Demo Login:<br>
        Username: <b>globalexdeliverycompany</b><br>
        Password: <b>adminsky1</b></small></p>
    </div>
</body>
</html>