verbings administration

This commit is contained in:
2026-02-16 14:43:15 +01:00
parent 510a248edb
commit 4a23713d31
7 changed files with 250 additions and 23 deletions

View File

@@ -51,6 +51,41 @@ if ($portAId <= 0 || $portBId <= 0) {
$errors[] = "Beide Ports sind erforderlich";
}
$otherConnections = $sql->get(
"SELECT id, port_a_type, port_a_id, port_b_type, port_b_id
FROM connections
WHERE id <> ?",
"i",
[$connId]
);
$isEndpointUsed = static function (string $endpointType, int $endpointId) use ($otherConnections, $normalizePortType): bool {
if ($endpointId <= 0) {
return false;
}
foreach ((array)$otherConnections as $row) {
$typeA = $normalizePortType((string)($row['port_a_type'] ?? ''));
$idA = (int)($row['port_a_id'] ?? 0);
if ($typeA === $endpointType && $idA === $endpointId) {
return true;
}
$typeB = $normalizePortType((string)($row['port_b_type'] ?? ''));
$idB = (int)($row['port_b_id'] ?? 0);
if ($typeB === $endpointType && $idB === $endpointId) {
return true;
}
}
return false;
};
if ($isEndpointUsed($portAType, $portAId)) {
$errors[] = "Port an Endpunkt A ist bereits in Verwendung";
}
if ($isEndpointUsed($portBType, $portBId)) {
$errors[] = "Port an Endpunkt B ist bereits in Verwendung";
}
if (!empty($errors)) {
$_SESSION['error'] = implode(', ', $errors);
$redirectUrl = $connId ? "?module=connections&action=edit&id=$connId" : "?module=connections&action=edit";
@@ -67,15 +102,36 @@ if ($connId > 0) {
// UPDATE
$sql->set(
"UPDATE connections SET port_a_type = ?, port_a_id = ?, port_b_type = ?, port_b_id = ?, vlan_config = ?, comment = ? WHERE id = ?",
"siisisi",
"sisissi",
[$portAType, $portAId, $portBType, $portBId, $vlanJson, $comment, $connId]
);
} else {
$connectionTypeId = (int)($sql->single(
"SELECT id FROM connection_types ORDER BY id LIMIT 1",
"",
[]
)['id'] ?? 0);
if ($connectionTypeId <= 0) {
$connectionTypeId = (int)$sql->set(
"INSERT INTO connection_types (name, medium, duplex, line_style, comment) VALUES (?, ?, ?, ?, ?)",
"sssss",
['Default', 'copper', 'custom', 'solid', 'Auto-created by connections/save'],
true
);
}
if ($connectionTypeId <= 0) {
$_SESSION['error'] = "Kein Verbindungstyp verfuegbar";
header("Location: ?module=connections&action=edit");
exit;
}
// INSERT
$sql->set(
"INSERT INTO connections (port_a_type, port_a_id, port_b_type, port_b_id, vlan_config, comment) VALUES (?, ?, ?, ?, ?, ?)",
"siisis",
[$portAType, $portAId, $portBType, $portBId, $vlanJson, $comment]
"INSERT INTO connections (connection_type_id, port_a_type, port_a_id, port_b_type, port_b_id, vlan_config, comment) VALUES (?, ?, ?, ?, ?, ?, ?)",
"isisiss",
[$connectionTypeId, $portAType, $portAId, $portBType, $portBId, $vlanJson, $comment]
);
}