<?php
	require_once('_approot.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

	$_SESSION['savepnews']=$_POST;
	$_SESSION['savegnews']=$_GET;
	$ls=$_POST['ls'];
	$id=$_POST['id'];
	$newsTitle=$_POST['newsTitle2']; //新闻标题行
	$newsText=editorprocess($_POST['newsText'],$_SERVER['PHP_SELF'],$newsTitle,$newsTitle); 

	$cate=$_POST['cate'];
	$Num=$_POST['Num'];
	$newsDate=$_POST['newsDate'];
	$title = $_POST['newsTitle'];
	$keywords = $_POST['newsKeywords'];
//	$description = substr(strip_tags(trim(preg_replace("/([\s]{2,})/"," ",$newsText))), 0, 200);
	$description = substr(strip_tags(trim(preg_replace("/([\s]{2,})/"," ", $_POST['newsDescription']))), 0, 200);
	$keywords = str_replace("，",",",$keywords);
	 
	 
	switch($ls){
		case "insert":
			$insert_sql=sprintf("insert into ls_news(title,keywords,description,newsTitle,newsText,newsDate,enable,cate,Num) values (%s,%s,%s,%s,%s,%s,%s,%s,%s)",
						GetSQLValueString($title,"text"),
						GetSQLValueString($keywords,"text"),
						GetSQLValueString($description,"text"),
						GetSQLValueString($newsTitle,"text"),
						GetSQLValueString($newsText,"text"),
						GetSQLValueString($newsDate,"date"),
						GetSQLValueString("1", "int"),
						GetSQLValueString($cate,"text"),
						GetSQLValueString($Num,"int")
						);
			$insert_query=$opendb->query($insert_sql);
			writelog($_SERVER['PHP_SELF'],"add news: ".$newsTitle,"cate: ".$cate);
			unset($_SESSION['savepnews']);
			unset($_SESSION['savegnews']);
				 
		echo "<script>alert('数据添加成功！');location='news.php?selectcate=".$selectcate."';</script>";
			
			break;
			
		case "update":
	$update_sql=sprintf("update ls_news set title=%s, keywords=%s, description=%s, newsTitle=%s,newsText=%s,newsDate=%s,enable=%s,cate=%s,Num=%s where id=%s",
						GetSQLValueString($title, "text"),
						GetSQLValueString($keywords, "text"),
						GetSQLValueString($description, "text"),
						GetSQLValueString($newsTitle,"text"),
						GetSQLValueString($newsText,"text"),
						GetSQLValueString($newsDate,"date"),
						GetSQLValueString("1", "int"),
						GetSQLValueString($cate,"text"),
						GetSQLValueString($Num, "int"),
						GetSQLValueString($id,"int")
						);
									//echo $update_sql;
			$update_query=$opendb->query($update_sql);
			writelog($_SERVER['PHP_SELF'],"changed news: ".$newsTitle,"cate: ".$cate);
			unset($_SESSION['savepnews']);
			unset($_SESSION['savegnews']);

			echo "<script>location='news.php?selectcate=".$selectcate."&ls_msg=No.".$id."文章已更新';</script>";
	}
?>
</body>
</html>