<div class="row-fluid">
    <div class="span3">
        <div class="well" >
            <ul id="treeDemo" name="treeDemo" class="ztree span12" style="height:938px;overflow-y:scroll;overflow-x:auto;">
            </ul>
            <legend></legend>
            <h4>未添加的用户列表</h4>
            <ul>
                <?php foreach ($undefined_ht_user as $hu) { ?>
                    <li><a href="<?php echo site_url('accessmanage/adduser').'/'.$userstructure[0]->id.'/'.$hu->OPI_Code.'/0'; ?>" ><?php echo $hu->OPI_Name.'('.$hu->OPI_Code.')'; ?></a></li>
                <?php } ?>
                <?php foreach ($undefined_a_user as $au) { ?>
                    <li><a href="<?php echo site_url('accessmanage/adduser').'/'.$userstructure[0]->id.'/'.$au->a_id.'/0'; ?>" ><?php echo $au->a_name; ?></a></li>
                <?php } ?>
            </ul>

        </div>
    </div>

    <div class="span7">
        <legend><?php echo $user_access->iao_author; ?>---权限编辑</legend>

        <form id="form_accessmanage_edit" name="form_accessmanage_edit" method="post" action="<?php echo site_url('accessmanage/editaccess'); ?>">
          <fieldset>
            <div class="<?php if($role_level!=1) echo 'hide'; ?>">
                <label>用户标识</label>
                <input name="iam_author" class="span2" type="text" value="<?php if(isset($user_access->iao_author)) echo $user_access->iao_author; ?>">
            </div>
            <label>编辑的站点</label>
            <select name="iao_site" class="form-control" onchange="javascript:location.href=('<?php echo site_url("accessmanage/index")."/".$user_access->iam_is_id."/"; ?>'+this.value)">
              <?php foreach ($this->config->item('site') as $site) { ?>
                <?php if(in_array($site['site_code'], $user_site)){ ?>
                <option value="<?php echo $site['site_code']; ?>" class="selectsite" <?php if($site['site_code']==$editsite) echo 'selected'; ?>><?php echo $site['site_code']; ?></option>
                <?php } ?>
              <?php } ?>
            </select>
            <label>可读节点列表<em class="small">(不同节点之间请用英文的逗号‘,’隔开，eg：242007009,200000176)</em></label>
            <input name="iao_read" class="span12" type="text" value="<?php if(isset($user_access->iao_read)) echo $user_access->iao_read; ?>">
            <label>可写节点列表<em class="small">(不同节点之间请用英文的逗号‘,’隔开，eg：242007009,200000176)</em></label>
            <input name="iao_write" class="span12" type="text" value="<?php if(isset($user_access->iao_write)) echo $user_access->iao_write; ?>">
            <br><br>
            <label>分配角色</label>
            <div class="row-fluid">
                <?php foreach ($role_list as $role) { ?>
                <label class="checkbox span2 <?php if($role_level!=1 && $role->is_level<=$role_level) echo 'hide'; ?>" style="margin-left:0;margin-right:10px;">
                  <input name="role_list[]" type="checkbox" value="<?php echo $role->iar_id; ?>" <?php if(in_array($role->iar_id, $current_role)) echo 'checked'; ?>> <?php echo $role->name; ?>
                </label>
                <?php } ?>
            </div><br><br>

            <div class="row-fluid <?php if($role_level!=1 && $user_level<=$role_level) echo 'hide'; ?>">
                <legend><label>分配站点</label></legend>
                <?php foreach ($admin_access_site as $site) { ?>
                <?php if(trim($site)!='' && in_array($site, $user_site)){ ?>
                  <a href='<?php echo site_url("accessmanage/deletesite/$user_access->iao_author/$site"); ?>' class="label label-success" style="padding:7px 15px; margin-bottom:10px; font-size:14px;"><?php echo $site; ?> -</a>
                <?php }elseif (trim($site)!='') { ?>
                    <a href='<?php echo site_url("accessmanage/addsite/$user_access->iao_author/$site"); ?>' class="label" style="padding:7px 15px; margin-bottom:10px; font-size:14px;"><?php echo $site; ?> +</a>
                <?php } ?>
                <?php } ?>
            </div>
            
            <div class="row-fluid clearfix" style="margin-top:15px;">
                <legend><label>设置作者</label></legend>
                <label class="checkbox span2 <?php if($role_level!=1 && $role->is_level<=$role_level) echo 'hide'; ?>" style="margin-left:0;margin-right:10px;">
                  <input name="iseditor" id="iseditor" type="checkbox" <?php if($user_access->iao_other=='editor') echo 'checked'; ?> value="editor" data-url='<?php echo site_url("accessmanage/addeditor/$user_access->iao_author/$editsite"); ?>'> 作者
                </label>
            </div>
            <label> <br><br></label>
            <input type="hidden" name="iam_id" value="<?php echo $user_access->iam_id; ?>">
            <input type="hidden" name="iao_author" value="<?php echo $user_access->iao_author; ?>">
            <input type="hidden" name="iao_id" value="<?php echo $user_access->iao_id; ?>">
            <div class="btn-group <?php if($role_level!=1 && $user_access->iao_author!='' && $user_level<=$role_level) echo 'hide'; ?>">
              <button type="button" class="btn" onclick="submitForm('form_accessmanage_edit');">保　存</button>
              <button class="btn dropdown-toggle" data-toggle="dropdown">
                <span class="caret"></span>
              </button>
              <ul class="dropdown-menu">
                <li><a href="javascript:void(0);" onClick="deleteInfo('form_accessmanage_edit')">删除用户</a></li>
              </ul>
            </div>
          </fieldset>
        </form>
    </div>
    <div class="span2 well" style="min-height:1000px;">
        <?php echo $right_nav; ?>
    </div>
</div>

<script type="text/javascript">
    zNodes =<?PHP echo json_encode($userstructure); ?>;
    var current_node = "<?php echo $user_access->iam_is_id; ?>"
    var indexpage= "<?php echo site_url('accessmanage/index'); ?>"
    var addpage  = "<?php echo site_url('accessmanage/adduser'); ?>"
    var movepage = "<?php echo site_url('accessmanage/tree_move'); ?>"
    var deletepage="<?php echo site_url('accessmanage/delete_user'); ?>"
    var form_id = "form_accessmanage_edit";
</script>
<script type="text/javascript" src="/js/init_ztree.js"></script>

<script type="text/javascript">
$("#iseditor").click(function(){
    var url=$(this).attr('data-url');
    var iao_other='';
    if ($(this).attr('checked')) {
        iao_other='editor';
    }
    $.get(url,{"iao_other":iao_other},function(result){
        if (result==1) {
            alert('设置成功！');
        }else{
            alert('设置失败，请联系管理员');
        }
    })
});
</script>