51 lines
1.2 KiB
PHP
51 lines
1.2 KiB
PHP
<?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();
|