2018-02-27 03:53:10 +00:00
|
|
|
|
<?php
|
2018-01-28 16:40:49 +00:00
|
|
|
|
ob_start("ob_gzhandler");
|
|
|
|
|
session_start();
|
|
|
|
|
if ($_SESSION['uid'] == null) header("Location: index.php");
|
2018-12-12 11:59:29 +00:00
|
|
|
|
require_once "functions.php";
|
2018-12-12 19:55:33 +00:00
|
|
|
|
if ($user['room'] != 29) {
|
|
|
|
|
header("Location: main.php");
|
|
|
|
|
die();
|
|
|
|
|
}
|
2018-02-27 03:53:10 +00:00
|
|
|
|
if ($user['battle'] != 0) {
|
|
|
|
|
header('location: fbattle.php');
|
|
|
|
|
die();
|
|
|
|
|
}
|
2018-03-09 18:55:26 +00:00
|
|
|
|
$bank = db::c()->query('SELECT `id`, `cr`, `ekr` FROM `bank` WHERE `id` = ?i', $_SESSION['uid'])->fetch_assoc();
|
2018-01-28 16:40:49 +00:00
|
|
|
|
|
2018-03-09 21:12:03 +00:00
|
|
|
|
/**
|
2018-03-22 21:26:43 +00:00
|
|
|
|
* Если вдруг нет счёта, создаём. Временная функция.
|
2018-03-09 21:12:03 +00:00
|
|
|
|
*/
|
2018-03-22 21:09:41 +00:00
|
|
|
|
if (!$bank['id']) db::c()->query('INSERT INTO `bank` (`id`) VALUES (?i)', $_SESSION['uid']);
|
2018-01-28 16:40:49 +00:00
|
|
|
|
?>
|
|
|
|
|
|
2018-02-27 03:53:10 +00:00
|
|
|
|
<!DOCTYPE html>
|
|
|
|
|
<html>
|
|
|
|
|
<head>
|
|
|
|
|
<meta charset="utf-8">
|
|
|
|
|
<link href="css/main.css" rel="stylesheet"/>
|
2018-12-12 11:59:29 +00:00
|
|
|
|
<link href="css/secondary.css" rel="stylesheet"/>
|
2019-01-15 11:54:44 +00:00
|
|
|
|
<script src="js/main.js"></script>
|
2018-02-27 03:53:10 +00:00
|
|
|
|
<title>Банк</title>
|
2018-01-28 16:40:49 +00:00
|
|
|
|
</head>
|
2018-02-27 03:53:10 +00:00
|
|
|
|
<body>
|
2018-02-27 05:41:56 +00:00
|
|
|
|
<h1>Банк</h1>
|
2018-02-27 03:53:10 +00:00
|
|
|
|
<?php
|
2018-03-22 21:09:41 +00:00
|
|
|
|
$get = urldecode(filter_input(INPUT_SERVER, 'QUERY_STRING'));
|
|
|
|
|
if ($get == 'exit') {
|
2018-02-27 05:41:56 +00:00
|
|
|
|
$_SESSION['bankid'] = null;
|
2018-01-28 16:40:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-03-09 22:01:20 +00:00
|
|
|
|
if (isset($_POST['userlogin'])) {
|
|
|
|
|
$_SESSION['bankid'] = $_SESSION['uid'];
|
2018-01-28 16:40:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-27 05:41:56 +00:00
|
|
|
|
if (!$_SESSION['bankid']) {
|
2018-02-27 03:53:10 +00:00
|
|
|
|
?>
|
2019-01-15 19:34:35 +00:00
|
|
|
|
<a href=# onclick=hrefToFrame('city.php?strah')> ← выйти из банка</a>
|
2018-03-09 22:34:51 +00:00
|
|
|
|
<form method="post"><input type="submit" name="userlogin" value="Управление счётом"></form>
|
2018-02-27 05:14:11 +00:00
|
|
|
|
<?
|
|
|
|
|
} else {
|
2018-03-09 18:07:04 +00:00
|
|
|
|
|
2018-03-09 22:01:20 +00:00
|
|
|
|
$toid = filter_input(INPUT_POST, 'to-id');
|
2018-03-22 20:46:12 +00:00
|
|
|
|
$summa = (int)filter_input(INPUT_POST, 'summa');
|
2018-03-09 22:16:41 +00:00
|
|
|
|
$submit = filter_input(INPUT_POST, 'action');
|
2018-03-22 20:46:12 +00:00
|
|
|
|
$mywarn = '';
|
2018-03-09 22:01:20 +00:00
|
|
|
|
/**
|
|
|
|
|
* Зачисдение кредитов на счёт.
|
|
|
|
|
*/
|
2018-03-09 22:12:59 +00:00
|
|
|
|
if ($submit == 'money-in' && $summa) {
|
2018-03-09 21:12:03 +00:00
|
|
|
|
if ($summa > 0 && ($summa <= $user['money'])) {
|
|
|
|
|
$user['money'] -= $summa;
|
2018-03-09 23:07:02 +00:00
|
|
|
|
db::c()->query('UPDATE `users` SET `money` = `money` - ?i WHERE `id` = ?i', $summa, $bank['id']);
|
|
|
|
|
db::c()->query('UPDATE `bank` SET `cr` = `cr` + ?i WHERE `id` = ?i', $summa, $bank['id']);
|
2018-03-09 21:12:03 +00:00
|
|
|
|
db::c()->query('INSERT INTO `bank_logs` (`user_id`, `sum`, `type`, `comments`, `source`)
|
2018-03-09 23:07:02 +00:00
|
|
|
|
VALUES (?i, ?i, "?s", "?s", ?i)', $bank['id'], $summa, 'money-in', 'Банк: Зачисление средств на счёт', $bank['id']);
|
2018-02-27 05:14:11 +00:00
|
|
|
|
} else {
|
|
|
|
|
$mywarn = "У вас недостаточно денег для выполнения операции";
|
2018-02-27 03:53:10 +00:00
|
|
|
|
}
|
2018-03-09 22:12:59 +00:00
|
|
|
|
$submit = '';
|
2018-03-09 21:12:03 +00:00
|
|
|
|
$summa = 0;
|
2018-02-27 05:14:11 +00:00
|
|
|
|
}
|
2018-03-09 18:07:04 +00:00
|
|
|
|
|
2018-03-09 22:01:20 +00:00
|
|
|
|
/**
|
|
|
|
|
* Снятие кредитов со счёта.
|
|
|
|
|
*/
|
2018-03-09 22:12:59 +00:00
|
|
|
|
if ($submit == 'money-out' && $summa) {
|
2018-03-09 21:12:03 +00:00
|
|
|
|
if ($summa > 0 && ($summa <= $bank['cr'])) {
|
|
|
|
|
$user['money'] += $summa;
|
2018-03-09 23:07:02 +00:00
|
|
|
|
db::c()->query('UPDATE `bank` SET `cr` = `cr` - ?i WHERE `id` = ?i', $summa, $bank['id']);
|
|
|
|
|
db::c()->query('UPDATE `users` SET `money` = `money` + ?i WHERE `id` = ?i', $summa, $bank['id']);
|
2018-03-09 21:12:03 +00:00
|
|
|
|
db::c()->query('INSERT INTO `bank_logs` (`user_id`, `sum`, `type`, `comments`, `source`)
|
2018-03-09 23:07:02 +00:00
|
|
|
|
VALUES (?i, ?i, "?s", "?s", ?i)', $bank['id'], $summa, 'money-out', 'Банк: Вывод средств на руки', $bank['id']);
|
2018-02-27 05:14:11 +00:00
|
|
|
|
} else {
|
|
|
|
|
$mywarn = "У вас недостаточно денег на счету для выполнения операции";
|
2018-01-28 16:40:49 +00:00
|
|
|
|
}
|
2018-03-09 22:12:59 +00:00
|
|
|
|
$submit = '';
|
2018-03-09 21:12:03 +00:00
|
|
|
|
$summa = 0;
|
2018-02-27 05:14:11 +00:00
|
|
|
|
}
|
2018-01-28 16:40:49 +00:00
|
|
|
|
|
2018-03-09 22:01:20 +00:00
|
|
|
|
/**
|
|
|
|
|
* Перевод кредитов на другой счёт.
|
|
|
|
|
*/
|
2018-03-09 23:28:29 +00:00
|
|
|
|
if ($submit == 'money-send' && $summa && $toid) {
|
2018-03-09 22:01:20 +00:00
|
|
|
|
$receiver = db::c()->query('SELECT `id` FROM `bank` WHERE `id` = ?i', $toid)->fetch_assoc();
|
|
|
|
|
if ($receiver['id']) {
|
|
|
|
|
if ($summa > 0) {
|
|
|
|
|
$nalog = round($summa * 0.05);
|
|
|
|
|
if ($nalog < 1) {
|
|
|
|
|
$nalog = 1;
|
|
|
|
|
}
|
|
|
|
|
$new_summa = $summa + $nalog;
|
|
|
|
|
if ($new_summa <= $bank['cr']) {
|
2018-03-09 23:07:02 +00:00
|
|
|
|
db::c()->query('UPDATE `bank` SET `cr` = `cr` - ?i WHERE `id` = ?i', $new_summa, $bank['id']);
|
2018-03-09 22:01:20 +00:00
|
|
|
|
db::c()->query('UPDATE `bank` SET `cr` = `cr` + ?i WHERE `id` = ?i', $summa, $toid);
|
|
|
|
|
db::c()->query('UPDATE `bank` SET `cr` = `cr` + ?i WHERE `id` = ?i', $nalog, 0);
|
|
|
|
|
db::c()->query('INSERT INTO `bank_logs` (`user_id`, `sum`, `type`, `comments`, `source`)
|
2018-03-09 23:07:02 +00:00
|
|
|
|
VALUES (?i, ?i, "?s", "?s", ?i)', $toid, $summa, 'money-in', 'Получение банковского перевода.', $bank['id']);
|
2018-03-09 22:01:20 +00:00
|
|
|
|
db::c()->query('INSERT INTO `bank_logs` (`user_id`, `sum`, `type`, `comments`, `source`)
|
2018-03-22 21:09:41 +00:00
|
|
|
|
VALUES (?i, ?i, "?s", "?s", ?i)', $bank['id'], $new_summa, 'money-send', 'Банк: Перевод средств на другой счёт. Комиссия: ' . $nalog . '.', $toid);
|
2018-03-09 22:01:20 +00:00
|
|
|
|
} else {
|
|
|
|
|
$mywarn = "У вас недостаточно денег на счету для выполнения операции";
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$mywarn = "Укажите сумму!";
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$mywarn = "Счёт не существует.";
|
|
|
|
|
}
|
2018-03-09 22:12:59 +00:00
|
|
|
|
$submit = '';
|
2018-03-09 22:01:20 +00:00
|
|
|
|
$summa = 0;
|
|
|
|
|
$toid = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-27 05:14:11 +00:00
|
|
|
|
/**
|
2018-03-22 20:46:12 +00:00
|
|
|
|
* Обмен еврокредитов на кредиты.
|
2018-02-27 05:14:11 +00:00
|
|
|
|
*/
|
2018-03-22 21:09:41 +00:00
|
|
|
|
if ($submit == 'donate-exchange' && $summa) {
|
2018-03-22 20:46:12 +00:00
|
|
|
|
if ($summa > 0 && $summa <= $bank['ekr']) {
|
2018-03-22 21:09:41 +00:00
|
|
|
|
db::c()->query('UPDATE `bank` SET `cr` = `cr` + ?i WHERE `id` = ?i', ($summa * 5), $bank['id']);
|
2018-03-22 20:46:12 +00:00
|
|
|
|
db::c()->query('UPDATE `bank` SET `ekr` = `ekr` - ?i WHERE `id` = ?i', $summa, $bank['id']);
|
|
|
|
|
db::c()->query('INSERT INTO `bank_logs` (`user_id`, `sum`, `type`, `comments`, `source`)
|
2018-03-22 21:09:41 +00:00
|
|
|
|
VALUES (?i, ?i, "?s", "?s", ?i)', $bank['id'], $summa, 'donate-exchange', 'Банк: Обмен валют на сумму ' . ($summa * 5) . ' кр.', $bank['id']);
|
2018-02-27 05:14:11 +00:00
|
|
|
|
} else {
|
2018-03-22 20:46:12 +00:00
|
|
|
|
$mywarn = "У вас недостаточно денег на валютном счету для выполнения операции";
|
2018-02-27 03:53:10 +00:00
|
|
|
|
}
|
2018-03-22 20:46:12 +00:00
|
|
|
|
$submit = '';
|
|
|
|
|
$summa = 0;
|
2018-02-27 05:14:11 +00:00
|
|
|
|
}
|
2018-01-28 16:40:49 +00:00
|
|
|
|
|
2018-02-27 05:14:11 +00:00
|
|
|
|
err($mywarn);
|
|
|
|
|
?>
|
2018-03-22 21:26:43 +00:00
|
|
|
|
<p><a href="?exit"> ← выйти из счёта</a></p>
|
2018-12-12 11:59:29 +00:00
|
|
|
|
<div class="appblock appblock-main">
|
2018-12-12 19:55:33 +00:00
|
|
|
|
<span class="legend">Cчет №<?= $bank['id'] ?></span>
|
|
|
|
|
<span class="wrap">Кредитов<span class="num"><?= $bank['cr'] ?></span></span>
|
|
|
|
|
<span class="wrap">ЕвроКредитов<span class="num"><?= $bank['ekr'] ?></span></span>
|
|
|
|
|
<hr>
|
|
|
|
|
<span class="wrap">На руках<span class="num"><?= $user['money'] ?></span></span>
|
2018-03-22 22:27:08 +00:00
|
|
|
|
</div>
|
2018-02-27 05:14:11 +00:00
|
|
|
|
<div class="appblock">
|
2018-03-22 22:35:17 +00:00
|
|
|
|
<span class="legend">Работа со счётом</span>
|
2018-03-09 21:12:03 +00:00
|
|
|
|
<form method="post">
|
|
|
|
|
<input size="10" name="summa" placeholder="Сумма">
|
2018-03-09 22:22:08 +00:00
|
|
|
|
<input type="hidden" name="action" value="money-in">
|
2018-03-22 22:35:17 +00:00
|
|
|
|
<input type="submit" value="Положить деньги">
|
2018-03-09 21:12:03 +00:00
|
|
|
|
</form>
|
|
|
|
|
<form method="post">
|
|
|
|
|
<input size="10" name="summa" placeholder="Сумма">
|
2018-03-09 22:22:08 +00:00
|
|
|
|
<input type="hidden" name="action" value="money-out">
|
2018-03-22 22:35:17 +00:00
|
|
|
|
<input type="submit" value="Снять деньги">
|
2018-03-09 21:12:03 +00:00
|
|
|
|
</form>
|
2018-02-27 05:14:11 +00:00
|
|
|
|
</div>
|
2018-03-09 22:01:20 +00:00
|
|
|
|
<div class="appblock">
|
2018-03-22 22:27:08 +00:00
|
|
|
|
<span class="legend">Перевод кредитов</span>
|
2018-03-09 21:12:03 +00:00
|
|
|
|
<form method="post">
|
|
|
|
|
<input size="10" name="summa" placeholder="Сумма">
|
2018-03-09 22:12:59 +00:00
|
|
|
|
<input size="10" name="to-id" placeholder="Cчёт"><br>
|
2018-03-09 23:28:29 +00:00
|
|
|
|
<input type="hidden" name="action" value="money-send">
|
2018-03-09 22:16:41 +00:00
|
|
|
|
<input type="submit" value="Перевести кредиты">
|
2018-02-27 05:14:11 +00:00
|
|
|
|
</form>
|
2018-03-22 22:35:17 +00:00
|
|
|
|
<span class="wrap">Комиссия: 5% от переводимой суммы, но не менее 1 кр.</span>
|
2018-02-27 05:14:11 +00:00
|
|
|
|
</div>
|
2018-03-22 20:46:12 +00:00
|
|
|
|
<div class="appblock">
|
2018-03-22 22:27:08 +00:00
|
|
|
|
<span class="legend">Обменять екр. на кр.</span>
|
2018-03-22 20:46:12 +00:00
|
|
|
|
<form method="post">
|
|
|
|
|
<input size="10" name="summa" placeholder="Сумма">
|
|
|
|
|
<input type="hidden" name="action" value="donate-exchange">
|
|
|
|
|
<input type=submit value="Обменять">
|
|
|
|
|
</form>
|
2018-03-22 22:35:17 +00:00
|
|
|
|
<span class="wrap">Курс обмена: 1:5.</span>
|
2018-03-22 20:46:12 +00:00
|
|
|
|
</div>
|
2018-03-22 21:09:41 +00:00
|
|
|
|
<?
|
2018-02-27 05:14:11 +00:00
|
|
|
|
} # Очень важная и гордая кавычка!
|
2018-01-28 16:40:49 +00:00
|
|
|
|
?>
|
|
|
|
|
</body>
|
|
|
|
|
</html>
|