function afficher_hebergement_dispo($data)
{
    $reponse = array();
    //on construit la requete au fur et à mesure
    $requete = '';
    $requete .= 'SELECT * FROM hebergement WHERE resident_hebergement="' . $data['client'] . '" ';
    //selection du bon type d'etablissement
    if ($data['residence'] != 'osef') {
        $requete .= 'AND categorie_hebergement ="' . $data['residence'] . '" ';
    }
    //selection de la bonne categorie de chambre
    if (!isset($data['chambre_commune'])) {
        $requete .= 'AND lit_1 > ' . intval($data['nb_places']) . ' ';
    } else {
        $requete .= 'AND lit_' . $data['nb_places'] . ' > 0 ';
    }
    $pdo = PdoSio::getPdoSio();
    $req = $pdo->selectRequest($requete);
    //On va maintenant récupérer les services associées à chaque etablissement
    $liste_services = array();
    foreach ($req as $key => $value) {
        $services = Hebergement::getServices($value['id_hebergement']);
        $liste_services[$key] = $services;
    }
    $reponse[0] = $req;
    $reponse[1] = $liste_services;
    return $reponse;
}
function preparation_formulaire($nb_places, $chambre_commune, $id, $data)
{
    $pdo = PdoSio::getPdoSio();
    //recuperation infos hebergement
    $req = $pdo->selectRequest('SELECT * FROM hebergement WHERE id_proprietaire = "' . $id . '"');
    $infos_hebergement = $req[0];
    //recuperation + formatage du nombre de jours que va passe le logé
    $date_debut = explode('/', $data['from']);
    $date_fin = explode('/', $data['to']);
    $date_debut_bd = new DateTime($data['from']);
    $date_fin_bd = new DateTime($data['to']);
    $date_debut_formatee = mktime(0, 0, 0, intval($date_debut[0]), intval($date_debut[1]), intval($date_debut[2]));
    $date_fin_formatee = mktime(0, 0, 0, intval($date_fin[0]), intval($date_fin[1]), intval($date_fin[2]));
    $diff = $date_fin_formatee - $date_debut_formatee;
    $retour = array();
    $tmp = $diff;
    $retour['second'] = $tmp % 60;
    $tmp = floor(($tmp - $retour['second']) / 60);
    $retour['minute'] = $tmp % 60;
    $tmp = floor(($tmp - $retour['minute']) / 60);
    $retour['hour'] = $tmp % 24;
    $tmp = floor(($tmp - $retour['hour']) / 24);
    $retour['day'] = $tmp;
    $duree = $retour['day'];
    //recuperation des chambres correspondantes + calcul du prix
    if ($chambre_commune == NULL) {
        $chambres = array(1, $infos_hebergement['lit_1']);
        $prix = $infos_hebergement['prix_hebergement'] * $nb_places * $duree;
    } else {
        $chambres = array($nb_places, $infos_hebergement['lit_' . $nb_places]);
        $prix = $infos_hebergement['prix_hebergement'] * $duree;
    }
    //Recuperation des services selectionnes et MaJ du prix
    $liste_services = Hebergement::getServicesTab(Hebergement::getId($id));
    $services_selectionnes = array();
    foreach ($liste_services as $service) {
        if (isset($data[$service['nom_service']])) {
            $services_selectionnes[$service['nom_service']] = $service['prix_service'];
            $prix += $service['prix_service'] * $nb_places * $duree;
        }
    }
    //variable contenant toutes les données
    $donnees = array($infos_hebergement, $data['from'], $data['to'], $duree, $chambres, $prix, $services_selectionnes);
    print_r($donnees);
    return $donnees;
}
Ejemplo n.º 3
0
<?php

include 'lib/PDO.php';
include 'lib/hebergement.php';
//permet de passer a l'etape 2 du formulaire
if (isset($_POST['action']) && $_POST['action'] == 'vue1') {
    $_SESSION['nb_places'] = intval($_POST['nb_places']);
    if (isset($_POST['chambre_commune'])) {
        $_SESSION['chambre_commune'] = $_POST['chambre_commune'];
    } else {
        $_SESSION['chambre_commune'] = NULL;
    }
    //recupere les services de l'hebergement
    $liste_services = Hebergement::getServicesTab(Hebergement::getId($_SESSION['id']));
    include 'vue/ajout_reservation/vue2.php';
} else {
    if (isset($_POST['action']) && $_POST['action'] == 'vue2') {
        include 'modele/ajout_reservation/get_loges.php';
        $liste_loges = get_loges($_POST, $_SESSION['nb_places']);
        //preparation a l'affichage du dernier formulaire
        include 'modele/ajout_reservation/preparation_formulaire.php';
        $donnees = preparation_formulaire($_SESSION['nb_places'], $_SESSION['chambre_commune'], $_SESSION['id'], $_POST);
        $_SESSION['donnees'] = $donnees;
        include 'vue/ajout_reservation/vue3.php';
    } else {
        if (isset($_POST['action']) && $_POST['action'] == 'vue3') {
            include 'modele/ajout_reservation/creation_reservation.php';
            creation_reservation($_POST, $_SESSION['donnees'], $_SESSION['nb_places'], $_SESSION['chambre_commune']);
        } else {
            include 'vue/ajout_reservation/vue1.php';
        }