121 lines
3.7 KiB
PHP
121 lines
3.7 KiB
PHP
<?php
|
|
|
|
require "db.php";
|
|
|
|
session_start();
|
|
|
|
// Verify session
|
|
if (!isset($_SESSION["auth"])) {
|
|
header("Location: index.php");
|
|
exit;
|
|
}
|
|
|
|
// Logout request
|
|
if (isset($_GET["logout"])) {
|
|
session_destroy();
|
|
header("Location: index.php");
|
|
exit;
|
|
}
|
|
|
|
// Add frequency request
|
|
if (isset($_POST["add_freq"])) {
|
|
db_query("INSERT INTO frequenze"
|
|
. " (frequenza, nome, descrizione, modulazione, organizzazione)"
|
|
. " VALUES (?, ?, ?, ?, ?)",
|
|
[
|
|
$_POST["frequenza"], $_POST["nome"], $_POST["descrizione"],
|
|
$_POST["modulazione"] ?: null,
|
|
$_POST["organizzazione"] ?: null
|
|
]);
|
|
}
|
|
|
|
// Delete frequency request
|
|
if (isset($_POST["del_freq"])) {
|
|
db_query("DELETE FROM frequenze WHERE id = ?", [$_POST["id"]]);
|
|
}
|
|
|
|
// Get data
|
|
$frequenze = db_query(
|
|
"SELECT f.*, o.nome as org_nome, m.nome as mod_nome FROM frequenze f"
|
|
. " LEFT JOIN organizzazioni o ON f.organizzazione = o.id"
|
|
. " LEFT JOIN modulazioni m ON f.modulazione = m.id"
|
|
. " ORDER BY f.frequenza");
|
|
|
|
$organizzazioni = db_query("SELECT * FROM organizzazioni");
|
|
|
|
$modulazioni = db_query("SELECT * FROM modulazioni");
|
|
|
|
?>
|
|
|
|
<!DOCTYPE html>
|
|
<html lang="it">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>RFDB - Gestione</title>
|
|
<link rel="stylesheet" href="style.css">
|
|
</head>
|
|
<body>
|
|
<nav>
|
|
<strong>RFDB MANAGER</strong> |
|
|
<a href="frequenze.php">Frequenze</a> |
|
|
<a href="?logout">Logout</a>
|
|
</nav>
|
|
|
|
<div class="form-box">
|
|
<h3>Aggiungi Nuova Frequenza</h3>
|
|
<form method="post">
|
|
Frequenza (MHz): <input type="number" step="any" name="frequenza" required>
|
|
Modulazione:
|
|
<select name="modulazione">
|
|
<option value="">Nessuna</option>
|
|
<?php foreach($modulazioni as $m): ?>
|
|
<option value="<?= $m["id"] ?>"><?= htmlspecialchars($m["nome"]) ?></option>
|
|
<?php endforeach; ?>
|
|
</select><br><br>
|
|
Nome: <input type="text" name="nome"><br><br>
|
|
Descrizione:<br>
|
|
<textarea name="descrizione" cols="40" rows="3"></textarea><br><br>
|
|
Organizzazione:
|
|
<select name="organizzazione">
|
|
<option value="">Nessuna</option>
|
|
<?php foreach($organizzazioni as $o): ?>
|
|
<option value="<?= $o["id"] ?>"><?= htmlspecialchars($o["nome"]) ?></option>
|
|
<?php endforeach; ?>
|
|
</select><br><br>
|
|
<button type="submit" name="add_freq">Salva Frequenza</button>
|
|
</form>
|
|
</div>
|
|
|
|
<h3>Elenco Frequenze Registrate</h3>
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>MHz</th>
|
|
<th>Modulazione</th>
|
|
<th>Nome</th>
|
|
<th>Descrizione</th>
|
|
<th>Organizzazione</th>
|
|
<th>#</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($frequenze as $f): ?>
|
|
<tr>
|
|
<td><strong><?= $f["frequenza"] ?></strong></td>
|
|
<td><?= htmlspecialchars($f["mod_nome"]) ?></td>
|
|
<td><?= htmlspecialchars($f["nome"]) ?></td>
|
|
<td><?= htmlspecialchars($f["descrizione"]) ?></td>
|
|
<td><?= htmlspecialchars($f["org_nome"] ?? "-") ?></td>
|
|
<td>
|
|
<form method="POST">
|
|
<input value="<?= $f["id"] ?>" name="id" hidden>
|
|
<button type="submit" name="del_freq">Elimina</button>
|
|
</form>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
</body>
|
|
</html>
|