<?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_attendance_inquiry_db.inc"); 
include_once($path_to_root . "/includes/db/module_settings_db.inc"); 
include_once($path_to_root . "/payroll/includes/db/employees_db.inc"); 
include_once($path_to_root . "/payroll/includes/db/shifts_db.inc"); 
include_once($path_to_root . "/payroll/includes/db/payroll_calculation_db.inc"); 
include_once($path_to_root . "/admin/db/list_values_db.inc");
include_once($path_to_root . "/payroll/includes/ui/view_employee_attendance_ui.inc"); 
include_once($path_to_root . "/payroll/includes/db/employee_attendances_db.inc");
include_once($path_to_root . "/payroll/includes/db/payroll_work_time_deficits_db.inc"); 
include_once($path_to_root . "/payroll/includes/ui/payroll_ui.inc"); 
include_once($path_to_root . "/payroll/includes/db/payroll_run_db.inc"); 

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

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

simple_page_mode(true);

if (isset($_GET['Reopen_attendace_msg'])) {
    display_notification_centered($_GET['Reopen_attendace_msg']);
    display_footer_exit();
}

if (isset($_POST['ReopenData'])) {
    $msg = reopen_approved_attendances_summary(date2sql($_POST['date']));
        if ($msg['success'] === false) {
            display_error($msg['message']);
        } else {
            meta_forward($_SERVER['PHP_SELF'], "Reopen_attendace_msg=".$msg['message']); 
        }
}

start_form();

global $Ajax;

    start_table();
        date_cells('Date:', 'date', 'Select a date', null, 0, 0, 0, null, true);
        submit_cells('Search:', _("Search"), '', '', 'default');
    end_table(2);

    $date_ = $_POST['date'];
    
    $Ajax->activate('reopen_approved_attendances_summary');
    div_start('reopen_approved_attendances_summary');
    
        $show_msg = "No any approved attendance summary records found on $date_.";
        $show_btn = display_employees_attendance_details(date2sql($date_), array("'A'"), $show_msg, true);
    
        if ($show_btn === true) {
            submit_center('ReopenData', _("Reopen"), true, false, 'default');
        }
        
    div_end();

end_form(2);

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

?>