kundenkarte/ajax/tree_config.php
data 71272fa425 fix(schematic): Terminal-Farbpropagierung, Auto-Naming, PWA-Abgänge
- buildTerminalPhaseMap: Schritt 1b - Leitungen mit expliziter Farbe als
  Startpunkte (nur Gerät→Gerät, keine Abgänge)
- buildTerminalPhaseMap: Block-Durchreichung (Top↔Bottom) entfernt
- buildTerminalPhaseMap: Junction-Verbindungen (Terminal→Leitung)
  bidirektional verarbeitet via _connectionById Index
- PWA: Abgangs-Rendering mit Index-Fallback wenn source_terminal_id fehlt
- PWA: Abgangs-Labels max-height 130px, min-height 30px
- Auto-Naming: EquipmentCarrier create/update → 'R' + count
- Auto-Naming: EquipmentPanel update → 'Feld ' + count
- pwa_api.php: Hardcoded Fallbacks 'Feld'/'Hutschiene' entfernt
- pwa.js: Hutschiene Auto-Naming dynamisch aus Panel-Carrier-Anzahl
- kundenkarte.js: Carrier-Dialog Placeholder 'z.B. R1 (automatisch)'
- SW Cache auf v12.5 hochgezählt

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-17 09:57:58 +01:00

107 lines
2.8 KiB
PHP
Executable file

<?php
/* Copyright (C) 2026 Alles Watt lauft
*
* AJAX endpoint for tree display configuration
*/
if (!defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1');
if (!defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1');
if (!defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1');
if (!defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1');
$res = 0;
if (!$res && file_exists("../../main.inc.php")) $res = @include "../../main.inc.php";
if (!$res && file_exists("../../../main.inc.php")) $res = @include "../../../main.inc.php";
if (!$res) die("Include of main fails");
header('Content-Type: application/json; charset=UTF-8');
$langs->loadLangs(array('kundenkarte@kundenkarte'));
$action = GETPOST('action', 'aZ09');
$systemId = GETPOSTINT('system_id');
$response = array('success' => false, 'error' => '');
// Security check
if (!$user->hasRight('kundenkarte', 'read')) {
$response['error'] = $langs->trans('ErrorPermissionDenied');
echo json_encode($response);
exit;
}
switch ($action) {
case 'get':
// Get tree config for a system
$defaultConfig = array(
'show_ref' => true,
'show_label' => true,
'show_type' => true,
'show_icon' => true,
'show_status' => true,
'show_fields' => false,
'expand_default' => true,
'indent_style' => 'lines'
);
if ($systemId > 0) {
$sql = "SELECT tree_display_config FROM ".MAIN_DB_PREFIX."c_kundenkarte_anlage_system WHERE rowid = ".(int)$systemId;
$resql = $db->query($sql);
if ($resql && $obj = $db->fetch_object($resql)) {
if (!empty($obj->tree_display_config)) {
$savedConfig = json_decode($obj->tree_display_config, true);
if (is_array($savedConfig)) {
$defaultConfig = array_merge($defaultConfig, $savedConfig);
}
}
}
}
$response['success'] = true;
$response['config'] = $defaultConfig;
break;
case 'list':
// Get all system configs
$sql = "SELECT rowid, code, label, tree_display_config FROM ".MAIN_DB_PREFIX."c_kundenkarte_anlage_system WHERE active = 1 ORDER BY position";
$resql = $db->query($sql);
$configs = array();
if ($resql) {
while ($obj = $db->fetch_object($resql)) {
$config = array(
'show_ref' => true,
'show_label' => true,
'show_type' => true,
'show_icon' => true,
'show_status' => true,
'show_fields' => false,
'expand_default' => true,
'indent_style' => 'lines'
);
if (!empty($obj->tree_display_config)) {
$savedConfig = json_decode($obj->tree_display_config, true);
if (is_array($savedConfig)) {
$config = array_merge($config, $savedConfig);
}
}
$configs[$obj->rowid] = array(
'id' => $obj->rowid,
'code' => $obj->code,
'label' => $obj->label,
'config' => $config
);
}
}
$response['success'] = true;
$response['systems'] = $configs;
break;
default:
$response['error'] = 'Unknown action';
}
echo json_encode($response);