verifica
This commit is contained in:
parent
2c82d90dd4
commit
5f80048cec
20 changed files with 999 additions and 1 deletions
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
require_once('../../includes/functions.php');
|
||||
checkSession();
|
||||
|
||||
try {
|
||||
$connection = getDbConnection();
|
||||
$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
$prepare = $connection->prepare("INSERT INTO `modello` (`codice`, `descrizione`, `quantita`, `tipologia`) VALUES (NULL, ?, ?, ?);");
|
||||
$prepare->bindParam(1, $_POST['descrizione']);
|
||||
$prepare->bindParam(2, $_POST['quantita']);
|
||||
$prepare->bindParam(3, $_POST['tipologia']);
|
||||
|
||||
try {
|
||||
$prepare->execute();
|
||||
} catch (PDOException $e) {
|
||||
echo "Impossibile inserire il modello, controllare i dati";
|
||||
die($e->getMessage());
|
||||
}
|
||||
|
||||
} catch (PDOException $e) {
|
||||
die("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="../../includes/css/pico.min.css">
|
||||
</head>
|
||||
<body>
|
||||
<main class="container">
|
||||
<a href="../dashboard.php" class="button">Torna alla dashboard</a>
|
||||
<h2>Operazione eseguita con successo</h2>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
require_once('../../includes/functions.php');
|
||||
checkSession();
|
||||
|
||||
try {
|
||||
$connection = getDbConnection();
|
||||
$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
$prepare = $connection->prepare("DELETE FROM modello WHERE codice = ?;");
|
||||
$prepare->bindParam(1, $_POST['codice']);
|
||||
|
||||
try {
|
||||
$prepare->execute();
|
||||
} catch (PDOException $e) {
|
||||
echo "Impossibile inserire il modello, controllare i dati";
|
||||
die($e->getMessage());
|
||||
}
|
||||
|
||||
} catch (PDOException $e) {
|
||||
die("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="../../includes/css/pico.min.css">
|
||||
</head>
|
||||
<body>
|
||||
<main class="container">
|
||||
<a href="../dashboard.php" class="button">Torna alla dashboard</a>
|
||||
<h2>Operazione eseguita con successo</h2>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
require_once('../../includes/functions.php');
|
||||
checkSession();
|
||||
|
||||
try {
|
||||
$connection = getDbConnection();
|
||||
$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
$tipologia = $_GET["tipologia"];
|
||||
$prepare = $connection->prepare("SELECT t.nome
|
||||
FROM modello AS m
|
||||
INNER JOIN biciclette.tipologia t on m.tipologia = t.codice
|
||||
WHERE m.tipologia = ?
|
||||
ORDER BY t.codice");
|
||||
|
||||
$prepare->bindParam(1, $tipologia);
|
||||
$prepare->execute();
|
||||
|
||||
if ($prepare->rowCount() >= 1) {
|
||||
$bici = $prepare->fetchAll();
|
||||
$quantita = $prepare->rowCount();
|
||||
$tipologia = $bici[0]['nome'];
|
||||
} else {
|
||||
echo "nessuna quantita";
|
||||
}
|
||||
|
||||
} catch (PDOException $e) {
|
||||
die("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="../../includes/css/pico.min.css">
|
||||
</head>
|
||||
<body>
|
||||
<main class="container">
|
||||
<a href="../dashboard.php" class="button">Torna alla dashboard</a>
|
||||
|
||||
<h1>Quantita per tipologia: <?php echo $tipologia ?></h1>
|
||||
<h1><?= $quantita ?></h1>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
82
moro_detto_rocco_andrea_biciclette/admin/dashboard.php
Normal file
82
moro_detto_rocco_andrea_biciclette/admin/dashboard.php
Normal file
|
@ -0,0 +1,82 @@
|
|||
<?php
|
||||
require_once('../includes/functions.php');
|
||||
|
||||
checkSession();
|
||||
|
||||
error_reporting(E_ALL);
|
||||
ini_set('display_errors', 1);
|
||||
|
||||
try {
|
||||
$connection = getDbConnection();
|
||||
$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
} catch (PDOException $e) {
|
||||
die("Error: " . $e->getMessage());
|
||||
}
|
||||
$marche = $connection->query("SELECT * FROM tipologia")->fetchAll(PDO::FETCH_ASSOC);
|
||||
$biciclette = $connection->query("SELECT * FROM modello")->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="../includes/css/pico.min.css">
|
||||
</head>
|
||||
<body>
|
||||
<main class="container">
|
||||
<h1>Admin Dashboard</h1>
|
||||
<a href="logout.php" class="button">Logout</a>
|
||||
|
||||
<!-- Tipologia Section -->
|
||||
<h2>Tipologia</h2>
|
||||
<form method="get" action="actions/getQuantityTipologia.php">
|
||||
<label for="tipologia">Tipologia:</label>
|
||||
<select name="tipologia" aria-label="Cerca per tipologia" required>
|
||||
<option selected disabled value="">
|
||||
Cerca per Tipologia
|
||||
</option>
|
||||
<?php foreach ($marche as $rw) : ?>
|
||||
<option value=<?= $rw["codice"] ?>><?= $rw["nome"] ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<button type="submit">Cerca</button>
|
||||
</form>
|
||||
|
||||
<!-- Add bici Section -->
|
||||
<h2>Aggiungi Bicicletta</h2>
|
||||
<form method="post" action="actions/addNewBike.php">
|
||||
<label for="descrizione">Descrizione</label>
|
||||
<input type="text" name="descrizione" id="descrizione" required>
|
||||
<label for="quantita">Quantità</label>
|
||||
<input type="text" name="quantita" id="quantita" required>
|
||||
<label for="tipologia">Tipologia:</label>
|
||||
<select name="tipologia" aria-label="Cerca per tipologia" required>
|
||||
<option selected disabled value="">
|
||||
Cerca per Tipologia
|
||||
</option>
|
||||
<?php foreach ($marche as $rw) : ?>
|
||||
<option value=<?= $rw["codice"] ?>><?= $rw["nome"] ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<button type="submit">Aggiungi</button>
|
||||
</form>
|
||||
|
||||
<!--Delete biciclette-->
|
||||
<h2>Cancella biciclette</h2>
|
||||
<form method="post" action="actions/deleteBike.php">
|
||||
<label for="codice">Bici:</label>
|
||||
<select name="codice" aria-label="Seleziona bici" required>
|
||||
<option selected disabled value="">
|
||||
Seleziona Bicicletta
|
||||
</option>
|
||||
<?php foreach ($biciclette as $rw) : ?>
|
||||
<option value=<?= $rw["codice"] ?>><?= $rw["descrizione"] ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<button type="submit">Cancella</button>
|
||||
</form>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
66
moro_detto_rocco_andrea_biciclette/admin/login.php
Normal file
66
moro_detto_rocco_andrea_biciclette/admin/login.php
Normal file
|
@ -0,0 +1,66 @@
|
|||
<?php
|
||||
require_once '../includes/functions.php';
|
||||
$error = $_SESSION["error"];
|
||||
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||
try {
|
||||
$connection = getDbConnection();
|
||||
$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
|
||||
$username = $_POST['username'];
|
||||
$password = $_POST['password'];
|
||||
|
||||
$stmt = $connection->prepare("SELECT * FROM utenti WHERE user = :username AND password = :password");
|
||||
$stmt->bindParam(':username', $username);
|
||||
$stmt->bindParam(':password', $password);
|
||||
$stmt->execute();
|
||||
$user = $stmt->fetch();
|
||||
|
||||
if ($user) {
|
||||
if ($user['llivello'] == 0) {
|
||||
$_SESSION['user_id'] = $user['idut'];
|
||||
$_SESSION['username'] = $user['user'];
|
||||
$_SESSION['livello'] = $user['livello'];
|
||||
$_SESSION["login"] = true;
|
||||
|
||||
header('Location: dashboard.php');
|
||||
} else {
|
||||
$_SESSION["error"] = "Invalid username or password.";
|
||||
}
|
||||
} else {
|
||||
$_SESSION["error"] = "Utente non trovato.";
|
||||
}
|
||||
|
||||
} 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="../includes/css/pico.min.css">
|
||||
</head>
|
||||
<body>
|
||||
<main class="container">
|
||||
<h1>Login</h1>
|
||||
<?php if (!empty($_SESSION["error"])): ?>
|
||||
<div class="alert alert-danger"><?php echo $_SESSION["error"]; ?></div>
|
||||
<?php endif; ?>
|
||||
<form method="post" action="">
|
||||
<label for="username">Username:</label>
|
||||
<input <?php if (!empty($_SESSION["error"])):
|
||||
echo "aria-invalid=\"true\""; endif; ?> type="text" id="username" name="username" required>
|
||||
|
||||
<label for="password">Password:</label>
|
||||
<input <?php if (!empty($_SESSION["error"])):
|
||||
echo "aria-invalid=\"true\""; endif; ?> type="password" id="password" name="password" required>
|
||||
|
||||
<button type="submit">Login</button>
|
||||
</form>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
5
moro_detto_rocco_andrea_biciclette/admin/logout.php
Normal file
5
moro_detto_rocco_andrea_biciclette/admin/logout.php
Normal file
|
@ -0,0 +1,5 @@
|
|||
<?php
|
||||
session_start();
|
||||
session_destroy();
|
||||
header("location:login.php");
|
||||
|
4
moro_detto_rocco_andrea_biciclette/includes/css/pico.min.css
vendored
Normal file
4
moro_detto_rocco_andrea_biciclette/includes/css/pico.min.css
vendored
Normal file
File diff suppressed because one or more lines are too long
2
moro_detto_rocco_andrea_biciclette/includes/footer.php
Normal file
2
moro_detto_rocco_andrea_biciclette/includes/footer.php
Normal file
|
@ -0,0 +1,2 @@
|
|||
<script src="/moro_detto_rocco_verifica_php/includes/js/bootstrap.bundle.js"
|
||||
crossorigin="anonymous"></script>
|
24
moro_detto_rocco_andrea_biciclette/includes/functions.php
Normal file
24
moro_detto_rocco_andrea_biciclette/includes/functions.php
Normal file
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
session_start();
|
||||
|
||||
$host = "127.0.0.1";
|
||||
$database = "biciclette";
|
||||
$user = "pdo";
|
||||
$password = "";
|
||||
|
||||
function getDbConnection()
|
||||
{
|
||||
global $host, $database, $user, $password, $database;
|
||||
return new PDO("mysql:host=$host;dbname=$database", $user, $password);
|
||||
}
|
||||
|
||||
function checkSession()
|
||||
{
|
||||
if (empty($_SESSION["llivello"]) || empty($_SESSION["login"])) {
|
||||
if($_SESSION["llivello"] != 0){
|
||||
$_SESSION["error"] = "Errore interno (Sessione non trovata)";
|
||||
header("Location: login.php");
|
||||
exit();
|
||||
}
|
||||
}
|
||||
}
|
1
moro_detto_rocco_andrea_biciclette/includes/head.php
Normal file
1
moro_detto_rocco_andrea_biciclette/includes/head.php
Normal file
|
@ -0,0 +1 @@
|
|||
<link rel="stylesheet" href="includes/css/pico.min.css" >
|
96
moro_detto_rocco_andrea_biciclette/index.php
Normal file
96
moro_detto_rocco_andrea_biciclette/index.php
Normal file
|
@ -0,0 +1,96 @@
|
|||
<?php
|
||||
require "includes/functions.php";
|
||||
|
||||
error_reporting(E_ALL);
|
||||
ini_set('display_errors', 1);
|
||||
|
||||
try {
|
||||
$connection = getDbConnection();
|
||||
$modello = $connection->prepare("SELECT codice, nome FROM tipologia");
|
||||
$modello->execute();
|
||||
|
||||
if (empty($_GET["cod"])) {
|
||||
$prepare = $connection->prepare("SELECT m.codice, m.descrizione, m.quantita, m.tipologia, t.nome
|
||||
FROM modello AS m
|
||||
INNER JOIN biciclette.tipologia t on m.tipologia = t.codice
|
||||
ORDER BY codice");
|
||||
} else {
|
||||
$codice_modello = $_GET["cod"];
|
||||
$prepare = $connection->prepare("SELECT m.codice, m.descrizione, m.quantita, t.nome
|
||||
FROM modello AS m
|
||||
INNER JOIN biciclette.tipologia t on m.tipologia = t.codice
|
||||
WHERE m.tipologia = ?
|
||||
ORDER BY t.codice");
|
||||
$prepare->bindParam(1, $codice_modello);
|
||||
}
|
||||
|
||||
$prepare->execute();
|
||||
$connection = null;
|
||||
} catch (PDOException $e) {
|
||||
die ("Error!: " . $e->getMessage() . "<br/>");
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>HTML</title>
|
||||
<?php require "includes/head.php"; ?>
|
||||
</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>
|
||||
<option value="">Tutte</option>
|
||||
<?php foreach ($modello->fetchAll() as $rw) : ?>
|
||||
<option value=<?= $rw["codice"] ?>><?= $rw["nome"] ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</form>
|
||||
</li>
|
||||
</ul>
|
||||
<ul>
|
||||
<li><a href="#">Login</a></li>
|
||||
<li><a href="index.php">Home</a></li>
|
||||
<li><a href="listino.php">Listino</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["descrizione"] ?></b></a>
|
||||
</header>
|
||||
<?= $row["nome"] ?>
|
||||
<footer>Quantità: <?= $row["quantita"] ?></footer>
|
||||
</article>
|
||||
<?= "</div>" ?>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<script>
|
||||
function redirectToMarca(selectElement) {
|
||||
const selectedMarca = selectElement.value;
|
||||
if (selectedMarca) {
|
||||
window.location.href = `index.php?cod=${encodeURIComponent(selectedMarca)}`;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
||||
|
||||
</html>
|
72
moro_detto_rocco_andrea_biciclette/listino.php
Normal file
72
moro_detto_rocco_andrea_biciclette/listino.php
Normal file
|
@ -0,0 +1,72 @@
|
|||
<?php
|
||||
require "includes/functions.php";
|
||||
|
||||
error_reporting(E_ALL);
|
||||
ini_set('display_errors', 1);
|
||||
|
||||
try {
|
||||
$connection = getDbConnection();
|
||||
$prepare = $connection->prepare("SELECT m.codice, m.descrizione, m.quantita, t.nome, t.codice AS codice_modello
|
||||
FROM modello AS m
|
||||
INNER JOIN biciclette.tipologia t on m.tipologia = t.codice
|
||||
ORDER BY m.codice");
|
||||
|
||||
$prepare->execute();
|
||||
$connection = null;
|
||||
} catch (PDOException $e) {
|
||||
die ("Error!: " . $e->getMessage() . "<br/>");
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>HTML</title>
|
||||
<?php require "includes/head.php"; ?>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<main class="container">
|
||||
<nav>
|
||||
<ul>
|
||||
<li><strong>Acme Corp</strong></li>
|
||||
</ul>
|
||||
<ul>
|
||||
<li><a href="#">Login</a></li>
|
||||
<li><a href="index.php">Home</a></li>
|
||||
<li><a href="listino.php">Listino</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
<div class="grid">
|
||||
<table>
|
||||
<tr>
|
||||
<th>Codice</th>
|
||||
<th>Descrizione</th>
|
||||
<th>Quantità</th>
|
||||
<th>Tipologia</th>
|
||||
</tr>
|
||||
<?php foreach ($prepare->fetchAll() as $model) : ?>
|
||||
<tr>
|
||||
<td><?= $model["codice"] ?></td>
|
||||
<td><?= $model["descrizione"] ?></td>
|
||||
<td><?= $model["quantita"] ?></td>
|
||||
<td><a href="index.php?cod=<?= $model["codice_modello"] ?>"><?= $model["nome"] ?></a></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</table>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<script>
|
||||
function redirectToMarca(selectElement) {
|
||||
const selectedMarca = selectElement.value;
|
||||
if (selectedMarca) {
|
||||
window.location.href = `index.php?cod=${encodeURIComponent(selectedMarca)}`;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
||||
|
||||
</html>
|
Loading…
Add table
Add a link
Reference in a new issue