Exemple #1
0
<?php

require_once "../../includes/initialize.php";
if (!$session->is_logged_in()) {
    redirect_to("login.php");
}
if (!isset($_GET['id'])) {
    redirect_to("login.php");
}
$room = Room::find_by_id($_GET['id']);
if (!$room) {
    redirect_to("login.php");
}
if ($session->user_id != $room->hotel_id) {
    redirect_to("login.php");
}
$count_photo = RoomPhoto::find_photo_by_room($room->id);
$max_file_size = 1048567;
$message1 = "";
$message2 = "";
$message3 = "";
$message4 = "";
if (isset($_POST['submit'])) {
    if (empty($count_photo)) {
        $room_photo = new RoomPhoto();
        $room_photo->room_id = $room->id;
        $room_photo->attach_file($_FILES['upload_file']);
        if ($room_photo->save()) {
            redirect_to("hotel_page.php?id={$room->hotel_id}");
        } else {
            $message1 = join("<br>", $room_photo->errors);
Exemple #2
0
    $adults = $_POST['adults'];
    $childs = $_POST['childs'];
    $price = trim($_POST['price']);
    $new_room = new Room();
    $new_room->hotel_id = $hotel->id;
    $new_room->make($room_name, $adults, $childs, $price);
    if (empty($new_room->errors) && $new_room->create()) {
        $session->message('Room created');
        redirect_to("add_room.php?id={$hotel->id}&room={$new_room->id}");
    } else {
        $message = join("<br>", $new_room->errors);
    }
}
$room = '';
if (isset($_GET['room']) && !empty($_GET['room'])) {
    $room = Room::find_by_id($_GET['room']);
}
if (isset($_POST['submit1'])) {
    if (!empty($room)) {
        $room_photo = new RoomPhoto();
        $room_photo->room_id = $room->id;
        $room_photo->attach_file($_FILES['upload_file']);
        if ($room_photo->save()) {
            redirect_to("page.php?id={$hotel->id}");
        } else {
            $message = join("<br>", $room_photo->errors);
        }
    } else {
        $session->message("First you have to create a room");
        redirect_to("add_room.php?id={$hotel->id}");
    }