kundenkarte/ajax/building_types.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

121 lines
3.3 KiB
PHP
Executable file

<?php
/* Copyright (C) 2026 Alles Watt lauft
*
* AJAX endpoint for building types (Gebäudetypen)
*/
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");
dol_include_once('/kundenkarte/class/buildingtype.class.php');
header('Content-Type: application/json; charset=UTF-8');
$langs->loadLangs(array('kundenkarte@kundenkarte'));
$action = GETPOST('action', 'aZ09');
$levelType = GETPOST('level_type', 'alpha');
$response = array('success' => false, 'error' => '');
// Security check
if (!$user->hasRight('kundenkarte', 'read')) {
$response['error'] = $langs->trans('ErrorPermissionDenied');
echo json_encode($response);
exit;
}
$buildingType = new BuildingType($db);
switch ($action) {
case 'list':
// Get all building types
$types = $buildingType->fetchAll(1, $levelType);
$result = array();
foreach ($types as $t) {
$result[] = array(
'id' => $t->id,
'ref' => $t->ref,
'label' => $t->label,
'label_short' => $t->label_short,
'level_type' => $t->level_type,
'level_type_label' => $t->getLevelTypeLabel(),
'icon' => $t->icon,
'color' => $t->color,
'can_have_children' => $t->can_have_children,
'is_system' => $t->is_system
);
}
$response['success'] = true;
$response['types'] = $result;
break;
case 'list_grouped':
// Get types grouped by level
$grouped = $buildingType->fetchGroupedByLevel(1);
$result = array();
$levelTypes = BuildingType::getLevelTypes();
foreach ($grouped as $level => $types) {
$levelLabel = isset($levelTypes[$level]) ? $levelTypes[$level] : $level;
$levelTypes_data = array();
foreach ($types as $t) {
$levelTypes_data[] = array(
'id' => $t->id,
'ref' => $t->ref,
'label' => $t->label,
'label_short' => $t->label_short,
'icon' => $t->icon,
'color' => $t->color,
'can_have_children' => $t->can_have_children
);
}
$result[] = array(
'level_type' => $level,
'level_type_label' => $levelLabel,
'types' => $levelTypes_data
);
}
$response['success'] = true;
$response['groups'] = $result;
break;
case 'get':
// Get single type details
$typeId = GETPOSTINT('type_id');
if ($typeId > 0 && $buildingType->fetch($typeId) > 0) {
$response['success'] = true;
$response['type'] = array(
'id' => $buildingType->id,
'ref' => $buildingType->ref,
'label' => $buildingType->label,
'label_short' => $buildingType->label_short,
'description' => $buildingType->description,
'level_type' => $buildingType->level_type,
'level_type_label' => $buildingType->getLevelTypeLabel(),
'icon' => $buildingType->icon,
'color' => $buildingType->color,
'can_have_children' => $buildingType->can_have_children,
'is_system' => $buildingType->is_system
);
} else {
$response['error'] = $langs->trans('ErrorRecordNotFound');
}
break;
default:
$response['error'] = 'Unknown action';
}
echo json_encode($response);