<?php
/**
 * Created by PhpStorm.
 * User: chenkuan
 * Date: 2017/12/19
 * Time: 上午10:58
 */
use yii\helpers\Url;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>BIT System 后台管理平台</title>
    <?php include(Yii::getAlias("@cp_module_views")."/common/css_js_main.php") ?>
</head>
<body id="main">
<div class="main-nav"> <span class="fn-left"><?php if($isAddAction) { ?>添加<?php } else { ?>编辑<?php } ?>角色</span> <span class="fn-right"><a href="javascript:javascript:history.go(-1);"><i class="icon-chevron-left"></i>返回</a></span>
    <div class="fn-clear"></div>
</div>
<div class="main-content">
    <div class="form-or-table">
        <form class="form-horizontal" id="validateForm" action="<?= Url::to(['/cp/role/save']) ?>" method="post">
            <input type="hidden" name="<?= Yii::$app->request->csrfParam ?>" value="<?= Yii::$app->request->getCsrfToken() ?>">
            <input type="hidden" name="id" value="<?= isset($role['id']) ? $role['id'] : ''?>" />
            <fieldset>
                <div class="blank15"></div>
                <?php $is_system = isset($role['is_system']) ? $role['is_system'] : ''; if($is_system) { ?>
                    <div class="alert alert-error"> 系统内置角色，不允许修改! </div>
                <?php } ?>
                <div class="control-group">
                    <label class="control-label"><span class="must-input">*</span>角色名称</label>
                    <div class="controls">
                        <input type="text" id="name" name="name" class="span5" value="<?= isset($role['name']) ? $role['name'] : ''?>"/>
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label" for="inlineCheckboxes">权限</label>
                    <div class="controls">
                        <p><label class="checkbox inline"> <input type="checkbox" id="ROLE_article" name="authorityList[]" value="ROLE_article" <?php if($isAddAction || ($userId == 1)) {?> checked<?php } ?>/> 文章管理 </label></p>
                        <p><label class="checkbox inline"> <input type="checkbox" id="ROLE_index" name="authorityList[]" value="ROLE_index" <?php if($isAddAction || ($userId == 1)) {?> checked<?php } ?>/> 首页管理 </label></p>
                        <p><label class="checkbox inline"> <input type="checkbox" id="ROLE_articleCategory" name="authorityList[]" value="ROLE_articleCategory" <?php if($isAddAction || ($userId == 1)) {?> checked<?php } ?>/> 文章分类管理 </label></p>
<!--                        <p><label class="checkbox inline"> <input type="checkbox" id="ROLE_product" name="authorityList[]" value="ROLE_product" <?php /*if($isAddAction) {*/?> checked<?php /*} */?>/> 产品管理 </label></p>
                        <p><label class="checkbox inline"> <input type="checkbox" id="ROLE_productCategory" name="authorityList[]" value="ROLE_productCategory" <?php /*if($isAddAction) {*/?> checked<?php /*} */?>/> 产品分类管理 </label></p>

                        <p><label class="checkbox inline"> <input type="checkbox" id="ROLE_slide" name="authorityList[]" value="ROLE_slide" <?php /*if($isAddAction) {*/?> checked<?php /*} */?>/> 轮播管理 </label></p>-->
