Added Staff Accomodation views
This commit is contained in:
parent
88cea3d0bb
commit
2f3925dd95
12 changed files with 265 additions and 20 deletions
|
@ -1,5 +1,5 @@
|
|||
<?php
|
||||
if ($_SESSION['USER']->isLoggedIn()) {
|
||||
if ($_SESSION['USER']->isLoggedIn() && $_SESSION['USER']->getType() == 'AccomodationOwner') {
|
||||
$accomodationType = ['Hôtel', 'Gîte', 'Camping', 'Villa en location'];
|
||||
$alert = '';
|
||||
$availableServices = AccomodationServices::getAll();
|
||||
|
@ -8,7 +8,7 @@ if ($_SESSION['USER']->isLoggedIn()) {
|
|||
if (isset($path[1])) {
|
||||
switch ($path[1]) {
|
||||
case 'add':
|
||||
if (!$_SESSION['USER']->getAccomodationId()) {
|
||||
if (!$_SESSION['USER']->getAccomodationId() && $_SESSION['USER']->getType() == 'AccomodationOwner') {
|
||||
/*
|
||||
* Creating Accomodation
|
||||
*/
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
|
||||
if(!$_SESSION['USER']->isLoggedIn() && !isset($path[1])) {
|
||||
$alert = '';
|
||||
if(isset($_POST['email'],$_POST['password'])){
|
||||
$user = new User;
|
||||
$userArray = $user->fetch(
|
||||
|
@ -9,7 +10,7 @@ if(!$_SESSION['USER']->isLoggedIn() && !isset($path[1])) {
|
|||
['passwordHash', '=', hash('sha256',$_POST['password'])]
|
||||
)
|
||||
);
|
||||
if(count($userArray) === 1){
|
||||
if(count($userArray) === 1 && in_array($userArray[0]->getType(), ['AccomodationOwner', 'Staff'])){
|
||||
/*
|
||||
* Successful login
|
||||
*/
|
||||
|
@ -19,6 +20,7 @@ if(!$_SESSION['USER']->isLoggedIn() && !isset($path[1])) {
|
|||
/*
|
||||
* Error message
|
||||
*/
|
||||
$alert = alert('danger', 'Information incorrectes.');
|
||||
}
|
||||
}
|
||||
require_once(VIEW_PATH . $path[0] . '.php');
|
||||
|
|
27
controller/manager.php
Normal file
27
controller/manager.php
Normal file
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
if ($_SESSION['USER']->isLoggedIn() && $_SESSION['USER']->getType() == 'Staff') {
|
||||
$alert = '';
|
||||
if (isset($path[1],$path[2]) && Accomodation::fetchById($path[1]) !== false) {
|
||||
switch ($path[2]) {
|
||||
case 'view':
|
||||
$hotel = Accomodation::fetchById($path[1]);
|
||||
$reservations = AccomodationReservation::fetchByAccomodationId($hotel->getId());
|
||||
require_once(VIEW_PATH . $path[2] . '_' . $path[0] . '.php');
|
||||
break;
|
||||
case 'add':
|
||||
break;
|
||||
case 'delete':
|
||||
if(getPost('email', false)){
|
||||
|
||||
}
|
||||
break;
|
||||
default:
|
||||
redirect();
|
||||
}
|
||||
} else {
|
||||
$hotels = Accomodation::fetch();
|
||||
require_once(VIEW_PATH . $path[0] . '.php');
|
||||
}
|
||||
} else {
|
||||
redirect('login');
|
||||
}
|
|
@ -40,6 +40,20 @@ class Accomodation extends Model
|
|||
{
|
||||
return $this->data['type'];
|
||||
}
|
||||
public function getServices()
|
||||
{
|
||||
$out = [];
|
||||
if(isset($this->data['id'])){
|
||||
$query = 'SELECT AccomodationServicesName FROM _AccomodationServices WHERE AccomodationId = ?;';
|
||||
$q = Accomodation::$db->prepare($query);
|
||||
$q->execute([$this->data['id']]);
|
||||
forEach($q->fetchAll(PDO::FETCH_ASSOC) as $item){
|
||||
$out[] = $item['AccomodationServicesName'];
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function insertUser(User $user, $data): bool
|
||||
{
|
||||
|
@ -73,20 +87,6 @@ class Accomodation extends Model
|
|||
}
|
||||
return false;
|
||||
}
|
||||
public function getServices()
|
||||
{
|
||||
$out = [];
|
||||
if(isset($this->data['id'])){
|
||||
$query = 'SELECT AccomodationServicesName FROM _AccomodationServices WHERE AccomodationId = ?;';
|
||||
$q = Accomodation::$db->prepare($query);
|
||||
$q->execute([$this->data['id']]);
|
||||
forEach($q->fetchAll(PDO::FETCH_ASSOC) as $item){
|
||||
$out[] = $item['AccomodationServicesName'];
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public function setServices(array $names)
|
||||
{
|
||||
/*
|
||||
|
|
69
models/AccomodationReservation.php
Normal file
69
models/AccomodationReservation.php
Normal file
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
|
||||
|
||||
class AccomodationReservation extends Model
|
||||
{
|
||||
private $data;
|
||||
|
||||
public function __construct($data = null)
|
||||
{
|
||||
parent::__construct();
|
||||
$_col = get_class()::getColumns();
|
||||
if($data !== null){
|
||||
forEach($data as $key=>$value){
|
||||
if(!key_exists($key, $_col)){
|
||||
throw new Exception('Invalid data entry');
|
||||
}else{
|
||||
$this->data[$key] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
/*
|
||||
* Getters
|
||||
*/
|
||||
public function getUserEmail(): string
|
||||
{
|
||||
if(isset($this->data['UserEmail']))
|
||||
return $this->data['UserEmail'];
|
||||
return false;
|
||||
}
|
||||
public function getAccomodationId(): string
|
||||
{
|
||||
if(isset($this->data['AccomodationId']))
|
||||
return $this->data['AccomodationId'];
|
||||
return false;
|
||||
}
|
||||
public function getPeopleCount(): string
|
||||
{
|
||||
if(isset($this->data['peopleCount']))
|
||||
return $this->data['peopleCount'];
|
||||
return false;
|
||||
}
|
||||
public function getStartDate(): string
|
||||
{
|
||||
if(isset($this->data['startDate']))
|
||||
return $this->data['startDate'];
|
||||
return false;
|
||||
}
|
||||
public function getEndDate(): string
|
||||
{
|
||||
if(isset($this->data['endDate']))
|
||||
return $this->data['endDate'];
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function fetchByAccomodationId(int $id)
|
||||
{
|
||||
$data = AccomodationReservation::fetch(array(['AccomodationId','=', $id]));
|
||||
return $data;
|
||||
}
|
||||
public static function fetchByUserEmail(string $email){
|
||||
$data = AccomodationReservation::fetch(array(['UserEmail','=', $email]));
|
||||
if(count($data) == 1){
|
||||
return $data[0];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -47,7 +47,6 @@ class User extends Model
|
|||
return $this->data['phoneNumber'];
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getType(): string
|
||||
{
|
||||
if(isset($this->data['UserTypeName']))
|
||||
|
|
|
@ -50,7 +50,7 @@ function alert($status , $msg){
|
|||
# Navbar button render
|
||||
function navItem($name, $path){
|
||||
$acc = '';
|
||||
if(($_SERVER['REQUEST_URI'] === WEBSITE_PATH . $path) || ($path === ($_SERVER["REQUEST_SCHEME"] . '://' . $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"]))){
|
||||
if((substr($_SERVER["REQUEST_SCHEME"] . '://' . $_SERVER["SERVER_NAME"] . $_SERVER['REQUEST_URI'], 0, strlen($path)) === $path) || ($path === ($_SERVER["REQUEST_SCHEME"] . '://' . $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"]))){
|
||||
$acc = 'active';
|
||||
}
|
||||
return '<li class="nav-item"><a class="nav-link ' .$acc. '" aria-current="page" href="' .htmlspecialchars($path). '">' .htmlspecialchars($name). '</a></li>';
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
<?php
|
||||
require_once('template/head.php');
|
||||
?>
|
||||
<div class="container-fluid section">
|
||||
<form action="">
|
||||
|
||||
</form>
|
||||
</div>
|
||||
<?php
|
||||
require_once('template/footer.php');
|
||||
?>
|
|
@ -5,6 +5,7 @@ require_once('template/head.php');
|
|||
<form class="form-signin" method="POST">
|
||||
<h1><?=WEBSITE_NAME?></h1>
|
||||
<h1 class="h3 mb-3 font-weight-normal">Please sign in</h1>
|
||||
<?=$alert?>
|
||||
<label for="inputEmail" class="sr-only">Email address</label>
|
||||
<input type="email" name="email" id="inputEmail" class="form-control" placeholder="Email address" required autofocus>
|
||||
<label for="inputPassword" class="sr-only">Password</label>
|
||||
|
|
39
view/manager.php
Normal file
39
view/manager.php
Normal file
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
require_once('template/head.php');
|
||||
?>
|
||||
<div class="container-fluid section">
|
||||
<h2>Gestions des réservations</h2>
|
||||
<table class="table table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">#</th>
|
||||
<th scope="col">Nom de logement</th>
|
||||
<th scope="col">Adresse</th>
|
||||
<th scope="col">Type</th>
|
||||
<th scope="col">Service(s)</th>
|
||||
<th scope="col">Nombre de Reservation(s)</th>
|
||||
<th scope="col">Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
foreach ($hotels as $hotel){
|
||||
?>
|
||||
<tr>
|
||||
<th scope="row"><?=$hotel->getId()?></th>
|
||||
<td><?=htmlspecialchars($hotel->getName())?></td>
|
||||
<td><?=htmlspecialchars($hotel->getAddress()) . ', ' . $hotel->getPostalCode() ?></td>
|
||||
<td><?=htmlspecialchars($hotel->getType())?></td>
|
||||
<td><?=$hotel->getServices() ? htmlspecialchars(join(',',$hotel->getServices())) : "Aucun" ?></td>
|
||||
<td>0</td>
|
||||
<td><a href="<?=genURL('manager/' . $hotel->getId() . '/view')?>" class="btn btn-primary">Editer une reservation</a></td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<?php
|
||||
require_once('template/footer.php');
|
||||
?>
|
|
@ -22,7 +22,7 @@
|
|||
}
|
||||
break;
|
||||
case 'Staff':
|
||||
echo navItem('Gestion des disponibilités',genURL('accomodation/manager'));
|
||||
echo navItem('Gestion des réservations',genURL('manager'));
|
||||
break;
|
||||
}
|
||||
}else{
|
||||
|
|
104
view/view_manager.php
Normal file
104
view/view_manager.php
Normal file
|
@ -0,0 +1,104 @@
|
|||
<?php
|
||||
require_once('template/head.php');
|
||||
?>
|
||||
<div class="container-fluid section">
|
||||
<h2>Gestions des réservations de "<?=htmlspecialchars($hotel->getName())?>"</h2>
|
||||
|
||||
<form class="row g-3 needs-validation justify-content-end" style="padding-top: 30px;">
|
||||
<div class="col-md-4">
|
||||
<div class="form-outline">
|
||||
<input
|
||||
type="text"
|
||||
class="form-control"
|
||||
id="validationCustom01"
|
||||
value="Mark"
|
||||
required
|
||||
/>
|
||||
<label for="validationCustom01" class="form-label">VIP</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<div class="form-outline">
|
||||
<input
|
||||
type="text"
|
||||
class="form-control"
|
||||
id="validationCustom02"
|
||||
value="Otto"
|
||||
required
|
||||
/>
|
||||
<label for="validationCustom02" class="form-label">Last name</label>
|
||||
<div class="valid-feedback">Looks good!</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<div class="input-group form-outline">
|
||||
<span class="input-group-text" id="inputGroupPrepend">@</span>
|
||||
<input
|
||||
type="text"
|
||||
class="form-control"
|
||||
id="validationCustomUsername"
|
||||
aria-describedby="inputGroupPrepend"
|
||||
required
|
||||
/>
|
||||
<label for="validationCustomUsername" class="form-label">Username</label>
|
||||
<div class="invalid-feedback">Please choose a username.</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="form-outline">
|
||||
<input type="text" class="form-control" id="validationCustom03" required />
|
||||
<label for="validationCustom03" class="form-label">City</label>
|
||||
<div class="invalid-feedback">Please provide a valid city.</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="form-outline">
|
||||
<input type="text" class="form-control" id="validationCustom05" required />
|
||||
<label for="validationCustom05" class="form-label">Zip</label>
|
||||
<div class="invalid-feedback">Please provide a valid zip.</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-1">
|
||||
<button class="btn btn-success" type="submit">Ajouter</button>
|
||||
</div>
|
||||
</form>
|
||||
<hr class="my-5">
|
||||
|
||||
|
||||
<table class="table table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">Email VIP</th>
|
||||
<th scope="col">Nombre d'occupants</th>
|
||||
<th scope="col">Date d'arrivée</th>
|
||||
<th scope="col">Date de sortie</th>
|
||||
<th scope="col">Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
forEach($reservations as $reservation){
|
||||
?>
|
||||
<tr>
|
||||
<th scope="row"><?=$reservation->getUserEmail()?></th>
|
||||
<td><?=$reservation->getPeopleCount()?></td>
|
||||
<td><?=$reservation->getStartDate()?></td>
|
||||
<td><?=$reservation->getEndDate()?></td>
|
||||
<td><button onclick="deleteReservation('<?=$reservation->getUserEmail()?>')" class="btn btn-danger">Supprimer</button></td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<script>
|
||||
function deleteReservation(email){
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", "<?=genURL('manager/') . $hotel->getId() . '/delete'?>", true);
|
||||
xhr.send('email=' + email);
|
||||
}
|
||||
</script>
|
||||
<?php
|
||||
require_once('template/footer.php');
|
||||
?>
|
Reference in a new issue