<%@page contentType="text/html; charset=UTF-8"%>
<%@page import="com.csc.library.entry.HelpEntry,com.csc.library.utilities.CheckNull,com.csc.library.mail.SendMail,com.csc.library.utilities.*,java.util.HashMap,com.csc.library.service.GenProcessQuque"%>
<%request.setCharacterEncoding("UTF-8");%>
<jsp:useBean id="MPROBATION_02" class="com.csc.library.system.Task" scope="page" />
<%
	MPROBATION_02.setChannel(request, response);
	HelpEntry screen = (HelpEntry) MPROBATION_02.process("HelpEntry", "MPROBATION_01HELP");
			
   CheckNull  chk = new CheckNull();
   String cmd = chk.chkNullString(request.getParameter("__cmd"));
   ThaiUtilities th = new ThaiUtilities();

   int result;
   String employee_req = chk.chkNullString(request.getParameter("__employee_req"));
   String astid_req = chk.chkNullString(request.getParameter("__astid_req"));
   if(cmd.equalsIgnoreCase("send")){
   		String from = chk.chkNullString(request.getParameter("__mail_from"));
		String to = chk.chkNullString(request.getParameter("__mail_to"));
		String cc = chk.chkNullString(request.getParameter("__mail_cc"));
		String subject = chk.chkNullString(request.getParameter("__mail_subject"));
		String message = chk.chkNullString(request.getParameter("__mail_message"));
		String message_s  = message.replaceAll("\n", "<br>");
		String message_result = message_s.replaceAll(" ","&nbsp;");

	/*	out.println("from"  + from + "<br>");
		out.println("to"  + to + "<br>");
		out.println("subject"  + subject + "<br>");
		out.println("message_result"  + message_result + "<br>");
	*/

		SendMail mail = new SendMail( "",from, to, cc, th.ASCII2Unicode(subject), th.ASCII2Unicode(message_result));
		result = mail.send();
   }
  UProfile  UPro= (UProfile) session.getAttribute("userprofile"); 
%>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="../CSS/TISCO.css" rel="stylesheet" type="text/css">
<script type='text/javascript' src='../JS/SCREEN.js'></script>
<script type='text/javascript' src='../JS/DATEINPUT.js'></script>
<script type='text/javascript' src='../JS/VIEWCALENDAR.js'></script>
<script type='text/javascript' src='../JS/ICONSMENU.js'></script>
<script language='javascript'>setLang('tha');</script>
<script language="javascript">getTitleName();</script>
<script language='javascript' src='../JS/HOTKEY.js'></script>
<script language="JavaScript" type="text/JavaScript">


function GoSave(){}
function GoUpdate(){}
function GoDelete(){}
function GoSearch(){}

function goHelp(helpName,inputName){
	var helpReturn;
	if(inputName=="__mail_from" )
		helpReturn="__mail_from:";

	linkHelp_Return(helpName,helpReturn);
	
}

function sendMail(){
	with(document.cscform){
		if (__mail_from.value == "" ) {
			alert("กรุณากรอกเมล์ผู้รับ");
			__mail_from.focus();
		} else if (__mail_to.value == "" ) {
			alert("กรุณากรอกเมล์ผู้ส่ง");
			__mail_to.focus();
		} else if (__mail_message.value == "") {
			alert("กรุณาใส่เนื้อหาในการส่งเมล์ครั้งนี้");
			__mail_message.focus();
		} else {
			__cmd.value = "send";
			genForm.value = "1";
			submit();
		}
	}
}

function goBack(){
	close();
}


function sendMailComp() {
	alert("ส่งเมล์เรียบร้อยแล้ว");
	//window.close();
}

