Fixed MAJOR bugs, currently at a semi-stable state

This commit is contained in:
2025-09-05 11:08:56 -04:00
parent 19f436a17c
commit e05434137c
14 changed files with 1559 additions and 1106 deletions

View File

@ -9,7 +9,7 @@ class CommentModel {
public function getCommentsByTicketId($ticketId) {
$sql = "SELECT * FROM ticket_comments WHERE ticket_id = ? ORDER BY created_at DESC";
$stmt = $this->conn->prepare($sql);
$stmt->bind_param("i", $ticketId);
$stmt->bind_param("s", $ticketId); // Changed to string since ticket_id is varchar
$stmt->execute();
$result = $stmt->get_result();
@ -31,11 +31,14 @@ class CommentModel {
$username = $commentData['user_name'] ?? 'User';
$markdownEnabled = isset($commentData['markdown_enabled']) && $commentData['markdown_enabled'] ? 1 : 0;
// Preserve line breaks in the comment text
$commentText = $commentData['comment_text'];
$stmt->bind_param(
"sssi",
$ticketId,
$username,
$commentData['comment_text'],
$commentText,
$markdownEnabled
);
@ -44,7 +47,8 @@ class CommentModel {
'success' => true,
'user_name' => $username,
'created_at' => date('M d, Y H:i'),
'markdown_enabled' => $markdownEnabled
'markdown_enabled' => $markdownEnabled,
'comment_text' => $commentText
];
} else {
return [
@ -53,4 +57,5 @@ class CommentModel {
];
}
}
}
}
?>

View File

@ -35,16 +35,45 @@ class TicketModel {
return $comments;
}
public function getAllTickets($page = 1, $limit = 15, $status = 'Open', $sortColumn = 'ticket_id', $sortDirection = 'desc') {
public function getAllTickets($page = 1, $limit = 15, $status = 'Open', $sortColumn = 'ticket_id', $sortDirection = 'desc', $category = null, $type = null) {
// Calculate offset
$offset = ($page - 1) * $limit;
// Build WHERE clause for status filtering
$whereClause = "";
// Build WHERE clause
$whereConditions = [];
$params = [];
$paramTypes = '';
// Status filtering
if ($status) {
$statuses = explode(',', $status);
$placeholders = str_repeat('?,', count($statuses) - 1) . '?';
$whereClause = "WHERE status IN ($placeholders)";
$whereConditions[] = "status IN ($placeholders)";
$params = array_merge($params, $statuses);
$paramTypes .= str_repeat('s', count($statuses));
}
// Category filtering
if ($category) {
$categories = explode(',', $category);
$placeholders = str_repeat('?,', count($categories) - 1) . '?';
$whereConditions[] = "category IN ($placeholders)";
$params = array_merge($params, $categories);
$paramTypes .= str_repeat('s', count($categories));
}
// Type filtering
if ($type) {
$types = explode(',', $type);
$placeholders = str_repeat('?,', count($types) - 1) . '?';
$whereConditions[] = "type IN ($placeholders)";
$params = array_merge($params, $types);
$paramTypes .= str_repeat('s', count($types));
}
$whereClause = '';
if (!empty($whereConditions)) {
$whereClause = 'WHERE ' . implode(' AND ', $whereConditions);
}
// Validate sort column to prevent SQL injection
@ -60,8 +89,8 @@ class TicketModel {
$countSql = "SELECT COUNT(*) as total FROM tickets $whereClause";
$countStmt = $this->conn->prepare($countSql);
if ($status) {
$countStmt->bind_param(str_repeat('s', count($statuses)), ...$statuses);
if (!empty($params)) {
$countStmt->bind_param($paramTypes, ...$params);
}
$countStmt->execute();
@ -72,12 +101,13 @@ class TicketModel {
$sql = "SELECT * FROM tickets $whereClause ORDER BY $sortColumn $sortDirection LIMIT ? OFFSET ?";
$stmt = $this->conn->prepare($sql);
if ($status) {
$types = str_repeat('s', count($statuses)) . 'ii';
$params = array_merge($statuses, [$limit, $offset]);
$stmt->bind_param($types, ...$params);
} else {
$stmt->bind_param("ii", $limit, $offset);
// Add limit and offset parameters
$params[] = $limit;
$params[] = $offset;
$paramTypes .= 'ii';
if (!empty($params)) {
$stmt->bind_param($paramTypes, ...$params);
}
$stmt->execute();