/home/awneajlw/.trash/admin/appointments.php
<?php
require_once '../config/database.php';
require_once '../includes/auth.php';
requireAdmin();
$database = new Database();
$db = $database->getConnection();
$status_filter = isset($_GET['status']) ? $_GET['status'] : '';
$search = isset($_GET['search']) ? $_GET['search'] : '';
// Build query
$query = "SELECT a.*, u.name as user_name, u.email as user_email, u.phone as user_phone,
s.title as service_name, s.price
FROM appointments a
JOIN users u ON a.user_id = u.id
JOIN services s ON a.service_id = s.id
WHERE 1=1";
$params = [];
if ($status_filter) {
$query .= " AND a.status = ?";
$params[] = $status_filter;
}
if ($search) {
$query .= " AND (u.name LIKE ? OR u.email LIKE ? OR s.title LIKE ?)";
$search_term = "%$search%";
$params = array_merge($params, [$search_term, $search_term, $search_term]);
}
$query .= " ORDER BY a.appointment_date DESC, a.appointment_time DESC";
$stmt = $db->prepare($query);
$stmt->execute($params);
$appointments = $stmt->fetchAll(PDO::FETCH_ASSOC);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Manage Appointments - Opti-Vision Eye Clinic</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 class="bg-light">
<!-- Navigation -->
<nav class="navbar navbar-expand-lg navbar-dark bg-primary shadow-sm">
<div class="container-fluid">
<a class="navbar-brand fw-bold" href="../index.php">
<i class="fas fa-eye me-2"></i>Opti-Vision Admin
</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 ms-auto">
<li class="nav-item">
<a class="nav-link" href="dashboard.php">Dashboard</a>
</li>
<li class="nav-item">
<a class="nav-link active" href="appointments.php">Appointments</a>
</li>
<li class="nav-item">
<a class="nav-link" href="users.php">Users</a>
</li>
<li class="nav-item">
<a class="nav-link" href="services.php">Services</a>
</li>
<li class="nav-item">
<a class="nav-link" href="doctors.php">Doctors</a>
</li>
<li class="nav-item">
<a class="nav-link" href="messages.php">Messages</a>
</li>
<li class="nav-item">
<a class="nav-link" href="../logout.php">Logout</a>
</li>
</ul>
</div>
</div>
</nav>
<div class="container-fluid py-4">
<div class="row">
<div class="col-12">
<div class="d-flex justify-content-between align-items-center mb-4">
<h2 class="fw-bold">Manage Appointments</h2>
<div class="d-flex gap-2">
<a href="dashboard.php" class="btn btn-outline-secondary">
<i class="fas fa-arrow-left me-2"></i>Back to Dashboard
</a>
</div>
</div>
<!-- Filters -->
<div class="card dashboard-card mb-4">
<div class="card-body">
<form method="GET" class="row g-3">
<div class="col-md-4">
<label for="status" class="form-label">Filter by Status</label>
<select class="form-select" id="status" name="status">
<option value="">All Status</option>
<option value="pending" <?php echo $status_filter === 'pending' ? 'selected' : ''; ?>>Pending</option>
<option value="confirmed" <?php echo $status_filter === 'confirmed' ? 'selected' : ''; ?>>Confirmed</option>
<option value="completed" <?php echo $status_filter === 'completed' ? 'selected' : ''; ?>>Completed</option>
<option value="cancelled" <?php echo $status_filter === 'cancelled' ? 'selected' : ''; ?>>Cancelled</option>
</select>
</div>
<div class="col-md-6">
<label for="search" class="form-label">Search</label>
<input type="text" class="form-control" id="search" name="search"
placeholder="Search by patient name, email, or service..."
value="<?php echo htmlspecialchars($search); ?>">
</div>
<div class="col-md-2">
<label class="form-label"> </label>
<div class="d-grid">
<button type="submit" class="btn btn-primary">
<i class="fas fa-search me-2"></i>Filter
</button>
</div>
</div>
</form>
</div>
</div>
<!-- Appointments Table -->
<div class="card dashboard-card">
<div class="card-body">
<?php if (empty($appointments)): ?>
<div class="text-center py-5">
<i class="fas fa-calendar-times fa-3x text-muted mb-3"></i>
<h5 class="text-muted">No appointments found</h5>
<p class="text-muted">Try adjusting your filters or check back later.</p>
</div>
<?php else: ?>
<div class="table-responsive">
<table class="table table-hover">
<thead>
<tr>
<th>ID</th>
<th>Patient</th>
<th>Contact</th>
<th>Service</th>
<th>Date & Time</th>
<th>Status</th>
<th>Notes</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php foreach($appointments as $appointment): ?>
<tr>
<td>#<?php echo $appointment['id']; ?></td>
<td>
<strong><?php echo htmlspecialchars($appointment['user_name']); ?></strong>
</td>
<td>
<small class="text-muted">
<?php echo htmlspecialchars($appointment['user_email']); ?><br>
<?php echo htmlspecialchars($appointment['user_phone']); ?>
</small>
</td>
<td>
<strong><?php echo htmlspecialchars($appointment['service_name']); ?></strong>
<br>
<small class="text-muted">PKR <?php echo number_format($appointment['price']); ?></small>
</td>
<td>
<?php echo date('M d, Y', strtotime($appointment['appointment_date'])); ?><br>
<small class="text-muted"><?php echo date('h:i A', strtotime($appointment['appointment_time'])); ?></small>
</td>
<td>
<span class="badge bg-<?php
echo $appointment['status'] === 'confirmed' ? 'success' :
($appointment['status'] === 'pending' ? 'warning' :
($appointment['status'] === 'completed' ? 'info' : 'secondary'));
?>">
<?php echo ucfirst($appointment['status']); ?>
</span>
</td>
<td>
<?php if ($appointment['notes']): ?>
<small class="text-muted"><?php echo htmlspecialchars(substr($appointment['notes'], 0, 50)); ?><?php echo strlen($appointment['notes']) > 50 ? '...' : ''; ?></small>
<?php else: ?>
<span class="text-muted">-</span>
<?php endif; ?>
</td>
<td>
<div class="btn-group btn-group-sm">
<button class="btn btn-outline-primary"
onclick="viewAppointment(<?php echo $appointment['id']; ?>)"
title="View Details">
<i class="fas fa-eye"></i>
</button>
<button class="btn btn-outline-success"
onclick="updateStatus(<?php echo $appointment['id']; ?>, 'confirmed')"
title="Confirm">
<i class="fas fa-check"></i>
</button>
<button class="btn btn-outline-info"
onclick="updateStatus(<?php echo $appointment['id']; ?>, 'completed')"
title="Mark Complete">
<i class="fas fa-check-double"></i>
</button>
<button class="btn btn-outline-danger"
onclick="updateStatus(<?php echo $appointment['id']; ?>, 'cancelled')"
title="Cancel">
<i class="fas fa-times"></i>
</button>
</div>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php endif; ?>
</div>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script>
function viewAppointment(id) {
// Implement view appointment modal
alert('View appointment details feature will be implemented soon.');
}
function updateStatus(id, status) {
if (confirm('Are you sure you want to update this appointment status to ' + status + '?')) {
// Implement AJAX call to update status
alert('Status update feature will be implemented soon.');
}
}
</script>
</body>
</html>