<?php
session_start();
require_once "../init.php";
require_once "../authority.inc.php";
$ClassName = $_POST['ClassName'];
if($_SESSION['AdmUserID_S'] ){
$UserName=$_SESSION['AdmUserID_S'];

}
else
{

$UserName=$_SESSION['User_S'];
}

$Title = $_POST['Title'];
$showIndex = $_POST['showIndex'];


$Content=$_POST['Content'];
$Add = $_POST['Add'];

$hot="add";

$arProType = array();
$proType = new ProductType1();
$tree = $proType->ShowProTypeTree('0',0,$arProType);
//print_r($tree);


$uppath=isset($_REQUEST["upPath"])?$_REQUEST["upPath"]."/":"/uploadimg";              //文件上传路径
$formName=isset($_REQUEST["formName"])?$_REQUEST["formName"]:"form";          //回传到上页面编辑框所在Form的Name
$editName=isset($_REQUEST["editName"])?$_REQUEST["editName"]:"pic";              //回传到上页面编辑框的Name
//示例


?>

<!--_meta 作为公共模版分离出去-->
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<LINK rel="Bookmark" href="/favicon.ico" >
<LINK rel="Shortcut Icon" href="/favicon.ico" />
<!--[if lt IE 9]>
<script type="text/javascript" src="../lib/html5.js"></script>
<script type="text/javascript" src="../lib/respond.min.js"></script>
<script type="text/javascript" src="../lib/PIE_IE678.js"></script>
<![endif]-->
<link rel="stylesheet" type="text/css" href="../static/h-ui/css/H-ui.min.css" />
<link rel="stylesheet" type="text/css" href="../static/h-ui.admin/css/H-ui.admin.css" />
<link rel="stylesheet" type="text/css" href="../lib/Hui-iconfont/1.0.7/iconfont.css" />
<link rel="stylesheet" type="text/css" href="../lib/icheck/icheck.css" />
<link rel="stylesheet" type="text/css" href="../static/h-ui.admin/skin/default/skin.css" id="skin" />
<link rel="stylesheet" type="text/css" href="../static/h-ui.admin/css/style.css" />
<!--[if IE 6]>
<script type="text/javascript" src="../static/h-ui.admin/js/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<!--/meta 作为公共模版分离出去-->



<title>增加网站新闻</title>
<LINK href="../share/style.css" rel=stylesheet>
  <script type="text/javascript" charset="gbk" src="../ueditor/lang/zh-cn/zh-cn.js"></script>

  <script type="text/javascript" charset="gbk" src="../ueditor/ueditor.config.js"></script>
    <script type="text/javascript" charset="gbk" src="../ueditor/ueditor.all.min.js"> </script>
<script>

function check(form){
   if(form.Title.value==""){
       alert("请输入标题");
	   form.Title.focus();
	   return false;
   }
   form.Content.value = GetHtml();
   if(form.Content.value==""){
       alert("请输入内容");
	   return false;
   }
   form.submit();
}

</script>
<script src='../share/global.js'></script>

</head>
<body>

