<!--
whilvydy 新闻发布系统
-->

<%@ page contentType="text/html; charset=GB2312" language="java" import="java.sql.*" errorPage="error.jsp" %>
<%@ page import="java.io.*" %> 
<%@ page import="java.util.*" %>
<%@ include file="function/parameter.jsp" %>


<jsp:useBean id="news_man" scope="page" class="net.jspcn.db.DbConnect" />
<jsp:useBean id='StrTool' scope='page' class='net.jspcn.tool.StringProcess' />

<%
String sql;
int[] news_id_array = new int[15];
ResultSet rs,rs1;
boolean newsRelated,reviewable;
newsRelated = flag[0];
reviewable = flag[1];

news_man.openConnection();

int news_id;
if("".equals(request.getParameter("news_id"))||request.getParameter("news_id")==null)
news_id = 1;
else
news_id = Integer.parseInt(request.getParameter("news_id"));

if(request.getParameter("review_name")!=null&&!"".equals(request.getParameter("review_name"))&&request.getParameter("review_content")!=null){
sql = "insert into "+review_table+" (review_name,review_email,review_content,review_time,news_id) values ('"+request.getParameter("review_name")+"','"+request.getParameter("review_email")+"','"+StrTool.HtmlEncode(request.getParameter("review_content"))+"',now(),"+news_id+")";
news_man.executeQuery(sql);
}



sql = "select * from "+news_table+" where news_id = " + news_id;
rs = news_man.executeQuery(sql);
rs.next();
int news_hits = Integer.parseInt(rs.getString("news_hits")) + 1;
%>

<%@ include file = "function/header1.jsp" %>
<%=rs.getString("news_title")%>
<%@ include file = "function/header3.jsp" %>
  <table width="75%" border="0" cellpadding="15" cellspacing="0" bordercolor="#FFFFFF" bgcolor="#FFFFFF"  style="border-left: 1 solid #66cc00">
    <tr> 
      <td height="40"> 
        <div align="center" class=typename><%=rs.getString("news_title")%></div></td>
    </tr>
    <tr>
      <td height="40"> 
        <div align="right">作者：<%=rs.getString("news_author")%>&nbsp;&nbsp;&nbsp;&nbsp;文章来源：<%=rs.getString("news_source")%><br>发布日期：<%=rs.getString("news_time")%>&nbsp;&nbsp;&nbsp;&nbsp;浏览次数：<%=news_hits%>次</div></td>
    </tr>
<%
	  sql = "update "+news_table+" set news_hits = " + news_hits +" where news_id = " + news_id;
	  rs = news_man.executeQuery(sql);
	  
	  sql = "select * from "+newsdetail_table+" where news_id = " + news_id +" order by newsdetail_id";
	  rs = news_man.executeQuery(sql);
	  
	  while(rs.next()) {
%>
	  <tr>
	  <td  style="word-break:break-all"><div align="left">
	  	<%=rs.getString("newsdetail_content")%></div>
	  </td>
    	</tr>
    	<%
    	if (!"".equalsIgnoreCase(rs.getString("newsdetail_img"))) {    	
    	%>
		<tr>
		<td><div align="center">
		<%
					out.println("<IMG src=\"upload\\"+rs.getString("newsdetail_img")+"\" border=0");
		%>
		</div>
		</td>
		</tr>
<%
		}
		}
