battles/user_anketa.php

66 lines
2.0 KiB
PHP

<?php
session_start();
if (!isset($_SESSION['uid'])) {
header('Location: /index.php');
die();
}
include('config.php');
include('functions.php');
$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']);
// $name = htmlspecialchars($_POST['name'], NULL, 'cp1251');
// $color = htmlspecialchars($_POST['color'], NULL, 'cp1251');
$hobbie = str_replace("\\n", "<br />", $_POST['hobbie']);
$hobbie = str_replace("\\r", "", $_POST['hobbie']);
$hobbie = str_replace("&lt;br&nbsp;/&gt;", "<br />", $_POST['hobbie']);
$simbolcount = strlen($hobbie);
switch ($color) {
case 1: $color = 'blue'; break;
case 2: $color = 'green'; break;
default: $color = 'black'; break;
}
if ($simbolcount > 1500) {
err('Максимальная длинна поля Хобби: 1500 символов!');
} else {
db::c()->query('UPDATE `users` SET `realname` = "?s", `color` = "?s", `info` = "?s" WHERE `id` = ?i', $name, $color, $hobbie, $u->i()['id']);
}
}
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8"/>
<link rel="stylesheet" href="css/main.css">
<title>Анкета</title>
</head>
<body>
<a href="main.php">← на главную</a>
<h1>Анкета персонажа <?= $u->i()['login'] ?></h1>
<form method="post" action="user_anketa.php">
<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><br>
<textarea name="hobbie" placeholder="Хобби"><?= $u->i()['info'] ?></textarea><br>
<input name="submit" type="submit">
</form>
</body>
</html>