function template(type){
with(document.cscform){
	//http://192.168.1.225:8082/hr/MYDOCUMENT.jsp?refnoteid=1&referid=&seq=&refpage=EMPVIEW/APP_EMV011_GPF

	__mail_subject.value = "กรุณาสร้างแบบฟอร์มติดตามผลงานทดลองงาน";
	if(type=="AP70" || type=="AP80"){
				text = "         เนื่องจากมีพนักงานเข้าใหม่ กรุณา สร้างแบบฟอร์มติดตามผลการทดลองงาน \nที่ https://myhr.gpf.or.th/hr/MYDOCUMENT.jsp?refnoteid=1&referid=&seq=&refpage=EMPVIEW/APP_EMV013_MONITOR  \n\n"
	}else{
		__mail_subject.value = "กรุณาประเมินผลการปฏิบัติงานของพนักงาน";
				text = "         เนื่องจากมีพนักงานหมดอายุสัญญา กรุณา ประเมินแบบฟอร์มผลการปฏิบัติงานของพนักงาน \nที่  https://myhr.gpf.or.th/hr/MYDOCUMENT.jsp?refnoteid=1&referid=&seq=&refpage=EMPVIEW/APP_EMV011_GPF \n\n"
	}
			text += "ขอแสดงความนับถือ\nส่วนบริหารทรัพยากรบุคคล\nกองทุนบำเน็จบำนาญข้าราชการ";

//	__mail_message.value=text.replace(/&nbsp;/g," ");
	__mail_message.value=text;
}

}
</script>
</head>
<body leftmargin="0" topmargin="0">
<div id="toolTipLayer" style="position:absolute; visibility: hidden"></div>
<form name="cscform" method="post" action="MPROBATION_02.jsp">
    <!----------BEGIN CSC INITIAL ZONE ------------------------>
    <%//=screen.InitialVariable()%>
    <!----------END CSC INITIAL ZONE -------------------------->
    <!---------------- HIDDEN FIELD ZONE ---------------------->
    <!-- All Use -->
    <input type="hidden" name="__screen" value="MPROBATION_02">
    <input type="hidden" name="__cmd" value="">
    <input type="hidden" name="__help" value="">
    <input type="hidden" name="__goPage" value="">
    <input type="hidden" name="__orderBy" value="">
    <input type="hidden" name="__helpReturn" value="">
    <input type="hidden" name="__helpName" value="">
    <input type="hidden" name="__pageCall" value="">
    <input type="hidden" name="__fixCon" value="">
    <input type="hidden" name="__fixFilter" value="">
    <input type="hidden" name="__language" value="<%//=screen.getUProfile().get("lang")%>">
    <input type="hidden" name="__companyid" value="<%//=screen.getUProfile().get("companyid")%>">
    <input name="aname" type="hidden" value="<%=th.ASCII2Unicode(request.getParameter("aname"))%>">   
    <input name="position" type="hidden" value="<%=th.ASCII2Unicode(request.getParameter("position"))%>">    
    <input name="place" type="hidden" value="<%=th.ASCII2Unicode(request.getParameter("place"))%>">   
    <input name="room" type="hidden" value="<%=th.ASCII2Unicode(request.getParameter("room"))%>">  
    <input name="date" type="hidden" value="<%=th.ASCII2Unicode(request.getParameter("date"))%>">   
    <input name="time" type="hidden" value="<%=th.ASCII2Unicode(request.getParameter("time"))%>">             
    <input name="__employee_req" type="hidden" value="<%=employee_req%>">             
    <input name="__astid_req" type="hidden" value="<%=astid_req%>">             
         
    <script language="javascript">getInputFormatDate();</script>
    <script language="javascript">initToolTips();</script>
    <br>
    <table width="814" height=""  border="0" align="center" cellpadding="0" cellspacing="0" class="large">
        <tr>
            <td  height="20" class="header">MPROBATION_02,<script language="javascript">swapLang("Send Mail");</script>&nbsp;</td>
        </tr>
        <tr>
            <td class="blankspace"></td>
        </tr>
        <td><table align="center" border="0" cellpadding="0" cellspacing="0" class="largest">
                    <tr>
                        <td><table border="0" cellpadding="0" cellspacing="1" class="inframe">
								<tr>
								  <td width="150" nowrap class="columnlabel"><script language="javascript">swapLang("To");</script>&nbsp;</td>
                                  <td width="717"><input name="__mail_to" type="text" size="80" maxlength="80" onkeypress = "chkNotThaiChaOnly()" value="<%=chk.chkNullString(request.getParameter("__mail_to"))%>"></td>
                                </tr>
                                <tr>
                                    <td nowrap class="columnlabel"><script language="javascript">swapLang("From");</script>&nbsp;</td>
                                  <td><input name="__mail_from" type="text" size="80" maxlength="80" onblur = "chkEmail(this)" onkeypress = "chkNotThaiChaOnly()" value="<%=chk.chkNullString(request.getParameter("__mail_from"))%>"></td>
                                </tr>
                                <tr>
                                    <td nowrap class="columnlabel"><script language="javascript">swapLang("Subject");</script>&nbsp;</td>
                                  <td><input name="__mail_subject" type="text" size="80" maxlength="80" value=""></td>
                                </tr>
                                <tr>
                                    <td valign="top" nowrap class="columnlabel"><script language="javascript">swapLang("Message");</script>&nbsp;</td>
                                  <td><textarea name="__mail_message" cols="125" rows="20"></textarea>
                                  <script language="javascript">template('<%=astid_req%>');</script></td>
                          </tr>
                      </table></td>
                    </tr>
                </table></td>
        </tr>
        <tr>
            <td class="blankspace">&nbsp;</td>
        </tr>


		<input type="hidden" name="genForm" value="">
			  <%
				if(request.getParameter("genForm") != null && request.getParameter("genForm").equals("1")){
					GenProcessQuque q_ap70 = new GenProcessQuque();
					GenProcessQuque q_ap80 = new GenProcessQuque();
					GenProcessQuque q_ap90 = new GenProcessQuque();
					try{
						HashMap param = new HashMap();
						param.put("uprofile", screen.getUProfile());
						param.put("ASSESSMENTID","");
						param.put("GROUPGRADE","");
						param.put("OBJECTIVE","ทดสอบการประเมินติดตามผลทดลองงาน");
						param.put("OVERRIDE","1");
						param.put("ASD$1","01-01-"+new CscCalendar().getYear());
						param.put("ASD$2","31-12-"+new CscCalendar().getYear());
						param.put("ASP$1","01-01-"+new CscCalendar().getYear());
						param.put("ASP$2","31-12-"+new CscCalendar().getYear());
						param.put("TITLE","ทดสอบการประเมินติดตามผลทดลองงาน");
						param.put("TDESC","ทดสอบการประเมินติดตามผลทดลองงาน");
						param.put("EDESC","ทดสอบการประเมินติดตามผลทดลองงาน");
						param.put("CONFIRM_STAT","0");

						if(astid_req.equals("AP90")){

									param.put("DOCNO","PROB-90");
									param.put("FORMS","FMT04");
									param.put("EMP$1",employee_req);
									param.put("EMP$2",employee_req);
									param.put("ASTYPE","AP90");

									q_ap70.createImmediateQueue(screen.getUProfile(), param,
											"Genarate Monitor form : ", 
											"Genarate Monitor form : ", 
											"","",  "GenApprisalTransaction", "APS","");



						}else{

									param.put("DOCNO","PROB-70");
									param.put("FORMS","FMT01");
									param.put("EMP$1",employee_req);
									param.put("EMP$2",employee_req);
									param.put("ASTYPE","AP70");

									q_ap70.createImmediateQueue(screen.getUProfile(), param,
											"Genarate Monitor form : ", 
											"Genarate Monitor form : ", 
											"","",  "GenApprisalTransaction", "APS","");


									param.put("DOCNO","PROB-80");
									param.put("FORMS","FMT02");
									param.put("EMP$1",employee_req);
									param.put("EMP$2",employee_req);
									param.put("ASTYPE","AP80");


									q_ap80.createImmediateQueue(screen.getUProfile(), param,
											"Genarate Monitor form : ", 
											"Genarate Monitor form : ", 
											"","",  "GenApprisalTransaction", "APS","");

							}

						


					}catch(Exception e){ 
					}
				}
			  %>

        <tr>
            <td class="blankspace">
            <div align="center" >
            <a href="javascript:sendMail();"><img src="../IMAGES/BUTTON/SEND.gif" border="0"></a>&nbsp;&nbsp;
            <a href="javascript:goBack();"><img src="../IMAGES/BUTTON/BACK.gif" border="0"></a>           </div>          </td>
        </tr>
        <tr>
            <td class="blankspace"></td>
        </tr>
        <td height="28" class="bottom"></td>
        </tr>
    </table>
<%
		if (request.getParameter("__cmd") != null && request.getParameter("__cmd").equals("send")) {
%>
			<script language="javascript">sendMailComp()</script>
<%
		}
%>
</form>
</body>
</html>