<?php
require_once 'config.php';
// หาก Login อยู่แล้วให้เด้งไปหน้า Dashboard ทันที
if(isset($_SESSION['u_id'])){
if($_SESSION['type'] == 'admin') header("Location: admin_dashboard.php");
else header("Location: user_dashboard.php");
exit();
}
?>
<!DOCTYPE html>
<html lang="th">
<head>
<meta charset="UTF-8">
<title>เข้าสู่ระบบ | ระบบลงเวลาปฏิบัติงาน</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
<style>
body { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); height: 100vh; display: flex; align-items: center; font-family: 'Sarabun', sans-serif; }
.login-card { border: none; border-radius: 20px; box-shadow: 0 10px 30px rgba(0,0,0,0.2); overflow: hidden; }
.login-header { background: #fff; padding: 30px; text-align: center; }
.btn-login { background: #764ba2; border: none; padding: 12px; border-radius: 10px; font-weight: 600; transition: 0.3s; }
.btn-login:hover { background: #5a377d; transform: translateY(-2px); }
</style>
</head>
<body>
<div class="container">
<div class="row justify-content-center">
<div class="col-md-5">
<div class="card login-card">
<div class="login-header">
<i class="fas fa-clock fa-3x text-primary mb-3"></i>
<h4 class="fw-bold">ระบบลงเวลาปฏิบัติงาน สพป.กำแพงเพชร เขต 2</h4>
<p class="text-muted">กรุณาเข้าสู่ระบบเพื่อใช้งาน</p>
</div>
<div class="card-body p-4">
<?php if(isset($_GET['error'])): ?>
<div class="alert alert-danger border-0 small">
<i class="fas fa-exclamation-circle me-2"></i>ชื่อผู้ใช้หรือรหัสผ่านไม่ถูกต้อง
</div>
<?php endif; ?>
<form action="process.php" method="post">
<input type="hidden" name="action" value="login">
<div class="mb-3">
<label class="form-label">ชื่อผู้ใช้งาน (Username)</label>
<div class="input-group">
<span class="input-group-text bg-light border-0"><i class="fas fa-user text-muted"></i></span>
<input type="text" name="username" class="form-control bg-light border-0" placeholder="Username" required>
</div>
</div>
<div class="mb-4">
<label class="form-label">รหัสผ่าน (Password)</label>
<div class="input-group">
<span class="input-group-text bg-light border-0"><i class="fas fa-lock text-muted"></i></span>
<input type="password" name="password" class="form-control bg-light border-0" placeholder="Password" required>
</div>
</div>
<button type="submit" class="btn btn-primary btn-login w-100 text-white">เข้าสู่ระบบ</button>
</form>
</div>
<div class="card-footer bg-white border-0 text-center pb-4">
<small class="text-muted">© 2026 จัดทำโดย นายชาคริต ราชนิธยากร ผู้อำนวยการกลุ่ม DLICT สพม.ราชบุรี</small>
</div>
</div>
</div>
</div>
</div>
</body>
</html>