<header class="toolbar toolbar-header">
    <h1 class="text-center" style="font-size: 12px;"><?php echo $this->lang->line('company_epos') ?></h1>
</header>
<div class="window-content" id="WindowContent">
    <div class="page-loader" style="display: none;"></div>
    <div class="pane-group">
        <?php if ($this->session->userdata('loginBranch') && $this->session->userdata('loginTeam')): ?>
            <div class="pane sidebar login-sidebar user-list-block">
                <div class="user-list" style="<?php $this->session->userdata('LoginBoss') == 'yes' ? print 'top:25%!important' : print print 'top:1%!important'  ?>">
                    <?php if (!empty($users)): ?>
                        <?php foreach ($users as $anUser): ?>
                            <?php $userDetail = get_single_record('employee', array('id' => $anUser->employee)) ?>
                            <div class="user" onclick="setEposUserInformation('<?php echo $anUser->id ?>', '<?php echo $userDetail->id ?>', '<?php echo $anUser->username ?>', '<?php echo $anUser->display ?>')">
                                <div class="user-image">
                                    <?php if (trim($userDetail->photo)): ?>
                                        <img src="<?php echo EPOS_UPLOAD_PATH . $userDetail->photo ?>">
                                    <?php else: ?>
                                        <?php if ($userDetail->gender === 'Male'): ?>
                                            <img class="user-male" alt="" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAF4AAABmAQMAAAB4NbTtAAAAA1BMVEX///+nxBvIAAAAAXRSTlMAQObYZgAAABRJREFUeNpjYBgFo2AUjIJRQBgAAAUuAAFWaieDAAAAAElFTkSuQmCC">
                                        <?php else: ?>
                                            <img class="user-female" alt="" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAF4AAABmAQMAAAB4NbTtAAAAA1BMVEX///+nxBvIAAAAAXRSTlMAQObYZgAAABRJREFUeNpjYBgFo2AUjIJRQBgAAAUuAAFWaieDAAAAAElFTkSuQmCC">
                                        <?php endif; ?>
                                    <?php endif; ?>
                                </div>
                                <div class="user-name text-center"><?php echo $anUser->display ?></div>
                            </div>
                        <?php endforeach; ?>
                    <?php else: ?>
                        <div class="user-image text-center" onclick="warning('<?php echo $this->lang->line('contact') ?>', '<?php echo $this->lang->line('system_owner_company') ?><br/><?php echo $this->lang->line('system_owner_phone') ?><br/><a style=' + 'cursor:pointer;' + ' href=' + 'mailto:<?php echo $this->lang->line('system_notify_email') ?>' + '><?php echo $this->lang->line('system_notify_email') ?></a><br/><?php echo $this->lang->line('system_owner_website') ?>', '<?php echo $this->lang->line('close') ?>')">
                            <img class="logo-lg" alt="GkSoft" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAPoAAACWAQMAAADNFAdfAAAAA1BMVEX///+nxBvIAAAAAXRSTlMAQObYZgAAABxJREFUeNrtwTEBAAAAwqD1T20Gf6AAAAAAgM8AE1YAARzmcjEAAAAASUVORK5CYII=">
                        </div>
                        <div><div class="clearfix brand-time text-center" id="ZamanEposClock"></div></div>
                    <?php endif; ?>
                </div>
            </div>
        <?php else: ?>
            <div class="pane sidebar login-sidebar">
                <div class="pane sidebar login-sidebar user-list-block" style="margin-top: 30%">

                    <div class="user-list">
                        <div class="user-image text-center" onclick="warning('<?php echo $this->lang->line('contact') ?>', 'GKSOFT<br/>017450 116225<br/><a style=' + 'cursor:pointer;' + ' href=' + 'mailto:info@gksoft.co.uk' + '>info@gksoft.co.uk</a><br/><a style=' + 'cursor:pointer;' + ' href=' + 'http://gksoft.co.uk' + ' target=' + '_blank' + '>gksoft.co.uk</a>', '<?php echo $this->lang->line('close') ?>')">
                            <img class="logo-lg" alt="GkSoft" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAPoAAACWAQMAAADNFAdfAAAAA1BMVEX///+nxBvIAAAAAXRSTlMAQObYZgAAABxJREFUeNrtwTEBAAAAwqD1T20Gf6AAAAAAgM8AE1YAARzmcjEAAAAASUVORK5CYII=">
                        </div>
                        <div>
                            <div class="clearfix brand-time text-center" id="ZamanEposClock"></div>
                        </div>
                    </div>
                </div>
            </div>
        <?php endif; ?>
        <div class="pane-one-half">
            <div style="width:70%; margin:10% auto; top: 10%">
                <?php echo form_open('user/login/validate', array('id' => 'eposUserLoginForm')); ?>
                <div class="neworder-table-guest collection-phone ccfee login-pad text-center">
                    <div class="clearfix brand-time text-center" id="ZamanEposClock" style="border-radius: 50px 50px 0px 0px;padding: 10px;"><span class="icon icon-lock"></span>&nbsp;<?php echo $this->lang->line('please_login') ?></div>
                    <div class="form-group"><input type="text" name="eposUserNames" id="eposUserNames" class="form-control" placeholder="<?php echo $this->lang->line('username') ?>" autocomplete="off" onfocus="if (this.hasAttribute('readonly')) {
                                this.removeAttribute('readonly');
                                this.blur();
                                this.focus();
                            }"></div>
                    <div class="form-group"><input type="password" name="eposUserPassword" id="zamanccFeePrimaryNumpad" class="form-control" placeholder="<?php echo $this->lang->line('password') ?>" autocomplete="new-password" onfocus="if (this.hasAttribute('readonly')) {
                                this.removeAttribute('readonly');
                                this.blur();
                                this.focus();
                            }"></div>
                    <div class="clearfix"></div>
                    <div class="tab-group keypad">
                        <div class="tab-item zaman-epos-nav quantity-digit keypad-key ccFeePrimaryNumKey"><?php echo $this->lang->line('numpad_key_1') ?></div>
                        <div class="tab-item zaman-epos-nav quantity-digit keypad-key ccFeePrimaryNumKey"><?php echo $this->lang->line('numpad_key_2') ?></div>
                        <div class="tab-item zaman-epos-nav quantity-digit keypad-key ccFeePrimaryNumKey"><?php echo $this->lang->line('numpad_key_3') ?></div>
                    </div>
                    <div class="tab-group keypad">
                        <div class="tab-item zaman-epos-nav quantity-digit keypad-key ccFeePrimaryNumKey"><?php echo $this->lang->line('numpad_key_4') ?></div>
                        <div class="tab-item zaman-epos-nav quantity-digit keypad-key ccFeePrimaryNumKey"><?php echo $this->lang->line('numpad_key_5') ?></div>
                        <div class="tab-item zaman-epos-nav quantity-digit keypad-key ccFeePrimaryNumKey"><?php echo $this->lang->line('numpad_key_6') ?></div>
                    </div>
                    <div class="tab-group keypad">
                        <div class="tab-item zaman-epos-nav quantity-digit keypad-key ccFeePrimaryNumKey"><?php echo $this->lang->line('numpad_key_7') ?></div>
                        <div class="tab-item zaman-epos-nav quantity-digit keypad-key ccFeePrimaryNumKey"><?php echo $this->lang->line('numpad_key_8') ?></div>
                        <div class="tab-item zaman-epos-nav quantity-digit keypad-key ccFeePrimaryNumKey"><?php echo $this->lang->line('numpad_key_9') ?></div>
                    </div>
                    <div class="tab-group keypad">
                        <div class="tab-item zaman-epos-nav quantity-digit keypad-key ccFeePrimaryActionKey"><?php echo $this->lang->line('numpad_key_DEL') ?></div>
                        <div class="tab-item zaman-epos-nav quantity-digit keypad-key ccFeePrimaryNumKey"><?php echo $this->lang->line('numpad_key_0') ?></div>
                        <div class="tab-item zaman-epos-nav quantity-digit keypad-key ccFeePrimaryActionKey"><?php echo $this->lang->line('numpad_key_CLR') ?></div>
                    </div>
                    <div class="tab-group keypad">
                        <div class="tab-item zaman-epos-nav quantity-digit keypad-key" onclick="zamanToogleEposVirtualKeyboard('setting-general-keyboard')">Open Extended Keyboard</div>
                    </div>
                    <div class="tab-group config-submit">
                        <input type="hidden" id="eposUserId" name="eposUserId">
                        <input type="hidden" id="eposUserEmployeeId" name="eposUserEmployeeId">
                        <input type="hidden" id="eposUsername" name="eposUsername">
                        <button type="submit" onclick="validateEposUser('eposUserLoginForm')" style="font-size: 25px;"><?php echo $this->lang->line('go') ?></button>
                    </div>
                </div>
                <?php echo form_close() ?>
            </div>
        </div>
        <div class="pane sidebar login-sidebar">
            <?php if (isDevice('Electron')): ?>
                <div class="tab-group" id="exitDesktopApplicationTab">
                    <div onclick="exitDesktopApplication()" class="tab-item text-uppercase" style="font-size: 25px; color: #9c0707;"><?php echo $this->lang->line('exit') ?></div>
                </div>
            <?php endif; ?>
            <div class="user-list" style="top: 13% !important">
                <div class="user-image text-center" onclick="window.location.reload(true)">
                    <img src="<?php echo EPOS_UPLOAD_PATH . $this->config->item('general_logo') ?>" alt="<?php echo $this->config->item('general_name') ?>" class="epos-logo">
                </div>
                <div>
                    <div class="clearfix brand-time text-center"><?php echo date('d/m/Y') ?></div>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="setting-general-keyboard text-center"></div>
