Skip to content

Commit

Permalink
Merge pull request #221 from DasunThathsara/view_security_profile
Browse files Browse the repository at this point in the history
feat: view security data and send and cancel request
  • Loading branch information
DasunThathsara authored Dec 28, 2023
2 parents 4e0e7a2 + b38cd5c commit b8444a1
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 62 deletions.
12 changes: 10 additions & 2 deletions app/controllers/Land.php
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ public function cancelRequest(){
}

// View security
public function viewSecurity($security_ID = null){
public function viewSecurity($land_ID = null, $security_ID = null){
if (sizeof($_GET) > 1){
$data = [
'id' => trim($_GET['id'])
Expand All @@ -601,11 +601,19 @@ public function viewSecurity($security_ID = null){
}
else{
$data = [
'id' => $security_ID
'id' => $security_ID,
'lid' => $land_ID
];

$security = $this->securityModel->viewSecurityProfile($data);

$pendingSec = $this->securityModel->getSecurityPendingList($land_ID);

$security['pending_securities'] = array();
foreach ($pendingSec as $sec){
$security['pending_securities'][] = $sec->sid;
}

$security['notification_count'] = 0;

if ($security['notification_count'] < 10)
Expand Down
2 changes: 1 addition & 1 deletion app/views/parkingOwner/securities/add.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@

// Set the parking view link
if (tileLink) {
tileLink.href = `<?php echo URLROOT?>/land/viewSecurity/${security.id}`;
tileLink.href = `<?php echo URLROOT?>/land/viewSecurity/${<?php print_r($other_data['id'])?>}/${security.id}`;
} else {
console.error("Anchor element with class 'tile' not found in the cloned card:", card);
}
Expand Down
104 changes: 45 additions & 59 deletions app/views/parkingOwner/securities/viewProfile.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
<?php
print_r($other_data[0]);
?>

<?php require APPROOT.'/views/inc/header.php'; ?>
<!-- TOP NAVIGATION -->
<?php //require APPROOT.'/views/inc/components/topnavbar.php'; ?>

<?php require APPROOT.'/views/inc/components/topnavbar.php'; ?>
<!-- SIDE NAVIGATION -->
<?php
$section = 'profile';
Expand All @@ -23,87 +18,78 @@
</div>
<?php } ?>

<form action="<?php echo URLROOT ?>/users/updateProfile" method="post" enctype="multipart/form-data">
<form action="" method="post" id="request-form">
<input type="text" name="landID" id="landID" hidden value="<?php echo $data['lid']?>" />
<input type="text" name="securityID" id="securityID" hidden value="<?php echo $data['id']?>" />

<div class="profile-container">
<?php if($_SESSION['profile_photo']){ ?>
<img class="profile-pic" id="preview" src="<?php echo URLROOT ?>/profile_pics/<?php echo $data['profile_photo']?>" alt="<?php echo $_SESSION['user_name'] ?>">
<?php if($other_data[0]->profilePhoto){ ?>
<img class="profile-pic" id="preview" src="<?php echo URLROOT ?>/profile_pics/<?php echo $other_data[0]->profilePhoto ?>" alt="<?php echo $_SESSION['user_name'] ?>">
<?php }
else{ ?>
<img class="profile-pic" id="preview" src="<?php echo URLROOT ?>/images/user.png" alt="<?php echo $_SESSION['user_name'] ?>">
<?php } ?>

<div class="profile-dropdown-container">
<img class="profile-pic-edit" src="<?php echo URLROOT ?>/images/edit-solid.svg" alt="" onclick="dropdownBtn()">
<div class="profile-dropdown-content">
<input type="file" id="profile_photo" name="profile_photo" hidden onchange="previewImage(this)"/>
<label for="profile_photo" class="dropdown-item" onclick="dropdownBtn()">Choose File</label>
<a class="dropdown-item" href="<?php echo URLROOT ?>/users/profilePhotoRemove" onclick="return confirmSubmit();">Remove photo</a>
</div>
</div>
</div>

<!-- Username -->
<div class="form-input-title">Username:</div>
<input type="text" name="username" id="username" required value="<?php echo $data['username'] ?>" />

<!-- Name -->
<div class="form-input-title">Name:</div>
<input type="text" name="name" id="name" required value="<?php echo $data['name'] ?>" />
<p><?php echo $other_data[0]->name ?></p>

<!-- Email -->
<div class="form-input-title">Email:</div>
<input type="email" name="email" id="email" required value="<?php echo $data['email'] ?>" />
<p><?php echo $other_data[0]->email ?></p>

<!-- Contact number -->
<div class="form-input-title">Contact number:</div>
<input type="text" name="contact_no" id="contact_no" required value="<?php echo $data['contact_no'] ?>" />
<p><?php echo $other_data[0]->contactNo ?></p>

<!-- NIC -->
<div class="form-input-title">NIC:</div>
<p><?php echo $other_data[0]->NIC ?></p>

<!-- Address -->
<div class="form-input-title">Address:</div>
<p><?php echo $other_data[0]->address ?></p>

<!-- District -->
<div class="form-input-title">District:</div>
<p><?php echo $other_data[0]->preferredDistrictToWork ?></p>

<!-- Province -->
<div class="form-input-title">Province:</div>
<p><?php echo $other_data[0]->preferredProvinceToWork ?></p>

<!-- Experience -->
<div class="form-input-title">Experience:</div>
<?php if ($other_data[0]->experience) {?>
<p><?php echo $other_data[0]->experience ?></p>
<?php } else{ ?>
<p>No experience</p>
<?php } ?>

<br><br>

<!-- Submit -->
<input type="submit" value="Submit">
<input type="submit" value="" id="submit-btn">
</form>
</div>
</div>
</section>
</main>

<script>
const actualBtn = document.getElementById('profile_photo');

actualBtn.addEventListener('change', function(){
fileChosen.textContent = this.files[0].name;
previewImage(this);
});

function previewImage(input) {
const preview = document.getElementById('preview');
const file = input.files[0];
const reader = new FileReader();

reader.onloadend = function () {
preview.src = reader.result;
}

if (file) {
reader.readAsDataURL(file);
} else {
preview.src = "<?php echo URLROOT ?>/images/user.png";
}
const pendingSecurityData = <?php echo json_encode($other_data['pending_securities']); ?>;
const requestForm = document.getElementById('request-form'); // Remove the dot before 'request-form'
const submitButton = document.getElementById('submit-btn'); // Remove the dot before 'submit-btn'

if (pendingSecurityData.includes(<?php print_r($data['id']); ?>)) { // Wrap $data['lid'] in quotes
requestForm.setAttribute("action", '<?php echo URLROOT ?>/land/cancelRequest');
submitButton.setAttribute("value", "Cancel request");
} else {
requestForm.setAttribute("action", '<?php echo URLROOT ?>/land/sendRequest');
submitButton.setAttribute("value", "Send request");
}

function confirmSubmit() {
return confirm("Are you sure you want to remove your profile photo?");
}

function dropdownBtn() {
var element1, element2;
element1 = document.querySelector('.profile-dropdown-content');
element1.classList.toggle("profile-dropdown-content-active");

element2 = document.querySelector('.profile-pic-edit');
element2.classList.toggle("profile-pic-edit-active");
}
</script>

<?php require APPROOT.'/views/inc/footer.php'; ?>

0 comments on commit b8444a1

Please sign in to comment.