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

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 'config.php';
require_once 'classes/u.php';
define("HPADDICTIONEFFECT", 33); define("HPADDICTIONEFFECT", 33);
$ip = filter_input(INPUT_SERVER,'REMOTE_ADDR', FILTER_VALIDATE_IP); $ip = filter_input(INPUT_SERVER,'REMOTE_ADDR', FILTER_VALIDATE_IP);

View File

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