JezK
Edit File: employees.php
<?php session_start(); require_once 'config/database.php'; require_once 'includes/functions.php'; // Check if user is logged in if (!isset($_SESSION['user_id'])) { header('Location: login.php'); exit(); } $message = ''; $error = ''; // Handle delete action if (isset($_GET['delete']) && isAdmin()) { $id = (int)$_GET['delete']; $sql = "DELETE FROM employees WHERE id = ?"; $stmt = $conn->prepare($sql); $stmt->bind_param("i", $id); if ($stmt->execute()) { $message = 'Employee deleted successfully!'; } else { $error = 'Error deleting employee.'; } } // Get search parameters $search = isset($_GET['search']) ? $_GET['search'] : ''; $status_filter = isset($_GET['status']) ? $_GET['status'] : ''; // Get employees $sql = "SELECT * FROM employees WHERE 1=1"; $params = array(); $types = ""; if (!empty($search)) { $sql .= " AND (employee_id LIKE ? OR full_name LIKE ? OR mobile LIKE ? OR district LIKE ?)"; $searchTerm = "%$search%"; $params[] = $searchTerm; $params[] = $searchTerm; $params[] = $searchTerm; $params[] = $searchTerm; $types .= "ssss"; } if (!empty($status_filter)) { $sql .= " AND status = ?"; $params[] = $status_filter; $types .= "s"; } $sql .= " ORDER BY created_at DESC"; $stmt = $conn->prepare($sql); if (!empty($params)) { $stmt->bind_param($types, ...$params); } $stmt->execute(); $result = $stmt->get_result(); $employees = $result->fetch_all(MYSQLI_ASSOC); $statuses = array( 'active' => 'Active', 'inactive' => 'Inactive', 'terminated' => 'Terminated' ); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Employees - PAYMIND</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.0.0/css/all.min.css" rel="stylesheet"> <link href="assets/css/style.css" rel="stylesheet"> </head> <body> <!-- Navigation --> <nav class="navbar navbar-expand-lg navbar-dark bg-primary"> <div class="container-fluid"> <a class="navbar-brand" href="index.php"> <i class="fas fa-credit-card me-2"></i>PAYMIND </a> <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav"> <span class="navbar-toggler-icon"></span> </button> <div class="collapse navbar-collapse" id="navbarNav"> <ul class="navbar-nav me-auto"> <li class="nav-item"> <a class="nav-link" href="index.php"> <i class="fas fa-tachometer-alt me-1"></i>Dashboard </a> </li> <li class="nav-item"> <a class="nav-link" href="transactions.php"> <i class="fas fa-list me-1"></i>Transactions </a> </li> <li class="nav-item"> <a class="nav-link" href="add_transaction.php"> <i class="fas fa-plus me-1"></i>Add Transaction </a> </li> <li class="nav-item"> <a class="nav-link" href="sellers.php"> <i class="fas fa-users me-1"></i>Sellers </a> </li> <li class="nav-item"> <a class="nav-link active" href="employees.php"> <i class="fas fa-user-tie me-1"></i>Employees </a> </li> <li class="nav-item"> <a class="nav-link" href="attendance.php"> <i class="fas fa-calendar-check me-1"></i>Attendance & Salary </a> </li> <li class="nav-item"> <a class="nav-link" href="expense_tracker.php"> <i class="fas fa-receipt me-1"></i>Expense Tracker </a> </li> <li class="nav-item"> <a class="nav-link" href="reports.php"> <i class="fas fa-chart-bar me-1"></i>Reports </a> </li> <li class="nav-item"> <a class="nav-link" href="reminders.php"> <i class="fas fa-bell me-1"></i>Reminders </a> </li> <li class="nav-item"> <a class="nav-link" href="settings.php"> <i class="fas fa-cog me-1"></i>Settings </a> </li> </ul> <ul class="navbar-nav"> <li class="nav-item dropdown"> <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown"> <i class="fas fa-user me-1"></i><?php echo isset($_SESSION['username']) ? $_SESSION['username'] : 'User'; ?> </a> <ul class="dropdown-menu"> <li><a class="dropdown-item" href="profile.php">Profile</a></li> <li><a class="dropdown-item" href="settings.php">Settings</a></li> <li><hr class="dropdown-divider"></li> <li><a class="dropdown-item" href="logout.php">Logout</a></li> </ul> </li> </ul> </div> </div> </nav> <div class="container-fluid mt-4"> <div class="row"> <div class="col-12"> <div class="d-flex justify-content-between align-items-center mb-4"> <h1 class="h3 mb-0">Employee Management</h1> <a href="add_employee.php" class="btn btn-primary"> <i class="fas fa-plus me-1"></i>Add Employee </a> </div> <?php if ($message): ?> <div class="alert alert-success alert-dismissible fade show" role="alert"> <i class="fas fa-check-circle me-2"></i><?php echo $message; ?> <button type="button" class="btn-close" data-bs-dismiss="alert"></button> </div> <?php endif; ?> <?php if ($error): ?> <div class="alert alert-danger alert-dismissible fade show" role="alert"> <i class="fas fa-exclamation-triangle me-2"></i><?php echo $error; ?> <button type="button" class="btn-close" data-bs-dismiss="alert"></button> </div> <?php endif; ?> <!-- Search and Filter --> <div class="card shadow mb-4"> <div class="card-body"> <form method="GET" action="" class="row g-3"> <div class="col-md-4"> <label for="search" class="form-label">Search</label> <input type="text" class="form-control" id="search" name="search" value="<?php echo htmlspecialchars($search); ?>" placeholder="Employee ID, Name, Mobile, District..."> </div> <div class="col-md-3"> <label for="status" class="form-label">Status</label> <select class="form-select" id="status" name="status"> <option value="">All Status</option> <?php foreach ($statuses as $key => $value): ?> <option value="<?php echo $key; ?>" <?php echo ($status_filter == $key) ? 'selected' : ''; ?>> <?php echo $value; ?> </option> <?php endforeach; ?> </select> </div> <div class="col-md-3 d-flex align-items-end"> <button type="submit" class="btn btn-primary me-2"> <i class="fas fa-search me-1"></i>Search </button> <a href="employees.php" class="btn btn-secondary"> <i class="fas fa-undo me-1"></i>Reset </a> </div> </form> </div> </div> <!-- Employees Table --> <div class="card shadow"> <div class="card-header py-3"> <h6 class="m-0 font-weight-bold text-primary"> <?php echo count($employees); ?> Employee(s) Found </h6> </div> <div class="card-body"> <div class="table-responsive"> <table class="table table-bordered table-hover" width="100%" cellspacing="0"> <thead class="table-dark"> <tr> <th>Employee ID</th> <th>Full Name</th> <th>Mobile</th> <th>District</th> <th>Basic Salary</th> <th>Status</th> <th>Joining Date</th> <th>Actions</th> </tr> </thead> <tbody> <?php if (empty($employees)): ?> <tr> <td colspan="8" class="text-center text-muted py-4"> <i class="fas fa-users fa-2x mb-3"></i> <p>No employees found</p> </td> </tr> <?php else: ?> <?php foreach ($employees as $employee): ?> <tr> <td> <strong><?php echo htmlspecialchars($employee['employee_id']); ?></strong> </td> <td><?php echo htmlspecialchars($employee['full_name']); ?></td> <td><?php echo htmlspecialchars($employee['mobile']); ?></td> <td><?php echo htmlspecialchars($employee['district']); ?></td> <td> <strong class="text-success">₹<?php echo number_format($employee['basic_salary'], 2); ?></strong> <small class="text-muted d-block">Monthly</small> </td> <td> <span class="badge bg-<?php echo getEmployeeStatusColor($employee['status']); ?>"> <?php echo ucfirst($employee['status']); ?> </span> </td> <td><?php echo date('d M Y', strtotime($employee['joining_date'])); ?></td> <td> <div class="btn-group" role="group"> <a href="view_employee.php?id=<?php echo $employee['id']; ?>" class="btn btn-sm btn-info" title="View"> <i class="fas fa-eye"></i> </a> <a href="edit_employee.php?id=<?php echo $employee['id']; ?>" class="btn btn-sm btn-warning" title="Edit"> <i class="fas fa-edit"></i> </a> <a href="attendance.php?employee_id=<?php echo $employee['id']; ?>" class="btn btn-sm btn-success" title="Attendance"> <i class="fas fa-calendar-check"></i> </a> <?php if (isAdmin()): ?> <a href="?delete=<?php echo $employee['id']; ?>" class="btn btn-sm btn-danger" title="Delete" onclick="return confirm('Are you sure you want to delete this employee?')"> <i class="fas fa-trash"></i> </a> <?php endif; ?> </div> </td> </tr> <?php endforeach; ?> <?php endif; ?> </tbody> </table> </div> </div> </div> </div> </div> </div> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script> </body> </html>