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

allow junk item categories to be selected from a drop-down list

parent 132df0ed
No related branches found
No related tags found
No related merge requests found
......@@ -82,8 +82,16 @@ if ($session->loggedin && isset($_REQUEST['action'])) {
}
// Update/Add item
if ($session->loggedin && $admin && (isset($_REQUEST['update']) || isset($_REQUEST['add']))) {
// try to guess which category field the user meant us to see
// ideally we'd use an html combo box, but since they don't exist...
if ($_REQUEST['categorymenu'] == "") {
$category = $_REQUEST['category'];
} else {
$category = $_REQUEST['categorymenu'];
}
// Update/Add item if title and category are filled in else error
if ($_REQUEST['title'] != "" && $_REQUEST['category'] != "") {
if ($_REQUEST['title'] != "" && $category != "") {
// if the description is blank, return null
if ($_REQUEST['description'] == ""){
$description = null;
......@@ -101,12 +109,12 @@ if ($session->loggedin && $admin && (isset($_REQUEST['update']) || isset($_REQUE
// run the query
if(isset($_REQUEST['update'])){
$query = "UPDATE inventory SET title=?, category=?, description=?, donated_by=?, status=? WHERE id=?";
$array = array($_REQUEST['title'], $_REQUEST['category'], $description, $donated_by, $_REQUEST['status'], $_REQUEST['id']);
$array = array($_REQUEST['title'], $category, $description, $donated_by, $_REQUEST['status'], $_REQUEST['id']);
message_flash("Item Updated");
}
elseif(isset($_REQUEST['add'])){
$query = "INSERT INTO inventory (title, category, description, donated_by, status) VALUES (?, ?, ?, ?, ?)";
$array = array($_REQUEST['title'], $_REQUEST['category'], $description, $donated_by, $_REQUEST['status']);
$array = array($_REQUEST['title'], $category, $description, $donated_by, $_REQUEST['status']);
message_flash("Item Added");
}
$DB->Query($query, $array);
......@@ -150,6 +158,9 @@ if ($mode == 'list'){
if (sizeof($junk) < 1) {
$mode = "nojunk";
}
} else {
$categories = $DB->GetCol("SELECT DISTINCT category FROM inventory ORDER BY category ASC");
$smarty->assign("categories", $categories);
}
// Generate output
......
......@@ -10,7 +10,7 @@
<li>
<strong>{$item.title}:</strong> {$item.description}
{if $item.donated_by != null}
<br /><strong>Donated by:</strong> {$item.donated_by}
<br /><small>Donated by {$item.donated_by}</small>
{/if}
{if $status == 'requested'}
<br /><small>Requested by {$item.requested_by} on {$item.requested_on|date_format:"%e %b %Y"}</small>
......@@ -73,7 +73,18 @@
</div>
<div class="row">
<label for="category">Category*</label>
<span class="textinput"><input type="text" name="category"{if $mode == 'edit'} value="{$item.category}"{/if} /></span>
<span class="textinput">
<select name="categorymenu">
<option value="">Other...</option>
{foreach name=categories from=$categories item=category}
<option{if ($category == $item.category) && ($mode == 'edit')} selected="selected"{/if}>{$category}</option>
{/foreach}
</select>
</span>
<span class="textinput">
<div class="note">If none of the existing categories apply, enter one below:</div>
<input type="text" name="category"/>
</span>
</div>
<div class="row">
<label for="description">Description</label>
......@@ -97,7 +108,7 @@
</div>
<div class="row">
<span class="textinput"><input type="submit" name="{if $mode == 'edit'}update{else}add{/if}" value="{if $mode == 'edit'}Update{else}Add{/if}" /></span>
<div class="note row">* denotes require fields</div>
<div class="note row">* denotes required fields</div>
</div>
<div class="clear"></div>
</form>
......
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