<%@page contentType="text/html; charset=UTF-8"%>
<%@page import="com.csc.library.utilities.CheckNull,com.csc.library.mail.SendMail,com.csc.library.utilities.*"%>
<%request.setCharacterEncoding("UTF-8");%>
<%
  CheckNull  chk = new CheckNull();
  String cmd = chk.chkNullString(request.getParameter("__cmd"));
  ThaiUtilities th = new ThaiUtilities();
  int result;
  UProfile  UPro= (UProfile) session.getAttribute("userprofile");
  String to = "";
  String toname = "";
  if(cmd.equalsIgnoreCase("send")){
    String from = chk.chkNullString(request.getParameter("__mail_from"));
    to = chk.chkNullString(request.getParameter("__mail_to"));
    toname = chk.chkNullString(request.getParameter("refNameList"));
    String cc = chk.chkNullString(request.getParameter("__mail_cc"));
    String subject = chk.chkNullString(request.getParameter("__mail_subject"));
    String message = "<PRE>"+chk.chkNullString(request.getParameter("__mail_message"))+"</PRE>";
    String arr_to[] = to.split(",");
    String arr_toname[] = toname.split(",");
    String dearRef = chk.chkNullString(request.getParameter("dearRef"));
    for(int i=0 ; i<arr_to.length ; i++){
      String newDearRef = dearRef.replaceAll(toname, arr_toname[i]);
      String newmsg = newDearRef + message;
      SendMail mail = new SendMail( "", from, arr_to[i], cc, subject, newmsg);
      result = mail.send();
    }
  }


  String fullname = UPro.get("fullname");
  String sendername = fullname.substring(fullname.indexOf(".")+1, fullname.length());
  //out.print(request.getParameter("refNameList"));
  // out.print("UPro :: "+UPro.get("branchname"));

%>
<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";
          submit();
        }
      }
    }

    function goBack(){
      close();
    }


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

    function template(type, appointment_type) {
      with (document.cscform) {
        var text = "";

        if (appointment_type == 0) { //appointment_type==0 สอบข้อเขียน
          if (type == "com1") {
//        text = "ขอเรียนเชิญเป็นกรรมการสอบข้อเขียน\n\nเรียน คณะกรรมการสอบข้อเขียน\n\n	ขอเรียนเชิญเป็นกรรมการสอบข้อเขียน ตำแหน่ง" + job.value + " ฝ่าย" + bu4.value + " ในวันที่ " + date.value + " เวลา " + time_st.value + " - " + time_en.value + " น. ณ " + place.value + " ห้อง " + room.value + "\n\nจึงขอเรียนเชิญท่านเป็นกรรมการสอบข้อเขียน ณ วันเวลา และสถานที่ดังกล่าว\n\nขอแสดงความนับถือ\n" + __branch.value;
            text += "Please find candidate profile as the attached <a href='http://" + svname.value + "'>http://"+ svname.value +"</a> For your consideration please." + "\n\n"
            text += "Should you require to interview this candidate please confirm back to Human Resources Department then we will process for next step." + "\n\n"
          } else if (type == "app") {
            text = "ขอเรียนเชิญสอบข้อเขียน\n\nเรียนคุณ " + aname.value + "\n\n	" + __branch.value + "  มีความยินดีที่จะแจ้งความประสงค์ ขอเรียนเชิญท่านสอบข้อเขียน ในตำแหน่ง " + job.value + " ฝ่าย " + bu4.value + " ในวันที่ " + date.value + " เวลา " + time_st.value + " - " + time_en.value + " น.  ณ " + place.value + " ห้อง " + room.value + "\n\n	จึงขอเรียนเชิญท่านเข้ารับการสอบข้อเขียน ณ วันเวลา และสถานที่ดังกล่าว\n\nขอแสดงความนับถือ\n" + __branch.value;
          }
          __mail_message.value = text;
          __mail_subject.value = "นัดหมายสอบข้อเขียน";
        } else if (appointment_type == 1) { //appointment_type==1 สอบสัมภาษณ์
          if (type == "com1") {
            text = "ขอเรียนเชิญเป็นกรรมการสัมภาษณ์งาน\n\nเรียน คณะกรรมการสัมภาษณ์\n\n	ขอเรียนเชิญเป็นกรรมการสัมภาษณ์งาน ตำแหน่ง" + job.value + " ฝ่าย" + bu4.value + " ในวันที่ " + date.value + " เวลา " + time_st.value + " - " + time_en.value + " น. ณ " + place.value + " ห้อง " + room.value + "\n\nจึงขอเรียนเชิญท่านเป็นกรรมการสัมภาษณ์ ณ วันเวลา และสถานที่ดังกล่าว\n\nขอแสดงความนับถือ\n" + __branch.value;
          } else if (type == "app") {
            text = "ขอเรียนเชิญเข้ารับการสัมภาษณ์\n\nเรียนคุณ " + aname.value + "\n\n	" + __branch.value + "  ขอเรียนเชิญเข้ารับการสัมภาษณ์งาน ตำแหน่ง" + job.value + " ฝ่าย" + bu4.value + " ในวันที่ " + date.value + " เวลา " + time_st.value + " - " + time_en.value + " น.  ณ " + place.value + " ห้อง " + room.value + "\n\n	จึงขอเรียนเชิญท่านเข้ารับการสัมภาษณ์ ณ วันเวลา และสถานที่ดังกล่าว\n\nขอแสดงความนับถือ\n" + __branch.value;
          }
          __mail_message.value = text;
          __mail_subject.value = "นัดหมายสัมภาษณ์งาน";
        } else { //appointment_type==3 อื่นๆ
          if (type == "com1") {
            text = "เรียนคณะกรรมการสัมภาษณ์\n                ทางส่วนบริหารทรัพยากรบุคคล ขอเรียนเชิญคณะกรรมการเข้าร่วมเป็นกรรมการสัมภาษณ์งาน\nในตำแหน่ง " + position.value + " ฝ่าย" + bu4.value + " ในวันที่ " + date.value + " เวลา " + time.value + " - " + timeend.value + " น. ณ " + place.value + " ห้อง " + room.value + " ชื่อผู้สมัคร " + aname.value + "\nโดยท่านสามารถดูรายละเอียดเพิ่มเติมที่ระบบ HRIS Module Recruitment / กรรมการสัมภาษณ์ / ตารางการสัมภาษณ์\n\n                ขอเชิญคณะกรรมการเข้าร่วมการสัมภาษณ์งาน ณ วัน เวลา และ สถานที่ดังกล่าว \n\nขอแสดงความนับถือ\n\nส่วนบริหารทรัพยากรบุคคล \n\n" + __branch.value;
          } else if (type == "app") {
            text = "เรียนคุณ " + aname.value + "\n	" + __branch.value + "  มีความยินดีที่จะแจ้งให้ท่านทราบว่าทางบริษัท มีความประสงค์ที่จะขอเชิญ\nท่านสัมภาษณ์งาน ในตำแหน่ง " + job.value + " ฝ่าย" + bu4.value + " ในวันที่ " + date.value + " เวลา " + time_st.value + " - " + time_en.value + " น.  ณ " + place.value + " ห้อง " + room.value + "\n	ขอเชิญท่านเข้ารับการสัมภาษณ์งาน ณ วันเวลา และสถานที่ดังกล่าว อนึ่งผู้สมัครจะต้องแต่งกายสุภาพในวันที่มาสัมภาษณ์งาน\nและนำเอกสารสมัครงานต่างๆ มาให้ครบถ้วน (สำเนาหลักฐานทางการศึกษา/สำเนาบัตรประชาชน/สำเนาทะเบียนบ้าน/\nรูปถ่ายสีขนาด 1 นิ้ว 1 รูป และเอกสารประกอบอื่นๆ) \n\nหากท่านมีข้อสงสัยสามารถติดต่อสอบถามได้โดยตรงกับทางบริษัทฯ\n\nขอแสดงความนับถือ\n\nส่วนบริหารทรัพยากรบุคคล \n\n" + __branch.value;
          }
          __mail_message.value = text;
          __mail_subject.value = "นัดหมายสัมภาษณ์งาน";
        }

      }
    }
  </script>
