From 891291c5eb6d9f271754d8aa831139370777ab0d Mon Sep 17 00:00:00 2001 From: Jared Vititoe Date: Sat, 30 Nov 2024 19:48:01 -0500 Subject: [PATCH] First Commit --- add_comment.php | 50 +++++++++++ create_ticket_api.php | 84 ++++++++++++++++++ dashboard.php | 149 ++++++++++++++++++++++++++++++++ logo.svg | 1 + new_ticket.php | 104 ++++++++++++++++++++++ ticket.php | 196 ++++++++++++++++++++++++++++++++++++++++++ update_ticket.php | 56 ++++++++++++ 7 files changed, 640 insertions(+) create mode 100644 add_comment.php create mode 100644 create_ticket_api.php create mode 100644 dashboard.php create mode 100644 logo.svg create mode 100644 new_ticket.php create mode 100644 ticket.php create mode 100644 update_ticket.php diff --git a/add_comment.php b/add_comment.php new file mode 100644 index 0000000..cfcbae6 --- /dev/null +++ b/add_comment.php @@ -0,0 +1,50 @@ +prepare($sql); + +// Convert markdown_enabled to integer for database +$markdownEnabled = $data['markdown_enabled'] ? 1 : 0; + +$stmt->bind_param("sssi", + $data['ticket_id'], + $username, + $data['comment_text'], + $markdownEnabled +); + +if ($stmt->execute()) { + header('Content-Type: application/json'); + echo json_encode([ + 'success' => true, + 'user_name' => $username, + 'created_at' => date('M d, Y H:i'), + 'markdown_enabled' => $markdownEnabled + ]); +} else { + echo json_encode([ + 'success' => false, + 'error' => $conn->error + ]); +} + +$stmt->close(); +$conn->close(); diff --git a/create_ticket_api.php b/create_ticket_api.php new file mode 100644 index 0000000..d956e25 --- /dev/null +++ b/create_ticket_api.php @@ -0,0 +1,84 @@ + false, + 'error' => 'Configuration file not found' + ]); + exit; +} + +$envVars = parse_ini_file($envFile); +if (!$envVars) { + echo json_encode([ + 'success' => false, + 'error' => 'Invalid configuration file' + ]); + exit; +} + +// Database connection with detailed error handling +$conn = new mysqli( + $envVars['REACT_APP_DB_HOST'], + $envVars['REACT_APP_DB_USER'], + $envVars['REACT_APP_DB_PASS'], + $envVars['REACT_APP_DB_NAME'] +); + +if ($conn->connect_error) { + echo json_encode([ + 'success' => false, + 'error' => 'Database connection failed: ' . $conn->connect_error + ]); + exit; +} + +// Get POST data +$data = json_decode(file_get_contents('php://input'), true); + +// Generate ticket ID (9-digit format with leading zeros) +$ticket_id = sprintf('%09d', mt_rand(1, 999999999)); + +// Prepare insert query +$sql = "INSERT INTO tickets (ticket_id, title, description, status, priority, category, type) + VALUES (?, ?, ?, ?, ?, ?, ?)"; + +$stmt = $conn->prepare($sql); +// First, store all values in variables +$title = $data['title']; +$description = $data['description']; +$status = $data['status'] ?? 'Open'; +$priority = $data['priority'] ?? '4'; +$category = $data['category'] ?? 'General'; +$type = $data['type'] ?? 'Issue'; + +// Then use the variables in bind_param +$stmt->bind_param( + "sssssss", + $ticket_id, + $title, + $description, + $status, + $priority, + $category, + $type +); + +if ($stmt->execute()) { + echo json_encode([ + 'success' => true, + 'ticket_id' => $ticket_id, + 'message' => 'Ticket created successfully' + ]); +} else { + echo json_encode([ + 'success' => false, + 'error' => $conn->error + ]); +} + +$stmt->close(); +$conn->close(); diff --git a/dashboard.php b/dashboard.php new file mode 100644 index 0000000..4c29e5c --- /dev/null +++ b/dashboard.php @@ -0,0 +1,149 @@ +connect_error) { + die("Connection failed: " . $conn->connect_error); +} + +// Pagination settings from localStorage or defaults +$page = isset($_GET['page']) ? (int)$_GET['page'] : 1; +$limit = isset($_COOKIE['ticketsPerPage']) ? (int)$_COOKIE['ticketsPerPage'] : 15; +$defaultSortColumn = isset($_COOKIE['defaultSortColumn']) ? $_COOKIE['defaultSortColumn'] : 'ticket_id'; +$sortDirection = isset($_COOKIE['sortDirection']) ? $_COOKIE['sortDirection'] : 'desc'; +$offset = ($page - 1) * $limit; + +// Get total number of tickets +$totalTicketsQuery = "SELECT COUNT(*) as total FROM tickets"; +$totalTicketsResult = $conn->query($totalTicketsQuery); +$totalTickets = $totalTicketsResult->fetch_assoc()['total']; +$totalPages = ceil($totalTickets / $limit); + +// Modify SQL to use these settings +$sql = "SELECT * FROM tickets ORDER BY $defaultSortColumn $sortDirection LIMIT $limit OFFSET $offset"; +$result = $conn->query($sql); +?> + + + + + + + Ticket Dashboard + + + + + +
+

