1
0
Fork 0

Added Remove Reservation functions & Removed Language artefacts

This commit is contained in:
p1907961 2021-01-16 22:33:01 +01:00
parent abc00dcca2
commit 81ecec446e
10 changed files with 190 additions and 79 deletions

View file

@ -11,8 +11,10 @@ if ($_SESSION['USER']->isLoggedIn() && $_SESSION['USER']->getType() == 'Staff')
case 'add':
break;
case 'delete':
if(getPost('email', false)){
if(getPost('email', false) && getPost('start', false)){
if(AccomodationReservation::remove($path[1], getPost('email'),getPost('start'))){
echo 'ok';
}
}
break;
default:

29
controller/vip.php Normal file
View file

@ -0,0 +1,29 @@
<?php
if ($_SESSION['USER']->isLoggedIn() && $_SESSION['USER']->getType() == 'Staff') {
$alert = '';
if (isset($path[1],$path[2]) && User::fetchByEmail($path[1]) !== false) {
switch ($path[2]) {
case 'view':
$select_user = User::fetchByEmail($path[1]);
$reservations = AccomodationReservation::fetchByUserEmail($select_user->getEmail());
require_once(VIEW_PATH . $path[2] . '_' . $path[0] . '.php');
break;
case 'add':
break;
case 'delete':
if(getPost('id', false) && getPost('start', false)){
if(AccomodationReservation::remove(getPost('id'), $path[1],getPost('start'))){
echo 'ok';
}
}
break;
default:
redirect();
}
} else {
$users = User::fetch(array(['UserTypeName', '=', 'VIP']));
require_once(VIEW_PATH . $path[0] . '.php');
}
} else {
redirect('login');
}

View file

@ -23,13 +23,6 @@ if(!isset($_SESSION['USER'])){
*/
$_SESSION['USER']->refresh();
}
/*
* Lang
*/
$lang = LANG_DEFAULT;
$langs = glob(LANG_PATH. '*.{json}', GLOB_BRACE);
if(isset($_SESSION['lang']) && in_array(LANG_PATH.$_SESSION['lang'].'.json', $langs)) $lang = $_SESSION['lang'];
if(isset($_GET['lang']) && in_array(LANG_PATH.$_GET['lang'].'.json', $langs)){ $lang = $_GET['lang']; $_SESSION['lang'] = $lang; }
/*
* Routing

View file

@ -41,6 +41,12 @@ class AccomodationReservation extends Model
return $this->data['peopleCount'];
return false;
}
public function getRoomCount(): string
{
if(isset($this->data['roomCount']))
return $this->data['roomCount'];
return false;
}
public function getStartDate(): string
{
if(isset($this->data['startDate']))
@ -61,9 +67,10 @@ class AccomodationReservation extends Model
}
public static function fetchByUserEmail(string $email){
$data = AccomodationReservation::fetch(array(['UserEmail','=', $email]));
if(count($data) == 1){
return $data[0];
}
return false;
return $data;
}
public static function remove($AccomodationId, $email, $startDate){
return AccomodationReservation::delete(array(['AccomodationId','=',$AccomodationId],['UserEmail','=',$email],['startDate','=',$startDate]));
}
}

View file

@ -59,6 +59,15 @@ class User extends Model
return $this->data['AccomodationId'];
return false;
}
public static function fetchByEmail(string $email)
{
$data = User::fetch(array(['email','=', $email]));
if(count($data) === 1){
return $data[0];
}
return false;
}
/*
* Session
*/

View file

@ -125,6 +125,34 @@ class Model {
return false;
}
/*
* DELETE
*/
public static function delete($filters = []): bool
{
$query = 'DELETE FROM ' . get_called_class();
$args = [];
$c = 0;
$output = [];
$_col = get_called_class()::getColumns();
forEach($filters as $filter){
if (is_array($filter) && count($filter) === 3 && array_key_exists($filter[0], $_col) && in_array($filter[1], ['=','<','>','<>','LIKE'])){
if($c === 0){
$query .= ' WHERE';
}else{
$query .= ' AND';
}
$query .= ' ' . $filter[0] . ' ' . $filter[1] . ' ?';
$args[] = $filter[2];
}else{
throw new Exception('Invalid SQL filters');
}
$c++;
}
$q = Model::$db->prepare($query);
return ($q->execute($args) == true);
}
protected function getColumns(): array
{
if(!isset(get_called_class()::$column[get_called_class()])) {

View file

@ -23,6 +23,7 @@
break;
case 'Staff':
echo navItem('Gestion des réservations',genURL('manager'));
echo navItem('Gestion des VIP',genURL('vip'));
break;
}
}else{

View file

@ -3,73 +3,12 @@ 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">Nombre de chambres</th>
<th scope="col">Date d'arrivée</th>
<th scope="col">Date de sortie</th>
<th scope="col">Action</th>
@ -80,11 +19,12 @@ require_once('template/head.php');
forEach($reservations as $reservation){
?>
<tr>
<th scope="row"><?=$reservation->getUserEmail()?></th>
<th scope="row"><a href="<?=genURL('vip/' . $reservation->getUserEmail() . '/view')?>"><?=$reservation->getUserEmail()?></a></th>
<td><?=$reservation->getPeopleCount()?></td>
<td><?=$reservation->getRoomCount()?></td>
<td><?=$reservation->getStartDate()?></td>
<td><?=$reservation->getEndDate()?></td>
<td><button onclick="deleteReservation('<?=$reservation->getUserEmail()?>')" class="btn btn-danger">Supprimer</button></td>
<td><button onclick="deleteReservation('<?=$reservation->getUserEmail()?>', '<?=$reservation->getStartDate()?>')" class="btn btn-danger">Supprimer</button></td>
</tr>
<?php
}
@ -93,10 +33,20 @@ require_once('template/head.php');
</table>
</div>
<script>
function deleteReservation(email){
function deleteReservation(email, date){
var xhr = new XMLHttpRequest();
xhr.onreadystatechange=function()
{
if (xhr.readyState==4 && xhr.status==200)
{
if(xhr.responseText == 'ok'){
location.reload();
}
}
}
xhr.open("POST", "<?=genURL('manager/') . $hotel->getId() . '/delete'?>", true);
xhr.send('email=' + email);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send('email=' + email + '&start=' + date);
}
</script>
<?php

55
view/view_vip.php Normal file
View file

@ -0,0 +1,55 @@
<?php
require_once('template/head.php');
?>
<div class="container-fluid section">
<h2>Gestions des réservations de "<?=htmlspecialchars($select_user->getEmail())?>"</h2>
<table class="table table-hover">
<thead>
<tr>
<th scope="col">Nom de logement</th>
<th scope="col">Nombre d'occupants</th>
<th scope="col">Nombre de chambres</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){
$acom = Accomodation::fetchById($reservation->getAccomodationId());
?>
<tr>
<th scope="row"><a href="<?=genURL('manager/' . $acom->getId() . '/view')?>"><?=htmlspecialchars($acom->getName())?></a></th>
<td><?=$reservation->getPeopleCount()?></td>
<td><?=$reservation->getRoomCount()?></td>
<td><?=$reservation->getStartDate()?></td>
<td><?=$reservation->getEndDate()?></td>
<td><button onclick="deleteReservation('<?=$reservation->getAccomodationId()?>', '<?=$reservation->getStartDate()?>')" class="btn btn-danger">Supprimer</button></td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
<script>
function deleteReservation(id, date){
var xhr = new XMLHttpRequest();
xhr.onreadystatechange=function()
{
if (xhr.readyState==4 && xhr.status==200)
{
if(xhr.responseText == 'ok'){
location.reload();
}
}
}
xhr.open("POST", "<?=genURL('vip/') . $reservation->getUserEmail() . '/delete'?>", true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send('id=' + id + '&start=' + date);
}
</script>
<?php
require_once('template/footer.php');
?>

37
view/vip.php Normal file
View file

@ -0,0 +1,37 @@
<?php
require_once('template/head.php');
?>
<div class="container-fluid section">
<h2>Gestions des VIP</h2>
<table class="table table-hover">
<thead>
<tr>
<th scope="col">Email</th>
<th scope="col">Nom</th>
<th scope="col">Prénom</th>
<th scope="col">Téléphone</th>
<th scope="col">Nombre de Reservation(s)</th>
<th scope="col">Action</th>
</tr>
</thead>
<tbody>
<?php
foreach ($users as $user){
?>
<tr>
<th scope="row"><?=$user->getEmail()?></th>
<td><?=htmlspecialchars($user->getFirstName())?></td>
<td><?=htmlspecialchars($user->getLastName())?></td>
<td><?=htmlspecialchars($user->getPhoneNumber())?></td>
<td><?=count(AccomodationReservation::fetchByUserEmail($user->getEmail()))?></td>
<td><a href="<?=genURL('vip/' . $user->getEmail() . '/view')?>" class="btn btn-primary">Liste des reservations</a></td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
<?php
require_once('template/footer.php');
?>