added a way to delete cupboards
This commit is contained in:
parent
d7556a9edb
commit
2b9b667bdd
@ -305,7 +305,7 @@ function get_users_cupboards_array()
|
|||||||
$user_cupboards = array();
|
$user_cupboards = array();
|
||||||
|
|
||||||
$sql = "SELECT
|
$sql = "SELECT
|
||||||
id, name, description, public_id
|
id, name, description, cupboards.public_id AS public_id
|
||||||
FROM cupboards WHERE owner_id = :owner_id;";
|
FROM cupboards WHERE owner_id = :owner_id;";
|
||||||
|
|
||||||
$query = $PDO->prepare($sql);
|
$query = $PDO->prepare($sql);
|
||||||
@ -317,3 +317,15 @@ function get_users_cupboards_array()
|
|||||||
}
|
}
|
||||||
return $user_cupboards;
|
return $user_cupboards;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function delete_cupboard($cupboard_public_id)
|
||||||
|
{
|
||||||
|
global $PDO;
|
||||||
|
|
||||||
|
$sql = "DELETE cupboards FROM cupboards INNER JOIN accounts ON cupboards.owner_id = accounts.id WHERE cupboards.public_id = :id;";
|
||||||
|
$query = $PDO->prepare($sql);
|
||||||
|
|
||||||
|
$query->bindValue(":id", $cupboard_public_id);
|
||||||
|
|
||||||
|
return $query->execute();
|
||||||
|
}
|
||||||
|
@ -6,12 +6,22 @@ if (!is_connected()) {
|
|||||||
header("location: login.php");
|
header("location: login.php");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$erreur = "";
|
||||||
|
|
||||||
|
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";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$cupboard_list = "";
|
$cupboard_list = "";
|
||||||
foreach (get_users_cupboards_array() as $row) {
|
foreach (get_users_cupboards_array() as $row) {
|
||||||
$cupboard_list = $cupboard_list . "<tr><td>"
|
$cupboard_list = $cupboard_list . "<tr><td>"
|
||||||
. htmlspecialchars($row["name"])
|
. htmlspecialchars($row["name"])
|
||||||
. "</td><td>"
|
. "</td><td>"
|
||||||
. htmlspecialchars($row["description"])
|
. htmlspecialchars($row["description"])
|
||||||
|
. "</td><td>"
|
||||||
|
. "<form method='post'><button type='publish' name='delete' value='" . $row["public_id"] . "'>Delete</button></form>"
|
||||||
. "</td></tr>\n";
|
. "</td></tr>\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,6 +45,7 @@ foreach (get_users_cupboards_array() as $row) {
|
|||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
<?php echo $erreur; ?>
|
||||||
<table>
|
<table>
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
@ -44,6 +55,9 @@ foreach (get_users_cupboards_array() as $row) {
|
|||||||
<th>
|
<th>
|
||||||
Description
|
Description
|
||||||
</th>
|
</th>
|
||||||
|
<td>
|
||||||
|
Supprimer
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
Loading…
Reference in New Issue
Block a user