2019-01-15 15:56:15 +00:00
|
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* Created by PhpStorm.
|
|
|
|
|
* User: Lopar
|
|
|
|
|
* Date: 15.01.2019
|
|
|
|
|
* Time: 14:51
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Файл в котором буду аккумулироваться покупка и отправка подарков и сувениров, которые не будут являться предметами,
|
|
|
|
|
* а просто записями в базе и просто будут отображаться в инвентаре, как неосязаемая сущность со сроком годности или
|
|
|
|
|
* без и правом игрока скрыть или удалить любой подаренный подарок.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
session_start();
|
|
|
|
|
if ($_SESSION['uid'] != 11263) header("Location: index.php");
|
2019-01-28 15:22:01 +00:00
|
|
|
|
require_once 'config.php';
|
2019-01-28 14:53:11 +00:00
|
|
|
|
|
|
|
|
|
$user = db::c()->query('SELECT `login`, `name` AS `ClanName`, u.`money`
|
|
|
|
|
FROM `users` u
|
|
|
|
|
LEFT JOIN `clans` c ON c.`id` = `klan`
|
|
|
|
|
WHERE u.`id` = ?i', $_SESSION['uid'])->fetch_assoc();
|
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;
|
|
|
|
|
}
|
2019-01-28 15:56:35 +00:00
|
|
|
|
if (empty($_POST['text'])) $_POST['text'] = null;
|
|
|
|
|
if (empty($_POST['days']) OR $_POST['days'] < 1 OR !is_numeric($_POST['days'])) $_POST['days'] = 1;
|
|
|
|
|
$cost = $_POST['days'] * 5;
|
|
|
|
|
if ($user['money'] < $cost) {
|
|
|
|
|
$status = "Не хватает кредитов на оплату подарка!";
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-01-28 13:42:46 +00:00
|
|
|
|
|
2019-01-28 15:56:35 +00:00
|
|
|
|
if ($_POST['sender'] == 1) $from = null;
|
|
|
|
|
elseif ($_POST['sender'] == 2 && $user['ClanName']) $from = ' клана ' . $user['ClanName'];
|
2019-01-28 14:53:11 +00:00
|
|
|
|
else $from = $user['login'];
|
2019-01-28 13:42:46 +00:00
|
|
|
|
|
2019-01-28 15:56:35 +00:00
|
|
|
|
db::c()->query('UPDATE `users` SET `money` = `money` - ?i WHERE `id` = ?i', $cost, $_SESSION['uid']);
|
2019-01-28 16:15:24 +00:00
|
|
|
|
db::c()->query('INSERT INTO users_presents (owner, img, text, sender, expiration_date) VALUES (?i,"?s","?s","?s",DATE_ADD(NOW(),INTERVAL ?i DAY))', $receiver['id'], $_POST['present'], $_POST['text'], $_POST['sender'], $_POST['days']);
|
|
|
|
|
#FIXME Я так не хочу подключать functions!
|
|
|
|
|
// $deloText = "{$user['login']} купил подарок за {$cost} кр. и подарил его персонажу {$_POST['receiver']}";
|
|
|
|
|
// addToDelo($deloText);
|
2019-01-28 15:22:01 +00:00
|
|
|
|
$telegraphText = "Вам пришёл подарок от {$from}!";
|
|
|
|
|
db::c()->query('INSERT INTO `telegraph` (receiver, text) VALUES (?i,"?s")', $receiver['id'], $telegraphText)->fetch_assoc();
|
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>
|
|
|
|
|
<html>
|
|
|
|
|
<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>
|
2019-01-15 15:56:15 +00:00
|
|
|
|
</head>
|
|
|
|
|
<body>
|
|
|
|
|
<h1>Магазин подарков</h1>
|
2019-01-28 16:11:26 +00:00
|
|
|
|
<div><?php if (!empty($status)) err($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>
|
2019-01-28 15:56:35 +00:00
|
|
|
|
<label><input type=radio name=sender value=0 checked> <?= $user['login'] ?></label><br>
|
|
|
|
|
<label><input type=radio name=sender value=1> анонимно</label><br>
|
2019-01-28 15:22:01 +00:00
|
|
|
|
<?php if (!empty($user['ClanName'])): ?>
|
2019-01-28 15:56:35 +00:00
|
|
|
|
<label><input type=radio name=sender value=2> от имени клана <b><?= $user['ClanName'] ?></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>
|