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 ID | +Priority | +Title | +Category | +Type | +Status | +Created | +Updated | +
|---|---|---|---|---|---|---|---|
| {$row['ticket_id']} | "; + echo "{$row['priority']} | "; + echo "{$row['title']} | "; + echo "{$row['category']} | "; + echo "{$row['type']} | "; + echo "{$row['status']} | "; + echo "" . date('Y-m-d H:i', strtotime($row['created_at'])) . " | "; + echo "" . date('Y-m-d H:i', strtotime($row['updated_at'])) . " | "; + echo "
| No tickets found | |||||||
Comments
+