closes #3
This commit is contained in:
@@ -27,7 +27,7 @@ $module = $_GET['module'] ?? 'dashboard';
|
|||||||
$action = $_GET['action'] ?? 'list';
|
$action = $_GET['action'] ?? 'list';
|
||||||
|
|
||||||
// Whitelist der Module
|
// Whitelist der Module
|
||||||
$validModules = ['dashboard', 'locations', 'buildings', 'device_types', 'devices', 'racks', 'floors', 'connections'];
|
$validModules = ['dashboard', 'locations', 'buildings', 'device_types', 'devices', 'racks', 'floors', 'connections', 'port_types'];
|
||||||
|
|
||||||
// Whitelist der Aktionen
|
// Whitelist der Aktionen
|
||||||
$validActions = ['list', 'edit', 'save', 'ports', 'delete'];
|
$validActions = ['list', 'edit', 'save', 'ports', 'delete'];
|
||||||
|
|||||||
168
app/modules/port_types/edit.php
Normal file
168
app/modules/port_types/edit.php
Normal file
@@ -0,0 +1,168 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* app/modules/port_types/edit.php
|
||||||
|
*
|
||||||
|
* Porttyp erstellen / bearbeiten
|
||||||
|
*/
|
||||||
|
|
||||||
|
// =========================
|
||||||
|
// Kontext bestimmen
|
||||||
|
// =========================
|
||||||
|
$portTypeId = (int)($_GET['id'] ?? 0);
|
||||||
|
$portType = null;
|
||||||
|
|
||||||
|
if ($portTypeId > 0) {
|
||||||
|
$portType = $sql->single(
|
||||||
|
"SELECT * FROM port_types WHERE id = ?",
|
||||||
|
"i",
|
||||||
|
[$portTypeId]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$isEdit = !empty($portType);
|
||||||
|
$pageTitle = $isEdit ? "Porttyp bearbeiten: " . htmlspecialchars($portType['name']) : "Neuen Porttyp anlegen";
|
||||||
|
$mediaOptions = ['copper' => 'Kupfer', 'fiber' => 'Lichtwelle', 'coax' => 'Koax', 'other' => 'Sonstiges'];
|
||||||
|
|
||||||
|
$error = $_SESSION['error'] ?? '';
|
||||||
|
unset($_SESSION['error']);
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
||||||
|
<div class="port-type-edit">
|
||||||
|
<h1><?php echo $pageTitle; ?></h1>
|
||||||
|
|
||||||
|
<?php if ($error): ?>
|
||||||
|
<div class="error-message">
|
||||||
|
<?php echo htmlspecialchars($error); ?>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<form method="post" action="?module=port_types&action=save" class="edit-form">
|
||||||
|
|
||||||
|
<?php if ($isEdit): ?>
|
||||||
|
<input type="hidden" name="id" value="<?php echo $portTypeId; ?>">
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<fieldset>
|
||||||
|
<legend>Details</legend>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="name">Name <span class="required">*</span></label>
|
||||||
|
<input type="text" id="name" name="name" required
|
||||||
|
value="<?php echo htmlspecialchars($portType['name'] ?? ''); ?>"
|
||||||
|
placeholder="z.B. RJ45 Gbit">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="medium">Medium</label>
|
||||||
|
<select id="medium" name="medium">
|
||||||
|
<?php foreach ($mediaOptions as $value => $label): ?>
|
||||||
|
<option value="<?php echo $value; ?>" <?php echo (($portType['medium'] ?? '') === $value) ? 'selected' : ''; ?>>
|
||||||
|
<?php echo $label; ?>
|
||||||
|
</option>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="comment">Beschreibung</label>
|
||||||
|
<textarea id="comment" name="comment" rows="4"><?php echo htmlspecialchars($portType['comment'] ?? ''); ?></textarea>
|
||||||
|
</div>
|
||||||
|
</fieldset>
|
||||||
|
|
||||||
|
<fieldset class="form-actions">
|
||||||
|
<button type="submit" class="button button-primary">Speichern</button>
|
||||||
|
<a href="?module=port_types&action=list" class="button">Zurück zur Liste</a>
|
||||||
|
</fieldset>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.port-type-edit {
|
||||||
|
max-width: 600px;
|
||||||
|
margin: 20px auto;
|
||||||
|
padding: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.edit-form {
|
||||||
|
background: white;
|
||||||
|
padding: 20px;
|
||||||
|
border: 1px solid #ddd;
|
||||||
|
border-radius: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.edit-form fieldset {
|
||||||
|
margin: 20px 0;
|
||||||
|
padding: 15px;
|
||||||
|
border: 1px solid #e0e0e0;
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.edit-form legend {
|
||||||
|
padding: 0 10px;
|
||||||
|
font-weight: bold;
|
||||||
|
font-size: 1.1em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-group {
|
||||||
|
margin: 15px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-group label {
|
||||||
|
display: block;
|
||||||
|
margin-bottom: 5px;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-group input[type="text"],
|
||||||
|
.form-group select,
|
||||||
|
.form-group textarea {
|
||||||
|
width: 100%;
|
||||||
|
padding: 8px 12px;
|
||||||
|
border: 1px solid #ddd;
|
||||||
|
border-radius: 4px;
|
||||||
|
font-family: inherit;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-group textarea {
|
||||||
|
resize: vertical;
|
||||||
|
}
|
||||||
|
|
||||||
|
.required {
|
||||||
|
color: red;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-actions {
|
||||||
|
display: flex;
|
||||||
|
gap: 10px;
|
||||||
|
margin-top: 30px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.button {
|
||||||
|
padding: 10px 15px;
|
||||||
|
background: #007bff;
|
||||||
|
color: white;
|
||||||
|
text-decoration: none;
|
||||||
|
border-radius: 4px;
|
||||||
|
border: none;
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 0.95em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.button-primary {
|
||||||
|
background: #28a745;
|
||||||
|
}
|
||||||
|
|
||||||
|
.button:hover {
|
||||||
|
opacity: 0.8;
|
||||||
|
}
|
||||||
|
|
||||||
|
.error-message {
|
||||||
|
background: #ffe3e3;
|
||||||
|
color: #a73737;
|
||||||
|
border: 1px solid #f5c2c2;
|
||||||
|
padding: 10px;
|
||||||
|
border-radius: 4px;
|
||||||
|
margin-bottom: 15px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
189
app/modules/port_types/list.php
Normal file
189
app/modules/port_types/list.php
Normal file
@@ -0,0 +1,189 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* app/modules/port_types/list.php
|
||||||
|
*
|
||||||
|
* Liste aller verfügbaren Porttypen
|
||||||
|
*/
|
||||||
|
|
||||||
|
// =========================
|
||||||
|
// Filter einlesen
|
||||||
|
// =========================
|
||||||
|
$search = trim($_GET['search'] ?? '');
|
||||||
|
|
||||||
|
// =========================
|
||||||
|
// Filter anwenden
|
||||||
|
// =========================
|
||||||
|
$where = [];
|
||||||
|
$types = '';
|
||||||
|
$params = [];
|
||||||
|
|
||||||
|
if ($search !== '') {
|
||||||
|
$where[] = "(name LIKE ? OR comment LIKE ?)";
|
||||||
|
$types .= "ss";
|
||||||
|
$params[] = "%$search%";
|
||||||
|
$params[] = "%$search%";
|
||||||
|
}
|
||||||
|
|
||||||
|
$whereSql = $where ? "WHERE " . implode(" AND ", $where) : "";
|
||||||
|
|
||||||
|
$portTypes = $sql->get(
|
||||||
|
"SELECT * FROM port_types
|
||||||
|
$whereSql
|
||||||
|
ORDER BY name",
|
||||||
|
$types,
|
||||||
|
$params
|
||||||
|
);
|
||||||
|
|
||||||
|
$success = $_SESSION['success'] ?? '';
|
||||||
|
unset($_SESSION['success']);
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
||||||
|
<div class="port-types-container">
|
||||||
|
<h1>Porttypen</h1>
|
||||||
|
|
||||||
|
<?php if ($success): ?>
|
||||||
|
<div class="success-message">
|
||||||
|
<?php echo htmlspecialchars($success); ?>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<div class="toolbar">
|
||||||
|
<form method="GET" class="filter-form">
|
||||||
|
<input type="hidden" name="module" value="port_types">
|
||||||
|
<input type="hidden" name="action" value="list">
|
||||||
|
<input type="text" name="search" placeholder="Suche Porttyp…"
|
||||||
|
value="<?php echo htmlspecialchars($search); ?>" class="search-input">
|
||||||
|
<button type="submit" class="button">Filter</button>
|
||||||
|
<a href="?module=port_types&action=list" class="button">Reset</a>
|
||||||
|
<a href="?module=port_types&action=edit" class="button button-primary">+ Neuer Porttyp</a>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php if (!empty($portTypes)): ?>
|
||||||
|
<table class="port-types-table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Name</th>
|
||||||
|
<th>Medium</th>
|
||||||
|
<th>Beschreibung</th>
|
||||||
|
<th>Aktionen</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<?php foreach ($portTypes as $pt): ?>
|
||||||
|
<tr>
|
||||||
|
<td><?php echo htmlspecialchars($pt['name']); ?></td>
|
||||||
|
<td><?php echo htmlspecialchars($pt['medium']); ?></td>
|
||||||
|
<td><small><?php echo htmlspecialchars($pt['comment'] ?? ''); ?></small></td>
|
||||||
|
<td class="actions">
|
||||||
|
<a href="?module=port_types&action=edit&id=<?php echo (int)$pt['id']; ?>" class="button button-small">Bearbeiten</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<?php else: ?>
|
||||||
|
<div class="empty-state">
|
||||||
|
<p>Keine Porttypen definiert.</p>
|
||||||
|
<a href="?module=port_types&action=edit" class="button button-primary">Porttyp hinzufügen</a>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.port-types-container {
|
||||||
|
padding: 20px;
|
||||||
|
max-width: 1000px;
|
||||||
|
margin: 0 auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toolbar {
|
||||||
|
margin: 20px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.filter-form {
|
||||||
|
display: flex;
|
||||||
|
gap: 10px;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.filter-form input[type="text"] {
|
||||||
|
padding: 8px 12px;
|
||||||
|
border: 1px solid #ddd;
|
||||||
|
border-radius: 4px;
|
||||||
|
flex: 1;
|
||||||
|
min-width: 200px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.button {
|
||||||
|
display: inline-block;
|
||||||
|
padding: 8px 12px;
|
||||||
|
background: #007bff;
|
||||||
|
color: white;
|
||||||
|
text-decoration: none;
|
||||||
|
border-radius: 4px;
|
||||||
|
border: none;
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 0.9em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.button:hover {
|
||||||
|
background: #0056b3;
|
||||||
|
}
|
||||||
|
|
||||||
|
.button-primary {
|
||||||
|
background: #28a745;
|
||||||
|
}
|
||||||
|
|
||||||
|
.button-primary:hover {
|
||||||
|
background: #218838;
|
||||||
|
}
|
||||||
|
|
||||||
|
.button-small {
|
||||||
|
padding: 4px 8px;
|
||||||
|
font-size: 0.85em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.port-types-table {
|
||||||
|
width: 100%;
|
||||||
|
border-collapse: collapse;
|
||||||
|
margin-top: 15px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.port-types-table th,
|
||||||
|
.port-types-table td {
|
||||||
|
border-bottom: 1px solid #ddd;
|
||||||
|
padding: 12px;
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
|
||||||
|
.port-types-table th {
|
||||||
|
background: #f5f5f5;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
.empty-state,
|
||||||
|
.success-message {
|
||||||
|
margin: 20px 0;
|
||||||
|
padding: 15px;
|
||||||
|
border-radius: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.empty-state {
|
||||||
|
background: #f9f9f9;
|
||||||
|
border: 1px solid #eee;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.success-message {
|
||||||
|
background: #e9f8f1;
|
||||||
|
border: 1px solid #c7eedc;
|
||||||
|
color: #2c7d59;
|
||||||
|
}
|
||||||
|
|
||||||
|
.actions {
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
54
app/modules/port_types/save.php
Normal file
54
app/modules/port_types/save.php
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* app/modules/port_types/save.php
|
||||||
|
*
|
||||||
|
* Speichert Porttyp-Daten
|
||||||
|
*/
|
||||||
|
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||||
|
header('Location: ?module=port_types&action=list');
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$portTypeId = (int)($_POST['id'] ?? 0);
|
||||||
|
$name = trim($_POST['name'] ?? '');
|
||||||
|
$medium = $_POST['medium'] ?? 'other';
|
||||||
|
$comment = trim($_POST['comment'] ?? '');
|
||||||
|
|
||||||
|
$allowedMediums = ['copper', 'fiber', 'coax', 'other'];
|
||||||
|
|
||||||
|
$errors = [];
|
||||||
|
|
||||||
|
if ($name === '') {
|
||||||
|
$errors[] = "Name ist erforderlich";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!in_array($medium, $allowedMediums, true)) {
|
||||||
|
$errors[] = "Ungültiges Medium";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($errors)) {
|
||||||
|
$_SESSION['error'] = implode(', ', $errors);
|
||||||
|
$redirect = $portTypeId ? "?module=port_types&action=edit&id=$portTypeId" : "?module=port_types&action=edit";
|
||||||
|
header("Location: $redirect");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($portTypeId > 0) {
|
||||||
|
$sql->set(
|
||||||
|
"UPDATE port_types SET name = ?, medium = ?, comment = ? WHERE id = ?",
|
||||||
|
"sssi",
|
||||||
|
[$name, $medium, $comment, $portTypeId]
|
||||||
|
);
|
||||||
|
$_SESSION['success'] = "Porttyp aktualisiert";
|
||||||
|
} else {
|
||||||
|
$sql->set(
|
||||||
|
"INSERT INTO port_types (name, medium, comment) VALUES (?, ?, ?)",
|
||||||
|
"sss",
|
||||||
|
[$name, $medium, $comment]
|
||||||
|
);
|
||||||
|
$_SESSION['success'] = "Porttyp erstellt";
|
||||||
|
}
|
||||||
|
|
||||||
|
header('Location: ?module=port_types&action=list');
|
||||||
|
exit;
|
||||||
@@ -35,6 +35,7 @@
|
|||||||
'locations' => 'Standorte',
|
'locations' => 'Standorte',
|
||||||
'buildings' => 'Gebäude',
|
'buildings' => 'Gebäude',
|
||||||
'device_types' => 'Gerätetypen',
|
'device_types' => 'Gerätetypen',
|
||||||
|
'port_types' => 'Porttypen',
|
||||||
'devices' => 'Geräte',
|
'devices' => 'Geräte',
|
||||||
'racks' => 'Racks',
|
'racks' => 'Racks',
|
||||||
'floors' => 'Stockwerke',
|
'floors' => 'Stockwerke',
|
||||||
|
|||||||
Reference in New Issue
Block a user