-
Notifications
You must be signed in to change notification settings - Fork 0
/
adminusers.php
86 lines (79 loc) · 3.43 KB
/
adminusers.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
<?php
include "./koneksi.php";
session_start();
if (!isset($_SESSION['userid'])) {
header("location:login.php");
}
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>View Users</title>
<link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.0.2/dist/tailwind.min.css" rel="stylesheet">
<!-- Add this line to your head section -->
<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" />
</head>
<body class="font-sans bg-gray-100">
<?php
// Check user role to determine the redirection link
if ($_SESSION['role'] === 'admin') {
?>
<?php include 'adminnavbar.php'; ?>
<?php
} else {
?>
<?php
include 'navbar.php';
?>
<?php
}
?>
<div class="bg-white p-4">
<h1 class="text-3xl text-center text-gray-800">Halaman User</h1>
<p class="text-center mt-2">Selamat datang <b><?= $_SESSION['namalengkap'] ?></b></p>
</div>
<div class="container mx-auto mt-8 p-4">
<!-- Search Form -->
<form action="" method="get" class="mb-4">
<input type="text" name="search" placeholder="Search by Username" class="border p-2 rounded">
<button type="submit" class="bg-blue-500 text-white px-4 py-2 rounded">Search</button>
</form>
<!-- User Cards -->
<div class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-4">
<?php
include "koneksi.php";
// Check if the search parameter is set
if (isset($_GET['search'])) {
$search = mysqli_real_escape_string($conn, $_GET['search']);
$result = mysqli_query($conn, "SELECT * FROM user WHERE username LIKE '%$search%'");
} else {
// If no search parameter, fetch all users
$result = mysqli_query($conn, "SELECT * FROM user");
}
while ($userData = mysqli_fetch_assoc($result)) {
?>
<div class="bg-white border rounded-md overflow-hidden shadow-md transform transition-transform ease-in-out hover:scale-105">
<!-- Customize the content based on user data -->
<div class="p-4">
<div class="text-lg font-bold mb-2"><?= $userData['namalengkap'] ?></div>
<p class="text-sm text-gray-700">Username: <?= $userData['username'] ?></p>
<p class="text-sm text-gray-700">Email: <?= $userData['email'] ?></p>
<p class="text-sm text-gray-700">Address: <?= $userData['alamat'] ?></p>
<p class="text-sm text-gray-700">Type: <?= $userData['role'] ?></p>
</div>
</div>
<?php
}
?>
</div>
</div>
</body>
</html>