<!doctype html>
<html lang="<?php echo $cms['config']['lang']; ?>">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<?php
if ( is_admin() ) {
    echo "<title>".__('Admin')." ".$_SERVER['SERVER_NAME']."</title>";
} elseif ( empty( $cms['config']['admin.mod.php']['admin_login'] ) && 
           empty( $cms['config']['admin.mod.php']['admin_password'] ) ) {
    echo "<title>".__('Install')." ".$_SERVER['SERVER_NAME']."</title>";
} else {
    echo "<title>".__('SignIn')." ".$_SERVER['SERVER_NAME']."</title>";
} ?>
<link rel="icon" href="<?php echo $cms['base_path']; ?>img/favicon.png">

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

<?php
$styles = array();
// admin.cms_style.codemirror_style.css
foreach( glob( $cms['cms_dir'].'/css/admin.*.css' ) as $file ) {
    preg_match( '/.*(\/admin\.(.*)\.(.*)\.css)/', $file, $m );
    echo "<link rel=stylesheet href='{$cms['base_path']}css{$m[1]}'>\n";
    array_push($styles,array($m[2],$m[3]));
}
echo "<script>\nadmin_styles = ".json_encode( $styles ).";\n";

if ( !empty( $cms['config']['locale'] ) ) {
    $lang = json_encode($cms["lang"]);
    $tr   = json_encode($cms["tr"]);
    echo "cms = {};
cms.locale = '{$cms['config']['locale']}';
cms.lang = {$lang};
cms.tr = {$tr};
cms.api = '{$cms['config']['admin.mod.php']['api_url']}';
</script>\n";
}
?>

</head>


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

<body class="logged">
    <header>
        <div class="coffee-cms_logo-container">
            <div class="coffee-cms_logo-and-text">
                <div class="coffee-cms_logo-img">
                    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 233.34 233.24"><defs><style>.a-logo{fill:#564c44;}</style></defs><path class="a-logo" d="M116.62,0c-1.63,0-3.25,0-4.87.11a112.56,112.56,0,0,0,1.74,44.51c6.09,24.94,16.07,49.17,26.47,72.77,15.52,35.21,24.37,70.68,21.06,107.13A116.63,116.63,0,0,0,116.62,0Z" transform="translate(0.05)"/><path class="a-logo" d="M120.92,233.16V233c7.12-39.29-3.54-75.28-21.28-109.75-19-36.9-30.46-74.6-27.76-114.33a116.64,116.64,0,0,0,44.7,224.36C118.06,233.24,119.49,233.21,120.92,233.16Z" transform="translate(0.05)"/></svg>
                </div>
                <div class="coffee-cms_logo-text">Coffee CMS</div>
            </div>
        </div>
        <div class="coffee-cms_top-right-menu-container">
            <div id=coffee_cms_top_right_menu class="coffee-cms_top-right-menu">
                <a href="/" data-front target=_blank><?php echo __('Home'); ?></a>
                <a href="#" data-cache><?php echo __('Clear Cache'); ?></a>
                <a href="#" id=theme_switcher data-theme><?php echo __('Theme'); ?></a>
                <a href="#" data-logout><?php echo __('Logout'); ?></a>
            </div>
            
            <div class="coffee-cms_mobile-menu-buttons-container">
                <div id=coffee_cms_mobile_menu class="coffee-cms_dropdown-left-menu-mobile-button">
                    <div class="menu-icon">
                        <span class="line-1"></span>
                        <span class="line-2"></span>
                    </div>
                </div>
                <div class="coffee-cms_dropdown-right-menu-mobile-button">
                    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 30" style="display: block;"><defs><style>.a-sb{fill:none;}.b-sb{fill:#fff;}</style></defs><rect class="a-sb" width="48" height="30"/><circle class="b-sb" cx="12.03" cy="15" r="3.02"/><circle class="b-sb" cx="23.94" cy="15" r="3.02"/><circle class="b-sb" cx="35.97" cy="15" r="3.02"/></svg>
                </div>
            </div>

        </div>
    </header>

  <aside id=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 = "";
                }
                if ( empty( $page['external_url'] ) ) {
                    echo "<a href='#{$page_name}' data-am-page='{$page_name}'{$class}>{$title}</a>";
                } else {
                    echo "<a href='{$page['external_url']}' {$class}>{$title}</a>";
                }
            }
        }
        echo '</div>';
    }
}
?>

        </div>
    </div>
  </aside>


  <main>

