449 lines
21 KiB
PHP
449 lines
21 KiB
PHP
<?php
|
||
ob_start("ob_gzhandler");
|
||
session_start();
|
||
if ($_SESSION['uid'] == null) header("Location: index.php");
|
||
include "config.php";
|
||
include "functions.php";
|
||
if ($user['room'] != 29) header("Location: main.php");
|
||
if ($user['battle'] != 0) {
|
||
header('location: fbattle.php');
|
||
die();
|
||
}
|
||
$bank = db::c()->query('SELECT `id`, `cr`, `ekr` FROM `bank` WHERE `id` = ?i', $_SESSION['uid'])->fetch_assoc();
|
||
|
||
/**
|
||
* Если вдруг нет счёта, создаём.
|
||
*/
|
||
if (!$bank['id']) {
|
||
db::c()->query('INSERT INTO `bank` (`id`) VALUES (?i)', $_SESSION['uid']);
|
||
}
|
||
?>
|
||
|
||
<!DOCTYPE html>
|
||
<html>
|
||
<head>
|
||
<meta charset="utf-8">
|
||
<link href="css/main.css" rel="stylesheet"/>
|
||
<title>Банк</title>
|
||
<script>
|
||
function leave() {
|
||
top.frames['main'].location = 'city.php?strah'
|
||
}
|
||
</script>
|
||
<script src="/js/jquery-1.7.2.min.js"></script>
|
||
<style>
|
||
.appblock {
|
||
background: silver;
|
||
border-radius: 2px;
|
||
float: left;
|
||
height: 200px;
|
||
margin: 10px;
|
||
width: 250px;
|
||
opacity: 0.75;
|
||
padding: 5px;
|
||
}
|
||
|
||
div.appblock form {
|
||
margin: 5px;
|
||
}
|
||
|
||
div.appblock span {
|
||
padding: 0.2em 0.5em;
|
||
color: #666;
|
||
font-weight: bold;
|
||
display: block;
|
||
}
|
||
div.appblock br {
|
||
margin:5px;
|
||
}
|
||
</style>
|
||
</head>
|
||
<body>
|
||
<h1>Банк</h1>
|
||
<table class='adm'>
|
||
<tr>
|
||
<th>№</th>
|
||
<th>Кредитов.</th>
|
||
<th>ЕвроКредитов.</th>
|
||
</tr>
|
||
<tr>
|
||
<td><?=$bank['id']?></td>
|
||
<td><?=$bank['cr']?></td>
|
||
<td><?=$bank['ekr']?></td>
|
||
</tr>
|
||
</table><br>
|
||
<?php
|
||
|
||
if ($_GET['exit']) {
|
||
$_SESSION['bankid'] = null;
|
||
}
|
||
|
||
if (isset($_POST['userlogin'])) {
|
||
$_SESSION['bankid'] = $_SESSION['uid'];
|
||
}
|
||
|
||
if (!$_SESSION['bankid']) {
|
||
?>
|
||
<a href=# onclick=leave()> ← выйти из банка</a>
|
||
<form method="post"><input type="submit" name="userlogin" value="Управление счётом"></form>
|
||
<?
|
||
} else {
|
||
|
||
$toid = filter_input(INPUT_POST, 'to-id');
|
||
$summa = filter_input(INPUT_POST, 'summa');
|
||
$submit = filter_input(INPUT_POST, 'action');
|
||
|
||
|
||
/**
|
||
* Зачисдение кредитов на счёт.
|
||
*/
|
||
if ($submit == 'money-in' && $summa) {
|
||
if ($summa > 0 && ($summa <= $user['money'])) {
|
||
$user['money'] -= $summa;
|
||
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']);
|
||
db::c()->query('INSERT INTO `bank_logs` (`user_id`, `sum`, `type`, `comments`, `source`)
|
||
VALUES (?i, ?i, "?s", "?s", ?i)', $bank['id'], $summa, 'money-in', 'Банк: Зачисление средств на счёт', $bank['id']);
|
||
} else {
|
||
$mywarn = "У вас недостаточно денег для выполнения операции";
|
||
}
|
||
$submit = '';
|
||
$summa = 0;
|
||
}
|
||
|
||
/**
|
||
* Снятие кредитов со счёта.
|
||
*/
|
||
if ($submit == 'money-out' && $summa) {
|
||
if ($summa > 0 && ($summa <= $bank['cr'])) {
|
||
$user['money'] += $summa;
|
||
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']);
|
||
db::c()->query('INSERT INTO `bank_logs` (`user_id`, `sum`, `type`, `comments`, `source`)
|
||
VALUES (?i, ?i, "?s", "?s", ?i)', $bank['id'], $summa, 'money-out', 'Банк: Вывод средств на руки', $bank['id']);
|
||
} else {
|
||
$mywarn = "У вас недостаточно денег на счету для выполнения операции";
|
||
}
|
||
$submit = '';
|
||
$summa = 0;
|
||
}
|
||
|
||
/**
|
||
* Перевод кредитов на другой счёт.
|
||
*/
|
||
if ($submit == 'money-send' && $summa && $toid) {
|
||
$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']) {
|
||
db::c()->query('UPDATE `bank` SET `cr` = `cr` - ?i WHERE `id` = ?i', $new_summa, $bank['id']);
|
||
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`)
|
||
VALUES (?i, ?i, "?s", "?s", ?i)', $toid, $summa, 'money-in', 'Получение банковского перевода.', $bank['id']);
|
||
db::c()->query('INSERT INTO `bank_logs` (`user_id`, `sum`, `type`, `comments`, `source`)
|
||
VALUES (?i, ?i, "?s", "?s", ?i)', $bank['id'], $new_summa, 'money-send', 'Банк: Перевод средств на другой счёт. Комиссия: '.$nalog.'.', $toid);
|
||
} else {
|
||
$mywarn = "У вас недостаточно денег на счету для выполнения операции";
|
||
}
|
||
} else {
|
||
$mywarn = "Укажите сумму!";
|
||
}
|
||
} else {
|
||
$mywarn = "Счёт не существует.";
|
||
}
|
||
$submit = '';
|
||
$summa = 0;
|
||
$toid = 0;
|
||
}
|
||
|
||
|
||
if ($_POST['change'] && $_POST['ok']) {
|
||
$_POST['ok'] = round($_POST['ok'], 2);
|
||
if (is_numeric($_POST['ok']) && ($_POST['ok'] > 0) && ($_POST['ok'] <= $bank['ekr'])) {
|
||
$bank['cr'] += $_POST['ok'] * 100;
|
||
$bank['ekr'] -= $_POST['ok'];
|
||
$add_money = $_POST['ok'] * 100;
|
||
if (mysql_query("UPDATE `bank` SET `cr`=`cr`+'$add_money' WHERE `id`='" . $bank['id'] . "' LIMIT 1;")) {
|
||
$mywarn = "Обмен произведен успешно";
|
||
mysql_query("UPDATE `bank` SET `ekr`=`ekr`-'" . $_POST['ok'] . "' WHERE `id`='" . $_SESSION['bankid'] . "' LIMIT 1;");
|
||
$bank = mysql_fetch_array(mysql_query("SELECT * FROM `bank` WHERE `id`='" . $_SESSION['bankid'] . "';"));
|
||
mysql_query("INSERT INTO `delo` (`id`,`author`,`pers`,`text`,`type`,`date`) VALUES ('','0','" . $_SESSION['uid'] . "','Персонаж " . $user['login'] . " обменял " . $_POST['ok'] . " екр. на " . $add_money . " кр. на счету №" . $_SESSION['bankid'] . " в банке. ',1,'" . time() . "');");
|
||
} else {
|
||
$mywarn = "Произошла ошибка!";
|
||
}
|
||
} else {
|
||
$mywarn = "У вас недостаточно денег на валютном счету для выполнения операции";
|
||
}
|
||
$_POST['change'] = 0;
|
||
}
|
||
|
||
if ($_GET['dropm']) {
|
||
if (2 <= $bank['ekr']) {
|
||
undressall($user['id']);
|
||
if (mysql_query("UPDATE `users` SET `master`=noj+mec+topor+dubina+mfire+mwater+mair+mearth+mlight+mgray+mdark+master,noj=0,mec=0,topor=0,dubina=0,mfire=0,mwater=0,mair=0,mearth=0,mlight=0,mgray=0,mdark=0 WHERE `id`='" . $user['id'] . "' LIMIT 1;")) {
|
||
mysql_query("UPDATE `bank` SET `ekr`=`ekr`-'2' WHERE `id`='" . $_SESSION['bankid'] . "' LIMIT 1;");
|
||
mysql_query("INSERT INTO `delo` (`id`,`author`,`pers`,`text`,`type`,`date`) VALUES ('','0','" . $_SESSION['uid'] . "','" . $user['login'] . " перераспределил умения, заплатив 2 екр. со счета №" . $_SESSION['bankid'] . " в банке. ',1,'" . time() . "');");
|
||
$bank = mysql_fetch_array(mysql_query("SELECT * FROM `bank` WHERE `id`='" . $_SESSION['bankid'] . "';"));
|
||
$mywarn = "Все прошло удачно. Вы можете перераспределить умения.";
|
||
} else {
|
||
$mywarn = "Произошла ошибка!";
|
||
}
|
||
} else {
|
||
$mywarn = "У вас недостаточно денег на валютном счету для выполнения операции";
|
||
}
|
||
$_GET['dropm'] = 0;
|
||
}
|
||
|
||
if ($_GET['dropst']) {
|
||
$travma = mysql_fetch_array(mysql_query("SELECT * FROM `effects` WHERE `owner`='" . $user['id'] . "' AND (`type`=11 OR `type`=12 OR `type`=13 OR `type`=14) ORDER BY `type` DESC LIMIT 1;"));
|
||
if ($travma['type']) {
|
||
$mywarn = "Невозможно сбрасывать статы находясь в травме!";
|
||
} else {
|
||
undressall($user['id']);
|
||
$user1 = mysql_fetch_array(mysql_query("SELECT * FROM `users` WHERE `id`='" . $user['id'] . "' LIMIT 1;"));
|
||
$svstats = $user1['sila'] + $user1['lovk'] + $user1['inta'] + $user1['vinos'] + $user1['intel'] + $user1['mudra'] - 12 - $user1['level'];
|
||
if ($svstats <= $bank['ekr']) {
|
||
$exps = ["20" => [15],
|
||
"45" => [16],
|
||
"75" => [17],
|
||
"110" => [18],
|
||
"160" => [21],
|
||
"215" => [22],
|
||
"280" => [23],
|
||
"350" => [24],
|
||
"410" => [25],
|
||
"530" => [28],
|
||
"670" => [29],
|
||
"830" => [30],
|
||
"950" => [31],
|
||
"1100" => [32],
|
||
"1300" => [33],
|
||
"1450" => [36],
|
||
"1650" => [37],
|
||
"1850" => [38],
|
||
"2050" => [39],
|
||
"2200" => [40],
|
||
"2500" => [41],
|
||
"2900" => [46],
|
||
"3350" => [47],
|
||
"3800" => [48],
|
||
"4200" => [49],
|
||
"4600" => [50],
|
||
"5000" => [51],
|
||
"6000" => [54],
|
||
"7000" => [55],
|
||
"8000" => [56],
|
||
"9000" => [57],
|
||
"10000" => [58],
|
||
"11000" => [59],
|
||
"12000" => [60],
|
||
"12500" => [61],
|
||
"14000" => [64],
|
||
"15500" => [65],
|
||
"17000" => [66],
|
||
"19000" => [67],
|
||
"21000" => [68],
|
||
"23000" => [69],
|
||
"26000" => [70],
|
||
"30000" => [71],
|
||
"60000" => [76],
|
||
"75000" => [77],
|
||
"150000" => [78],
|
||
"175000" => [79],
|
||
"200000" => [80],
|
||
"225000" => [81],
|
||
"250000" => [82],
|
||
"260000" => [83],
|
||
"280000" => [84],
|
||
"300000" => [85],
|
||
"1500000" => [86],
|
||
"1750000" => [87],
|
||
"2000000" => [88],
|
||
"2175000" => [89],
|
||
"2300000" => [90],
|
||
"2400000" => [91],
|
||
"2500000" => [92],
|
||
"2600000" => [93],
|
||
"2800000" => [94],
|
||
"3000000" => [95],
|
||
"6000000" => [96],
|
||
"6500000" => [97],
|
||
"7500000" => [98],
|
||
"8500000" => [99],
|
||
"9000000" => [100],
|
||
"9250000" => [101],
|
||
"9500000" => [102],
|
||
"9750000" => [103],
|
||
"9900000" => [104],
|
||
"10000000" => [105],
|
||
"13000000" => [106],
|
||
"14000000" => [107],
|
||
"15000000" => [108],
|
||
"16000000" => [109],
|
||
"17000000" => [110],
|
||
"17500000" => [111],
|
||
"18000000" => [112],
|
||
"19000000" => [113],
|
||
"19500000" => [114]];
|
||
echo "<pre>";
|
||
$ss = mysql_query("SELECT `id`,`nextup`,`level` FROM `users` WHERE `level` > 0 AND `level` < 8 AND id='" . $user['id'] . "';");
|
||
$errdo = 0;
|
||
while ($ssd = mysql_fetch_array($ss)) {
|
||
undressall($ssd['id']);
|
||
if (!mysql_query("UPDATE `users` SET `sila`='3',`lovk`='3',`inta`='3',`vinos`='" . (3 + $ssd['level']) . "',`intel`='0',`fkrit`='0',`fakrit`='0',`fuvorot`='0',`fauvorot`='0',`stats`='" . ($exps[$ssd['nextup']][0] - 12) . "' WHERE `id`='" . $ssd['id'] . "';")) $errdo = 1;
|
||
}
|
||
if ($errdo == 0) {
|
||
mysql_query("UPDATE `bank` SET `ekr`=`ekr`-'" . $svstats . "' WHERE `id`='" . $_SESSION['bankid'] . "' LIMIT 1;");
|
||
mysql_query("INSERT INTO `delo` (`id`,`author`,`pers`,`text`,`type`,`date`) VALUES ('','0','" . $_SESSION['uid'] . "','" . $user['login'] . " перераспределил статы, заплатив " . $svstats . " екр. со счета №" . $_SESSION['bankid'] . " в банке. ',1,'" . time() . "');");
|
||
$bank = mysql_fetch_array(mysql_query("SELECT * FROM `bank` WHERE `id`='" . $_SESSION['bankid'] . "';"));
|
||
$mywarn = "Все прошло удачно. Вы можете перераспределить статы.";
|
||
} else {
|
||
$mywarn = "Произошла ошибка! Обратитесь к палладинам.";
|
||
}
|
||
|
||
$vinos = $user1['level'] + 3;
|
||
$hp = $vinos * 6;
|
||
if (mysql_query("UPDATE `users` SET `stats`='" . $svstats . "',lovk=3,sila=3,inta=3,vinos='" . $vinos . "',hp='" . $hp . "',maxhp='" . $hp . "',intel=0,mudra=0 WHERE `id`='" . $user['id'] . "' LIMIT 1;")) {
|
||
mysql_query("UPDATE `bank` SET `ekr`=`ekr`-'" . $svstats . "' WHERE `id`='" . $_SESSION['bankid'] . "' LIMIT 1;");
|
||
mysql_query("INSERT INTO `delo` (`id`,`author`,`pers`,`text`,`type`,`date`) VALUES ('','0','" . $_SESSION['uid'] . "','" . $user['login'] . " перераспределил статы, заплатив " . $svstats . " екр. со счета №" . $_SESSION['bankid'] . " в банке. ',1,'" . time() . "');");
|
||
$bank = mysql_fetch_array(mysql_query("SELECT * FROM `bank` WHERE `id`='" . $_SESSION['bankid'] . "';"));
|
||
|
||
$mywarn = "Все прошло удачно. Вы можете перераспределить статы.";
|
||
|
||
} else {
|
||
$mywarn = "Произошла ошибка!";
|
||
}
|
||
} else {
|
||
$mywarn = "У вас недостаточно денег на валютном счету для выполнения операции";
|
||
}
|
||
}
|
||
$_GET['dropst'] = 0;
|
||
}
|
||
|
||
|
||
### Чеки
|
||
/**
|
||
*
|
||
*/
|
||
function bank_show()
|
||
{
|
||
global $user;
|
||
$pl = db::c()->query('SELECT `id`,`name`,`bcost` FROM `inventory` WHERE `owner` = ?i AND `bcost` > 0 ORDER BY `bcost` ASC', $user['id']);
|
||
if ($pl->getNumRows() > 0) {
|
||
echo '<select name=\'coste\'>';
|
||
while ($sp = $pl->fetch_assoc()) {
|
||
echo '<option value=\'' . $sp['id'] . '\'>' . $sp['name'] . '</option>';
|
||
}
|
||
echo '</select> <input class="ctContent" type="submit" value="Обменять" name="saled" />';
|
||
} else {
|
||
echo '<b>Нет чеков для обмена</b>';
|
||
}
|
||
}
|
||
|
||
if ($_POST['sales'] && $_POST['count_ekr'] && (!empty($user['admin']))) {
|
||
if (isset($bank['id'])) {
|
||
$cnt = round($_POST['count_ekr'], 2);
|
||
if ($cnt < 1) {
|
||
err('Минимальная сумма: 1 екр');
|
||
} elseif ($bank['ekr'] < $cnt) {
|
||
err('Недостаточно средств ...');
|
||
} else {
|
||
$name = 'Банковский чек на ' . $cnt . ' еврокредитов';
|
||
db::c()->query('INSERT INTO `inventory` SET `name` = "?s", `bcost` = ?i, `owner` = ?i, `prototype` = ?i', $name, $cnt, $user['id'], 1123);
|
||
// $bank['ekr'] -= $cnt;
|
||
// mysql_query('UPDATE `bank` SET `ekr` = "' . $bank['ekr'] . '" WHERE `id` = "' . $bank['id'] . '" LIMIT 1');
|
||
db::c()->query('UPDATE `bank` SET `ekr` = `ekr` - ?i WHERE `id` = ?i', $cnt, $bank['id']);
|
||
err('Чек на сумму : ' . $cnt . ' екр., появится у Вас в инвентаре ...');
|
||
}
|
||
} else {
|
||
err('Банковский счёт, не найден ...');
|
||
}
|
||
}
|
||
|
||
if ($_POST['saled'] && $_POST['coste'] && (!empty($user['admin']))) {
|
||
$item = mysql_fetch_array(mysql_query('SELECT `id`, `name`, `bcost` FROM `inventory` WHERE `owner` = "' . $user['id'] . '" AND `id` = "' . mysql_real_escape_string($_POST['coste']) . '" LIMIT 1'));
|
||
if (isset($item['id'])) {
|
||
if ($item['bcost'] > 0) {
|
||
mysql_query('DELETE FROM `inventory` WHERE `owner` = "' . $user['id'] . '" AND `id` = "' . $item['id'] . '" LIMIT 1');
|
||
$bank['ekr'] += $item['bcost'];
|
||
mysql_query('UPDATE `bank` SET `ekr` = "' . $bank['ekr'] . '" WHERE `id` = "' . $bank['id'] . '" LIMIT 1');
|
||
err($item['name'] . ', успешно обналичен ...');
|
||
} else {
|
||
err('Это не чек ...');
|
||
}
|
||
} else {
|
||
err('Чек, не найден ...');
|
||
}
|
||
}
|
||
###
|
||
|
||
err($mywarn);
|
||
$mywarn = '';
|
||
?>
|
||
<a href="?exit=1"> ← выйти из счёта</a>
|
||
<br><br>Красным <span style="background:#FFAAAA;">помечены</span> нерабочие элементы.<br>
|
||
<div class="appblock">
|
||
<span>Денежные средства</span>
|
||
Кредитов на руках: <b><?=$user['money']?></b> кр.<br>
|
||
<form method="post">
|
||
<input size="10" name="summa" placeholder="Сумма">
|
||
<input type="hidden" name="action" value="money-in">
|
||
<input type="submit" value="Положить на счёт">
|
||
</form>
|
||
<form method="post">
|
||
<input size="10" name="summa" placeholder="Сумма">
|
||
<input type="hidden" name="action" value="money-out">
|
||
<input type="submit" value="Снять со счёта">
|
||
</form>
|
||
</div>
|
||
|
||
<div class="appblock">
|
||
<span>Перевод кредитов</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="money-send">
|
||
<input type="submit" value="Перевести кредиты">
|
||
</form>
|
||
<i>Комиссия составит 5% от переводимой суммы, но не менее 1 кр.</i>
|
||
</div>
|
||
|
||
<? if (!empty($user['admin'])): ?>
|
||
<div class="appblock" style="background:#FFAAAA;">
|
||
<legend>Обменять екр. на кр.</legend>
|
||
Курс обмена: 1 екр. = 5 кр.<br>
|
||
<form method="POST">
|
||
Сумма екр. для обмена
|
||
<input type=text name=ok placeholder="Сумма">
|
||
<input type=submit name=change value="обменять">
|
||
</form>
|
||
</div>
|
||
|
||
<div class="appblock" style="background:#FFAAAA;">
|
||
<legend>Выписать чек</legend>
|
||
Услуга "чек на предъявителя". Вы выписываете екровый чек, который затем сможет обналичить любой
|
||
персонаж.<br>
|
||
<form method="POST">
|
||
Сумма (екр): <input type="text" size="4" name="count_ekr"/> <input type="submit" value="Выписать"
|
||
name="sales"/>
|
||
</form>
|
||
</div>
|
||
<div class="appblock" style="background:#FFAAAA;">
|
||
<legend>Обналичить чек</legend>
|
||
В нашем банке мы принимаем к погашению екровые чеки на предъявителя.
|
||
<form method="POST">
|
||
<?php bank_show(); ?>
|
||
</form>
|
||
</div>
|
||
<?php endif;
|
||
} # Очень важная и гордая кавычка!
|
||
?>
|
||
|
||
</body>
|
||
</html>
|