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

$page_security = 'SA_USERS';
$path_to_root = "..";

include_once($path_to_root . "/includes/db_pager.inc");
include_once($path_to_root . "/includes/session.inc");
include_once($path_to_root . "/includes/ui.inc");
include_once($path_to_root . "/payroll/includes/db/employees_db.inc");
include_once($path_to_root . "/admin/db/users_db.inc");

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

page($help_context = "System Users Inquiry", false, false, "", $js);

simple_page_mode(true);

function display_users_inquiry_filtering_controls() {
    start_table(TABLESTYLE_NOBORDER);
        start_row();
            text_cells_ex(_('Login Id:'), 'user_id', 20);
            text_cells_ex(_('Name:'), 'name', 35, 200);
            employees_simple_list_cells('Emoloyee:', 'employee_code', null, '', true);
            security_roles_list_cells(_("Access Level:"), 'role_id', null, true, true, false);
            submit_cells('SearchOrders', _("Search"), '', _("Search"), false, ICON_SUBMIT);
        end_row();
    end_table(1);
}

function display_user_login_log_data() {
    $user_id = $_POST["user_id"];
    $name = $_POST["name"];
    $role_id = $_POST["role_id"];
    $employee_code = $_POST["employee_code"];

        start_table(TABLESTYLE, "width=98%");
            $th = array("Id", "Login Id", "Name", "Role", "Last Login Date", "Employee", "Theme", "Inactive");
            table_header($th);

            $result = get_users(true, $user_id, $name, $role_id, $employee_code);
                while ($row = db_fetch($result)) {
                    alt_table_row_color($k);
                        label_cell($row["id"], 'align=center'); 
                        label_cell($row["user_id"]);           
                        label_cell($row["real_name"]);  
                        label_cell($row["role"]);         
                        if (! is_null($row["last_visit_date"])) {
                            label_cell(sql2date($row["last_visit_date"]), 'align=center'); 
                        } else {
                            label_cell('');
                        }
                        if ($row["employee_code"] != '') {
                            label_cell(get_employee_formatted_long_name($row["employee_code"]));   
                        } else {
                            label_cell('');
                        }
                        label_cell($row["theme"], 'align=center'); 
                        label_cell(get_yes_no_name($row["inactive"]), 'align=center'); 
                    end_row();
                }

        end_table(1);
}

    $Ajax->activate('_page_body');

    start_form();

        display_users_inquiry_filtering_controls();

        display_user_login_log_data();

    end_form();
end_page();

?>