1
0
Fork 0
This repository has been archived on 2024-02-17. You can view files and clone it, but cannot push or open issues or pull requests.
Accommodation_Management/controller/accomodation.php
p1907961 240492d94f ok
2021-01-05 17:53:26 +01:00

77 lines
No EOL
3.2 KiB
PHP

<?php
if($_SESSION['USER']->isLoggedIn()) {
$accomodationType = ['Hôtel', 'Gîte','Camping','Villa en location'];
$alert = '';
if(isset($path[1])) {
switch ($path[1]) {
case 'add':
if(!$_SESSION['USER']->getAccomodationId())
{
/*
* Creating Accomodation
*/
if(isset(
$_POST['accomodationName'],
$_POST['postalCode'],
$_POST['address'],
$_POST['accomodationType']
)){
$availableServices = AccomodationServices::getAll();
$re_name = '/^[a-zA-Z -\'?*éàèôê0-9"()+&]{1,}$/';
$re_cp = '/[0-9]{5}/';
/*
* Checking inputs
*/
if(!preg_match($re_name, $_POST['accomodationName']) || !preg_match($re_cp, $_POST['postalCode']) || ((isset($_POST["accomodationService"]) && gettype($_POST['accomodationService']) === 'array' && array_diff($_POST["accomodationService"], $availableServices))))
{
$alert = alert('danger','Le formulaire est invalide');
}else{
if(Accomodation::insertUser($_SESSION['USER'], array(
"name" => $_POST['accomodationName'],
"address" => $_POST['address'],
"postalCode" => $_POST['postalCode'],
"type" => $_POST['accomodationType'])) != false){
/*
* Update users information
*/
$_SESSION['USER']->update();
/*
* Insert ok
*/
$accomodation = Accomodation::fetchByUser($_SESSION['USER']);
$accomodation->setServices($_POST["accomodationService"]);
$alert = alert('success','Ajout du logement réussi.');
}else{
$alert = alert('danger','Erreur lors de l\'insertion du logement.');
}
}
}
$services = AccomodationServices::fetch();
require_once(VIEW_PATH.$path[1] . '_' . $path[0].'.php');
}else{
redirect();
}
break;
case 'edit':
if($_SESSION['USER']->getAccomodationId())
{
$accomodation = Accomodation::fetchByuser($_SESSION['USER']);
$services = AccomodationServices::fetch();
require_once(VIEW_PATH.$path[1] . '_' . $path[0].'.php');
}else{
redirect();
}
break;
default:
redirect();
}
}else{
redirect();
}
}else{
redirect('login');
}