+ global $all_items;
+
+ if ($selected_id == null)
+ $selected_id = (!isset($_POST[$name]) ? "" : $_POST[$name]);
+ $no_item_list = get_company_pref('no_item_list');
+ if ($no_item_list)
+ {
+ $edit_name = $name."_edit";
+ $edit_button = $name."_button";
+
+ $val = (isset($_POST[$edit_name]) && $_POST[$edit_name] != "" ? $_POST[$edit_name] : "");
+ if (isset($_POST[$edit_button]))
+ {
+ $selected_id = $_POST[$name] = "";
+ }
+
+ if ($selected_id != "")
+ {
+ $val = DEFVAL;
+ $sql = "SELECT stock_id, ".TB_PREF."stock_master.description, ".TB_PREF."stock_category.description
+ FROM ".TB_PREF."stock_master,".TB_PREF."stock_category WHERE ".TB_PREF."stock_master.category_id=".TB_PREF."stock_category.category_id
+ AND mb_flag !='M' AND stock_id='$selected_id'";
+ $result = db_query($sql);
+ }
+ else
+ {
+ if ($val != "" && $val != DEFVAL)
+ {
+ $sql = "SELECT stock_id, ".TB_PREF."stock_master.description, ".TB_PREF."stock_category.description
+ FROM ".TB_PREF."stock_master,".TB_PREF."stock_category WHERE "
+ .TB_PREF."stock_master.category_id=".TB_PREF."stock_category.category_id AND mb_flag !='M' AND
+ (stock_id LIKE '%{$val}%' OR ".TB_PREF."stock_category.description LIKE '%{$val}%' OR "
+ .TB_PREF."stock_master.description LIKE '%{$val}%')";
+ $result = db_query($sql);
+ }
+ else
+ $result = false;
+ }
+
+ echo "<input type='text' name='$edit_name' size='8' maxlength='50' value='$val' > ";
+
+ echo "<input type='submit' class='inputsubmit' name='$edit_button' value='?'> ";
+ }
+ else
+ {
+ $sql = "SELECT stock_id, ".TB_PREF."stock_master.description, ".TB_PREF."stock_category.description
+ FROM ".TB_PREF."stock_master,".TB_PREF."stock_category WHERE ".TB_PREF."stock_master.category_id="
+ .TB_PREF."stock_category.category_id AND mb_flag !='M'";
+ $result = db_query($sql);
+ }
+
+ if ($submit_on_change==true)
+ echo "<select name='$name' onchange='this.form.submit();'>";
+ else if ($extra != "")
+ echo "<select name='$name' $extra>";
+ else
+ echo "<select name='$name'>";
+
+ if ($all_option == true)
+ {
+ if ($selected_id == $all_items)
+ {
+ echo "<option selected value='$all_items'>"._("All Items")."</option>\n";
+ }
+ else
+ {
+ echo "<option value='$all_items'>"._("All Items")."</option>\n";
+ }
+ if ($selected_id == "")
+ {
+ $selected_id = $all_items;
+ }
+ }
+
+ while ($row = db_fetch_row($result))
+ {
+ if ($selected_id == $row[0])
+ {
+ echo "<option selected value='" . $row[0] . "'>";
+ }
+ else
+ {
+ echo "<option value='" . $row[0] . "'>";
+ }
+ echo (user_show_codes()?$row[0] . " - ":"") . $row[2] . " - " . $row[1] . "</option>\n";
+
+ if ($selected_id == "")
+ {
+ $selected_id = $row[0];
+ $_POST[$name] = $selected_id;
+ }
+ }