From 2f3925dd95bac93f795fdcd3144b49d6ef540736 Mon Sep 17 00:00:00 2001 From: p1907961 Date: Thu, 14 Jan 2021 19:01:32 +0100 Subject: [PATCH] Added Staff Accomodation views --- controller/accomodation.php | 4 +- controller/login.php | 4 +- controller/manager.php | 27 ++++++++ models/Accomodation.php | 28 ++++---- models/AccomodationReservation.php | 69 +++++++++++++++++++ models/User.php | 1 - src/func.php | 2 +- view/date_accomodation.php | 4 ++ view/login.php | 1 + view/manager.php | 39 +++++++++++ view/template/navbar.php | 2 +- view/view_manager.php | 104 +++++++++++++++++++++++++++++ 12 files changed, 265 insertions(+), 20 deletions(-) create mode 100644 controller/manager.php create mode 100644 models/AccomodationReservation.php create mode 100644 view/manager.php create mode 100644 view/view_manager.php diff --git a/controller/accomodation.php b/controller/accomodation.php index 9458d04..194d0ef 100644 --- a/controller/accomodation.php +++ b/controller/accomodation.php @@ -1,5 +1,5 @@ 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 */ diff --git a/controller/login.php b/controller/login.php index 8c968ab..0f3cd89 100644 --- a/controller/login.php +++ b/controller/login.php @@ -1,6 +1,7 @@ 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'); diff --git a/controller/manager.php b/controller/manager.php new file mode 100644 index 0000000..42caeff --- /dev/null +++ b/controller/manager.php @@ -0,0 +1,27 @@ +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'); +} \ No newline at end of file diff --git a/models/Accomodation.php b/models/Accomodation.php index bcf9b0b..5886d99 100644 --- a/models/Accomodation.php +++ b/models/Accomodation.php @@ -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) { /* diff --git a/models/AccomodationReservation.php b/models/AccomodationReservation.php new file mode 100644 index 0000000..0f96f40 --- /dev/null +++ b/models/AccomodationReservation.php @@ -0,0 +1,69 @@ +$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; + } +} \ No newline at end of file diff --git a/models/User.php b/models/User.php index 533b138..db8e987 100644 --- a/models/User.php +++ b/models/User.php @@ -47,7 +47,6 @@ class User extends Model return $this->data['phoneNumber']; return false; } - public function getType(): string { if(isset($this->data['UserTypeName'])) diff --git a/src/func.php b/src/func.php index 951a51f..9f4ce9a 100644 --- a/src/func.php +++ b/src/func.php @@ -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 ''; diff --git a/view/date_accomodation.php b/view/date_accomodation.php index bc0e1a5..d132d8a 100644 --- a/view/date_accomodation.php +++ b/view/date_accomodation.php @@ -1,7 +1,11 @@ +
+
+
+
\ No newline at end of file diff --git a/view/login.php b/view/login.php index 77e3126..baccead 100644 --- a/view/login.php +++ b/view/login.php @@ -5,6 +5,7 @@ require_once('template/head.php');

Please sign in

+ diff --git a/view/manager.php b/view/manager.php new file mode 100644 index 0000000..3a5845b --- /dev/null +++ b/view/manager.php @@ -0,0 +1,39 @@ + +
+

Gestions des réservations

+ + + + + + + + + + + + + + + + + + + + + + + + + +
#Nom de logementAdresseTypeService(s)Nombre de Reservation(s)Action
getId()?>getName())?>getAddress()) . ', ' . $hotel->getPostalCode() ?>getType())?>getServices() ? htmlspecialchars(join(',',$hotel->getServices())) : "Aucun" ?>0Editer une reservation
+
+ \ No newline at end of file diff --git a/view/template/navbar.php b/view/template/navbar.php index ae65ebc..660d0ab 100644 --- a/view/template/navbar.php +++ b/view/template/navbar.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{ diff --git a/view/view_manager.php b/view/view_manager.php new file mode 100644 index 0000000..5f883ed --- /dev/null +++ b/view/view_manager.php @@ -0,0 +1,104 @@ + +
+

Gestions des réservations de "getName())?>"

+ + +
+
+ + +
+
+
+
+ + +
Looks good!
+
+
+
+
+ @ + + +
Please choose a username.
+
+
+
+
+ + +
Please provide a valid city.
+
+
+
+
+ + +
Please provide a valid zip.
+
+
+
+ +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Email VIPNombre d'occupantsDate d'arrivéeDate de sortieAction
getUserEmail()?>getPeopleCount()?>getStartDate()?>getEndDate()?>
+
+ + \ No newline at end of file