diff --git a/api.php b/api.php index 091d85b..8292136 100644 --- a/api.php +++ b/api.php @@ -1837,6 +1837,35 @@ switch ($action) { 'muokkaaja' => currentUser(), ]; dbSaveIpam($companyId, $entry); + // Auto-VLAN: jos subnet/ip:llä on vlan_id, luo VLAN automaattisesti jos ei vielä ole + if ($entry['tyyppi'] !== 'vlan' && !empty($entry['vlan_id'])) { + $vlanNum = (int)$entry['vlan_id']; + $existingIpam = dbLoadIpam($companyId); + $vlanExists = false; + foreach ($existingIpam as $ie) { + if ($ie['tyyppi'] === 'vlan' && (int)$ie['vlan_id'] === $vlanNum) { + $vlanExists = true; + break; + } + } + if (!$vlanExists) { + $newVlan = [ + 'id' => generateId(), + 'tyyppi' => 'vlan', + 'nimi' => 'VLAN ' . $vlanNum, + 'verkko' => '', + 'vlan_id' => $vlanNum, + 'site_id' => $entry['site_id'], + 'tila' => 'varattu', + 'asiakas' => '', + 'lisatiedot' => 'Luotu automaattisesti', + 'luotu' => date('Y-m-d H:i:s'), + 'muokattu' => null, + 'muokkaaja' => currentUser(), + ]; + dbSaveIpam($companyId, $newVlan); + } + } $action_label = isset($input['id']) && !empty($input['id']) ? 'ipam_update' : 'ipam_create'; $desc = ($entry['tyyppi'] === 'vlan' ? 'VLAN ' . ($entry['vlan_id'] ?? '') : $entry['verkko']) . ' ' . $entry['nimi']; dbAddLog($companyId, currentUser(), $action_label, $entry['id'], $desc, $action_label === 'ipam_create' ? 'Lisäsi IPAM-merkinnän' : 'Muokkasi IPAM-merkintää');