Files
awo-hamburg-intranet/module/knowledgecenter_update/Views/post_cardform_article.php

318 lines
16 KiB
PHP
Raw Normal View History

<?php
// if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['check_certificate_wiki'])) {
// $certId = (int) $_POST['check_certificate_wiki'];
// $userId = (int) $GLOBALS['main_contact']['id'];
// $currentDate = (new DateTime())->format('Y-m-d H:i:s');
// // prüfen, ob schon ein Eintrag existiert
// $sqlSubmit = "
// SELECT id
// FROM certificate_contact_submit
// WHERE certificate_id = {$certId}
// AND main_contact_id = {$userId}
// LIMIT 1
// ";
// $resSubmit = mysqli_query($GLOBALS['mysql_con'], $sqlSubmit);
// if ($row = mysqli_fetch_assoc($resSubmit)) {
// // UPDATE
// $sqlUp = "
// UPDATE certificate_contact_submit
// SET correct = 1,
// issue_date = '{$currentDate}'
// WHERE id = " . (int) $row['id'];
// mysqli_query($GLOBALS['mysql_con'], $sqlUp);
// } else {
// // INSERT
// $sqlIn = "
// INSERT INTO certificate_contact_submit
// (certificate_id, main_contact_id, issue_date, correct)
// VALUES
// ({$certId}, {$userId}, '{$currentDate}', 1)
// ";
// mysqli_query($GLOBALS['mysql_con'], $sqlIn);
// }
// echo "<script>
// // ersetzt die aktuelle Seite durch einen sauberen GET auf dieselbe URL
// window.location.replace(window.location.href);
// </script>";
// exit;
// }
// // fetch_and_process_emails();
// $certificate_type = $sitepart['learning_certificate_type'];
// $certificate_items = $sitepart['sitepart_items'];
// if (isset($_GET['contact'])) {
// return;
// }
// $query = "
// SELECT *
// FROM main_certificate
// LEFT JOIN certificate_contact
// ON certificate_contact.certificate_id = main_certificate.id
// WHERE main_contact_id = " . (int) $GLOBALS['main_contact']['id'] . "
// AND main_certificate.state = 1
// AND (main_certificate.validity_from <= NOW() OR main_certificate.validity_from IS NULL)
// AND active = 1
// ";
// $result = @mysqli_query($GLOBALS['mysql_con'], $query);
// $completedCertificates = [];
// $incompleteCertificates = [];
// while ($row = @mysqli_fetch_assoc($result)) {
// // statt $row['certificate_id'] immer main_certificate.id verwenden
// $certId = (int) $row['id'];
// $query_submit = "
// SELECT *
// FROM certificate_contact_submit
// WHERE certificate_id = {$certId}
// AND main_contact_id = " . (int) $GLOBALS['main_contact']['id'] . "
// ORDER BY id DESC
// LIMIT 1
// ";
// $result_submit = @mysqli_query($GLOBALS['mysql_con'], $query_submit);
// $row_submit = @mysqli_fetch_assoc($result_submit);
// $current_date = new DateTime();
// $issue_date = new DateTime($row_submit['issue_date'] ?? 'now');
// $validity_date = clone $issue_date;
// $validity_date->modify('+' . (int) $row['validity_period'] . ' months');
// if (($row_submit['correct'] ?? 0) == 1 && $validity_date >= $current_date) {
// $completedCertificates[] = [
// 'row' => $row,
// 'row_submit' => $row_submit,
// 'issue_date' => $issue_date,
// 'validity_date' => $validity_date
// ];
// } else {
// $incompleteCertificates[] = [
// 'row' => $row,
// 'row_submit' => $row_submit,
// 'issue_date' => $issue_date,
// 'validity_date' => $validity_date
// ];
// }
// }
// $siteParam = isset($_GET['site']) ? trim($_GET['site']) : '';
// $langCode = $GLOBALS['language']['code'] ?? '';
// function buildCertificateLink(array $row, string $siteParam, string $langCode): string
// {
// if (!empty($row['main_collection_id'])) {
// return get_link_to_navigation($row['main_collection_page_list_id'])
// . get_collection_rewrite("-", $row['main_collection_id']);
// }
// if (!empty($row['post_id'])) {
// return "/{$siteParam}/{$langCode}/wiki?action=Post&id=" . (int) $row['post_id'];
// }
// return "javascript:void(0)";
// }
?>
<div class="post-title">
<?php if ($isNew): ?>
<h1 id="displayTitle"><?= $translation->get("create_article") ?></h1>
<?php else: ?>
<h1 id="displayTitle"><?php echo htmlspecialchars($currentVersion['title']); ?></h1>
<?php endif; ?>
<div>
<?php if (!empty($postId) && $postId > 0 && ($canEditPost ?? false)): ?>
<span id="editBtn" class="post-action-btn grey" title="Aktuelle Version bearbeiten"></span>
<span id="createBtn" class="green" title="Neue Version erstellen">Neue Version erstellen +</span>
<?php endif; ?>
</div>
</div>
<div class="post-grid-container">
<div class="post-left-container">
<?php if (!empty($currentVersion['teaser'])): ?>
<div class="post-teaser" id="displayTeaser">
<p><?php echo nl2br(htmlspecialchars($currentVersion['teaser'])); ?></p>
</div>
<?php endif; ?>
<?php
if (!empty($post['preview_inline']) && $post['preview_inline'] == 1) {
$pdfQuery = "
SELECT *
FROM knowledgecenter_post_files
WHERE post_id = " . intval($postId) . "
AND LOWER(path) LIKE '%.pdf%'
LIMIT 1
";
$pdfResult = mysqli_query($GLOBALS['mysql_con'], $pdfQuery);
if ($pdfResult && mysqli_num_rows($pdfResult) > 0) {
$pdfFile = mysqli_fetch_assoc($pdfResult);
$pdfPath = htmlspecialchars($pdfFile['path']);
?>
<div class="post-preview-embed">
<object data="<?php echo $pdfPath; ?>" type="application/pdf" width="100%" height="1000px">
Ihr Browser unterstützt die Anzeige von PDFs nicht.
<a href="<?php echo $pdfPath; ?>">PDF herunterladen</a>
</object>
</div>
<?php
}
}
?>
<div class="post-content" id="displayContent">
<?php echo $currentVersion['content']; ?>
</div>
</div><!-- /.post-left-container -->
<div class="post-right-container">
<?php if (!empty($postId) && $postId > 0): ?>
<?php if (!empty($currentVersion['image'])): ?>
<?php
$imgSrc = '/userdata/' . htmlspecialchars($currentVersion['image']);
?>
<div class="post-aside-section">
<a data-fslightbox="gallery" href="<?= $imgSrc ?>">
<img id="displayImage" src="<?= $imgSrc ?>" alt="Beitragsbild">
</a>
</div>
<?php endif; ?>
<?php
$linkRaw = trim((string) ($currentVersion['link'] ?? ''));
$linkLabelRaw = trim((string) ($currentVersion['link_label'] ?? ''));
if ($linkRaw !== '') {
// Fallback Label: wenn kein Label angegeben, URL als Label nutzen
$label = $linkLabelRaw !== '' ? $linkLabelRaw : $linkRaw;
// Falls es eine rohe Domain ohne Schema ist, https:// voranstellen
$hrefForCheck = $linkRaw;
if (!preg_match('~^(?:https?:)?//|mailto:|/|#~i', $hrefForCheck)) {
$hrefForCheck = 'https://' . $hrefForCheck;
}
$safeUrl = htmlspecialchars($hrefForCheck, ENT_QUOTES, 'UTF-8');
$safeLabel = htmlspecialchars($label, ENT_QUOTES, 'UTF-8');
?>
<div class="post-aside-section">
<h3><?= $translation->get("Link") ?></h3>
<div class="post-link">
<a href="<?= $safeUrl ?>" target="_blank" rel="noopener noreferrer"><?= $safeLabel ?></a>
</div>
</div>
<?php } ?>
<?php if (!empty($currentVersion['summary'])): ?>
<div class="post-aside-section post-summary-section">
<h3>Zusammenfassung</h3>
<div class="post-summary">
<p><?= nl2br(htmlspecialchars($currentVersion['summary'])) ?></p>
</div>
</div>
<?php endif; ?>
<div id="filesContainer"></div>
<div id="contactsContainer"></div>
<div class="post-aside-section">
<h3><?= $translation->get("last_change_on") ?></h3>
<div class="post-meta">
<?php
$timestamp = strtotime($currentVersion['modified_at']);
$fmt = new IntlDateFormatter('de_DE', IntlDateFormatter::LONG, IntlDateFormatter::SHORT);
$formattedDate = $fmt->format($timestamp);
?>
<div class="post-meta-item">
<?= htmlspecialchars($formattedDate) ?> - <?= htmlspecialchars($currentVersion['author']) ?>
</div>
</div>
</div>
<?php endif; ?>
</div><!-- /.post-right-container -->
</div><!-- /.post-grid-container -->
<script>
$(document).ready(function () {
// ---- Kontakte laden ----
$.post("/module/knowledgecenter_update/Ajax/Ajax.php", {
action: "get_contact_cards",
post_id: <?= $postId ?>
}, "json")
.done(function (response) {
if (response.success && $.trim(response.html).length > 0) {
var html = "<div class='post-aside-section'><h3><?= $translation->get("Ansprechpartner") ?></h3>";
html += "<div id='contacts-content'>" + response.html + "</div></div>";
$("#contactsContainer").html(html);
} else {
$("#contactsContainer").empty();
}
})
.fail(function () {
$("#contactsContainer").html("<p>Ein Fehler ist aufgetreten.</p>");
});
// ---- Datei-Icons definieren ----
var fileIcons = {
pdf: '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="red" class="bi bi-file-earmark-pdf" viewBox="0 0 16 16"> <path d="M14 14V4.5L9.5 0H4a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h8a2 2 0 0 0 2-2M9.5 3A1.5 1.5 0 0 0 11 4.5h2V14a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1h5.5z"/> <path d="M4.603 14.087a.8.8 0 0 1-.438-.42c-.195-.388-.13-.776.08-1.102.198-.307.526-.568.897-.787a7.7 7.7 0 0 1 1.482-.645 20 20 0 0 0 1.062-2.227 7.3 7.3 0 0 1-.43-1.295c-.086-.4-.119-.796-.046-1.136.075-.354.274-.672.65-.823.192-.077.4-.12.602-.077a.7.7 0 0 1 .477.365c.088.164.12.356.127.538.007.188-.012.396-.047.614-.084.51-.27 1.134-.52 1.794a11 11 0 0 0 .98 1.686 5.8 5.8 0 0 1 1.334.05c.364.066.734.195.96.465.12.144.193.32.2.518.007.192-.047.382-.138.563a1.04 1.04 0 0 1-.354.416.86.86 0 0 1-.51.138c-.331-.014-.654-.196-.933-.417a5.7 5.7 0 0 1-.911-.95 11.7 11.7 0 0 0-1.997.406 11.3 11.3 0 0 1-1.02 1.51c-.292.35-.609.656-.927.787a.8.8 0 0 1-.58.029m1.379-1.901q-.25.115-.459.238c-.328.194-.541.383-.647.547-.094.145-.096.25-.04.361q.016.032.026.044l.035-.012c.137-.056.355-.235.635-.572a8 8 0 0 0 .45-.606m1.64-1.33a13 13 0 0 1 1.01-.193 12 12 0 0 1-.51-.858 21 21 0 0 1-.5 1.05zm2.446.45q.226.245.435.41c.24.19.407.253.498.256a.1.1 0 0 0 .07-.015.3.3 0 0 0 .094-.125.44.44 0 0 0 .059-.2.1.1 0 0 0-.026-.063c-.052-.062-.2-.152-.518-.209a4 4 0 0 0-.612-.053zM8.078 7.8a7 7 0 0 0 .2-.828q.046-.282.038-.465a.6.6 0 0 0-.032-.198.5.5 0 0 0-.145.04c-.087.035-.158.106-.196.283-.04.192-.03.469.046.822q.036.167.09.346z"/> </svg>',
image: '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="green" class="bi bi-file-earmark-image" viewBox="0 0 16 16"> <path d="M6.502 7a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3"/> <path d="M14 14a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V2a2 2 0 0 1 2-2h5.5L14 4.5zM4 1a1 1 0 0 0-1 1v10l2.224-2.224a.5.5 0 0 1 .61-.075L8 11l2.157-3.02a.5.5 0 0 1 .76-.063L13 10V4.5h-2A1.5 1.5 0 0 1 9.5 3V1z"/> </svg>',
doc: '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="blue" class="bi bi-file-earmark-word" viewBox="0 0 16 16"> <path d="M5.485 6.879a.5.5 0 1 0-.97.242l1.5 6a.5.5 0 0 0 .967.01L8 9.402l1.018 3.73a.5.5 0 0 0 .967-.01l1.5-6a.5.5 0 0 0-.97-.242l-1.036 4.144-.997-3.655a.5.5 0 0 0-.964 0l-.997 3.655L5.485 6.88z"/> <path d="M14 14V4.5L9.5 0H4a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h8a2 2 0 0 0 2-2M9.5 3A1.5 1.5 0 0 0 11 4.5h2V14a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1h5.5z"/> </svg>',
default: '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-file-earmark-text" viewBox="0 0 16 16"> <path d="M5.5 7a.5.5 0 0 0 0 1h5a.5.5 0 0 0 0-1zM5 9.5a.5.5 0 0 1 .5-.5h5a.5.5 0 0 1 0 1h-5a.5.5 0 0 1-.5-.5m0 2a.5.5 0 0 1 .5-.5h2a.5.5 0 0 1 0 1h-2a.5.5 0 0 1-.5-.5"/> <path d="M9.5 0H4a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h8a2 2 0 0 0 2-2V4.5zm0 1v2A1.5 1.5 0 0 0 11 4.5h2V14a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1z"/> </svg>'
};
// ---- Dateien laden ----
$.ajax({
type: "POST",
url: "/module/knowledgecenter_update/Ajax/Ajax.php",
data: {
action: "get_post_files",
post_id: <?= $postId ?>
},
dataType: "json",
success: function (response) {
if (response.success && response.files && response.files.length > 0) {
var html = "<div class='post-aside-section'><h3><?= $translation->get("files") ?></h3><div id='article-files-content'>";
var imageExts = ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp', 'svg'];
var pdfExts = ['pdf'];
var docExts = ['doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx'];
response.files.forEach(function (file, i) {
var ext = file.path.split('.').pop().toLowerCase();
if (!ext && file.description.indexOf('.') !== -1) {
ext = file.description.split('.').pop().toLowerCase();
}
var icon = fileIcons.default;
if (pdfExts.indexOf(ext) !== -1) icon = fileIcons.pdf;
else if (imageExts.indexOf(ext) !== -1) icon = fileIcons.image;
else if (docExts.indexOf(ext) !== -1) icon = fileIcons.doc;
html += "<div class='fileItem'>" + icon + " ";
if (pdfExts.indexOf(ext) !== -1) {
var embedId = "sidebar_pdf_" + i;
html += "<a href='#" + embedId + "' data-fslightbox='sidebar_gallery' data-type='inline'>" + file.description + "</a>";
html += "<object id='" + embedId + "' data='" + file.path + "' type='application/pdf' width='100%' height='900px'></object>";
} else if (imageExts.indexOf(ext) !== -1) {
html += "<a href='" + file.path + "' data-fslightbox='sidebar_gallery'>" + file.description + "</a>";
} else {
html += "<a href='" + file.path + "' download>" + file.description + "</a>";
}
html += "</div><hr>";
});
html += "</div></div>";
$("#filesContainer").html(html);
refreshFsLightbox();
} else {
$("#filesContainer").empty();
}
},
error: function () {
$("#filesContainer").html("<p>Ein Fehler ist aufgetreten.</p>");
}
});
});
</script>