-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_ticket.php
115 lines (99 loc) · 3.85 KB
/
create_ticket.php
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
session_start();
require_once 'includes/config/database.php';
// Kullanıcı girişi kontrolü
if (!isset($_SESSION['user_id'])) {
header('Location: login.php');
exit;
}
$current_page = 'tickets';
// Kategorileri çek
$categories_query = $db->query("SELECT * FROM ticket_categories WHERE status = 1");
$categories = $categories_query->fetchAll(PDO::FETCH_ASSOC);
// Form gönderildiğinde
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$category_id = (int)$_POST['category'];
$subject = trim($_POST['subject']);
$message = trim($_POST['message']);
if (empty($subject) || empty($message)) {
$error = 'Lütfen tüm alanları doldurun.';
} else {
try {
$db->beginTransaction();
// Ticket oluştur
$ticket_stmt = $db->prepare("
INSERT INTO tickets (user_id, category_id, subject)
VALUES (?, ?, ?)
");
$ticket_stmt->execute([$_SESSION['user_id'], $category_id, $subject]);
$ticket_id = $db->lastInsertId();
// İlk mesajı ekle
$message_stmt = $db->prepare("
INSERT INTO ticket_messages (ticket_id, user_id, message)
VALUES (?, ?, ?)
");
$message_stmt->execute([$ticket_id, $_SESSION['user_id'], $message]);
$db->commit();
header('Location: tickets.php?success=created');
exit;
} catch (Exception $e) {
$db->rollBack();
$error = 'Bir hata oluştu, lütfen tekrar deneyin.';
}
}
}
include 'includes/header.php';
?>
<!DOCTYPE html>
<html lang="tr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Yeni Ticket Oluştur - <?php echo htmlspecialchars($settings['site_name']); ?></title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
<link rel="stylesheet" href="assets/css/style.css">
<link rel="stylesheet" href="assets/css/tickets.css">
</head>
<body>
<div class="tickets-container">
<div class="tickets-header">
<h1>Yeni Ticket Oluştur</h1>
<a href="tickets.php" class="back-btn">
<i class="fas fa-arrow-left"></i>
Geri Dön
</a>
</div>
<?php if (isset($error)): ?>
<div class="error-message">
<i class="fas fa-exclamation-circle"></i>
<?php echo htmlspecialchars($error); ?>
</div>
<?php endif; ?>
<form method="post" class="ticket-form">
<div class="form-group">
<label>Kategori</label>
<select name="category" required>
<?php foreach ($categories as $category): ?>
<option value="<?php echo $category['id']; ?>" class="category-option">
<i class="fas <?php echo htmlspecialchars($category['icon']); ?>"></i>
<?php echo htmlspecialchars($category['name']); ?>
</option>
<?php endforeach; ?>
</select>
</div>
<div class="form-group">
<label>Konu</label>
<input type="text" name="subject" required>
</div>
<div class="form-group">
<label>Mesaj</label>
<textarea name="message" rows="6" required></textarea>
</div>
<button type="submit" class="submit-btn">
<i class="fas fa-paper-plane"></i>
Ticket Oluştur
</button>
</form>
</div>
</body>
</html>