web_php/hotel_booking/admin/users.php

127 lines
No EOL
4.6 KiB
PHP

<?php
require('components/utils.php');
require('components/db_config.php');
adminLogin();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Admin Dashboard-users | Midtown Hotel</title>
<?php require('components/link.php') ?>
<style>
.custom-alert-t{
position:fixed;
top: 100px;
right: 25px;
z-index: 10000;
}
</style>
</head>
<body>
<?php require('components/sidebar.php')?>
<div class="container-fluid" id="dashboard-body">
<div class="row">
<div class="col-lg-10 ms-auto p-4 overflow-hidden">
<h4 class="mb-4">Users</h4>
<div class="card mb-4">
<div class="card-body">
<div class="mb-4 text-end">
<input type="text" oninput="search_users(this.value)" class="form-control w-25 ms-auto shadow-none" placeholder="Search">
</div>
<div class="table-responsive">
<table class="table table-hover border">
<thead>
<tr style="background-color: #D3D3D3;">
<th scope="col">#</th>
<th scope="col">Firstname</th>
<th scope="col">Lastname</th>
<th scope="col">Email</th>
<th scope="col">Phone</th>
<th scope="col">Address</th>
<th scope="col">Birthday</th>
<th scope="col">Verify</th>
<th scope="col">Status</th>
<th scope="col">Date</th>
<th scope="col">Action</th>
</tr>
</thead>
<tbody id="users_data">
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
<?php require('components/script.php') ?>
<script>
function get_users(){
let xhr = new XMLHttpRequest();
xhr.open("POST", "ajax/users.php", true);
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xhr.onload = function(){
document.getElementById('users_data').innerHTML = this.responseText;
}
xhr.send('get_users');
}
function toggleStatus(id, val){
let xhr = new XMLHttpRequest();
xhr.open("POST", "ajax/users.php", true);
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xhr.onload = function(){
if(this.responseText == 1){
alert('success', 'Active');
get_users();
} else{
alert('success', 'Inactive');
}
}
xhr.send('toggleStatus='+id+'&value='+val);
}
function remove_user(user_id){
if(confirm("Are you sure you want to delete this user?")){
let data = new FormData();
data.append('user_id', room_id);
data.append('remove_user', '');
let xhr = new XMLHttpRequest();
xhr.open("POST", "ajax/users.php", true)
xhr.onload = function(){
if(this.responseText == 1){
alert('success', 'Delete user');
get_users();
} else{
alert('error', 'Fail to delete this user');
}
}
xhr.send(data);
}
}
function search_users(username){
let xhr = new XMLHttpRequest();
xhr.open("POST", "ajax/users.php", true);
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xhr.onload = function(){
document.getElementById('users_data').innerHTML = this.responseText;
}
xhr.send('search_users&firstname='+username);
}
window.onload = function(){
get_users();
}
</script>
</body>
</html>