229 lines
11 KiB
PHP
229 lines
11 KiB
PHP
<?php
|
||
|
||
use Battles\Bank;
|
||
use Battles\Database\DBPDO;
|
||
use Battles\Nick;
|
||
use Battles\Rooms;
|
||
use Battles\Template;
|
||
use Battles\User;
|
||
|
||
ob_start("ob_gzhandler");
|
||
session_start();
|
||
require_once 'functions.php';
|
||
$user = $user ?? new User($_SESSION['uid']);
|
||
$db = new DBPDO();
|
||
$clanRow = [];
|
||
if (!$user->clan) {
|
||
exit(err('Вы не состоите в клане!'));
|
||
}
|
||
try {
|
||
$clanRow = $db->fetch('SELECT * FROM `clans` WHERE short_name = ?', $user->clan);
|
||
} catch (Exception $e) {
|
||
echo "<div>MYSQL_ERROR: Таблица clans сломана!</div>";
|
||
}
|
||
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;
|
||
$lock = true; // блокировка функций
|
||
|
||
if ($zamok && !$lock) {
|
||
$db->execute('UPDATE `clans` SET `zamok` = 1 WHERE `glava` = ?', $user->id);
|
||
$status = "Начат сбор средств на строительство Кланового Замка.";
|
||
header("Location: clan.php");
|
||
}
|
||
if ($kr && $kolv > 0 && !$lock) {
|
||
if ($user->money >= $kolv) {
|
||
$db->execute('UPDATE clans SET zbor = zbor + ? WHERE id = ?', [$kolv, $user->clan]);
|
||
Bank::setWalletMoney($user->money -= $kolv, $user->id);
|
||
header("Location: clan.php");
|
||
} else {
|
||
$status = 'Не хватает денег!';
|
||
}
|
||
}
|
||
if ($login && $action == 'add_member') {
|
||
$sok = $db->fetch('SELECT id, level, clan FROM users WHERE align = 0 AND login = ?', $login);
|
||
$proverka = $db->fetch('SELECT 1 FROM users_effects WHERE type = 20 AND owner_id = ?', $sok['id']);
|
||
if (!$proverka) {
|
||
echo "Нет проверки!";
|
||
} elseif ($sok['clan']) {
|
||
echo 'Персонаж уже состоит в клане!';
|
||
} elseif ($sok['level'] > 0 && $user->money >= COST_ADD_MEMBER) {
|
||
Bank::setWalletMoney($user->money - COST_ADD_MEMBER, $user->id);
|
||
$db->execute('UPDATE users SET clan = ?, align = ? WHERE id = ?', [$clanRow['id'], $clanRow['align'], $sok['id']]);
|
||
$status = "Персонаж «{$login}» успешно принят в клан.";
|
||
} else {
|
||
$status = 'Не хватает денег, или персонажа не существует.';
|
||
}
|
||
}
|
||
|
||
if ($login) {
|
||
$sok = $db->fetch('SELECT id FROM users WHERE clan = ? AND login = ?', [$clanRow['id'], $login]);
|
||
if ($action == 'remove_member' && $sok['id'] != $clanRow['owner_id'] && $user->money >= COST_REMOVE_MEMBER) {
|
||
Bank::setWalletMoney($user->money - COST_REMOVE_MEMBER, $user->id);
|
||
$db->execute('UPDATE users SET clan = null, align = 0 WHERE id = ?', $sok['id']);
|
||
$status = "Персонаж «{$login}» покинул клан.";
|
||
}
|
||
if ($action == 'change_owner' && $clanRow['owner_id'] == $user->id) {
|
||
$db->execute('UPDATE clans SET owner_id = ? WHERE id = ?', [$sok['id'], $clanRow['id']]);
|
||
$clanRow['owner_id'] = $sok['id'];
|
||
}
|
||
if ($action == 'edit_status' && !$lock) {
|
||
if ($sok['id'] != $clanRow['owner_id']) {
|
||
if ($newClanStatus) {
|
||
$st = strip_tags(str_replace("<", "<", str_replace(">", ">", $newClanStatus)), "<B><I><U>");
|
||
$db->execute('UPDATE users SET status = ? WHERE id = ?', [$st, $sok['id']]);
|
||
$sok['status'] = $st;
|
||
}
|
||
} else {
|
||
$status = 'Главу клана редактировать запрещено!';
|
||
}
|
||
}
|
||
}
|
||
|
||
$clan_memberlist = $db->fetchAll('SELECT id, login, level, align, (SELECT id FROM online WHERE date >= ? AND id = users.id) AS online FROM users WHERE clan = ? ORDER BY online DESC, login', [time() - 60, $clanRow['short_name']]);
|
||
Template::header('clan');
|
||
$clanRow['zamok'] = null; //Замков нет!
|
||
$clanRow['rating'] = null; //рейтов тоже!
|
||
$clanRow['zbor'] = null; // И копилки.
|
||
?>
|
||
<div>
|
||
<button onclick="location.href='main.php'">Вернуться</button>
|
||
<?php if (!empty($status)) {
|
||
err($status);
|
||
} ?>
|
||
</div>
|
||
<table style="width: 100%">
|
||
<tr>
|
||
<td>
|
||
<p style="width: 50%; vertical-align: top;" rowspan=2>
|
||
<h3><img src="./i/clan/<?= $clanRow['short_name'] ?>.png"><?= $clanRow['full_name'] ?></h3>
|
||
|
||
<?php if ($clanRow['owner_id'] == $user->id): ?>
|
||
<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 ($clanRow['owner_id'] == $user->id): ?>
|
||
<?php if ($login && $action == 'edit_status' && $sok['id'] != $clanRow['owner_id']): ?>
|
||
<form method='post'>
|
||
<input placeholder='Статус' name='new_status'>
|
||
<input type="hidden" name="login" value="<?= $login ?>">
|
||
<?php if ($clanRow['glava'] == $user->id): ?>
|
||
<?php if ($clanRow['owner_id'] == $user->id): ?>
|
||
<br><input type=checkbox name=vin checked> Может принимать/выгонять членов клана
|
||
<?php else: ?>
|
||
<br><input type=checkbox name=vin> Может принимать/выгонять членов клана
|
||
<?php endif; ?>
|
||
<?php if ($clanRow['owner_id'] == $user->id): ?>
|
||
<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['owner_id'] == $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; ?>
|
||
|
||
<?php if ($clanRow['zamok'] == 1): ?>
|
||
<p>
|
||
<?php if ($clanRow['zbor'] < CASTLE_COST): ?>
|
||
Сбор средств на постройку кланового замка:
|
||
<?= showProgressBar($clanRow['zbor'], CASTLE_COST) ?>
|
||
<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; ?>
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
<h3>Соклановцы</h3>
|
||
<table class="zebra" style="width: 100%;">
|
||
<tr>
|
||
<th>Имя</th>
|
||
<th>Статус</th>
|
||
<th>Местонахождение</th>
|
||
</tr>
|
||
<?php
|
||
$i = 0;
|
||
while ($i < count($clan_memberlist)):
|
||
if ($clan_memberlist[$i]['id'] == $clanRow['owner_id']) {
|
||
$clan_memberlist[$i]['status'] = '<b style="color: #008080;">Глава клана</b>';
|
||
}
|
||
if (empty($clan_memberlist[$i]['status'])) {
|
||
$clan_memberlist[$i]['status'] = 'Боец';
|
||
}
|
||
if (empty($clan_memberlist[$i]['online'])) {
|
||
$rrm = 'Персонаж не в игре';
|
||
} elseif ($clan_memberlist[$i]['room'] > 500 && $clan_memberlist[$i]['room'] < 561) {
|
||
$rrm = 'Башня смерти';
|
||
} else {
|
||
$rrm = Rooms::$roomNames[$clan_memberlist[$i]['room']];
|
||
}
|
||
?>
|
||
<tr>
|
||
<td><?= Nick::id($clan_memberlist[$i]['id'])->full() ?></td>
|
||
<td><?= $clan_memberlist[$i]['status'] ?></td>
|
||
<td><i style="font-size: smaller;"><?= $rrm ?></i></td>
|
||
</tr>
|
||
<?php $i++; ?>
|
||
<?php endwhile; ?>
|
||
</table>
|
||
</td>
|
||
</tr>
|
||
</table>
|
||
<script type="text/javascript">
|
||
function use(option) {
|
||
document.getElementById(option).innerHTML = "<form method='post'><input placeholder='Имя персонажа' name='login'><button name='action' value='" + option + "' type='submit'>Ок</button><button>×</button></form>";
|
||
}
|
||
</script>
|