$Ajax->activate('details');
}
function clear_data()
{
    unset($_POST['empl_id']);
    unset($_POST['empl_name']);
    unset($_POST['gross_salary']);
}
if (isset($_POST['submit'])) {
    if (strlen(trim($_POST['empl_name'])) == 0) {
        display_error(_("The employee name cannot be empty."));
        set_focus('empl_name');
        return false;
    }
    if (isset($_POST['empl_id'])) {
        $empl_id = update_employee($_POST['empl_id'], $_POST['empl_name'], $_POST['pre_address'], $_POST['per_address'], $_POST['date_of_birth'], $_POST['age'], $_POST['mobile_phone'], $_POST['email'], $_POST['grade'], $_POST['department'], $_POST['designation'], $_POST['gross_salary'], $_POST['date_of_join']);
        meta_forward($_SERVER['PHP_SELF'], "Updated=yes&selected_id={$empl_id}");
    } else {
        $empl_id = add_employee($_POST['empl_name'], $_POST['pre_address'], $_POST['per_address'], $_POST['date_of_birth'], $_POST['age'], $_POST['mobile_phone'], $_POST['email'], $_POST['grade'], $_POST['department'], $_POST['designation'], $_POST['gross_salary'], $_POST['date_of_join']);
        meta_forward($_SERVER['PHP_SELF'], "Added=yes&selected_id={$empl_id}");
    }
}
start_form();
if (db_has_employees()) {
    start_table(TABLESTYLE_NOBORDER);
    start_row();
    hrm_year_list(_("Year:"), 'year', null);
    hrm_months_list(_("Month:"), 'month', null);
    employee_list_cells(_("Select an Employee: "), 'selected_id', null, _('New Employee'), true, check_value('show_inactive'));
    $new_item = get_post('selected_id') == '';
    end_row();
        }
        if (!empty($employee['fax']) && !preg_match("/^[0-9]{3}-[0-9]{3}-[0-9]{4}\$/", $employee['fax'])) {
            $error_fax = 'Fax must be valid fax number';
            $formValidation = false;
        }
        if ($formValidation) {
            if (empty($employee['employeeID'])) {
                $employee['password'] = password_hash($employee['password'], PASSWORD_DEFAULT);
                add_employee($employee);
            } else {
                if (!empty($employee['password']) && !empty($_POST['confirmPassword']) && $employee['password'] == $_POST['confirmPassword']) {
                    $employee['password'] = password_hash($employee['password'], PASSWORD_DEFAULT);
                } else {
                    $employee['password'] = get_employee($employee['employeeID'])['password'];
                }
                update_employee($employee);
            }
            $success_notification = 'Successfully saved';
        }
    } catch (Exception $e) {
        $error_notification = $e->getMessage();
    }
} else {
    if (isset($_GET['employeeID'])) {
        $employeeID = $_GET['employeeID'];
    }
    if (!empty($employeeID)) {
        $employee = get_employee($employeeID);
    }
}
?>