<?php
    session_start();
	require_once('inc/conn.php');
	require_once('inc/constant.php');
	require_once('inc/ls_syscode.php');
	require_once('inc/check.php');
	$opendb=new mydb();
	require_once('inc/char_set.php');
	$selectcate=$_GET['selectcate'];

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<link href="css/admin.css" rel="stylesheet" type="text/css">
		<title>无标题文档</title>
	</head>

	<body>
<?php
	$ls=$_POST['ls'];
	$id=$_POST['id'];
	$problemTitle=$_POST['problemTitle'];
	$problemText=$_POST['problemText'];
	$cate=$_POST['cate'];
	$cateID=$_POST['cateID'];
	$Num=$_POST['Num'];
	$problemDate=$_POST['problemDate'];
	
	$title = $_POST['newsTitle'];
	$keywords = $_POST['newsKeywords'];
	$description = $_POST['newsDescription'];
	
	switch($ls)
	{
		case "insert":
			$insert_sql=sprintf("insert into ls_problem(title,keywords,description,problemTitle,problemText,problemDate,enable,cate,Num) values (%s,%s,%s,%s,%s,%s,%s,%s,%s)",
						GetSQLValueString($title,"text"),
						GetSQLValueString($keywords,"text"),
						GetSQLValueString($description,"text"),
						GetSQLValueString($problemTitle,"text"),
						GetSQLValueString($problemText,"text"),
						GetSQLValueString(date("Y-m-d"),"date"),
						GetSQLValueString("1", "int"),
						GetSQLValueString($cateID,"text"),
						GetSQLValueString($Num,"int")
						);
			$insert_query=$opendb->query($insert_sql);
			writelog($_SERVER['PHP_SELF'],"add problem: ".$problemTitle,"cate: ".$cateID);
			echo "<script>alert('数据添加成功！');location='problem.php?selectcate=".$selectcate."';</script>";
			break;
			
		case "update":
	$update_sql=sprintf("update ls_problem set title=%s, keywords=%s, description=%s, problemTitle=%s, problemText=%s, problemDate=%s, enable=%s, cate=%s, Num=%s where id=%s",
						GetSQLValueString($title, "text"),
						GetSQLValueString($keywords, "text"),
						GetSQLValueString($description, "text"),
						GetSQLValueString($problemTitle,"text"),
						GetSQLValueString($problemText,"text"),
						GetSQLValueString($problemDate,"date"),
						GetSQLValueString("1", "int"),
						GetSQLValueString($cateID,"text"),
						GetSQLValueString($Num, "int"),
						GetSQLValueString($id,"int")
						);
			//echo $update_sql;
			$update_query=$opendb->query($update_sql);
			writelog($_SERVER['PHP_SELF'],"changed problem: ".$problemTitle,"cate: ".$cateID);

			echo "<script>alert('数据更新成功！');location='problem.php?selectcate=".$selectcate."';</script>";
	}
?>
</body>
</html>