<?php
/**********************************************************************
***********************************************************************/
$page_security = 'SA_ORDER_CATEGORIES';
$path_to_root = "..";
include($path_to_root . "/includes/session.inc");

page(_($help_context = "Order Categories"));

include_once($path_to_root . "/admin/db/order_categories_db.inc");
include_once($path_to_root . "/includes/ui/ui_input.inc");
include_once($path_to_root . "/includes/ui/ui_lists_custom.inc");
include_once($path_to_root . "/includes/data_checks.inc");
//include_once($path_to_root . "/includes/ui.inc");

simple_page_mode(true);
//-----------------------------------------------------------------------------------

global $order_categories_type, $inventory_movement_type_linked_fields;

if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM') 
{
	//initialise no input errors assumed initially before we test
	$input_error = 0;

	if (!($selected_id > 0) && !($_POST['type'] > 0)) 
	{
		$input_error = 1;
		display_error(_("Please select an order category type."));
		set_focus('type');
	}

	if ($input_error != 1) 
	{
            if ($selected_id != -1) 
            {
                    update_order_category($selected_id, $_POST['name'], $_POST['prefix'], $_POST['display_order']);
                            display_notification(_('Selected order category has been updated'));
            } 
            else 
            {
                    add_order_category($_POST['type'], $_POST['name'], $_POST['prefix'], $_POST['display_order']);
                            display_notification(_('New order category has been added'));
            }
    	
		$Mode = 'RESET';
	}
} 

//-----------------------------------------------------------------------------------

if ($Mode == 'Delete')
{
	if (can_delete($selected_id))
	{

	}
	$Mode = 'RESET';
}

if ($Mode == 'RESET')
{
	$selected_id = -1;
	$sav = get_post('show_inactive');
	unset($_POST);
//	$_POST['show_inactive'] = $sav;
}
//-----------------------------------------------------------------------------------

$result = get_all_order_categories(check_value('show_inactive'));

start_form();
start_table(TABLESTYLE, "width=40%");

$th = array(_("Transaction Type"), _("Display Order"), _("Category Name"),"Prefix", "");
inactive_control_column($th);
table_header($th);
$k = 0;
while ($myrow = db_fetch($result)) 
{	
    alt_table_row_color($k);	

    label_cell($order_category_types[$myrow['type']]);
    label_cell($myrow['display_order'], "align=center");
    label_cell($myrow["name"]);
    label_cell($myrow['prefix']);
    
    inactive_control_cell($myrow["id"], $myrow["inactive"], 'order_categories', 'id');
 	
    edit_button_cell("Edit".$myrow['id'], _("Edit"));
//    delete_button_cell("Delete".$myrow['id'], _("Delete"));
	end_row();
}
inactive_control_row($th);
end_table(1);

//-----------------------------------------------------------------------------------

start_table(TABLESTYLE2);

if ($selected_id != -1) 
{
// 	if ($Mode == 'Edit') {
		//editing an existing status code
               
    $myrow = get_order_category($selected_id);            

    $_POST['name']  = $myrow["name"];
    $_POST['type']  = $myrow["type"];
    $_POST['prefix']  = $myrow["prefix"];
    $_POST['type'] = $myrow["type"];
    $_POST['display_order'] = $myrow["display_order"];
    
    
    hidden('selected_id', $selected_id);
//	}
	
} 

//inventory_movement_types_list_row(_("Movement Type:"), 'type');
if ($selected_id > 0) {
//    inventory_movement_types_list_row(_("Movement Type:"), 'type', $_POST['type']) ;
    label_row(_("Types:"), $order_category_types[$_POST["type"]]);
//    hidden('type', $_POST['type']);
}
else{
    order_category_types_list_row("Types:", 'type', null, 'Select Order Category Type', false);
}


text_row(_("Category Name:"), 'name', null, 50, 50);

text_row(_("Prefix:"), 'prefix', null, 5, 5);

qty_row("Display Order", 'display_order', null, null, null, 0);

end_table(1);

submit_add_or_update_center($selected_id == -1, '', 'both');

end_form();

//------------------------------------------------------------------------------------

end_page();



?>
