<?php
/**********************************************************************
***********************************************************************/
$page_security = 'SA_GLACCOUNTGROUP';
$path_to_root = "../..";

include($path_to_root . "/includes/session.inc");
include($path_to_root . "/gl/includes/gl_db.inc");
include($path_to_root . "/includes/ui.inc");
include($path_to_root . "/gl/includes/ui/gl_account_types_ui.inc"); 

page(_($help_context = "GL Account Groups"));

simple_page_mode(false);

if ($Mode == 'ADD_ITEM' || $Mode == 'UPDATE_ITEM') {
    if (can_process($selected_id)) {
        if ($selected_id != "") {
            if (update_account_type($_POST['id'], $_POST['name'], $_POST['class_id'], $_POST['parent'], $_POST['old_id'])) {
                
                build_calculate_upadte_gl_account_types();
                
                display_notification(_('Selected account type has been updated.'));
            }
        } else {
            if (add_account_type($_POST['id'], $_POST['name'], $_POST['class_id'], $_POST['parent'])) {
                
                build_calculate_upadte_gl_account_types();
                
                display_notification(_('New account type has been added.'));
            }
        }
        
            $Mode = 'RESET';
    }
}

if ($Mode == 'Delete') {
    if (can_delete($selected_id)) {
        delete_account_type($selected_id);
        display_notification(_('Selected account group has been deleted'));
    }
    
    $Mode = 'RESET';
}

if ($Mode == 'RESET') {
    $selected_id = "";
    $_POST['id']  = $_POST['name']  = '';
    unset($_POST['parent']);
    unset($_POST['class_id']);
}

start_form();

    display_gl_account_types_details();

    display_gl_account_types_control($Mode, $selected_id);

    submit_add_or_update_center($selected_id == "", '', 'both');

end_form(2);

end_page();

?>