This repository was archived by the owner on May 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-ticket.php
More file actions
50 lines (43 loc) · 1.57 KB
/
create-ticket.php
File metadata and controls
50 lines (43 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
session_start();
if (!isset($_SESSION['user_id'])) {
header("Location: login.php");
exit;
}
include 'navbar.php';
include 'config/config.php';
if ($db->connect_error) {
die("Błąd połączenia z bazą danych: " . $db->connect_error);
}
$error_message = $success_message = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
try {
$subject = $_POST['subject'];
$category = $_POST['category'];
$priority = $_POST['priority'];
$description = $_POST['description'];
if (empty($subject) || empty($category) || empty($priority) || empty($description)) {
$error_message = 'Wszystkie pola formularza są wymagane.';
} else {
$user_id = $_SESSION['user_id'];
$status = 'open';
if (!isset($db)) {
$error_message = 'Błąd połączenia z bazą danych.';
} else {
$sql = "INSERT INTO tickets (user_id, category, priority, status, subject, description) VALUES (?, ?, ?, ?, ?, ?)";
$stmt = $db->prepare($sql);
$stmt->bind_param("isssss", $user_id, $category, $priority, $status, $subject, $description);
$stmt->execute();
$success_message = 'Twój ticket został pomyślnie dodany.';
}
}
} catch (PDOException $e) {
$error_message = 'Błąd zapytania do bazy danych.';
} catch (Exception $e) {
$error_message = 'Wystąpił ogólny błąd.';
}
}
include "themes/$theme/create-ticket.php";
?>