File "index.php"
Full path: /home/itsevak/public_html/prepaiddev.itsevak.com/dashboard/index.php
File
size: 16.36 B (16.36 KB bytes)
MIME-type: text/x-php
Charset: utf-8
Download Open Edit Advanced Editor Back
<?php
require_once '../includes/functions.php';
// Require login
requireLogin();
$user = getCurrentUser();
$db = Database::getInstance();
// Get statistics for auto owners
$stats = [];
if ($_SESSION['user_type'] === 'auto_owner') {
// Total rickshaws
$totalRickshaws = $db->fetch(
"SELECT COUNT(*) as count FROM auto_rickshaws WHERE owner_id = ?",
[$_SESSION['user_id']]
)['count'];
// Active rickshaws
$activeRickshaws = $db->fetch(
"SELECT COUNT(*) as count FROM auto_rickshaws WHERE owner_id = ? AND status = 'active'",
[$_SESSION['user_id']]
)['count'];
// Pending approval
$pendingRickshaws = $db->fetch(
"SELECT COUNT(*) as count FROM auto_rickshaws WHERE owner_id = ? AND status = 'pending_approval'",
[$_SESSION['user_id']]
)['count'];
// Recent rickshaws
$recentRickshaws = $db->fetchAll(
"SELECT * FROM auto_rickshaws WHERE owner_id = ? ORDER BY created_at DESC LIMIT 5",
[$_SESSION['user_id']]
);
$stats = [
'total' => $totalRickshaws,
'active' => $activeRickshaws,
'pending' => $pendingRickshaws,
'recent' => $recentRickshaws
];
}
$pageTitle = 'Dashboard';
require_once '../includes/header.php';
?>
<div class="container py-4">
<!-- Welcome Section -->
<div class="row mb-4">
<div class="col-12">
<div class="card">
<div class="card-body">
<h2 class="card-title mb-2">Welcome back, <?php echo htmlspecialchars($user['name']); ?>!</h2>
<p class="card-text text-muted">
<?php if ($_SESSION['user_type'] === 'auto_owner'): ?>
Manage your auto rickshaws and track your earnings.
<?php else: ?>
Book rides and manage your trips.
<?php endif; ?>
</p>
</div>
</div>
</div>
</div>
<?php if ($_SESSION['user_type'] === 'auto_owner'): ?>
<!-- Statistics Cards -->
<div class="row mb-4">
<div class="col-md-4">
<div class="card text-center">
<div class="card-body">
<i class="bi bi-truck display-4 text-primary mb-3"></i>
<h3 class="card-title"><?php echo $stats['total']; ?></h3>
<p class="card-text text-muted">Total Rickshaws</p>
</div>
</div>
</div>
<div class="col-md-4">
<div class="card text-center">
<div class="card-body">
<i class="bi bi-check-circle display-4 text-success mb-3"></i>
<h3 class="card-title"><?php echo $stats['active']; ?></h3>
<p class="card-text text-muted">Active Rickshaws</p>
</div>
</div>
</div>
<div class="col-md-4">
<div class="card text-center">
<div class="card-body">
<i class="bi bi-clock display-4 text-warning mb-3"></i>
<h3 class="card-title"><?php echo $stats['pending']; ?></h3>
<p class="card-text text-muted">Pending Approval</p>
</div>
</div>
</div>
</div>
<!-- Quick Actions -->
<div class="row mb-4">
<div class="col-12">
<div class="card">
<div class="card-header">
<h5 class="card-title mb-0">Quick Actions</h5>
</div>
<div class="card-body">
<div class="row">
<div class="col-md-6">
<a href="<?php echo url_for('dashboard/add_rickshaw.php'); ?>" class="btn btn-primary w-100 mb-3">
<i class="bi bi-plus-circle me-2"></i>Add New Rickshaw
</a>
</div>
<div class="col-md-6">
<a href="<?php echo url_for('dashboard/manage_rickshaws.php'); ?>" class="btn btn-outline-primary w-100 mb-3">
<i class="bi bi-list me-2"></i>Manage Rickshaws
</a>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Recent Rickshaws -->
<?php if (!empty($stats['recent'])): ?>
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-header d-flex justify-content-between align-items-center">
<h5 class="card-title mb-0">Recent Rickshaws</h5>
<a href="<?php echo url_for('dashboard/manage_rickshaws.php'); ?>" class="btn btn-sm btn-outline-primary">View All</a>
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table table-hover">
<thead>
<tr>
<th>Number Plate</th>
<th>Local ID</th>
<th>Status</th>
<th>Added On</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php foreach ($stats['recent'] as $rickshaw): ?>
<tr>
<td>
<strong><?php echo htmlspecialchars($rickshaw['number_plate']); ?></strong>
</td>
<td><?php echo htmlspecialchars($rickshaw['unique_local_id']); ?></td>
<td><?php echo getStatusBadge($rickshaw['status']); ?></td>
<td><?php echo formatDate($rickshaw['created_at']); ?></td>
<td>
<a href="<?php echo url_for('dashboard/view_rickshaw.php'); ?>?id=<?php echo $rickshaw['id']; ?>"
class="btn btn-sm btn-outline-primary">
<i class="bi bi-eye"></i>
</a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<?php else: ?>
<!-- Empty State -->
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-body text-center py-5">
<i class="bi bi-truck display-1 text-muted mb-3"></i>
<h4>No Rickshaws Yet</h4>
<p class="text-muted mb-4">Get started by adding your first auto rickshaw to the platform.</p>
<a href="<?php echo url_for('dashboard/add_rickshaw.php'); ?>" class="btn btn-primary">
<i class="bi bi-plus-circle me-2"></i>Add Your First Rickshaw
</a>
</div>
</div>
</div>
</div>
<?php endif; ?>
<?php else: ?>
<!-- Passenger Dashboard -->
<div class="row mb-4">
<div class="col-md-6">
<div class="card">
<div class="card-body text-center">
<i class="bi bi-qr-code display-4 text-primary mb-3"></i>
<h5 class="card-title">Book a Ride</h5>
<p class="card-text text-muted">Select destination, pay commission, and get QR code</p>
<a href="book_ride.php" class="btn btn-primary">
<i class="bi bi-plus-circle"></i> Book Now
</a>
</div>
</div>
</div>
<div class="col-md-6">
<div class="card">
<div class="card-body text-center">
<i class="bi bi-clock-history display-4 text-info mb-3"></i>
<h5 class="card-title">My Bookings</h5>
<p class="card-text text-muted">View and track your ride bookings</p>
<a href="my_bookings.php" class="btn btn-outline-primary">
<i class="bi bi-list"></i> View Bookings
</a>
</div>
</div>
</div>
</div>
<!-- Recent Bookings -->
<?php
$recentBookings = $db->fetchAll(
"SELECT b.*, tl.name as to_location_name, tl.city as to_city
FROM bookings b
JOIN to_locations tl ON b.to_location_id = tl.id
WHERE b.passenger_id = ?
ORDER BY b.created_at DESC LIMIT 5",
[$user['id']]
);
?>
<?php if (!empty($recentBookings)): ?>
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-header d-flex justify-content-between align-items-center">
<h5 class="card-title mb-0">Recent Bookings</h5>
<a href="my_bookings.php" class="btn btn-sm btn-outline-primary">View All</a>
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table table-hover">
<thead>
<tr>
<th>Booking ID</th>
<th>Destination</th>
<th>Amount</th>
<th>Status</th>
<th>Date</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php foreach ($recentBookings as $booking): ?>
<tr>
<td>
<strong>#<?php echo $booking['id']; ?></strong>
</td>
<td>
<?php echo htmlspecialchars($booking['to_location_name']); ?>
<br><small class="text-muted"><?php echo $booking['to_city']; ?></small>
</td>
<td>
<strong>₹<?php echo number_format($booking['total_amount'], 2); ?></strong>
</td>
<td>
<?php
$statusClass = [
'pending' => 'bg-warning',
'confirmed' => 'bg-info',
'in_progress' => 'bg-primary',
'completed' => 'bg-success',
'cancelled' => 'bg-danger'
];
$statusText = [
'pending' => 'Pending',
'confirmed' => 'Confirmed',
'in_progress' => 'In Progress',
'completed' => 'Completed',
'cancelled' => 'Cancelled'
];
?>
<span class="badge <?php echo $statusClass[$booking['status']] ?? 'bg-secondary'; ?>">
<?php echo $statusText[$booking['status']] ?? ucfirst($booking['status']); ?>
</span>
</td>
<td><?php echo date('M d, H:i', strtotime($booking['created_at'])); ?></td>
<td>
<?php if ($booking['status'] === 'pending'): ?>
<a href="book_ride.php?booking_id=<?php echo $booking['id']; ?>&action=proceed_payment"
class="btn btn-sm btn-success">
<i class="bi bi-credit-card"></i> Proceed to Payment
</a>
<?php elseif ($booking['status'] === 'confirmed'): ?>
<a href="payment_success.php?booking_id=<?php echo $booking['id']; ?>"
class="btn btn-sm btn-outline-primary">
<i class="bi bi-qr-code"></i> View QR
</a>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<?php else: ?>
<!-- Empty State -->
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-body text-center py-5">
<i class="bi bi-qr-code display-1 text-muted mb-3"></i>
<h4>No Bookings Yet</h4>
<p class="text-muted mb-4">Get started by booking your first ride.</p>
<a href="book_ride.php" class="btn btn-primary">
<i class="bi bi-plus-circle me-2"></i>Book Your First Ride
</a>
</div>
</div>
</div>
</div>
<?php endif; ?>
<?php endif; ?>
</div>
<?php require_once '../includes/footer.php'; ?>