Update: Add publish/unpublish button to admin trips table and improve table styling
This commit is contained in:
@@ -12,12 +12,22 @@ $token = $_GET['token'];
|
||||
// Sanitize the trip_id to prevent SQL injection
|
||||
$trip_id = intval(decryptData($token, $salt)); // Ensures $trip_id is treated as an integer
|
||||
|
||||
// Check if user is admin or superadmin to allow draft preview
|
||||
// Check if user is admin/superadmin
|
||||
$user_role = getUserRole();
|
||||
$is_admin = in_array($user_role, ['admin', 'superadmin']);
|
||||
|
||||
// Prepare the SQL query
|
||||
$sql = "SELECT trip_id, trip_name, location, short_description, long_description, start_date, end_date,
|
||||
vehicle_capacity, cost_members, cost_nonmembers, places_booked, booking_fee, cost_pensioner, cost_pensioner_member
|
||||
vehicle_capacity, cost_members, cost_nonmembers, places_booked, booking_fee, cost_pensioner, cost_pensioner_member, published
|
||||
FROM trips
|
||||
WHERE trip_id = ?";
|
||||
|
||||
// If not admin, only show published trips
|
||||
if (!$is_admin) {
|
||||
$sql .= " AND published = 1";
|
||||
}
|
||||
|
||||
// Use prepared statements for added security
|
||||
$stmt = $conn->prepare($sql);
|
||||
|
||||
@@ -194,12 +204,39 @@ include_once(dirname(dirname(dirname(__DIR__))) . '/header.php');
|
||||
</ol>
|
||||
</nav>
|
||||
</div>
|
||||
<!-- Draft Notice for Admin -->
|
||||
<?php if ($is_admin && isset($row['published']) && $row['published'] == 0): ?>
|
||||
<div class="alert alert-warning mt-3" role="alert">
|
||||
<strong><i class="fas fa-exclamation-triangle"></i> Draft Trip</strong><br>
|
||||
This trip is currently in draft status and is not visible to regular users. Only admins and superadmins can preview it.
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<!-- Publish/Unpublish Button -->
|
||||
<?php
|
||||
$user_role = getUserRole();
|
||||
if (in_array($user_role, ['admin', 'superadmin'])):
|
||||
// Use published status from the main query
|
||||
$is_published = $row['published'] ?? 0;
|
||||
?>
|
||||
<div class="admin-actions mt-20">
|
||||
<button type="button" class="theme-btn" style="width: 100%; id="publishBtn" onclick="toggleTripPublished(<?php echo $trip_id; ?>)">
|
||||
<?php if ($is_published): ?>
|
||||
<i class="fas fa-eye-slash"></i> Unpublish Trip
|
||||
<?php else: ?>
|
||||
<i class="fas fa-eye"></i> Publish Trip
|
||||
<?php endif; ?>
|
||||
</button>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<!-- Tour Gallery start -->
|
||||
<div class="tour-gallery">
|
||||
<div class="container-fluid">
|
||||
@@ -260,36 +297,7 @@ include_once(dirname(dirname(dirname(__DIR__))) . '/header.php');
|
||||
</div>
|
||||
<span class="subtitle mb-15"><?php echo $badge_text; ?></span>
|
||||
|
||||
<!-- Admin Publish/Unpublish Button -->
|
||||
<?php
|
||||
$user_role = $_SESSION['role'] ?? 'user';
|
||||
if (in_array($user_role, ['admin', 'superadmin'])):
|
||||
// Fetch current published status
|
||||
$status_stmt = $conn->prepare("SELECT published FROM trips WHERE trip_id = ?");
|
||||
$status_stmt->bind_param("i", $trip_id);
|
||||
$status_stmt->execute();
|
||||
$status_result = $status_stmt->get_result();
|
||||
$trip_status = $status_result->fetch_assoc();
|
||||
$is_published = $trip_status['published'] ?? 0;
|
||||
$status_stmt->close();
|
||||
?>
|
||||
<div class="admin-actions mt-20">
|
||||
<button type="button" class="theme-btn" id="publishBtn" onclick="toggleTripPublished(<?php echo $trip_id; ?>)">
|
||||
<?php if ($is_published): ?>
|
||||
<i class="fas fa-eye-slash"></i> Unpublish Trip
|
||||
<?php else: ?>
|
||||
<i class="fas fa-eye"></i> Publish Trip
|
||||
<?php endif; ?>
|
||||
</button>
|
||||
<span id="publishStatus" class="ml-3" style="margin-left: 10px;">
|
||||
<?php if ($is_published): ?>
|
||||
<span class="badge bg-success">Published</span>
|
||||
<?php else: ?>
|
||||
<span class="badge bg-warning">Draft</span>
|
||||
<?php endif; ?>
|
||||
</span>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
</div>
|
||||
<!-- <div class="col-xl-4 col-lg-5 text-lg-end" data-aos="fade-right" data-aos-duration="1500" data-aos-offset="50">
|
||||
<div class="tour-header-social mb-10">
|
||||
|
||||
@@ -7,14 +7,18 @@ include_once($rootPath . '/header.php');
|
||||
|
||||
<style>
|
||||
.image {
|
||||
width: 400px;
|
||||
/* Set your desired width */
|
||||
width: 100%;
|
||||
height: 350px;
|
||||
/* Set your desired height */
|
||||
overflow: hidden;
|
||||
/* Hide any overflow */
|
||||
display: block;
|
||||
/* Ensure proper block behavior */
|
||||
}
|
||||
|
||||
.image img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
object-position: top;
|
||||
display: block;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -52,8 +56,17 @@ include_once($rootPath . '/header.php');
|
||||
<?php
|
||||
|
||||
|
||||
// Check if user is admin or superadmin to show draft trips
|
||||
$user_role = getUserRole();
|
||||
$is_admin = in_array($user_role, ['admin', 'superadmin']);
|
||||
|
||||
// Query to retrieve data from the trips table
|
||||
$sql = "SELECT trip_id, trip_name, location, short_description, start_date, end_date, vehicle_capacity, cost_members, places_booked FROM trips WHERE published = 1 AND start_date > CURDATE()";
|
||||
// Admins see all trips (published and draft), regular users only see published upcoming trips
|
||||
if ($is_admin) {
|
||||
$sql = "SELECT trip_id, trip_name, location, short_description, start_date, end_date, vehicle_capacity, cost_members, places_booked, published FROM trips ORDER BY start_date DESC";
|
||||
} else {
|
||||
$sql = "SELECT trip_id, trip_name, location, short_description, start_date, end_date, vehicle_capacity, cost_members, places_booked, published FROM trips WHERE published = 1 AND start_date > CURDATE() ORDER BY start_date ASC";
|
||||
}
|
||||
$result = $conn->query($sql);
|
||||
|
||||
if ($result->num_rows > 0) {
|
||||
@@ -68,16 +81,18 @@ include_once($rootPath . '/header.php');
|
||||
$capacity = $row['vehicle_capacity'];
|
||||
$cost_members = $row['cost_members'];
|
||||
$places_booked = $row['places_booked'];
|
||||
$published = $row['published'] ?? 1;
|
||||
$remaining_places = getAvailableSpaces($trip_id);
|
||||
|
||||
// Determine the badge text based on the status
|
||||
$badge_text = ($remaining_places > 0) ? $remaining_places.' PLACES LEFT!!' : 'FULLY BOOKED';
|
||||
$draft_badge = ($published == 0) ? '<span class="badge bg-warning ms-2">DRAFT</span>' : '';
|
||||
|
||||
// Output the HTML structure with dynamic data
|
||||
echo '
|
||||
<div class="destination-item style-three bgc-lighter" data-aos="fade-up" data-aos-duration="1500" data-aos-offset="50">
|
||||
<div class="image">
|
||||
<span class="badge bgc-pink">' . $badge_text . '</span>
|
||||
<span class="badge bgc-pink">' . $badge_text . '</span>' . $draft_badge . '
|
||||
<img src="assets/images/trips/' . $trip_id . '_01.jpg" alt="' . $trip_name . '">
|
||||
</div>
|
||||
<div class="content">
|
||||
@@ -91,7 +106,7 @@ include_once($rootPath . '/header.php');
|
||||
<i class="fas fa-star"></i>
|
||||
</div>
|
||||
</div>
|
||||
<h5><a href="trip-details.php?token=' . encryptData($trip_id, $salt) . '">' . $trip_name . '</a></h5>
|
||||
<h5><a href="trip-details?token=' . encryptData($trip_id, $salt) . '">' . $trip_name . '</a></h5>
|
||||
<p>' . $short_description . '</p>
|
||||
<ul class="blog-meta">
|
||||
<li><i class="far fa-calendar"></i> ' . convertDate($start_date) . ' - ' . convertDate($end_date) . '</li>
|
||||
@@ -100,7 +115,7 @@ include_once($rootPath . '/header.php');
|
||||
</ul>
|
||||
<div class="destination-footer">
|
||||
<span class="price"><span>R ' . $cost_members . '</span>/person</span>
|
||||
<a href="trip-details.php?token=' . encryptData($trip_id, $salt) . '" class="theme-btn style-two style-three">
|
||||
<a href="trip-details?token=' . encryptData($trip_id, $salt) . '" class="theme-btn style-two style-three">
|
||||
<span data-hover="Book Now">Book Now</span>
|
||||
<i class="fal fa-arrow-right"></i>
|
||||
</a>
|
||||
|
||||
Reference in New Issue
Block a user