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

99 lines
2.7 KiB
PHP
Executable file

<?php
/* Copyright (C) 2026 Alles Watt lauft
*
* AJAX-Endpunkt: Graph-Positionen speichern
* Speichert x/y-Koordinaten der Nodes nach Drag&Drop
*/
if (!defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1');
if (!defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1');
if (!defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1');
if (!defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1');
if (!defined('NOCSRFCHECK')) define('NOCSRFCHECK', '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');
$response = array('success' => false, 'error' => '');
// Berechtigungsprüfung
if (!$user->hasRight('kundenkarte', 'write')) {
$response['error'] = 'Keine Berechtigung';
echo json_encode($response);
exit;
}
$action = GETPOST('action', 'aZ');
if ($action === 'save') {
// Positionen als JSON-Array: [{id: 123, x: 45.6, y: 78.9}, ...]
$rawInput = file_get_contents('php://input');
$input = json_decode($rawInput, true);
if (!is_array($input) || empty($input['positions'])) {
$response['error'] = 'Keine Positionen übergeben';
echo json_encode($response);
exit;
}
$saved = 0;
$db->begin();
foreach ($input['positions'] as $pos) {
$anlageId = (int) ($pos['id'] ?? 0);
$x = (float) ($pos['x'] ?? 0);
$y = (float) ($pos['y'] ?? 0);
if ($anlageId <= 0) continue;
$sql = "UPDATE ".MAIN_DB_PREFIX."kundenkarte_anlage";
$sql .= " SET graph_x = ".$x.", graph_y = ".$y;
// Gebäude-Größe optional mitspeichern
if (isset($pos['w']) && isset($pos['h'])) {
$w = (float) $pos['w'];
$h = (float) $pos['h'];
$sql .= ", graph_width = ".($w > 0 ? $w : "NULL").", graph_height = ".($h > 0 ? $h : "NULL");
}
$sql .= " WHERE rowid = ".$anlageId;
if ($db->query($sql)) {
$saved++;
}
}
$db->commit();
$response['success'] = true;
$response['saved'] = $saved;
} elseif ($action === 'reset') {
// Alle Positionen für einen Kunden zurücksetzen
$socId = GETPOSTINT('socid');
$contactId = GETPOSTINT('contactid');
if ($socId <= 0) {
$response['error'] = 'Fehlende socid';
echo json_encode($response);
exit;
}
$sql = "UPDATE ".MAIN_DB_PREFIX."kundenkarte_anlage";
$sql .= " SET graph_x = NULL, graph_y = NULL, graph_width = NULL, graph_height = NULL";
$sql .= " WHERE fk_soc = ".(int)$socId;
if ($contactId > 0) {
$sql .= " AND fk_contact = ".(int)$contactId;
}
if ($db->query($sql)) {
$response['success'] = true;
$response['reset'] = $db->affected_rows;
} else {
$response['error'] = 'Datenbankfehler';
}
} else {
$response['error'] = 'Unbekannte Aktion';
}
echo json_encode($response);