<?php
include_once("htui_header.php");

if (!empty($_POST)){
    if (check_permission($_SESSION["a_uid"],'rolelist.php',2)){
		$role_id    = intval($_POST["role_id"]);
		$role_code  = flc_request($_POST["role_code"]);
		$role_name  = flc_request($_POST["role_name"]);
		$role_desc  = flc_request($_POST["role_desc"]);
		$is_system  = intval($_POST["is_system"]);
		$buildin    = intval($_POST["buildin"]);

		$sql = "update {$tablepre}role set role_code='".$role_code."',role_name='".$role_name."',role_desc='".$role_desc."'";
		$sql .= ",is_system='".$is_system."',buildin='".$buildin."' where role_id='".$role_id."'";
		$db->exec($sql);
		$response_arr = array("status" => 1,"message"  => '操作成功');
	}else{
        $response_arr = array("status" => -1,"message"  => '对不起,您无权限操作!');
	}

    echo json_encode($response_arr);
    exit;
}

$id = intval($_GET["id"]);
$role_name =flc_request(trim($_GET["role_name"]));
$sql = "select * from {$tablepre}role where role_id='".$id."'";
$row = $db->get_row($sql);
?>
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
<title>后台管理中心_飞天素材网</title>
<meta name="author" content="ftsucai.com">
<link href="../css/bootstrap.min.css" rel="stylesheet">
<link href="../css/fonts.css" rel="stylesheet">
<link href="../css/htstyle.css" rel="stylesheet">
<link href="../js/bootstrap-datepicker/bootstrap-datepicker3.min.css" rel="stylesheet">
<link href="../js/bootstrap-colorpicker/css/bootstrap-colorpicker.min.css" rel="stylesheet">
</head>
  
<body>

    <!--页面主要内容-->
    <main class="ftdms-layout-content">
      
      <div class="container-fluid" style="margin-bottom:90px;">
        
        <div class="row" style="margin-top:15px;">
          <div class="col-lg-12">
            <div class="card">
              <div class="card-header"><h4>修改<?php echo $role_name;?>角色</h4>
			     <ul class="card-actions">
                    <li> <span><a href="rolelist.php">返回列表</a></span> </li>
                 </ul>
			  </div>
              <div class="card-body" style="padding:5px 20px;">
                
                <form class="form-horizontal" action="" method="post" id="form">

				  <div class="form-group">
                    <label class="col-xs-12" for="role_code">角色代码</label>
                    <div class="col-xs-12">
                      <input class="form-control" type="text" id="role_code" name="role_code" value="<?php echo $row['role_code'];?>">
                    </div>
                  </div>

				  <div class="form-group">
                    <label class="col-xs-12" for="role_name">角色名称</label>
                    <div class="col-xs-12">
                      <input class="form-control" type="text" id="role_name" name="role_name" value="<?php echo $row['role_name'];?>">
                    </div>
                  </div>

				  <div class="form-group">
                    <label class="col-xs-12" for="role_desc">角色描述</label>
                    <div class="col-xs-12">
                      <input class="form-control" type="text" id="role_desc" name="role_desc" value="<?php echo $row['role_desc'];?>">
                    </div>
                  </div>

				  <div class="form-group">
                    <label class="col-xs-12" for="is_system">系统默认</label>
					<div class="col-xs-12">
						<label class="radio-inline">
						<input type="radio" name="is_system" value="1" <?php if ($row['is_system']==1){?>checked<?php }?>><span> 是</span>
						</label>
						<label class="radio-inline">
						<input type="radio" name="is_system" value="0" <?php if ($row['is_system']==0){?>checked<?php }?>><span> 否</span>
						</label>
					</div>
                  </div>

                  <div class="form-group">
                    <label class="col-xs-12" for="buildin">内置角色</label>
					<div class="col-xs-12">
					    <label class="radio-inline">
                        <input type="radio" id="buildin" name="buildin" value="1" <?php if ($row['buildin']==1){?>checked<?php }?>>是
                        </label>
						<label class="radio-inline">
                        <input type="radio" id="buildin" name="buildin" value="0" <?php if ($row['buildin']==0){?>checked<?php }?>>否
                        </label>
					</div>
                  </div><br>
                  
                  <div class="form-group">
                    <div class="col-xs-12">
					  <input type="hidden" name="role_id" id="role_id" value="<?php echo $id;?>">
					  <button class="btn btn-primary" type="button" id="submit">确认提交</button>
					  <button type="button" class="btn btn-default" onclick="javascript:history.back(-1);return false;">返回</button>
                    </div>
                  </div>
                </form>
				<br>
                
              </div>
            </div>
          </div>
          
        </div>
        
      </div>
      
    </main>
    <!--End 页面主要内容-->
<script src="../js/jquery.min.js"></script>
<script src="../js/bootstrap.js"></script>
<script src="../js/perfect-scrollbar.min.js"></script>
<script src="../js/main.min.js"></script>
<script src="../js/bootstrap-notify.min.js"></script>
<script src="../js/tips.js"></script>
<script>
$("#submit").click(function(){
    var role_code = $("#role_code").val();
	var role_name = $("#role_name").val();
	var role_desc = $("#role_desc").val();

	if (role_code==''){
		tips.notify('角色代码不能为空', 'warning', 200);
		return false;
	}
    
	if (role_name==''){
		tips.notify('角色名称不能为空', 'warning', 200);
		return false;
	}
	
	if (role_desc==''){
		tips.notify('角色描述不能为空', 'warning', 200);
		return false;
	}

    $.post("edit_role.php", $("#form").serialize(), function(data) {
		var rs  = eval('('+data+')');
        if(rs.status==1){
           tips.notify(rs.message, 'success', 200, 'ftsucai-name', 'top', 'center');
		   window.location.href='rolelist.php';
		}else{
		   tips.notify(rs.message, 'danger', 200);
		}
    });
	
});
</script>
</body>
</html>