⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 magic_del.jsp

📁 论坛软件系统亦称电子公告板(BBS)系统
💻 JSP
字号:
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.io.File"%>
<%@page import="cn.jsprun.domain.Members"%>
<%@ page import="org.hibernate.SessionFactory" %>
<%@ page import="cn.jsprun.utils.HibernateUtil" %>
<%@ page import="org.hibernate.Session" %>
<%@ page import="org.hibernate.Transaction" %>
<%! private final String tablePrefix = "jrun_"; %>
<%
boolean noException = false;
Integer targetuid = null;
Integer expiration = 0; 
boolean extra = false;
Members currentMember = (Members)session.getAttribute("user");
String magicid = request.getParameter("magicid");
Integer userid = (Integer)session.getAttribute("jsprun_uid");
Integer pid = (Integer)request.getAttribute("targetPid");
Integer tid = (Integer)request.getAttribute("targetTid");
String targetUsername = (String)request.getAttribute("targetUsername");
SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
Session hibernateSession = sessionFactory.getCurrentSession();
Transaction transaction = hibernateSession.beginTransaction();	
Connection connection = null;
Statement statement = null;
ResultSet rs = null;
try{
	connection = hibernateSession.connection();
	connection.setAutoCommit(false);
	statement = connection.createStatement();
	
	Integer nowtime = (Integer)request.getAttribute("timestamp");
	rs = statement.executeQuery("SELECT tid,fid,authorid, first FROM "+tablePrefix+"posts WHERE pid="+pid);
	if(rs.next()){
		Integer tid_p = rs.getInt("tid");
		Integer fid_p = rs.getInt("fid");
		Integer authorid = rs.getInt("authorid");
		byte first = rs.getByte("first");
		if(authorid.intValue()!=userid){
			request.setAttribute("messageFromOperationMagic","对不起,此道具只能操作自己发的主题和帖子,请返回.");
			return;
		}
		String realayPath = application.getRealPath("");
		if(first==1){
			rs = statement.executeQuery("SELECT replies FROM "+tablePrefix+"threads WHERE tid="+tid_p);
			int replies = 0;
			if(rs.next()){
				replies = rs.getInt("replies");
			}
			rs = statement.executeQuery("SELECT attachment,thumb FROM "+tablePrefix+"attachments WHERE tid="+tid_p);
			while(rs.next()){
				String attachment = rs.getString("attachment");
				byte thumb = rs.getByte("thumb");
				File file = new File(realayPath+"/"+attachment);
				if(file.isFile()){
					file.delete();
				}
				if(thumb==1){
					String imagePostfix = attachment.substring(attachment.lastIndexOf("."),attachment.length());
					file = new File(realayPath+"/"+attachment+".thumb"+imagePostfix);
					if(file.isFile()){
						file.delete();
					}
				}
			}
			String[] tableNames = {"threads", "threadsmod", "relatedthreads", "posts", "polls", "polloptions", "trades", "activities", "activityapplies", "attachments", "favorites", "mythreads", "myposts", "subscriptions", "debates", "debateposts", "typeoptionvars", "forumrecommend"};
			for(String tableName : tableNames){
				statement.execute("DELETE FROM "+tablePrefix+tableName+" WHERE tid='"+tid_p+"'");
			}
			rs = statement.executeQuery("SELECT tid,dateline,author FROM "+tablePrefix+"posts WHERE fid="+fid_p+" AND invisible=0 ORDER BY dateline DESC LIMIT 1");
			StringBuffer sqlBuffer = new StringBuffer("UPDATE "+tablePrefix+"forums AS f SET f.threads=f.threads-1, f.posts=f.posts-"+(replies+1)+", ");
			if(rs.next()){
				Integer lastTid = rs.getInt("tid");
				Integer lastDateline = rs.getInt("dateline");
				String lastAuthor = rs.getString("author");
				String lastThreadSubject = "";
				rs = statement.executeQuery("SELECT subject FROM "+tablePrefix+"threads WHERE tid="+lastTid);
				if(rs.next()){
					lastThreadSubject = rs.getString("subject");
				}
				sqlBuffer.append("f.lastpost='"+lastTid+"\t"+lastThreadSubject+"\t"+lastDateline+"\t"+lastAuthor+"' ");
			}else{
				sqlBuffer.append("f.lastpost='' ");
			}
			sqlBuffer.append("WHERE f.fid="+fid_p);
			statement.executeUpdate(sqlBuffer.toString());
			//~~!
		}else {
			rs = statement.executeQuery("SELECT attachment,thumb FROM "+tablePrefix+"attachments WHERE pid="+pid);
			while(rs.next()){
				String attachment = rs.getString("attachment");
				byte thumb = rs.getByte("thumb");
				File file = new File(realayPath+"/"+attachment);
				if(file.isFile()){
					file.delete();
				}
				if(thumb==1){
					String imagePostfix = attachment.substring(attachment.lastIndexOf("."),attachment.length());
					file = new File(realayPath+"/"+attachment+".thumb"+imagePostfix);
					if(file.isFile()){
						file.delete();
					}
				}
			}
			statement.execute("DELETE FROM "+tablePrefix+"posts WHERE pid="+pid);
			statement.execute("DELETE FROM "+tablePrefix+"myposts WHERE pid="+pid);
			statement.execute("DELETE FROM "+tablePrefix+"attachments WHERE pid="+pid);
			
			rs = statement.executeQuery("SELECT tid,dateline,author FROM "+tablePrefix+"posts WHERE fid="+fid_p+" AND invisible=0 ORDER BY dateline DESC LIMIT 1");
			StringBuffer sqlBuffer = new StringBuffer("UPDATE "+tablePrefix+"forums AS f SET f.posts=f.posts-1, ");
			if(rs.next()){
				Integer lastTid = rs.getInt("tid");
				Integer lastDateline = rs.getInt("dateline");
				String lastAuthor = rs.getString("author");
				String lastThreadSubject = "";
				rs = statement.executeQuery("SELECT subject FROM "+tablePrefix+"threads WHERE tid="+lastTid);
				if(rs.next()){
					lastThreadSubject = rs.getString("subject");
				}
				sqlBuffer.append("f.lastpost='"+lastTid+"\t"+lastThreadSubject+"\t"+lastDateline+"\t"+lastAuthor+"' ");
			}else{
				sqlBuffer.append("f.lastpost='' ");
			}
			sqlBuffer.append("WHERE f.fid="+fid_p);
			statement.executeUpdate(sqlBuffer.toString());
		}
	}else{
		request.setAttribute("messageFromOperationMagic","Posts is null");
		return;
	}
%>
<%@ include file="/include/magics/mLogAndmm.jsp" %>
<%
	connection.commit();
	noException = true;
}catch(Exception exception){
	connection.rollback();
	exception.printStackTrace();
	throw exception;
}finally{
	try{
		if(!noException&&connection!=null){
			connection.rollback();
		}
		if(rs!=null){
			rs.close();
			rs = null;
		}
		if(statement!=null){
			statement.close();
			statement = null;
		}
		if(connection != null){
			connection.close();
			connection = null;
		}
	}catch(Exception exception2){
		exception2.printStackTrace();
	}
}
%>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -