diff --git a/add_employee.php b/add_employee.php new file mode 100644 index 0000000..5812fb5 --- /dev/null +++ b/add_employee.php @@ -0,0 +1,157 @@ +prepare($sql)) { + $stmt->bindParam(':username', trim($_POST['username']), PDO::PARAM_STR); + if ($stmt->execute()) { + if ($stmt->rowCount() == 1) { + $username_err = 'This username is already taken.'; + } else { + $username = trim($_POST['username']); + } + } else { + echo 'Oops! Something went wrong. Please try again later.'; + } + unset($stmt); + } + } + + // Validate password + if (empty(trim($_POST['password']))) { + $password_err = 'Please enter a password.'; + } elseif (strlen(trim($_POST['password'])) < 6) { + $password_err = 'Password must have at least 6 characters.'; + } else { + $password = trim($_POST['password']); + } + + // Validate role + if (empty($_POST['role'])) { + $role_err = 'Please select a role.'; + } else { + $role = $_POST['role']; + } + + // Check input errors before inserting in database + if (empty($username_err) && empty($password_err) && empty($role_err)) { + $sql = 'INSERT INTO users (username, password, role) VALUES (:username, :password, :role)'; + + if ($stmt = db()->prepare($sql)) { + $stmt->bindParam(':username', $username, PDO::PARAM_STR); + $stmt->bindParam(':password', $hashed_password, PDO::PARAM_STR); + $stmt->bindParam(':role', $role, PDO::PARAM_STR); + + // Hash password + $hashed_password = password_hash($password, PASSWORD_DEFAULT); + + if ($stmt->execute()) { + $success_msg = 'Employee added successfully!'; + // Clear form fields + $username = $password = $role = ''; + } else { + echo 'Oops! Something went wrong. Please try again later.'; + } + unset($stmt); + } + } +} +?> + + + + + + + Add Employee - Employee Attendance System + + + + + + + + + + + +
+
+

Add New Employee

+

Fill out the form to add a new employee to the system.

+ + +
+ + +
" method="post" class="mt-4 card p-4 bg-white border-0 shadow-sm"> +
+ + + +
+
+ + + +
+
+ + + +
+
+ +
+
+
+
+ + + + diff --git a/assets/css/custom.css b/assets/css/custom.css new file mode 100644 index 0000000..82af728 --- /dev/null +++ b/assets/css/custom.css @@ -0,0 +1,43 @@ +body { + font-family: 'Inter', sans-serif; + background-color: #F3F4F6; +} + +.login-body { + background-image: linear-gradient(to right, #3B82F6, #1E40AF); +} + +.card-header { + border-bottom: 0; +} + +.form-control:focus { + box-shadow: 0 0 0 0.25rem rgba(59, 130, 246, 0.25); + border-color: #3B82F6; +} + +.sidebar { + position: fixed; + top: 0; + left: 0; + bottom: 0; + width: 250px; + padding: 20px; + background-color: #1F2937; + color: #fff; +} + +.sidebar .nav-link { + color: #D1D5DB; + font-weight: 500; +} + +.sidebar .nav-link:hover, .sidebar .nav-link.active { + color: #fff; + background-color: #374151; +} + +.main-content { + margin-left: 250px; + padding: 20px; +} diff --git a/attendance_report.php b/attendance_report.php new file mode 100644 index 0000000..10cbe4a --- /dev/null +++ b/attendance_report.php @@ -0,0 +1,111 @@ +prepare($sql); +$stmt->execute($params); +$attendance_records = $stmt->fetchAll(); +?> + +
+
+

This is the Attendance Report Page

+
+ +
+
+
Filter by Date
+
+
+
+
+
+
+ + +
+
+
+
+ + +
+
+
+ +
+
+
+ +
+
+
Attendance Records
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
Employee NameStatusDateCheck-in TimeCheck-out Time
No records found for this date.
+
+
+
+
+ + diff --git a/auth.php b/auth.php new file mode 100644 index 0000000..ab983cd --- /dev/null +++ b/auth.php @@ -0,0 +1,40 @@ +prepare("SELECT * FROM users WHERE username = ?"); + $stmt->execute([$username]); + $user = $stmt->fetch(); + + if ($user) { + if (password_verify($password, $user['password'])) { + $_SESSION['loggedin'] = true; + $_SESSION['id'] = $user['id']; + $_SESSION['username'] = $user['username']; + $_SESSION['role'] = $user['role']; + header("location: index.php"); + exit; + } else { + $_SESSION['error'] = "Invalid username or password."; + header("location: login.php"); + exit; + } + } else { + $_SESSION['error'] = "Invalid username or password."; + header("location: login.php"); + exit; + } +} else { +} +?> \ No newline at end of file diff --git a/db/config.php b/db/config.php index 3fc1d00..ba93231 100644 --- a/db/config.php +++ b/db/config.php @@ -15,3 +15,23 @@ function db() { } return $pdo; } + +function init_db() { + $pdo = db(); + $pdo->exec("CREATE TABLE IF NOT EXISTS users ( + id INT AUTO_INCREMENT PRIMARY KEY, + username VARCHAR(50) NOT NULL UNIQUE, + password VARCHAR(255) NOT NULL, + role ENUM('Admin', 'HR', 'Employee', 'Supervisor') NOT NULL + );"); + + $stmt = $pdo->prepare("SELECT * FROM users WHERE username = ?"); + $stmt->execute(['admin']); + if ($stmt->rowCount() == 0) { + $password = password_hash('password', PASSWORD_DEFAULT); + $stmt = $pdo->prepare("INSERT INTO users (username, password, role) VALUES (?, ?, ?)"); + $stmt->execute(['admin', $password, 'Admin']); + } +} + +init_db(); diff --git a/db/migrate_leave_requests.php b/db/migrate_leave_requests.php new file mode 100644 index 0000000..6fa3dcf --- /dev/null +++ b/db/migrate_leave_requests.php @@ -0,0 +1,21 @@ +exec($sql); + echo "Table 'leave_requests' created successfully." . PHP_EOL; +} catch (PDOException $e) { + die("Error creating table: " . $e->getMessage()); +} +?> \ No newline at end of file diff --git a/delete_employee.php b/delete_employee.php new file mode 100644 index 0000000..c838dd5 --- /dev/null +++ b/delete_employee.php @@ -0,0 +1,22 @@ +prepare("DELETE FROM users WHERE id = ?"); +$stmt->execute([$id]); + +header('location: view_employees.php'); +exit; +?> \ No newline at end of file diff --git a/edit_employee.php b/edit_employee.php new file mode 100644 index 0000000..9133124 --- /dev/null +++ b/edit_employee.php @@ -0,0 +1,79 @@ +prepare("SELECT * FROM users WHERE id = ?"); +$stmt->execute([$id]); +$user = $stmt->fetch(PDO::FETCH_ASSOC); + +if (!$user) { + die('User not found.'); +} + +if ($_SERVER['REQUEST_METHOD'] == 'POST') { + $username = $_POST['username']; + $role = $_POST['role']; + + $updateStmt = $pdo->prepare("UPDATE users SET username = ?, role = ? WHERE id = ?"); + $updateStmt->execute([$username, $role, $id]); + + header('location: view_employees.php'); + exit; +} + +?> + + + + + + Edit Employee - Employee Attendance System + + + + + + + + +
+
+

Edit Employee

+ +
+
+
+
+ + +
+
+ + +
+ +
+
+
+
+
+ + + + \ No newline at end of file diff --git a/get_leave_events.php b/get_leave_events.php new file mode 100644 index 0000000..4b5eb86 --- /dev/null +++ b/get_leave_events.php @@ -0,0 +1,46 @@ +prepare($sql); + + if ($_SESSION['role'] == 'Employee') { + $stmt->bindParam(':employee_id', $_SESSION['id'], PDO::PARAM_INT); + } + + $stmt->execute(); + $events = $stmt->fetchAll(PDO::FETCH_ASSOC); + + // Adjust end date for FullCalendar + foreach ($events as &$event) { + $event['end'] = date('Y-m-d', strtotime($event['end'] . ' +1 day')); + } + +} catch (PDOException $e) { + // On error, return empty array + echo json_encode([]); + exit; +} + +echo json_encode($events); +?> \ No newline at end of file diff --git a/index.php b/index.php index 7205f3d..91f2d7f 100644 --- a/index.php +++ b/index.php @@ -1,150 +1,159 @@ -query('SELECT COUNT(*) FROM users'); +$total_employees = $stmt_total->fetchColumn(); + +// Fetch attendance stats for today +$stmt_attendance = $pdo->prepare("SELECT status, COUNT(*) as count FROM attendance WHERE attendance_date = ? GROUP BY status"); +$stmt_attendance->execute([$today]); +$attendance_stats = $stmt_attendance->fetchAll(PDO::FETCH_KEY_PAIR); + +$on_time_today = $attendance_stats['Present'] ?? 0; +$late_today = $attendance_stats['Late'] ?? 0; +$absent_today = $attendance_stats['Absent'] ?? 0; + +// Fetch pending leave requests for Admin/HR +$pending_leave_requests = 0; +if (in_array($_SESSION['role'], ['Admin', 'HR'])) { + $stmt_leave = $pdo->query("SELECT COUNT(*) FROM leave_requests WHERE status = 'pending'"); + $pending_leave_requests = $stmt_leave->fetchColumn(); +} + ?> - + - - - New Style - - - - - - - - - - - - - - - - - - - + + + Dashboard - Employee Attendance System + + + + + + - -
-
-

Analyzing your requirements and generating your website…

-
- Loading… -
-

AI is collecting your requirements and applying the first changes.

-

This page will update automatically as the plan is implemented.

-

Runtime: PHP — UTC

+ + +
+ + +
+
+
+

Dashboard

+

Welcome, !

+
+ +
+ +
+
+
+
+
+
Total Employees
+
+
+
+ +
+
+
+
+
+ + +
+
+
+
+
+
On Time Today
+
+
+
+ +
+
+
+
+
+ + +
+
+
+
+
+
Late Today
+
+
+
+ +
+
+
+
+
+ + +
+
+
+
+
+
Absent Today
+
+
+
+ +
+
+
+
+
+
+ + + + +

From here you can manage employees, track attendance, and generate reports.

+
-
- + + + + diff --git a/leave_requests.php b/leave_requests.php new file mode 100644 index 0000000..ebd310f --- /dev/null +++ b/leave_requests.php @@ -0,0 +1,230 @@ +prepare($sql); + + if ($_SESSION['role'] == 'Employee') { + $stmt->bindParam(':employee_id', $_SESSION['id'], PDO::PARAM_INT); + } + + $stmt->execute(); + $requests = $stmt->fetchAll(PDO::FETCH_ASSOC); +} catch (PDOException $e) { + die("Could not fetch leave requests."); +} + +?> + + + + + + Leave Requests - Employee Attendance System + + + + + + + +
+
+
+

Leave Requests

+
+ Submit New Request + +
+
+

Manage and view employee leave requests.

+ +

You are viewing all employee leave requests.

+ +

You are viewing your own leave requests.

+ + +
+ +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
EmployeeStart DateEnd DateReasonStatusActions
No leave requests found.
+ + + + + + + + + + + + Approve + + Reject + + + +
+ +
+ +
+ +
+ +
+ + + + + + + + + + + + diff --git a/login.php b/login.php new file mode 100644 index 0000000..9e2a4a6 --- /dev/null +++ b/login.php @@ -0,0 +1,60 @@ + + + + + + + Login - Employee Attendance System + + + + + + + + +
+
+
+
+
+

Employee Attendance System

+
+
+
+ +
+ +
+ + +
+
+ + +
+
+ +
+
+
+
+
+
+
+ + + diff --git a/logout.php b/logout.php new file mode 100644 index 0000000..25a9a09 --- /dev/null +++ b/logout.php @@ -0,0 +1,7 @@ + \ No newline at end of file diff --git a/mark_attendance.php b/mark_attendance.php new file mode 100644 index 0000000..dfdccfd --- /dev/null +++ b/mark_attendance.php @@ -0,0 +1,102 @@ +prepare("SELECT id FROM attendance WHERE employee_id = ? AND date = ?"); + $stmt->execute([$employee_id, $current_date]); + $attendance_record = $stmt->fetch(); + + if ($attendance_record) { + $stmt = db()->prepare("UPDATE attendance SET check_in_time = ?, status = 'Present' WHERE id = ?"); + $stmt->execute([$current_time, $attendance_record['id']]); + } else { + $stmt = db()->prepare("INSERT INTO attendance (employee_id, date, status, check_in_time) VALUES (?, ?, 'Present', ?)"); + $stmt->execute([$employee_id, $current_date, $current_time]); + } + } elseif ($action === 'check-out') { + $stmt = db()->prepare("UPDATE attendance SET check_out_time = ? WHERE employee_id = ? AND date = ?"); + $stmt->execute([$current_time, $employee_id, $current_date]); + } + + header('Location: mark_attendance.php'); + exit(); +} + + +// Only allow Admin and HR to access this page +if (!isset($_SESSION['user_role']) || ($_SESSION['user_role'] !== 'Admin' && $_SESSION['user_role'] !== 'HR')) { + header('Location: index.php'); + exit(); +} + +$pdo = db(); +$today = date('Y-m-d'); + +// Fetch all employees (users) +$stmt = $pdo->prepare('SELECT id, username, role FROM users ORDER BY username'); +$stmt->execute(); +$employees = $stmt->fetchAll(PDO::FETCH_ASSOC); + +?> + + + + + + Mark Attendance + + + + + +
+ +
+
+
+

Mark Daily Attendance

+
+
+ + + + + + + + + + + + + + + + + +
Employee NameRoleActions
+
+ + +
+
+ + +
+
+
+ +
+
+
+
+ + + diff --git a/profile.php b/profile.php new file mode 100644 index 0000000..fc88a92 --- /dev/null +++ b/profile.php @@ -0,0 +1,70 @@ +prepare("SELECT * FROM users WHERE username = ?"); +$stmt->execute([$username]); +$user = $stmt->fetch(); + +// Fetch user attendance +$stmt = db()->prepare("SELECT attendance_date, status FROM attendance WHERE user_id = ? ORDER BY attendance_date DESC"); +$stmt->execute([$user['id']]); +$attendance_records = $stmt->fetchAll(); + +?> + + + + Employee Profile + + + + +
+ +
+

Employee Profile

+
+
+
Profile Details
+

Name:

+

Username:

+

Role:

+
+
+ +
+
+
Attendance History
+ + + + + + + + + + + + + + + + + + + + +
DateStatus
No attendance records found.
+
+
+
+
+ + diff --git a/sidebar.php b/sidebar.php new file mode 100644 index 0000000..9335ba5 --- /dev/null +++ b/sidebar.php @@ -0,0 +1,35 @@ + + diff --git a/submit_leave_request.php b/submit_leave_request.php new file mode 100644 index 0000000..974d88e --- /dev/null +++ b/submit_leave_request.php @@ -0,0 +1,119 @@ +prepare($sql)) { + $stmt->bindParam(':employee_id', $_SESSION['id'], PDO::PARAM_INT); + $stmt->bindParam(':start_date', $start_date, PDO::PARAM_STR); + $stmt->bindParam(':end_date', $end_date, PDO::PARAM_STR); + $stmt->bindParam(':reason', $reason, PDO::PARAM_STR); + + if ($stmt->execute()) { + $success_msg = 'Leave request submitted successfully!'; + + // Send email notification to Admins and HR + require_once 'mail/MailService.php'; + $sql_users = "SELECT username FROM users WHERE role = 'Admin' OR role = 'HR'"; + $stmt_users = db()->query($sql_users); + $recipients = $stmt_users->fetchAll(PDO::FETCH_COLUMN); + + if (!empty($recipients)) { + $subject = "New Leave Request Submitted"; + $body = "A new leave request has been submitted by {$_SESSION['username']}.

" + . "Start Date: {$start_date}
" + . "End Date: {$end_date}
" + . "Reason: {$reason}

" + . "Please log in to the system to approve or reject this request."; + MailService::sendMail($recipients, $subject, $body, strip_tags($body)); + } + + $start_date = $end_date = $reason = ''; + } else { + echo 'Oops! Something went wrong. Please try again later.'; + } + unset($stmt); + } + } +} + +?> + + + + + + Submit Leave Request - Employee Attendance System + + + + + + +
+
+

Submit Leave Request

+

Fill out the form to request time off.

+ + +
+ + +
" method="post" class="mt-4 card p-4 bg-white border-0 shadow-sm"> +
+ + + +
+
+ + + +
+
+ + + +
+
+ +
+
+
+
+ + + + diff --git a/update_leave_status.php b/update_leave_status.php new file mode 100644 index 0000000..6576cde --- /dev/null +++ b/update_leave_status.php @@ -0,0 +1,42 @@ +prepare($sql)) { + $stmt->bindParam(':status', $status, PDO::PARAM_STR); + $stmt->bindParam(':id', $id, PDO::PARAM_INT); + if ($stmt->execute()) { + // Send email notification to the employee + require_once 'mail/MailService.php'; + $sql_request = "SELECT lr.start_date, lr.end_date, u.username FROM leave_requests lr JOIN users u ON lr.employee_id = u.id WHERE lr.id = :id"; + $stmt_request = db()->prepare($sql_request); + $stmt_request->bindParam(':id', $id, PDO::PARAM_INT); + $stmt_request->execute(); + $request_data = $stmt_request->fetch(PDO::FETCH_ASSOC); + + if ($request_data) { + $to = $request_data['username']; + $subject = "Your Leave Request has been " . ucfirst($status); + $body = "Your leave request from {$request_data['start_date']} to {$request_data['end_date']} has been {$status}.

" + . "Log in to the system for more details."; + MailService::sendMail($to, $subject, $body, strip_tags($body)); + } + } + } + } +} + +header('location: leave_requests.php'); +exit; +?> \ No newline at end of file diff --git a/view_employees.php b/view_employees.php new file mode 100644 index 0000000..6b185fa --- /dev/null +++ b/view_employees.php @@ -0,0 +1,103 @@ +query("SELECT id, username, role FROM users ORDER BY id DESC"); + $users = $stmt->fetchAll(PDO::FETCH_ASSOC); +} catch (PDOException $e) { + // For a real app, you'd want to log this error + die("Could not connect to the database or fetch users."); +} + +?> + + + + + + View Employees - Employee Attendance System + + + + + + + + + + + +
+
+

View Employees

+

A list of all users in the system.

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + +
IDUsernameRoleActions
No users found.
+ + +
+
+
+
+
+ + + +