First Commit
This commit is contained in:
50
add_comment.php
Normal file
50
add_comment.php
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
<?php
|
||||||
|
// Load environment variables
|
||||||
|
$envFile = __DIR__ . '/.env';
|
||||||
|
$envVars = parse_ini_file($envFile);
|
||||||
|
|
||||||
|
// Database connection
|
||||||
|
$conn = new mysqli(
|
||||||
|
$envVars['REACT_APP_DB_HOST'],
|
||||||
|
$envVars['REACT_APP_DB_USER'],
|
||||||
|
$envVars['REACT_APP_DB_PASS'],
|
||||||
|
$envVars['REACT_APP_DB_NAME']
|
||||||
|
);
|
||||||
|
|
||||||
|
// Get POST data
|
||||||
|
$data = json_decode(file_get_contents('php://input'), true);
|
||||||
|
|
||||||
|
// Set default username (you can modify this based on your user system)
|
||||||
|
$username = "User";
|
||||||
|
|
||||||
|
// Prepare insert query
|
||||||
|
$sql = "INSERT INTO ticket_comments (ticket_id, user_name, comment_text, markdown_enabled) VALUES (?, ?, ?, ?)";
|
||||||
|
$stmt = $conn->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();
|
||||||
84
create_ticket_api.php
Normal file
84
create_ticket_api.php
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
<?php
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
|
||||||
|
// Load environment variables with error check
|
||||||
|
$envFile = __DIR__ . '/.env';
|
||||||
|
if (!file_exists($envFile)) {
|
||||||
|
echo json_encode([
|
||||||
|
'success' => 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();
|
||||||
149
dashboard.php
Normal file
149
dashboard.php
Normal file
@ -0,0 +1,149 @@
|
|||||||
|
<?php
|
||||||
|
error_reporting(E_ALL);
|
||||||
|
ini_set('display_errors', 1);
|
||||||
|
|
||||||
|
// Load environment variables
|
||||||
|
$envFile = __DIR__ . '/.env';
|
||||||
|
$envVars = parse_ini_file($envFile);
|
||||||
|
// Database connection settings
|
||||||
|
$dbHost = $envVars['REACT_APP_DB_HOST'];
|
||||||
|
$dbUser = $envVars['REACT_APP_DB_USER'];
|
||||||
|
$dbPass = $envVars['REACT_APP_DB_PASS'];
|
||||||
|
$dbName = $envVars['REACT_APP_DB_NAME'];
|
||||||
|
|
||||||
|
// Create database connection
|
||||||
|
$conn = new mysqli($dbHost, $dbUser, $dbPass, $dbName);
|
||||||
|
|
||||||
|
// Check connection
|
||||||
|
if ($conn->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);
|
||||||
|
?>
|
||||||
|
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Ticket Dashboard</title>
|
||||||
|
<link rel="icon" type="image/png" href="assets/images/favicon.png">
|
||||||
|
<link rel="stylesheet" href="assets/css/dashboard.css">
|
||||||
|
<script src="assets/js/dashboard.js"></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="dashboard-header">
|
||||||
|
<h1>Tinker Tickets</h1>
|
||||||
|
<button onclick="window.location.href='new_ticket.php'" class="btn create-ticket">New Ticket</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="table-controls">
|
||||||
|
<div class="ticket-count">
|
||||||
|
Total Tickets: <?php echo $totalTickets; ?>
|
||||||
|
</div>
|
||||||
|
<div class="table-actions">
|
||||||
|
<div class="pagination">
|
||||||
|
<?php
|
||||||
|
// Previous page button
|
||||||
|
if ($page > 1) {
|
||||||
|
echo "<button onclick='window.location.href=\"?page=" . ($page - 1) . "\"'>«</button>";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Page number buttons
|
||||||
|
for ($i = 1; $i <= $totalPages; $i++) {
|
||||||
|
$activeClass = ($i === $page) ? 'active' : '';
|
||||||
|
echo "<button class='$activeClass' onclick='window.location.href=\"?page=$i\"'>$i</button>";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Next page button
|
||||||
|
if ($page < $totalPages) {
|
||||||
|
echo "<button onclick='window.location.href=\"?page=" . ($page + 1) . "\"'>»</button>";
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
|
<div class="settings-icon">
|
||||||
|
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
||||||
|
<circle cx="12" cy="12" r="3"></circle>
|
||||||
|
<path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z"></path>
|
||||||
|
</svg>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Ticket ID</th>
|
||||||
|
<th>Priority</th>
|
||||||
|
<th>Title</th>
|
||||||
|
<th>Category</th>
|
||||||
|
<th>Type</th>
|
||||||
|
<th>Status</th>
|
||||||
|
<th>Created</th>
|
||||||
|
<th>Updated</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<?php
|
||||||
|
if ($result->num_rows > 0) {
|
||||||
|
while($row = $result->fetch_assoc()) {
|
||||||
|
echo "<tr class='priority-{$row['priority']}'>";
|
||||||
|
echo "<td><a href='ticket.php?id={$row['ticket_id']}' class='ticket-link'>{$row['ticket_id']}</a></td>";
|
||||||
|
echo "<td><span>{$row['priority']}</span></td>";
|
||||||
|
echo "<td>{$row['title']}</td>";
|
||||||
|
echo "<td>{$row['category']}</td>";
|
||||||
|
echo "<td>{$row['type']}</td>";
|
||||||
|
echo "<td class='status-{$row['status']}'>{$row['status']}</td>";
|
||||||
|
echo "<td>" . date('Y-m-d H:i', strtotime($row['created_at'])) . "</td>";
|
||||||
|
echo "<td>" . date('Y-m-d H:i', strtotime($row['updated_at'])) . "</td>";
|
||||||
|
echo "</tr>";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
echo "<tr><td colspan='8'>No tickets found</td></tr>";
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<?php $conn->close(); ?>
|
||||||
|
<script>
|
||||||
|
document.body.dataset.categories = JSON.stringify([
|
||||||
|
<?php
|
||||||
|
$categories = [];
|
||||||
|
mysqli_data_seek($categoriesResult, 0);
|
||||||
|
while($row = $categoriesResult->fetch_assoc()) {
|
||||||
|
$categories[] = "'" . $row['category'] . "'";
|
||||||
|
}
|
||||||
|
echo implode(',', $categories);
|
||||||
|
?>
|
||||||
|
]);
|
||||||
|
document.body.dataset.types = JSON.stringify([
|
||||||
|
<?php
|
||||||
|
$types = [];
|
||||||
|
mysqli_data_seek($typesResult, 0);
|
||||||
|
while($row = $typesResult->fetch_assoc()) {
|
||||||
|
$types[] = "'" . $row['type'] . "'";
|
||||||
|
}
|
||||||
|
echo implode(',', $types);
|
||||||
|
?>
|
||||||
|
]);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
1
logo.svg
Normal file
1
logo.svg
Normal file
@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 841.9 595.3"><g fill="#61DAFB"><path d="M666.3 296.5c0-32.5-40.7-63.3-103.1-82.4 14.4-63.6 8-114.2-20.2-130.4-6.5-3.8-14.1-5.6-22.4-5.6v22.3c4.6 0 8.3.9 11.4 2.6 13.6 7.8 19.5 37.5 14.9 75.7-1.1 9.4-2.9 19.3-5.1 29.4-19.6-4.8-41-8.5-63.5-10.9-13.5-18.5-27.5-35.3-41.6-50 32.6-30.3 63.2-46.9 84-46.9V78c-27.5 0-63.5 19.6-99.9 53.6-36.4-33.8-72.4-53.2-99.9-53.2v22.3c20.7 0 51.4 16.5 84 46.6-14 14.7-28 31.4-41.3 49.9-22.6 2.4-44 6.1-63.6 11-2.3-10-4-19.7-5.2-29-4.7-38.2 1.1-67.9 14.6-75.8 3-1.8 6.9-2.6 11.5-2.6V78.5c-8.4 0-16 1.8-22.6 5.6-28.1 16.2-34.4 66.7-19.9 130.1-62.2 19.2-102.7 49.9-102.7 82.3 0 32.5 40.7 63.3 103.1 82.4-14.4 63.6-8 114.2 20.2 130.4 6.5 3.8 14.1 5.6 22.5 5.6 27.5 0 63.5-19.6 99.9-53.6 36.4 33.8 72.4 53.2 99.9 53.2 8.4 0 16-1.8 22.6-5.6 28.1-16.2 34.4-66.7 19.9-130.1 62-19.1 102.5-49.9 102.5-82.3zm-130.2-66.7c-3.7 12.9-8.3 26.2-13.5 39.5-4.1-8-8.4-16-13.1-24-4.6-8-9.5-15.8-14.4-23.4 14.2 2.1 27.9 4.7 41 7.9zm-45.8 106.5c-7.8 13.5-15.8 26.3-24.1 38.2-14.9 1.3-30 2-45.2 2-15.1 0-30.2-.7-45-1.9-8.3-11.9-16.4-24.6-24.2-38-7.6-13.1-14.5-26.4-20.8-39.8 6.2-13.4 13.2-26.8 20.7-39.9 7.8-13.5 15.8-26.3 24.1-38.2 14.9-1.3 30-2 45.2-2 15.1 0 30.2.7 45 1.9 8.3 11.9 16.4 24.6 24.2 38 7.6 13.1 14.5 26.4 20.8 39.8-6.3 13.4-13.2 26.8-20.7 39.9zm32.3-13c5.4 13.4 10 26.8 13.8 39.8-13.1 3.2-26.9 5.9-41.2 8 4.9-7.7 9.8-15.6 14.4-23.7 4.6-8 8.9-16.1 13-24.1zM421.2 430c-9.3-9.6-18.6-20.3-27.8-32 9 .4 18.2.7 27.5.7 9.4 0 18.7-.2 27.8-.7-9 11.7-18.3 22.4-27.5 32zm-74.4-58.9c-14.2-2.1-27.9-4.7-41-7.9 3.7-12.9 8.3-26.2 13.5-39.5 4.1 8 8.4 16 13.1 24 4.7 8 9.5 15.8 14.4 23.4zM420.7 163c9.3 9.6 18.6 20.3 27.8 32-9-.4-18.2-.7-27.5-.7-9.4 0-18.7.2-27.8.7 9-11.7 18.3-22.4 27.5-32zm-74 58.9c-4.9 7.7-9.8 15.6-14.4 23.7-4.6 8-8.9 16-13 24-5.4-13.4-10-26.8-13.8-39.8 13.1-3.1 26.9-5.8 41.2-7.9zm-90.5 125.2c-35.4-15.1-58.3-34.9-58.3-50.6 0-15.7 22.9-35.6 58.3-50.6 8.6-3.7 18-7 27.7-10.1 5.7 19.6 13.2 40 22.5 60.9-9.2 20.8-16.6 41.1-22.2 60.6-9.9-3.1-19.3-6.5-28-10.2zM310 490c-13.6-7.8-19.5-37.5-14.9-75.7 1.1-9.4 2.9-19.3 5.1-29.4 19.6 4.8 41 8.5 63.5 10.9 13.5 18.5 27.5 35.3 41.6 50-32.6 30.3-63.2 46.9-84 46.9-4.5-.1-8.3-1-11.3-2.7zm237.2-76.2c4.7 38.2-1.1 67.9-14.6 75.8-3 1.8-6.9 2.6-11.5 2.6-20.7 0-51.4-16.5-84-46.6 14-14.7 28-31.4 41.3-49.9 22.6-2.4 44-6.1 63.6-11 2.3 10.1 4.1 19.8 5.2 29.1zm38.5-66.7c-8.6 3.7-18 7-27.7 10.1-5.7-19.6-13.2-40-22.5-60.9 9.2-20.8 16.6-41.1 22.2-60.6 9.9 3.1 19.3 6.5 28.1 10.2 35.4 15.1 58.3 34.9 58.3 50.6-.1 15.7-23 35.6-58.4 50.6zM320.8 78.4z"/><circle cx="420.9" cy="296.5" r="45.7"/><path d="M520.5 78.1z"/></g></svg>
|
||||||
|
After Width: | Height: | Size: 2.6 KiB |
104
new_ticket.php
Normal file
104
new_ticket.php
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
<?php
|
||||||
|
// Load environment variables
|
||||||
|
$envFile = __DIR__ . '/.env';
|
||||||
|
$envVars = parse_ini_file($envFile);
|
||||||
|
?>
|
||||||
|
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Create New Ticket</title>
|
||||||
|
<link rel="icon" type="image/png" href="assets/images/favicon.png">
|
||||||
|
<link rel="stylesheet" href="assets/css/dashboard.css">
|
||||||
|
<link rel="stylesheet" href="assets/css/ticket.css">
|
||||||
|
<script src="assets/js/dashboard.js"></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="ticket-container">
|
||||||
|
<div class="ticket-header">
|
||||||
|
<h1>Create New Ticket</h1>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<form id="newTicketForm" class="ticket-details">
|
||||||
|
<div class="detail-group">
|
||||||
|
<label>Title</label>
|
||||||
|
<input type="text" name="title" required class="editable">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="detail-group status-priority-row">
|
||||||
|
<div class="detail-quarter">
|
||||||
|
<label>Status</label>
|
||||||
|
<select name="status" required class="editable">
|
||||||
|
<option value="Open">Open</option>
|
||||||
|
<option value="Closed">Closed</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="detail-quarter">
|
||||||
|
<label>Priority</label>
|
||||||
|
<select name="priority" required class="editable">
|
||||||
|
<option value="1">P1 - Critical Impact</option>
|
||||||
|
<option value="2">P2 - High Impact</option>
|
||||||
|
<option value="3">P3 - Medium Impact</option>
|
||||||
|
<option value="4">P4 - Low Impact</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="detail-quarter">
|
||||||
|
<label>Category</label>
|
||||||
|
<select name="category" required class="editable">
|
||||||
|
<option value="Hardware">Hardware</option>
|
||||||
|
<option value="Software">Software</option>
|
||||||
|
<option value="Network">Network</option>
|
||||||
|
<option value="Security">Security</option>
|
||||||
|
<option value="Other">Other</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="detail-quarter">
|
||||||
|
<label>Type</label>
|
||||||
|
<select name="type" required class="editable">
|
||||||
|
<option value="Incident">Incident</option>
|
||||||
|
<option value="Request">Request</option>
|
||||||
|
<option value="Problem">Problem</option>
|
||||||
|
<option value="Task">Task</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="detail-group full-width">
|
||||||
|
<label>Description</label>
|
||||||
|
<textarea name="description" required class="editable"></textarea>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-actions">
|
||||||
|
<button type="button" onclick="window.location.href='dashboard.php'" class="btn">Cancel</button>
|
||||||
|
<button type="submit" class="btn create-ticket">Create Ticket</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
document.getElementById('newTicketForm').addEventListener('submit', function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
const formData = new FormData(this);
|
||||||
|
const data = {};
|
||||||
|
formData.forEach((value, key) => data[key] = value);
|
||||||
|
|
||||||
|
fetch('create_ticket_api.php', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify(data)
|
||||||
|
})
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(data => {
|
||||||
|
if(data.success) {
|
||||||
|
window.location.href = 'ticket.php?id=' + data.ticket_id;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
196
ticket.php
Normal file
196
ticket.php
Normal file
@ -0,0 +1,196 @@
|
|||||||
|
<?php
|
||||||
|
// Load environment variables and DB connection (same as dashboard.php)
|
||||||
|
$envFile = __DIR__ . "/.env";
|
||||||
|
$envVars = parse_ini_file($envFile);
|
||||||
|
$conn = new mysqli(
|
||||||
|
$envVars["REACT_APP_DB_HOST"],
|
||||||
|
$envVars["REACT_APP_DB_USER"],
|
||||||
|
$envVars["REACT_APP_DB_PASS"],
|
||||||
|
$envVars["REACT_APP_DB_NAME"]
|
||||||
|
);
|
||||||
|
|
||||||
|
$ticket_id = $_GET["id"];
|
||||||
|
$sql = "SELECT * FROM tickets WHERE ticket_id = ?";
|
||||||
|
$stmt = $conn->prepare($sql);
|
||||||
|
$stmt->bind_param("i", $ticket_id);
|
||||||
|
$stmt->execute();
|
||||||
|
$result = $stmt->get_result();
|
||||||
|
$ticket = $result->fetch_assoc();
|
||||||
|
?>
|
||||||
|
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Ticket #<?php echo $ticket_id; ?></title>
|
||||||
|
<link rel="icon" type="image/png" href="assets/images/favicon.png">
|
||||||
|
<link rel="stylesheet" href="assets/css/dashboard.css">
|
||||||
|
<link rel="stylesheet" href="assets/css/ticket.css">
|
||||||
|
<script src="assets/js/dashboard.js"></script>
|
||||||
|
<script src="assets/js/ticket.js"></script>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="ticket-container" data-priority="<?php echo $ticket[
|
||||||
|
"priority"
|
||||||
|
]; ?>">
|
||||||
|
<div class="ticket-header">
|
||||||
|
<h2><input type="text" class="editable title-input" value="<?php echo $ticket[
|
||||||
|
"title"
|
||||||
|
]; ?>" data-field="title" disabled></h2>
|
||||||
|
<div class="ticket-subheader">
|
||||||
|
<div class="ticket-id">UUID <?php echo $ticket_id; ?></div>
|
||||||
|
<div class="header-controls">
|
||||||
|
<div class="status-priority-group">
|
||||||
|
<span id="statusDisplay" class="status-<?php echo $ticket[
|
||||||
|
"status"
|
||||||
|
]; ?>"><?php echo $ticket["status"]; ?></span>
|
||||||
|
<span class="priority-indicator priority-<?php echo $ticket[
|
||||||
|
"priority"
|
||||||
|
]; ?>">P<?php echo $ticket["priority"]; ?></span>
|
||||||
|
</div>
|
||||||
|
<button id="editButton" class="btn" onclick="toggleEditMode()">Edit Ticket</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="ticket-details">
|
||||||
|
<div class="detail-group status-priority-row">
|
||||||
|
<div class="detail-quarter">
|
||||||
|
<label>Status</label>
|
||||||
|
<select class="editable" data-field="status" disabled>
|
||||||
|
<option value="Open" <?php echo $ticket["status"] == "Open"
|
||||||
|
? "selected"
|
||||||
|
: ""; ?>>Open</option>
|
||||||
|
<option value="Closed" <?php echo $ticket["status"] ==
|
||||||
|
"Closed"
|
||||||
|
? "selected"
|
||||||
|
: ""; ?>>Closed</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="detail-quarter">
|
||||||
|
<label>Priority</label>
|
||||||
|
<select class="editable" data-field="priority" disabled>
|
||||||
|
<option value="1" <?php echo $ticket["priority"] == 1
|
||||||
|
? "selected"
|
||||||
|
: ""; ?>>P1 - Critical Impact</option>
|
||||||
|
<option value="2" <?php echo $ticket["priority"] == 2
|
||||||
|
? "selected"
|
||||||
|
: ""; ?>>P2 - High Impact</option>
|
||||||
|
<option value="3" <?php echo $ticket["priority"] == 3
|
||||||
|
? "selected"
|
||||||
|
: ""; ?>>P3 - Medium Impact</option>
|
||||||
|
<option value="4" <?php echo $ticket["priority"] == 4
|
||||||
|
? "selected"
|
||||||
|
: ""; ?>>P4 - Low Impact</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="detail-quarter">
|
||||||
|
<label>Category</label>
|
||||||
|
<select class="editable" data-field="category" disabled>
|
||||||
|
<option value="Hardware" <?php echo $ticket["category"] ==
|
||||||
|
"Hardware"
|
||||||
|
? "selected"
|
||||||
|
: ""; ?>>Hardware</option>
|
||||||
|
<option value="Software" <?php echo $ticket["category"] ==
|
||||||
|
"Software"
|
||||||
|
? "selected"
|
||||||
|
: ""; ?>>Software</option>
|
||||||
|
<option value="Network" <?php echo $ticket["category"] ==
|
||||||
|
"Network"
|
||||||
|
? "selected"
|
||||||
|
: ""; ?>>Network</option>
|
||||||
|
<option value="Security" <?php echo $ticket["category"] ==
|
||||||
|
"Security"
|
||||||
|
? "selected"
|
||||||
|
: ""; ?>>Security</option>
|
||||||
|
<option value="Other" <?php echo $ticket["category"] ==
|
||||||
|
"Other"
|
||||||
|
? "selected"
|
||||||
|
: ""; ?>>Other</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="detail-quarter">
|
||||||
|
<label>Type</label>
|
||||||
|
<select class="editable" data-field="type" disabled>
|
||||||
|
<option value="Maintenance" <?php echo $ticket["type"] == "Maintenance" ? "selected" : ""; ?>>Maintenance</option>
|
||||||
|
<option value="Install" <?php echo $ticket["type"] == "Install" ? "selected" : ""; ?>>Install</option>
|
||||||
|
<option value="Task" <?php echo $ticket["type"] == "Task" ? "selected" : ""; ?>>Task</option>
|
||||||
|
<option value="Upgrade" <?php echo $ticket["type"] == "Upgrade" ? "selected" : ""; ?>>Upgrade</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="ticket-tabs">
|
||||||
|
<button class="tab-btn active" onclick="showTab('description')">Description</button>
|
||||||
|
<button class="tab-btn" onclick="showTab('comments')">Comments</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="description-tab" class="tab-content active">
|
||||||
|
<div class="detail-group full-width">
|
||||||
|
<label>Description</label>
|
||||||
|
<textarea class="editable" data-field="description" disabled><?php echo $ticket[
|
||||||
|
"description"
|
||||||
|
]; ?></textarea>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="comments-tab" class="tab-content">
|
||||||
|
<div class="comments-section">
|
||||||
|
<h2>Comments</h2>
|
||||||
|
<div class="comment-form">
|
||||||
|
<textarea id="newComment" placeholder="Add a comment..."></textarea>
|
||||||
|
<div class="comment-controls">
|
||||||
|
<div class="markdown-toggles">
|
||||||
|
<div class="preview-toggle">
|
||||||
|
<label class="switch">
|
||||||
|
<input type="checkbox" id="markdownMaster" onchange="toggleMarkdownMode()">
|
||||||
|
<span class="slider round"></span>
|
||||||
|
</label>
|
||||||
|
<span class="toggle-label">Enable Markdown</span>
|
||||||
|
</div>
|
||||||
|
<div class="preview-toggle">
|
||||||
|
<label class="switch">
|
||||||
|
<input type="checkbox" id="markdownToggle" onchange="togglePreview()" disabled>
|
||||||
|
<span class="slider round"></span>
|
||||||
|
</label>
|
||||||
|
<span class="toggle-label">Preview Markdown</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<button onclick="addComment()" class="btn">Add Comment</button>
|
||||||
|
</div>
|
||||||
|
<div id="markdownPreview" class="markdown-preview" style="display: none;"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="comments-list">
|
||||||
|
<?php
|
||||||
|
$commentsSql = "SELECT * FROM ticket_comments WHERE ticket_id = ? ORDER BY created_at DESC";
|
||||||
|
$stmt = $conn->prepare($commentsSql);
|
||||||
|
$stmt->bind_param("s", $ticket_id);
|
||||||
|
$stmt->execute();
|
||||||
|
$comments = $stmt->get_result();
|
||||||
|
|
||||||
|
while($comment = $comments->fetch_assoc()) {
|
||||||
|
echo "<div class='comment'>";
|
||||||
|
echo "<div class='comment-header'>";
|
||||||
|
echo "<span class='comment-user'>{$comment['user_name']}</span>";
|
||||||
|
echo "<span class='comment-date'>" . date('M d, Y H:i', strtotime($comment['created_at'])) . "</span>";
|
||||||
|
echo "</div>";
|
||||||
|
echo "<div class='comment-text'>";
|
||||||
|
if ($comment['markdown_enabled']) {
|
||||||
|
echo "<script>document.write(marked.parse(" . json_encode($comment['comment_text']) . "))</script>";
|
||||||
|
} else {
|
||||||
|
echo htmlspecialchars($comment['comment_text']);
|
||||||
|
}
|
||||||
|
echo "</div>";
|
||||||
|
echo "</div>";
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="ticket-footer">
|
||||||
|
<button onclick="window.location.href='dashboard.php'" class="btn back-btn">Back to Dashboard</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
56
update_ticket.php
Normal file
56
update_ticket.php
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
<?php
|
||||||
|
// Load environment variables
|
||||||
|
$envFile = __DIR__ . '/.env';
|
||||||
|
$envVars = parse_ini_file($envFile);
|
||||||
|
|
||||||
|
// Database connection
|
||||||
|
$conn = new mysqli(
|
||||||
|
$envVars['REACT_APP_DB_HOST'],
|
||||||
|
$envVars['REACT_APP_DB_USER'],
|
||||||
|
$envVars['REACT_APP_DB_PASS'],
|
||||||
|
$envVars['REACT_APP_DB_NAME']
|
||||||
|
);
|
||||||
|
|
||||||
|
// Get POST data
|
||||||
|
$data = json_decode(file_get_contents('php://input'), true);
|
||||||
|
|
||||||
|
// Prepare update query
|
||||||
|
$sql = "UPDATE tickets SET
|
||||||
|
title = ?,
|
||||||
|
priority = ?,
|
||||||
|
status = ?,
|
||||||
|
description = ?,
|
||||||
|
category = ?,
|
||||||
|
type = ?,
|
||||||
|
updated_at = NOW()
|
||||||
|
WHERE ticket_id = ?";
|
||||||
|
|
||||||
|
$stmt = $conn->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();
|
||||||
Reference in New Issue
Block a user