/***********************************************************************************
 * @@ 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.ArrayList;
import java.util.List;
//import javax.jdo.JDOObjectNotFoundException;
//import javax.jdo.PersistenceManager;
//import javax.jdo.Transaction;

//import javax.servlet.ServletException;
//import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
//import kr.co.kihyun.beans.entity.MDept;
//import kr.co.kihyun.beans.entity.MUser;
//import kr.co.kihyun.beans.entity.UserPart;
//import kr.co.kihyun.beans.entity.util.MPersistenceManager;
//import kr.co.kihyun.beans.entity.util.PMF;
//import kr.co.kihyun.beans.totsys.report.Report;
import kr.co.kihyun.db.DBManager;

//import kr.co.kihyun.lang.Encoder;
//import kr.co.kihyun.moumi.MoumiConfig;
//import kr.co.kihyun.lang.MString;
//import kr.co.kihyun.text.html.ServletUtil;

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

public class HttpProveRestoreSet extends DBManager {

    private  List<String> recogid;
    private ResultSet rs = null;
   	private static final Logger LOG = LoggerFactory.getLogger(HttpProveRecogSet.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 HttpProveRestoreSet(String docName,Long reportID,String reportType,String typeList,Long repoadminID,String userID,String GetID,String Contents,HttpServletRequest req, HttpServletResponse res) throws SQLException, IOException
	{
        String[] reoogUserDList = null;
        Long tmpID = null;
        String strUserID = null;
        String sql = null;
        String sql2 = null;

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

        res.setContentType("text/html;charset=UTF-8");
		PrintWriter out = res.getWriter();

		try
		{

         tmpID = repoadminID+1;
         UpdateRestoreRepoAdm(reportID,Contents,repoadminID);
         UpdateTotReport(repoadminID,reportID);

            //v2. 1.HTTP 응답분할 : Update by KWON,HAN

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

            //v2. 3.신뢰되지 않는 URL 주소로 자동 접속 연결_CWE-601 : Update by KWON,HAN
            // 다른 페이지 이동하는 URL 리스트를 만듬
            String connURL = "";
            String allowURL[] = { "/totsys/repoper/mydocbox/approve/report_list.jsp" };
            connURL = allowURL[0] + "?reportID="+reportID+"&totperInfo=true&reportType=COMPLETE&doctName="+docName+"&repoadminID="+repoadminID;
            LOG.debug("v2 3.신뢰되지 않는 URL 주소로 자동 접속 연결_CWE-601 : HttpProveRestoreSet.HttpProveRestoreSet() connURL={} : Not Test", connURL);
            res.sendRedirect(connURL);
            //========================================================================
            //======================================
         return;

		}catch (Exception e){
			e.printStackTrace();
		}
		finally
        {
           if(null != rs) rs.close();
           execClose();
        }
	}


     public void  UpdateRestoreRepoAdm(Long reportID,String Contents,Long repoadminID) throws SQLException
	{
        String tmpUserID = null;
        String restorFlag = null;
        ResultSet rs = null;
		PrintWriter out=null;
		try
		{
            restorFlag = "N";
            String sql="UPDATE MOUMI_REPOADM SET RECOG = 3,ACCEPTFLAG=?,HISTORY=? WHERE REPORT_ID = ? AND ID =?";
            execUpdate(sql,restorFlag,Contents,reportID,repoadminID);

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

            return;

		}catch (Exception e){
			e.printStackTrace();
		}finally {
           if(null != rs) rs.close();
           execClose();
        }
	}


      public void  UpdateTotReport(Long repoadminID,Long ReportID) throws SQLException
	{
        Long strReportID = null;
        Long tmpRepId = null;
        ResultSet rs = null;
		PrintWriter out=null;
		try
		{
            strReportID = ReportID;
            tmpRepId = repoadminID;

                String sql="UPDATE MOUMI_TOT_REPORT SET CURRENT_REPOADM_ID = ?,PRSS=4 WHERE ID =?";
                execUpdate(sql,tmpRepId,strReportID);
                //System.out.println("UpdateTotReport 실행 SQL::::::"+sql);
                return;

		}catch (Exception e){
			e.printStackTrace();
		}
		finally
        {
           if(null != rs) rs.close();
           execClose();
        }
	}


}
