Feature: Add trip publisher system - create, edit, delete, and publish trips

This commit is contained in:
twotalesanimation
2025-12-04 16:56:31 +02:00
parent ec563e0376
commit 674af23994
9 changed files with 782 additions and 0 deletions

View File

@@ -259,6 +259,37 @@ 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 ($user_role === 'admin'):
// 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">
@@ -673,4 +704,42 @@ include_once(dirname(dirname(dirname(__DIR__))) . '/header.php');
});
</script>
<!-- Trip Publish/Unpublish Script -->
<script>
function toggleTripPublished(tripId) {
$.ajax({
url: 'toggle_trip_published',
type: 'POST',
data: {
trip_id: tripId
},
dataType: 'json',
success: function(response) {
if (response.status === 'success') {
// Update button and status badge
const publishBtn = $('#publishBtn');
const statusBadge = $('#publishStatus');
if (response.published === 1) {
publishBtn.html('<i class="fas fa-eye-slash"></i> Unpublish Trip');
statusBadge.html('<span class="badge bg-success">Published</span>');
} else {
publishBtn.html('<i class="fas fa-eye"></i> Publish Trip');
statusBadge.html('<span class="badge bg-warning">Draft</span>');
}
// Show success message
alert(response.message);
} else {
alert('Error: ' + response.message);
}
},
error: function(xhr, status, error) {
console.log('Error:', error);
alert('Error updating trip status');
}
});
}
</script>
<?php include_once(dirname(dirname(dirname(__DIR__))) . '/components/insta_footer.php') ?>