battles/clan.php

241 lines
12 KiB
PHP
Raw Normal View History

2018-01-28 16:40:49 +00:00
<?php
ob_start("ob_gzhandler");
2018-03-03 11:50:13 +00:00
session_start();
if (empty($_SESSION['uid'])) {
header("Location: index.php");
}
2018-03-03 11:50:13 +00:00
include_once 'functions.php';
if (!$user->clan) {
2018-03-03 11:50:13 +00:00
die(err('Вы не состоите в клане!'));
}
try {
$clanRow = db::c()->query('SELECT * FROM `clans` WHERE `id` = ?i', $user['klan'])->fetch_assoc();
$polno = unserialize($clanRow['vozm']) ?? [];
} catch (Exception $e) {
echo "MYSQL_ERROR: Таблицы clans не существует! Вся панель — одна сплошная ошибка!";
}
define('COST_ADD_MEMBER', 100);
define('COST_REMOVE_MEMBER', 30);
define('CASTLE_REPUTATION_NEEDED', 1000000);
define('CASTLE_COST', 25000);
$status = null;
$action = $_POST['action'] ?? 0;
$login = $_POST['login'] ?? 0;
$zamok = $_POST['zamok'] ?? null;
$kr = $_POST['kr'] ?? null;
$kolv = $_POST['kolv'] ?? null;
$newClanStatus = $_POST['new_status'] ?? null;
$vin = $_POST['vin'] ?? null;
$tus = $_POST['tus'] ?? null;
2019-06-20 21:48:46 +00:00
if ($zamok) {
2019-06-20 21:48:46 +00:00
db::c()->query('UPDATE `clans` SET `zamok` = 1 WHERE `glava` = ?i', $_SESSION['uid']);
$status = "Начат сбор средств на строительство Кланового Замка.";
2019-06-21 14:35:09 +00:00
header("Location: clan.php");
2019-06-20 21:48:46 +00:00
}
if ($kr && $kolv > 0) {
if ($user->money >= $kolv) {
db::c()->query('UPDATE `clans` SET `zbor` = `zbor` + ?i WHERE `id` = ?i', $kolv, $user->clan);
db::c()->query('UPDATE `users` SET `money` = `money` - ?i WHERE `id` = ?i', $kolv, $user->id);
2019-06-21 14:35:09 +00:00
header("Location: clan.php");
} else {
$status = 'Не хватает денег!';
}
2019-06-20 21:48:46 +00:00
}
if ($login && $action == 'add_member' && $polno[$user['id']][0] == 1) {
$sok = db::c()->query('SELECT id, level, clan FROM users WHERE align = 0 AND login = "?s"', $login)->fetch_assoc();
$proverka = db::c()->query('SELECT 1 FROM users_effects WHERE type = 20 AND owner_id = ?i', $sok['id'])->getNumRows();
if (!$proverka) {
echo "Нет проверки!";
} elseif ($sok['clan']) {
echo 'Персонаж уже состоит в клане!';
} elseif ($sok['level'] > 0 && $user->money >= COST_ADD_MEMBER) {
db::c()->query('UPDATE users SET money = money - ?i WHERE `id` = ?i', COST_ADD_MEMBER, $_SESSION['uid']);
db::c()->query('UPDATE users SET clan = "?s", align = ?i WHERE id = ?i', $clanRow['id'], $clanRow['align'], $sok['id']);
2019-06-22 14:10:37 +00:00
$status = 'Персонаж «' . $login . '» успешно принят в клан.';
} else {
$status = 'Не хватает денег, или персонажа не существует.';
}
2019-06-20 23:37:39 +00:00
}
if ($login && $action == 'remove_member' && $polno[$user['id']][0] == 1) {
$sok = db::c()->query('SELECT id FROM users WHERE clan = "?s" AND login = "?s"', $clanRow['id'], $login)->fetch_assoc();
if ($sok['id'] != $clanRow['glava'] && $user->money >= COST_REMOVE_MEMBER) {
db::c()->query('UPDATE users SET money = money - ?i WHERE id = ?i', COST_REMOVE_MEMBER, $_SESSION['uid']);
db::c()->query('UPDATE users SET clan = "?s", align = 0 WHERE id = ?i', '', $sok['id']);
2019-06-22 14:10:37 +00:00
$status = 'Персонаж «' . $login . '» покинул клан.';
2019-06-20 23:37:39 +00:00
}
}
if ($login && $action == 'change_owner' && $clanRow['glava'] == $_SESSION['uid']) {
$sok = db::c()->query('SELECT id FROM users WHERE clan = "?s" AND login = "?s"', $clanRow['id'], $login)->fetch_assoc();
db::c()->query('UPDATE clans SET glava = ?i WHERE id = ?i', $sok['id'], $clanRow['id']);
db::c()->query('UPDATE users SET status = "?s" WHERE id = ?i', '', $sok['id']);
db::c()->query('UPDATE users SET status = "?s" WHERE id = ?i', 'Боец', $_SESSION['uid']);
$clanRow['glava'] = $sok['id'];
2019-06-20 23:37:39 +00:00
}
if ($login && $action == 'edit_status') {
$sok = db::c()->query('SELECT id, status FROM users WHERE clan = "?s" AND login = "?s"', $clanRow['id'], $login)->fetch_assoc();
if ($sok['id'] != $clanRow['glava']) {
if ($newClanStatus) {
$st = strip_tags(str_replace("&lt;", "<", str_replace("&gt;", ">", $newClanStatus)), "<B><I><U>");
db::c()->query('UPDATE users SET status = "?s" WHERE id = ?i', $st, $sok['id']);
2019-06-22 14:13:47 +00:00
$sok['status'] = $st;
}
if ($clanRow['glava'] == $_SESSION['uid']) {
if ($vin) {
$polno[$sok['id']][0] = 1;
} else {
$polno[$sok['id']][0] = 0;
}
if ($tus) {
$polno[$sok['id']][1] = 1;
} else {
$polno[$sok['id']][1] = 0;
}
db::c()->query('UPDATE clans SET vozm = "?s" WHERE id = ?i', serialize($polno), $clanRow['id']);
}
} else {
$status = 'Главу клана редактировать запрещено!';
}
}
$clan_memberlist = db::c()->query('SELECT `id`, `login`, `status`, `level`, `room`, `align`, (select `id` from `online` WHERE `date` >= ?i AND `id` = users.`id`) AS `online` FROM `users` WHERE `klan` = ?i ORDER BY `online` DESC , `login` ASC', (time() - 60), $clanRow['id']);
2018-01-28 16:40:49 +00:00
?>
2018-03-03 11:50:13 +00:00
<!doctype html>
<html>
<head>
<link rel=stylesheet href="css/main.css">
<meta charset="utf-8">
</head>
2018-03-03 12:29:30 +00:00
<body>
2019-06-22 12:49:35 +00:00
<div>
<button onclick="location.href='main.php'">Вернуться</button>
<?php if (!empty($status)) {err($status);} ?>
</div>
2019-06-20 21:48:46 +00:00
<table style="width: 100%">
2018-03-03 11:50:13 +00:00
<tr>
2019-06-22 12:27:35 +00:00
<td>
<p style="width: 50%; vertical-align: top;" rowspan=2>
<h3><img src="./i/clan/<?= $clanRow['short'] ?>.gif"><?= $clanRow['name'] ?></h3>
2019-06-22 12:27:35 +00:00
Количество рейтинговых очков клана: <span
style="color: #428f21; font-size: larger;"><?= $clanRow['rating'] ?></span><br>
<?php if ($polno[$user['id']][0] == 1): ?>
<div>
<span id="add_member">
<input type="submit" onclick="use('add_member')" value="Принять в клан">
</span>
(стоимость услуги: <B><?= COST_ADD_MEMBER ?></B> кр.)
</div>
<div>
<span id="remove_member">
<input type="submit" onclick="use('remove_member')" value="Выгнать из клана">
</span>
(стоимость услуги: <B><?= COST_REMOVE_MEMBER ?></B> кр.)
</div>
<?php endif; ?>
<?php if ($polno[$user['id']][1] == 1 || $clanRow['glava'] == $user['id']): ?>
<?php if ($login && $action == 'edit_status' && $sok['id'] != $clanRow['glava']): ?>
<form method='post'>
<input placeholder='Статус' name='new_status'>
2019-06-22 14:10:37 +00:00
<input type="hidden" name="login" value="<?= $login ?>">
<?php if ($clanRow['glava'] == $user['id']): ?>
<?php if ($polno[$sok['id']][0] == 1): ?>
<br><input type=checkbox name=vin checked> Может принимать/выгонять членов клана
<?php else: ?>
<br><input type=checkbox name=vin> Может принимать/выгонять членов клана
<?php endif; ?>
<?php if ($polno[$sok['id']][1] == 1): ?>
<br><input type=checkbox name=tus checked> Может менять статус членов клана
<?php else: ?>
<br><input type=checkbox name=tus> Может менять статус членов клана
<?php endif; ?>
<?php endif; ?>
<button name='action' value='edit_status' type='submit'>Ок</button>
<button>×</button>
</form>
<?php else: ?>
<div>
<span id="edit_status">
<input type="submit" onclick="use('edit_status')" value="Редактировать статус">
</span>
</div>
<?php endif; ?>
<?php endif; ?>
<?php if ($clanRow['glava'] == $user['id']): ?>
<div>
<span id="change_owner">
<input type="submit" onclick="use('change_owner')" value="Сменить главу клана">
</span>
(сложить с себя полномочия, назначив <b style="color: teal;">Главой Клана</b> другого персонажа)
</div>
<?php if (empty($clanRow['zamok'])): ?>
<?php if ($clanRow['rating'] < CASTLE_REPUTATION_NEEDED): ?>
Недостаточно рейтинга для постройки замка. <?= showProgressBar($clanRow['rating'], CASTLE_REPUTATION_NEEDED) ?>
<?php else: ?>
<form method="post">
<button type="submit" name="zamok" value="zamok">Построить Замок</button>
(собрать силами всего клана <?= CASTLE_COST ?> кр.)<BR>
</form>
<?php endif; ?>
<?php endif; ?>
<?php endif; ?>
2018-03-03 15:52:28 +00:00
<?php if ($clanRow['zamok'] == 1): ?>
2019-06-22 12:26:14 +00:00
<p>
<?php if ($clanRow['zbor'] < CASTLE_COST): ?>
Сбор средств на постройку кланового замка:
<?= showProgressBar($clanRow['zbor'], CASTLE_COST) ?>
2019-06-22 12:20:02 +00:00
<form method="post">
<input name="kolv" size="10">
<button type="submit" name="kr" value="kr">Пожертвовать</button>
</form>
<?php else: ?>
Средства на постройку кланового замка собраны!
<?= showProgressBar(CASTLE_COST, CASTLE_COST) ?>
<?php endif; ?>
<?php endif; ?>
2018-03-03 11:50:13 +00:00
</td>
<td style="vertical-align: top;">
2019-06-20 23:02:30 +00:00
<h3>Соклановцы</h3>
2019-06-22 12:52:55 +00:00
<table class="zebra" style="width: 100%;">
2019-06-22 12:49:35 +00:00
<tr>
<th>Имя</th>
<th>Статус</th>
<th>Местонахождение</th>
</tr>
2019-06-22 12:51:07 +00:00
<?php
while ($row = $clan_memberlist->fetch_assoc()):
if ($row['id'] == $clanRow['glava']) {
$row['status'] = '<b style="color: #008080;">Глава клана</b>';
}
if (empty($row['status'])) {
$row['status'] = 'Боец';
}
if (empty($row['online'])) {
$rrm = 'Персонаж не в игре';
} elseif ($row['room'] > 500 && $row['room'] < 561) {
$rrm = 'Башня смерти';
} else {
$rrm = $rooms[$row['room']];
}
2019-06-22 12:51:07 +00:00
?>
<tr>
<td><?= Nick::id($row['id'])->full() ?></td>
2019-06-22 12:49:35 +00:00
<td><?= $row['status'] ?></td>
<td><i style="font-size: smaller;"><?= $rrm ?></i></td>
2019-06-22 12:51:07 +00:00
</tr>
<?php endwhile; ?>
2019-06-22 12:49:35 +00:00
</table>
2018-03-03 11:50:13 +00:00
</td>
</tr>
2018-01-28 16:40:49 +00:00
</table>
2019-06-20 21:48:46 +00:00
<script type="text/javascript">
function use(option) {
2019-06-20 23:57:48 +00:00
document.getElementById(option).innerHTML = "<form method='post'><input placeholder='Имя персонажа' name='login'><button name='action' value='" + option + "' type='submit'>Ок</button><button>×</button></form>";
2019-06-20 21:48:46 +00:00
}
</script>
2018-01-28 16:40:49 +00:00
</body>
</html>