Merge
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Clan;
|
||||
|
||||
use Core\Db;
|
||||
|
||||
class ClanInfo
|
||||
{
|
||||
public static function isJoinable(string $name): bool
|
||||
{
|
||||
return Db::getValue('select count(name) from clan where name = ? and status = 1', [$name]) > 0;
|
||||
}
|
||||
}
|
||||
@@ -11,33 +11,13 @@ class ItemStorage
|
||||
{
|
||||
private string $error = '';
|
||||
|
||||
private function isGoodForStorage(array $item, $userClanId): bool
|
||||
{
|
||||
if (empty($item['inslot']) || !empty($item['gift'])) {
|
||||
$this->error = 'Ïðåäìåò íå íàéäåí.';
|
||||
}
|
||||
$idata = ConversionHelper::dataStringToArray($item['data']);
|
||||
if (
|
||||
!empty($idata['frompisher']) ||
|
||||
!empty($idata['sudba']) ||
|
||||
!empty($idata['icos']) ||
|
||||
!empty($idata['fromlaba'])
|
||||
) {
|
||||
$this->error = 'Ïðåäìåò íå ïîäõîäèò.';
|
||||
}
|
||||
if (!empty($idata['toclan']) && explode('#', $idata['toclan'])[0] == $userClanId) {
|
||||
$this->error = 'Ïðåäìåò óæå ïðèíàäëåæèò êëàíó.';
|
||||
}
|
||||
return empty($this->error);
|
||||
}
|
||||
|
||||
public function put(int $itemId, int $clanId): string
|
||||
{
|
||||
$user = User::start()->info;
|
||||
$item = ItemsModel::getOwnedItemById($itemId, $user['id']);
|
||||
$clanName = Db::getValue('select name from clan where id = ?', [$clanId]) ?? '';
|
||||
if (empty($clanName)) {
|
||||
return 'Êëàí íå íàéäåí.';
|
||||
return 'Клан не найден.';
|
||||
}
|
||||
if (!$this->isGoodForStorage($item, $user['clan'])) {
|
||||
return $this->error;
|
||||
@@ -50,7 +30,7 @@ class ItemStorage
|
||||
User::start()->addDelo(
|
||||
2,
|
||||
$user['id'],
|
||||
'"System.transfer.MONEY": Ïðåäìåò "' . $item['name'] . '" (#id : "' . $itemId . '") (x' . $col . ') áûë ïîæåðòâîâàí êëàíó "' . $clanName . '" (' . $clanId . ').',
|
||||
'"System.transfer.MONEY": Предмет "' . $item['name'] . '" (#id : "' . $itemId . '") (x' . $col . ') был пожертвован клану "' . $clanName . '" (' . $clanId . ').',
|
||||
time(),
|
||||
$user['city'],
|
||||
'System.transfer.clan',
|
||||
@@ -63,16 +43,35 @@ class ItemStorage
|
||||
}
|
||||
Db::sql(
|
||||
'insert into clan_operations (clan, time, type, text, val, uid) values (?,unix_timestamp(),?,?,?,?)',
|
||||
[$clanId, $sendType, $user['login'], $item['name'] . ("x$col Èä: [$itemId]"), $user['id']]
|
||||
[$clanId, $sendType, $user['login'], $item['name'] . ("x$col Ид: [$itemId]"), $user['id']]
|
||||
);
|
||||
Db::sql(
|
||||
'update items_users set lastUPD = unix_timestamp(), uid = ?, data = ? where id = ?',
|
||||
['-21' . $user['clan'], $item['data'], $itemId]
|
||||
);
|
||||
|
||||
return 'Âû ïåðåäàëè ïðåäìåò "' . $item['name'] . '" êëàíó.';
|
||||
return 'Вы передали предмет "' . $item['name'] . '" клану.';
|
||||
}
|
||||
|
||||
private function isGoodForStorage(array $item, $userClanId): bool
|
||||
{
|
||||
if (empty($item['inslot']) || !empty($item['gift'])) {
|
||||
$this->error = 'Предмет не найден.';
|
||||
}
|
||||
$idata = ConversionHelper::dataStringToArray($item['data']);
|
||||
if (
|
||||
!empty($idata['frompisher']) ||
|
||||
!empty($idata['sudba']) ||
|
||||
!empty($idata['icos']) ||
|
||||
!empty($idata['fromlaba'])
|
||||
) {
|
||||
$this->error = 'Предмет не подходит.';
|
||||
}
|
||||
if (!empty($idata['toclan']) && explode('#', $idata['toclan'])[0] == $userClanId) {
|
||||
$this->error = 'Предмет уже принадлежит клану.';
|
||||
}
|
||||
return empty($this->error);
|
||||
}
|
||||
|
||||
public function ungive_itm_cl($id, $user, $cl): string
|
||||
{
|
||||
@@ -86,27 +85,25 @@ class ItemStorage
|
||||
mysql_query('SELECT `id`,`bot`,`clone` FROM `stats` WHERE `id` = "' . $itm_['uid'] . '" LIMIT 1')
|
||||
);
|
||||
if ($user_itm['bot'] > 0 || $user_itm['clone'] > 0 || !isset($user_itm['id'])) {
|
||||
$r = '<font color="#FF0000"><strong>Âû íå ìîæåòå èçüÿòü äàííûé ïðåäìåò, îí íå ïðèíàäëåæèò êëàíó</strong></font><br />';
|
||||
$r = '<font color="#FF0000"><strong>Вы не можете изьять данный предмет, он не принадлежит клану</strong></font><br />';
|
||||
} elseif (isset($itm_['id'])) {
|
||||
|
||||
if ($itm_['inOdet'] != 0) {
|
||||
$o = ', `inOdet` = 0';
|
||||
} else {
|
||||
$o = '';
|
||||
}
|
||||
$r = '<font color="#FF0000"><strong>Âû óñïåøíî èçúÿëè ïðåäìåò "' . $itm_['name'] . '"</strong></font><br />';
|
||||
$col = $this->itemsX(((int)$id));
|
||||
mysql_query(
|
||||
'INSERT INTO `clan_operations` (`clan`, `time`, `type`, `text`, `val`, `uid`) VALUES ("' . $res['id'] . '", "' . time(
|
||||
) . '", "6", "' . $user['login'] . '", "' . $itm_['name'] . ' (x' . $col . ') Èä : [' . $id . '] | Ó ïåðñîíàæà : [' . $itm_['uid'] . ']", "' . $user['id'] . '")'
|
||||
);
|
||||
mysql_query(
|
||||
'UPDATE `items_users` SET `lastUPD` = "' . time(
|
||||
) . '", `uid` = "-21' . $res['id'] . '" ' . $o . ' WHERE `id` = "' . $id . '" LIMIT 1'
|
||||
);
|
||||
if ($itm_['inOdet'] != 0) {
|
||||
$o = ', `inOdet` = 0';
|
||||
} else {
|
||||
$o = '';
|
||||
}
|
||||
$r = '<font color="#FF0000"><strong>Вы успешно изъяли предмет "' . $itm_['name'] . '"</strong></font><br />';
|
||||
$col = $this->itemsX(((int)$id));
|
||||
mysql_query(
|
||||
'INSERT INTO `clan_operations` (`clan`, `time`, `type`, `text`, `val`, `uid`) VALUES ("' . $res['id'] . '", "' . time() . '", "6", "' . $user['login'] . '", "' . $itm_['name'] . ' (x' . $col . ') Ид : [' . $id . '] | У персонажа : [' . $itm_['uid'] . ']", "' . $user['id'] . '")'
|
||||
);
|
||||
mysql_query(
|
||||
'UPDATE `items_users` SET `lastUPD` = "' . time() . '", `uid` = "-21' . $res['id'] . '" ' . $o . ' WHERE `id` = "' . $id . '" LIMIT 1'
|
||||
);
|
||||
|
||||
} else {
|
||||
$r = '<font color="#FF0000"><strong>Ïðåäìåò íå íàéäåí.</strong></font><br />';
|
||||
$r = '<font color="#FF0000"><strong>Предмет не найден.</strong></font><br />';
|
||||
}
|
||||
return $r;
|
||||
}
|
||||
@@ -126,19 +123,17 @@ class ItemStorage
|
||||
$cls = $cls[1];
|
||||
}
|
||||
|
||||
$col = $this->itemsX(((int)$id));
|
||||
mysql_query(
|
||||
'INSERT INTO `clan_operations` (`clan`, `time`, `type`, `text`, `val`, `uid`) VALUES ("' . $res['id'] . '", "' . time(
|
||||
) . '", "5", "' . $user['login'] . '", "' . $itm_['name'] . ' (x' . $col . ') Èä : [' . $id . '] Õîçÿèí : [' . $cls . ']", "' . $user['id'] . '")'
|
||||
);
|
||||
mysql_query(
|
||||
'UPDATE `items_users` SET `lastUPD` = "' . time(
|
||||
) . '", `uid` = "' . $user['id'] . '" WHERE `id` = "' . $id . '" LIMIT 1'
|
||||
);
|
||||
$r = '<font color="#FF0000"><strong>Âû óñïåøíî âçÿëè ïðåäìåò "' . $itm_['name'] . '" èç õðàíèëèùà</strong></font><br />';
|
||||
$col = $this->itemsX(((int)$id));
|
||||
mysql_query(
|
||||
'INSERT INTO `clan_operations` (`clan`, `time`, `type`, `text`, `val`, `uid`) VALUES ("' . $res['id'] . '", "' . time() . '", "5", "' . $user['login'] . '", "' . $itm_['name'] . ' (x' . $col . ') Ид : [' . $id . '] Хозяин : [' . $cls . ']", "' . $user['id'] . '")'
|
||||
);
|
||||
mysql_query(
|
||||
'UPDATE `items_users` SET `lastUPD` = "' . time() . '", `uid` = "' . $user['id'] . '" WHERE `id` = "' . $id . '" LIMIT 1'
|
||||
);
|
||||
$r = '<font color="#FF0000"><strong>Вы успешно взяли предмет "' . $itm_['name'] . '" из хранилища</strong></font><br />';
|
||||
|
||||
} else {
|
||||
$r = '<font color="#FF0000"><strong>Ïðåäìåò íå íàéäåí.</strong></font><br />' . $id;
|
||||
$r = '<font color="#FF0000"><strong>Предмет не найден.</strong></font><br />' . $id;
|
||||
}
|
||||
return $r;
|
||||
}
|
||||
@@ -167,12 +162,10 @@ class ItemStorage
|
||||
mysql_query('SELECT `name` FROM `items_main` WHERE `id` = "' . $pl['item_id'] . '"')
|
||||
);
|
||||
mysql_query(
|
||||
'UPDATE `items_users` SET `lastUPD` = "' . time(
|
||||
) . '", `uid` = "' . $user['id'] . '", `data` = "' . $pl['data'] . '" WHERE `id` = "' . $pl['id'] . '"'
|
||||
'UPDATE `items_users` SET `lastUPD` = "' . time() . '", `uid` = "' . $user['id'] . '", `data` = "' . $pl['data'] . '" WHERE `id` = "' . $pl['id'] . '"'
|
||||
);
|
||||
mysql_query(
|
||||
'INSERT INTO `clan_operations` (`clan`, `time`, `type`, `text`, `val`, `uid`) VALUES ("' . $res['id'] . '", "' . time(
|
||||
) . '", "' . $type . '", "' . $user['login'] . '", "' . $it_n['name'] . ' (x' . $col . ') Èä : [' . $pl['id'] . ']", "' . $user['id'] . '")'
|
||||
'INSERT INTO `clan_operations` (`clan`, `time`, `type`, `text`, `val`, `uid`) VALUES ("' . $res['id'] . '", "' . time() . '", "' . $type . '", "' . $user['login'] . '", "' . $it_n['name'] . ' (x' . $col . ') Ид : [' . $pl['id'] . ']", "' . $user['id'] . '")'
|
||||
);
|
||||
} elseif ($pl['uid'] == $user['id']) {
|
||||
$col = $this->itemsX(((int)$pl['id']));
|
||||
@@ -180,14 +173,12 @@ class ItemStorage
|
||||
mysql_query('SELECT `name` FROM `items_main` WHERE `id` = "' . $pl['item_id'] . '"')
|
||||
);
|
||||
mysql_query(
|
||||
'UPDATE `items_users` SET `lastUPD` = "' . time(
|
||||
) . '", `uid` = "-21' . $user['clan'] . '" WHERE `id` = "' . $pl['id'] . '"'
|
||||
'UPDATE `items_users` SET `lastUPD` = "' . time() . '", `uid` = "-21' . $user['clan'] . '" WHERE `id` = "' . $pl['id'] . '"'
|
||||
);
|
||||
mysql_query(
|
||||
'INSERT INTO `clan_operations` (`clan`, `time`, `type`, `text`, `val`, `uid`) VALUES ("' . $res['id'] . '", "' . time(
|
||||
) . '", "9", "' . $user['login'] . '", "' . $it_n['name'] . ' (x' . $col . ') Èä : [' . $pl['id'] . ']", "' . $user['id'] . '")'
|
||||
'INSERT INTO `clan_operations` (`clan`, `time`, `type`, `text`, `val`, `uid`) VALUES ("' . $res['id'] . '", "' . time() . '", "9", "' . $user['login'] . '", "' . $it_n['name'] . ' (x' . $col . ') Ид : [' . $pl['id'] . ']", "' . $user['id'] . '")'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,136 @@
|
||||
<?php
|
||||
|
||||
namespace Clan;
|
||||
|
||||
use Core\Config;
|
||||
use Core\Db;
|
||||
use Uploader;
|
||||
|
||||
class Register
|
||||
{
|
||||
const REGISTER_COST_EKR = 50;
|
||||
private string $name;
|
||||
private int $align = 0;
|
||||
private Uploader $logo;
|
||||
private int $newClanId = 0;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
if (!isset($_POST['newclanname'], $_POST['newclanalign'], $_FILES['newclanlogo'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->setName($_POST['newclanname']);
|
||||
$this->setLogo();
|
||||
$this->setAlign(intval($_POST['newclanalign']));
|
||||
$this->new();
|
||||
}
|
||||
|
||||
private function setName(string $name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
private function setLogo()
|
||||
{
|
||||
$this->logo = new Uploader('newclanlogo');
|
||||
$this->logo->setMaxFileSize(.03);
|
||||
$this->logo->setDimensions(24, 15);
|
||||
$this->logo->setExtentions(['gif', 'png']);
|
||||
}
|
||||
|
||||
private function setAlign(int $align)
|
||||
{
|
||||
if (!in_array($align, [0, 1, 3, 7])) {
|
||||
$align = 0;
|
||||
}
|
||||
$this->align = $align;
|
||||
}
|
||||
|
||||
public function new()
|
||||
{
|
||||
if (!$this->hasGoodName()) {
|
||||
return;
|
||||
}
|
||||
$imageId = $this->logo->saveToDb();
|
||||
if (!$imageId) {
|
||||
echo $this->logo::$error;
|
||||
return;
|
||||
}
|
||||
Db::sql('insert into clan (name, align, logo) values (?,?,?)', [$this->name, $this->align, $imageId]);
|
||||
$this->newClanId = Db::lastInsertId();
|
||||
}
|
||||
|
||||
private function hasGoodName(): bool
|
||||
{
|
||||
return Db::getValue('select count(id) from clan where name = ?', [$this->name]) === 0;
|
||||
}
|
||||
|
||||
public static function approve(int $clanId)
|
||||
{
|
||||
Db::sql('update clan set status = 1, time_reg = unix_timestamp() where id = ?', [$clanId]);
|
||||
}
|
||||
|
||||
public static function reject(int $clanId)
|
||||
{
|
||||
Db::sql('delete from clan where id = ?', [$clanId]);
|
||||
}
|
||||
|
||||
public static function printForm(): string
|
||||
{
|
||||
$img = Config::img() . '/i/align';
|
||||
return <<<REGISTERFORM
|
||||
<style>
|
||||
div.regclangrid [type=radio] {
|
||||
position: absolute;
|
||||
opacity: 0;
|
||||
width: 0;
|
||||
height: 0;
|
||||
}
|
||||
|
||||
/* IMAGE STYLES */
|
||||
div.regclangrid [type=radio] + img {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
/* CHECKED STYLES */
|
||||
div.regclangrid [type=radio]:checked + img {
|
||||
outline: 1px solid brown;
|
||||
padding: 2px;
|
||||
}
|
||||
|
||||
div.regclangrid {
|
||||
display: grid;
|
||||
grid-template-columns: 100px auto;
|
||||
}
|
||||
</style>
|
||||
<form method="POST" enctype="multipart/form-data">
|
||||
<div class="regclangrid">
|
||||
<div><label for="clanname">Название:</label></div>
|
||||
<div><input name="newclanname" id="clanname"></div>
|
||||
<div><label for="clanlogo">Логотип:</label></div>
|
||||
<div><input type="file" name="newclanlogo" accept="image/*" id="newclanlogo"> размер: 24×15, формат: png или gif, до 30Кб</div>
|
||||
<div>Склонность:</div>
|
||||
<div>
|
||||
<label><input type="radio" name="newclanalign" value="0" checked><img src="$img/align0.gif" alt="none"></label>
|
||||
<label><input type="radio" name="newclanalign" value="1"><img src="$img/align1.gif" alt="light"></label>
|
||||
<label><input type="radio" name="newclanalign" value="3"><img src="$img/align3.gif" alt="dark"></label>
|
||||
<label><input type="radio" name="newclanalign" value="7"><img src="$img/align7.gif" alt="neutral"></label>
|
||||
</div>
|
||||
<div></div>
|
||||
<div><button type="submit">Подать заявку</button></div>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
REGISTERFORM;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getNewClanId(): int
|
||||
{
|
||||
return $this->newClanId;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user