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 '