2018-01-28 16:40:49 +00:00
< ? php
2021-01-28 15:57:55 +00:00
use Battles\Bank ;
use Battles\Database\DBPDO ;
use Battles\Nick ;
use Battles\Rooms ;
use Battles\Template ;
use Battles\User ;
2018-01-28 16:40:49 +00:00
ob_start ( " ob_gzhandler " );
2018-03-03 11:50:13 +00:00
session_start ();
2020-10-29 23:30:05 +00:00
require_once 'functions.php' ;
2021-01-28 15:57:55 +00:00
$user = $user ? ? new User ( $_SESSION [ 'uid' ]);
$db = new DBPDO ();
$clanRow = [];
2021-02-01 16:42:52 +00:00
if ( ! $user -> getClan ()) {
2020-09-30 12:01:33 +00:00
exit ( err ( 'Вы не состоите в клане!' ));
2018-03-03 11:50:13 +00:00
}
2020-08-29 23:21:22 +00:00
try {
2021-02-01 16:42:52 +00:00
$clanRow = $db -> fetch ( 'SELECT * FROM `clans` WHERE short_name = ?' , $user -> getClan ());
2020-08-29 23:21:22 +00:00
} catch ( Exception $e ) {
2021-01-28 15:57:55 +00:00
echo " <div>MYSQL_ERROR: Таблица clans сломана!</div> " ;
2020-08-29 23:21:22 +00:00
}
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 ;
2021-01-28 15:57:55 +00:00
$lock = true ; // блокировка функций
2019-06-20 21:48:46 +00:00
2021-01-28 15:57:55 +00:00
if ( $zamok && ! $lock ) {
2021-02-01 16:42:52 +00:00
$db -> execute ( 'UPDATE `clans` SET `zamok` = 1 WHERE `glava` = ?' , $user -> getId ());
2019-06-20 21:48:46 +00:00
$status = " Начат с б о р средств на строительство Кланового Замка. " ;
2019-06-21 14:35:09 +00:00
header ( " Location: clan.php " );
2019-06-20 21:48:46 +00:00
}
2021-01-28 15:57:55 +00:00
if ( $kr && $kolv > 0 && ! $lock ) {
2021-02-01 16:42:52 +00:00
if ( $user -> getMoney () >= $kolv ) {
$db -> execute ( 'UPDATE clans SET zbor = zbor + ? WHERE id = ?' , [ $kolv , $user -> getClan ()]);
Bank :: setWalletMoney ( $user -> setMoney ( $user -> getMoney () - $kolv ), $user -> getId ());
2019-06-21 14:35:09 +00:00
header ( " Location: clan.php " );
2020-08-29 23:21:22 +00:00
} else {
$status = 'Н е хватает денег!' ;
}
2019-06-20 21:48:46 +00:00
}
2021-01-28 15:57:55 +00:00
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' ]);
2020-08-29 23:21:22 +00:00
if ( ! $proverka ) {
echo " Нет проверки! " ;
} elseif ( $sok [ 'clan' ]) {
echo 'Персонаж уже состоит в клане!' ;
2021-02-01 16:42:52 +00:00
} elseif ( $sok [ 'level' ] > 0 && $user -> getMoney () >= COST_ADD_MEMBER ) {
Bank :: setWalletMoney ( $user -> setMoney ( $user -> getMoney () - COST_ADD_MEMBER ), $user -> getId ());
2021-01-28 15:57:55 +00:00
$db -> execute ( 'UPDATE users SET clan = ?, align = ? WHERE id = ?' , [ $clanRow [ 'id' ], $clanRow [ 'align' ], $sok [ 'id' ]]);
$status = " Персонаж « { $login } » успешно принят в клан. " ;
2020-08-29 23:21:22 +00:00
} else {
$status = 'Н е хватает денег, или персонажа не существует.' ;
}
2019-06-20 23:37:39 +00:00
}
2021-01-28 15:57:55 +00:00
if ( $login ) {
$sok = $db -> fetch ( 'SELECT id FROM users WHERE clan = ? AND login = ?' , [ $clanRow [ 'id' ], $login ]);
2021-02-01 16:42:52 +00:00
if ( $action == 'remove_member' && $sok [ 'id' ] != $clanRow [ 'owner_id' ] && $user -> getMoney () >= COST_REMOVE_MEMBER ) {
Bank :: setWalletMoney ( $user -> setMoney ( $user -> getMoney () - COST_REMOVE_MEMBER ), $user -> getId ());
2021-01-28 15:57:55 +00:00
$db -> execute ( 'UPDATE users SET clan = null, align = 0 WHERE id = ?' , $sok [ 'id' ]);
$status = " Персонаж « { $login } » покинул клан. " ;
2019-06-20 23:37:39 +00:00
}
2021-02-01 16:42:52 +00:00
if ( $action == 'change_owner' && $clanRow [ 'owner_id' ] == $user -> getId ()) {
2021-01-28 15:57:55 +00:00
$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 ;
2020-08-29 23:21:22 +00:00
}
2021-01-28 15:57:55 +00:00
} else {
$status = 'Главу клана редактировать запрещено!' ;
2019-06-22 14:05:14 +00:00
}
2020-08-29 23:21:22 +00:00
}
2019-06-22 14:05:14 +00:00
}
2021-01-28 15:57:55 +00:00
$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 ; // И копилки.
2018-01-28 16:40:49 +00:00
?>
2019-06-22 12:49:35 +00:00
< div >
2020-08-29 23:21:22 +00:00
< button onclick = " location.href='main.php' " > Вернуться </ button >
2021-01-28 15:57:55 +00:00
< ? php if ( ! empty ( $status )) {
err ( $status );
} ?>
2020-08-29 23:21:22 +00:00
</ 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 >
2021-01-28 15:57:55 +00:00
< h3 >< img src = " ./i/clan/<?= $clanRow['short_name'] ?>.png " >< ? = $clanRow [ 'full_name' ] ?> </h3>
2019-06-22 10:56:52 +00:00
2021-02-01 16:42:52 +00:00
< ? php if ( $clanRow [ 'owner_id' ] == $user -> getId ()) : ?>
2019-06-22 10:56:52 +00:00
< div >
< span id = " add_member " >
< input type = " submit " onclick = " use('add_member') " value = " Принять в клан " >
</ span >
2020-08-29 23:21:22 +00:00
( стоимость услуги : < B >< ? = COST_ADD_MEMBER ?> </B> кр.)
2019-06-22 10:56:52 +00:00
</ div >
< div >
< span id = " remove_member " >
< input type = " submit " onclick = " use('remove_member') " value = " Выгнать из клана " >
</ span >
2020-08-29 23:21:22 +00:00
( стоимость услуги : < B >< ? = COST_REMOVE_MEMBER ?> </B> кр.)
2019-06-22 10:56:52 +00:00
</ div >
< ? php endif ; ?>
2021-02-01 16:42:52 +00:00
< ? php if ( $clanRow [ 'owner_id' ] == $user -> getId ()) : ?>
2021-01-28 15:57:55 +00:00
< ? php if ( $login && $action == 'edit_status' && $sok [ 'id' ] != $clanRow [ 'owner_id' ]) : ?>
2019-06-22 14:05:14 +00:00
< form method = 'post' >
< input placeholder = 'Статус' name = 'new_status' >
2019-06-22 14:10:37 +00:00
< input type = " hidden " name = " login " value = " <?= $login ?> " >
2021-02-01 16:42:52 +00:00
< ? php if ( $clanRow [ 'glava' ] == $user -> getId ()) : ?>
< ? php if ( $clanRow [ 'owner_id' ] == $user -> getId ()) : ?>
2019-06-22 14:05:14 +00:00
< br >< input type = checkbox name = vin checked > Может принимать / выгонять членов клана
< ? php else : ?>
< br >< input type = checkbox name = vin > Может принимать / выгонять членов клана
< ? php endif ; ?>
2021-02-01 16:42:52 +00:00
< ? php if ( $clanRow [ 'owner_id' ] == $user -> getId ()) : ?>
2019-06-22 14:05:14 +00:00
< 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 ; ?>
2019-06-22 10:56:52 +00:00
< ? php endif ; ?>
2021-02-01 16:42:52 +00:00
< ? php if ( $clanRow [ 'owner_id' ] == $user -> getId ()) : ?>
2019-06-22 10:56:52 +00:00
< div >
< span id = " change_owner " >
< input type = " submit " onclick = " use('change_owner') " value = " Сменить главу клана " >
</ span >
( сложить с себя полномочия , назначив < b style = " color: teal; " > Главой Клана </ b > другого персонажа )
</ div >
2020-08-29 23:21:22 +00:00
< ? php if ( empty ( $clanRow [ 'zamok' ])) : ?>
< ? php if ( $clanRow [ 'rating' ] < CASTLE_REPUTATION_NEEDED ) : ?>
Недостаточно рейтинга для постройки замка . < ? = showProgressBar ( $clanRow [ 'rating' ], CASTLE_REPUTATION_NEEDED ) ?>
2019-06-22 12:00:26 +00:00
< ? php else : ?>
< form method = " post " >
< button type = " submit " name = " zamok " value = " zamok " > Построить Замок </ button >
2020-08-29 23:21:22 +00:00
( собрать силами всего клана < ? = CASTLE_COST ?> кр.)<BR>
2019-06-22 12:00:26 +00:00
</ form >
< ? php endif ; ?>
< ? php endif ; ?>
2019-06-22 10:56:52 +00:00
< ? php endif ; ?>
2018-03-03 15:52:28 +00:00
2020-08-29 23:21:22 +00:00
< ? php if ( $clanRow [ 'zamok' ] == 1 ) : ?>
2019-06-22 12:26:14 +00:00
< p >
2020-08-29 23:21:22 +00:00
< ? php if ( $clanRow [ 'zbor' ] < CASTLE_COST ) : ?>
2019-06-22 12:00:26 +00:00
С б о р средств на постройку кланового замка :
2020-08-29 23:21:22 +00:00
< ? = 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 >
2019-06-22 12:00:26 +00:00
< ? php else : ?>
Средства на постройку кланового замка собраны !
2020-08-29 23:21:22 +00:00
< ? = showProgressBar ( CASTLE_COST , CASTLE_COST ) ?>
2019-06-22 12:00:26 +00:00
< ? php endif ; ?>
< ? php endif ; ?>
2018-03-03 11:50:13 +00:00
</ td >
2019-06-21 15:54:48 +00:00
< 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
2021-01-28 15:57:55 +00:00
$i = 0 ;
while ( $i < count ( $clan_memberlist )) :
if ( $clan_memberlist [ $i ][ 'id' ] == $clanRow [ 'owner_id' ]) {
$clan_memberlist [ $i ][ 'status' ] = '<b style="color: #008080;">Глава клана</b>' ;
2020-08-29 23:21:22 +00:00
}
2021-01-28 15:57:55 +00:00
if ( empty ( $clan_memberlist [ $i ][ 'status' ])) {
$clan_memberlist [ $i ][ 'status' ] = 'Боец' ;
2020-08-29 23:21:22 +00:00
}
2021-01-28 15:57:55 +00:00
if ( empty ( $clan_memberlist [ $i ][ 'online' ])) {
2020-08-29 23:21:22 +00:00
$rrm = 'Персонаж не в игре' ;
2021-01-28 15:57:55 +00:00
} elseif ( $clan_memberlist [ $i ][ 'room' ] > 500 && $clan_memberlist [ $i ][ 'room' ] < 561 ) {
2020-08-29 23:21:22 +00:00
$rrm = 'Башня смерти' ;
} else {
2021-01-28 15:57:55 +00:00
$rrm = Rooms :: $roomNames [ $clan_memberlist [ $i ][ 'room' ]];
2020-08-29 23:21:22 +00:00
}
2019-06-22 12:51:07 +00:00
?>
< tr >
2021-01-28 15:57:55 +00:00
< td >< ? = Nick :: id ( $clan_memberlist [ $i ][ 'id' ]) -> full () ?> </td>
< td >< ? = $clan_memberlist [ $i ][ 'status' ] ?> </td>
2019-06-22 12:49:35 +00:00
< td >< i style = " font-size: smaller; " >< ? = $rrm ?> </i></td>
2019-06-22 12:51:07 +00:00
</ tr >
2021-01-28 15:57:55 +00:00
< ? php $i ++ ; ?>
2019-06-22 12:51:07 +00:00
< ? 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
}
2020-09-30 14:19:55 +00:00
</ script >