2019-01-15 15:56:15 +00:00
|
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* Created by PhpStorm.
|
|
|
|
|
* User: Lopar
|
|
|
|
|
* Date: 15.01.2019
|
|
|
|
|
* Time: 14:51
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*
|
2020-09-29 22:39:06 +00:00
|
|
|
|
* Файл в котором будуn аккумулироваться покупка и отправка подарков и сувениров, которые не будут являться предметами,
|
2019-01-15 15:56:15 +00:00
|
|
|
|
* а просто записями в базе и просто будут отображаться в инвентаре, как неосязаемая сущность со сроком годности или
|
|
|
|
|
* без и правом игрока скрыть или удалить любой подаренный подарок.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2021-02-01 16:42:52 +00:00
|
|
|
|
use Battles\Template;
|
|
|
|
|
use Battles\User;
|
|
|
|
|
|
2021-08-25 15:24:12 +00:00
|
|
|
|
|
2020-10-29 23:30:05 +00:00
|
|
|
|
if ($_SESSION['uid'] != 2) {
|
|
|
|
|
header("Location: index.php");
|
|
|
|
|
exit;
|
|
|
|
|
}
|
2019-01-28 15:22:01 +00:00
|
|
|
|
require_once 'config.php';
|
2019-01-28 14:53:11 +00:00
|
|
|
|
|
2020-09-30 19:12:34 +00:00
|
|
|
|
$status = '';
|
2019-01-28 13:42:46 +00:00
|
|
|
|
$dirname = "i/presents/";
|
|
|
|
|
$images = glob($dirname . "*.png");
|
|
|
|
|
|
2019-01-28 16:11:26 +00:00
|
|
|
|
if (!empty($_POST['sendAction'])) {
|
|
|
|
|
if (empty($_POST['present'])) {
|
|
|
|
|
$status = "Подарок не выбран!";
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-01-28 14:53:11 +00:00
|
|
|
|
if (empty($_POST['receiver'])) {
|
2019-01-28 15:56:35 +00:00
|
|
|
|
$status = "Поле «Получатель» не заполнено!";
|
2019-01-28 14:53:11 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2019-01-28 16:11:26 +00:00
|
|
|
|
$receiver = db::c()->query('SELECT `id` FROM `users` WHERE `login` = "?s"', $_POST['receiver'])->fetch_assoc();
|
2019-01-28 15:22:01 +00:00
|
|
|
|
if (empty($receiver)) {
|
|
|
|
|
$status = "Получатель {$receiver} не найден в базе!";
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-09-29 22:39:06 +00:00
|
|
|
|
$_POST['text'] = $_POST['text'] ?? null;
|
|
|
|
|
if (empty($_POST['days']) || $_POST['days'] < 1 || !is_numeric($_POST['days'])) {
|
|
|
|
|
$_POST['days'] = 1;
|
|
|
|
|
}
|
2019-01-28 15:56:35 +00:00
|
|
|
|
$cost = $_POST['days'] * 5;
|
2022-08-09 19:57:43 +00:00
|
|
|
|
if (!User::getInstance()->money()->spend($cost)) {
|
2019-01-28 15:56:35 +00:00
|
|
|
|
$status = "Не хватает кредитов на оплату подарка!";
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-01-28 13:42:46 +00:00
|
|
|
|
|
2020-09-29 22:39:06 +00:00
|
|
|
|
if ($_POST['sender'] == 1) {
|
|
|
|
|
$sender = "Анонимный подарок";
|
2022-01-26 23:15:33 +00:00
|
|
|
|
} elseif ($_POST['sender'] == 2 && User::getInstance()->getClan()) {
|
|
|
|
|
$sender = "Подарок от клана " . User::getInstance()->getClan();
|
2020-09-30 19:12:34 +00:00
|
|
|
|
} else {
|
2022-01-26 23:15:33 +00:00
|
|
|
|
$sender = "Подарок от " . User::getInstance()->getLogin();
|
2020-09-29 22:39:06 +00:00
|
|
|
|
}
|
2019-01-28 13:42:46 +00:00
|
|
|
|
|
2022-08-09 19:57:43 +00:00
|
|
|
|
\Battles\Database\Db::getInstance()->execute('insert into users_presents (owner_id, sender_id, image) values (?,?,?)', [$receiver['id'], $sender, $_POST['present']]);
|
|
|
|
|
//db::c()->query('INSERT INTO users_presents (owner, img, text, sender, expiration_date) VALUES (?i,"?s","?s","?s",DATE_ADD(CURDATE(),INTERVAL ?i DAY))', $receiver['id'], $_POST['present'], $_POST['text'], $sender, $_POST['days']);
|
2019-01-28 16:29:22 +00:00
|
|
|
|
|
2019-01-28 16:53:14 +00:00
|
|
|
|
$telegraphText = "Вам пришёл подарок от {$sender}!";
|
2019-01-28 16:29:22 +00:00
|
|
|
|
db::c()->query('INSERT INTO `telegraph` (receiver, text) VALUES (?i,"?s")', $receiver['id'], $telegraphText);
|
2019-01-28 16:04:42 +00:00
|
|
|
|
$status = "Подарок удачно доставлен к {$_POST['receiver']}! Вы потратили <b>{$cost}</b> кр.";
|
2019-01-28 16:06:50 +00:00
|
|
|
|
}
|
2021-02-01 16:42:52 +00:00
|
|
|
|
Template::header('Дарильня');
|
2019-01-15 15:56:15 +00:00
|
|
|
|
?>
|
2020-09-30 19:12:34 +00:00
|
|
|
|
<script src="js/main.js"></script>
|
|
|
|
|
<style>
|
|
|
|
|
label.present > input { /* HIDE RADIO */
|
|
|
|
|
visibility: hidden; /* Makes input not-clickable */
|
|
|
|
|
position: absolute; /* Remove input from document flow */
|
|
|
|
|
}
|
2019-01-28 12:35:41 +00:00
|
|
|
|
|
2020-09-30 19:12:34 +00:00
|
|
|
|
label.present > input + img { /* IMAGE STYLES */
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
border: 1px solid transparent;
|
|
|
|
|
}
|
2019-01-28 12:35:41 +00:00
|
|
|
|
|
2020-09-30 19:12:34 +00:00
|
|
|
|
label.present > input:checked + img { /* (RADIO CHECKED) IMAGE STYLES */
|
|
|
|
|
border: 1px solid darkred;
|
|
|
|
|
background: lightcoral;
|
|
|
|
|
}
|
|
|
|
|
</style>
|
|
|
|
|
<h1>Дарильня</h1>
|
|
|
|
|
<div class="private"><?= $status ?></div>
|
2019-01-28 14:53:11 +00:00
|
|
|
|
Вы можете сделать подарок любому персонажу. Ваш подарок будет
|
|
|
|
|
отображаться в информации о персонаже.<br><br>
|
2019-01-28 12:29:34 +00:00
|
|
|
|
<div>
|
2019-01-28 13:42:46 +00:00
|
|
|
|
Выберите подарок:<br>
|
|
|
|
|
<form method="post">
|
2019-01-28 16:03:02 +00:00
|
|
|
|
<?php foreach ($images as $image): ?>
|
|
|
|
|
<label class="present">
|
|
|
|
|
<input type="radio" name="present" value="<?= $image ?>">
|
|
|
|
|
<img src="<?= $image ?>" alt="">
|
|
|
|
|
</label>
|
|
|
|
|
<?php endforeach; ?>
|
2019-01-28 16:06:50 +00:00
|
|
|
|
<br><input name="receiver" placeholder="Имя получателя"><br>
|
2019-01-28 14:53:11 +00:00
|
|
|
|
<textarea name="text"
|
|
|
|
|
rows=6 cols=80
|
|
|
|
|
placeholder="Текст сопроводительной записки (в информации о персонаже не отображается). Заполнять не обязательно."></textarea><br>
|
2019-01-28 13:42:46 +00:00
|
|
|
|
<br>Выберите, от чьего имени подарок:<br>
|
2022-01-26 23:15:33 +00:00
|
|
|
|
<label><input type=radio name=sender value=0 checked> <?= User::getInstance()->getLogin() ?></label><br>
|
2019-01-28 15:56:35 +00:00
|
|
|
|
<label><input type=radio name=sender value=1> анонимно</label><br>
|
2022-01-26 23:15:33 +00:00
|
|
|
|
<?php if (!empty(User::getInstance()->getClan())): ?>
|
|
|
|
|
<label><input type=radio name=sender value=2> от имени клана <b><?= User::getInstance()->getClan() ?></b></label><br>
|
2019-01-28 15:22:01 +00:00
|
|
|
|
<?php endif; ?>
|
2019-01-28 13:42:46 +00:00
|
|
|
|
<br>Долговечность подарка (5кр в день):<br>
|
|
|
|
|
<input name="days" placeholder="Количество дней"><br>
|
2019-01-28 16:11:26 +00:00
|
|
|
|
<input type="hidden" name="sendAction" value="1">
|
2019-01-28 14:53:11 +00:00
|
|
|
|
<br>
|
2019-01-28 15:59:01 +00:00
|
|
|
|
<input type="submit" value="Подарить">
|
2019-01-28 13:42:46 +00:00
|
|
|
|
</form>
|
2020-09-30 19:12:34 +00:00
|
|
|
|
</div>
|