Фикс анкеты персонажа.

This commit is contained in:
lopar 2018-03-01 21:14:51 +02:00
parent 7d7a83a8a0
commit 61b0ca565b
3 changed files with 45 additions and 22 deletions

28
classes/u.php Normal file
View File

@ -0,0 +1,28 @@
<?php
/**
* Copyright (c) 2018.
* Author: Igor Barkov <lopar.4ever@gmail.com>
* Project name: Battles-Game
*/
class u
{
private $id;
/**
* u constructor.
* @param $playerId
*/
public function __construct($playerId)
{
$this->id = $playerId;
}
/**
* @return mixed
*/
public function i()
{
return db::c()->query('SELECT * FROM `users` WHERE `id` = ?i',$this->id)->fetch_assoc();
}
}

View File

@ -6,6 +6,8 @@
*/
require_once 'config.php';
require_once 'classes/u.php';
define("HPADDICTIONEFFECT", 33);
$ip = filter_input(INPUT_SERVER,'REMOTE_ADDR', FILTER_VALIDATE_IP);

View File

@ -7,11 +7,14 @@ if (!isset($_SESSION['uid'])) {
include('config.php');
include('functions.php');
if ($user['battle'] > 0) {
$u = new u($_SESSION['uid']);
if ($u->i()['battle'] > 0) {
header('Location: /fbattle.php');
die();
}
if ($_POST['submit']) {
$name = filter_input(INPUT_POST, $_POST['name']);
$color = filter_input(INPUT_POST, $_POST['color']);
@ -21,26 +24,18 @@ if ($_POST['submit']) {
$hobbie = str_replace("\\r", "", $_POST['hobbie']);
$hobbie = str_replace("&lt;br&nbsp;/&gt;", "<br />", $_POST['hobbie']);
$simbolcount = strlen($hobbie);
switch ($color) {
case 1: $newcolor = 'blue'; break;
case 2: $newcolor = 'green'; break;
default: $newcolor = 'black'; break;
case 1: $color = 'blue'; break;
case 2: $color = 'green'; break;
default: $color = 'black'; break;
}
if (isset($color) && !($color == "black" || $color == "blue" || $color == "green")) {
$error = "Возможно использовать цвета указанные только в меню анкеты!";
$color = "Black";
} elseif ($simbolcount > 1500) {
$error = "Максимальная длинна поля Хобби: 1500 символов ...";
if ($simbolcount > 1500) {
err('Максимальная длинна поля Хобби: 1500 символов!');
} else {
db::c()->query('UPDATE `users` SET `realname` = "?s", `color` = "?s", `info` = "?s" WHERE `id` = ?i', $name, $color, $hobbie, $user['id']);
$user['realname'] = $name;
$user['color'] = $color;
$user['info'] = $hobbie;
$error = 'Изменения вступили в силу ...';
db::c()->query('UPDATE `users` SET `realname` = "?s", `color` = "?s", `info` = "?s" WHERE `id` = ?i', $name, $color, $hobbie, $u->i()['id']);
}
}
@ -55,18 +50,16 @@ if ($_POST['submit']) {
</head>
<body>
<a href="main.php"> на главную</a>
<h1>Анкета персонажа <?= $user['login'] ?></h1>
<h1>Анкета персонажа <?= $u->i()['login'] ?></h1>
<form method="post" action="user_anketa.php">
<input name="name" placeholder="Реальное имя" value="<?= $user['realname']; ?>"><br>
<input name="name" placeholder="Реальное имя" value="<?= $u->i()['realname']; ?>"><br>
<select name="color" id="color">
<option value="0" selected>Чёрный</option>
<option value="1">Синий</option>
<option value="2">Зелёный</option>
</select><label for="color"></label>
<textarea name="hobby" placeholder="Хобби"><?= $user['info'] ?></textarea>
</select><label for="color"></label><br>
<textarea name="hobbie" placeholder="Хобби"><?= $u->i()['info'] ?></textarea><br>
<input name="submit" type="submit">
</form>
<div id="hint4"></div>
<?php if (!empty($error)) err($error); ?>
</body>
</html>