Files
4WDCSA.co.za/src/pages/gallery/gallery.php
twotalesanimation e6d298c506 fix: correct require paths and database connection in album processors
- Fix rootPath calculation in all album processors (was going up too many levels)
- Use global \ from connection.php instead of calling openDatabaseConnection()
- Fix cleanup code in save_album.php to use existing \
- Update all processors to use proper config file includes (env.php, session.php, connection.php, functions.php)
- Ensures validateCSRFToken() and other functions are properly available
2025-12-05 09:59:05 +02:00

324 lines
11 KiB
PHP

<?php
$headerStyle = 'light';
$rootPath = dirname(dirname(dirname(__DIR__)));
include_once($rootPath . '/header.php');
// Check if user has active membership
if (!isset($_SESSION['user_id'])) {
header('Location: login');
exit;
}
$is_member = getUserMemberStatus($_SESSION['user_id']);
if (!$is_member) {
header('Location: index');
exit;
}
$conn = openDatabaseConnection();
// Fetch all albums with creator information
$albums_query = "
SELECT
pa.album_id,
pa.title,
pa.description,
pa.cover_image,
pa.created_at,
u.user_id,
u.first_name,
u.last_name,
u.profile_pic,
COUNT(p.photo_id) as photo_count
FROM photo_albums pa
INNER JOIN users u ON pa.user_id = u.user_id
LEFT JOIN photos p ON pa.album_id = p.album_id
GROUP BY pa.album_id
ORDER BY pa.created_at DESC
";
$result = $conn->query($albums_query);
$albums = [];
if ($result && $result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
$albums[] = $row;
}
}
$conn->close();
?>
<style>
.album-carousel-container {
margin: 30px 0;
}
.carousel-item-album {
display: none;
text-align: center;
padding: 20px;
animation: fadeIn 0.5s;
}
.carousel-item-album.active {
display: block;
}
@keyframes fadeIn {
from { opacity: 0; }
to { opacity: 1; }
}
.album-card {
background: white;
border-radius: 10px;
overflow: hidden;
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
transition: transform 0.3s;
}
.album-card:hover {
transform: translateY(-5px);
box-shadow: 0 4px 16px rgba(0,0,0,0.15);
}
.album-cover {
width: 100%;
height: 300px;
object-fit: cover;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}
.album-info {
padding: 20px;
}
.album-title {
font-size: 1.5rem;
font-weight: 600;
color: #2c3e50;
margin-bottom: 10px;
}
.album-description {
color: #666;
font-size: 0.95rem;
margin-bottom: 15px;
line-height: 1.5;
}
.album-meta {
display: flex;
align-items: center;
margin-bottom: 15px;
gap: 10px;
}
.album-avatar {
width: 40px;
height: 40px;
border-radius: 50%;
object-fit: cover;
border: 2px solid #667eea;
}
.album-creator {
flex: 1;
}
.creator-name {
font-weight: 600;
color: #2c3e50;
display: block;
font-size: 0.9rem;
}
.photo-count {
font-size: 0.85rem;
color: #999;
}
.album-actions {
display: flex;
gap: 10px;
}
.carousel-nav {
display: flex;
justify-content: center;
align-items: center;
gap: 20px;
margin-top: 20px;
}
.carousel-btn {
background: #667eea;
color: white;
border: none;
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
font-weight: 500;
transition: background 0.3s;
}
.carousel-btn:hover {
background: #764ba2;
}
.carousel-btn:disabled {
background: #ccc;
cursor: not-allowed;
}
.carousel-counter {
font-weight: 600;
color: #2c3e50;
min-width: 80px;
text-align: center;
}
.create-album-btn {
display: inline-block;
margin-bottom: 30px;
}
.no-albums {
text-align: center;
padding: 60px 20px;
color: #999;
}
.no-albums p {
font-size: 1.1rem;
margin-bottom: 20px;
}
</style>
<?php
$pageTitle = 'Photo Gallery';
$breadcrumbs = [['Home' => 'index.php'], ['Members Area' => '#']];
require_once($rootPath . '/components/banner.php');
?>
<section class="tour-list-page py-100 rel">
<div class="container">
<div class="row">
<div class="col-lg-12">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 30px;">
<h2>Member Photo Gallery</h2>
<a href="create_album" class="theme-btn create-album-btn">
<i class="far fa-plus"></i> Create Album
</a>
</div>
<?php if (count($albums) > 0): ?>
<div class="album-carousel-container">
<div id="albumCarousel">
<?php foreach ($albums as $index => $album): ?>
<div class="carousel-item-album <?php echo $index === 0 ? 'active' : ''; ?>">
<div class="row">
<div class="col-lg-6">
<?php if ($album['cover_image']): ?>
<img src="<?php echo htmlspecialchars($album['cover_image']); ?>" alt="<?php echo htmlspecialchars($album['title']); ?>" class="album-cover" style="border-radius: 10px;">
<?php else: ?>
<div class="album-cover" style="display: flex; align-items: center; justify-content: center; font-size: 3rem; color: white;">
<i class="far fa-image"></i>
</div>
<?php endif; ?>
</div>
<div class="col-lg-6">
<div class="album-info" style="text-align: left; height: 100%; display: flex; flex-direction: column; justify-content: space-between;">
<div>
<h3 class="album-title"><?php echo htmlspecialchars($album['title']); ?></h3>
<?php if ($album['description']): ?>
<p class="album-description"><?php echo htmlspecialchars($album['description']); ?></p>
<?php endif; ?>
</div>
<div>
<div class="album-meta">
<img src="<?php echo htmlspecialchars($album['profile_pic']); ?>" alt="<?php echo htmlspecialchars($album['first_name']); ?>" class="album-avatar">
<div class="album-creator">
<span class="creator-name"><?php echo htmlspecialchars($album['first_name'] . ' ' . $album['last_name']); ?></span>
<span class="photo-count"><?php echo $album['photo_count']; ?> photo<?php echo $album['photo_count'] !== 1 ? 's' : ''; ?></span>
</div>
</div>
<div class="album-actions">
<a href="view_album?id=<?php echo $album['album_id']; ?>" class="theme-btn style-two">
View Album <i class="far fa-arrow-right ms-2"></i>
</a>
<?php if ($album['user_id'] == $_SESSION['user_id']): ?>
<a href="edit_album?id=<?php echo $album['album_id']; ?>" class="theme-btn" style="background: #666;">
Edit
</a>
<?php endif; ?>
</div>
</div>
</div>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
<?php if (count($albums) > 1): ?>
<div class="carousel-nav">
<button class="carousel-btn" id="prevBtn" onclick="changeSlide(-1)">
<i class="far fa-chevron-left"></i> Previous
</button>
<div class="carousel-counter">
<span id="currentSlide">1</span> / <span id="totalSlides"><?php echo count($albums); ?></span>
</div>
<button class="carousel-btn" id="nextBtn" onclick="changeSlide(1)">
Next <i class="far fa-chevron-right"></i>
</button>
</div>
<?php endif; ?>
</div>
<?php else: ?>
<div class="no-albums">
<i class="far fa-image" style="font-size: 4rem; color: #ddd; margin-bottom: 20px; display: block;"></i>
<p>No photo albums yet. Be the first to create one!</p>
<a href="create_album" class="theme-btn">Create Album</a>
</div>
<?php endif; ?>
</div>
</div>
</div>
</section>
<script>
let currentSlide = 0;
const slides = document.querySelectorAll('.carousel-item-album');
const totalSlides = slides.length;
function updateCarousel() {
slides.forEach((slide, index) => {
slide.classList.remove('active');
if (index === currentSlide) {
slide.classList.add('active');
}
});
document.getElementById('currentSlide').textContent = currentSlide + 1;
document.getElementById('prevBtn').disabled = currentSlide === 0;
document.getElementById('nextBtn').disabled = currentSlide === totalSlides - 1;
}
function changeSlide(direction) {
currentSlide += direction;
if (currentSlide < 0) currentSlide = 0;
if (currentSlide >= totalSlides) currentSlide = totalSlides - 1;
updateCarousel();
}
// Initialize carousel
if (totalSlides > 1) {
updateCarousel();
}
</script>
<?php include_once(dirname(dirname(dirname(__DIR__))) . '/components/insta_footer.php'); ?>