38916-vm/create_ticket.php
Flatlogic Bot fd8a2de90a z
2026-03-01 18:23:38 +00:00

82 lines
3.3 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
require_once __DIR__ . '/auth.php';
$user = requireAuth();
if ($user['role'] !== 'user') {
header('Location: index.php');
exit;
}
// Check open tickets limit (max 3)
$stmt = db()->prepare("SELECT COUNT(*) FROM tickets WHERE user_id = ? AND status != 'closed'");
$stmt->execute([$user['id']]);
$openTicketsCount = $stmt->fetchColumn();
if ($openTicketsCount >= 3) {
die('У вас уже 3 открытых тикета. Пожалуйста, закройте один из них, прежде чем открывать новый.');
}
$error = null;
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$title = trim($_POST['title']);
$description = trim($_POST['description']);
$category = trim($_POST['category']);
if (empty($title) || empty($description)) {
$error = 'Пожалуйста, заполните все обязательные поля.';
} else {
$stmt = db()->prepare("INSERT INTO tickets (user_id, title, description, category) VALUES (?, ?, ?, ?)");
$stmt->execute([$user['id'], $title, $description, $category]);
header('Location: index.php');
exit;
}
}
?>
<!doctype html>
<html lang="ru">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Создать тикет - Система поддержки</title>
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&display=swap" rel="stylesheet">
</head>
<body>
<div class="bg-animations">
<div class="blob blob-1"></div>
<div class="blob blob-2"></div>
<div class="blob blob-3"></div>
</div>
<div class="main-wrapper">
<div class="auth-card" style="max-width: 600px; margin: 0 auto;">
<h2>Новый тикет</h2>
<?php if ($error): ?>
<div class="alert alert-error"><?= htmlspecialchars($error) ?></div>
<?php endif; ?>
<form method="POST">
<div class="form-group">
<label for="title">Тема</label>
<input type="text" name="title" id="title" required placeholder="Например: Не работает вход в систему">
</div>
<div class="form-group">
<label for="category">Категория</label>
<select name="category" id="category">
<option value="technical">Техническая проблема</option>
<option value="question">Вопрос</option>
<option value="complaint">Жалоба</option>
<option value="other">Другое</option>
</select>
</div>
<div class="form-group">
<label for="description">Описание</label>
<textarea name="description" id="description" rows="6" required placeholder="Опишите проблему как можно подробнее..."></textarea>
</div>
<button type="submit" class="btn-primary">Отправить тикет</button>
<a href="index.php" class="auth-footer" style="display: block; margin-top: 1rem; color: var(--text-secondary);">Отмена</a>
</form>
</div>
</div>
</body>
</html>