From bb3f4d46aeaaa98a7e064eb13724500b09812964 Mon Sep 17 00:00:00 2001 From: Graham Cole <chckens@sucs.org> Date: Fri, 13 Jun 2008 18:05:49 +0000 Subject: [PATCH] allow junk item categories to be selected from a drop-down list --- components/junk.php | 17 ++++++++++++++--- templates/junk.tpl | 17 ++++++++++++++--- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/components/junk.php b/components/junk.php index 2de0bf6..9c5e848 100644 --- a/components/junk.php +++ b/components/junk.php @@ -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 diff --git a/templates/junk.tpl b/templates/junk.tpl index 1c2b782..bc78ad2 100644 --- a/templates/junk.tpl +++ b/templates/junk.tpl @@ -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> -- GitLab