-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
171 lines (148 loc) · 6.94 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<?php
session_start();
include "koneksi.php";
$search = isset($_GET['search']) ? $_GET['search'] : '';
// Query untuk menghitung jumlah total hasil pencarian
$total_results_query = mysqli_query($conn, "SELECT COUNT(*) as total FROM foto
INNER JOIN album ON foto.albumid = album.albumid
INNER JOIN user ON foto.userid = user.userid
WHERE album.acceslevel = 'public' AND judulfoto LIKE '%$search%'");
$total_results_row = mysqli_fetch_assoc($total_results_query);
$total_results = $total_results_row['total'];
// Jumlah item per halaman
$items_per_page = 12;
// Menghitung jumlah halaman
$total_pages = ceil($total_results / $items_per_page);
// Mendapatkan halaman saat ini
$current_page = isset($_GET['page']) ? $_GET['page'] : 1;
// Mendapatkan offset (mulai dari mana data ditampilkan)
$offset = ($current_page - 1) * $items_per_page;
// Query untuk mendapatkan data foto sesuai dengan halaman saat ini, diurutkan berdasarkan tanggal_upload secara descending
$sql = mysqli_query($conn, "SELECT * FROM foto
INNER JOIN album ON foto.albumid = album.albumid
INNER JOIN user ON foto.userid = user.userid
WHERE album.acceslevel = 'public' AND judulfoto LIKE '%$search%'
ORDER BY foto.tanggalunggah DESC LIMIT $items_per_page OFFSET $offset");
function getUserProfile($conn, $userid)
{
$query = mysqli_query($conn, "SELECT * FROM user WHERE userid = $userid");
return mysqli_fetch_assoc($query);
}
$user = isset($_SESSION['userid']) ? getUserProfile($conn, $_SESSION['userid']) : null;
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Halaman Landing</title>
<link rel="stylesheet" href="./css/all.min.css">
<link rel="stylesheet" href="./css/fontawesome.min.css">
<link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.0.2/dist/tailwind.min.css" rel="stylesheet">
<!-- Font Awesome 6 CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css"
integrity="sha512-KyZXEAg3QhqLMpG8r+Knujsl5+z0I5t9zwnlOP6a7tRO0pgdeU4jre0o9W6cd9c3i8a7b/Dmm7vcubGcRtIUUQ=="
crossorigin="anonymous" referrerpolicy="no-referrer" />
<style>
.like-button {
position: absolute;
top: -9999px;
right: -9999px;
z-index: 1;
transition: transform 0.3s ease;
}
.like-button.show {
top: 10px;
right: 10px;
}
.like-button:hover {
transform: scale(1.2);
}
.like-icon {
font-size: 1.5rem;
}
</style>
</head>
<body class="font-sans bg-gray-100" >
<?php include 'navbar.php'; ?>
<div class="p-10">
<h1 class="text-3xl text-center text-gray-800 font-semibold">Selamat Datang di Fotopia</h1>
<?php if(isset($_SESSION['userid'])): ?>
<p class="text-center mt-4">Selamat datang <b><?= $_SESSION['namalengkap'] ?></b></p>
<?php endif; ?>
</div>
<div class="container mx-auto mt-8 p-4 grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-4">
<?php
while ($data = mysqli_fetch_array($sql)) {
?>
<div class="relative bg-white border rounded-md overflow-hidden shadow-md transform transition-transform ease-in-out hover:scale-105">
<!-- Container for image -->
<div class="relative" style="padding-bottom: 56.25%;">
<!-- Padding bottom 56.25% for 16:9 ratio -->
<a href="detail.php?fotoid=<?= $data['fotoid'] ?>">
<img src="gambar/<?= $data['lokasifile'] ?>" alt="<?= $data['judulfoto'] ?>" class="absolute inset-0 w-full h-full object-cover rounded-md">
</a>
</div>
<!-- Like button -->
<div class="like-button">
<?php
if (isset($_SESSION['userid'])) {
$sql_check_like = mysqli_query($conn, "SELECT * FROM likefoto WHERE fotoid='{$data['fotoid']}' AND userid='{$_SESSION['userid']}'");
$liked = mysqli_num_rows($sql_check_like) > 0;
$heart_icon_class = $liked ? "fa-solid fa-heart text-red-500" : "fa-regular fa-heart text-gray-500";
?>
<a href="like.php?fotoid=<?= $data['fotoid'] ?>" class="like-icon"><i class="fa <?= $heart_icon_class ?>"></i></a>
<?php
} else {
// Jika pengguna belum login, munculkan tombol like tetapi non-aktif
?>
<a href="login.php" class="like-icon"><i class="fa fa-regular fa-heart text-gray-500"></i></a>
<?php
}
?>
</div>
<!-- Container for text -->
<div class="p-4">
<div class="text-lg font-bold mb-2"><?= $data['judulfoto'] ?></div>
<p class="text-sm text-gray-700"><?= $data['deskripsifoto'] ?></p>
<div class="flex justify-between items-center mt-2">
<span><?= $data['namalengkap'] ?></span>
<span>like <?php echo mysqli_num_rows(mysqli_query($conn, "SELECT * FROM likefoto WHERE fotoid={$data['fotoid']}")); ?></span>
</div>
</div>
</div>
<?php
}
?>
</div>
<!-- Pagination -->
<div class="container mx-auto mt-8 p-4">
<ul class="flex justify-center space-x-4">
<?php
// Generate pagination links
for ($page = 1; $page <= $total_pages; $page++) {
echo '<li><a href="?search=' . $search . '&page=' . $page . '" class="px-4 py-2 bg-blue-500 text-white rounded-md hover:bg-blue-600">' . $page . '</a></li>';
}
?>
</ul>
</div>
<footer class="bg-gray-800 text-white p-4 text-center">
<p>© 2024 Fotopia. All rights reserved.</p>
</footer>
<script>
document.addEventListener("DOMContentLoaded", function () {
const photoContainers = document.querySelectorAll(".relative");
photoContainers.forEach(container => {
container.addEventListener("mouseover", function () {
const likeButton = container.querySelector(".like-button");
likeButton.classList.add("show");
});
container.addEventListener("mouseleave", function () {
const likeButton = container.querySelector(".like-button");
likeButton.classList.remove("show");
});
});
});
</script>
</body>
</html>