battles/user_anketa.php

73 lines
2.4 KiB
PHP

<?php
session_start();
if (!isset($_SESSION['uid'])) {
header('Location: /index.php');
die();
}
include('config.php');
include('functions.php');
if ($user['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: $newcolor = 'blue'; break;
case 2: $newcolor = 'green'; break;
default: $newcolor = 'black'; break;
}
if (isset($color) && !($color == "black" || $color == "blue" || $color == "green")) {
$error = "Возможно использовать цвета указанные только в меню анкеты!";
$color = "Black";
} elseif ($simbolcount > 1500) {
$error = "Максимальная длинна поля Хобби: 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 = 'Изменения вступили в силу ...';
}
}
?>
<!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>Анкета персонажа <?= $user['login'] ?></h1>
<form method="post" action="user_anketa.php">
<input name="name" placeholder="Реальное имя" value="<?= $user['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>
<input name="submit" type="submit">
</form>
<div id="hint4"></div>
<?php if (!empty($error)) err($error); ?>
</body>
</html>