Tinker Tickets

+ +
+ +
+
+ Total Tickets: +
+
+ +
+ + + + +
+
+
+ + + + + + + + + + + + + + + + num_rows > 0) { + while($row = $result->fetch_assoc()) { + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + } + } else { + echo ""; + } + ?> + +
Ticket IDPriorityTitleCategoryTypeStatusCreatedUpdated
{$row['ticket_id']}{$row['priority']}{$row['title']}{$row['category']}{$row['type']}{$row['status']}" . date('Y-m-d H:i', strtotime($row['created_at'])) . "" . date('Y-m-d H:i', strtotime($row['updated_at'])) . "
No tickets found
+ + close(); ?> + + + + diff --git a/logo.svg b/logo.svg new file mode 100644 index 0000000..9dfc1c0 --- /dev/null +++ b/logo.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/new_ticket.php b/new_ticket.php new file mode 100644 index 0000000..3f5ef8d --- /dev/null +++ b/new_ticket.php @@ -0,0 +1,104 @@ + + + + + + + + Create New Ticket + + + + + + +
+
+

Create New Ticket

+
+ +
+
+ + +
+ +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ + +
+ +
+ + +
+
+
+ + + + diff --git a/ticket.php b/ticket.php new file mode 100644 index 0000000..eaaceb3 --- /dev/null +++ b/ticket.php @@ -0,0 +1,196 @@ +prepare($sql); +$stmt->bind_param("i", $ticket_id); +$stmt->execute(); +$result = $stmt->get_result(); +$ticket = $result->fetch_assoc(); +?> + + + + + + + Ticket #<?php echo $ticket_id; ?> + + + + + + + + +
"> +
+

" data-field="title" disabled>

+
+
UUID
+
+
+ "> + ">P +
+ +
+
+
+
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+
+ + +
+ +
+
+ + +
+
+ +
+
+

Comments

+
+ +
+
+
+ + Enable Markdown +
+
+ + Preview Markdown +
+
+ +
+ +
+
+
+ prepare($commentsSql); + $stmt->bind_param("s", $ticket_id); + $stmt->execute(); + $comments = $stmt->get_result(); + + while($comment = $comments->fetch_assoc()) { + echo "
"; + echo "
"; + echo "{$comment['user_name']}"; + echo "" . date('M d, Y H:i', strtotime($comment['created_at'])) . ""; + echo "
"; + echo "
"; + if ($comment['markdown_enabled']) { + echo ""; + } else { + echo htmlspecialchars($comment['comment_text']); + } + echo "
"; + echo "
"; + } + ?> +
+
+
+ +
+ + diff --git a/update_ticket.php b/update_ticket.php new file mode 100644 index 0000000..49dd054 --- /dev/null +++ b/update_ticket.php @@ -0,0 +1,56 @@ +prepare($sql); +$stmt->bind_param( + "sisssss", + $data['title'], + $data['priority'], + $data['status'], + $data['description'], + $data['category'], + $data['type'], + $data['ticket_id'] +); + +// After successful update +if ($stmt->execute()) { + header('Content-Type: application/json'); + echo json_encode([ + 'success' => true, + 'status' => $data['status'] // Send back the new status + ]); +} else { + header('Content-Type: application/json'); + echo json_encode([ + 'success' => false, + 'error' => $conn->error + ]); +} + +$stmt->close(); +$conn->close();