Mini Kabibi Habibi

Current Path : C:/xampp/htdocs/dcp_inventory/
Upload File :
Current File : C:/xampp/htdocs/dcp_inventory/index.php

<?php
session_start();  // Start the session to manage user state
include('db_connection.php');  // Include your DB connection

// Check if the form is submitted
if (isset($_POST['login'])) {
    $username = $_POST['username'];
    $password = $_POST['password'];

    // Query to check if the user exists with the given username and password
    $query = "SELECT * FROM users WHERE username='$username' AND password='$password'";  // In production, use password_hash() and password_verify() for secure authentication
    $result = mysqli_query($conn, $query);
    $user = mysqli_fetch_assoc($result);

    // If the user exists and the credentials are correct
    if ($user) {
        // Store session variables
        $_SESSION['username'] = $user['username'];  // Store the username in session
        $_SESSION['role'] = $user['role'];          // Store the role (admin or school user)
        $_SESSION['school_id'] = $user['school_id']; // Store the school ID associated with the user

        // Redirect based on role
        if ($user['role'] == 'admin') {
            header("Location: admin_dashboard.php");
        } else {
            // Redirect to school dashboard
            header("Location: school_dashboard.php");
        }
        exit();  // Make sure to call exit after header() to prevent further code execution
    } else {
        // Display error message if login fails
        echo "<script>alert('Invalid login credentials.');</script>";
    }
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Login - DCP Inventory Management System</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f4;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
        }

        .container {
            background-color: white;
            padding: 30px;
            border-radius: 10px;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
            width: 300px;
            text-align: center;
            display: flex;
            flex-direction: column;
            justify-content: space-between;
            min-height: 450px;
        }

        .container h2 {
            margin-bottom: 20px;
            font-size: 24px;
        }

        .dcp-system-section {
            margin-top: 20px;
            font-size: 18px;
            padding-top: 20px;
            border-top: 2px solid #eee;
        }

        .dcp-system-section h3 {
            margin-bottom: 15px;
            color: #333;
        }

        .dcp-system-section p {
            color: #666;
            font-size: 12px;
        }

        .login-container {
            margin-top: 4px;
            flex-grow: 1;
        }

        .login-container input[type="text"],
        .login-container input[type="password"] {
            width: 90%;
            padding: 10px;
            margin: 10px 0;
            border: 1px solid #ccc;
            border-radius: 5px;
        }

        .login-container button {
            width: 100%;
            padding: 10px;
            background-color: #007BFF;
            color: white;
            border: none;
            border-radius: 5px;
            font-size: 16px;
        }

        .login-container button:hover {
            background-color: #0056b3;
            cursor: pointer;
        }

        /* Adjust logo size and margin */
        .container img {
            width: 80%; /* Adjust the width to a smaller size */
            max-width: 80px; /* Set a max width for the logo */
            margin-top: 10px; /* Reduced the top margin to bring the logo closer */
            display: block;
            margin-left: auto;
            margin-right: auto;
        }
    </style>
</head>
<body>

<div class="container">
    <img src="image/sdologo.png" alt="Logo">
    <!-- DCP Inventory Management System Section -->
    <div class="dcp-system-section">
        <h3>DCP Inventory Management and Monitoring System</h3>
        <p>Welcome to the DCP Inventory Management System of SDO Batangas City. This system helps you manage the inventory of DCP packages delivered to the schools and monitor the current status.</p>
    </div>

    <!-- Login Form Section -->
    <div class="login-container">
        <form method="post" action="">
            <input type="text" name="username" placeholder="Username" required>
            <input type="password" name="password" placeholder="Password" required>
            <button type="submit" name="login">Login</button>
        </form>
    </div>
</div>

</body>
</html>