</head>
<body leftmargin="0" topmargin="0">
<div id="toolTipLayer" style="position:absolute; visibility: hidden"></div>
<form name="cscform" method="post" action="REC604.jsp">
  <!----------BEGIN CSC INITIAL ZONE ------------------------>
  <%//=screen.InitialVariable()%>
  <!----------END CSC INITIAL ZONE -------------------------->
  <!---------------- HIDDEN FIELD ZONE ---------------------->
  <!-- All Use -->
  <input type="hidden" name="__screen" value="REC604">
  <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="svname" type="hidden" value="<%=th.ASCII2Unicode(request.getServerName() + "/hr")%>">
  <input name="senderfullname" type="hidden" value="<%=th.ASCII2Unicode(sendername)%>">
  <input name="senderposition" type="hidden" value="<%=th.ASCII2Unicode(UPro.get("positionname"))%>">
  <input name="sendercomname" type="hidden" value="<%=th.ASCII2Unicode(UPro.get("branchname"))%>">
  <input name="aname" type="hidden" value="<%=th.ASCII2Unicode(request.getParameter("aname"))%>">
  <input name="job" type="hidden" value="<%=th.ASCII2Unicode(request.getParameter("job"))%>">
  <input name="bu4" type="hidden" value="<%=th.ASCII2Unicode(request.getParameter("bu4"))%>">
  <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="timeend" type="hidden" value="<%=th.ASCII2Unicode(request.getParameter("timeend"))%>">
  <input name="refNameList" type="hidden" value="<%=th.ASCII2Unicode(request.getParameter("refNameList"))%>">
  <input name="__branch" type="hidden" value="<%=UPro.get("branchname")%>">

  <input name="time_st" type="hidden" value="<%=th.ASCII2Unicode(request.getParameter("time_st"))%>">
  <input name="time_en" type="hidden" value="<%=th.ASCII2Unicode(request.getParameter("time_en"))%>">
  <input name="__sendmail" type="hidden" value="">


  <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">REC604,<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="<%= chk.chkNullString(request.getParameter("__mail_subject"),"")%>"></td>
          </tr>
          <tr>
            <td valign="top" nowrap class="columnlabel"><script language="javascript">swapLang("Message");</script>&nbsp;</td>
            <td>
              <input name="dearRef" style="width: 863px;height:40px;background-color: #ffffff;border-bottom: transparent" readonly value="Dear <%= chk.chkNullString(request.getParameter("refNameList"),"")%>">
              <textarea style="border-top: transparent " name="__mail_message" cols="120" rows="20"><%= chk.chkNullString(request.getParameter("__mail_message"),"")%>
              </textarea>
          </tr>

        </table></td>
      </tr>
    </table></td>
    </tr>
    <tr>
      <td class="blankspace">&nbsp;</td>
    </tr>
    <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>
  <%
  }else{
  %>
  <script language="javascript">template('<%=chk.chkNullString(request.getParameter("type"))%>','<%=chk.chkNullString(request.getParameter("appointment_type"))%>');</script>
  <%		}%>
</form>
</body>
</html>