<?php
require '../conn/conn.php';
require '../conn/function.php';
require 'admin_check.php';

$action=$_GET["action"];
$S_id=intval($_GET["S_id"]);

if($S_id!=""){
	$aa="edit&S_id=".$S_id;
	$sql="select * from sl_usort where S_id=".$S_id;

	$result = mysqli_query($conn, $sql);
	$row = mysqli_fetch_assoc($result);
	if (mysqli_num_rows($result) > 0) {
		$S_pic=$row["S_pic"];
		$S_order=$row["S_order"];
		$S_sub=$row["S_sub"];
		$S_show=$row["S_show"];
		$S_title=$row["S_title"];
		$S_content=$row["S_content"];
		$S_keywords=$row["S_keywords"];

	}
}else{
	$aa="add";
	$S_pic="nopic.png";
	$S_show=1;
	$S_order=0;
}

if($action=="add"){
$S_pic=$_POST["S_pic"];
$S_order=intval($_POST["S_order"]);
$S_sub=intval($_POST["S_sub"]);
$S_show=intval($_POST["S_show"]);
$S_title=$_POST["S_title"];
$S_content=$_POST["S_content"];
$S_keywords=$_POST["S_keywords"];

if($S_title!=""){
	mysqli_query($conn,"insert into sl_usort(S_pic,S_title,S_content,S_order,S_sub,S_show,S_keywords) values('$S_pic','$S_title','$S_content',$S_order,$S_sub,$S_show,'$S_keywords')");
	mysqli_query($conn,"insert into sl_log(L_aid,L_time,L_add,L_ip,L_title) values(".$_SESSION["A_id"].",'".date('Y-m-d H:i:s')."','".$_SESSION["add"]."','".getip()."','新增新闻分类')");
	die("success");
}else{
	die("error");
}
}