<?php
    $hello = __("Hello!");
    if ( cms_base_connect() === false ) {
        $base_ok = __("The first step is to set up your database connection.");
    } else {
        $base_ok = "";
    }
    
echo <<<EOS
<section id="start" class="module-settings" data-settings="start">
    <div class="main-header"></div>
    <div class="main-main">
        <div class="info-grid">
            <h1>{$hello}</h1>
            <p>{$base_ok}</p>
        </div>
    </div>
    <div class="main-footer"></div>
</section>
EOS;

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

  </main>

  <div id=coffee_cms_mobile_menu_milk class="bg-reset"></div>

<?php else: ?>

<body class="login">
  
    <header>
        <div class="coffee-cms_logo-container">
            <div class="coffee-cms_logo-and-text">
                <div class="coffee-cms_logo-img">
                    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 233.34 233.24"><defs><style>.a-logo{fill:#564c44;}</style></defs><path class="a-logo" d="M116.62,0c-1.63,0-3.25,0-4.87.11a112.56,112.56,0,0,0,1.74,44.51c6.09,24.94,16.07,49.17,26.47,72.77,15.52,35.21,24.37,70.68,21.06,107.13A116.63,116.63,0,0,0,116.62,0Z" transform="translate(0.05)"/><path class="a-logo" d="M120.92,233.16V233c7.12-39.29-3.54-75.28-21.28-109.75-19-36.9-30.46-74.6-27.76-114.33a116.64,116.64,0,0,0,44.7,224.36C118.06,233.24,119.49,233.21,120.92,233.16Z" transform="translate(0.05)"/></svg>
                </div>
                <div class="coffee-cms_logo-text">Coffee CMS</div>
            </div>
        </div>
        <div class="coffee-cms_top-right-menu-container">
            <div id=cms_right_menu class="coffee-cms_top-right-menu">
                <a href="#" id=theme_switcher data-theme><?php echo __('Theme'); ?></a>
            </div>
        </div>
    </header>

    

    <div class="aside-main">
        <div class="center-box">
            <div class='setup-error'>
                <?php // config.php not writeable
                if ( isset( $cms['config_writeable'] ) && $cms['config_writeable'] === false ) {
                    echo __('Can\'t write')." ".$cms['cms_dir']."/config.php";
                }
                ?>
            </div>
            <div class="lang-selector">
                <?php if ( true|| empty( $cms['config']['admin.mod.php']['admin_password'] ) ) { ?>
                <select id=lang_selector class=settingx>
                    <option value="en_US.UTF-8">English</option>
                <?php
                    $t = array(
                        'ru_RU.UTF-8' => 'Русский',
                        'uk_UA.UTF-8' => 'Українська',
                    );
                    // Scan all locales
                    foreach( glob( 'lang/*.UTF-8',  GLOB_ONLYDIR ) as $locale ) {
                        $locale = preg_replace( '/.*\//', '', $locale );
                        if ( isset( $t[$locale] ) ) {
                            $lang = $t[$locale];
                        } else {
                            $lang = $locale;
                        }
                        echo "<option value='{$locale}'>{$lang}</option>";
                    }
                ?>
                </select>
                <?php } ?>                                                     
            </div>
            <div class='setup-auth'>
                <?php
                if ( empty( $cms['config']['admin.mod.php']['admin_login'] ) && empty( $cms['config']['admin.mod.php']['admin_password'] ) ) {
                    echo __('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">
                    <div title="<?php echo __('Enter'); ?>" class="button-adminix-avtor" type="submit" data-login-btn></div>
                </div>
            </div>
            <div class=flatfree></div>
            <div class="support-box">
                <?php echo __( "<a target=_blank href='https://coffee-cms.com/support/'>Technical Support</a>" ); ?>
            </div>
        </div>
    </div>

    
<?php endif; ?>
    
    <div class="log-info-box">
        <!-- div for messages -->
    </div>
</body>
</html>
