if (item_unit_used($selected_id)) { display_error(_("Cannot delete this unit of measure because items have been created using this unit.")); } else { delete_item_unit($selected_id); display_notification(_('Selected unit has been deleted')); } $Mode = 'RESET'; } if ($Mode == 'RESET') { $selected_id = ''; $sav = get_post('show_inactive'); unset($_POST); $_POST['show_inactive'] = $sav; } //---------------------------------------------------------------------------------- $result = get_all_item_units(check_value('show_inactive')); start_form(); start_table(TABLESTYLE, "width=40%"); $th = array(_('Unit'), _('Description'), _('Decimals'), "", ""); inactive_control_column($th); table_header($th); $k = 0; //row colour counter while ($myrow = db_fetch($result)) { alt_table_row_color($k); label_cell($myrow["abbr"]); label_cell($myrow["name"]); label_cell($myrow["decimals"] == -1 ? _("User Quantity Decimals") : $myrow["decimals"]); inactive_control_cell($myrow["abbr"], $myrow["inactive"], 'item_units', 'abbr'); edit_button_cell("Edit" . $myrow["abbr"], _("Edit")); delete_button_cell("Delete" . $myrow["abbr"], _("Delete"));
write_item_unit(isset($selected_id) ? $selected_id : '', $_POST['abbr'], $_POST['description'], $_POST['decimals']); meta_forward($_SERVER['PHP_SELF']); } } //---------------------------------------------------------------------------------- if (isset($_GET['delete'])) { // PREVENT DELETES IF DEPENDENT RECORDS IN 'stock_master' if (item_unit_used($selected_id)) { display_error(tr("Cannot delete this unit of measure because items have been created using this units.")); } else { delete_item_unit($selected_id); meta_forward($_SERVER['PHP_SELF']); } } //---------------------------------------------------------------------------------- $result = get_all_item_units(); start_table("{$table_style} width=50%"); $th = array(tr('Unit'), tr('Description'), tr('Decimals'), "", ""); table_header($th); $k = 0; //row colour counter while ($myrow = db_fetch($result)) { alt_table_row_color($k); label_cell($myrow["abbr"]); label_cell($myrow["name"]); label_cell($myrow["decimals"]); edit_link_cell(SID . "selected_id={$myrow['0']}"); delete_link_cell(SID . "selected_id={$myrow['0']}&delete=yes"); end_row(); } end_table();
function stock_units_list_row($label, $name, $value = null, $enabled = true) { View::get()->layoutHintRow(); $result = get_all_item_units(); while ($unit = db_fetch($result)) { $units[$unit['abbr']] = $unit['name']; } $controls = array_selector($name, $value, $units, array('disabled' => !$enabled)); View::get()->addComboControls($label, $controls); }