<?php

use yii\bootstrap\Alert;

if (Yii::$app->session->getFlash('message') != null) {
    echo Alert::widget([
        'options' => [
            'class' => 'alert-info',
        ],
        'body' => Yii::$app->session->getFlash('message'),
    ]);
}

use yii\helpers\Html;
use yii\helpers\Url;
use yii\grid\GridView;
use yii\widgets\Menu;
use yii\bootstrap\Tabs;
use yii\bootstrap\Nav;

$this->title = 'PPP';
$this->params['breadcrumbs'] = [
    'Mikrotik',
    $this->title,
];
?>
<div class="site-plugins">
    <div class="row">
        <div class="col-lg-3">
            <?php
            echo Menu::widget($menu);
            ?> 
        </div>
        <div class="col-md-9">
            <h1 style="margin-top: 0px"><?= Html::encode($this->title) ?></h1>

            <?php
            echo Nav::widget([
                'options' => ['class' => 'navbar-nav navbar-right'],
                'items' => [
                    ['label' => 'Settings', 'items' => [
                            ['label' => 'PPTP Server', 'url' => \yii\helpers\Url::toRoute(['mikrotik/ppp/ppp/update?type=pptp',])],
                            ['label' => 'SSTP Server', 'url' => \yii\helpers\Url::toRoute(['mikrotik/ppp/ppp/update?type=sstp',])],
                            ['label' => 'L2TP Server', 'url' => \yii\helpers\Url::toRoute(['mikrotik/ppp/ppp/update?type=l2tp',])],
                            ['label' => 'OVPN Server', 'url' => \yii\helpers\Url::toRoute(['mikrotik/ppp/ppp/update?type=ovpn',])],
                        ]], ['label' => 'Add', 'items' => [
                            ['label' => 'PPP Client', 'url' => \yii\helpers\Url::toRoute(['mikrotik/ppp/ppp/create?type=ppp-client',])],
                            ['label' => 'PPTP Server Binding', 'url' => \yii\helpers\Url::toRoute(['mikrotik/ppp/ppp/create?type=pptp-server',])],
                            ['label' => 'PPTP Client', 'url' => \yii\helpers\Url::toRoute(['mikrotik/ppp/ppp/create?type=pptp-client',])],
                            ['label' => 'SSTP Server Binding', 'url' => \yii\helpers\Url::toRoute(['mikrotik/ppp/ppp/create?type=sstp-server',])],
                            ['label' => 'SSTP Client', 'url' => \yii\helpers\Url::toRoute(['mikrotik/ppp/ppp/create?type=sstp-client',])],
                            ['label' => 'L2TP Server Binding', 'url' => \yii\helpers\Url::toRoute(['mikrotik/ppp/ppp/create?type=l2tp-server',])],
                            ['label' => 'L2TP Client', 'url' => \yii\helpers\Url::toRoute(['mikrotik/ppp/ppp/create?type=l2tp-client',])],
                            ['label' => 'OVPN Server Binding', 'url' => \yii\helpers\Url::toRoute(['mikrotik/ppp/ppp/create?type=ovpn-server',])],
                            ['label' => 'OVPN Client', 'url' => \yii\helpers\Url::toRoute(['mikrotik/ppp/ppp/create?type=ovpn-client',])],
                            ['label' => 'PPPoE Server Binding', 'url' => \yii\helpers\Url::toRoute(['mikrotik/ppp/ppp/create?type=pppoe-server',])],
                            ['label' => 'PPPoE Client', 'url' => \yii\helpers\Url::toRoute(['mikrotik/ppp/ppp/create?type=pppoe-client',])],
                        ]],
            ]]);
            $tabs[] = ['label' => 'Interface', 'content' => GridView::widget([
                    'dataProvider' => $provider['interface'],
                    'id' => 'type',
                    'rowOptions' => function($provider) {
                        if ($provider->disabled == 'true') {
                            return ['class' => 'info',];
                        }
                    },
                            'columns' => [
                                'name:text:Name',
                                'type:text:Type',
                                [
                                    'class' => 'yii\grid\ActionColumn',
                                    'template' => '{update} {delete}',
                                    'buttons' => [
                                        'update' => function ($url, $model, $key) {
                                            $options = array_merge([
                                                'title' => Yii::t('yii', 'Update'),
                                                'aria-label' => Yii::t('yii', 'Update'),
                                                //'data-confirm' => Yii::t('yii', 'Are you sure you want to update this item?'),
                                                'data-method' => 'post',
                                                'data-pjax' => '0',
                                            ]);
                                            $url = \yii\helpers\Url::toRoute(['mikrotik/ppp/ppp/update', 'id' => $key, 'type' => $model->type]);
                                            return Html::a('<span class="glyphicon glyphicon-pencil"></span>', $url, $options);
                                        },
                                                'delete' => function ($url, $model, $key) {
                                            $options = array_merge([
                                                'title' => Yii::t('yii', 'Delete'),
                                                'aria-label' => Yii::t('yii', 'Delete'),
                                                'data-confirm' => Yii::t('yii', 'Are you sure you want to delete this item?'),
                                                'data-method' => 'post',
                                                'data-pjax' => '0',
                                            ]);
                                            $url = \yii\helpers\Url::toRoute(['mikrotik/ppp/ppp/delete', 'id' => $key, 'type' => $model->type]);
                                            return Html::a('<span class="glyphicon glyphicon-trash"></span>', $url, $options);
                                        }
                                            ],
                                            'controller' => 'mikrotik/ppp/ppp',
                                        ],
                                    ],
                                    'showFooter' => false,
                                ])
                            ];
                            $tabs[] = ['label' => 'PPPoE Servers', 'content' => GridView::widget([
                                    'dataProvider' => $provider['server'],
                                    'id' => 'interfaces',
                                    'rowOptions' => function($provider) {
                                        if ($provider->disabled == 'true') {
                                            return ['class' => 'info',];
                                        }
                                    },
                                            'columns' => [
                                                'service_name:text:Service Name',
                                                'interface:text:Interface',
                                                'max_mtu:text:Max MTU',
                                                'max_mru:text:Max MRU',
                                                'mrru:text:MRRU',
                                                'default_profile:text:Default Profile',
                                                'authentication:text:Authentication',
                                                [
                                                    'class' => 'yii\grid\ActionColumn',
                                                    'template' => '{update} {delete}',
                                                    'controller' => 'mikrotik/ppp/servers',
                                                    'header' => Html::button('Add', ['class' => 'btn btn-primary', 'name' => 'add-button', 'onclick' =>
                                                        'js:document.location.href="' . Url::toRoute('mikrotik/ppp/servers/create') . '"']),
                                                ],
                                            ],
                                            'showFooter' => false,
                                        ])
                                    ];
                                    $tabs[] = ['label' => 'Secrets', 'content' => GridView::widget([
                                            'dataProvider' => $provider['secrets'],
                                            'id' => 'interfaces',
                                            'rowOptions' => function($provider) {
                                                if ($provider->disabled == 'true') {
                                                    return ['class' => 'info',];
                                                }
                                            },
                                                    'columns' => [
                                                        'name:text:Name',
                                                        'service:text:Service',
                                                        'caller_id:text:Caller ID',
                                                        'profile:text:Profile',
                                                        'local_address:text:Local Address',
                                                        'remote_address:text:Remote Address',
                                                        'last_logged_out:text:Last Logged Out',
                                                        [
                                                            'class' => 'yii\grid\ActionColumn',
                                                            'template' => '{update} {delete}',
                                                            'controller' => 'mikrotik/ppp/secrets',
                                                            'header' => Html::button('Add', ['class' => 'btn btn-primary', 'name' => 'add-button', 'onclick' =>
                                                                'js:document.location.href="' . Url::toRoute('mikrotik/ppp/secrets/create') . '"']),
                                                            'footer' => Html::button('Auth. & Accounting', ['class' => 'btn btn-primary', 'name' => 'add-button', 'onclick' =>
                                                                'js:document.location.href="' . Url::toRoute('mikrotik/ppp/aaa/update') . '"']),
                                                        ],
                                                    ],
                                                    'showFooter' => true,
                                                ])
                                            ];
                                            $tabs[] = ['label' => 'Profiles', 'content' => GridView::widget([
                                                    'dataProvider' => $provider['profiles'],
                                                    'id' => 'interfaces',
                                                    'columns' => [
                                                        'name:text:Name',
                                                        'local_address:text:Local Address',
                                                        'remote_address:text:Remote Address',
                                                        'bridge:text:Bridge',
                                                        'rate_limit:text:Rate Limit',
                                                        'only_one:text:Only One',
                                                        [
                                                            'class' => 'yii\grid\ActionColumn',
                                                            'template' => '{update} {delete}',
                                                            'controller' => 'mikrotik/ppp/profiles',
                                                            'header' => Html::button('Add', ['class' => 'btn btn-primary', 'name' => 'add-button', 'onclick' =>
                                                                'js:document.location.href="' . Url::toRoute('mikrotik/ppp/profiles/create') . '"']),
                                                        ],
                                                    ],
                                                    'showFooter' => false,
                                                ])
                                            ];
                                            $tabs[] = ['label' => 'Active Connections', 'content' => GridView::widget([
                                                    'dataProvider' => $provider['active'],
                                                    'id' => 'interfaces',
                                                    'columns' => [
                                                        'name:text:Name',
                                                        'service:text:Service',
                                                        'caller_id:text:Caller ID',
                                                        'address:text:Address',
                                                        'uptime:text:Uptime',
                                                        'encoding:text:Encoding',
                                                        [
                                                            'class' => 'yii\grid\ActionColumn',
                                                            'template' => '',
                                                            'controller' => 'mikrotik/ppp/ppp',
                                                        ],
                                                    ],
                                                    'showFooter' => false,
                                                ])
                                            ];

                                            $tabs[] = ['label' => 'L2TP Secrets', 'content' => GridView::widget([
                                                    'dataProvider' => $provider['l2tpsecret'],
                                                    'id' => 'interfaces',
                                                    'columns' => [
                                                        'address:text:Address',
                                                        [
                                                            'class' => 'yii\grid\ActionColumn',
                                                            'template' => '{update} {delete}',
                                                            'controller' => 'mikrotik/ppp/l2tpsecrets',
                                                            'header' => Html::button('Add', ['class' => 'btn btn-primary', 'name' => 'add-button', 'onclick' =>
                                                                'js:document.location.href="' . Url::toRoute('mikrotik/ppp/l2tpsecrets/create') . '"']),
                                                        ],
                                                    ],
                                                    'showFooter' => false,
                                                ])
                                            ];

//           

                                            echo Tabs::widget([
                                                'items' => $tabs]);
//                                                            
                                            ?>



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