<!--                        <p><label class="checkbox inline"> <input type="checkbox" id="ROLE_finalContent" name="authorityList[]" value="ROLE_finalContent" <?php /*if($isAddAction) {*/?> checked<?php /*} */?>/> 固定内容管理 </label></p>
                        <p><label class="checkbox inline"> <input type="checkbox" id="ROLE_special" name="authorityList[]" value="ROLE_special" <?php /*if($isAddAction) {*/?> checked<?php /*} */?>/> 专题管理 </label></p>
                        <p><label class="checkbox inline"> <input type="checkbox" id="ROLE_navigation" name="authorityList[]" value="ROLE_navigation" <?php /*if($isAddAction) {*/?> checked<?php /*} */?>/> 导航管理 </label></p>
                        <p><label class="checkbox inline"> <input type="checkbox" id="ROLE_lm" name="authorityList[]" value="ROLE_lm" <?php /*if($isAddAction) {*/?> checked<?php /*} */?>/> 留言管理 </label></p>
                        <p><label class="checkbox inline"> <input type="checkbox" id="ROLE_friendLink" name="authorityList[]" value="ROLE_friendLink" <?php /*if($isAddAction) {*/?> checked<?php /*} */?>/> 友情链接管理 </label></p>
                        <p><label class="checkbox inline"> <input type="checkbox" id="ROLE_template" name="authorityList[]" value="ROLE_template" <?php /*if($isAddAction) {*/?> checked<?php /*} */?>/> 模板管理 </label></p>
                        <p><label class="checkbox inline"> <input type="checkbox" id="ROLE_setting" name="authorityList[]" value="ROLE_setting" <?php /*if($isAddAction) {*/?> checked<?php /*} */?>/> 网站参数设置 </label></p>-->
                        <p><label class="checkbox inline"> <input type="checkbox" id="ROLE_activity" name="authorityList[]" value="ROLE_activity" <?php if($isAddAction || ($userId == 1)) {?> checked<?php } ?>/> 活动管理 </label></p>
                        <p><label class="checkbox inline"> <input type="checkbox" id="ROLE_indexRegister" name="authorityList[]" value="ROLE_indexRegister" <?php if($isAddAction || ($userId == 1)) {?> checked<?php } ?>/> 首页报名管理 </label></p>
                        <p><label class="checkbox inline"> <input type="checkbox" id="ROLE_partner" name="authorityList[]" value="ROLE_partner" <?php if($isAddAction || ($userId == 1)) {?> checked<?php } ?>/> 合作伙伴管理 </label></p>
                        <p><label class="checkbox inline"> <input type="checkbox" id="ROLE_activityRegister" name="authorityList[]" value="ROLE_activityRegister" <?php if($isAddAction || ($userId == 1)) {?> checked<?php } ?>/> 活动报名管理 </label></p>
                        <p><label class="checkbox inline"> <input type="checkbox" id="ROLE_showWin" name="authorityList[]" value="ROLE_showWin" <?php if($isAddAction || ($userId == 1)) {?> checked<?php } ?>/> 展会中奖管理 </label></p>
                        <p><label class="checkbox inline"> <input type="checkbox" id="ROLE_pcWin" name="authorityList[]" value="ROLE_pcWin" <?php if($isAddAction || ($userId == 1)) {?> checked<?php } ?>/> PC中奖管理 </label></p>
                        <p><label class="checkbox inline"> <input type="checkbox" id="ROLE_messageWin" name="authorityList[]" value="ROLE_messageWin" <?php if($isAddAction || ($userId == 1)) {?> checked<?php } ?>/> 抽奖短信管理 </label></p>
                        <p><label class="checkbox inline"> <input type="checkbox" id="ROLE_role" name="authorityList[]" value="ROLE_role" <?php if($isAddAction || ($userId == 1)) {?> checked<?php } ?>/> 角色管理 </label></p>
                        <p><label class="checkbox inline"> <input type="checkbox" id="ROLE_admin" name="authorityList[]" value="ROLE_admin" <?php if($isAddAction || ($userId == 1)) {?> checked<?php } ?>/> 管理员管理 </label></p>
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label" for="textarea">描述</label>
                    <div class="controls">
          <textarea id="textarea" name="description" rows="6" ><?= isset($role['description']) ? $role['description'] : ''?>
</textarea>
                    </div>
                </div>
                <div class="form-actions">
                    <button type="submit" class="btn btn-primary"><i class="icon-upload"></i> 提交</button>
                    <button type="reset" class="btn" onclick="javascript:history.go(-1);"><i class="icon-repeat"></i> 返回</button>
                </div>
            </fieldset>
        </form>
    </div>
</div>
</body>
<script type="text/javascript">
    $().ready(function() {
        $("#validateForm").validate({
            rules: {
                name: "required",
                authorityList: "required"
            }
        })
    });
</script>
<?php if (!empty($role)) { ?>
    <script type="text/javascript">
        $().ready(function(){
            <?php $authorityList = isset($role['authority_list_store']) ? $role['authority_list_store'] : []; foreach ($authorityList as $authority) { ?>
            $("#<?= $authority ?>").attr("checked", true);
            <?php } ?>
        });
    </script>
<?php } ?>
</html>
