layout.php 14.2 KB
Newer Older
Игорь's avatar
init    
Игорь committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
<!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>
    <link rel="shortcut icon" href="/favicon.ico">
    <?php
    $path_prefix = isset($_SERVER['PATH_PREFIX']) ? $_SERVER['PATH_PREFIX'] : '';
    ?>
    <script type="text/javascript">
        var sf_app = '<?php echo sfConfig::get('sf_app');?>';
        var sf_prefix = '<?php echo $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
    if ($sf_user->isAuthenticated()) {
        if (file_exists(sfConfig::get('sf_web_js_dir_name', 'js') . $path_prefix . '/' . $this->getModuleName() . '.js')) {
            use_javascript(mb_substr($path_prefix, 1) . '/' . $this->getModuleName() . '.js');
        }
        if (file_exists(sfConfig::get('sf_web_css_dir_name', 'css') . $path_prefix . '/' . $this->getModuleName() . '.css')) {
            use_stylesheet(mb_substr($path_prefix, 1) . '/' . $this->getModuleName() . '.css');
        }
    }
    include_http_metas();
    include_stylesheets();
    include_javascripts();
    ?>
</head>
<body>
<div class="jcrop_curtain">
    <table width="100%" height="100%" cellcpacing="0" cellpadding="0">
        <tr>
            <td align="center" valign="middle">
                <div class="jcrop_curtain__long_item"></div>
            </td>
        </tr>
    </table>
