<?php
	include_once("check_login.php");
	include_once("include/config.php");
	$action = trim($_GET["action"]);
	if($action == "save"){
		check_site_url();
		array_pop($_POST);//表单提交上来的数据都存入$_POST数组中，现在弹出最后一个数组值，因为最后一个是按纽
		extract($_POST);//把数组名作为变量名，数组值作为变量值

		$news_title = trim($news_title);
		(strlen($news_title) < 1 || check_bad_str($news_title)) ? show_err("请输入文章标题，或文章标题中有非法字符") : $news_title = addslashes($news_title);
		$news_type = is_numeric($news_type) ? ($news_type > 2 ? 1 : $news_type) : 1;
		$news_top = check_is_numb($news_top) && $news_top >0 ? $news_top : 9999;
		
		strlen($news_content) < 9 ? show_err("请输入至少10个英文字符或5个中文字的文章内容") : $news_content = addslashes($news_content);
		mysql_query("insert into hmcss_news (news_type,news_title,news_content,news_top,news_time) values ('$news_type','$news_title','$news_content',$news_top,'" . date("Y-m-d H:i:s",time()) . "')")
			or show_err("添加文章出错，请联系管理员");
		show_err("文章已成功添加","set_news_list.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" />
<title>添加文章</title>
<script language = "javascript" src="include/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript" src="ckeditor/ckeditor.js"></script>
<script type="text/javascript" src="ckfinder/ckfinder.js"></script>
<style type="text/css">
input,select{margin:4px auto;}
</style>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>

<body>
<div class="head_menu"><a href="set_news_list.php">文章列表</a><span class="head_menu_on"><a href="set_news_new.php">添加文章</a></span></div>
<div class="set_main_out">
  <form id="form1" name="form1" method="post" action="set_news_new.php?action=save">
    <div class="set_main">
      <ul>
        <li style="width:100px; color:#C03;">文章标题:</li>
        <li style="width:678px;"><input name="news_title" type="text" id="news_title" size="100" maxlength="200" /></li>
        <li style="width:100px; color:#C03;">文章类型:</li>
        <li style="width:678px;">
          <?php echo get_news_type(); ?>
        &nbsp;&nbsp;<span style="color:#999; font-size:12px;">请选择文章的类型(公告会在顶部滚动显示)</span></li>
        <li style="width:100px; color:#C03;">置顶顺序:</li>
        <li style="width:678px;"><input name="news_top" type="text" id="news_top" size="10" maxlength="2" value="0" />&nbsp;&nbsp;<span style="color:#999; font-size:12px;">0表示不置顶</span></li>
        <li style="width:100px; height:440px; color:#C03;">文章内容:</li>
        <li style="width:678px; height:440px;"><textarea cols="80" id="news_content" name="news_content" rows="10" style="margin:0px auto;"></textarea>
            <script type="text/javascript">
            if (typeof CKEDITOR == 'undefined') {
            	document.write('加载CKEditor失败');
            	}
            	else {
            	var editor = CKEDITOR.replace('news_content');
            	CKFinder.SetupCKEditor(editor, 'ckfinder'); //ckfinder总目录的相对路径.
            	}
                CKEDITOR.config.height = 350;
				CKEDITOR.config.width = 670;
            </script></li>
        <li style="width:789px; text-indent:0px; text-align:center;">
          <input type="submit" name="button" id="button" value="  提 交  " />
        </li>
      </ul>
    </div>
  </form>
</div>
</body>
</html>