<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    <title><?php include_slot('title', sfConfig::get('app_arm_title')); ?></title>
    <?php
//    <link rel="shortcut icon" href="/i/favicon.ico" type="image/x-icon"/>
    ?>
    <script type="text/javascript">
        var sf_app = '<?php echo sfConfig::get('sf_app');?>';
        var sf_prefix = '<?php echo isset($_SERVER['PATH_PREFIX']) ? $_SERVER['PATH_PREFIX'] : '';?>';
        var sf_user = <?php echo $sf_user->isAuthenticated() ? $sf_user->getUserId() : 'false';?>;
        var sf_user_root = <?php echo ($sf_user->isAuthenticated() ? ($sf_user->getUsername() == 'root' ? 'true' : 'false') : 'false');?>;
        var sf_ws_pub = '<?php echo sfConfig::get('app_ws_pub');?>';
    </script>

    <?php
    include_http_metas();
    include_stylesheets();
    include_javascripts();
    $module_image_sizes = sfConfig::get('app_' . $this->getModuleName() . '_sizes');
    if(is_array($module_image_sizes) && count($module_image_sizes) > 0 && $this->getModuleName() != 'cat'){
        unset($module_image_sizes['min']);
        foreach ($module_image_sizes as $size_key => $size){
            $module_image_size = $size_key;
        }
        if($module_image_size == 'S' || isset($module_image_sizes['equal'])){
            $module_image_size = '';
        }
    }
    if(isset($module_image_size)){
        echo '<script type="text/javascript">ftm.openSize = \'' . $module_image_size . '\';</script>';
    }
    ?>
    <link rel="icon" href="/i/favicon.png" type="image/x-icon">
