/*************************************************************************************************
 * 프로그램명 : HttpReReportCancle.java 프로그램설명 : 재보고 취소 작성자 : 작성일 : 변경일 :
 **************************************************************************************************/

package kr.co.kihyun.beans.totsys.totper;

import java.io.IOException;
import java.io.PrintWriter;

import javax.jdo.PersistenceManager;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import kr.co.kihyun.beans.entity.TotReport;
import kr.co.kihyun.beans.entity.TotReportProcess;
import kr.co.kihyun.beans.entity.util.MPersistenceManager;
import kr.co.kihyun.beans.entity.util.*;
import kr.co.kihyun.beans.user.HttpSSOLogin;
import kr.co.kihyun.lang.Encoder;
import kr.co.kihyun.lang.MLong;
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;
@WebServlet("/servlet/kr.co.kihyun.beans.totsys.totper.HttpReReportCancle")
public class HttpReReportCancle extends HttpServlet {
        private static final Logger LOG = LoggerFactory.getLogger(HttpReReportCancle.class);
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
        
	public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
		res.setContentType("text/html;charset=UTF-8");
		PrintWriter out = res.getWriter();

		/*********** User HttpSSOLogin check ***********/
		if (!HttpSSOLogin.isLogin(req)) {
			String connURL = "location='/totsys/login/login.jsp';";
			out.println(ServletUtil.getJavaScript(connURL));
			return;
		}

		/********** parameter value **********/
		String reportID = Encoder.toJava(req.getParameter("reportID"));
		String url = MString.checkNull(req.getParameter("url"));

		PersistenceManager pm = new MPersistenceManager(PMF.get().getPersistenceManager());
		try {
			TotReport totReport = pm.getObjectById(TotReport.class, MLong.parseLong(reportID));
			totReport.setProcess(TotReportProcess.COMP);
			pm.makePersistent(totReport);
			out.println(ServletUtil.alert(MoumiConfig.getMessageBundle().getString("moumi.message.popup.reReportComplete")));
			if ("mmReReportCancel".equals(url))
				out.println(ServletUtil
						.getJavaScript("document.location='/totsys/totadm/prssbox/reports/report_list.jsp?docID="
								+ totReport.getTotDoc().getId() + "';"));
			else
				out.println(ServletUtil
						.getJavaScript("document.location='/totsys/totper/mydocbox/prssbox/reports/report_list.jsp?docID="
								+ totReport.getTotDoc().getId() + "';"));
		} catch (Exception ex) {
			out.println(ServletUtil.alert(MoumiConfig.getMessageBundle().getString("moumi.message.popup.reReportFail")));
                        
                        //v2. 9.크로스사이트 스크립트 (PrintWrier) : Update by KWON,HAN
//			out.println(ServletUtil.getJavaScript("history.go(-1);"));
                        
                        // 수정 : 외부 입력값 필터링
                        String callbackFunc = "history.go(-1);";
                        String filtered_callbackFunc = callbackFunc.replaceAll("<","").replaceAll(">","").replaceAll("&","").replaceAll(",","");
                        LOG.debug("v2 9.크로스사이트 스크립트 (PrintWrier) : HttpReReportCancle.doPost() filtered_callbackFunc={}, Not Test", filtered_callbackFunc);
                        out.println(ServletUtil.getJavaScript(filtered_callbackFunc));      
                        //========================================
                        
			ex.printStackTrace();
		} finally {
			pm.close();
		}
	}
}
