<?php
/**********************************************************************
***********************************************************************/
$page_security = 'SA_ATTENDANCE_ENTRY';
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/employee_attendances_ui.inc");
include_once($path_to_root . "/payroll/includes/attendance_calculation.inc");
include_once($path_to_root . "/payroll/includes/db/employee_attendances_db.inc");
include_once($path_to_root . "/payroll/includes/db/employee_shifts_db.inc");
include_once($path_to_root . "/payroll/includes/db/attendance_db.inc");
include_once($path_to_root . "/payroll/includes/db/shifts_db.inc");
include_once($path_to_root . "/payroll/includes/db/employees_db.inc");
include_once($path_to_root . "/includes/db/module_settings_db.inc");
include_once($path_to_root . "/admin/db/list_values_db.inc");

$week_start_date = "";
$week_end_date = "";

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

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

simple_page_mode(true);

$status = true;
if (isset($_POST['SAVE'])) {   
    $msg = save_employee_attendances($_POST['date']); 
        if ($msg['success'] === false) {
            display_error($msg['message']);
        } else {
            display_notification($msg['message']);
        }
}

global $Ajax;


if (!isset_string_post('date')) {
    $_POST['date'] = Today();
    $_POST['Search:'] = "Search";
} else {

}
$Ajax->activate('date');
$Ajax->activate('emp_attendances');

start_form();    
div_start('emp_attendances');
    start_table();
        date_cells('Date:', 'date', 'Select a date', null, 0, 0, 0, null, true);
        submit_cells('Search:', _("Search"), '', '', 'default');
    end_table(1);
    
        
    
    display_employee_attendance_details($_POST['date'], $status);
    div_end();
    
    submit_center('SAVE', 'Save', true, 'Save empployee attendances', false, ICON_SUBMIT);
    br(2);
    
if (!@$_GET['popup']) {
    end_form();
    end_page(@$_GET['popup'], false, false);
}

?>