<?php
//if we want to ignore the head session check
if (empty($_GET['__trusto__head_ignore_login']) || $_GET['__trusto__head_ignore_login'] != 1) {
    if (Session::isAlive() == false) {
        Session::kill();
        exit();
    }
    $permissions = Session::getPermissionsObject();
    if (!($permissions instanceof Permissions) || (!isset($pageName))) {
        Session::kill();
        exit();
    } else {
        if (!$permissions->hasPermission($pageName)) {
            header('Location: ' . SITE_LINK . 'error_class/Error401');
        }
    }
} else {
    Session::create2(); //to initialize settings, ..
}

$Language = Session::getUserPreferences();
//
mb_internal_encoding("UTF-8");
mb_http_output("UTF-8");
ob_start("mb_output_handler");
include(INC_PATH . 'language.php');
?>
<!DOCTYPE html>
<html lang='<?php echo $Language; ?>'>

<head>
    <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
    <!--FAV ICON-->
    <link rel="shortcut icon" href="img/favicon.ico" type="image/x-icon" />

     <link rel="apple-touch-icon" sizes="180x180" href="img/apple-touch-icon.png">
    <link rel="icon" type="img/png" sizes="32x32" href="img/favicon-32x32.png">
    <link rel="icon" type="img/png" sizes="16x16" href="img/favicon-16x16.png">
     <link rel="mask-icon" href="img/safari-pinned-tab.svg" color="#5bbad5">
    <meta name="msapplication-TileColor" content="#ffc40d">
    <meta name="theme-color" content="#ffffff">

    <meta charset="utf-8" />
    <title><?php echo $title; ?></title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    
    <link rel="icon" type="image/x-icon" href="favicon.ico" />
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-touch-fullscreen" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="default">
    <meta content="TRUSTO_ ERP SYSTEM is a process used by companies to manage and integrate the important parts of their businesses. TRUSTO_ ERP SYSTEM can also integrate planning, purchasing inventory, sales, marketing, finance, human resources, and more." name="description" />
    <meta name="keywords" content="ERP System">
    <meta content="Trusto Tech" name="author" />
    <meta name="theme-color"  content="#e19421">
    <base href="<?php echo SITE_LINK; ?>">
    <link href="<?php echo SITE_LINK . THEME_PATH; ?>plugins/datatables/css/jquery.datatables.min.css?v=<?php echo trusto_VERSION; ?>" rel="stylesheet" type="text/css" />
    <link href="<?php echo SITE_LINK . THEME_PATH; ?>plugins/datatables/css/jquery.datatables_themeroller.css" rel="stylesheet" type="text/css" />
    <link href="<?php echo SITE_LINK . THEME_PATH; ?>plugins/datatables/css/buttons.dataTables.min.css?v=<?php echo trusto_VERSION; ?>" rel="stylesheet" type="text/css" />


    <link href="<?php echo THEME_PATH; ?>plugins/pace/pace-theme-flash.css" rel="stylesheet" type="text/css" />
    <?php echo $Language == 'ar' ? ' <link href="Theme/css/bootstrap.rtl.css?v=' . trusto_VERSION . '" rel="stylesheet">' : '' ?>
    <link href="Theme/plugins/boostrapv3/css/bootstrap.min.css?v=<?php echo trusto_VERSION; ?>" rel="stylesheet" type="text/css" />
    <!--<link rel="stylesheet" media="screen" href="Theme/css/droid-arabic-kufi.css" type="text/css"/>-->

    <link href="<?php echo THEME_PATH; ?>plugins/font-awesome/css/font-awesome.css" rel="stylesheet" type="text/css" />
    <link href="<?php echo THEME_PATH; ?>plugins/jquery-scrollbar/jquery.scrollbar.css" rel="stylesheet" type="text/css" media="screen" />
    <link href="<?php echo THEME_PATH; ?>plugins/bootstrap-select2/select2.css" rel="stylesheet" type="text/css" media="screen" />
    <link href="<?php echo THEME_PATH; ?>plugins/switchery/css/switchery.min.css" rel="stylesheet" type="text/css" media="screen" />
    <!--<link href="<?php echo THEME_PATH; ?>plugins/nvd3/nv.d3.min.css" rel="stylesheet" type="text/css" media="screen"/>-->
    <!--<link href="<?php echo THEME_PATH; ?>plugins/mapplic/css/mapplic.css" rel="stylesheet" type="text/css"/>-->
    <link href="<?php echo THEME_PATH; ?>plugins/rickshaw/rickshaw.min.css" rel="stylesheet" type="text/css" />
    <link href="<?php echo THEME_PATH; ?>plugins/uniform/css/uniform.default.min.css" rel="stylesheet" type="text/css" />
    <?php echo $Language == 'ar' ? '<link href="Theme/plugins/bootstrap-datepicker/css/datepicker3.rtl.css"  rel="stylesheet" type="text/css"/>' : ' <link href="Theme/plugins/bootstrap-datepicker/css/datepicker3.css" rel="stylesheet">' ?>
    <link href="<?php echo THEME_PATH; ?>plugins/jquery-metrojs/MetroJs.css" rel="stylesheet" type="text/css" media="screen" />
    <link href="<?php echo CSS_PATH; ?>pages-icons.css" rel="stylesheet" type="text/css">
    <?php echo $Language == 'ar' ? '<link href="Theme/css/style.rtl.css?v=' . trusto_VERSION . '"  rel="stylesheet" type="text/css"/>' : ' <link href="Theme/css/pages.css?v=' . trusto_VERSION . '" rel="stylesheet">' ?>

    <link class="main-stylesheet" href="<?php echo CSS_PATH; ?>flaticon.css" rel="stylesheet" type="text/css" />
    <link href="<?php echo CSS_PATH . 'stylesheet.css?v=' . trusto_VERSION; ?>" rel="stylesheet" type="text/css" />
    <link href="<?php echo THEME_PATH; ?>plugins/toastr/toastr.min.css" rel="stylesheet" type="text/css" />
    <!-- old datatable includes
        <link href="< ?php echo THEME_PATH; ?>plugins/jquery-datatable/media/css/jquery.dataTables.css" rel="stylesheet" type="text/css"/>-->
    <script src="<?php echo THEME_PATH; ?>plugins/jquery/jquery-2.1.1.js" type="text/javascript"></script>
    <script src="<?php echo THEME_PATH; ?>plugins/balupton-jquery-scrollto/lib/jquery-scrollto.js" type="text/javascript"></script>
    <script type="text/javascript" src="<?php echo THEME_PATH; ?>plugins/bootstrap-daterangepicker-master/moment.min.js"></script>
    <script type="text/javascript" src="<?php echo THEME_PATH; ?>plugins/bootstrap-daterangepicker-master/daterangepicker.js"></script>
    <link href="<?php echo THEME_PATH; ?>plugins/bootstrap-daterangepicker-master/daterangepicker.css" rel="stylesheet" type="text/css" />
    <link href="<?php echo THEME_PATH; ?>plugins/bootstrap-colorpicker-master/dist/css/bootstrap-colorpicker.css" rel="stylesheet" type="text/css" />
    <link href="<?php echo THEME_PATH; ?>plugins/bootstrap-datetimepicker-master/css/bootstrap-datetimepicker.min.css" rel="stylesheet" type="text/css" />
    <link href="<?php echo THEME_PATH; ?>plugins/bootstrap-timepicker/css/bootstrap-timepicker.min.css" rel="stylesheet" type="text/css" />
    <link src="<?php echo THEME_PATH; ?>plugins/bootstrap-tag/bootstrap-tagsinput.css" rel="text/css" />


    <link href="<?php echo CSS_PATH; ?>aos.css" rel="stylesheet" type="text/css">





    <!--[if lte IE 9]><link href="pages/css/ie9.css" rel="stylesheet" type="text/css" /><![endif]-->
    <!--[if lt IE 9]><link href="<?php echo THEME_PATH; ?>plugins/mapplic/css/mapplic-ie.css" rel="stylesheet" type="text/css" /><![endif]-->
    <script type="text/javascript">
        var site_link = <?php echo json_encode(SITE_LINK); ?>,
            page_link = <?php echo json_encode(str_replace('/', '__', $_SERVER['REQUEST_URI'])); ?>,
            default_start_time = <?php echo json_encode(smc_session()['default_setting']['default_start_time']); ?>,
            activate_scroll_input_number = <?php echo json_encode(smc_session()['default_setting']['activate_scroll_input_number']); ?>,
            default_barcode_length = <?php echo json_encode(smc_session()['default_setting']['default_barcode_length']); ?>,
            datatable_default_align = <?php echo json_encode(smc_session()['default_setting']['datatable_default_align']); ?>,
            lang_code = <?php echo json_encode(smc_session()['lang_code']); ?>,
            excel_lang = <?php echo json_encode(CommonLanguage::getMessage('excel')); ?>,
            print_lang = <?php echo json_encode(CommonLanguage::getMessage('print')); ?>,
            colvis_lang = <?php echo json_encode(CommonLanguage::getMessage('column_visibility')); ?>,
            select_lang = <?php echo json_encode(CommonLanguage::getMessage('select')); ?>,
            smc__view_name = <?php echo json_encode(pathinfo($full_view, PATHINFO_FILENAME)); ?>,
            common_delete_modal = <?php
                                    echo json_encode([
                                        CommonLanguage::getMessage('Confirm_Delete'),
                                        CommonLanguage::getMessage('About_To_Delete'),
                                        CommonLanguage::getMessage('Proceed_Delete'),
                                        CommonLanguage::getMessage('Close'),
                                        CommonLanguage::getMessage('delete'),
                                        CommonLanguage::getMessage('Deleted_Successfully')
                                    ]);
                                    ?>,
            datatable_header = <?php echo json_encode(smc_session()['datatable_header']); ?>,
            datatable_message_top = <?php echo json_encode(empty(smc_session()['datatable_message_top']) ? '' : smc_session()['datatable_message_top']); ?>,
            datatable_message_bottom = <?php echo json_encode(empty(smc_session()['datatable_message_bottom']) ? '' : smc_session()['datatable_message_bottom']); ?>,
            today = <?php echo json_encode(Date::getToday()); ?>;
        window.onload = function() {
            // fix for windows 8
            if (navigator.appVersion.indexOf("Windows NT 6.2") != -1)
                document.head.innerHTML += '<link rel="stylesheet" type="text/css" href="pages/css/windows.chrome.fix.css" />';
        };

        $(document).ready(function() {
            $(document).on('hidden.bs.modal', '.modal', function() {
                if ($('.modal:visible').length)
                    $(document.body).addClass('modal-open');
            });
        });
    </script>
    <style type="text/css">
        <?php echo smc_session()['general_setting']['custom_style']; ?>.select2_width_class {
            width: 200px !important;
        }
    </style>

