99 lines
3.4 KiB
PHP
99 lines
3.4 KiB
PHP
<?php
|
||
ob_start("ob_gzhandler");
|
||
session_start();
|
||
|
||
if (is_null($_SESSION['uid'])) {
|
||
header("Location: index.php");
|
||
}
|
||
require_once "functions.php";
|
||
if ($user['room'] != 29) {
|
||
header("Location: main.php");
|
||
die();
|
||
}
|
||
if ($user['battle'] != 0) {
|
||
header('location: fbattle.php');
|
||
die();
|
||
}
|
||
const BANK_SESSION_NAME = "bankid";
|
||
$get = urldecode(filter_input(INPUT_SERVER, 'QUERY_STRING'));
|
||
if ($get == 'exit') {
|
||
$_SESSION[BANK_SESSION_NAME] = null;
|
||
}
|
||
$bank = new Bank($_SESSION['uid']);
|
||
|
||
if (isset($_POST['userlogin'])) {
|
||
$_SESSION[BANK_SESSION_NAME] = $bank->user_id;
|
||
}
|
||
if ($_SESSION[BANK_SESSION_NAME]) {
|
||
$toid = (int)$_POST['to_id'] ?? 0;
|
||
$summa = (int)$_POST['summa'] ?? 0;
|
||
$submit = $_POST['action'] ?? '';
|
||
|
||
// Зачисдение кредитов на счёт.
|
||
if ($submit === 'depositMoney' && $summa) {
|
||
$bank->depositMoney($summa);
|
||
unset($submit, $summa);
|
||
}
|
||
|
||
// Снятие кредитов со счёта.
|
||
if ($submit === 'withdrawMoney' && $summa) {
|
||
$bank->withdrawMoney($summa);
|
||
unset($submit, $summa);
|
||
}
|
||
|
||
// Перевод кредитов на другой счёт.
|
||
if ($submit === 'sendMoney' && $summa && $toid) {
|
||
$bank->sendMoney($toid, $summa);
|
||
unset($submit, $summa, $toid);
|
||
}
|
||
}
|
||
?>
|
||
<!DOCTYPE html>
|
||
<html lang="ru">
|
||
<head>
|
||
<meta charset="utf-8">
|
||
<link href="css/main.css" rel="stylesheet"/>
|
||
<link href="css/secondary.css" rel="stylesheet"/>
|
||
<script src="js/main.js"></script>
|
||
<title>Банк</title>
|
||
</head>
|
||
<body>
|
||
<h1>Банк</h1>
|
||
<?php if (!$_SESSION[BANK_SESSION_NAME]): ?>
|
||
<a href=# onclick=hrefToFrame('city.php?strah')> ← выйти из банка</a>
|
||
<form method="post"><input type="submit" name="userlogin" value="Управление счётом"></form>
|
||
<?php else: ?>
|
||
<p><a href="?exit"> ← выйти из счёта</a></p>
|
||
<div><?= $bank->status ?></div>
|
||
<div class="appblock appblock-main">
|
||
<span class="legend">Cчет №<?= $bank->user_id ?></span>
|
||
<span class="wrap">На счету: <span class="num"><?= $bank->money ?></span></span>
|
||
<hr>
|
||
<span class="wrap">На руках: <span class="num"><?= $user['money'] ?></span></span>
|
||
</div>
|
||
<div class="appblock">
|
||
<span class="legend">Работа со счётом</span>
|
||
<form method="post">
|
||
<input size="10" name="summa" placeholder="Сумма">
|
||
<input type="hidden" name="action" value="depositMoney">
|
||
<input type="submit" value="Положить деньги">
|
||
</form>
|
||
<form method="post">
|
||
<input size="10" name="summa" placeholder="Сумма">
|
||
<input type="hidden" name="action" value="withdrawMoney">
|
||
<input type="submit" value="Снять деньги">
|
||
</form>
|
||
</div>
|
||
<div class="appblock">
|
||
<span class="legend">Перевод кредитов</span>
|
||
<form method="post">
|
||
<input size="10" name="summa" placeholder="Сумма">
|
||
<input size="10" name="to-id" placeholder="Cчёт"><br>
|
||
<input type="hidden" name="action" value="sendMoney">
|
||
<input type="submit" value="Перевести кредиты">
|
||
</form>
|
||
<span class="wrap">Комиссия: <?= Bank::BANK_COMISSION * 100 ?>% от переводимой суммы, но не менее 1 кр.</span>
|
||
</div>
|
||
<?php endif; ?>
|
||
</body>
|
||
</html>
|