<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 资讯管理 <span class="c-gray en">&gt;</span> 发布资讯 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>



	<?

 if($Add==1){


//转换根目录的路径
if(strpos($uppath,"/")==0) {
      $i=0;
      $thpath=$_SERVER["SCRIPT_NAME"];
      $thpath=substr($thpath,1,strlen($thpath));
      while(strripos($thpath,"/")!==false){
          $thpath=substr($thpath,strpos($thpath,"/")+1,strlen($thpath));
          $i=++$i;        
      }

$pp="";
      for($j=0;$j<$i;++$j){
          $pp .="../";
      }

      $uppaths=$pp.substr($uppath,1,strlen($thpath));
}
$filename=date("y-m");
if(is_dir($uppaths.$filename)!=TRUE) mkdir($uppaths.$filename,0777);
// if(is_dir($filename."/".$ctime)!=TRUE) mkdir($filename."/".$ctime,0777);

$f = $_FILES['file1'];

$dest = $uppaths.$filename."/".date("ymd")."_".$f['name'];//设置文件名为日期加上文件名避免重复上传目录



if($f['name']){
$dest1 = $uppath.$filename."/".date("ymd")."_".$f['name'];//设置文件名为日期加上文件名避免重复
}
else
{
	  $delpath = "../..$OldLogo";
		  @unlink($delpath);
$dest1="";
}

$r = move_uploaded_file($f['tmp_name'],$dest);
if($f['size']>0){
$delpath = "../..$OldLogo";
		  @unlink($delpath);
      echo    "<script>window.opener.document.".$formName.".".$editName.".value='".$dest1."'</script>";
}


	
		  $sql="insert into news set Title='$Title',ClassName='$ClassName',pic='$dest1',UserName='$UserName',Content='".$Content."',dtCreate=now(), showIndex='$showIndex', nub='1'";
		  $DB->query($sql);
		  $NewsID = $DB->insert_id();
		  echo "<center>";
		  echo "<br><br><br>网站新闻发布成功</font>";
		  echo "<br><br><br><a href='news_list.php'>[ 返 回 ]</a>";

	 }else{?>
<article class="page-container">
<? include "news_nav.inc.php"?>
      <form action="news_add.php" method="post"  onSubmit="return check(this)" class="form form-horizontal" id="form-article-add" name="form1" enctype="multipart/form-data">
        <div class="row cl">
			<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>文章标题：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text"  placeholder="" name="Title">
			</div>
		</div>

<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>分类栏目：</label>
			<div class="formControls col-xs-8 col-sm-9"> <span class="select-box">
					     <?
	  $treestring .= "<select name='ClassName' class='select'>";
	  for($i=0;$i<count($tree);$i++){
	 
          $treestring .= "<option value='".$tree[$i]['IDProduct']."'>" .$tree[$i]['Disp'] . "</option>";
		
		 
	  }
      $treestring .= "</select>";
	  echo $treestring;
	 ?>
				</span> </div>
		</div>

   <div class="row cl">
			<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>封面图片：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="hidden" name="upPath" value="<?=$uppath?>">
          <input type="hidden" name="editName" value="<?=$editName?>">
          <input type="hidden" name="formName" value="<?=$formName?>">
			<input  type="file" name="file1"  class="inputline" > (如不修改请不要上传,只能上传图片文件或flash文件)
 		
			

			</div>
		</div>
<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>发布状态：</label>
			<div class="formControls col-xs-8 col-sm-9"> <span class="select-box">
				<select name="showIndex" class="select">
					<option value="1">显示</option>
			<option value="0">不显示</option>
				</select>
				</span> </div>
		</div>
  	 
	<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">文章内容：</label>
			<div class="formControls col-xs-8 col-sm-9"> 



			  <script id="editor" type="text/plain" style="width:100%;height:500px;"  name="Content"><?=$NewsInfo[Content]?></script>
	</div>
		</div>

	<div class="row cl">
			<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-2">
				
  <input name="Add" type="hidden" value="1">
<button onClick="article_save_submit();" class="btn btn-primary radius" type="submit" name="submit" ><i class="Hui-iconfont">&#xe632;</i> 保存并提交审核</button>
				<button name="reset" type="reset" class="btn btn-secondary radius" type="button"><i class="Hui-iconfont">&#xe632;</i> 重 填</button>
				<button onClick=" window.location.href='/admin/news/news_list.php';"  class="btn btn-default radius" type="button">&nbsp;&nbsp;返回列表&nbsp;&nbsp;</button>
			</div>
		</div>
	</form>
</article>


<script type="text/javascript">
var ue = UE.getEditor('editor');

</script>

	<?}?>








<? 
@$DB->close();
include "../share/bottom.php"?>
</body>
</html>