//找出相关新闻
		if(newsRelated==true)
		{
		sql = "select keyword_value from "+keyword_table+" where news_id ="+news_id +" limit 3";
		rs = news_man.executeQuery(sql);
		int i=0;
		int ipos=0;
		
		while(rs.next()) {
			sql = "select news_id from "+keyword_table+" where keyword_value ='"+rs.getString("keyword_value")+"' and news_id<>"+news_id+" order by news_id";
			rs1 = news_man.executeQuery(sql);
			for(;i<15&&rs1.next();i++) {
				int k;
				for(k=0;k<=ipos;k++) {
					if(news_id_array[k]==Integer.parseInt(rs1.getString("news_id")))
					break;
					}
				if(k>ipos){
					news_id_array[ipos]=Integer.parseInt(rs1.getString("news_id"));
					ipos++;
				}
				
				}
			}
			
		ipos--;	
		%>
			<tr>
			<td height=1  style="border-top: 1 solid #66cc00" align="left"><span class="typename">相关新闻</span><br><br>

			
		<%
			for(;ipos>=0;ipos--){
			sql = "select news_title,news_id,news_time from "+news_table+" where news_id ="+news_id_array[ipos];
			rs = news_man.executeQuery(sql);
			
			while(rs.next())
			{
		%>
			&nbsp;&nbsp;&nbsp;&nbsp;<IMG height=14 src="images/square.gif" width=14 border=0 valign="middle">
			<a href="newsdetail.jsp?news_id=<%=rs.getString("news_id")%>" target=_blank><%=rs.getString("news_title")%></a>&nbsp;&nbsp;<span class="copyright">[<%=rs.getString("news_time").substring(0,10)%>]</span><br>
		<%
			}
			}
		%>
		</td></tr>
		<%
		}
		
////可以评论
		if(reviewable==true)
		{
		%>
		<tr>
		<td align="left" style="border-top: 1 solid #66cc00">
		<span class="typename">发表评论</span>
		<br>
		<table border="0" width="70%"  bordercolor="#FFFFFF" bgcolor="#FFFFFF">
		<%
		sql = "select * from "+review_table+" where news_id = "+news_id+" order by review_id desc";
		rs = news_man.executeQuery(sql);
		
		while(rs.next()) {
		%>
		<tr><td width="20%" align="right">网 名:</td><td width="80%"><%=rs.getString("review_name")%></td></tr>
		<tr><td width="20%" align="right">EMAIL:</td><td width="80%"><%=rs.getString("review_email")%></td></tr>
		<tr><td width="20%" align="right">时 间:</td><td width="80%"><%=rs.getString("review_time")%></td></tr>
		<tr><td width="20%" align="right">评 论:</td><td width="80%"><%=rs.getString("review_content")%></td></tr>
		<tr><td width="20%" align="right"  style="border-top: 1 solid #66cc00">&nbsp;</td><td width="80%"  style="border-top: 1 solid #66cc00">&nbsp;</td></tr>
		<%
		}
		%>
		<tr><td width="20%" class=typename align="right">&nbsp;</td><td width="80%">&nbsp;</td></tr>
		</table>
		<!-- ---------------------------- 评论表单 -------------------------------------- -->
		<form action="newsdetail.jsp" method=post name=form1 onsubmit="return formCheck()">
			<input type="Hidden" name="news_id" value="<%=news_id%>">
    			<table width="60%"  border="1" cellspacing="0" cellpadding="2"  bordercolor="#00CC66"  borderColorDark="#FFFFFF" borderColorLight="#00CC66">
				<tr> 
        				<td width="30%"><div align="right">您的网名：</div></td>
        				<td><div align="left"><input name="review_name" type="text"  class=input size="12" maxlength=13  value=""></div></td>
				</tr>
				<tr> 
        				<td width="30%"><div align="right">您的EMAIL:</div></td>
        				<td><div align="left"><input name="review_email" type="text"  class=input size="12" maxlength=20  value=""></div></td>
				</tr>
				<tr> 
        				<td width="30%"><div align="right">您的评论</div></td>
        				<td><textarea class="textare" name="review_content"></textarea><div align="left"></td>
				</tr>
  			</table>
  			<br>
  			<input type=submit value="确 定" class=button>&nbsp;&nbsp;&nbsp;&nbsp;<input type=reset value="重 置" class=button>
		</form>
		<!-- ---------------------------- 评论表单结束 -------------------------------------- -->
		
		</td>
		</tr>
		
		<SCRIPT language=JavaScript>
         		function formCheck()
			{
			if(document.form1.review_name.value=="")
            		{
            			alert("请输入您的网名！");
				document.form1.review_name.focus();
				return false;
			}    
			
			if(document.form1.review_content.value=="")
            		{
            			alert("请输入您要发表的评论！");
				document.form1.review_content.focus();
				return false;
			}  

         		}
</SCRIPT>
		
		<%
		}
		%>
		
  </table>
  
  <%
  news_man.close();
  %>
  <%@ include file = "function/feeder.jsp" %>
