<%@ page contentType="text/html; charset=gb2312" language="java" import="java.util.*,com.jspsmart.upload.*" errorPage="" %>
<%@ page import="java.sql.*"%> 
<%@ page import="java.util.Date"%>
<%@ page import="java.text.*"%>
<%@ include file="checkbbsuser.jsp"%>
<%@ include file="../inc/conn.jsp"%>
<%@ include file="../inc/ftbbstohtml.jsp"%>
<%!int picsize;%>
<%!String menu,sql,strsql,title,TitleID,strDest="";%>
<%
    String content,bbs_img;
    ResultSet rs,rs1,rs2,rs3,rs4;
	String IP=request.getRemoteAddr();
    Date currTime = new Date();
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss",Locale.US);
    String ftime=new String(formatter.format(currTime).getBytes("iso-8859-1"));
	
    SimpleDateFormat formatter2 = new SimpleDateFormat("yyyyMMddhhmmss",Locale.US);
    String ptime=new String(formatter2.format(currTime).getBytes("iso-8859-1"));
	
    sql="select * from config where kind='3' order by id asc";
    Statement stmt4=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
    rs4=stmt4.executeQuery(sql);
	if(rs4.next())
	{
	picsize = Integer.parseInt(rs4.getString("content"));
	}

SmartUpload su = new SmartUpload();
su.initialize(pageContext);
su.upload();

com.jspsmart.upload.File file = su.getFiles().getFile(0);
if (!file.isMissing()){
String myFileName=file.getFileName();//取得上载的文件的文件名
String  suffix=myFileName.substring(0,myFileName.lastIndexOf('.'));//取得不带后缀的文件名

int fileSize=file.getSize();//取得文件的大小
String  ext= su.getFiles().getFile(0).getFileExt(); //取得后缀名

if(fileSize>picsize)
{
   out.print("<script language='javascript'>");
   out.print("alert('你上传文件太大了！');");
   out.print("history.go(-1);");
   out.print("</script>");
   out.close();
   return;
}
if (ext.equals("gif")||ext.equals("GIF")||ext.equals("jpg")||ext.equals("JPG"))
{
}
else
{
   out.print("<script language='javascript'>");
   out.print("alert('只能上传gif,jpg文件类型！');");
   out.print("history.go(-1);");
   out.print("</script>");
   out.close();
   return;
}
String picname=ptime+"."+ext;
bbs_img = picname;
file.saveAs("/upfile/"+picname);//将文件保存在服务器端
}
else{
bbs_img = "";
}

    String BoardID_1 = su.getRequest().getParameter("BoardID_1");
    String BoardID_2 = su.getRequest().getParameter("BoardID_2");
if(BoardID_1==null||BoardID_1.equals("")||BoardID_2==null||BoardID_2.equals("")){
    out.print("<script language='javascript'>");
    out.print("alert('请选择论坛类别！');");
    out.print("history.go(-1);");
    out.print("</script>");
    out.close();
	return;
}
	String zhiye = su.getRequest().getParameter("zhiye");
	title = su.getRequest().getParameter("title");
if(title==null||title.equals("")){
    out.print("<script language='javascript'>");
    out.print("alert('标题不能为空！');");
    out.print("history.go(-1);");
    out.print("</script>");
    out.close();
	return;
}
	menu = su.getRequest().getParameter("menu");
	//String bbs_img = picname;//file.getFileName();
	String bbs_img_text = su.getRequest().getParameter("bbs_img_text");
	String ticon = su.getRequest().getParameter("ticon");
	
    String tptype=su.getRequest().getParameter("tptype");
	String tpnl1=su.getRequest().getParameter("tpnl1");
	String tpnl2=su.getRequest().getParameter("tpnl2");
	String tpnl3=su.getRequest().getParameter("tpnl3");
	String tpnl4=su.getRequest().getParameter("tpnl4");
	String tpnl5=su.getRequest().getParameter("tpnl5");
	String tpnl6=su.getRequest().getParameter("tpnl6");
	String tpnl7=su.getRequest().getParameter("tpnl7");
	String tpnl8=su.getRequest().getParameter("tpnl8");
	String tpnl9=su.getRequest().getParameter("tpnl9");
	String tpnl10=su.getRequest().getParameter("tpnl10");

    String Sql_arrest="select * from BBS_arrest where (kind='Keyword' or kind='IP') order by id asc";
    Statement stmt3=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
    rs3=stmt3.executeQuery(Sql_arrest);
	if(rs3.next()){
	   content=rs3.getString("content");
	   if(menu.indexOf(content)!=-1||IP.indexOf(content)!=-1)
	   {
           out.print("<script language='javascript'>");
           out.print("alert('对不起，回复内容中不能含有"+rs3.getString("content")+"关键字或你的IP被禁止！');");
           out.print("history.go(-1);");
           out.print("</script>");
           out.close();
	   }
	 }

    if(bbs_img==null||bbs_img.equals("")){
    sql="insert into bbstitle(BoardID_1,BoardID_2,user_id,name,title,menu,ip,date,redate,zhiye,bbs_img_display,bbs_img_text,img_url_display,deleted,picture)";
    sql=sql+" values('"+BoardID_1+"','"+BoardID_2+"','"+(String)session.getAttribute("bbsuser")+"','"+(String)session.getAttribute("name")+"','"+title+"','"+menu+"','"+IP+"','"+ftime+"','"+ftime+"','"+zhiye+"','1','"+bbs_img_text+"','0','0','"+ticon+"')";
    }
	else{
	sql="insert into bbstitle(BoardID_1,BoardID_2,user_id,name,title,menu,bbs_img,ip,date,redate,zhiye,bbs_img_display,bbs_img_text,img_url_display,deleted,picture)";
    sql=sql+" values('"+BoardID_1+"','"+BoardID_2+"','"+(String)session.getAttribute("bbsuser")+"','"+(String)session.getAttribute("name")+"','"+title+"','"+menu+"','"+bbs_img+"','"+IP+"','"+ftime+"','"+ftime+"','"+zhiye+"','1','"+bbs_img_text+"','0','0','"+ticon+"')";
	}
	
	stmt.executeUpdate(sql);

    strsql="update BBS_Cate set BBS_Cate_Reply=BBS_Cate_Reply+1 where BBS_Cate_ID='"+BoardID_1+"'";
    stmt.executeUpdate(strsql);
	
    if(BoardID_2!=null)
	{
	strsql="update BBS_Cate set BBS_Cate_Reply=BBS_Cate_Reply+1 where BBS_Cate_ID='"+BoardID_2+"'";
	stmt.executeUpdate(strsql);
     }
	 
    if((String)session.getAttribute("bz")!="1"){
    strsql="update clubuser set jingyuan=jingyuan+10,tili=tili-10 where clubuser_name='"+(String)session.getAttribute("name")+"'";
    stmt.executeUpdate(strsql);
     }
	 
    sql="select top 1 id,date from bbstitle order by id desc";
    //Statement stmt3=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
    rs=stmt.executeQuery(sql);
    if(rs.next()){
    TitleID=rs.getString("id");
	}
 
	response.sendRedirect("checkasp.jsp?id="+TitleID);
%>