</div>
<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;">
                    <?php
                    if ($sf_user->getUsername() === 'root') {
                        echo '<a href="' . url_for('@version') . '" class="version_top">v&nbsp;' . ProjectUtils::getVersion() . '</a>';
                    }
                    ?>
                    <div class="lui__desktop_left_hider" title="<?php echo __('Свернуть'); ?>"></div>
                    <div class="lui__desktop_left__wrapper">
                        <div class="logo_wrap">
                            <a target="_blank" href="/" class="logo"></a>
                        </div>
                        <i class="br20" style="border-bottom:1px solid #D8D8D866"></i>
                        <b class="br20"></b>
                        <div class="lui__nav__wrapper" style="position:relative;height: 0;">
                            <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();
                                $group_counts = 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') && $module !== 'help_dialog') || $p['generator']['param']['skip'] || $p['generator']['param']['config']['list']['title'] == '') {
                                            continue;
                                        }
                                        $model = str_replace(' ', '', ucwords(str_replace('_', ' ', $module)));
                                        $count = '';
                                        $count_number = 0;
                                        if (class_exists($model) && method_exists($model, 'getMenuCount')) {
                                            $count = $model::getMenuCount();
                                            $count_number = $count;
                                            $count = '<span class="lui__nav_menu__count">' . ($count > 0 ? $count : '') . '</span>';
                                        }

                                        $group_class = isset($p['generator']['param']['group']) ? Page::translit($p['generator']['param']['group']) : false;
                                        if($group_class !== false){
                                            if(!isset($group_counts[$group_class])){
                                                $group_counts[$group_class] = 0;
                                            }
                                            $group_counts[$group_class] += $count_number;
                                        }

                                        $links[] = array(
                                            'm' => $module,
                                            'title' => $p['generator']['param']['config']['list']['title'],
                                            'order' => isset($p['generator']['param']['order']) ? $p['generator']['param']['order'] : 0,
                                            'group' => isset($p['generator']['param']['group']) ? $p['generator']['param']['group'] : false,
                                            'group_class' => $group_class,
                                            'tab_group' => isset($p['generator']['param']['tab_group']) ? $p['generator']['param']['tab_group'] : false,
                                            'add' => isset($p['generator']['param']['add']) ? $p['generator']['param']['add'] : true,
                                            'hr' => isset($p['generator']['param']['hr']),
                                            'count' => $count
                                        );
                                    }
                                }

                                usort($links, 'menu_cmp');

                                $open_groups = array('zakazchik', 'kurer');
                                $tab_groups = array();
                                foreach ($links as $link){
                                    if($link['tab_group']){
                                        if(!isset($tab_groups[$link['tab_group']])){
                                            $tab_groups[$link['tab_group']] = array();
                                        }
                                        $tab_groups[$link['tab_group']][] = $link['m'];
                                    }
                                    if($link['group'] && $this->getModuleName() == $link['m']){
                                        $open_group = $link['group_class'];
                                    }
                                }

                                foreach ($links as $k => $v) {
                                    if($v['tab_group']){
                                        $tab_group_link_count_sum = 0;
                                        foreach ($links as $tab_group_link){
                                            if($v['tab_group'] === $tab_group_link['tab_group'] && isset($tab_group_link['count_num'])){
                                                $tab_group_link_count_sum += $tab_group_link['count_num'];
                                            }
                                        }
                                        $v['count_num'] = $tab_group_link_count_sum;
                                        $tab_groups_on = in_array($this->getModuleName(), $tab_groups[$v['tab_group']]);
                                        if(($tab_groups_on && $this->getModuleName() != $v['m']) || (!$tab_groups_on && $tab_groups[$v['tab_group']][0] != $v['m'])){
                                            continue;
                                        }
                                    }
                                    if ($v['group'] && (!isset($links[$k - 1]) || $links[$k - 1]['group'] != $v['group'])) {
                                        echo '<li class="lui__nav_li_group_btn' . (in_array($v['group_class'], $open_groups) ? ' lui__nav_li_group_btn_open' : '') . '" data-group="' . $v['group_class'] . '">';
                                        echo '<div class="lui__nav_li_group_btn__cont">' . $v['group'] . '</div>';
                                        if(isset($group_counts[$v['group_class']]) && $group_counts[$v['group_class']] > 0){
                                            echo '<span class="lui__nav_menu__count">' . $group_counts[$v['group_class']] . '</span>';
                                        }
                                        echo '</li>';
                                    }
                                    echo '<li class="' . ($this->getModuleName() == $v['m'] ? 'current' : '') . ($v['group'] ? ' lui__nav_li_group lui__nav_li_group_' . $v['group_class'] : '') . '" ' . ($v['group'] && !in_array($v['group_class'], $open_groups) ? 'style="display:none;"' : '') . '>';
                                    $link = $v['m'];
                                    echo '<a class="lui__nav_a lui__nav_a_' . $v['m'] . '" href="' . url_for('@' . $v['m']) . '">' . $v['title'] . '</a>' . $v['count'];
                                    echo '</li>';
                                    if ($v['hr'] && $k != count($links) - 1) {
                                        echo '<i class="hr20" style="margin:10px 0;background:#D8D8D866;"></i>';
                                    }
                                }
                                echo '</ul>';
                                echo '</div>';
                                echo '<div class="fixed_user_menu">';
                                echo '<div style="position:relative;">';
//                                echo link_to('Профиль', '@profile', array('class' => 'sprite_link sprite_link_user'));
                                echo '</div>';
                                echo '<i class="br10"></i>';
                                if ($sf_user->getUsername() === 'root') {
                                    echo '<a href="' . url_for('@cs_setting') . '" class="sprite_link sprite_link_setting">Настройки</a>';
                                    echo '<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>
<?php
if($sf_user->isAuthenticated()){
    ?>
    <script type="text/javascript">
        $(document).ready(function () {
            var calc_lui__nav__wrapper = function () {
                $('.lui__nav__wrapper').height($(window).height() - $('.lui__nav__wrapper').offset().top - $('.fixed_user_menu').outerHeight());
                $('.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();

            $('.lui__nav_li_group_btn').click(function(){
                var btn = $(this);
                if(btn.data('group')){
                    var groupLi = $('.lui__nav_li_group_' + btn.data('group'));
                    if(btn.hasClass('lui__nav_li_group_btn_open')){
                        btn.removeClass('lui__nav_li_group_btn_open');
                        groupLi.hide();
                    }else{
                        btn.addClass('lui__nav_li_group_btn_open');
                        groupLi.show();
                    }
                    $('.lui__nav__wrapper').scroll();
                }
            });
        });
    </script>
    <?php
}
?>
</body>
</html>