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

508 lines
21 KiB
PHP
Raw Normal View History

<?php
// post_cardform_settings.php
// Sicherstellen, dass $postId gesetzt ist andernfalls neuen Beitrag (0) annehmen
if (!isset($postId)) {
$postId = 0;
}
// Falls $languageId noch nicht definiert ist, Standard (z.B. 1) verwenden
if (!isset($languageId)) {
$languageId = 1;
}
// Load current linked form for this post (if any)
$currentFormId = 0;
$res = mysqli_query($GLOBALS['mysql_con'], "
SELECT form_id
FROM knowledgecenter_post_form
WHERE post_id = $postId
LIMIT 1
");
if ($row = mysqli_fetch_assoc($res)) {
$currentFormId = (int)$row['form_id'];
}
// Build <option> list from contactform_header with 'selected' on current form
$formOptions = "";
$query = "SELECT id, description FROM contactform_header ORDER BY id ASC";
$result = mysqli_query($GLOBALS['mysql_con'], $query);
while ($row = mysqli_fetch_assoc($result)) {
// Mark the currently linked form as selected
$selected = ($row['id'] == $currentFormId) ? 'selected' : '';
$formOptions .= "<option value='" . $row['id'] . "' $selected>"
. htmlspecialchars($row['description']) . "</option>";
}
// -------------------- Kategorien --------------------
// Erzeuge die Whitelist für alle verfügbaren Kategorien (mit Übersetzung)
$categoriesData = [];
$query = "SELECT c.id, t.title, c.enable_post_color_pickers
FROM knowledgecenter_categories_update AS c
LEFT JOIN knowledgecenter_category_translations AS t
ON c.id = t.category_id
WHERE t.language_id = $languageId";
$result = mysqli_query($GLOBALS['mysql_con'], $query);
while ($row = mysqli_fetch_assoc($result)) {
// Hier wird der in der Übersetzungstabelle gespeicherte Titel als 'name' verwendet.
$categoriesData[] = [
'value' => $row['id'],
'name' => $row['title'],
'enable_post_color_pickers' => (int) ($row['enable_post_color_pickers'] ?? 0)
];
}
// Bereits zugeordnete Kategorien abrufen (falls vorhanden)
$selectedCategories = [];
if ($postId != 0) {
$querySelected = "SELECT c.id, t.title
FROM knowledgecenter_category_post AS pc
JOIN knowledgecenter_categories_update AS c ON pc.category_id = c.id
LEFT JOIN knowledgecenter_category_translations AS t
ON c.id = t.category_id
WHERE pc.post_id = $postId AND t.language_id = $languageId";
$resultSelected = mysqli_query($GLOBALS['mysql_con'], $querySelected);
while ($row = mysqli_fetch_assoc($resultSelected)) {
$selectedCategories[] = ['value' => $row['id'], 'name' => $row['title']];
}
}
// -------------------- Mandanten für Post --------------------
$postMandantsData = [];
$query = "SELECT id, description FROM main_mandant";
$result = mysqli_query($GLOBALS['mysql_con'], $query);
while ($row = mysqli_fetch_assoc($result)) {
// Hier verwenden wir 'name' als Anzeige-Text, der die description enthält.
$postMandantsData[] = ['value' => $row['id'], 'name' => $row['description']];
}
$selectedPostMandants = [];
if ($postId != 0) {
$querySelected = "SELECT m.id, m.description
FROM knowledgecenter_post_mandant AS pm
JOIN main_mandant AS m ON pm.mandant_id = m.id
WHERE pm.post_id = $postId";
$resultSelected = mysqli_query($GLOBALS['mysql_con'], $querySelected);
while ($row = mysqli_fetch_assoc($resultSelected)) {
$selectedPostMandants[] = ['value' => $row['id'], 'name' => $row['description']];
}
}
// -------------------- Departments für Post --------------------
$postDepartmentsData = [];
$query = "SELECT id, description FROM main_department";
$result = mysqli_query($GLOBALS['mysql_con'], $query);
while ($row = mysqli_fetch_assoc($result)) {
$postDepartmentsData[] = ['value' => $row['id'], 'name' => $row['description']];
}
$selectedPostDepartments = [];
if ($postId != 0) {
$querySelected = "SELECT d.id, d.description
FROM knowledgecenter_post_department AS pd
JOIN main_department AS d ON pd.department_id = d.id
WHERE pd.post_id = $postId";
$resultSelected = mysqli_query($GLOBALS['mysql_con'], $querySelected);
while ($row = mysqli_fetch_assoc($resultSelected)) {
$selectedPostDepartments[] = ['value' => $row['id'], 'name' => $row['description']];
}
}
// -------------------- Rollen für Post --------------------
$postRolesData = [];
$query = "SELECT id, description FROM main_role";
$result = mysqli_query($GLOBALS['mysql_con'], $query);
while ($row = mysqli_fetch_assoc($result)) {
$postRolesData[] = ['value' => $row['id'], 'name' => $row['description']];
}
$selectedPostRoles = [];
if ($postId != 0) {
$querySelected = "SELECT r.id, r.description
FROM knowledgecenter_post_role AS pr
JOIN main_role AS r ON pr.role_id = r.id
WHERE pr.post_id = $postId";
$resultSelected = mysqli_query($GLOBALS['mysql_con'], $querySelected);
while ($row = mysqli_fetch_assoc($resultSelected)) {
$selectedPostRoles[] = ['value' => $row['id'], 'name' => $row['description']];
}
}
// -------------------- Produkte für Post --------------------
$productsData = [];
$query = "SELECT p.id, pt.title
FROM product AS p
JOIN product_translation AS pt
ON p.id = pt.product_id
WHERE pt.language_id = $languageId";
$result = mysqli_query($GLOBALS['mysql_con'], $query);
while ($row = mysqli_fetch_assoc($result)) {
$productsData[] = ['value' => $row['id'], 'name' => $row['title']];
}
$selectedProducts = [];
if ($postId != 0) {
$querySelected = "SELECT p.id, pt.title
FROM product_knowledgecenter_post_link AS pl
JOIN product AS p ON pl.product_id = p.id
JOIN product_translation AS pt
ON p.id = pt.product_id
WHERE pl.post_id = $postId
AND pt.language_id = $languageId";
$resultSelected = mysqli_query($GLOBALS['mysql_con'], $querySelected);
while ($row = mysqli_fetch_assoc($resultSelected)) {
$selectedProducts[] = ['value' => $row['id'], 'name' => $row['title']];
}
}
$postBackgroundColor = '#FFFFFF';
if (!empty($post['background_color'])) {
$postBackgroundColor = $post['background_color'];
} elseif (!empty($currentVersion['background_color'])) {
$postBackgroundColor = $currentVersion['background_color'];
}
$postTextColor = '#000000';
if (!empty($post['text_color'])) {
$postTextColor = $post['text_color'];
} elseif (!empty($currentVersion['text_color'])) {
$postTextColor = $currentVersion['text_color'];
}
?>
<button id="message" style="opacity:0; position: absolute;"></button>
<div class="titlebar_small">
<h2><?=$translation->get("settings")?></h2>
<?php if (get_permission_state('r-wiki', $GLOBALS['main_contact']['master_mandant_id'], $GLOBALS['main_contact']['id']) == 1) { ?>
<span id="saveAllBtn" class="post-action-btn-small green"><?= $saveIcon ?></span>
<?php } ?>
</div>
<hr>
<div class="settings">
<form id="postSettingsForm">
<input type="hidden" id="post_id" name="post_id" value="<?php echo $postId; ?>" />
<h3><?=$translation->get("categories")?>
</h3>
<div class="settings_container">
<input type="text" id="categoryTags" name="categories" placeholder="Kategorie hinzufügen…" />
</div>
<div id="postColorPickersSection" class="post-color-grid" style="display:none;">
<div class="post-color-item">
<label for="postBackgroundColor"><?= $translation->get("post_background_color") ?></label>
<input type="color" id="postBackgroundColor" name="background_color"
value="<?= htmlspecialchars($postBackgroundColor, ENT_QUOTES, 'UTF-8') ?>">
</div>
<div class="post-color-item">
<label for="postTextColor"><?= $translation->get("post_text_color") ?></label>
<input type="color" id="postTextColor" name="text_color"
value="<?= htmlspecialchars($postTextColor, ENT_QUOTES, 'UTF-8') ?>">
</div>
</div>
<h3><?=$translation->get("Geschäftsstellen")?>
</h3>
<div class="settings_container">
<input type="text" id="postMandantTags" name="postMandants" placeholder="<?=$translation->get("Geschäftsstellen")?>…" />
</div>
<h3><?=$translation->get("departments")?>
</h3>
<div class="settings_container">
<input type="text" id="postDepartmentTags" name="postDepartments" placeholder="<?=$translation->get("departments")?>…" />
</div>
<h3><?=$translation->get("roles")?>
</h3>
<div class="settings_container">
<input type="text" id="postRoleTags" name="postRoles" placeholder="<?=$translation->get("roles")?>…" />
</div>
<h3><?=$translation->get("products")?></h3>
<div class="settings_container">
<input type="text" id="postProductTags" name="postProducts" placeholder="<?=$translation->get("products")?>…" />
</div>
<h3>Formular auswählen</h3>
<div class="settings_container">
<select name="postFormSelect" id="postFormSelect">
<option value="">Bitte wählen…</option>
<?php echo $formOptions; ?>
</select>
</div>
<hgroup>
<h3><?=$translation->get("pdf_inline_preview")?></h3>
<small><?=$translation->get("pdf_inline_preview_explanation")?></small>
</hgroup>
<div class="settings_container">
<label>
<input type="checkbox" id="pdfInlineCheckbox" name="pdf_inline" value="1"
<?php echo (!empty($post['preview_inline']) && $post['preview_inline'] == 1) ? 'checked' : ''; ?>>
<?=$translation->get("pdf_inline_preview_label")?>
</label>
</div>
<h3><?=$translation->get("delete_post")?></h3>
<div class="settings_container">
<div id="deletePostBtn" class="post-action-btn-text red">
<?=$translation->get("delete_post")?>
</div>
</div>
</form>
</div>
<script>
// Übergabe der Whitelist-Daten aus PHP
var categoriesData = <?php echo json_encode($categoriesData); ?>;
var postMandantsData = <?php echo json_encode($postMandantsData); ?>;
var postDepartmentsData = <?php echo json_encode($postDepartmentsData); ?>;
var postRolesData = <?php echo json_encode($postRolesData); ?>;
var selectedCategories = <?php echo json_encode($selectedCategories); ?>;
var selectedPostMandants = <?php echo json_encode($selectedPostMandants); ?>;
var selectedPostDepartments = <?php echo json_encode($selectedPostDepartments); ?>;
var selectedPostRoles = <?php echo json_encode($selectedPostRoles); ?>;
var productsData = <?php echo json_encode($productsData); ?>;
var selectedProducts = <?php echo json_encode($selectedProducts); ?>;
var categoryEnableColorMap = {};
categoriesData.forEach(function (cat) {
categoryEnableColorMap[String(cat.value)] = parseInt(cat.enable_post_color_pickers || 0, 10) === 1;
});
function updatePostColorPickerVisibility() {
var selectedValues = tagifyCategories.value.map(function (tag) {
return String(tag.value);
});
var hasEnabledCategory = selectedValues.some(function (catId) {
return categoryEnableColorMap[catId] === true;
});
if (hasEnabledCategory) {
$("#postColorPickersSection").css("display", "grid");
} else {
$("#postColorPickersSection").hide();
}
}
// Kategorien
var tagifyCategories = new Tagify(document.getElementById('categoryTags'), {
whitelist: categoriesData,
tagTextProp: 'name',
enforceWhitelist: true,
dropdown: {
enabled: 0,
maxItems: Infinity,
searchKeys: ["name"]
},
templates: {
dropdownItem: function (tagData) {
return `<div ${this.getAttributes(tagData)} class="tagify__dropdown__item">
<span>${tagData.name}</span>
</div>`;
}
}
});
if (selectedCategories.length) {
tagifyCategories.addTags(selectedCategories);
}
tagifyCategories.on('add', updatePostColorPickerVisibility);
tagifyCategories.on('remove', updatePostColorPickerVisibility);
updatePostColorPickerVisibility();
// Mandanten für Post
var tagifyPostMandants = new Tagify(document.getElementById('postMandantTags'), {
whitelist: postMandantsData,
tagTextProp: 'name',
enforceWhitelist: true,
dropdown: { enabled: 0, maxItems: Infinity, searchKeys: ["name"] },
templates: {
dropdownItem: function (tagData) {
return `<div ${this.getAttributes(tagData)} class="tagify__dropdown__item">
<span>${tagData.name}</span>
</div>`;
}
}
});
if (selectedPostMandants.length) {
tagifyPostMandants.addTags(selectedPostMandants);
}
// Departments für Post
var tagifyPostDepartments = new Tagify(document.getElementById('postDepartmentTags'), {
whitelist: postDepartmentsData,
tagTextProp: 'name',
enforceWhitelist: true,
dropdown: { enabled: 0, maxItems: Infinity, searchKeys: ["name"] },
templates: {
dropdownItem: function (tagData) {
return `<div ${this.getAttributes(tagData)} class="tagify__dropdown__item">
<span>${tagData.name}</span>
</div>`;
}
}
});
if (selectedPostDepartments.length) {
tagifyPostDepartments.addTags(selectedPostDepartments);
}
// Rollen für Post
var tagifyPostRoles = new Tagify(document.getElementById('postRoleTags'), {
whitelist: postRolesData,
tagTextProp: 'name',
enforceWhitelist: true,
dropdown: { enabled: 0, maxItems: Infinity, searchKeys: ["name"] },
templates: {
dropdownItem: function (tagData) {
return `<div ${this.getAttributes(tagData)} class="tagify__dropdown__item">
<span>${tagData.name}</span>
</div>`;
}
}
});
if (selectedPostRoles.length) {
tagifyPostRoles.addTags(selectedPostRoles);
}
// Produkte für Post
var tagifyPostProducts = new Tagify(document.getElementById('postProductTags'), {
whitelist: productsData,
tagTextProp: 'name',
enforceWhitelist: true,
dropdown: { enabled: 0, maxItems: Infinity, searchKeys: ["name"] },
templates: {
dropdownItem: function (tagData) {
return `<div ${this.getAttributes(tagData)} class="tagify__dropdown__item">
<span>${tagData.name}</span>
</div>`;
}
}
});
if (selectedProducts.length) {
tagifyPostProducts.addTags(selectedProducts);
}
<?php if (get_permission_state('r-wiki', $GLOBALS['main_contact']['master_mandant_id'], $GLOBALS['main_contact']['id']) == 1) { ?>
$("#saveAllBtn").on("click", function () {
// Während des Speicherns blurren
$("#tab-settings").addClass("blurred");
var postId = $("#post_id").val();
var pdfInline = $("#pdfInlineCheckbox").prop("checked") ? 1 : 0;
var selectedCat = tagifyCategories.value.map(tag => tag.value);
var selectedMandants = tagifyPostMandants.value.map(tag => tag.value);
var selectedDepartments = tagifyPostDepartments.value.map(tag => tag.value);
var selectedRoles = tagifyPostRoles.value.map(tag => tag.value);
var selectedFormId = $("#postFormSelect").val();
var postBackgroundColor = $("#postBackgroundColor").val();
var postTextColor = $("#postTextColor").val();
$.when(
$.post("/module/knowledgecenter_update/Ajax/Ajax.php", {
action: "update_post_categories",
post_id: postId,
categories: JSON.stringify(selectedCat)
}, "json"),
$.post("/module/knowledgecenter_update/Ajax/Ajax.php", {
action: "update_post_mandants",
post_id: postId,
mandants: JSON.stringify(selectedMandants)
}, "json"),
$.post("/module/knowledgecenter_update/Ajax/Ajax.php", {
action: "update_post_form",
post_id: postId,
form_id: selectedFormId
}, "json"),
$.post("/module/knowledgecenter_update/Ajax/Ajax.php", {
action: "update_post_departments",
post_id: postId,
departments: JSON.stringify(selectedDepartments)
}, "json"),
$.post("/module/knowledgecenter_update/Ajax/Ajax.php", {
action: "update_post_roles",
post_id: postId,
roles: JSON.stringify(selectedRoles)
}, "json"),
$.post("/module/knowledgecenter_update/Ajax/Ajax.php", {
action: "update_post_products",
post_id: postId,
products: JSON.stringify(tagifyPostProducts.value.map(tag => tag.value))
}, "json"),
$.post("/module/knowledgecenter_update/Ajax/Ajax.php", {
action: "update_post_pdf_inline",
post_id: postId,
pdf_inline: pdfInline
}, "json"),
$.post("/module/knowledgecenter_update/Ajax/Ajax.php", {
action: "update_post_colors",
post_id: postId,
background_color: postBackgroundColor,
text_color: postTextColor
}, "json")
).done(function (categoriesResponse, mandantsResponse, formResponse, departmentsResponse, rolesResponse, productsResponse, pdfInlineResponse, postColorsResponse) {
var catSuccess = categoriesResponse[0].success;
var mandantsSuccess = mandantsResponse[0].success;
var formSuccess = formResponse[0].success;
var departmentsSuccess = departmentsResponse[0].success;
var rolesSuccess = rolesResponse[0].success;
var productsSuccess = productsResponse[0].success;
var pdfInlineSuccess = pdfInlineResponse[0].success;
var postColorsSuccess = postColorsResponse[0].success;
if (catSuccess && mandantsSuccess && formSuccess && departmentsSuccess && rolesSuccess && productsSuccess && pdfInlineSuccess && postColorsSuccess) {
showMessage("Alle Daten erfolgreich gespeichert!", true);
} else {
var errorMsg = "Fehler beim Speichern:";
if (!catSuccess) errorMsg += " Kategorien";
if (!mandantsSuccess) errorMsg += " Mandanten";
if (!formSuccess) errorMsg += " Formular";
if (!departmentsSuccess) errorMsg += " Departments";
if (!rolesSuccess) errorMsg += " Rollen";
if (!productsSuccess) errorMsg += " Produkte";
if (!pdfInlineSuccess) errorMsg += " PDF Inline Vorschau";
if (!postColorsSuccess) errorMsg += " Farben";
showMessage(errorMsg, false);
}
}).fail(function () {
showMessage("Es ist ein Fehler beim Speichern aufgetreten!", false);
}).always(function () {
$("#tab-settings").removeClass("blurred");
});
});
<?php } ?>
// Post löschen
$("#deletePostBtn").on("click", function() {
if (!confirm("<?= addslashes($translation->get("delete_post_confirm")) ?>")) {
return;
}
// Ajax-Aufruf an Deinen neuen Case
$.post("/module/knowledgecenter_update/Ajax/Ajax.php", {
action: "delete_post",
post_id: <?=$postId?>
}, function(response) {
if (response.success) {
// Weiterleitung nach dem Löschen, z.B. zurück zur Übersicht
window.location.href = "?action=Category";
} else {
showMessage("Fehler beim Löschen: " + (response.error || "Unbekannter Fehler"), false);
}
}, "json").fail(function() {
showMessage("Serverfehler beim Löschen.", false);
});
});
</script>