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

if (!empty($_POST)){
    if (check_permission($_SESSION["a_uid"],'treemenu.php',1)){
		$category_name     = flc_request($_POST["category_name"]);
		$category_url      = flc_request($_POST["category_url"]);
		$category_shrink   = intval($_POST["category_shrink"]);
		$category_icon     = flc_request($_POST["category_icon"]);
		$category_parentid = intval($_POST["category_parentid"]);
		$category_order    = intval($_POST["category_order"]);
		$category_status   = intval($_POST["category_status"]);

		$sql = "INSERT INTO {$tablepre}treemenu (category_name,category_parentid,category_order,category_url,category_shrink,category_status,category_icon,category_createtime) VALUES('".$category_name."','".$category_parentid."','".$category_order."','".$category_url."','".$category_shrink."','".$category_status."','".$category_icon."','".$getnow."')";
		$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}treemenu 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);
   }
}
?>
<!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="treemenu.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">
                    </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">
                    </div>
                  </div>

				  <div class="form-group">
                    <label class="col-xs-12" for="category_shrink">收缩状态</label>
					<div class="col-xs-12">
						<label class="radio-inline">
						<input type="radio" name="category_shrink" value="1" checked><span> 默认展开</span>
						</label>
						<label class="radio-inline">
						<input type="radio" name="category_shrink" value="0"><span> 默认收缩</span>
						</label>
					</div>
                  </div>

                  <div class="form-group">
                    <label class="col-xs-12" for="category_icon">菜单图标</label>
                    <div class="col-xs-12">
                      <input class="form-control" type="text" id="category_icon" name="category_icon">
                    </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,0);
			            ?>
                      </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="0">
                    </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" checked>显示
                        </label>
						<label class="radio-inline" for="category_status">
                        <input type="radio" id="category_status" name="category_status" value="0">隐藏
                        </label>
					</div>
                  </div><br>
                  
                  <div class="form-group">
                    <div class="col-xs-12">
                      <!--<button class="btn btn-primary" type="submit" id="submit">提交</button>-->
					  <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_url = $("#category_url").val();

	if (category_name==''){
		tips.notify('菜单名称不能为空', 'warning', 200);
		return false;
	}else if (category_url==''){
		tips.notify('链接地址不能为空', 'warning', 200);
		return false;
	}

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