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");
|
|
|
|
|
include "config.php";
|
|
|
|
|
include "functions.php";
|
2018-02-27 03:53:10 +00:00
|
|
|
|
if ($user['room'] != 29) header("Location: main.php");
|
|
|
|
|
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: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"/>
|
|
|
|
|
<title>Банк</title>
|
|
|
|
|
<script>
|
2018-02-27 05:41:56 +00:00
|
|
|
|
function leave() {
|
2018-03-09 18:07:04 +00:00
|
|
|
|
top.frames['main'].location = 'city.php?strah'
|
2018-02-27 03:53:10 +00:00
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
<script src="/js/jquery-1.7.2.min.js"></script>
|
|
|
|
|
<style>
|
|
|
|
|
.appblock {
|
|
|
|
|
background: silver;
|
|
|
|
|
border-radius: 2px;
|
|
|
|
|
float: left;
|
|
|
|
|
height: 200px;
|
|
|
|
|
margin: 10px;
|
2018-03-09 21:12:03 +00:00
|
|
|
|
width: 250px;
|
2018-02-27 03:53:10 +00:00
|
|
|
|
opacity: 0.75;
|
|
|
|
|
padding: 5px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
div.appblock form {
|
2018-03-09 21:12:03 +00:00
|
|
|
|
margin: 5px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
div.appblock span {
|
|
|
|
|
padding: 0.2em 0.5em;
|
|
|
|
|
color: #666;
|
|
|
|
|
font-weight: bold;
|
|
|
|
|
display: block;
|
|
|
|
|
}
|
2018-03-22 21:09:41 +00:00
|
|
|
|
|
2018-03-09 21:12:03 +00:00
|
|
|
|
div.appblock br {
|
2018-03-22 21:09:41 +00:00
|
|
|
|
margin: 5px;
|
2018-02-27 03:53:10 +00:00
|
|
|
|
}
|
|
|
|
|
</style>
|
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-03-09 22:34:51 +00:00
|
|
|
|
<table class='adm'>
|
|
|
|
|
<tr>
|
|
|
|
|
<th>№</th>
|
|
|
|
|
<th>Кредитов.</th>
|
|
|
|
|
<th>ЕвроКредитов.</th>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
2018-03-22 21:09:41 +00:00
|
|
|
|
<td><?= $bank['id'] ?></td>
|
|
|
|
|
<td><?= $bank['cr'] ?></td>
|
|
|
|
|
<td><?= $bank['ekr'] ?></td>
|
2018-03-09 22:34:51 +00:00
|
|
|
|
</tr>
|
2018-03-22 21:09:41 +00:00
|
|
|
|
</table>
|
|
|
|
|
<br>
|
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
|
|
|
|
?>
|
2018-02-27 05:41:56 +00:00
|
|
|
|
<a href=# onclick=leave()> ← выйти из банка</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:09:41 +00:00
|
|
|
|
<a href="?exit"> ← выйти из счёта</a>
|
2018-02-27 05:14:11 +00:00
|
|
|
|
<div class="appblock">
|
2018-03-09 21:12:03 +00:00
|
|
|
|
<span>Денежные средства</span>
|
2018-03-22 21:09:41 +00:00
|
|
|
|
Кредитов на руках: <b><?= $user['money'] ?></b> кр.<br>
|
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-09 22:16:41 +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-09 22:16:41 +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-09 21:12:03 +00:00
|
|
|
|
<span>Перевод кредитов</span>
|
|
|
|
|
<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-09 22:01:20 +00:00
|
|
|
|
<i>Комиссия составит 5% от переводимой суммы, но не менее 1 кр.</i>
|
2018-02-27 05:14:11 +00:00
|
|
|
|
</div>
|
2018-03-22 20:46:12 +00:00
|
|
|
|
<div class="appblock">
|
|
|
|
|
<span>Обменять екр. на кр.</span>
|
|
|
|
|
<form method="post">
|
|
|
|
|
<input size="10" name="summa" placeholder="Сумма">
|
|
|
|
|
<input type="hidden" name="action" value="donate-exchange">
|
|
|
|
|
<input type=submit value="Обменять">
|
|
|
|
|
</form>
|
|
|
|
|
<i>Курс обмена: 1:5.</i>
|
|
|
|
|
</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>
|