Skip to content

Commit

Permalink
Merge pull request #255 from DasunThathsara/admins_view
Browse files Browse the repository at this point in the history
Assigning land registration verification to them selves
  • Loading branch information
DasunThathsara authored Feb 8, 2024
2 parents eccb6b4 + a88d48c commit 357e25a
Show file tree
Hide file tree
Showing 6 changed files with 232 additions and 150 deletions.
24 changes: 23 additions & 1 deletion app/controllers/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,26 @@ public function unverifyLand(){
redirect('admin/viewRegistrationRequests');
}
}
}

// Assign land verification to admin
public function assignLandVerification(){
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
$_POST = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING);

$this->landModel->assignLandVerification($_POST['id'], $_SESSION['user_id']);

redirect('admin/requests');
}
}

// Assign registration requests to admin
public function assignMySelf(){
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
$_POST = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING);

$this->landModel->assignMySelf($_POST['id'], $_SESSION['user_id']);

redirect('admin/viewRegistrationRequests');
}
}
}
21 changes: 20 additions & 1 deletion app/models/LandModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ public function getLandID($name){

public function getUnVerifyLandCount(){
// Prepare statement
$this->db->query('SELECT COUNT(*) FROM land WHERE status = :status');
$this->db->query('SELECT COUNT(*) FROM land WHERE status = :status AND admin = 0');

// Bind values
$this->db->bind(':status', 0);
Expand Down Expand Up @@ -607,4 +607,23 @@ public function getLandownerID($landID){

return $row->uid;
}

// Assign land verification to admin
public function assignMySelf($landID, $adminID): bool
{
// Prepare statement
$this->db->query('UPDATE land SET admin = :admin WHERE id = :id');

// Bind values
$this->db->bind(':admin', $adminID);
$this->db->bind(':id', $landID);

// Execute
if ($this->db->execute()){
return true;
}
else {
return false;
}
}
}
208 changes: 109 additions & 99 deletions app/views/admin/requests.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,53 +11,124 @@
<main class="page-container">
<section class="section" id="main">
<div class="container">
<h1>Requests</h1>
<h1>Registration Requests</h1>

<br><br>
<?php if (sizeof($data) == 0) {?>
<div class="emptyLand">There are no any requests</div>
<?php if (sizeof($data) == 1) {?>
<div class="emptyVehicle">You have no any registered vehicles</div>
<?php }
else {?>
<!-- Search bar -->
<input type="search" class="data-search" placeholder="Search.." style="top: 50px;">

<!-- Card set -->
<div class="user-cards" style="margin-top: 0;"></div>
<template class="data-user-template">
<div class="card">
<a href="" class="tile">
<table>
<tr>
<td>
<div style="display: flex; width: 50%">
<div>
<p class="name" style="width: 150px;" data-header></p>
<h1>Unassigned</h1>
<div class="table-container">
<table class="table">
<tr>
<th width="60px">
<div class="content" style="display:flex;">
<div class="left" style="width:31%">
Name
</div>
<div class="left" style="width:20%; padding-left:5px">
City
</div>
</div>
</th>
</tr>

<?php for ($i = 0; $i < sizeof($data) - 1; $i++) {
if ($data[$i]->admin != 0) {
continue;
}?>
<tr>
<td>
<a class="tile">
<div class="content">
<div class="left" style="width:30%">
<?php echo $data[$i]->name ?>
</div>
<div>
<p class="city" data-header></p>
<div class="left" style="width:20%">
<?php echo $data[$i]->city ?>
</div>
<div class="right">
<form action="<?php echo URLROOT ?>/admin/verifyLand" method="post" class="update-form">
<input type="text" name="id" id="id" hidden value="<?php echo $data[$i]->id ?>" />
<button type="submit" class="edit" onclick="return confirmSubmit();">
<img src="<?php echo URLROOT ?>/images/tick.svg" style="width: 18px" alt="">
</button>
</form>
&nbsp;
<form action="<?php echo URLROOT ?>/admin/unverifyLand" method="post" class="delete-form">
<input type="text" name="id" id="id" hidden value="<?php echo $data[$i]->id ?>" />
<button type="submit" class="delete" onclick="return confirmSubmit();">
<img src="<?php echo URLROOT ?>/images/circle-xmark-regular.svg" style="width: 18px;" alt="">
</button>
</form>
&nbsp;
<form action="<?php echo URLROOT ?>/admin/assignMySelf" method="post" class="delete-form">
<input type="text" name="id" id="id" hidden value="<?php echo $data[$i]->id ?>" />
<button type="submit" class="delete" onclick="return confirmSubmit();" style="background-color: #fcd426; padding: 5px 10px;">
Assign myself
</button>
</form>
</div>
</div>
</td>
<td class="options"> &nbsp;
<form action="<?php echo URLROOT ?>/admin/verifyLand" method="post" class="update-form">
<input type="text" name="id" id="id" hidden value="" />
<button type="submit" class="edit" onclick="return confirmSubmit();">
<img src="<?php echo URLROOT ?>/images/tick.svg" style="width: 18px" alt="">
</button>
</form>
&nbsp;
<form action="<?php echo URLROOT ?>/admin/unverifyLand" method="post" class="delete-form">
<input type="text" name="id" id="id" hidden value="" />
<button type="submit" class="delete" onclick="return confirmSubmit();">
<img src="<?php echo URLROOT ?>/images/circle-xmark-regular.svg" style="width: 18px;" alt="">
</button>
</form>
</a>
</td>
</tr>
<?php } ?>
</table>
</div>

<h1>Assigned</h1>
<div class="table-container">
<table class="table">
<tr>
<th width="60px">
<div class="content" style="display:flex;">
<div class="left" style="width:31%">
Name
</div>
<div class="left" style="width:20%; padding-left:5px">
City
</div>
</div>
</th>
</tr>

<?php for ($i = 0; $i < sizeof($data) - 1; $i++) {
if ($data[$i]->admin == $_SESSION['user_id']) {?>
<tr>
<td>
<a class="tile">
<div class="content">
<div class="left" style="width:30%">
<?php echo $data[$i]->name ?>
</div>
<div class="left" style="width:20%">
<?php echo $data[$i]->city ?>
</div>
<div class="right">
<form action="<?php echo URLROOT ?>/admin/verifyLand" method="post" class="update-form">
<input type="text" name="id" id="id" hidden value="<?php echo $data[$i]->id ?>" />
<button type="submit" class="edit" onclick="return confirmSubmit();">
<img src="<?php echo URLROOT ?>/images/tick.svg" style="width: 18px" alt="">
</button>
</form>
&nbsp;
<form action="<?php echo URLROOT ?>/admin/unverifyLand" method="post" class="delete-form">
<input type="text" name="id" id="id" hidden value="<?php echo $data[$i]->id ?>" />
<button type="submit" class="delete" onclick="return confirmSubmit();">
<img src="<?php echo URLROOT ?>/images/circle-xmark-regular.svg" style="width: 18px;" alt="">
</button>
</form>
</div>
</div>
</a>
</td>
</tr>
</table>
</a>
</div>
</template>
<?php }?>
<?php } ?>
</table>
</div>
<?php } ?>
</div>
</section>
Expand All @@ -67,66 +138,5 @@
function confirmSubmit() {
return confirm("Are you sure you want to delete this land?");
}

// ------------------------------- Search Bar -------------------------------
const userCardTemplate = document.querySelector(".data-user-template");
const searchInput = document.querySelector(".data-search");

searchInput.addEventListener("input", (data) => {
const value = data.target.value.toLowerCase();
lands.forEach(land => {
const isVisible = land.name.toLowerCase().includes(value) || land.city.toLowerCase().includes(value) || land.street.toLowerCase().includes(value);
if (land.element) {
land.element.classList.toggle("hide", !isVisible);
}
});
});

let lands = [];
var backendData = <?php echo json_encode($data); ?>;

lands = backendData.map(land => {
const card = userCardTemplate.content.cloneNode(true).children[0];
console.log(card);
card.querySelector(".name").textContent = land.name;
card.querySelector(".city").textContent = land.city;
document.querySelector(".user-cards").appendChild(card);
const tileLink = card.querySelector('.tile');

// Set the parking view link
if (tileLink) {
tileLink.href = `viewRegistrationRequestedLand/${land.id}`;
} else {
console.error("Anchor element with class 'tile' not found in the cloned card:", card);
}


// Set id and name to delete the land
const deleteForm = card.querySelector('.delete-form');
if (deleteForm) {
const idInput = deleteForm.querySelector('#id');

if (idInput) {
idInput.value = land.id; // Set the value dynamically
} else {
console.error("Form input with id 'name' not found in the cloned card:", card);
}
}


// Set values to go to the update page
const updateForm = card.querySelector('.update-form');
if (updateForm) {
const idInput = updateForm.querySelector('#id');

if (idInput) {
idInput.value = land.id;
} else {
console.error("One or more form inputs not found in the cloned card:", card);
}
}

return { id: land.id, name: land.name, city: land.city, street: land.street, element: card };
});
</script>
<?php require APPROOT.'/views/inc/footer.php'; ?>
3 changes: 3 additions & 0 deletions app/views/parkingOwner/lands.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@
<div class="emptyLand">You have no any registered lands</div>
<?php }
else {?>
<!-- Titles of the table -->
<div class="title-options">
<div class="all-lands option-item option-item-active">All Lands</div>
<div class="available-lands option-item">Available</div>
<div class="unavailable-lands option-item">Unavailable</div>
</div>

<hr class="option-break" />

<!-- Search area -->
<div class="search-area">
<!-- Search bar -->
Expand Down
Loading

0 comments on commit 357e25a

Please sign in to comment.