<?php
session_start();
$dbtype = "root";
require("includes/dbconnect.php");
require("includes/config.php");
require("includes/function.php");

ini_set('display_errors', 1);
error_reporting(E_ERROR);

$zdir = $dbname;
$zcomp = 1;
$zdbroot = $zdir;
$focusfield = "user";

$addflag = '';


$dbyear = "apps2ai_galaxycargo_1_2526";

$loginerrormsg = "";

if (isset($_POST["submit"])) {
    $udbf = $zdbroot . "passmain";

    $mobile = mysqli_real_escape_string($conn, $_POST['mobile']);
    $pass = mysqli_real_escape_string($conn, $_POST['pass']);

    $login = mysqli_query($conn, "SELECT * FROM $dbyear.`accmast` WHERE `active` = '1' AND `mobile` = '$mobile' AND `pass` = '$pass' ") or die(mysqli_error($conn));

    //    browse(mysqli_num_rows($login));

    $_SESSION["zdbroot"] = $zdbroot;
    $_SESSION["zdir"] = $zdir;

    $_SESSION["zcompany"] = '';

    if (mysqli_num_rows($login) == 1) {
        
        $_SESSION['logged-in'] = true;
         session_regenerate_id(true);
        $getuser_dtl = mysqli_fetch_object($login);

        $_SESSION["usertype"] = $getuser_dtl->usertype;
        $_SESSION["customer_code"] = $getuser_dtl->accode;
        $_SESSION["username_customer"] = $getuser_dtl->name;
        $_SESSION["zdbyear"] = $dbyear;
        
        header("Location: mainmenu.php");
        // exit;
    } else {
        $loginerrormsg = "Mobile or Password is incorrect";
    }
}

?>

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?= $project_title ?></title>
    <style>
        body {
            font-family: 'Poppins', sans-serif;
            background: url("images/galaxycargoship.jpg") no-repeat center center fixed;
            background-size: cover;
            color: #fff;
            margin: 10;
            display: flex;
            justify-content: center;
            align-items: center;
            /* height: 120vh; */
            margin-top: 120px;
        }

        .login-container {
            background: #fff;
            color: #333;
            border-radius: 10px;
            padding: 30px 25px;
            box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
            width: 100%;
            max-width: 400px;
            text-align: center;
            opacity: 0.8;
        }

        .login-container h2 {
            margin-bottom: 20px;
            font-size: 24px;
            color: #0b5475;
        }

        .login-container form {
            display: flex;
            flex-direction: column;
        }

        .login-container form input {
            margin: 10px 0;
            padding: 15px;
            border: 1px solid #ddd;
            border-radius: 8px;
            font-size: 16px;
        }

        .login-container form input:focus {
            border-color: #0b5475;
            outline: none;
            box-shadow: 0 0 5px rgba(11, 84, 117, 0.5);
        }

        .login-container form button {
            padding: 15px;
            margin-top: 10px;
            border: none;
            background: linear-gradient(135deg, #0b5475, #2575fc);
            color: #fff;
            font-size: 16px;
            border-radius: 8px;
            cursor: pointer;
            transition: background 0.3s;
        }

        .login-container form button:hover {
            background: linear-gradient(135deg, #2575fc, #0b5475);
        }

        .login-container p {
            margin-top: 15px;
            font-size: 14px;
        }

        .login-container p a {
            color: #0b5475;
            text-decoration: none;
            font-weight: bold;
        }

        .login-container p a:hover {
            text-decoration: underline;
        }

        h1 {
            color: #0b5475;
        }

        @media (max-width: 480px) {

            .login-container {
                padding: 10px 8px;
            }

            .login-container h2 {
                font-size: 20px;
            }

            .login-container form input,
            .login-container form button {
                font-size: 14px;
                padding: 12px;
            }
        }


        .wrapper {
            background-color: transparent;
        }

        /* Chrome, Safari, Edge, Opera */
        input::-webkit-outer-spin-button,
        input::-webkit-inner-spin-button {
            -webkit-appearance: none;
            margin: 0;
        }

        /* Firefox */
        input[type=number] {
            -moz-appearance: textfield;
        }

        .error-msg {
            color: red;
            font-size: 14px;
            margin-bottom: 10px;
            opacity: 0;
            animation: fadeIn 0.5s ease-in-out forwards;
        }

        @keyframes fadeIn {
            from {
                opacity: 0;
                transform: translateY(-5px);
            }

            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
    </style>
</head>

<body>
    <div class="login-container">
        <div class="wrapper">
            <h1> <?= $project_title ?> </h1>
        </div>
        <?php if (!empty($loginerrormsg)): ?>
            <p class="error-msg"><?= $loginerrormsg ?></p>
        <?php endif; ?>
        <form method="POST">
            <input type="number" name="mobile" placeholder="Mobile No." required autofocus>
            <input type="password" name="pass" placeholder="Password" required>
            <button type="submit" name="submit">Login</button>
        </form>
        <!-- <p>
            Don't have an account? <a href="signup.php">Sign up</a>
        </p> -->
    </div>
</body>

</html>