<?php
/**********************************************************************
***********************************************************************/

$page_security = 'SA_APPROVE_LEAVE';
$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/approve_attendances_summary_ui.inc"); 
include_once($path_to_root . "/payroll/includes/db/employee_attendances_db.inc"); 
include_once($path_to_root . "/payroll/includes/db/payroll_run_db.inc"); 
include_once($path_to_root . "/admin/db/list_values_db.inc"); 

$js = "";
$js .= get_js_open_window(900, 500);
$js .= get_js_date_picker();

page(_($help_context = "Approve Attendances Summary"), @$_GET['popup'], false, "", $js);

simple_page_mode(true);

if (isset($_POST['ApproveData'])) {
    $msg = approve_unapproved_attendances_summary($_POST['payroll_run_id']);
        if ($msg['success'] === false) {
            display_error($msg['message']);
        } else {
            display_notification($msg['message']);
        }
}

start_form();

    start_table();
        payroll_run_list_cells("Payroll Run:", 'payroll_run_id', false, "", true);
        submit_cells('Refresh', 'Refresh');
    end_table(2);
    
    if (! ($_POST['payroll_run_id'] > 0)) {
        display_note("Please select a payroll run.", 2, 2, 'style=color:red');
    } else {

        $pay_run_row = get_payroll_run_details($_POST['payroll_run_id']);
        
        display_unapproved_attendances_summary($pay_run_row['period_start_date'], $pay_run_row['period_end_date']);

        submit_center('ApproveData', _("Approve"), true, false, 'default');
    }

end_form(2);

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

?>