<?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\widgets\Menu;
use yii\widgets\ActiveForm;

$this->title = 'Certificate';
$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
            if ($model->private_key == null && $model->trusted == null) {
                $readonly = false;
            } else
                $readonly = true;
            ?>
            <?php $form = ActiveForm::begin(['id' => 'form-cer']); ?>

            <?= $form->field($model, 'name')->textInput(['readonly' => $readonly]); ?>
            <?= $form->field($model, 'country')->textInput(['readonly' => $readonly]); ?>
            <?= $form->field($model, 'state')->textInput(['readonly' => $readonly]); ?>
            <?= $form->field($model, 'locality')->textInput(['readonly' => $readonly]); ?>
            <?= $form->field($model, 'organization')->textInput(['readonly' => $readonly]); ?>
            <?= $form->field($model, 'unit')->textInput(['readonly' => $readonly]); ?>
            <?= $form->field($model, 'common_name')->label('Common Name')->textInput(['readonly' => $readonly]); ?>
            <?= $form->field($model, 'subject_alt_name')->textInput(['readonly' => $readonly]); ?>
            <?=
            $form->field($model, 'key_size')->dropDownList(['1024' => '1024',
                '1536' => '1536',
                '2048' => '2048',
                '4096' => '4096',
                '8192' => '8192',
                    ], ['readonly' => $readonly]);
            ?>
            <?= $form->field($model, 'days_valid')->label('Days Valid')->textInput(['readonly' => $readonly]); ?>
            <?=
            $form->field($model, 'key_usage')->dropDownList(['digital-signature' => 'digital-signature',
                'content-commitment' => 'content-commitment',
                'key-encipherment' => 'key-encipherment',
                'data-encipherment' => 'data-encipherment',
                'key-agreement' => 'key-agreement',
                'key-cert-sign' => 'key-cert-sign',
                'crl-sign' => 'crl-sign',
                'encipher-only' => 'encipher-only',
                'decipher-only' => 'decipher-only',
                'tls-server' => 'tls-server',
                'tls-client' => 'tls-client',
                'code-sign' => 'code-sign',
                'email-protect' => 'email-protect',
                'ipsec-end-system' => 'ipsec-end-system',
                'ipsec-tunnel' => 'ipsec-tunnel',
                'ipsec-user' => 'ipsec-user',
                'timestamp' => 'timestamp',
                'ocsp-sign' => 'ocsp-sign',
                'server-gated-crypto' => 'server-gated-crypto',
                'dvcs' => 'dvcs',
                    ], ['multiple' => true, 'readonly' => $readonly]);
            ?>
            <?php
            if ($model->private_key == null) {

                if ($model->name != null) {
                    echo ' ' . Html::submitButton('Update', ['class' => 'btn btn-primary', 'name' => 'create-button']) . ' ';
                    echo Html::a('Sign', ['sign', 'id' => $model->id], ['class' => 'btn btn-primary']);
                    // echo ' ' . Html::submitButton('Sign', ['class' => 'btn btn-primary', 'name' => 'create-button', 'id' => $model->id]);
                } else {
                    echo Html::submitButton('Create', ['class' => 'btn btn-primary', 'name' => 'create-button']);
                }
            } else {
                echo Html::a('Export', ['export', 'id' => $model->id], ['class' => 'btn btn-primary']);
            }
            ?>

        </div>
        <?php ActiveForm::end();
        ?> 
    </div>
</div>
</div>



