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

include($path_to_root . "/includes/session.inc");
include_once($path_to_root . "/includes/ui.inc");
include_once($path_to_root . "/payroll/includes/ui/employee_rates_ui.inc"); 
include_once($path_to_root . "/payroll/includes/db/employee_rates_db.inc");

page(_($help_context = "WMS Employee Rates"));

simple_page_mode(false);

$state = true;

if (isset($_POST['ADD_EMP_RATE']) || isset($_POST['UPDATE_EMP_RATE'])) {
    $msg = save_employee_rate($selected_id);
        if ($msg['success'] === false) {
            if (isset($msg['focus_to'])) {
                set_focus($msg['focus_to']);
            }
            display_error($msg['message']);
        } else {
            display_notification($msg['message']);
            clear_employee_rate_data($selected_id);
            $Mode = 'RESET';
        }
}

if ($Mode == 'Delete') {
    $msg = handle_delete_employee_rate($selected_id);
        if ($msg['success'] === false) {
            if (isset($msg['focus_to'])) {
                set_focus($msg['focus_to']);
            }
            display_error($msg['message']);
        } else {
            display_notification($msg['message']);
            clear_employee_rate_data($selected_id);
            $Mode = 'RESET';
        }
}

if ($Mode == 'RESET' || isset($_POST['Refresh']) || isset($_POST['CLEAR_DATA'])) { 
    clear_employee_rate_data();
}

start_form();

    global $Ajax;

    display_employee_rate_selection_parameters();

    $Ajax->activate('employee_rate');
    div_start('employee_rate');
        display_employee_rates_details($_POST['emp_rate_category']);
    div_end();
    
    display_employee_rate_controls($Mode, $selected_id, $state);

end_form(1);

end_page();

?>