if($action=="edit"){
$S_pic=$_POST["S_pic"];
$S_order=intval($_POST["S_order"]);
$S_show=intval($_POST["S_show"]);
$S_sub=intval($_POST["S_sub"]);
$S_title=$_POST["S_title"];
$S_content=$_POST["S_content"];
$S_keywords=$_POST["S_keywords"];
if($S_title!=""){
	mysqli_query($conn, "update sl_usort set
	S_pic='$S_pic',
	S_order=$S_order,
	S_sub=$S_sub,
	S_show=$S_show,
	S_title='$S_title',
	S_keywords='$S_keywords',
	S_content='$S_content'
	where S_id=".$S_id);
	mysqli_query($conn,"insert into sl_log(L_aid,L_time,L_add,L_ip,L_title) values(".$_SESSION["A_id"].",'".date('Y-m-d H:i:s')."','".$_SESSION["add"]."','".getip()."','编辑新闻分类')");
	die("success");
}else{
	die("error");
}
}


?>
<!DOCTYPE html>
<html lang="en">
	<head>

		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<title>课程分类设置 - 后台管理</title>

		<!--favicon -->
		<link rel="icon" href="../media/<?php echo $C_ico?>" type="image/x-icon"/>

		<!--Bootstrap.min css-->
		<link rel="stylesheet" href="assets/plugins/bootstrap/css/bootstrap.min.css">

		<!--Icons css-->
		<link rel="stylesheet" href="assets/css/icons.css">

		<!--Style css-->
		<link rel="stylesheet" href="assets/css/style.css">

		<!--mCustomScrollbar css-->
		<link rel="stylesheet" href="assets/plugins/scroll-bar/jquery.mCustomScrollbar.css">

		<!--Sidemenu css-->
		<link rel="stylesheet" href="assets/plugins/toggle-menu/sidemenu.css">


		<!--Toastr css-->
		<link rel="stylesheet" href="assets/plugins/toastr/build/toastr.css">


		<script type="text/javascript" src="../upload/upload.js"></script>
		<style type="text/css">
		.showpic{height: 100px;border: solid 1px #DDDDDD;padding: 5px;}
		.list-group a{text-decoration:none}
	</style>
	</head>

	<body class="app ">

		<div id="spinner"></div>

		<div id="app">
			<div class="main-wrapper" >
				
					<?php
					require 'nav.php';
					?>

				<div class="app-content">
					<section class="section">
                    	<ol class="breadcrumb">
                            <li class="breadcrumb-item"><a href="course_list.php">课程管理</a></li>
                            <li class="breadcrumb-item active"><a href="usort_add.php">课程分类</a></li>

                        </ol>
                        <style type="text/css">
                        .active a{font-weight: bold;color: #a2a9d4}
                    	</style>

						<div class="section-body ">
							
							<div class="row">
								
								<div class="col-lg-3">

									<div class="card card-primary">

										<div class="card-header">
											<h4>课程分类列表</h4>

										</div>
										
											
											<ul class="list-group">
												<li class="list-group-item">分类标题
														<span class="pull-right">首页展示/图片</span>
													</li>
											
											<?php 
													$sql="select * from sl_usort where S_del=0 and S_sub=0 order by S_order,S_id desc";
														$result = mysqli_query($conn, $sql);
														if (mysqli_num_rows($result) > 0) {
														while($row = mysqli_fetch_assoc($result)) {
															if($row["S_id"]==$S_id){
																$active="active";
															}else{
																$active="";
															}
															if($row["S_show"]==1){
																$show="<i class='fa fa-check-circle pull-right' style='margin-right:10px'></i>";
															}else{
																$show="";
															}
															
															echo "<a href=\"?S_id=".$row["S_id"]."\" id=\"s".$row["S_id"]."\" class=\"list-group-item ".$active."\"><b>└ ".$row["S_order"].".".$row["S_title"]."</b><img src=\"".pic2($row["S_pic"])."\" alt=\"<img src='".pic2($row["S_pic"])."' width='300'>\" style=\"height:25px;width:25px;border-radius:10px;\" class=\"pull-right\">".$show."</a>";


															$sql2="select * from sl_usort where S_del=0 and S_sub=".$row["S_id"]." order by S_order,S_id desc";
																$result2 = mysqli_query($conn, $sql2);
																if (mysqli_num_rows($result2) > 0) {
																while($row2 = mysqli_fetch_assoc($result2)) {
																	if($row2["S_id"]==$S_id){
																		$active2="active";
																	}else{
																		$active2="";
																	}

																	if($row2["S_show"]==1){
																		$show="<i class='fa fa-check-circle pull-right' style='margin-right:10px'></i>";
																	}else{
																		$show="";
																	}
																	
																	echo "<a href=\"?S_id=".$row2["S_id"]."\" id=\"s".$row2["S_id"]."\" class=\"list-group-item ".$active2."\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;└ ".$row2["S_order"].".".$row2["S_title"]."<img src=\"".pic2($row2["S_pic"])."\" alt=\"<img src='".pic2($row2["S_pic"])."' width='300'>\" style=\"height:25px;width:25px;border-radius:10px;\" class=\"pull-right\">".$show."</a>";
																}
															}
														}
													}
											?>
											
										</ul>
											
										
									</div>
									<a href="usort_add.php" class="btn btn-sm btn-primary"><i class="fa fa-plus-circle"></i> 新增课程分类</a>
								</div>

								<div class="col-lg-9">
									<div class="card card-primary">
										<div class="card-header ">
											<h4>课程分类管理</h4>
										</div>
										<div class="card-body">
											<form id="form">
												<div class="form-group row">
													<label class="col-md-3 col-form-label" >分类标题</label>
													<div class="col-md-9">
														<input type="text"  name="S_title" class="form-control" value="<?php echo $S_title?>">
													</div>
												</div>

												<div class="form-group row">
													<label class="col-md-3 col-form-label" >上级分类</label>
													<div class="col-md-9">
														<select name="S_sub" class="form-control">
															<option value="0">根分类</option>
															<?php
															$sql="select * from sl_usort where S_del=0 and S_sub=0 and not S_id=$S_id order by S_order,S_id desc";
																$result = mysqli_query($conn, $sql);
																if (mysqli_num_rows($result) > 0) {
																while($row = mysqli_fetch_assoc($result)) {
																	if($S_sub==$row["S_id"]){
																		$selected="selected";
																	}else{
																		$selected="";
																	}
																	echo "<option value=\"".$row["S_id"]."\" ".$selected.">".$row["S_title"]."</option>";
																}
															}

															?>
														</select>
														
													</div>
												</div>

												<div class="form-group row">
													<label class="col-md-3 col-form-label" >分类排序</label>
													<div class="col-md-9" style="position: relative;">
														<input type="text"  name="S_order" class="form-control" value="<?php echo $S_order?>">
														<label style="position: absolute;right: 25px;top: 10px;"><input type="checkbox" name="S_show" value="1" <?php if($S_show==1){echo "checked='checked'";}?> >首页展示</label>
													</div>
												</div>
												
												<div class="form-group row">
													<label class="col-md-3 col-form-label" >分类图片</label>
													<div class="col-md-9">
														<p><img src="<?php echo pic2($S_pic)?>" id="S_picx" class="showpic" onClick="showUpload('S_pic','S_pic','../media',1,null,'','');"></p>
														<div class="input-group">
															
						                                        <input type="text" id="S_pic" name="S_pic" class="form-control" value="<?php echo $S_pic?>">
						                                        <span class="input-group-btn">
						                                                <button class="btn btn-primary m-b-5 m-t-5" type="button" onClick="showUpload('S_pic','S_pic','../media',1,null,'','');">上传</button>
						                                        </span>
						                                </div>
														
													</div>
												</div>
												<hr>

												<div class="form-group row">
													<label class="col-md-3 col-form-label" >SEO关键词</label>
													<div class="col-md-9">
														<input type="text"  name="S_keywords" class="form-control" value="<?php echo $S_keywords?>" placeholder="多个词用,隔开">
													</div>
												</div>

												<div class="form-group row">
													<label class="col-md-3 col-form-label" >SEO描述</label>
													<div class="col-md-9">
														<textarea name="S_content" class="form-control"><?php echo $S_content?></textarea>
													</div>
												</div>

												<button class="btn btn-info" type="button" onClick="usort_add_save(1)">保存</button>
												<button class="btn btn-primary" type="button" onClick="usort_add_save(2)">保存并返回</button>
											</form>
										</div>
									</div>
								</div>

								

							
							</div>
							
						</div>
					</section>
				</div>

			</div>
		</div>

		<script src="assets/js/jquery.min.js"></script>
		<script src="assets/plugins/bootstrap/js/bootstrap.min.js"></script>
		<script src="assets/plugins/toggle-menu/sidemenu.js"></script>
		<script src="assets/plugins/scroll-bar/jquery.mCustomScrollbar.concat.min.js"></script>
		<script src="assets/js/scripts.js"></script>
		<script src="assets/js/help.js"></script>
		<script src="assets/plugins/toastr/build/toastr.min.js"></script>
		<script src="ajax.js"></script>

		<script type="text/javascript">
		var $aa="<?php echo $aa?>";

		</script>
		
	</body>
</html>
