<?php

use Battles\User, Battles\Database\Db;

require_once "functions.php";
$hostel = Db::getInstance()->execute('select id, time, type from hostel where uid = ?', User::getInstance()->getId());
$base = [1 => [8, 16, 24, 32], 2 => [15, 30, 45, 60], 3 => [25, 50, 75, 100], 4 => [40, 80, 120, 160]];

if (isset($_POST['act']) && $_POST['act'] == 'pay' && isset($user['id']) && !empty($hostel->fetchColumn())) {
    echo '<fieldset class="hostelClientState">';
    echo '<legend>Предварительная оплата</legend>';
    echo '<div style="text-align: center;"><p class="NORMAL" style="margin: 5px 0">';
    echo 'Аренда оплачена по: <b>' . date('h:i d.m.y', $hostel->fetchColumn(1)) . '</b> <small>(' . timeOut($hostel->fetchColumn(1) - time()) . ')</small></p></div>';

    echo '<table align="center" class="periods"><caption style="text-align: left;">Выберите срок предоплаты.</caption>
           <tbody>
             <tr class="caption"><th>Сутки</th><td title="7 дн.">7</td><td title="14 дн.">14</td><td title="21 дн.">21</td><td title="28 дн.">28</td></tr>
             <tr class="value"><th>Сумма</th><td title="7 дн."><a href="?pays=1">' . $base[$hostel->fetchColumn(2)][0] . '</a></td><td title="14 дн."><a href="?pays=2">' . $base[$hostel->fetchColumn(2)][1] . '</a></td><td title="21 дн."><a href="?pays=3">' . $base[$hostel->fetchColumn(2)][2] . '</a></td><td title="28 дн."><a href="?pays=4">' . $base[$hostel->fetchColumn(2)][3] . '</a></td></tr>
           </tbody>
          </table>
          <div style="color: red; font-size: 9px; padding-top: 3px;"><b>Внимание!</b> При расторжении договора или смене тарифа, внесенная плата не возвращается</div></fieldset></div>';
}