Skip to content
Snippets Groups Projects
Commit ac5453c8 authored by Graham Cole's avatar Graham Cole
Browse files

Allow admins to remove unrequested junk items, no questions asked. (plus a...

Allow admins to remove unrequested junk items, no questions asked. (plus a little extra error handling)
parent 372d3655
No related branches found
No related tags found
No related merge requests found
......@@ -75,9 +75,13 @@ if ($session->loggedin && isset($_REQUEST['action'])) {
$DB->Query($query, $_REQUEST['item']);
}
elseif ($_REQUEST['action'] == "Remove" && $admin){
// Remove item, if you're admin and its been taken
$query = "DELETE FROM inventory WHERE id=? AND taken_on IS NOT NULL";
$DB->Query($query, $_REQUEST['item']);
// Remove item, if you're admin
$query = "DELETE FROM inventory WHERE id=?";
if ($DB->Query($query, $_REQUEST['item'])) {
message_flash("Item removed");
} else {
trigger_error("Failed to remove item");
}
}
elseif ($_REQUEST['action'] == "Not Junk" && $admin){
// Mark item as not junk if it's not been requested and you're admin
......@@ -121,14 +125,21 @@ if ($session->loggedin && $admin && (isset($_REQUEST['update']) || isset($_REQUE
if(isset($_REQUEST['update'])){
$query = "UPDATE inventory SET title=?, category=?, description=?, donated_by=?, status=? WHERE id=?";
$array = array($_REQUEST['title'], $category, $description, $donated_by, $_REQUEST['status'], $_REQUEST['id']);
message_flash("Item Updated");
if ($DB->Query($query, $array)) {
message_flash("Item Updated");
} else {
trigger_error("Item update failed :-(", E_USER_ERROR);
}
}
elseif(isset($_REQUEST['add'])){
$query = "INSERT INTO inventory (title, category, description, donated_by, status) VALUES (?, ?, ?, ?, ?)";
$array = array($_REQUEST['title'], $category, $description, $donated_by, $_REQUEST['status']);
message_flash("Item Added");
if ($DB->Query($query, $array)) {
message_flash("Item Added");
} else {
trigger_error("Adding item failed :-( - ".$DB->ErrorMsg(), E_USER_ERROR);
}
}
$DB->Query($query, $array);
}
else{
trigger_error("Required field(s) missing", E_USER_WARNING);
......
......@@ -36,10 +36,9 @@
{if $admin}
{if $item.requested_by!=null && $item.taken_on==null}
<input type="submit" name="action" value="Item Taken" />
{elseif $item.taken_on!=null}
<input type="submit" name="action" value="Remove" />
{elseif $item.requested_by==null}
<input type="submit" name="action" value="Not Junk" />
<input type="submit" name="action" value="Remove" />
{/if}
{/if}
{elseif $admin}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment