Первоначальная версия проекта chinilich-1.0

This commit is contained in:
2026-05-10 16:49:04 +03:00
commit 9b598697c5
16 changed files with 2886 additions and 0 deletions
+51
View File
@@ -0,0 +1,51 @@
<?php
require_once __DIR__ . '/config.php';
require_once __DIR__ . '/glpi_api.php';
$user = checkAuth($pdo);
if (!$user) {
http_response_code(401);
exit;
}
$kid = isset($_GET['kid']) ? (int)$_GET['kid'] : 0;
$docId = isset($_GET['doc']) ? (int)$_GET['doc'] : 0;
if (!$kid || !$docId) {
http_response_code(400);
exit;
}
$article = getLocalKnowledgeArticle($pdo, $kid);
if (!$article) {
http_response_code(404);
exit;
}
$docs = json_decode($article['documents'], true);
$targetDoc = null;
foreach ($docs as $d) {
if ($d['id'] == $docId) {
$targetDoc = $d;
break;
}
}
if (!$targetDoc) {
http_response_code(403);
exit;
}
$glpi = new GlpiApi(GLPI_API_URL, GLPI_APP_TOKEN, GLPI_USERNAME, GLPI_PASSWORD);
$filePath = lazyLoadDocument($pdo, $kid, $docId, $targetDoc['name'], $targetDoc['mime'], $glpi);
if (!$filePath || !file_exists($filePath)) {
http_response_code(404);
exit;
}
$mime = mime_content_type($filePath);
header('Content-Type: ' . $mime);
header('Content-Length: ' . filesize($filePath));
header('Content-Disposition: inline; filename="' . $targetDoc['name'] . '"');
header('Cache-Control: public, max-age=86400');
readfile($filePath);
exit;