<!doctype html>
<html lang="<?php echo $cms['config']['lang']; ?>">
<head>
<meta charset="utf-8">
<?php
if ( is_admin() ) {
    echo "<title>".__('Admin')."</title>";
} elseif ( empty( $cms['config']['admin.mod.php']['admin_login'] ) && 
           empty( $cms['config']['admin.mod.php']['admin_password'] ) ) {
    echo "<title>".__('Install')."</title>";
} else {
    echo "<title>".__('Auth')."</title>";
} ?>
<link href="https://fonts.googleapis.com/css?family=Open+Sans&display=swap&subset=cyrillic" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Source+Code+Pro&display=swap&subset=cyrillic" rel="stylesheet">
<link rel="icon" href="<?php echo $cms['base_url']; ?>img/favicon.png">
<link rel="stylesheet" type="text/css" href="<?php echo $cms['base_url']; ?>css/select2.min.css">
<script src="<?php echo $cms['base_url']; ?>js/jquery-3.3.1.min.js"></script>
<script src="<?php echo $cms['base_url']; ?>js/jquery.cookie.js"></script>
<script src="<?php echo $cms['base_url']; ?>js/jquery.form.js"></script>
<script src="<?php echo $cms['base_url']; ?>js/jquery.searcher.min.js"></script>

<?php cms_do_stage('admin_header'); ?>

<link rel=stylesheet href="<?php echo $cms['base_url']; ?>lib/codemirror-5.52.2/lib/codemirror.css">
<link rel=stylesheet href="<?php echo $cms['base_url']; ?>lib/codemirror-5.52.2/addon/hint/show-hint.css">
<link rel=stylesheet href="<?php echo $cms['base_url']; ?>lib/codemirror-5.52.2/addon/dialog/dialog.css">
<?php
$styles = array();
foreach( glob( $cms['cms_dir'].'/css/admin.*.css' ) as $file ) {
    preg_match( '/.*(\/admin\.(.*)\.(.*)\.css)/', $file, $m );
    echo "<link rel=stylesheet href='{$cms['base_url']}css{$m[1]}'>\n";
    array_push($styles,array($m[2],$m[3]));
}
echo '<script>admin_styles = '.json_encode( $styles ).';</script>';
?>
<script src="<?php echo $cms['base_url']; ?>lib/codemirror-5.52.2/lib/codemirror.js"></script>
<script src="<?php echo $cms['base_url']; ?>lib/codemirror-5.52.2/addon/hint/show-hint.js"></script>
<script src="<?php echo $cms['base_url']; ?>lib/codemirror-5.52.2/addon/hint/xml-hint.js"></script>
<script src="<?php echo $cms['base_url']; ?>lib/codemirror-5.52.2/addon/hint/html-hint.js"></script>
<script src="<?php echo $cms['base_url']; ?>lib/codemirror-5.52.2/addon/selection/active-line.js"></script>
<script src="<?php echo $cms['base_url']; ?>lib/codemirror-5.52.2/addon/search/search.js"></script>
<script src="<?php echo $cms['base_url']; ?>lib/codemirror-5.52.2/addon/search/searchcursor.js"></script>
<script src="<?php echo $cms['base_url']; ?>lib/codemirror-5.52.2/addon/search/jump-to-line.js"></script>
<script src="<?php echo $cms['base_url']; ?>lib/codemirror-5.52.2/addon/dialog/dialog.js"></script>
<script src="<?php echo $cms['base_url']; ?>lib/codemirror-5.52.2/mode/xml/xml.js"></script>
<script src="<?php echo $cms['base_url']; ?>lib/codemirror-5.52.2/mode/javascript/javascript.js"></script>
<script src="<?php echo $cms['base_url']; ?>lib/codemirror-5.52.2/mode/css/css.js"></script>
<script src="<?php echo $cms['base_url']; ?>lib/codemirror-5.52.2/mode/htmlmixed/htmlmixed.js"></script>
<script src="<?php echo $cms['base_url']; ?>js/pages.js"></script>
<script src="<?php echo $cms['base_url']; ?>js/menu.js"></script>
<script src='<?php echo $cms['base_url']; ?>js/select2.min.js' type='text/javascript'></script>
<script src='<?php echo $cms['base_url']; ?>lang/select2/<?php echo $cms['config']['lang']; ?>.js' type='text/javascript'></script>
<script src="<?php echo $cms['base_url']; ?>js/admin.js"></script>
</head>


<?php if (is_admin()): ?>

<body class="logged">

    <header>
        <div class="headscroll">
        <div class="logo"><p class="namecms">Coffee CMS</p></div>
        <a href="#" class=logout data-logout><?php echo __('Logout'); ?></a>
        <a href="#" class=theme-switcher data-theme><?php echo __('Theme'); ?></a>
        <a href="#" class=recreate-cache data-cache><?php echo __('Update Cache'); ?></a>
        <a href="/" class=open-front-page data-front target=_blank><?php echo __('Home'); ?></a>
        </div>
    </header>

  <aside>
   <div class="adminmenuwrap">
     <div class="height-corrector">
<?php
foreach( $cms['admin_sections'] as $section_name => $section ) {
    if ( !isset($section['hide']) || isset($section['hide']) && !$section['hide'] ) {
        echo '<div class="adminmenubox">';
        echo "<h1>{$cms['admin_sections'][$section_name]['title']}</h1>";
        # Пункты секции
        if ( !empty( $cms['admin_sections'][$section_name]['items'] ) )
        foreach( $cms['admin_sections'][$section_name]['items'] as $page_name => $page ) {
            if ( !isset($page['hide']) || isset($page['hide']) && !$page['hide'] ) {
                $title = __($page['title'],$page['module']);
                if ( !empty($page['class']) ) {
                    $class = " class='{$page['class']}'";
                } else {
                    $class = "";
                }
                echo "<a href=# data-am-page='{$page_name}'{$class}>{$title}</a>";
            }
        }
        echo '</div>';
    }
}
?>
      </div>
    </div>
  </aside>


  <main>
<?php

    foreach( $cms['admin_pages'] as $name => $page ) {
        echo "<div class='hidden' data-settings={$name}>{$page}</div>";
    }
    
?>
  </main>

  <footer>
  <a href="http://coffee-cms.com/instrukcii/" class="version cms" target=_blank>ver. 20.05</a>
  </footer>


<?php else: ?>

<body class="login">
  
    <header class="logintoppanel">
        <a href="#" class=theme-switcher data-theme><?php echo __('Theme'); ?></a>
    </header>

    <div class="authorization-box">
        <div class="authorization-logo"></div>
        <?php if ( empty( $cms['config']['admin.mod.php']['admin_login'] ) && 
                   empty( $cms['config']['admin.mod.php']['admin_password'] ) ) {
            echo "<div class='setup-auth'>".__('Setup Login and Password')."</div>";
        } ?>
        <div class="authorization">
            <div class="authorization-input-log">
                <input placeholder="<?php echo __('Login or Email'); ?>" name="login" type="text" class="authorization-settingx-log">
            </div>
            <div class="authorization-input-pass">
                <input placeholder="<?php echo __('Password'); ?>" name="password" type="password" class="authorization-settingx-pass">
                <button title="<?php echo __('Enter'); ?>" class="button-adminix-avtor" type="submit"></button>
            </div>
        </div>
    </div>
    
<?php endif; ?>
    
<div class="log-info-box">
    <!-- div for messages -->
</div>

</body>
</html>
