package kr.co.kihyun.tree;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import kr.co.kihyun.moumi.MoumiConfig;
import kr.co.kihyun.db.DBManager;
import kr.co.kihyun.beans.user.HttpSSOLogin;
import kr.co.kihyun.text.html.ServletUtil;

public class UserDelete extends DBManager {
    public UserDelete(HttpServletRequest req,HttpServletResponse res) {
        PrintWriter out=null;
        try {
            res.setContentType("text/html;charset=UTF-8");
            out = res.getWriter();
        
            if(!HttpSSOLogin.isLogin(req)) {
                String connURL = "location='/totsys/login/login.jsp';";
                out.println(ServletUtil.getJavaScript(connURL));
                return;
            }
            
            String userId=req.getParameter("userID");
            
            if(userId==null || userId.equals("null")) {
                return;
            }
            
            String sql="UPDATE MOUMI_MUSER SET DEL_TYPE='Y' WHERE ID='"+userId+"'";
            execUpdate(sql);
            
            out.println(ServletUtil.alert("삭제되었습니다"));
            out.println(ServletUtil.redirect("/totsys/sysadm/dept/empty.jsp?reload=yes"));
            
        //44.적절하지 않은 예외처리(광범위예외클래스)_CWE-754 : Add by YOUNGJUN,CHO    
        } catch (IOException ioex) {
            ioex.printStackTrace();
            out.println(ServletUtil.alert("삭제에 실패하였습니다"));
            out.println(ServletUtil.redirect("/totsys/sysadm/dept/empty.jsp"));
        } catch (SQLException sqlex) {
            sqlex.printStackTrace();
            out.println(ServletUtil.alert("삭제에 실패하였습니다"));
            out.println(ServletUtil.redirect("/totsys/sysadm/dept/empty.jsp"));
        //++++++++++++++++++++++++++++++++++++++++++++++++    
        } catch (Exception e) {
            e.printStackTrace();
            out.println(ServletUtil.alert("삭제에 실패하였습니다"));
            out.println(ServletUtil.redirect("/totsys/sysadm/dept/empty.jsp"));
        } finally { 
            execClose(); 
        }
    }
}
