verifica
This commit is contained in:
parent
2c82d90dd4
commit
5f80048cec
20 changed files with 999 additions and 1 deletions
221
orologi/admin/dashboard.php
Normal file
221
orologi/admin/dashboard.php
Normal file
|
@ -0,0 +1,221 @@
|
|||
<?php
|
||||
session_start();
|
||||
error_reporting(E_ALL);
|
||||
ini_set('display_errors', 1);
|
||||
// Database connection details
|
||||
$host = "192.168.1.20";
|
||||
$database = "orologi";
|
||||
$user = "pdo";
|
||||
$password = "";
|
||||
|
||||
try {
|
||||
// Establish a connection to the database
|
||||
$connection = new PDO("mysql:host=$host;dbname=$database", $user, $password);
|
||||
$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
} catch (PDOException $e) {
|
||||
die("Error: " . $e->getMessage());
|
||||
}
|
||||
|
||||
// Handle CRUD operations for Marche
|
||||
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['action'])) {
|
||||
$action = $_POST['action'];
|
||||
|
||||
if ($action == 'add_marca') {
|
||||
$marca = $_POST['marca'];
|
||||
$nazione = $_POST['nazione'];
|
||||
$stmt = $connection->prepare("INSERT INTO marche (marca, nazione) VALUES (:marca, :nazione)");
|
||||
$stmt->execute(['marca' => $marca, 'nazione' => $nazione]);
|
||||
} elseif ($action == 'delete_marca') {
|
||||
$marca = $_POST['marca'];
|
||||
$stmt = $connection->prepare("DELETE FROM marche WHERE marca = :marca");
|
||||
$stmt->execute(['marca' => $marca]);
|
||||
} elseif ($action == 'update_marca') {
|
||||
$marca = $_POST['marca'];
|
||||
$nazione = $_POST['nazione'];
|
||||
$stmt = $connection->prepare("UPDATE marche SET nazione = :nazione WHERE marca = :marca");
|
||||
$stmt->execute(['marca' => $marca, 'nazione' => $nazione]);
|
||||
}
|
||||
|
||||
// Redirect to avoid form resubmission
|
||||
header("Location: dashboard.php");
|
||||
exit();
|
||||
}
|
||||
|
||||
// Handle CRUD operations for Orologi
|
||||
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['action'])) {
|
||||
$action = $_POST['action'];
|
||||
|
||||
// Handle Marche operations
|
||||
if ($action == 'add_marca') {
|
||||
$marca = $_POST['marca'];
|
||||
$nazione = $_POST['nazione'];
|
||||
$stmt = $connection->prepare("INSERT INTO marche (marca, nazione) VALUES (:marca, :nazione)");
|
||||
$stmt->execute(['marca' => $marca, 'nazione' => $nazione]);
|
||||
} elseif ($action == 'delete_marca') {
|
||||
$marca = $_POST['marca'];
|
||||
$stmt = $connection->prepare("DELETE FROM marche WHERE marca = :marca");
|
||||
$stmt->execute(['marca' => $marca]);
|
||||
} elseif ($action == 'update_marca') {
|
||||
$marca = $_POST['marca'];
|
||||
$nazione = $_POST['nazione'];
|
||||
$stmt = $connection->prepare("UPDATE marche SET nazione = :nazione WHERE marca = :marca");
|
||||
$stmt->execute(['marca' => $marca, 'nazione' => $nazione]);
|
||||
}
|
||||
// Handle Orologi operations
|
||||
elseif ($action == 'add_orologio') {
|
||||
try {
|
||||
$marca = $_POST['marca'];
|
||||
$modello = $_POST['modello'];
|
||||
$prezzo = $_POST['prezzo'];
|
||||
$descrizione = $_POST['descrizione'];
|
||||
|
||||
$checkMarca = $connection->prepare("SELECT marca FROM marche WHERE marca = :marca");
|
||||
$checkMarca->execute(['marca' => $marca]);
|
||||
if (!$checkMarca->fetch()) {
|
||||
echo "Error: Brand does not exist in marche table";
|
||||
die();
|
||||
}
|
||||
echo
|
||||
$stmt = $connection->prepare("INSERT INTO orologi (Marca, Modello, Prezzo, Descrizione) VALUES (:marca, :modello, :prezzo, :descrizione)");
|
||||
$stmt->execute(['marca' => $marca, 'modello' => $modello, 'prezzo' => $prezzo, 'descrizione' => $descrizione]);
|
||||
|
||||
if ($stmt->rowCount() > 0) {
|
||||
echo "Insert successful";
|
||||
} else {
|
||||
echo "Insert failed";
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
echo "Error: " . $e->getMessage();
|
||||
die();
|
||||
}
|
||||
} elseif ($action == 'delete_orologio') {
|
||||
$codice = $_POST['codice'];
|
||||
$stmt = $connection->prepare("DELETE FROM orologi WHERE Codice = :codice");
|
||||
$stmt->execute(['codice' => $codice]);
|
||||
} elseif ($action == 'update_orologio') {
|
||||
$codice = $_POST['codice'];
|
||||
$marca = $_POST['marca'];
|
||||
$modello = $_POST['modello'];
|
||||
$prezzo = $_POST['prezzo'];
|
||||
$descrizione = $_POST['descrizione'];
|
||||
$stmt = $connection->prepare("UPDATE orologi SET Marca = :marca, Modello = :modello, Prezzo = :prezzo, Descrizione = :descrizione WHERE Codice = :codice");
|
||||
$stmt->execute(['codice' => $codice, 'marca' => $marca, 'modello' => $modello, 'prezzo' => $prezzo, 'descrizione' => $descrizione]);
|
||||
}
|
||||
|
||||
// Single redirect after all operations
|
||||
header("Location: dashboard.php");
|
||||
exit();
|
||||
}
|
||||
|
||||
// Fetch all Marche and Orologi
|
||||
$marche = $connection->query("SELECT * FROM marche")->fetchAll(PDO::FETCH_ASSOC);
|
||||
$orologi = $connection->query("SELECT * FROM orologi")->fetchAll(PDO::FETCH_ASSOC);
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Admin Dashboard</title>
|
||||
<link rel="stylesheet" href="https://unpkg.com/@picocss/pico@2/css/pico.min.css">
|
||||
</head>
|
||||
<body>
|
||||
<main class="container">
|
||||
<h1>Admin Dashboard</h1>
|
||||
<a href="logout.php" class="button">Logout</a>
|
||||
|
||||
<!-- Marche Section -->
|
||||
<h2>Marche</h2>
|
||||
<form method="post">
|
||||
<input type="hidden" name="action" value="add_marca">
|
||||
<label for="marca">Marca:</label>
|
||||
<input type="text" id="marca" name="marca" required>
|
||||
<label for="nazione">Nazione:</label>
|
||||
<input type="text" id="nazione" name="nazione" required>
|
||||
<button type="submit">Add Marca</button>
|
||||
</form>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Marca</th>
|
||||
<th>Nazione</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($marche as $marca): ?>
|
||||
<tr>
|
||||
<td><?php echo htmlspecialchars($marca['marca']); ?></td>
|
||||
<td><?php echo htmlspecialchars($marca['nazione']); ?></td>
|
||||
<td>
|
||||
<form method="post" style="display:inline;">
|
||||
<input type="hidden" name="action" value="delete_marca">
|
||||
<input type="hidden" name="marca" value="<?php echo $marca['marca']; ?>">
|
||||
<button type="submit">Delete</button>
|
||||
</form>
|
||||
<form method="post" style="display:inline;">
|
||||
<input type="hidden" name="action" value="update_marca">
|
||||
<input type="hidden" name="marca" value="<?php echo $marca['marca']; ?>">
|
||||
<input type="text" name="nazione" placeholder="New Nazione" required>
|
||||
<button type="submit">Update</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<!-- Orologi Section -->
|
||||
<h2>Orologi</h2>
|
||||
<form method="post">
|
||||
<input type="hidden" name="action" value="add_orologio">
|
||||
<label for="marca">Marca:</label>
|
||||
<select id="marca" name="marca" required>
|
||||
<?php foreach ($marche as $marca): ?>
|
||||
<option value="<?php echo $marca['marca']; ?>"><?php echo $marca['marca']; ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<label for="modello">Modello:</label>
|
||||
<input type="text" id="modello" name="modello" required>
|
||||
<label for="prezzo">Prezzo:</label>
|
||||
<input type="number" id="prezzo" name="prezzo" required>
|
||||
<label for="descrizione">Descrizione:</label>
|
||||
<textarea id="descrizione" name="descrizione" required></textarea>
|
||||
<button type="submit">Add Orologio</button>
|
||||
</form>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Codice</th>
|
||||
<th>Marca</th>
|
||||
<th>Modello</th>
|
||||
<th>Prezzo</th>
|
||||
<th>Descrizione</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($orologi as $orologio): ?>
|
||||
<tr>
|
||||
<td><?php echo htmlspecialchars($orologio['Codice']); ?></td>
|
||||
<td><?php echo htmlspecialchars($orologio['Marca']); ?></td>
|
||||
<td><?php echo htmlspecialchars($orologio['Modello']); ?></td>
|
||||
<td><?php echo htmlspecialchars($orologio['Prezzo']); ?></td>
|
||||
<td><?php echo htmlspecialchars($orologio['Descrizione']); ?></td>
|
||||
<td>
|
||||
<form method="post" style="display:inline;">
|
||||
<input type="hidden" name="action" value="delete_orologio">
|
||||
<input type="hidden" name="codice" value="<?php echo $orologio['Codice']; ?>">
|
||||
<button type="submit">Delete</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
77
orologi/admin/login.php
Normal file
77
orologi/admin/login.php
Normal file
|
@ -0,0 +1,77 @@
|
|||
<?php
|
||||
session_start();
|
||||
|
||||
// Database connection details
|
||||
$host = "192.168.1.20";
|
||||
$database = "orologi";
|
||||
$user = "pdo";
|
||||
$password = "";
|
||||
|
||||
// Initialize error message
|
||||
$error = '';
|
||||
|
||||
// Check if the form is submitted
|
||||
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||
try {
|
||||
// Establish a connection to the database
|
||||
$connection = new PDO("mysql:host=$host;dbname=$database", $user, $password);
|
||||
$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
|
||||
// Get the username and password from the form
|
||||
$username = $_POST['username'];
|
||||
$password = $_POST['password'];
|
||||
|
||||
// Prepare the SQL statement to fetch the user
|
||||
$stmt = $connection->prepare("SELECT * FROM utenti WHERE user = :username");
|
||||
$stmt->execute(['username' => $username]);
|
||||
$user = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
// Verify the password
|
||||
if ($user && $user['password'] === $password) {
|
||||
// Password is correct, start a new session
|
||||
$_SESSION['user_id'] = $user['idut'];
|
||||
$_SESSION['username'] = $user['user'];
|
||||
$_SESSION['livello'] = $user['livello'];
|
||||
$_SESSION["login"] = true;
|
||||
|
||||
// Redirect to a different page after successful login
|
||||
header("Location: index.php");
|
||||
exit();
|
||||
} else {
|
||||
// Invalid credentials
|
||||
$error = "Invalid username or password.";
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
$error = "Error: " . $e->getMessage();
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Login</title>
|
||||
<link rel="stylesheet" href="https://unpkg.com/@picocss/pico@2/css/pico.min.css">
|
||||
</head>
|
||||
<body>
|
||||
<main class="container">
|
||||
<h1>Login</h1>
|
||||
<?php if ($error): ?>
|
||||
<div class="alert alert-danger"><?php echo $error; ?></div>
|
||||
<?php endif; ?>
|
||||
<form method="post" action="">
|
||||
<label for="username">Username:</label>
|
||||
<input <?php if ($error):
|
||||
echo "aria-invalid=\"true\""; endif; ?> type="text" id="username" name="username" required>
|
||||
|
||||
<label for="password">Password:</label>
|
||||
<input <?php if ($error):
|
||||
echo "aria-invalid=\"true\""; endif; ?> type="password" id="password" name="password" required>
|
||||
|
||||
<button type="submit">Login</button>
|
||||
</form>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
59
orologi/dettagli.php
Normal file
59
orologi/dettagli.php
Normal file
|
@ -0,0 +1,59 @@
|
|||
<?php
|
||||
|
||||
error_reporting(E_ALL);
|
||||
ini_set('display_errors', 1);
|
||||
|
||||
$host = "192.168.1.20";
|
||||
$database = "orologi";
|
||||
$user = "pdo";
|
||||
$password = "";
|
||||
|
||||
try {
|
||||
$connection = new PDO("mysql:host=$host;dbname=$database", $user, $password);
|
||||
|
||||
$prepare = $connection->prepare("SELECT * FROM orologi WHERE Codice = ?");
|
||||
$prepare->bindValue(1, $_GET["cod"], PDO::PARAM_INT);
|
||||
$prepare->execute();
|
||||
|
||||
if ($prepare->rowCount() == 0) {
|
||||
die("Non trovato");
|
||||
}
|
||||
$connection = null;
|
||||
|
||||
} catch (PDOException $e) {
|
||||
die ("Error!: " . $e->getMessage() . "<br/>");
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>HTML</title>
|
||||
<link
|
||||
rel="stylesheet"
|
||||
href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.min.css"
|
||||
>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<main class="container">
|
||||
<nav>
|
||||
<ul>
|
||||
<li><strong>Acme Corp</strong></li>
|
||||
</ul>
|
||||
<ul>
|
||||
<li><a href="index.php">Home</a></li>
|
||||
<li><a href="#">Login</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
<?php foreach ($prepare->fetchAll() as $row) : ?>
|
||||
<h1><?= $row["Marca"] . " " . $row["Modello"] ?></h1>
|
||||
<h2>Descrizione</h2>
|
||||
<p><?= $row["Descrizione"] ?></p>
|
||||
<h2>Prezzo: <?= $row["Prezzo"] ?> €</h2>
|
||||
<p><small>(Codice Orologio: <?= $row["Codice"] ?>)</p>
|
||||
<?php endforeach; ?>
|
||||
</main>
|
||||
</body>
|
||||
|
||||
</html>
|
96
orologi/index.php
Normal file
96
orologi/index.php
Normal file
|
@ -0,0 +1,96 @@
|
|||
<?php
|
||||
|
||||
error_reporting(E_ALL);
|
||||
ini_set('display_errors', 1);
|
||||
|
||||
$host = "192.168.1.20";
|
||||
$database = "orologi";
|
||||
$user = "pdo";
|
||||
$password = "";
|
||||
|
||||
try {
|
||||
$connection = new PDO("mysql:host=$host;dbname=$database", $user, $password);
|
||||
$marche = $connection->prepare("SELECT marca FROM marche");
|
||||
$marche->execute();
|
||||
|
||||
if (empty($_GET["marca"])) {
|
||||
$prepare = $connection->prepare("SELECT Codice, Modello, Marca, Prezzo FROM orologi ORDER BY Marca");
|
||||
} else {
|
||||
$marca = $_GET["marca"];
|
||||
$prepare = $connection->prepare("SELECT Codice, Modello, Marca, Prezzo FROM orologi WHERE Marca = ? ORDER BY Marca");
|
||||
$prepare->bindParam(1, $marca);
|
||||
}
|
||||
|
||||
$prepare->execute();
|
||||
|
||||
$connection = null;
|
||||
|
||||
} catch (PDOException $e) {
|
||||
die ("Error!: " . $e->getMessage() . "<br/>");
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>HTML</title>
|
||||
<link
|
||||
rel="stylesheet"
|
||||
href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.min.css"
|
||||
>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<main class="container">
|
||||
<nav>
|
||||
<ul>
|
||||
<li><strong>Acme Corp</strong></li>
|
||||
</ul>
|
||||
<ul>
|
||||
<li>
|
||||
<form>
|
||||
<select name="favorite-cuisine" aria-label="Cerca per Marca" required
|
||||
onchange="redirectToMarca(this)">
|
||||
<option selected disabled value="">
|
||||
Cerca per Marca
|
||||
</option>
|
||||
<?php foreach ($marche->fetchAll() as $rw) : ?>
|
||||
<option value=<?= $rw["marca"] ?>><?= $rw["marca"] ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</form>
|
||||
</li>
|
||||
</ul>
|
||||
<ul>
|
||||
<li><a href="#">Login</a></li>
|
||||
<li><a href="index.php">Home</a></li>
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
<div class="grid">
|
||||
<?php foreach ($prepare->fetchAll() as $row) : ?>
|
||||
<?= "<div>" ?>
|
||||
<article>
|
||||
<header><a href=<?= "dettagli.php?cod=" . $row["Codice"] ?>><b><?= $row["Modello"] ?></b></a>
|
||||
</header>
|
||||
<?= $row["Marca"] ?>
|
||||
<footer>Prezzo: <?= $row["Prezzo"] ?> €</footer>
|
||||
</article>
|
||||
<?= "</div>" ?>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<script>
|
||||
function redirectToMarca(selectElement) {
|
||||
const selectedMarca = selectElement.value;
|
||||
if (selectedMarca) {
|
||||
window.location.href = `index.php?marca=${encodeURIComponent(selectedMarca)}`;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
||||
|
||||
</html>
|
Loading…
Add table
Add a link
Reference in a new issue