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
|
|
|
|
* а просто записями в базе и просто будут отображаться в инвентаре, как неосязаемая сущность со сроком годности или
|
|
|
|
|
* без и правом игрока скрыть или удалить любой подаренный подарок.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
session_start();
|
2020-09-29 22:39:06 +00:00
|
|
|
|
if ($_SESSION['uid'] != 2) header("Location: index.php");
|
2019-01-28 15:22:01 +00:00
|
|
|
|
require_once 'config.php';
|
2019-01-28 14:53:11 +00:00
|
|
|
|
|
2020-09-29 22:39:06 +00:00
|
|
|
|
$user = new User($_SESSION['uid']);
|
2019-01-15 15:56:15 +00:00
|
|
|
|
|
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;
|
2020-09-29 22:39:06 +00:00
|
|
|
|
if ($user->money < $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 = "Анонимный подарок";
|
|
|
|
|
}
|
|
|
|
|
elseif ($_POST['sender'] == 2 && $user->clan) {
|
|
|
|
|
$sender = "Подарок от клана {$user->clan}";
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$sender = "Подарок от {$user->login}";
|
|
|
|
|
}
|
2019-01-28 13:42:46 +00:00
|
|
|
|
|
2020-09-29 22:39:06 +00:00
|
|
|
|
$user->money -= $cost;
|
|
|
|
|
Bank::setWalletMoney($user->money, $user->id);
|
2019-01-28 16:53:14 +00:00
|
|
|
|
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
|
|
|
|
}
|
2019-01-15 15:56:15 +00:00
|
|
|
|
?>
|
|
|
|
|
<!DOCTYPE html>
|
2020-06-23 10:26:39 +00:00
|
|
|
|
<html lang="ru">
|
2019-01-15 15:56:15 +00:00
|
|
|
|
<head>
|
|
|
|
|
<meta charset="utf-8">
|
|
|
|
|
<link href="css/main.css" rel="stylesheet"/>
|
|
|
|
|
<script src="js/main.js"></script>
|
2019-01-28 12:29:34 +00:00
|
|
|
|
<style>
|
2019-01-28 12:35:41 +00:00
|
|
|
|
label.present > input { /* HIDE RADIO */
|
2019-01-28 12:29:34 +00:00
|
|
|
|
visibility: hidden; /* Makes input not-clickable */
|
|
|
|
|
position: absolute; /* Remove input from document flow */
|
|
|
|
|
}
|
2019-01-28 12:35:41 +00:00
|
|
|
|
|
|
|
|
|
label.present > input + img { /* IMAGE STYLES */
|
|
|
|
|
cursor: pointer;
|
2019-01-28 12:47:42 +00:00
|
|
|
|
border: 1px solid transparent;
|
2019-01-28 12:29:34 +00:00
|
|
|
|
}
|
2019-01-28 12:35:41 +00:00
|
|
|
|
|
|
|
|
|
label.present > input:checked + img { /* (RADIO CHECKED) IMAGE STYLES */
|
2019-01-28 12:47:42 +00:00
|
|
|
|
border: 1px solid darkred;
|
|
|
|
|
background: lightcoral;
|
2019-01-28 12:29:34 +00:00
|
|
|
|
}
|
|
|
|
|
</style>
|
2020-06-23 10:26:39 +00:00
|
|
|
|
<title></title>
|
2019-01-15 15:56:15 +00:00
|
|
|
|
</head>
|
|
|
|
|
<body>
|
|
|
|
|
<h1>Магазин подарков</h1>
|
2020-06-23 09:24:37 +00:00
|
|
|
|
<div class="private"><?php if (!empty($status)) echo $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>
|
2020-09-29 22:39:06 +00:00
|
|
|
|
<label><input type=radio name=sender value=0 checked> <?= $user->login ?></label><br>
|
2019-01-28 15:56:35 +00:00
|
|
|
|
<label><input type=radio name=sender value=1> анонимно</label><br>
|
2019-01-28 15:22:01 +00:00
|
|
|
|
<?php if (!empty($user['ClanName'])): ?>
|
2020-09-29 22:39:06 +00:00
|
|
|
|
<label><input type=radio name=sender value=2> от имени клана <b><?= $user->clan ?></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>
|
|
|
|
|
</div>
|
2019-01-15 15:56:15 +00:00
|
|
|
|
</body>
|
|
|
|
|
</html>
|