<?php include 'template_config.php'; // Configuration php file ?>
<!DOCTYPE html>
<!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
    <head>
        <meta charset="utf-8">
        <title> <?php 
            echo $template['title']; ?></title>

        <meta name="description" content="<?php echo $template['description'] ?>">
        <meta name="author" content="<?php echo $template['author'] ?>">
        <meta name="robots" content="noindex, nofollow">

        <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1.0">

        <!-- Icons -->
        <!-- The following icons can be replaced with your own, they are used by desktop and mobile browsers -->
        <!--<link rel="shortcut icon" href="img/favicon.ico">
        <link rel="apple-touch-icon" href="img/apple-touch-icon.png">
        <link rel="apple-touch-icon" sizes="57x57" href="img/apple-touch-icon-57x57-precomposed.png">
        <link rel="apple-touch-icon" sizes="72x72" href="img/apple-touch-icon-72x72-precomposed.png">
        <link rel="apple-touch-icon" sizes="114x114" href="img/apple-touch-icon-114x114-precomposed.png">
        <link rel="apple-touch-icon-precomposed" href="img/apple-touch-icon-precomposed.png">-->
        <!-- END Icons -->

        <!-- Stylesheets -->
        <!-- The Open Sans font is included from Google Web Fonts -->
        <link rel="stylesheet" href='http://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,800italic,300,400,800'>

        <!-- Bootstrap is included in its original form, unaltered -->
        <link rel="stylesheet" href="<?= $base_url ?>theme/admin/css/bootstrap.css">

        <!-- Related styles of various icon packs and javascript plugins -->
        <link rel="stylesheet" href="<?= $base_url ?>theme/admin/css/plugins.css">

        <!-- The main stylesheet of this template. All Bootstrap overwrites are defined in here -->
        <link rel="stylesheet" href="<?= $base_url ?>theme/admin/css/main.css">
        <link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">
        <link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/themes/smoothness/jquery-ui.css">
        <!-- Include a specific file here from css/themes/ folder to alter the default theme of the template -->
        <?php if ($template['theme']) { ?>
        <link id="theme-link" rel="stylesheet" href="<?= $base_url ?>theme/admin/css/themes/<?php echo $template['theme']; ?>.css">
        <?php } ?>
        
        
        <?php
        if(isset($stylesheets) && count($stylesheets) > 0) {
           foreach($stylesheets as $stylesheet) {
        ?> 
              <link href="<?= $base_url ?>theme/admin/css/<?= $stylesheet ?>" rel="stylesheet" type="text/css" >
        <?php
            }
        }
        ?>

        <!-- The themes stylesheet of this template (for using specific theme color in individual elements - must included last) -->
        <link rel="stylesheet" href="<?= $base_url ?>theme/admin/css/themes.css">
        <!-- END Stylesheets -->

        <!-- Modernizr (Browser feature detection library) & Respond.js (Enable responsive CSS code on browsers that don't support it, eg IE8) -->
        <script src="<?= $base_url ?>js/admin/js/vendor/modernizr-2.6.2-respond-1.3.0.min.js"></script>
    </head>

    <!-- Body -->
    <!-- In the PHP version you can set the following options from the config file -->
    <!--
        Add one of the following classes to the body element for the desirable feature:
        'sidebar-left-pinned'                         for a left pinned sidebar (always visible > 1200px)
        'sidebar-right-pinned'                        for a right pinned sidebar (always visible > 1200px)
        'sidebar-left-pinned sidebar-right-pinned'    for both sidebars pinned (always visible > 1200px)
    -->
    <?php
    $body_classes = '';

    if ($template['header'] == 'navbar-fixed-top')
        $body_classes = 'header-fixed-top';
    else if ($template['header'] == 'navbar-fixed-bottom')
        $body_classes = 'header-fixed-bottom';

    if ($template['navigation'])
        $body_classes .= ' ' . $template['navigation'];
    
    $body_classes .= ' sidebar-left-pinned';
    
    ?>
    <body<?php if ($body_classes) echo ' class="' . $body_classes . '"'; ?>>
        <!-- Left Sidebar -->
        <!-- In the PHP version you can set the following options from the config file -->
        <!-- If you add the class .enable-hover, then a small portion of left sidebar will be visible and it can be opened with a mouse hover (> 1200px) (may affect website performance) -->
        <div id="sidebar-left"<?php if ($template['sidebar_left'] == 'enable-hover') echo ' class="enable-hover"'; ?>>
            <!-- Sidebar Content -->
            <div class="sidebar-content">
                <!-- Search Form -->
                <!-- END Search Form -->
                <div>
                    <img src="<?= $base_url ?>images/imgo.jpg" style="width:120px;height:120px;margin-left:20%;"/>
                </div>
                <!-- Wrapper for scrolling functionality -->
                <div class="sidebar-left-scroll" >
                    <?php if ($primary_nav) { ?>
                    <!-- Sidebar Navigation -->
                    <ul class="sidebar-nav" style="width: 215px !important;">
                        <?php 
                        foreach ($primary_nav as $key => $link) {
                            $link_class = '';
                            //if($link['id'] != 0 && in_array($link['id'], $permissions) == false)continue;
                            // Get link's vital info
                            $url = (isset($link['url']) && $link['url']) ? $link['url'] : '#';
                            $link_functions = explode(',', $link['function']);
                            $active = (isset($link['function']) && (in_array($template['active_page'], $link_functions))) ? ' active' : '';
                            if($active == '' && $link['function'] != $template['default_controller'] && $link['function'] != ''){
                                if(strpos($_SERVER['PHP_SELF'],$link['function'])){
                                    $active = ' active';
                                }
                            }
                            $icon = (isset($link['icon']) && $link['icon']) ? '<i class="' . $link['icon'] . '"></i>' : '';

                            // Check if we need add the class active to the li element (only if a sublink is active)
                            $li_active = '';
                            $menu_link = '';

                            if (isset($link['sub']) && $link['sub']) {
                                foreach ($link['sub'] as $sub_link) {
                                    if (in_array($template['active_page'], $sub_link)) {
                                        $li_active = ' class="active"';
                                        break;
                                    }
                                }

                                $menu_link = 'menu-link';
                            }

                            if ($menu_link || $active)
                                $link_class = ' class="'. $menu_link . $active .'"';
                        ?>
                            <?php if ($url == 'header') { ?>
                            <li>
                                <h2 class="sidebar-header"><?php echo $link['name']; ?></h2>
                            </li>
                            <?php } else { ?>
                            <li<?php echo $li_active; ?>>
                                <a href="<?= $base_url ?><?php echo $url; ?>"<?php echo $link_class; ?>><?php echo $icon . $link['name']; ?></a>
                                <?php if (isset($link['sub']) && $link['sub']) { ?>
                                    <ul>
                                        <?php foreach ($link['sub'] as $sub_link) {
                                            // Get sublink's vital info
                                            $url = (isset($sub_link['url']) && $sub_link['url']) ? $sub_link['url'] : '#';
                                            $active = (isset($sub_link['url']) && ($template['active_page'] == $sub_link['url'])) ? ' class="active"' : '';
                                        ?>
                                        <li>
                                            <a href="<?= $base_url ?><?php echo $url; ?>"<?php echo $active; ?>><?php echo $sub_link['name']; ?></a>
                                        </li>
                                        <?php } ?>
                                    </ul>
                                <?php } ?>
                            </li>
                            <?php } ?>
                        <?php } ?>
                    </ul>
                    <!-- END Sidebar Navigation -->
                    <?php } ?>
                </div>
                <!-- END Wrapper for scrolling functionality -->
            </div>
            <!-- END Sidebar Content -->
        </div>
        <!-- END Left Sidebar -->

        <!-- Page Container -->
        <!-- In the PHP version you can set the following options from the config file -->
        <!-- Add the class .full-width for a full width page (100%, 1920px max width) -->
        <div id="page-container"<?php if ($template['page'] == 'full-width') echo ' class="full-width"'; ?>>
            <!-- Header -->
            <!-- In the PHP version you can set the following options from the config file -->
            <!-- Add the class .navbar-default or .navbar-inverse for a light or dark header respectively -->
            <!-- Add the class .navbar-fixed-top or .navbar-fixed-bottom for a fixed header on top or bottom respectively -->
            <!-- If you add the class .navbar-fixed-top remember to add the class .header-fixed-top to <body> element -->
            <!-- If you add the class .navbar-fixed-bottom remember to add the class .header-fixed-bottom to <body> element -->
            <header class="navbar<?php if ($template['header_navbar']) echo ' ' . $template['header_navbar']; ?><?php if ($template['header']) echo ' '. $template['header']; ?>">
                <!-- Right Header Navigation -->
                <ul class="nav header-nav pull-left">
                    <li class="">
                        <a href="javascript:void(0)" id="sidebar-left-toggle">
                            <i class="icon-reorder"></i>
                        </a>
                    </li>
                </ul>
                <!-- END Left Header Navigation -->

                <!-- Header Brand -->
                <div class='header_title'><?php echo $template['name']; ?></div>
                <a href="<?= $base_url ?>admin/logout" class="logout"><i class="icon-off"></i> Logout</a>
                <!-- END Header Brand -->
            </header>
            <!-- END Header -->

            <!-- FX Container -->
            <!-- In the PHP version you can set the following options from the config file -->
            <!--
                All effects apply in resolutions larger than 1200px width
                Add one of the following classes to #fx-container for setting an effect to main content when one of the sidebars are opened
                'fx-none'           remove all effects (better website performance)
                'fx-opacity'        opacity effect
                'fx-move'           move effect
                'fx-push'           push effect
                'fx-rotate'         rotate effect
                'fx-push-move'      push-move effect
                'fx-push-rotate'    push-rotate effect
            -->
            <div id="fx-container"<?php if ($template['content_fx']) echo ' class="'.$template['content_fx'].'"'; ?>>
                
                <?php
                    $success_message = $this->session->flashdata('success_message');
                    $class = 'style="display:none"';
                    if($success_message != '' && $success_message != false){
                        $class = '';
                    }else{
                        $success_message = '';
                    }    
                 ?>
                
                <div class="alert alert-success alert-dismissible" role="alert" id="alert_message" <?= $class ?>>
                            <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <span id="box_success_message"><?= $success_message ?></span>
                </div>  
