<?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');
?>
<!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
	$selectcate=$_GET['selectcate'];
	$selectfunctionName=$_GET['selectfunctionName'];
	
	$title=$_POST['newsTitle'];
	$keywords=$_POST['newsKeywords'];
	$description=$_POST['newsDescription'];

	$ls=$_POST['ls'];
	$id=$_POST['id'];
	$articleTitle=$_POST['articleTitle'];
	$articleText=$_POST['articleText'];
	
	//编辑器中的内链与图片转换成相对路径
	$articleText = editorPath('http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'], $articleText);//内链
	$articleText = editorPath($_SERVER['PHP_SELF'], $articleText);//图片
	$articleText = addAltTitle($articleTitle, $articleTitle, $articleText); //图片添加alt,title
	
	$in_sql="SELECT * FROM ls_internal where enable=1 order by Num asc"; //count the error by searchtype
	$in_query=$opendb->query($in_sql);
	while ($in_rows=mysql_fetch_assoc($in_query)){
		$articleText = internal_keyword_link($articleText, $in_rows['title'], $in_rows['url']);
	}
	
	$articleBrief=$_POST['articleBrief'];
	$articleDate=$_POST['articleDate'];
	$cateName=$_POST['cateName'];;
	$functionName=$_POST['functionName'];;

	$Num=$_POST['Num'];

	
	switch($ls)
	{
		case "insert":
			$insert_sql=sprintf("insert into ls_article (title, keywords, description, articleTitle, articleText, articleDate, enable, articleBrief, cateName, functionName, Num) values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)",
						GetSQLValueString($title,"text"),
						GetSQLValueString($keywords,"text"),
						GetSQLValueString($description,"text"),
						GetSQLValueString($articleTitle,"text"),
						GetSQLValueString($articleText,"text"),
						GetSQLValueString(date("Y-m-d"),"date"),
						GetSQLValueString("1", "int"),
						GetSQLValueString($articleBrief,"text"),
						GetSQLValueString($cateName,"text"),
						GetSQLValueString($functionName,"text"),
						GetSQLValueString($Num,"int")
						);
			$insert_query=$opendb->query($insert_sql);
			echo "<script>location='managearticle.php?selectcate=".$selectcate."&selectfunctionName=".$selectfunctionName."';</script>";
			break;
			
		case "update":
	$update_sql=sprintf("update ls_article  set title=%s, keywords=%s, description=%s, functionName=%s, articleTitle=%s, articleText=%s, articleBrief=%s, articleDate=%s, enable=%s, cateName=%s, Num=%s where id=%s",
						GetSQLValueString($title,"text"),
						GetSQLValueString($keywords,"text"),
						GetSQLValueString($description,"text"),
						GetSQLValueString($functionName,"text"),
						GetSQLValueString($articleTitle,"text"),
						GetSQLValueString($articleText,"text"),
						GetSQLValueString($articleBrief,"text"),
						GetSQLValueString($articleDate,"date"),
						GetSQLValueString("1", "int"),
						GetSQLValueString($cateName,"text"),
						GetSQLValueString($Num, "int"),
						GetSQLValueString($id,"int")
						);
									//echo $update_sql;
			$update_query=$opendb->query($update_sql);
			echo "<script>location='managearticle.php?selectcate=".$selectcate."&selectfunctionName=".$selectfunctionName."&ls_msg=No.".$id."文章已更新';</script>";
	}
?>
</body>
</html>