From 411a48d577c67bd44c1afde80929a58e96d2d875 Mon Sep 17 00:00:00 2001 From: data Date: Thu, 19 Feb 2026 08:02:34 +0100 Subject: [PATCH] Exclude GLOBAL system from customer tab display GLOBAL types (buildings) are now available in all system tabs via fetchAllBySystem(), but the GLOBAL system itself should not appear as a separate tab for customers. Co-Authored-By: Claude Opus 4.5 --- tabs/anlagen.php | 22 ++++++++++++++++------ tabs/contact_anlagen.php | 21 +++++++++++++++------ 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/tabs/anlagen.php b/tabs/anlagen.php index e26fdf6..ec73b5d 100755 --- a/tabs/anlagen.php +++ b/tabs/anlagen.php @@ -82,6 +82,7 @@ $sql = "SELECT ss.rowid, ss.fk_system, s.code, s.label, s.picto, s.color FROM ".MAIN_DB_PREFIX."kundenkarte_societe_system ss JOIN ".MAIN_DB_PREFIX."c_kundenkarte_anlage_system s ON s.rowid = ss.fk_system WHERE ss.fk_soc = ".((int) $id)." AND (ss.fk_contact IS NULL OR ss.fk_contact = 0) AND ss.active = 1 AND s.active = 1 + AND s.code != 'GLOBAL' ORDER BY s.position ASC"; $resql = $db->query($sql); if ($resql) { @@ -156,10 +157,14 @@ if ($action == 'add' && $permissiontoadd) { $anlage->note_private = isset($_POST['note_private']) ? $_POST['note_private'] : ''; $anlage->status = 1; - // Get type for system ID + // Get type - but keep current system for GLOBAL types (buildings) $type = new AnlageType($db); if ($type->fetch($anlage->fk_anlage_type) > 0) { - $anlage->fk_system = $type->fk_system; + // Only change system if type is NOT a global type + // Global types (buildings) should stay in the current system + if ($type->system_code !== 'GLOBAL') { + $anlage->fk_system = $type->fk_system; + } } // All fields come from dynamic fields now @@ -177,7 +182,7 @@ if ($action == 'add' && $permissiontoadd) { $result = $anlage->create($user); if ($result > 0) { setEventMessages($langs->trans('RecordSaved'), null, 'mesgs'); - header('Location: '.$_SERVER['PHP_SELF'].'?id='.$id.'&system='.$anlage->fk_system); + header('Location: '.$_SERVER['PHP_SELF'].'?id='.$id.'&system='.$systemId); exit; } else { setEventMessages($anlage->error, $anlage->errors, 'errors'); @@ -187,15 +192,20 @@ if ($action == 'add' && $permissiontoadd) { if ($action == 'update' && $permissiontoadd) { $anlage->fetch($anlageId); + $systemIdBefore = $anlage->fk_system; // Remember original system $anlage->label = GETPOST('label', 'alphanohtml'); $anlage->fk_anlage_type = GETPOSTINT('fk_anlage_type'); $anlage->fk_parent = GETPOSTINT('fk_parent'); $anlage->note_private = isset($_POST['note_private']) ? $_POST['note_private'] : ''; - // Get type for system ID + // Get type - but keep current system for GLOBAL types (buildings) $type = new AnlageType($db); if ($type->fetch($anlage->fk_anlage_type) > 0) { - $anlage->fk_system = $type->fk_system; + // Only change system if type is NOT a global type + // Global types (buildings) should stay in their current system + if ($type->system_code !== 'GLOBAL') { + $anlage->fk_system = $type->fk_system; + } } // All fields come from dynamic fields now @@ -213,7 +223,7 @@ if ($action == 'update' && $permissiontoadd) { $result = $anlage->update($user); if ($result > 0) { setEventMessages($langs->trans('RecordSaved'), null, 'mesgs'); - header('Location: '.$_SERVER['PHP_SELF'].'?id='.$id.'&system='.$anlage->fk_system); + header('Location: '.$_SERVER['PHP_SELF'].'?id='.$id.'&system='.$systemId); exit; } else { setEventMessages($anlage->error, $anlage->errors, 'errors'); diff --git a/tabs/contact_anlagen.php b/tabs/contact_anlagen.php index 73d75ca..8f825f1 100755 --- a/tabs/contact_anlagen.php +++ b/tabs/contact_anlagen.php @@ -79,6 +79,7 @@ $sql = "SELECT ss.rowid, ss.fk_system, s.code, s.label, s.picto, s.color FROM ".MAIN_DB_PREFIX."kundenkarte_societe_system ss JOIN ".MAIN_DB_PREFIX."c_kundenkarte_anlage_system s ON s.rowid = ss.fk_system WHERE ss.fk_soc = ".((int) $object->socid)." AND ss.fk_contact = ".((int) $id)." AND ss.active = 1 AND s.active = 1 + AND s.code != 'GLOBAL' ORDER BY s.position ASC"; $resql = $db->query($sql); if ($resql) { @@ -160,10 +161,14 @@ if ($action == 'add' && $permissiontoadd) { $anlage->note_private = isset($_POST['note_private']) ? $_POST['note_private'] : ''; $anlage->status = 1; - // Get type for system ID + // Get type - but keep current system for GLOBAL types (buildings) $type = new AnlageType($db); if ($type->fetch($anlage->fk_anlage_type) > 0) { - $anlage->fk_system = $type->fk_system; + // Only change system if type is NOT a global type + // Global types (buildings) should stay in the current system + if ($type->system_code !== 'GLOBAL') { + $anlage->fk_system = $type->fk_system; + } } // Dynamic fields @@ -180,7 +185,7 @@ if ($action == 'add' && $permissiontoadd) { $result = $anlage->create($user); if ($result > 0) { setEventMessages($langs->trans('RecordSaved'), null, 'mesgs'); - header('Location: '.$_SERVER['PHP_SELF'].'?id='.$id.'&system='.$anlage->fk_system); + header('Location: '.$_SERVER['PHP_SELF'].'?id='.$id.'&system='.$systemId); exit; } else { setEventMessages($anlage->error, $anlage->errors, 'errors'); @@ -201,10 +206,14 @@ if ($action == 'update' && $permissiontoadd) { $anlage->installation_date = dol_mktime(0, 0, 0, GETPOSTINT('installation_datemonth'), GETPOSTINT('installation_dateday'), GETPOSTINT('installation_dateyear')); $anlage->note_private = isset($_POST['note_private']) ? $_POST['note_private'] : ''; - // Get type for system ID + // Get type - but keep current system for GLOBAL types (buildings) $type = new AnlageType($db); if ($type->fetch($anlage->fk_anlage_type) > 0) { - $anlage->fk_system = $type->fk_system; + // Only change system if type is NOT a global type + // Global types (buildings) should stay in their current system + if ($type->system_code !== 'GLOBAL') { + $anlage->fk_system = $type->fk_system; + } } // Dynamic fields @@ -221,7 +230,7 @@ if ($action == 'update' && $permissiontoadd) { $result = $anlage->update($user); if ($result > 0) { setEventMessages($langs->trans('RecordSaved'), null, 'mesgs'); - header('Location: '.$_SERVER['PHP_SELF'].'?id='.$id.'&system='.$anlage->fk_system); + header('Location: '.$_SERVER['PHP_SELF'].'?id='.$id.'&system='.$systemId); exit; } else { setEventMessages($anlage->error, $anlage->errors, 'errors');