- Create knowledgecenter_category_einricht, _fachbereich, knowledgecenter_post_einricht, knowledgecenter_post_fachbereich tables; extend task_target_rule with main_einricht_id and main_bereich_id columns - Middleware: load main_einricht_id/main_bereich_id from main_contact_department, expose $allowedEinrichts/$allowedFachbereiche globals (same pattern as existing 3 types) - Ajax: add update_category/post_einrichts/fachbereiche functions, extend update_category_links() and search filter query - Views: add einricht/fachbereich LEFT JOINs and WHERE filters in all 5 query sites (categories_posts_listform, category_posts_widget, post_announcement_listform, post_cardform userHasAccessForPost, Ajax search) - post_cardform_settings: add Einrichtungen/Fachbereiche tagify pickers with save/load - Tasks: add listEinrichts/listFachbereiche to repo+service, add UI selects in task_form, extend target-rule normalization and upsert builder, extend AssignmentResolverService scope loading and matchesAnyRule to include einricht/fachbereich matching Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
63 lines
2.5 KiB
PHP
63 lines
2.5 KiB
PHP
<?php
|
||
|
||
/**
|
||
* Zunächst: Holen der User-Daten (Mandanten, Abteilungen, Rollen, Einrichtungen, Fachbereiche)
|
||
*/
|
||
$currentUserId = $GLOBALS["main_contact"]["id"] ?? 0;
|
||
$userMandants = [];
|
||
$userDepartments = [];
|
||
$userRoles = [];
|
||
$userEinrichts = [];
|
||
$userFachbereiche = [];
|
||
|
||
if ($currentUserId) {
|
||
$query = "SELECT main_mandant_id, main_department_id, main_role_id, main_einricht_id, main_bereich_id
|
||
FROM main_contact_department
|
||
WHERE main_contact_id = $currentUserId AND active = 1";
|
||
$result = mysqli_query($GLOBALS['mysql_con'], $query);
|
||
while ($row = mysqli_fetch_assoc($result)) {
|
||
// Filtere 0 aus – 0 gilt als "keine Zuordnung"
|
||
if ($row['main_mandant_id'] != 0 && !in_array($row['main_mandant_id'], $userMandants)) {
|
||
$userMandants[] = $row['main_mandant_id'];
|
||
}
|
||
if ($row['main_department_id'] != 0 && !in_array($row['main_department_id'], $userDepartments)) {
|
||
$userDepartments[] = $row['main_department_id'];
|
||
}
|
||
if ($row['main_role_id'] != 0 && !in_array($row['main_role_id'], $userRoles)) {
|
||
$userRoles[] = $row['main_role_id'];
|
||
}
|
||
if ($row['main_einricht_id'] != 0 && !in_array($row['main_einricht_id'], $userEinrichts)) {
|
||
$userEinrichts[] = $row['main_einricht_id'];
|
||
}
|
||
if ($row['main_bereich_id'] != 0 && !in_array($row['main_bereich_id'], $userFachbereiche)) {
|
||
$userFachbereiche[] = $row['main_bereich_id'];
|
||
}
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Für den LEFT JOIN-Ansatz bereiten wir die erlaubten Werte als
|
||
* kommaseparierte Strings vor.
|
||
*/
|
||
$allowedMandants = !empty($userMandants) ? implode(',', $userMandants) : 'NULL';
|
||
$allowedDepartments = !empty($userDepartments) ? implode(',', $userDepartments) : 'NULL';
|
||
$allowedRoles = !empty($userRoles) ? implode(',', $userRoles) : 'NULL';
|
||
$allowedEinrichts = !empty($userEinrichts) ? implode(',', $userEinrichts) : 'NULL';
|
||
$allowedFachbereiche = !empty($userFachbereiche) ? implode(',', $userFachbereiche) : 'NULL';
|
||
|
||
// Für den globalen Zugriff kannst Du auch die Variablen in $GLOBALS speichern:
|
||
$GLOBALS['allowedMandants'] = $allowedMandants;
|
||
$GLOBALS['allowedDepartments'] = $allowedDepartments;
|
||
$GLOBALS['allowedRoles'] = $allowedRoles;
|
||
$GLOBALS['allowedEinrichts'] = $allowedEinrichts;
|
||
$GLOBALS['allowedFachbereiche'] = $allowedFachbereiche;
|
||
|
||
|
||
|
||
|
||
// echo "<pre>";
|
||
// echo "Mandanten: " . $allowedMandants . "\n";
|
||
// echo "Abteilungen: " . $allowedDepartments . "\n";
|
||
// echo "Rollen: " . $allowedRoles . "\n";
|
||
// echo "</pre>";
|