Behebe Dashboard-, Loesch- und Infrastruktur-Issues
closes #20 closes #19 closes #18 closes #17
This commit is contained in:
@@ -80,6 +80,7 @@ if ($type === 'patchpanel') {
|
||||
$x = (int)($_POST['x'] ?? 0);
|
||||
$y = (int)($_POST['y'] ?? 0);
|
||||
$comment = trim($_POST['comment'] ?? '');
|
||||
$bindPatchpanelPortId = (int)($_POST['bind_patchpanel_port_id'] ?? 0);
|
||||
$outletId = $id;
|
||||
$errors = [];
|
||||
|
||||
@@ -126,6 +127,132 @@ if ($type === 'patchpanel') {
|
||||
[$outletId]
|
||||
);
|
||||
}
|
||||
|
||||
if ($bindPatchpanelPortId > 0) {
|
||||
$roomFloorId = (int)($sql->single(
|
||||
"SELECT floor_id FROM rooms WHERE id = ?",
|
||||
"i",
|
||||
[$roomId]
|
||||
)['floor_id'] ?? 0);
|
||||
|
||||
$patchpanelPort = $sql->single(
|
||||
"SELECT
|
||||
fpp.id,
|
||||
fp.floor_id
|
||||
FROM floor_patchpanel_ports fpp
|
||||
JOIN floor_patchpanels fp ON fp.id = fpp.patchpanel_id
|
||||
WHERE fpp.id = ?",
|
||||
"i",
|
||||
[$bindPatchpanelPortId]
|
||||
);
|
||||
|
||||
if (!$patchpanelPort) {
|
||||
$_SESSION['error'] = 'Gewaehlter Patchpanel-Port existiert nicht';
|
||||
$_SESSION['validation_errors'] = ['Gewaehlter Patchpanel-Port existiert nicht'];
|
||||
header('Location: ?module=floor_infrastructure&action=edit&type=outlet&id=' . $outletId);
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($roomFloorId <= 0 || (int)$patchpanelPort['floor_id'] !== $roomFloorId) {
|
||||
$_SESSION['error'] = 'Patchpanel-Port und Raum muessen auf demselben Stockwerk liegen';
|
||||
$_SESSION['validation_errors'] = ['Patchpanel-Port und Raum muessen auf demselben Stockwerk liegen'];
|
||||
header('Location: ?module=floor_infrastructure&action=edit&type=outlet&id=' . $outletId);
|
||||
exit;
|
||||
}
|
||||
|
||||
$outletPortId = (int)($sql->single(
|
||||
"SELECT id
|
||||
FROM network_outlet_ports
|
||||
WHERE outlet_id = ?
|
||||
ORDER BY id
|
||||
LIMIT 1",
|
||||
"i",
|
||||
[$outletId]
|
||||
)['id'] ?? 0);
|
||||
|
||||
if ($outletPortId <= 0) {
|
||||
$_SESSION['error'] = 'Wandbuchsen-Port konnte nicht ermittelt werden';
|
||||
$_SESSION['validation_errors'] = ['Wandbuchsen-Port konnte nicht ermittelt werden'];
|
||||
header('Location: ?module=floor_infrastructure&action=edit&type=outlet&id=' . $outletId);
|
||||
exit;
|
||||
}
|
||||
|
||||
$existingPatchpanelUsage = $sql->single(
|
||||
"SELECT
|
||||
id,
|
||||
port_a_type,
|
||||
port_a_id,
|
||||
port_b_type,
|
||||
port_b_id
|
||||
FROM connections
|
||||
WHERE
|
||||
((port_a_type = 'patchpanel' OR port_a_type = 'floor_patchpanel_ports') AND port_a_id = ?)
|
||||
OR
|
||||
((port_b_type = 'patchpanel' OR port_b_type = 'floor_patchpanel_ports') AND port_b_id = ?)
|
||||
LIMIT 1",
|
||||
"ii",
|
||||
[$bindPatchpanelPortId, $bindPatchpanelPortId]
|
||||
);
|
||||
|
||||
if ($existingPatchpanelUsage) {
|
||||
$sameOutletConnection = (
|
||||
(
|
||||
(($existingPatchpanelUsage['port_a_type'] ?? '') === 'outlet' || ($existingPatchpanelUsage['port_a_type'] ?? '') === 'network_outlet_ports')
|
||||
&& (int)($existingPatchpanelUsage['port_a_id'] ?? 0) === $outletPortId
|
||||
)
|
||||
||
|
||||
(
|
||||
(($existingPatchpanelUsage['port_b_type'] ?? '') === 'outlet' || ($existingPatchpanelUsage['port_b_type'] ?? '') === 'network_outlet_ports')
|
||||
&& (int)($existingPatchpanelUsage['port_b_id'] ?? 0) === $outletPortId
|
||||
)
|
||||
);
|
||||
|
||||
if (!$sameOutletConnection) {
|
||||
$_SESSION['error'] = 'Gewaehlter Patchpanel-Port ist bereits verbunden';
|
||||
$_SESSION['validation_errors'] = ['Gewaehlter Patchpanel-Port ist bereits verbunden'];
|
||||
header('Location: ?module=floor_infrastructure&action=edit&type=outlet&id=' . $outletId);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$sql->set(
|
||||
"DELETE FROM connections
|
||||
WHERE
|
||||
((port_a_type = 'outlet' OR port_a_type = 'network_outlet_ports') AND port_a_id = ? AND (port_b_type = 'patchpanel' OR port_b_type = 'floor_patchpanel_ports'))
|
||||
OR
|
||||
((port_b_type = 'outlet' OR port_b_type = 'network_outlet_ports') AND port_b_id = ? AND (port_a_type = 'patchpanel' OR port_a_type = 'floor_patchpanel_ports'))",
|
||||
"ii",
|
||||
[$outletPortId, $outletPortId]
|
||||
);
|
||||
|
||||
$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 floor_infrastructure/save'],
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
if ($connectionTypeId <= 0) {
|
||||
$_SESSION['error'] = 'Kein Verbindungstyp fuer automatische Bindung verfuegbar';
|
||||
$_SESSION['validation_errors'] = ['Kein Verbindungstyp fuer automatische Bindung verfuegbar'];
|
||||
header('Location: ?module=floor_infrastructure&action=edit&type=outlet&id=' . $outletId);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql->set(
|
||||
"INSERT INTO connections (connection_type_id, port_a_type, port_a_id, port_b_type, port_b_id, vlan_config, comment)
|
||||
VALUES (?, 'outlet', ?, 'patchpanel', ?, NULL, ?)",
|
||||
"iiis",
|
||||
[$connectionTypeId, $outletPortId, $bindPatchpanelPortId, 'Auto-Link bei Wandbuchsen-Erstellung']
|
||||
);
|
||||
}
|
||||
}
|
||||
$_SESSION['success'] = $id > 0 ? 'Wandbuchse gespeichert' : 'Wandbuchse erstellt';
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user