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

if (!empty($_POST)){
    if (check_permission($_SESSION["a_uid"],'categorylist.php',2)){
		$category_name     = flc_request($_POST["category_name"]);
		$category_url      = flc_request($_POST["category_url"]);
		$category_desc     = flc_request($_POST["category_desc"]);
		$category_parentid = intval($_POST["category_parentid"]);
		$category_order    = intval($_POST["category_order"]);
		$category_status   = intval($_POST["category_status"]);

		$sql = "update {$tablepre}category set category_name='".$category_name."',category_parentid=".$category_parentid.",category_order=".$category_order;
		$sql .= ",category_url='".$category_url."',category_desc='".$category_desc."',category_status='".$category_status."' where category_id='".$category_id."'";
		$db->exec($sql);

		$response_arr = array("status" => 1,"message"  => '操作成功');
	}else{
        $response_arr = array("status" => -1,"message"  => '对不起,您无权限操作!');
	}
    echo json_encode($response_arr);
    exit;
}

$sql = "select * from {$tablepre}category order by category_order asc, category_id Desc";
$ListArray = $db->get_all($sql);

if(!empty($ListArray) && is_array($ListArray)){
   foreach($ListArray as $k => $row){
	  $createtime = dateFormat($row['category_createtime'],'Y-m-d H:i:s');
	  $class_arr[] = array($row['category_id'],$row['category_name'],$row['category_parentid'],$row['category_order'],$row['category_status'],$row['category_url'],$createtime);
   }
}

$id = intval($_GET["id"]);
$sql = "select * from {$tablepre}category where category_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>
<link rel="icon" href="favicon.ico" type="image/ico">
<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>修改分类</h4>
			     <ul class="card-actions">
                    <li> <span><a href="categorylist.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="category_name">分类名称</label>
                    <div class="col-xs-12">
                      <input class="form-control" type="text" id="category_name" name="category_name" value="<?php echo $row['category_name'];?>">
                    </div>
                  </div>

				  <div class="form-group">
                    <label class="col-xs-12" for="category_url">链接地址</label>
                    <div class="col-xs-12">
                      <input class="form-control" type="text" id="category_url" name="category_url" value="<?php echo $row['category_url'];?>">
                    </div>
                  </div>

                  <div class="form-group">
                    <label class="col-xs-12" for="category_parentid">父级栏目</label>
					<div class="col-xs-12">
                      <select class="form-control" id="category_parentid" name="category_parentid" style="height:40px;">
					    <option value="0">一级菜单</option>
                        <?php
            	           dafenglei_select(0,0,$row['category_parentid']);
			            ?>
                      </select>
                    </div>
                  </div>

                  <div class="form-group">
                    <label class="col-xs-12" for="category_order">排序(值越小排越前)</label>
                    <div class="col-xs-12">
                      <input class="form-control" type="text" id="category_order" name="category_order" value="<?php echo $row['category_order'];?>">
                    </div>
                  </div>

                  <div class="form-group">
                    <label class="col-xs-12" for="category_status">显示状态</label>
					<div class="col-xs-12">
					    <label class="radio-inline" for="category_status">
                        <input type="radio" id="category_status" name="category_status" value="1" <?php if ($row['category_status']==1){?>checked<?php }?>>显示
                        </label>
						<label class="radio-inline" for="category_status">
                        <input type="radio" id="category_status" name="category_status" value="0" <?php if ($row['category_status']==0){?>checked<?php }?>>隐藏
                        </label>
					</div>
                  </div>
				  
				  <div class="form-group">
                    <label class="col-xs-12" for="category_icon">分类标签(多个标签用逗号隔开)</label>
                    <div class="col-xs-12">
					  <textarea class="form-control" id="category_desc" name="category_desc" rows="5"><?php echo $row['category_desc'];?></textarea>
                    </div>
                  </div><br>
                  
                  <div class="form-group">
                    <div class="col-xs-12">
                      <input type="hidden" name="category_id" id="category_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 category_name = $("#category_name").val();
	var category_desc = $("#category_desc").val();

	if (category_name==''){
		tips.notify('分类名称不能为空', 'warning', 200);
		return false;
	}else if (category_desc==''){
		tips.notify('分类标签不能为空', 'warning', 200);
		return false;
	}

    $.post("edit_category.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='categorylist.php';
		}else{
		   tips.notify(rs.message, 'danger', 200);
		}
    });
	
});
</script>
</body>
</html>