352 lines
17 KiB
PHP
352 lines
17 KiB
PHP
<?php
|
|
require_once 'auth.php';
|
|
|
|
// Check if user is logged in
|
|
if (!is_logged_in()) {
|
|
header('Location: login.php');
|
|
exit;
|
|
}
|
|
|
|
require_once 'db/config.php';
|
|
$pdo = db();
|
|
|
|
|
|
|
|
// Pagination for Candidates
|
|
$candidate_page = isset($_GET['candidate_page']) ? (int)$_GET['candidate_page'] : 1;
|
|
$limit = 5;
|
|
$candidate_offset = ($candidate_page - 1) * $limit;
|
|
|
|
$stmt = $pdo->prepare("SELECT * FROM candidates LIMIT :limit OFFSET :offset");
|
|
$stmt->bindParam(':limit', $limit, PDO::PARAM_INT);
|
|
$stmt->bindParam(':offset', $candidate_offset, PDO::PARAM_INT);
|
|
$stmt->execute();
|
|
$candidates = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
$stmt = $pdo->query("SELECT COUNT(*) FROM candidates");
|
|
$total_candidates_records = $stmt->fetchColumn();
|
|
$total_candidate_pages = ceil($total_candidates_records / $limit);
|
|
|
|
// Pagination for Tasks
|
|
$task_page = isset($_GET['task_page']) ? (int)$_GET['task_page'] : 1;
|
|
$task_offset = ($task_page - 1) * $limit;
|
|
|
|
$stmt = $pdo->prepare("SELECT * FROM tasks LIMIT :limit OFFSET :offset");
|
|
$stmt->bindParam(':limit', $limit, PDO::PARAM_INT);
|
|
$stmt->bindParam(':offset', $task_offset, PDO::PARAM_INT);
|
|
$stmt->execute();
|
|
$tasks = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
$stmt = $pdo->query("SELECT COUNT(*) FROM tasks");
|
|
$total_tasks_records = $stmt->fetchColumn();
|
|
$total_task_pages = ceil($total_tasks_records / $limit);
|
|
|
|
// Handle form submissions for adding candidates and tasks
|
|
$message = '';
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
if (isset($_POST['add_candidate'])) {
|
|
$name = $_POST['name'];
|
|
$email = $_POST['email'];
|
|
$status = $_POST['status'];
|
|
|
|
$stmt = $pdo->prepare("INSERT INTO candidates (name, email, status) VALUES (:name, :email, :status)");
|
|
$stmt->execute(['name' => $name, 'email' => $email, 'status' => $status]);
|
|
$message = 'Candidate added successfully!';
|
|
}
|
|
|
|
if (isset($_POST['add_task'])) {
|
|
$title = $_POST['title'];
|
|
$status = $_POST['status'];
|
|
$assigned_to = $_POST['assigned_to'];
|
|
|
|
$stmt = $pdo->prepare("INSERT INTO tasks (title, status, assigned_to) VALUES (:title, :status, :assigned_to)");
|
|
$stmt->execute(['title' => $title, 'status' => $status, 'assigned_to' => $assigned_to]);
|
|
$message = 'Task added successfully!';
|
|
}
|
|
// Redirect to the same page to avoid form resubmission
|
|
header("Location: dashboard.php?tab=" . (isset($_POST['add_candidate']) ? 'candidates' : 'tasks'));
|
|
exit;
|
|
}
|
|
|
|
// Fetch data for overview
|
|
$total_candidates = $pdo->query("SELECT COUNT(*) FROM candidates")->fetchColumn();
|
|
$total_tasks = $pdo->query("SELECT COUNT(*) FROM tasks")->fetchColumn();
|
|
$completed_tasks = $pdo->query("SELECT COUNT(*) FROM tasks WHERE status = 'Completed'")->fetchColumn();
|
|
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Dashboard</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
|
</head>
|
|
<body>
|
|
<header class="header d-flex justify-content-between align-items-center">
|
|
<div class="logo">
|
|
<a href="app.php">
|
|
<img src="assets/pasted-20251120-051320-b2b0cdfa.png" alt="FinMox Logo" style="height: 32px;">
|
|
</a>
|
|
</div>
|
|
<nav class="d-flex align-items-center">
|
|
<a href="app.php" class="btn btn-outline-primary me-2">Home</a>
|
|
<a href="workflows.php" class="btn btn-outline-primary me-2">Workflows</a>
|
|
<a href="settings.php" class="btn btn-outline-primary me-3">Settings</a>
|
|
<div class="dropdown">
|
|
<button class="btn btn-outline-secondary dropdown-toggle" type="button" id="userDropdown" data-bs-toggle="dropdown" aria-expanded="false">
|
|
<?php echo htmlspecialchars($_SESSION['username']); ?>
|
|
</button>
|
|
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="userDropdown">
|
|
<li><a class="dropdown-item" href="roles.php">Manage Roles</a></li>
|
|
<li><hr class="dropdown-divider"></li>
|
|
<li><a class="dropdown-item" href="logout.php">Logout</a></li>
|
|
</ul>
|
|
</div>
|
|
</nav>
|
|
</header>
|
|
|
|
<main class="container-fluid mt-4">
|
|
<h2 class="mb-4">Dashboard</h2>
|
|
|
|
<?php if ($message): ?>
|
|
<div class="alert alert-success"><?php echo $message; ?></div>
|
|
<?php endif; ?>
|
|
|
|
<!-- Nav tabs -->
|
|
<ul class="nav nav-tabs" id="dashboardTab" role="tablist">
|
|
<li class="nav-item" role="presentation">
|
|
<button class="nav-link active" id="overview-tab" data-bs-toggle="tab" data-bs-target="#overview" type="button" role="tab" aria-controls="overview" aria-selected="true">Overview</button>
|
|
</li>
|
|
<?php if (hasPermission('view_candidates')) { ?>
|
|
<li class="nav-item" role="presentation">
|
|
<button class="nav-link" id="candidates-tab" data-bs-toggle="tab" data-bs-target="#candidates" type="button" role="tab" aria-controls="candidates" aria-selected="false">Candidates</button>
|
|
</li>
|
|
<?php } ?>
|
|
<?php if (hasPermission('view_tasks')) { ?>
|
|
<li class="nav-item" role="presentation">
|
|
<button class="nav-link" id="tasks-tab" data-bs-toggle="tab" data-bs-target="#tasks" type="button" role="tab" aria-controls="tasks" aria-selected="false">Tasks</button>
|
|
</li>
|
|
<?php } ?>
|
|
</ul>
|
|
|
|
<!-- Tab content -->
|
|
<div class="tab-content" id="dashboardTabContent">
|
|
<!-- Overview Tab -->
|
|
<div class="tab-pane fade show active" id="overview" role="tabpanel" aria-labelledby="overview-tab">
|
|
<div class="row mb-4 mt-4">
|
|
<div class="col-md-4">
|
|
<div class="card text-center shadow-sm">
|
|
<div class="card-body">
|
|
<h5 class="card-title">Total Candidates</h5>
|
|
<p class="card-text fs-4"><?php echo $total_candidates; ?></p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-4">
|
|
<div class="card text-center shadow-sm">
|
|
<div class="card-body">
|
|
<h5 class="card-title">Total Tasks</h5>
|
|
<p class="card-text fs-4"><?php echo $total_tasks; ?></p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-4">
|
|
<div class="card text-center shadow-sm">
|
|
<div class="card-body">
|
|
<h5 class="card-title">Completed Tasks</h5>
|
|
<p class="card-text fs-4"><?php echo $completed_tasks; ?></p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Candidates Tab -->
|
|
<div class="tab-pane fade" id="candidates" role="tabpanel" aria-labelledby="candidates-tab">
|
|
<div class="card shadow-sm mt-4">
|
|
<div class="card-body">
|
|
<div class="d-flex justify-content-between align-items-center mb-3">
|
|
<h5 class="card-title">Candidates</h5>
|
|
<button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addCandidateModal">Add Candidate</button>
|
|
</div>
|
|
<div class="table-responsive">
|
|
<table class="table table-striped">
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Email</th>
|
|
<th>Status</th>
|
|
<th>Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($candidates as $candidate) { ?>
|
|
<tr>
|
|
<td><?php echo htmlspecialchars($candidate['name']); ?></td>
|
|
<td><?php echo htmlspecialchars($candidate['email']); ?></td>
|
|
<td><span class="badge bg-secondary"><?php echo htmlspecialchars($candidate['status']); ?></span></td>
|
|
<td>
|
|
<a href="edit_candidate.php?id=<?php echo $candidate['id']; ?>" class="btn btn-sm btn-outline-primary">Edit</a>
|
|
<a href="delete_candidate.php?id=<?php echo $candidate['id']; ?>" class="btn btn-sm btn-outline-danger" onclick="return confirm('Are you sure?')">Delete</a>
|
|
</td>
|
|
</tr>
|
|
<?php } ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<nav>
|
|
<ul class="pagination">
|
|
<?php for ($i = 1; $i <= $total_candidate_pages; $i++) { ?>
|
|
<li class="page-item <?php if ($i == $candidate_page) echo 'active'; ?>"><a class="page-link" href="?candidate_page=<?php echo $i; ?>&tab=candidates"><?php echo $i; ?></a></li>
|
|
<?php } ?>
|
|
</ul>
|
|
</nav>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Tasks Tab -->
|
|
<div class="tab-pane fade" id="tasks" role="tabpanel" aria-labelledby="tasks-tab">
|
|
<div class="card shadow-sm mt-4">
|
|
<div class="card-body">
|
|
<div class="d-flex justify-content-between align-items-center mb-3">
|
|
<h5 class="card-title">Tasks</h5>
|
|
<button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addTaskModal">Add Task</button>
|
|
</div>
|
|
<div class="table-responsive">
|
|
<table class="table table-striped">
|
|
<thead>
|
|
<tr>
|
|
<th>Title</th>
|
|
<th>Status</th>
|
|
<th>Assigned To</th>
|
|
<th>Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($tasks as $task) { ?>
|
|
<tr>
|
|
<td><?php echo htmlspecialchars($task['title']); ?></td>
|
|
<td><span class="badge bg-info"><?php echo htmlspecialchars($task['status']); ?></span></td>
|
|
<td><?php echo htmlspecialchars($task['assigned_to'] ?? 'N/A'); ?></td>
|
|
<td>
|
|
<a href="edit_task.php?id=<?php echo $task['id']; ?>" class="btn btn-sm btn-outline-primary">Edit</a>
|
|
<a href="delete_task.php?id=<?php echo $task['id']; ?>" class="btn btn-sm btn-outline-danger" onclick="return confirm('Are you sure?')">Delete</a>
|
|
</td>
|
|
</tr>
|
|
<?php } ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<nav>
|
|
<ul class="pagination">
|
|
<?php for ($i = 1; $i <= $total_task_pages; $i++) { ?>
|
|
<li class="page-item <?php if ($i == $task_page) echo 'active'; ?>"><a class="page-link" href="?task_page=<?php echo $i; ?>&tab=tasks"><?php echo $i; ?></a></li>
|
|
<?php } ?>
|
|
</ul>
|
|
</nav>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</main>
|
|
|
|
<!-- Add Candidate Modal -->
|
|
<div class="modal fade" id="addCandidateModal" tabindex="-1" aria-labelledby="addCandidateModalLabel" aria-hidden="true">
|
|
<div class="modal-dialog">
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<h5 class="modal-title" id="addCandidateModalLabel">Add New Candidate</h5>
|
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
|
</div>
|
|
<div class="modal-body">
|
|
<form method="POST" action="dashboard.php">
|
|
<input type="hidden" name="add_candidate" value="1">
|
|
<div class="mb-3">
|
|
<label for="name" class="form-label">Name</label>
|
|
<input type="text" class="form-control" id="name" name="name" required>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="email" class="form-label">Email</label>
|
|
<input type="email" class="form-control" id="email" name="email" required>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="status" class="form-label">Status</label>
|
|
<select class="form-select" id="status" name="status">
|
|
<option>Applied</option>
|
|
<option>Interviewing</option>
|
|
<option>Offered</option>
|
|
<option>Hired</option>
|
|
</select>
|
|
</div>
|
|
<button type="submit" class="btn btn-primary">Save Candidate</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Add Task Modal -->
|
|
<div class="modal fade" id="addTaskModal" tabindex="-1" aria-labelledby="addTaskModalLabel" aria-hidden="true">
|
|
<div class="modal-dialog">
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<h5 class="modal-title" id="addTaskModalLabel">Add New Task</h5>
|
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
|
</div>
|
|
<div class="modal-body">
|
|
<form method="POST" action="dashboard.php">
|
|
<input type="hidden" name="add_task" value="1">
|
|
<div class="mb-3">
|
|
<label for="title" class="form-label">Title</label>
|
|
<input type="text" class="form-control" id="title" name="title" required>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="status" class="form-label">Status</label>
|
|
<select class="form-select" id="status" name="status">
|
|
<option>Pending</option>
|
|
<option>In Progress</option>
|
|
<option>Completed</option>
|
|
</select>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="assigned_to" class="form-label">Assigned To</label>
|
|
<input type="text" class="form-control" id="assigned_to" name="assigned_to">
|
|
</div>
|
|
<button type="submit" class="btn btn-primary">Save Task</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
|
<script>
|
|
document.addEventListener('DOMContentLoaded', function () {
|
|
// Tab persistence
|
|
const urlParams = new URLSearchParams(window.location.search);
|
|
const tab = urlParams.get('tab');
|
|
if (tab) {
|
|
const tabEl = document.querySelector('#' + tab + '-tab');
|
|
if(tabEl) {
|
|
const tab = new bootstrap.Tab(tabEl);
|
|
tab.show();
|
|
}
|
|
}
|
|
|
|
// Reset URL after modal close
|
|
const modals = document.querySelectorAll('.modal');
|
|
modals.forEach(modal => {
|
|
modal.addEventListener('hidden.bs.modal', function () {
|
|
// To refresh the content, we reload the page with the correct tab active
|
|
const activeTab = document.querySelector('.nav-tabs .nav-link.active').id.replace('-tab', '');
|
|
window.location.href = 'dashboard.php?tab=' + activeTab;
|
|
});
|
|
});
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|