193 lines
9.3 KiB
PHP
193 lines
9.3 KiB
PHP
<?php
|
|
// index.php
|
|
session_start();
|
|
require_once 'db/config.php';
|
|
|
|
$pdo = db();
|
|
$leads = [];
|
|
if ($pdo) {
|
|
try {
|
|
$stmt = $pdo->query("SELECT id, lead_name, status, category, contact_email, owner FROM leads ORDER BY created_at DESC");
|
|
$leads = $stmt->fetchAll();
|
|
} catch (PDOException $e) {
|
|
error_log("Fetch Leads Error: " . $e->getMessage());
|
|
// Set a message to be displayed if fetching fails
|
|
$_SESSION['message'] = ['type' => 'danger', 'text' => 'Could not fetch leads from the database.'];
|
|
}
|
|
} else {
|
|
$_SESSION['message'] = ['type' => 'danger', 'text' => 'Database connection failed. Please check configuration.'];
|
|
}
|
|
|
|
// Get flash message from session
|
|
$message = null;
|
|
if (isset($_SESSION['message'])) {
|
|
$message = $_SESSION['message'];
|
|
unset($_SESSION['message']);
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Law CRM - 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(); ?>">
|
|
<script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
|
|
</head>
|
|
<body>
|
|
|
|
<!-- Navbar -->
|
|
<nav class="navbar navbar-expand-lg navbar-light">
|
|
<div class="container-fluid">
|
|
<a class="navbar-brand" href="#">
|
|
<img src="https://picsum.photos/seed/law-crm-logo/120/40" alt="Law CRM Logo" width="120" height="40" class="d-inline-block align-text-top">
|
|
</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 mb-2 mb-lg-0">
|
|
<li class="nav-item"><a class="nav-link active" href="#">Leads</a></li>
|
|
<li class="nav-item"><a class="nav-link" href="#">Contacts</a></li>
|
|
<li class="nav-item"><a class="nav-link" href="#">Reports</a></li>
|
|
</ul>
|
|
<div class="d-flex align-items-center">
|
|
<button class="btn btn-primary me-3" data-bs-toggle="modal" data-bs-target="#addLeadModal">
|
|
<i data-feather="plus" class="me-1"></i> Add Lead
|
|
</button>
|
|
<img src="https://picsum.photos/seed/law-crm-avatar1/40/40" alt="User avatar" class="rounded-circle" width="40" height="40">
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
|
|
<!-- Main Content -->
|
|
<div class="container main-content">
|
|
<div class="card p-4">
|
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
|
<h1 class="h3 mb-0">Leads Dashboard</h1>
|
|
<div class="d-flex">
|
|
<div class="input-group">
|
|
<input type="text" class="form-control" placeholder="Search leads...">
|
|
<button class="btn btn-outline-secondary" type="button"><i data-feather="search"></i></button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Leads Table -->
|
|
<div class="table-responsive">
|
|
<table class="table table-hover align-middle">
|
|
<thead>
|
|
<tr>
|
|
<th>Lead</th>
|
|
<th>Status</th>
|
|
<th>Category</th>
|
|
<th>Contact</th>
|
|
<th>Owner</th>
|
|
<th></th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php if (empty($leads)): ?>
|
|
<tr>
|
|
<td colspan="6" class="text-center py-5">
|
|
<p class="mb-2">No leads found.</p>
|
|
<button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addLeadModal">Add your first lead</button>
|
|
</td>
|
|
</tr>
|
|
<?php else: ?>
|
|
<?php foreach ($leads as $lead): ?>
|
|
<tr>
|
|
<td><strong><?php echo htmlspecialchars($lead['lead_name']); ?></strong></td>
|
|
<td>
|
|
<span class="status-badge status-<?php echo strtolower(htmlspecialchars($lead['status'])); ?>">
|
|
<?php echo htmlspecialchars($lead['status']); ?>
|
|
</span>
|
|
</td>
|
|
<td><?php echo htmlspecialchars($lead['category']); ?></td>
|
|
<td><?php echo htmlspecialchars($lead['contact_email']); ?></td>
|
|
<td><?php echo htmlspecialchars($lead['owner']); ?></td>
|
|
<td>
|
|
<button class="btn btn-sm btn-outline-secondary"><i data-feather="edit-2"></i></button>
|
|
<button class="btn btn-sm btn-outline-danger"><i data-feather="trash-2"></i></button>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Add Lead Modal -->
|
|
<div class="modal fade" id="addLeadModal" tabindex="-1">
|
|
<div class="modal-dialog modal-dialog-centered">
|
|
<div class="modal-content">
|
|
<form action="add_lead.php" method="POST">
|
|
<div class="modal-header">
|
|
<h5 class="modal-title">Add New Lead</h5>
|
|
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
|
</div>
|
|
<div class="modal-body">
|
|
<div class="mb-3">
|
|
<label for="lead_name" class="form-label">Lead Name</label>
|
|
<input type="text" class="form-control" id="lead_name" name="lead_name" required>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="status" class="form-label">Status</label>
|
|
<select class="form-select" id="status" name="status" required>
|
|
<option value="New">New</option>
|
|
<option value="Contacted">Contacted</option>
|
|
<option value="Qualified">Qualified</option>
|
|
<option value="Lost">Lost</option>
|
|
</select>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="category" class="form-label">Category</label>
|
|
<select class="form-select" id="category" name="category" required>
|
|
<option value="Corporate">Corporate</option>
|
|
<option value="Family">Family</option>
|
|
<option value="Criminal">Criminal</option>
|
|
</select>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="contact_email" class="form-label">Contact Email</label>
|
|
<input type="email" class="form-control" id="contact_email" name="contact_email" required>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="owner" class="form-label">Owner</label>
|
|
<input type="text" class="form-control" id="owner" name="owner" required>
|
|
</div>
|
|
</div>
|
|
<div class="modal-footer">
|
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
|
|
<button type="submit" class="btn btn-primary">Save Lead</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Toast Notification -->
|
|
<?php if ($message): ?>
|
|
<div class="toast-container position-fixed bottom-0 end-0 p-3">
|
|
<div class="toast align-items-center text-white bg-<?php echo $message['type']; ?> border-0" role="alert" aria-live="assertive" aria-atomic="true">
|
|
<div class="d-flex">
|
|
<div class="toast-body">
|
|
<?php echo htmlspecialchars($message['text']); ?>
|
|
</div>
|
|
<button type="button" class="btn-close btn-close-white me-2 m-auto" data-bs-dismiss="toast" aria-label="Close"></button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
|
<script src="assets/js/main.js?v=<?php echo time(); ?>"></script>
|
|
<script>
|
|
feather.replace();
|
|
</script>
|
|
</body>
|
|
</html>
|