/***********************************************************************************
 * @@ Program Name : HttpDeptList.java Description : 기관에속한 부서들의 목록 Author : 강원중 Create Date : 2003-12-16 History :
 * @@
 ***********************************************************************************/

package kr.co.kihyun.beans.user;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import kr.co.kihyun.beans.totsys.report.Report;
import kr.co.kihyun.db.DBManager;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class HttpApproveUpdateCancel extends DBManager {

    private  List<String> recogid;
    private ResultSet rs = null;
   	private static final Logger LOG = LoggerFactory.getLogger(Report.class);

   	private String[] ID = null;
   	private String[] RECOG = null;
   	private String[] RECOG_NUM = null;
   	private String[] RECOG_USER_ID = null;
   	private String[] REPORT_ID = null;
   	private String[] RECOGFLAG = null;

    public HttpApproveUpdateCancel(Long reportID,String reportType,String typeList,String docReportID,HttpServletRequest req, HttpServletResponse res) throws SQLException, IOException
	{
        String[] reoogUserDList = null;
        String strReportID = null;
        String sql = null;
        String sql2 = null;

       	String usID = HttpSSOLogin.getLoginID(req);
		int sysAuth = HttpSSOLogin.getSysAuth(req);
        strReportID = docReportID;
        String RecogId = null;
        ResultSet rs = null;

        res.setContentType("text/html;charset=UTF-8");
		PrintWriter out = res.getWriter();
		try
		{
                //System.out.println("::reportID:::"+strReportID);

                UpdateCancelRepoAdm(strReportID);
                cancelRepoAdm(strReportID);

            //v2. 1.HTTP 응답분할 : Update by KWON,HAN
//          res.sendRedirect("/totsys/repoper/mydocbox/tempbox/report_view.jsp?reportID="	+ reportID + "&totperInfo=true&reportType=" + reportType + "'&cancelState=Y");

            // 수정 : 외부 입력값 필터링
            String filtered_reportType = reportType.replaceAll("\r","").replaceAll("\n","");
            LOG.debug("v2 1.HTTP 응답분할 : HttpApproveUpdateCancel.HttpApproveUpdateCancel() filtered_reportType={}, Not Test", filtered_reportType);


            //v2. 3.신뢰되지 않는 URL 주소로 자동 접속 연결_CWE-601 : Update by KWON,HAN
//            res.sendRedirect("/totsys/repoper/mydocbox/tempbox/report_view.jsp?reportID="	+ reportID + "&totperInfo=true&reportType=" + filtered_reportType + "'&cancelState=Y");

            // 다른 페이지 이동하는 URL 리스트를 만듬
            String connURL = "";
            String allowURL[] = { "/totsys/repoper/mydocbox/tempbox/report_view.jsp" };
            connURL = allowURL[0] + "?reportID="	+ reportID + "&totperInfo=true&reportType=" + filtered_reportType + "'&cancelState=Y";
            LOG.debug("v2 3.신뢰되지 않는 URL 주소로 자동 접속 연결_CWE-601 : HttpApproveUpdateCancel.HttpApproveUpdateCancel() connURL={} : Not Test", connURL);
            res.sendRedirect(connURL);
            //========================================================================
            //======================================

         return;

		}catch (Exception e){
			e.printStackTrace();
		}
		finally
        {

            try {
                if (pstmt != null)
                	pstmt.close();
            } catch (SQLException ex) {
                ex.printStackTrace();
            }try {
                if (con != null)
                    con.close();
            } catch (SQLException ex) {
                ex.printStackTrace();
            }
            try {
                if (rs != null)
                    rs.close();
            } catch (SQLException ex) {
                ex.printStackTrace();
            }
        }
	}


     public void  cancelRepoAdm(String strReportID) throws SQLException
	{
        ResultSet rs = null;
		PrintWriter out=null;
        String recogFlag="Y";

		try
		{
                  //System.out.println("::reportID:::"+strReportID);
                  //String sql="DELETE FROM MOUMI_REPOADM WHERE REPORT_ID = ?";
                  String sql="UPDATE MOUMI_REPOADM SET DELTYPE='Y',RECOG=0 WHERE REPORT_ID = ?";
                  execUpdate(sql,strReportID);

                  //System.out.println("cancelRepoAdm 실행 SQL::::::"+sql);
                  return;
		}catch (Exception e){
    			e.printStackTrace();
		}
		finally
        {
            try {
                if (pstmt != null)
                	pstmt.close();
            } catch (SQLException ex) {
                ex.printStackTrace();
            }
            try {
                if (con != null)
                    con.close();
            } catch (SQLException ex) {
                ex.printStackTrace();
            }
            try {
                if (rs != null)
                    rs.close();
            } catch (SQLException ex) {
                ex.printStackTrace();
            }
        }
	}

     public void  UpdateCancelRepoAdm(String docReportID) throws SQLException
	{
        String strReportID = null;
        ResultSet rs = null;
		PrintWriter out=null;
		try
		{
            strReportID = docReportID;

            String sql="UPDATE MOUMI_TOT_REPORT SET CURRENT_REPOADM_ID ='',PRSS=4 WHERE ID =?";
            execUpdate(sql,strReportID);

            //System.out.println("UpdateCancelRepoAdm 실행 SQL::::::"+sql);

            return;

		}catch (Exception e){
			e.printStackTrace();
		}
		finally
        {
            try {
                if (pstmt != null)
                	pstmt.close();
            } catch (SQLException ex) {
                ex.printStackTrace();
            }
            try {
                if (con != null)
                    con.close();
            } catch (SQLException ex) {
                ex.printStackTrace();
            }
            try {
                if (rs != null)
                    rs.close();
            } catch (SQLException ex) {
                ex.printStackTrace();
            }
        }
	}


}
