Загрузка данных
booking.php
<?php
require_once 'config/database.php';
include 'includes/header.php';
if(!isset($_SESSION['user_id'])) { echo '<div class="alert warn"> Для бронирования <a href="profile.php">войдите</a></div>'; include 'includes/footer.php'; exit; }
$room_id=(int)$_GET['id'];
if(!$room_id) { echo '<div class="alert error"> Ошибка: помещение не выбрано</div>'; include 'includes/footer.php'; exit; }
$room=$pdo->prepare("SELECT * FROM rooms WHERE id=?");
$room->execute([$room_id]);
$room=$room->fetch();
if(!$room) { echo '<div class="alert error">Ошибка: помещение не найдено</div>'; include 'includes/footer.php'; exit; }
$user=$pdo->prepare("SELECT * FROM users WHERE id=?");
$user->execute([$_SESSION['user_id']]);
$user=$user->fetch();
$msg='';
if($_POST && isset($_POST['submit'])) {
$date=$_POST['date']; $start=$_POST['start']; $end=$_POST['end']; $purpose=trim($_POST['purpose']); $days=(int)$_POST['days'];
$total=$room['price_per_day']*$days;
if(empty($date)||empty($start)||empty($end)||empty($purpose)) $msg='<div class="alert error">Заполните все поля</div>';
elseif($days<1) $msg='<div class="alert error">Дней не менее 1</div>';
else {
$book=$pdo->prepare("INSERT INTO bookings (user_id,room_id,booking_date,start_time,end_time,purpose,total_price) VALUES (?,?,?,?,?,?,?)");
$book->execute([$_SESSION['user_id'],$room_id,$date,$start,$end,$purpose,$total]);
$msg='<div class="alert success"> Заявка создана! <a href="my-bookings.php">Мои заявки</a> | <a href="rooms.php">Назад</a></div>';
unset($_POST);
}
}
$types=['auditorium'=>'Аудитория','coworking'=>'Коворкинг','cinema'=>'Кинозал'];
?>
<h1>Бронирование</h1>
<?=$msg?>
<div style="display:grid;grid-template-columns:1fr 1fr;gap:30px;">
<div style="background:#fff;border-radius:12px;overflow:hidden;box-shadow:0 2px 15px rgba(0,0,0,0.08);">
<img src="<?=$room['image_url']?>" style="width:100%;height:300px;object-fit:cover;">
<div style="padding:25px;">
<div style="display:flex;justify-content:space-between;margin-bottom:15px;">
<span class="type"><?=$types[$room['type']]??$room['type']?></span>
<span style="background:#fff3e0;color:#e65100;padding:4px 12px;border-radius:20px;font-size:12px;"> <?=$room['capacity']?> чел.</span>
</div>
<h2 style="color:#1a237e;font-size:28px;"><?=htmlspecialchars($room['name'])?></h2>
<p style="color:#666;line-height:1.8;"><?=nl2br(htmlspecialchars($room['description']))?></p>
<div style="background:#f5f7fa;border-radius:8px;padding:15px;margin-top:15px;">
<div style="display:flex;justify-content:space-between;padding:5px 0;border-bottom:1px solid #ddd;"> <b><?=number_format($room['price_per_day'],0)?> ₽/день</b></div>
<div style="display:flex;justify-content:space-between;padding:5px 0;"> <?=$types[$room['type']]??$room['type']?></div>
</div>
</div>
</div>
<div style="background:#fff;border-radius:12px;padding:30px;box-shadow:0 2px 15px rgba(0,0,0,0.08);">
<h3> Данные пользователя</h3>
<div style="background:#f5f7fa;border-radius:8px;padding:15px;margin:15px 0;">
<div style="display:flex;justify-content:space-between;padding:5px 0;border-bottom:1px solid #ddd;">Имя: <b><?=htmlspecialchars($user['full_name'])?></b></div>
<div style="display:flex;justify-content:space-between;padding:5px 0;border-bottom:1px solid #ddd;">Email: <b><?=htmlspecialchars($user['email'])?></b></div>
<div style="display:flex;justify-content:space-between;padding:5px 0;">Телефон: <b><?=htmlspecialchars($user['phone']??'Не указан')?></b></div>
</div>
<form method="POST">
<input type="date" name="date" required style="width:100%;padding:10px;margin:5px 0;border:1px solid #ddd;border-radius:6px;box-sizing:border-box;">
<div style="display:grid;grid-template-columns:1fr 1fr;gap:10px;">
<input type="time" name="start" required style="padding:10px;border:1px solid #ddd;border-radius:6px;box-sizing:border-box;">
<input type="time" name="end" required style="padding:10px;border:1px solid #ddd;border-radius:6px;box-sizing:border-box;">
</div>
<input type="number" name="days" id="days" value="1" min="1" required style="width:100%;padding:10px;margin:5px 0;border:1px solid #ddd;border-radius:6px;box-sizing:border-box;">
<textarea name="purpose" rows="3" required style="width:100%;padding:10px;margin:5px 0;border:1px solid #ddd;border-radius:6px;box-sizing:border-box;resize:vertical;" placeholder="Цель мероприятия"></textarea>
<div style="background:#f5f7fa;border-radius:8px;padding:15px;margin:10px 0;">
<div style="display:flex;justify-content:space-between;padding:5px 0;border-bottom:1px solid #ddd;">Дней: <span id="daysDisplay">1</span></div>
<div style="display:flex;justify-content:space-between;padding:5px 0;font-size:20px;font-weight:700;">Итого: <span style="color:#2e7d32;" id="totalPrice"><?=number_format($room['price_per_day'],0)?> ₽</span></div>
</div>
<button type="submit" name="submit" class="btn btn-success" style="width:100%;padding:14px;font-size:16px;"> Отправить заявку</button>
<div style="text-align:center;margin-top:10px;"><a href="rooms.php" style="color:#1a237e;">← Назад</a></div>
</form>
</div>
</div>
<script>
document.getElementById('days').oninput=function(){
let d=parseInt(this.value)||0;
document.getElementById('daysDisplay').textContent=d;
document.getElementById('totalPrice').textContent=(d>0?d*<?=$room['price_per_day']?>:0)+' ₽';
};
</script>
<?php include 'includes/footer.php'; ?>