<?php
use yii\helpers\Url;
use qcbase\models\Auth;
use common\models\PermissionScope;
use yii\widgets\ActiveForm;
use qcbase\assets\RoleAuthAsset;

RoleAuthAsset::register($this);
?>
<style>
    .table-bordered {
        border: 1px solid #ddd;
    }
    .table-bordered th, .table-bordered td {
        border: 1px solid #ddd;
    }
    .table {
        width: 100%;
        margin-bottom: 18px;
    }
    table {
        max-width: 100%;
        background-color: transparent;
    }
    .table-priv caption {
        background-color: #f5f5f5;
        border: 1px solid #DDD;
        height: 40;
        line-height: 40px;
        text-align: left;
        padding-left: 8px;
        font-size: 15px;
    }
    .table-priv td {
        padding: 8px 40px;
        line-height: 20px;
    }
    .table-bordered td {
        border: 1px solid #ddd;
    }
    .form-inline .checkbox {
        display: inline-block;
        padding-left: 0;
        margin-top: 0;
        margin-bottom: 0;
    }
    .table-priv td label {
        /*width: 200px;*/
        font-size: 12px;
        padding: 5px 10px;
    }
    .table-priv th {
        vertical-align: middle;
    }
    .table th, .table td {
        padding: 8px;
        line-height: 1.42857143;
        vertical-align: top;
        border-bottom: 1px solid #ddd;
        -webkit-transition: all .3s cubic-bezier(.175,.885,.32,1);
        -o-transition: all .3s cubic-bezier(.175,.885,.32,1);
        transition: all .3s cubic-bezier(.175,.885,.32,1);
    }
    select {
        height: 25px;
        line-height: 25px;
        padding: 2px;
        -webkit-border-radius: 4px;
        -moz-border-radius: 4px;
        border-radius: 4px; 
        vertical-align: middle; 
    }
</style>


<div class="nav">
    <ul class="cc">
        <?php foreach ($app_list as $app): ?>
        <li <?php
        if ($app['value'] == $app_name) {
        echo "class='current'";
        }
        ?>><a href="<?= Url::to(['role/show-auth-menu', 'role' => $role, 'user_id' => $user_id, 'app_name' => $app['value']]) ?>"><?= $app['name'] ?></a></li>
        <?php endforeach; ?>
    </ul>
</div>

<div class="h_a">温馨提示</div>
<div class="prompt_text">
<p>1.您正在给 <b><?= $role ?></b> 授权，勾选多选框添加权限，如需限定权限范围，可选择其后的下拉框来限定</p>
<p>2.数据范围分为以下四种：“所有人”:所有人的数据范围、“仅自己”:仅仅自己的数据范围、“部门所有人”:当前用户和其所在部门及其子部门下所有人的数据范围（包括用户所在部门的人）、“自己和下属”:当前用户和其所处角色的子角色下所有人的数据范围（不包括用户所处角色下的人）</p>
<p>3.特别说明：“编辑”控制进入编辑页面的权限，“提交更新”真实控制修改更新数据权限</p>
</div>


<div class="list">
    <form class="form-inline" id="main-form" action="<?= Url::to(['auth']) ?>" method="post">
        <input type="hidden" name="_csrf" value="<?= Yii::$app->request->getCsrfToken() ?>" />
        <input type="hidden" name="role" value="<?= $role ?>" />
        <input type="hidden" name="app_name" value="<?= $app_name ?>" />
        <?php foreach ($authList as $firstAuth) : ?>
        <div class="item">
            <div class="item-content">
                <table class="table table-hover table-bordered table-priv"> 
                    <caption>
                        <label class="checkbox" style="font-weight:600">
                        <?= $firstAuth['name'] ?> <input type="checkbox" class="check-item"> 
                        </label>
                    </caption>
                    <tbody>
                    <?php if (isset($firstAuth['second_menu'])) : ?>
                    <?php foreach ($firstAuth['second_menu'] as $secondAuth) : ?>
                        <tr>
                            <th class="text-right" style="width:100px;">
                                <label class="checkbox">
                                <?= $secondAuth['name'] ?> <input type="checkbox" class="check-tr"> 
                                </label>
                            </th>
                            <td id="order">
                            <?php if (isset($secondAuth['third_menu'])) : ?>
                            <?php foreach ($secondAuth['third_menu'] as $thirdAuth) : ?>
                            <p style="width:240px;display:inline-block;">
                            <label class="checkbox" title="<?= (empty($thirdAuth['remark'])) ? $thirdAuth['name'] : $thirdAuth['remark'] ?>" ><input type="checkbox" name="permissions[]" value="<?= $thirdAuth['auth_url'] ?>" <?= isset($thirdAuth['checked']) ? 'checked="checked"' : '' ?> > <?= $thirdAuth['name'] ?>
                            </label>
                            <?php if ($thirdAuth['show_scope'] == 1) : ?>
                            <select name="permission_scopes[<?= $thirdAuth['auth_url'] ?>]" >
                                <?php foreach (PermissionScope::getScopes() as $scope) : ?>
                                <option <?= (isset($roleScopes[$thirdAuth['auth_url']]) && $roleScopes[$thirdAuth['auth_url']]['scope'] == $scope['value']) ? 'selected="selected"' : '' ?>  value="<?= $scope['value'] ?>"><?= $scope['name'] ?></option>
                                <?php endforeach; ?>
                            </select>
                            <?php endif; ?>
                            </p>

                            <?php endforeach; ?>
                            <?php endif; ?>
                            </td>
                        </tr>
                    <?php endforeach; ?>
                    <?php endif; ?>
                    </tbody>
                </table>
            </div>
        </div>
        <?php endforeach; ?>
    </form>
</div>

<div class="btn_wrap">
    <div class="btn_wrap_pd">
        <button class="btn btn_submit mr10" onclick="javascript:this.innerHTML='正在授权中...';document.getElementById('main-form').submit();" type="submit" >授权</button>
        <button type="submit" class="btn mr10 switch-check-all">全选</button>
    </div>
</div>

