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 pathticket.php
More file actions
56 lines (47 loc) · 1.56 KB
/
ticket.php
File metadata and controls
56 lines (47 loc) · 1.56 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
51
52
53
54
55
56
<?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 {
if (isset($_POST['open_ticket'])) {
$ticket_id = $_POST['ticket_id'];
$status = 'open';
$sql = "UPDATE tickets SET status = ? WHERE id = ?";
$stmt = $db->prepare($sql);
$stmt->bind_param("si", $status, $ticket_id);
$stmt->execute();
$success_message = 'Ticket został otwarty.';
} elseif (isset($_POST['close_ticket'])) {
$ticket_id = $_POST['ticket_id'];
$status = 'closed';
$sql = "UPDATE tickets SET status = ? WHERE id = ?";
$stmt = $db->prepare($sql);
$stmt->bind_param("si", $status, $ticket_id);
$stmt->execute();
$success_message = 'Ticket został zamknięty.';
}
} catch (PDOException $e) {
$error_message = 'Błąd zapytania do bazy danych.';
} catch (Exception $e) {
$error_message = 'Wystąpił ogólny błąd.';
}
}
$user_id = $_SESSION['user_id'];
$sql = "SELECT * FROM tickets WHERE user_id = ?";
$stmt = $db->prepare($sql);
$stmt->bind_param("i", $user_id);
$stmt->execute();
$result = $stmt->get_result();
include "themes/$theme/ticket.php";
?>