2019-11-10 15:55:06 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require_once("./assets/php/utils.php");
|
|
|
|
|
|
|
|
if (!is_connected()) {
|
|
|
|
header("location: login.php");
|
|
|
|
}
|
|
|
|
|
2019-11-16 23:12:11 +01:00
|
|
|
$erreur = $edit_id = $edit_name = $edit_description = "";
|
2019-11-12 00:35:30 +01:00
|
|
|
|
|
|
|
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST["delete"])) {
|
|
|
|
if (!delete_cupboard($_POST["delete"])) {
|
|
|
|
$erreur = "<p>An item is in this cupboard, you can't delete it now.</p>\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-16 23:12:11 +01:00
|
|
|
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST["edit"])) {
|
|
|
|
if (isset($_POST["edit"]))
|
|
|
|
foreach (get_users_cupboards_array() as $cupboard) {
|
|
|
|
if ($cupboard["public_id"] === $_POST["edit"]) {
|
|
|
|
$edit_id = $_POST["edit"];
|
|
|
|
$edit_name = $cupboard["name"];
|
|
|
|
$edit_description = $cupboard["description"];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST["edit_completed"])) {
|
|
|
|
if (isset($_POST["name"]) && isset($_POST["description"])) {
|
|
|
|
if (!update_cupboard($_POST["edit_completed"], $_POST["name"], $_POST["description"])) {
|
|
|
|
$erreur = "<p>Something went wrong. Try again later.</p>";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$erreur = "<p>One of the edited section is missing.</p>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-10 15:55:06 +01:00
|
|
|
$cupboard_list = "";
|
|
|
|
foreach (get_users_cupboards_array() as $row) {
|
2019-11-11 14:42:07 +01:00
|
|
|
$cupboard_list = $cupboard_list . "<tr><td>"
|
|
|
|
. htmlspecialchars($row["name"])
|
|
|
|
. "</td><td>"
|
|
|
|
. htmlspecialchars($row["description"])
|
2019-11-12 00:35:30 +01:00
|
|
|
. "</td><td>"
|
2019-11-16 23:12:11 +01:00
|
|
|
. "<form method='post'><button type='publish' name='edit' value='"
|
|
|
|
. $row["public_id"] . "'>Editer</button></form>"
|
|
|
|
. "</td><td>"
|
|
|
|
. "<form method='post'><button type='publish' name='delete' value='"
|
|
|
|
. $row["public_id"] . "'>Delete</button></form>"
|
2019-11-11 14:42:07 +01:00
|
|
|
. "</td></tr>\n";
|
2019-11-10 15:55:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
?>
|
|
|
|
|
|
|
|
<!DOCTYPE html>
|
|
|
|
<html lang="en">
|
2019-11-11 14:42:07 +01:00
|
|
|
|
2019-11-10 15:55:06 +01:00
|
|
|
<head>
|
|
|
|
<meta charset="UTF-8">
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
|
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
2019-11-11 14:42:07 +01:00
|
|
|
<style type="text/css">
|
|
|
|
table,
|
|
|
|
th,
|
|
|
|
td {
|
|
|
|
border: 1px solid #333;
|
|
|
|
}
|
|
|
|
</style>
|
2019-11-10 15:55:06 +01:00
|
|
|
<title>List cupboard</title>
|
|
|
|
</head>
|
2019-11-11 14:42:07 +01:00
|
|
|
|
2019-11-10 15:55:06 +01:00
|
|
|
<body>
|
2019-11-12 00:35:30 +01:00
|
|
|
<?php echo $erreur; ?>
|
2019-11-16 23:12:11 +01:00
|
|
|
<?php
|
|
|
|
if ($edit_id !== "") {
|
|
|
|
?>
|
|
|
|
<form method="post">
|
|
|
|
<label>Nom : </label><input type="text" name="name" value="<?php echo $edit_name; ?>">
|
|
|
|
<label>Description : </label><input type="text" name="description" value="<?php echo $edit_description; ?>">
|
|
|
|
<button type="publish" name="edit_completed" value="<?php echo $edit_id; ?>">Valider</button>
|
|
|
|
</form>
|
|
|
|
<?php
|
|
|
|
}
|
|
|
|
?>
|
2019-11-11 14:42:07 +01:00
|
|
|
<table>
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<th>
|
|
|
|
Nom
|
|
|
|
</th>
|
|
|
|
<th>
|
|
|
|
Description
|
|
|
|
</th>
|
2019-11-16 23:12:11 +01:00
|
|
|
<th>
|
|
|
|
Editer
|
|
|
|
</th>
|
2019-11-12 00:36:52 +01:00
|
|
|
<th>
|
2019-11-12 00:35:30 +01:00
|
|
|
Supprimer
|
2019-11-12 00:36:52 +01:00
|
|
|
</th>
|
2019-11-11 14:42:07 +01:00
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
<?php echo $cupboard_list; ?>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
2019-11-10 15:55:06 +01:00
|
|
|
</body>
|
2019-11-11 14:42:07 +01:00
|
|
|
|
|
|
|
</html>
|