</head>

<body class="fixed-header dashboard <?= empty($full_view)/* defined in loader */ ? '' : ('main-div-' . pathinfo($full_view, PATHINFO_FILENAME)); ?>">
    <div class="snackbar_reminder" data-type="<?php echo smc_session()['reminder_end_day']; ?>"></div>
    <style type="text/css">
        #frameModal {
            /*put them here not in style since overwrite it by js.*/
            padding: 15px 15px 5px !important;
            top: 0px;
            bottom: 0px;
            right: 0px;
            left: 0px;
        }
    </style>
    <div style="position:fixed;left:0;right:0;top:0;bottom:0;display:none;background:#000;background:rgba(0,0,0,0.7);z-index:9999999;">
        <div id="frameModal" class="modal fade" tabindex="-1" data-backdrop="static" role="dialog">
            <button class="btn bg-primary white" data-dismiss="modal" style="position:absolute;top:0px;right:0px;z-index:1;background:red !important;border:0px !important;padding:1px 2px !important;opacity:0.9;" title="<?php echo CommonLanguage::getMessage('finish') ?>"><i class="fa fa-times-circle fa-2x" style="font-size:22px;color:#fff;"></i></button>
            <div class="modal-content" style="margin:0 auto;padding:0;border:2px solid #f00;width:100%;height:100%;">
                <div class="modal-body" style="margin:0 auto;padding:0;border:0;width:100%;height:100%;">
                    <iframe id="checkframe" name="trusto_global_iframe" src="about:blank" style="margin:0 auto;padding:0;border:0;width:100%;height:100%;" frameborder="0"></iframe>
                </div>
                <!--<div class="modal-footer">
                        <button class="btn bg-primary white" data-dismiss="modal"><?php echo CommonLanguage::getMessage('finish') ?></button>
                    </div>-->
                <?php echo Forms::ModalLoader('common_iframe_loader'); ?>
            </div>
        </div>
    </div>

    <script>
        $(function() {
            if ($('.snackbar_reminder').attr('data-type') == 1) {
                $('.snackbar_reminder').addClass('show');
                $('.snackbar_reminder').html('Check end of day');
                <?php smc_session()['reminder_end_day'] = 0; ?>
            }
        });
    </script>
 
  