</head>
<body>
<div class="lui__root">
    <div class="ftm_wrap ftm" onclick="$(this).hide();">
        <div class="ftm__actions">
            <div class="ftm__close"></div>
            <div class="ftm__rotate" title="Повернуть по часовой стрелке" onclick="ftm.rotate(this);event.stopPropagation();return false;"></div>
        </div>
        <table width="100%" height="100%" cellpadding="0" cellspacing="0">
            <tr>
                <td valign="middle" align="center">
                    <div class="fotorama" data-auto="false" onclick="event.stopPropagation();"></div>
                </td>
            </tr>
        </table>
    </div>
    <?php
    if (!$sf_user->isAuthenticated()) {
        echo $sf_content;
    } else {
        ?>
        <table class="lui__desktop" border="0" cellspacing="0" cellpadding="0" width="100%">
            <tr valign="top">
                <td class="lui__desktop_left invert" style="padding-top:20px;">
                    <div class="lui__desktop_left__wrapper">
                        <a href="/" target="_blank"><img class="logo__full" src="/i/logo.svg" hspace="20" width="100" height="51" style="margin: 0 auto; display: block;"/></a>
                        <i class="br20" style="border-bottom:1px solid #393f41"></i>
                        <b class="br20"></b>
                        <div class="lui__nav__wrapper" style="position:relative;">
                            <ul class="lui__nav">
                                <?php
                                function menu_cmp($a, $b)
                                {
                                    if ($a['order'] == $b['order']) {
                                        return 0;
                                    }
                                    return ($a['order'] < $b['order']) ? -1 : 1;
                                }

                                $parser = new sfYamlParser();
                                $modules = glob(sfConfig::get('sf_app_module_dir') . '/*');
                                $links = array();


                                foreach ($modules as $k => $v) {
                                    if (file_exists($v . '/config/generator.yml')) {
                                        $p = $parser->parse(file_get_contents($v . '/config/generator.yml'));
                                        $module = basename($v);

                                        if (!$sf_user->hasCredential($module . '_index') || @$p['generator']['param']['skip'] || @$p['generator']['param']['config']['list']['title'] == '') {
                                            continue;
                                        }


                                        if ($sf_user->getUsername() != 'root' && basename($v) == 'manager') {
                                            continue;
                                        }

                                        $model = str_replace(' ', '', ucwords(str_replace('_', ' ', $module)));

                                        $count = '';

                                        if (class_exists($model) && method_exists($model, 'getMenuCount')) {
                                            $countc = $module::getMenuCount($sf_user);
                                            if ($countc > 0) {
                                                $count = '&nbsp;<span class="lui__nav_menu__count">' . $countc . '</span>';
                                            }
                                        }


                                        $links[] = array(
                                            'm' => $module,
                                            'title' => $p['generator']['param']['config']['list']['title'] . $count,
                                            'order' => isset($p['generator']['param']['order']) ? $p['generator']['param']['order'] : 0,
                                            'group' => isset($p['generator']['param']['group']) ? $p['generator']['param']['group'] : false,
                                            'add' => isset($p['generator']['param']['add']) ? $p['generator']['param']['add'] : true,
                                            'hr' => isset($p['generator']['param']['hr']),
                                        );
                                    }
                                }
                                usort($links, 'menu_cmp');
                                foreach ($links as $k => $v) {
                                    if ($sf_user->hasCredential($v['m'] . '_index')) {
                                        if ($v['group']) {
                                            echo '<i class="br10"></i>';
                                            if ($v['group'] != '-') {
                                                echo '<li><b>' . $v['group'] . '</b></li>';
                                            }
                                        }
                                        echo '<li' . ($this->getModuleName() == $v['m'] ? ' class="current"' : '') . '>';
                                        echo '<a class="lui__nav_a_' . $v['m'] . '" href="' . url_for('@' . $v['m']) . '">' . $v['title'] . '</a>';
                                        echo '</li>';
                                        if ($v['hr'] && $k != count($links) - 1) {
                                            echo '<i class="hr20" style="margin:10px 0;background:#2d3436;"></i>';
                                        }
                                    }
                                }
                                echo '</ul>';
                                echo '</div>';
                                echo '<div class="fixed_user_menu">';
                                echo '<a href="' . url_for('@cs_setting') . '" class="sprite_link sprite_link_settings">Настройки</a><i class="br10"></i>';
                                echo '<a href="' . url_for('@signout') . '" class="sprite_link sprite_link_logout">Выйти</a>';
                                echo '</div>';
                                ?>
                        </div>
                </td>
                <td width="100%" class="lui__desktop_right" height="100%">
                    <div class="lui__desktop_right__wrapper <?php echo sfConfig::get('sf_app') . '_' . $this->getModuleName(); ?>">
                        <?php
                        echo $sf_content;
                        ?>
                    </div>
                </td>
            </tr>
        </table>
        <?php
    }
    ?>
</div>
<script type="text/javascript">
    $(document).ready(function () {
        var calc_lui__nav__wrapper = function () {
            $('.lui__nav__wrapper').height($(window).height() - 200);
            $('.lui__nav__wrapper').perfectScrollbar('update');
        };
        $('.lui__nav__wrapper').perfectScrollbar();
        $('.lui__nav__wrapper').scroll(function () {

            var top = $(this).scrollTop();
            var bottom = $('.lui__nav').outerHeight() - $(this).outerHeight();


            $(this).removeClass('lui__nav__wrapper__sh_top');
            $(this).removeClass('lui__nav__wrapper__sh_bottom');
            $(this).removeClass('lui__nav__wrapper__sh_bottom_top');

            if (bottom < 0) {
                return false;
            }

            if (top == 0) {
                $(this).addClass('lui__nav__wrapper__sh_bottom');
            } else if (top == bottom) {
                $(this).addClass('lui__nav__wrapper__sh_top');
            } else {
                $(this).addClass('lui__nav__wrapper__sh_bottom_top');
            }
        }).scroll();

        $(window).resize(function () {
            calc_lui__nav__wrapper();
            $('.lui__nav__wrapper').scroll();
        }).resize();

    });
</script>
</body>
</html>