<?php $this->load->view('settings/partials/footer') ?>

<script type="text/javascript">
    $('document').ready(function () {
        zamanEposCart.userLoggedOut();
        var isElectron = '<?php isDevice('Electron') ? print'yes' : 'no' ?>';
        var userAccessTypeGroup = localStorage.getItem('userAccessTypeGroup');
        if (isElectron === 'yes' && Number(userAccessTypeGroup) === 5) {
            eposExitOnIdleTimeElapse();
        } else {
            if ($('#exitDesktopApplicationTab').length > 0) {
                $('#exitDesktopApplicationTab').hide();
            }
        }
    });
    function setEposUserInformation(one, two, three, four) {
        var LoginBoos = '<?php echo $this->session->userdata('LoginBoss') ?>';
        if (checkApi() || $.trim(LoginBoos) === 'yes') {
            $('#eposUserId').val(one);
            $('#eposUserEmployeeId').val(two);
            $('#eposUsername').val(three);
            $('#eposUserNames').val(four);
            playBeepSound();
        } else {
            location.reload();
        }
    }
    function validateEposUser(formId) {
        if (!$('.page-loader').is(":visible")) {
            $('#' + formId).validate({
                submitHandler: function () {
                    var myform = document.getElementById(formId);
                    var formdata = new FormData(myform);
                    var LoginBoos = '<?php echo $this->session->userdata('LoginBoss') ?>';
                    if (checkInternetConnection() && (checkApi() || LoginBoos === 'yes')) {
                        $.ajax({
                            url: $('#' + formId).attr('action'),
                            data: formdata,
                            cache: false,
                            processData: false,
                            contentType: false,
                            type: 'POST',
                            dataType: 'json',
                            beforeSend: function () {
                                $('.page-loader').show();
                            },
                            success: function (response) {
                                if (response.status) {
                                    if (response.userData) {
                                        zamanEposCart.setUserData(response.userData);
                                        localStorage.setItem("userAccessTypeGroup", response.userData.group);
                                    }
                                    window.location.href = '<?php echo site_url('user/login/index/' . $this->session->userdata('loginBranch') . '/' . $this->session->userdata('loginTeam')) ?>';
                                } else {
                                    warning('<?php echo $this->lang->line('error') ?>', response.message, '<?php echo $this->lang->line('ok') ?>');
                                }
                            }
                        });
                    } else {
                        warning('<?php echo $this->lang->line('lost_connection') ?>', '<?php echo $this->lang->line('lost_connection_message') ?>', '<?php echo $this->lang->line('close') ?>');
                    }
                },
                errorClass: "has-error",
                highlight: function (e) {
                    $(e).closest('.form-group').addClass('has-error');
                },
                unhighlight: function (e) {
                    $(e).closest('.form-group').removeClass('has-error');
                },
                rules: {
                    eposUserNames: {required: true},
                    eposUserPassword: {required: true}
                },
                messages: {
                    eposUserNames: '<?php echo $this->lang->line('username_warning') ?>',
                    eposUserPassword: '<?php echo $this->lang->line('password_warning') ?>'
                },
                errorPlacement: function (error, element) {
                    errorPlacement(error, element);
                }
            });
        }
    }
    function exitDesktopApplication() {
        var string = '<?php echo uri_string() ?>';
        var urlArray = string.split('/');
        if (urlArray.length === 5) {
            var branch = urlArray[urlArray.length - 2];
            var team = urlArray[urlArray.length - 1];
            $.ajax({
                url: '<?php echo site_url('user/login/exitDesktopApplication') ?>',
                type: 'POST',
                data: {branch: branch, team: team, command: 'exitApp'},
                dataType: 'json',
                success: function (response) {
                    if (response.status) {
                        console.log('System Exitting.....');
                    }
                }
            });
        }
    }
    function eposExitOnIdleTimeElapse() {
        var t;
        window.onload = resetTimer;
        window.onmousemove = resetTimer;
        window.onmousedown = resetTimer;
        window.onclick = resetTimer;
        window.onscroll = resetTimer;
        window.onkeypress = resetTimer;
        function exitEposApp() {
            exitDesktopApplication();
        }
        function resetTimer() {
            clearTimeout(t);
            t = setTimeout(exitEposApp, 900000);
        }
    }
</script>