<?php
/**********************************************************************
***********************************************************************/
$page_security = 'SA_APPROVE_SALARY_AJUSTMENTS';
if (!@$_GET['popup'])
	$path_to_root = "..";
else	
	$path_to_root = "../..";

include_once($path_to_root . "/includes/session.inc");
include_once($path_to_root . "/includes/ui.inc");
include_once($path_to_root . "/payroll/includes/ui/reopen_salary_adjustments_ui.inc"); 
include_once($path_to_root . "/payroll/includes/db/approve_salary_adjustments_db.inc");
include_once($path_to_root . "/payroll/includes/db/employees_db.inc"); 

simple_page_mode(true);

page(_($help_context = "Reopen Salary Adjustments"));

$display_error = false;
$selected_rec_count = 0;

if (isset($_POST['UpdateData'])) {
    $a_result = get_approved_salary_adjustments();
        while ($a_row = db_fetch($a_result)) {
            if ((isset($_POST["selected_".$a_row["rec_id"]])) && ($_POST["selected_".$a_row["rec_id"]] == true)) {
                $msg = reopen_salary_adjustments($a_row["rec_id"], $a_row["employee_code"], $a_row["type"]);
                    if ($msg['success'] === false) {
                        display_error($msg['message']);
                        $display_error = true;
                        break;
                    }
                    
                $selected_rec_count++;
            }
        }
        
        if ($display_error === false) {
            if ($selected_rec_count > 0) {
                display_notification(_("Salary adjustments have been reopened."));
            } else {
                display_error(_("Please select at least one record before reopening."));
            }
        }
}

start_form();

    $Ajax->activate('leaves');
    div_start('leaves');

        display_reopen_salary_adjustment_additions();

        display_reopen_salary_adjustment_deductions();

        display_reopen_salary_adjustment_advances();

        submit_center('UpdateData', _("Update"), true, false, 'default');

    div_end();

end_form(2);

end_page(@$_GET['popup'], false, false);

?>