<%@page contentType="text/html; charset=UTF-8"%>
<%@include file="/inc/init.jsp"%>
<%
	response.setHeader("Cache-Control", "no-cache"); //HTTP   1.1   
	response.setHeader("Pragma", "no-cache"); //HTTP   1.0   
	response.setDateHeader("Expires", 0);
	/**
	 * 处理同一IP提交超过1次
	 */
	 DOC doc=null;
	String curDate=new DateUtil().getDate();//对比IP有无重复
	String ip = pu.getIpAddr();
	String create_time = new DateUtil().getCurTime();
	Count_ip_db cidb = new Count_ip_db();
	doc = cidb.getOne(ip);
	int times = doc.geti("times");
	if (times >= 2) {///如果今天已经评论2次以上，限制评论
		out.print("发表评论成功！！");
		return;
	} else if (times == 0) { //若没有记录，加入数据库，删除旧记录有两重逻辑，一是今天新加的订单，另一是1的记录时间不是今天
		cidb.insert(ip, create_time);
		doc = cidb.getOne("1");//根据ip为1的记录，判断是否删除前一天记录
		if (!DOCUtil.isFine(doc)) { //若未初始化或错误删除，重新初始化
			new Install_db().setIpFlag();
		}
		String date = doc.get("create_time");
		if (!date.equals(curDate)) {//对比日期是否是今天更新过的
			cidb.delete(curDate);
			cidb.updateCreateTime("1", curDate);
		}
	} else { //否则更新加1
		cidb.update(ip);
	}
	String action = pu.getString("action");
	Comment_db cmdb = new Comment_db();
	String name = pu.getString("username");
	String content = URLDecoder.decode(pu.getString("content"),"UTF-8");
	content=Util.sub_String(content,600,"...多的不要了");
	int classid = pu.getInt("classid");
	int type = pu.getInt("type",0);
	int state = pu.getInt("state",0);
	String retain1 = pu.getString("top","99");
	String retain2 = "";
	String retain3 = "";
	String retain4 = "";
	if (action.equals("add")) {
		cmdb.insert(name, content, classid, type, state, create_time,
				ip, retain1, retain2, retain3, retain4);
		out.print("发表评论成功！");
		return;
	}
%>