50 lines
1.3 KiB
PHP
50 lines
1.3 KiB
PHP
<?php
|
|
ini_set('display_errors', 0);
|
|
error_reporting(0);
|
|
require_once __DIR__ . '/config.php';
|
|
header('Content-Type: application/json; charset=utf-8');
|
|
|
|
if (empty($_SERVER['HTTP_X_REQUESTED_WITH']) || strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest') {
|
|
http_response_code(403);
|
|
exit(json_encode(['error' => 'Forbidden']));
|
|
}
|
|
|
|
$user = checkAuth($pdo);
|
|
if (!$user) {
|
|
http_response_code(401);
|
|
exit(json_encode(['error' => 'Unauthorized']));
|
|
}
|
|
|
|
$id = isset($_GET['id']) ? (int)$_GET['id'] : 0;
|
|
if (!$id) {
|
|
exit(json_encode(['error' => 'Invalid ID']));
|
|
}
|
|
|
|
$article = getLocalKnowledgeArticle($pdo, $id);
|
|
if (!$article) {
|
|
exit(json_encode(['error' => 'Article not found']));
|
|
}
|
|
|
|
$documents = [];
|
|
if ($article['documents']) {
|
|
$docs = json_decode($article['documents'], true);
|
|
if (is_array($docs)) {
|
|
foreach ($docs as $doc) {
|
|
$documents[] = [
|
|
'id' => $doc['id'],
|
|
'name' => $doc['name'],
|
|
'mime' => $doc['mime'],
|
|
'url' => 'get_document.php?kid=' . $id . '&doc=' . $doc['id']
|
|
];
|
|
}
|
|
}
|
|
}
|
|
|
|
echo json_encode([
|
|
'id' => $article['id'],
|
|
'title' => $article['title'],
|
|
'content' => $article['content'],
|
|
'documents' => $documents,
|
|
'date' => $article['updated_at'] ?? $article['created_at']
|
|
]);
|
|
exit; |