/home/awneajlw/.trash/user/dashboard.php
<?php
require_once '../config/database.php';
require_once '../includes/auth.php';
requireLogin();

$database = new Database();
$db = $database->getConnection();

$user_id = $_SESSION['user_id'];

// Get user appointments
$query = "SELECT a.*, s.title as service_name, s.price 
          FROM appointments a 
          JOIN services s ON a.service_id = s.id 
          WHERE a.user_id = ? 
          ORDER BY a.appointment_date DESC, a.appointment_time DESC";
$stmt = $db->prepare($query);
$stmt->execute([$user_id]);
$appointments = $stmt->fetchAll(PDO::FETCH_ASSOC);

// Get upcoming appointments
$query = "SELECT a.*, s.title as service_name, s.price 
          FROM appointments a 
          JOIN services s ON a.service_id = s.id 
          WHERE a.user_id = ? AND a.appointment_date >= CURDATE() 
          ORDER BY a.appointment_date ASC, a.appointment_time ASC";
$stmt = $db->prepare($query);
$stmt->execute([$user_id]);
$upcoming_appointments = $stmt->fetchAll(PDO::FETCH_ASSOC);

// Get user info
$query = "SELECT * FROM users WHERE id = ?";
$stmt = $db->prepare($query);
$stmt->execute([$user_id]);
$user = $stmt->fetch(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>Dashboard - 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-light bg-white shadow-sm">
        <div class="container">
            <a class="navbar-brand fw-bold text-primary" href="../index.php">
                <i class="fas fa-eye me-2"></i>Opti-Vision
            </a>
            <div class="navbar-nav ms-auto">
                <a class="nav-link" href="../index.php">Home</a>
                <a class="nav-link" href="profile.php">Profile</a>
                <a class="nav-link" href="../logout.php">Logout</a>
            </div>
        </div>
    </nav>

    <div class="container py-5">
        <div class="row">
            <div class="col-lg-3">
                <div class="card dashboard-card">
                    <div class="card-body text-center">
                        <img src="../assets/images/avatar.jpg" alt="Profile" class="rounded-circle mb-3" width="100" height="100">
                        <h5 class="fw-bold"><?php echo htmlspecialchars($user['name']); ?></h5>
                        <p class="text-muted"><?php echo htmlspecialchars($user['email']); ?></p>
                        <p class="text-muted"><?php echo htmlspecialchars($user['phone']); ?></p>
                        <a href="profile.php" class="btn btn-outline-primary btn-sm">Edit Profile</a>
                    </div>
                </div>
                
                <div class="card dashboard-card mt-4">
                    <div class="card-body">
                        <h6 class="fw-bold mb-3">Quick Actions</h6>
                        <div class="d-grid gap-2">
                            <a href="../appointment.php" class="btn btn-primary">
                                <i class="fas fa-calendar-plus me-2"></i>Book Appointment
                            </a>
                            <a href="../services.php" class="btn btn-outline-primary">
                                <i class="fas fa-list me-2"></i>View Services
                            </a>
                            <a href="../doctors.php" class="btn btn-outline-primary">
                                <i class="fas fa-user-md me-2"></i>Our Doctors
                            </a>
                        </div>
                    </div>
                </div>
            </div>
            
            <div class="col-lg-9">
                <div class="d-flex justify-content-between align-items-center mb-4">
                    <h2 class="fw-bold">Dashboard</h2>
                    <a href="../appointment.php" class="btn btn-primary">
                        <i class="fas fa-plus me-2"></i>New Appointment
                    </a>
                </div>
                
                <!-- Stats Cards -->
                <div class="row g-4 mb-5">
                    <div class="col-md-4">
                        <div class="card dashboard-card stat-card">
                            <div class="stat-number"><?php echo count($appointments); ?></div>
                            <div class="stat-label">Total Appointments</div>
                        </div>
                    </div>
                    <div class="col-md-4">
                        <div class="card dashboard-card stat-card">
                            <div class="stat-number"><?php echo count($upcoming_appointments); ?></div>
                            <div class="stat-label">Upcoming</div>
                        </div>
                    </div>
                    <div class="col-md-4">
                        <div class="card dashboard-card stat-card">
                            <div class="stat-number">
                                <?php 
                                $completed = array_filter($appointments, function($apt) {
                                    return $apt['status'] === 'completed';
                                });
                                echo count($completed);
                                ?>
                            </div>
                            <div class="stat-label">Completed</div>
                        </div>
                    </div>
                </div>
                
                <!-- Upcoming Appointments -->
                <div class="card dashboard-card">
                    <div class="card-header bg-primary text-white">
                        <h5 class="mb-0"><i class="fas fa-calendar-check me-2"></i>Upcoming Appointments</h5>
                    </div>
                    <div class="card-body">
                        <?php if (empty($upcoming_appointments)): ?>
                            <div class="text-center py-4">
                                <i class="fas fa-calendar-times fa-3x text-muted mb-3"></i>
                                <p class="text-muted">No upcoming appointments</p>
                                <a href="../appointment.php" class="btn btn-primary">Book Now</a>
                            </div>
                        <?php else: ?>
                            <div class="table-responsive">
                                <table class="table table-hover">
                                    <thead>
                                        <tr>
                                            <th>Service</th>
                                            <th>Date</th>
                                            <th>Time</th>
                                            <th>Status</th>
                                            <th>Action</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php foreach($upcoming_appointments as $appointment): ?>
                                        <tr>
                                            <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'])); ?></td>
                                            <td><?php echo date('h:i A', strtotime($appointment['appointment_time'])); ?></td>
                                            <td>
                                                <span class="badge bg-<?php 
                                                    echo $appointment['status'] === 'confirmed' ? 'success' : 
                                                        ($appointment['status'] === 'pending' ? 'warning' : 'secondary'); 
                                                ?>">
                                                    <?php echo ucfirst($appointment['status']); ?>
                                                </span>
                                            </td>
                                            <td>
                                                <button class="btn btn-sm btn-outline-danger" 
                                                        onclick="cancelAppointment(<?php echo $appointment['id']; ?>)">
                                                    <i class="fas fa-times"></i> Cancel
                                                </button>
                                            </td>
                                        </tr>
                                        <?php endforeach; ?>
                                    </tbody>
                                </table>
                            </div>
                        <?php endif; ?>
                    </div>
                </div>
                
                <!-- Recent Appointments -->
                <div class="card dashboard-card mt-4">
                    <div class="card-header">
                        <h5 class="mb-0"><i class="fas fa-history me-2"></i>Recent Appointments</h5>
                    </div>
                    <div class="card-body">
                        <?php if (empty($appointments)): ?>
                            <div class="text-center py-4">
                                <i class="fas fa-calendar-alt fa-3x text-muted mb-3"></i>
                                <p class="text-muted">No appointments yet</p>
                            </div>
                        <?php else: ?>
                            <div class="table-responsive">
                                <table class="table table-hover">
                                    <thead>
                                        <tr>
                                            <th>Service</th>
                                            <th>Date</th>
                                            <th>Time</th>
                                            <th>Status</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php foreach(array_slice($appointments, 0, 5) as $appointment): ?>
                                        <tr>
                                            <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'])); ?></td>
                                            <td><?php echo date('h:i A', strtotime($appointment['appointment_time'])); ?></td>
                                            <td>
                                                <span class="badge bg-<?php 
                                                    echo $appointment['status'] === 'completed' ? 'success' : 
                                                        ($appointment['status'] === 'confirmed' ? 'success' : 
                                                        ($appointment['status'] === 'pending' ? 'warning' : 'secondary')); 
                                                ?>">
                                                    <?php echo ucfirst($appointment['status']); ?>
                                                </span>
                                            </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 cancelAppointment(appointmentId) {
            if (confirm('Are you sure you want to cancel this appointment?')) {
                // You can implement AJAX call here to cancel appointment
                alert('Appointment cancellation feature will be implemented soon.');
            }
        }
    </script>
</body>
</html>