<%@page contentType="text/html; charset=UTF-8"%>
<%@page import="com.csc.library.entry.HelpEntry,com.csc.library.system.*,com.csc.library.utilities.*,com.csc.library.dwr.*"%>
<%@page import="com.csc.library.entry.*,com.csc.library.database.*,com.csc.library.session.*,javax.mail.*,java.util.*"  %>
<%@page import="com.csc.library.session.InitialEnvironment,com.csc.library.util.download.Downloadfile"%>
<%@page import="java.util.HashMap,java.util.ArrayList, com.csc.library.report.ReportUDF"%>
<%@page import="com.csc.library.database.StaticProperties, com.csc.library.database.CscConnection,com.csc.library.mail.SendMail"%>
<jsp:useBean id="screen" class="com.csc.library.system.Task" scope="page"/>
<%
	CheckNull chk = new CheckNull();
	ThaiUtilities chkChar = new ThaiUtilities();
	screen.setChannel(request,response);
	screen.checkProfile();
	
	long attach_time = Long.parseLong(chk.chkNullString(request.getParameter("attach_time"),String.valueOf(new CscCalendar().getTimeInMillis())));
	String dbtype =  ((CscConnection) StaticProperties.myConnection.getConnection(screen.getUProfile().get("dbname"), screen.getUProfile())).getVendor();

	String cmd = chk.chkNullString(request.getParameter("__cmd"));
    int result=0;
    if(cmd.equalsIgnoreCase("send")){
   		String from = chk.chkNullString(request.getParameter("__condition$from"));
		String to = chk.chkNullString(request.getParameter("__condition$to"));
		String cc = chk.chkNullString(request.getParameter("__mail_cc"));
		String subject = new ThaiUtilities().ASCII2Unicode(chk.chkNullString(request.getParameter("__condition$subject")));
		String message = new ThaiUtilities().ASCII2Unicode(chk.chkNullString(request.getParameter("__condition$message")).replaceAll("\r\n","<br>"));
		SendMail mail = new SendMail( "", from, to, cc, subject, message);
		result = mail.send();
    }
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<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  language="JavaScript" src="../JS/SCREEN.js"></script>
<script type='text/javascript' src='../JS/ICONSMENU.js'></script>
<script language='javascript' src='../JS/HOTKEY.js'></script>
<script language='javascript'>setLang('<%=screen.getUProfile().get("lang")%>');</script>
<script language="JavaScript" type="text/JavaScript">
	var tagmail = "";
	function goHelp(helpName,inputName){
		var helpReturn;
		var tmp;
		with (document.cscform) {
			tmp = __fixCon.value;
			__fixCon.value = "";
			if(inputName=="__bu1id" ) {
				helpReturn="__bu1id:bu1id,__bu1desc:tdesc";
			}else if(inputName=="__bu2id" ) {
				__fixCon.value =  (__bu1id.value!="")?"parent='"+__bu1id.value+"'":"";
				helpReturn="__bu2id:bu2id,__bu2desc:tdesc";
			}else if(inputName=="__bu3id" ) {
				__fixCon.value =  (__bu2id.value!="")?"parent='"+__bu2id.value+"'":"";
				helpReturn="__bu3id:bu3id,__bu3desc:tdesc";
			}else if(inputName=="__positionid" ) {
				helpReturn="__positionid:positionid,__positiondesc:tdesc";
			}else if(inputName=="__apsid" ) {
				__fixCon.value = "astid='AP10'";
				helpReturn="__apsid:apsid,__apsdesc:tdesc";
			}
			linkHelp_Return(helpName,helpReturn);
			__fixCon.value = tmp;
		}
	}
	function filter(){
		var filter_emp = "";
		with(document.cscform){
			if(chk_bu1.checked && __bu1id.value!=""){
				filter_emp += ((filter_emp!="")?" and ":"")+"memployee.bu1='"+__bu1id.value+"'";
			}
			if(chk_bu2.checked && __bu2id.value!=""){
				filter_emp += ((filter_emp!="")?" and ":"")+"memployee.bu2='"+__bu2id.value+"'";
			}
			if(chk_bu3.checked && __bu3id.value!=""){
				filter_emp += ((filter_emp!="")?" and ":"")+"memployee.bu3='"+__bu3id.value+"'";
			}
			if(chk_posi.checked && __positionid.value!=""){
				filter_emp += ((filter_emp!="")?" and ":"")+"memployee.emp_position='"+__positionid.value+"'";
			}
			if(chk_name.checked && __name.value!=""){
				filter_emp += ((filter_emp!="")?" and ":"")+"memployee.fname like '%"+__name.value+"%'";
			}

			if(filter_emp!=""){
				filter_emp = " and "+filter_emp;
			}
		}
		var filter = filter_emp;
		window.document.cscform.__fixCon.value = filter;
		window.document.cscform.__issearch.value = '1';
		window.document.cscform.submit();		
	}
	function setChkCon(ccon){
		if(ccon.checked){
			ccon.value = "1";
		}else{
			ccon.value = "0";
		}
	}
	function chkTextCon(textc, textcl, ccon){
		var obj;
		if(textc == ""){
			obj = eval("window.document.cscform."+textcl);
			obj.value = "";
			obj = eval("window.document.cscform."+ccon);
			obj.checked = false;
			obj.value = '0';
		}else{
			obj = eval("window.document.cscform."+ccon);
			obj.checked = true;
			obj.value = '1';
		}
	}
	function setListEmp(chkbox){
		with(document.cscform){
			if(chkbox.checked){
				if(listEmp.value.indexOf(","+chkbox.id+",")<0){
					listEmp.value += chkbox.id+",";
					__condition$to.value += chkbox.value+", ";
				}
			}else{
				if(listEmp.value.indexOf(","+chkbox.id+",")>=0){
					listEmp.value = listEmp.value.replace(","+chkbox.id+",",",");
					__condition$to.value = __condition$to.value.replace(chkbox.value+", ","");
				}
			}
		}
	}
	function restListEmp(){
		with(document.cscform){
			var tmp = listEmp.value.split(",");
			for(i=0;i<tmp.length;i++){
				if(tmp[i]!=""){
					document.getElementById(tmp[i]).checked = true;
				}
			}
		}
	}
	function clearTo(){
		with(document.cscform){
			var tmp = listEmp.value.split(",");
			for(i=0;i<tmp.length;i++){
				if(tmp[i]!=""){
					document.getElementById(tmp[i]).checked = false;
				}
			}
			__condition$to.value = "";
			listEmp.value = ",";
		}
	}
	function send(){
		with (document.cscform){
			if( __condition$to.value != ''){
				__cmd.value = "send";
				filter();
			}else{
				alert("ไม่มีข้อมูลเมลล์ที่จะส่ง");
			}
		}
	}
	/*function send(){
		with (document.cscform){
			if( __condition$to.value != ''){
				var _from = __condition$from.value;
				var _to = __condition$to.value;
				var _cc = "";
				var _subject = __condition$subject.value;
				var _content = __condition$message.value;
				
				var allFile = new Array();
				var fileName ="";
				for(i=0;i<filesize.value;i++){
						fileName = document.getElementById('fileAttach'+i).value;
						if(fileName.toString()!=''){
							allFile[i] = filepath.value+fileName;
						}
				}		
				tagmail = document.getElementById("t_mail").innerHTML;
				document.getElementById("t_mail").innerHTML = "กรุณารอสักครู่ ระบบกำลังดำเนินการอยู่";
				SendMail.sendMail(_from,_to,_cc,_subject,_content,allFile,doCallBack);	
			}else{
				alert("ไม่มีข้อมูลเมลล์ที่จะส่ง");
			}
		}
	}*/
	var doCallBack = function(data) { 
		if(data==1){
			alert("Send Complete !!!");
		}else{
			alert("Send Fail !!");
		}
		document.getElementById("t_mail").innerHTML = tagmail;
	}
	function checkAll(){
		with(document.cscform){
			var obj = document.getElementsByName("chkemp");
			if(typeof obj!="undefined"){
				for(i=0;i<obj.length;i++){
						obj[i].checked = true;
						setListEmp(obj[i]);
				}
			}
		}
	}
	function decheckAll(){
		with(document.cscform){
			var obj = document.getElementsByName("chkemp");
			if(typeof obj!="undefined"){
				for(i=0;i<obj.length;i++){
						obj[i].checked = false;
						setListEmp(obj[i]);
				}
			}
		}
	}
	function goAttach(){
		with(document.cscform){
			window.open('ATTACH_FILE.jsp?attach_time=<%=attach_time%>','attach_file','scrollbars=yes,status=yes,resizable=yes,width=620,height=300');
		}
	}
	function sendMailComp(status) {
		with(document.cscform){
			if(status=="0"){
				alert("การส่งเมล์ล้มเหลว");
			}else{
				alert("ส่งเมล์เรียบร้อยแล้ว");
			}
		}
	}
</script>

</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" onLoad="MM_preloadImages('../IMAGES/BUTTON/SWAP/BACK_SWAP20.gif')">
<form name="cscform" method="post" action="#">


<input type="hidden" name="__screen" value="ASP709">
<input type="hidden" name="__cmd" value="">
<input type="hidden" name="__help" value="">
<input type="hidden" name="__fixCon" value="<%=chk.chkNullString(request.getParameter("__fixCon"))%>">
<input type="hidden" name="listEmp" value="<%=chk.chkNullString(request.getParameter("listEmp"),",")%>">
<input type="hidden" name="__language" value ="<%=screen.getUProfile().get("lang")%>"> 
<input type="hidden" name="__issearch" value ="<%=chk.chkNullString(request.getParameter("__issearch"),"0")%>"> 

<input type="hidden" name="attach_time" value="<%=attach_time%>">
  <br>
  <div align="center">
    <table  cellpadding="0"  cellspacing="0"  class="largest">
		<tr > 
			<td  class="header">ASP709, &nbsp;สถานะ / ส่งเมล์แจ้งผู้ประเมิน&nbsp;</td>
		</tr>
		<tr>
			<td  class="blankspace">&nbsp;</td>
		</tr>
		<tr>
			<td>
				<table  cellpadding="0"  cellspacing="0"  class="largest">
					<tr>
						<td align="right" width="15%"><script language="JavaScript">swapLang('Condition');</script>&nbsp;<input type="checkbox" name="chk_bu1" value="<%=chk.chkNullString(request.getParameter("chk_bu1"),"0")%>" <%=(chk.chkNullString(request.getParameter("chk_bu1"),"0").equals("1"))?"checked":""%> onclick="setChkCon(this);"></td>
						<td align="right" width="15%"><script language="JavaScript">swapLang('BU1');</script>&nbsp;</td>
						<td width="70%"><input type="text" name="__bu1id" size="10" value = '<%=chk.chkNullString(request.getParameter("__bu1id"))%>' onblur="chkTextCon(this.value,'__bu1desc','chk_bu1');"> <a href="javascript: goHelp('MBU1HELP','__bu1id');"  onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('__bu1_image','','../IMAGES/BUTTON/SWAP/SEARCH_SWAP20.gif',1)"><img src="../IMAGES/BUTTON/MAIN/SEARCH20.gif" alt="SEARCH" name="__bu1_image" width="20" height="20" border="0" align="absmiddle" ></a> <input type="text" name="__bu1desc" size="40" value = '<%=chk.chkNullString(chkChar.ASCII2Unicode(request.getParameter("__bu1desc")))%>' readonly></td>
					</tr>
					<tr>
						<td align="right"><script language="JavaScript">swapLang('Condition');</script>&nbsp;<input type="checkbox" name="chk_bu2" value="<%=chk.chkNullString(request.getParameter("chk_bu2"),"0")%>" <%=(chk.chkNullString(request.getParameter("chk_bu2"),"0").equals("1"))?"checked":""%> onclick="setChkCon(this);"></td>
						<td align="right"><script language="JavaScript">swapLang('BU2');</script>&nbsp;</td>
						<td><input type="text" name="__bu2id" size="10" value = '<%=chk.chkNullString(request.getParameter("__bu2id"))%>' onblur="chkTextCon(this.value,'__bu2desc','chk_bu2');"> <a href="javascript: goHelp('MBU2HELP','__bu2id');"  onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('__bu2_image','','../IMAGES/BUTTON/SWAP/SEARCH_SWAP20.gif',1)"><img src="../IMAGES/BUTTON/MAIN/SEARCH20.gif" alt="SEARCH" name="__bu2_image" width="20" height="20" border="0" align="absmiddle" ></a> <input type="text" name="__bu2desc" size="40" value = '<%=chk.chkNullString(chkChar.ASCII2Unicode(request.getParameter("__bu2desc")))%>' readonly></td>
					</tr>
					<tr>
						<td align="right"><script language="JavaScript">swapLang('Condition');</script>&nbsp;<input type="checkbox" name="chk_bu3" value="<%=chk.chkNullString(request.getParameter("chk_bu3"),"0")%>" <%=(chk.chkNullString(request.getParameter("chk_bu3"),"0").equals("1"))?"checked":""%> onclick="setChkCon(this);"></td>
						<td align="right"><script language="JavaScript">swapLang('BU3');</script>&nbsp;</td>
						<td><input type="text" name="__bu3id" size="10" value = '<%=chk.chkNullString(request.getParameter("__bu3id"))%>' onblur="chkTextCon(this.value,'__bu3desc','chk_bu3');"> <a href="javascript: goHelp('MBU3HELP','__bu3id');"  onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('__bu3_image','','../IMAGES/BUTTON/SWAP/SEARCH_SWAP20.gif',1)"><img src="../IMAGES/BUTTON/MAIN/SEARCH20.gif" alt="SEARCH" name="__bu3_image" width="20" height="20" border="0" align="absmiddle" ></a> <input type="text" name="__bu3desc" size="40" value = '<%=chk.chkNullString(chkChar.ASCII2Unicode(request.getParameter("__bu3desc")))%>' readonly></td>
					</tr>
					<tr>
						<td align="right"><script language="JavaScript">swapLang('Condition');</script>&nbsp;<input type="checkbox" name="chk_posi" value="<%=chk.chkNullString(request.getParameter("chk_posi"),"0")%>" <%=(chk.chkNullString(request.getParameter("chk_posi"),"0").equals("1"))?"checked":""%> onclick="setChkCon(this);"></td>
						<td align="right"><script language="JavaScript">swapLang('Position');</script>&nbsp;</td>
						<td><input type="text" name="__positionid" size="10" value = '<%=chk.chkNullString(request.getParameter("__positionid"))%>' onblur="chkTextCon(this.value,'__positiondesc','chk_posi');"> <a href="javascript: goHelp('MPOSITIONHELP','__positionid');"  onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('__position_image','','../IMAGES/BUTTON/SWAP/SEARCH_SWAP20.gif',1)"><img src="../IMAGES/BUTTON/MAIN/SEARCH20.gif" alt="SEARCH" name="__position_image" width="20" height="20" border="0" align="absmiddle" ></a> <input type="text" name="__positiondesc" size="40" value = '<%=chk.chkNullString(chkChar.ASCII2Unicode(request.getParameter("__positiondesc")))%>' readonly></td>
					</tr>
					<tr>
						<td align="right"><script language="JavaScript">swapLang('Condition');</script>&nbsp;<input type="checkbox" name="chk_name" value="<%=chk.chkNullString(request.getParameter("chk_name"),"0")%>" <%=(chk.chkNullString(request.getParameter("chk_name"),"0").equals("1"))?"checked":""%> onclick="setChkCon(this);"></td>
						<td align="right">ชื่อพนักงาน&nbsp;</td>
						<td><input type="text" name="__name" size="40" value = '<%=chk.chkNullString(chkChar.ASCII2Unicode(request.getParameter("__name")))%>'  onblur="chkTextCon(this.value,'__name','chk_name');"></td>
					</tr>
					<tr>
						<td align="right"></td>
						<td align="right"><script language="JavaScript">swapLang('Assessor LV');</script>&nbsp;</td>
						<td><select name="__assvl" value = "<%=chk.chkNullString(request.getParameter("__assvl"),"1")%>"> 
									<option value="all" <%=(chk.chkNullString(request.getParameter("__assvl"),"all").equals("all"))?"selected":""%>><script language="JavaScript">swapLang('All');</script></option>
									<option value="1" <%=(chk.chkNullString(request.getParameter("__assvl"),"all").equals("1"))?"selected":""%>>1</option>
									<option value="2" <%=(chk.chkNullString(request.getParameter("__assvl"),"all").equals("2"))?"selected":""%>>2</option>
									<option value="3" <%=(chk.chkNullString(request.getParameter("__assvl"),"all").equals("3"))?"selected":""%>>3</option>
									<option value="4" <%=(chk.chkNullString(request.getParameter("__assvl"),"all").equals("4"))?"selected":""%>>4</option>
									<option value="5" <%=(chk.chkNullString(request.getParameter("__assvl"),"all").equals("5"))?"selected":""%>>5</option>
								</select>
								&nbsp;
								
								<script language="JavaScript">swapLang('Status');</script>
								<select name="__status">
									<option value="all" <%=(chk.chkNullString(request.getParameter("__status"),"all").equals("all"))?"selected":""%>><script language="JavaScript">swapLang('All');</script></option>
								<%
									String status[] = new ReportUDF().getSystemCode("APPSTATUS",screen.getUProfile().get("lang"));
									for(int i=0;i<status.length;i++){
								%>
									<option value="<%=status[i].split(",")[0]%>"  <%=(chk.chkNullString(request.getParameter("__status"),"all").equals(status[i].split(",")[0]))?" selected":""%>><%=status[i].split(",")[1]%></option>
								<%		
									}
								%>
								</select>
						</td>
					</tr>
					<tr> 
						<td class="blankspace" ></td>
						<td ><a href="javascript:filter();"><img src="../IMAGES/BUTTON/SEARCH.gif" border="0" align="middle"></a></td>
						<td class="blankspace" ></td>
					  </tr>
				</table>
			</td>
		</tr>
		<tr>
			<td  class="blankspace">&nbsp;</td>
		</tr>
		<tr > 
			<td  align="center"> 
				<table align="center" cellpadding="1" bgcolor="#666666" cellspacing="1" class="largest" colspan="9" border="1">
					<tr> 
						<td width="5%" class="title1" align="center">ส่ง</td>
						<td width="8%" class="title1" align="center"><script language="JavaScript">swapLang('Employee ID');</script></td>
						<td width="20%" class="title1" align="center"><script language="JavaScript">swapLang('Name Surname');</script></td>
						<td width="15%" class="title1" align="center"><script language="JavaScript">swapLang('BU1');</script></td>
						<td width="15%" class="title1" align="center"><script language="JavaScript">swapLang('BU2');</script></td>
						<td width="6%" class="title1" align="center">สถานะประเมิน 1</td>
						<td width="6%" class="title1" align="center">สถานะประเมิน 2</td>
						<td width="6%" class="title1" align="center">สถานะประเมิน 3</td>
						<td width="6%" class="title1" align="center">สถานะประเมิน 4</td>
						<td width="6%" class="title1" align="center">สถานะประเมิน 5</td>
					</tr>
					<%
						 DataSet ds = new DataSet();
						 String fixlv = chk.chkNullString(request.getParameter("__assvl"),"all"); 
						 String stat = chk.chkNullString(request.getParameter("__status"),"all"); 
							String sql = "select taps.employeeid, mprefix.tdesc"+((dbtype.equalsIgnoreCase("ORACLE"))?"||":"+")+"memployee.fname"+((dbtype.equalsIgnoreCase("ORACLE"))?"|| ' ' ||":"+' '+")+"memployee.lname as fullname, memployee.email, "+
										"mbu1.tdesc as bu1, mbu2.tdesc as bu2, taps.LV1_A, taps.LV1_W, taps.LV2_A, taps.LV2_W, "+
										"taps.LV3_A, taps.LV3_W, taps.LV4_A, taps.LV4_W, taps.LV5_A, taps.LV5_W "+
							"from ( "+
								"select apsassessor as employeeid, sum(LV1_A)LV1_A, sum(LV1_W)LV1_W, sum(LV2_A)LV2_A, sum(LV2_W)LV2_W, sum(LV3_A)LV3_A, sum(LV3_W)LV3_W "+
								" , sum(LV4_A)LV4_A, sum(LV4_W)LV4_W, sum(LV5_A)LV5_A, sum(LV5_W)LV5_W "+
								"from ( "+
									((fixlv.equals("all") || fixlv.equals("1"))?
									"select distinct apsassessor, "+
											"sum(case when apsstatus='A' then 1 else 0 end) as LV1_A, "+
											"count(apsstatus) as LV1_W, "+
											"0 as LV2_A, "+
											"0 as LV2_W, "+
											"0 as LV3_A, "+
											"0 as LV3_W, "+
											"0 as LV4_A, "+
											"0 as LV4_W, "+
											"0 as LV5_A, "+
											"0 as LV5_W "+
									"from tapstran "+
									"where astid='AP10' "+
									((!stat.equals("all"))?" and apsstatus = '"+stat+"' ":"")+
									"group by apsassessor ":" ")+ 
									((fixlv.equals("all") || fixlv.equals("2"))?
									((fixlv.equals("all"))?"union all ":"")+
									"select distinct apsapprove1 as apsassessor, "+
											"0 as LV1_A, "+
											"0 as LV1_W, "+
											"sum(case when apsappstatus1='A' then 1 else 0 end) as LV2_A, "+
											"count(apsappstatus1) as LV2_W, "+
 											"0 as LV3_A, "+
											"0 as LV3_W, "+
											"0 as LV4_A, "+
											"0 as LV4_W, "+
											"0 as LV5_A, "+
											"0 as LV5_W "+
									"from tapstran "+
									"where astid='AP10' "+
									((!stat.equals("all"))?" and apsappstatus1 = '"+stat+"' ":"")+
									"group by apsapprove1 ":" ")+
									((fixlv.equals("all") || fixlv.equals("3"))?
									((fixlv.equals("all"))?"union all ":"")+
									"select distinct apsapprove2 as apsassessor, "+
											"0 as LV1_A, "+
											"0 as LV1_W, "+
											"0 as LV2_A, "+
											"0 as LV2_W, "+
											"sum(case when apsappstatus2='A' then 1 else 0 end) as LV3_A, "+
											"count(apsappstatus2) as LV3_W, "+
											"0 as LV4_A, "+
											"0 as LV4_W, "+
											"0 as LV5_A, "+
											"0 as LV5_W "+
									"from tapstran "+
									"where astid='AP10' "+
									((!stat.equals("all"))?" and apsappstatus2 = '"+stat+"' ":"")+
									"group by apsapprove2 ":" ")+
									((fixlv.equals("all") || fixlv.equals("4"))?
									((fixlv.equals("all"))?"union all ":"")+
									"select distinct apsapprove3 as apsassessor, "+
											"0 as LV1_A, "+
											"0 as LV1_W, "+
											"0 as LV2_A, "+
											"0 as LV2_W, "+
											"0 as LV3_A, "+
											"0 as LV3_W, "+
											"sum(case when apsappstatus3='A' then 1 else 0 end) as LV4_A, "+
											"count(apsappstatus3) as LV4_W, "+
											"0 as LV5_A, "+
											"0 as LV5_W "+
									"from tapstran "+
									"where astid='AP10' "+
									((!stat.equals("all"))?" and apsappstatus3 = '"+stat+"' ":"")+
									"group by apsapprove3 ":" ")+
									((fixlv.equals("all") || fixlv.equals("5"))?
									((fixlv.equals("all"))?"union all ":"")+
									"select distinct apsapprove4 as apsassessor, "+
											"0 as LV1_A, "+
											"0 as LV1_W, "+
											"0 as LV2_A, "+
											"0 as LV2_W, "+
											"0 as LV3_A, "+
											"0 as LV3_W, "+
											"0 as LV4_A, "+
											"0 as LV4_W, "+
											"sum(case when apsappstatus4='A' then 1 else 0 end) as LV5_A, "+
											"count(apsappstatus4) as LV5_W "+
									"from tapstran "+
									"where astid='AP10' "+
									((!stat.equals("all"))?" and apsappstatus4 = '"+stat+"' ":"")+
									"group by apsapprove4 ":" ")+
								") taps "+
								"group by apsassessor "+
							") taps, memployee, mprefix, mbu1, mbu2 "+
							"where memployee.employeeid = taps.employeeid "+ 
								"and mprefix.prefixid = memployee.emp_prefix "+
								"and mbu1.bu1id = memployee.bu1 "+
								"and mbu2.bu2id = memployee.bu2 ";
								//out.print(sql);
						 String issearch = chk.chkNullString(request.getParameter("__issearch"),"0"); 
						 String fixC = chk.chkNullString(chkChar.ASCII2Unicode(request.getParameter("__fixCon")));
						 if(issearch.equals("1")){
							ds.setInfo(sql+fixC, (String)screen.getUProfile().get("dbname"), "tapstran");
							ds.initConnection(screen.getUProfile());
							while(ds.next()){
					%>
					<tr > 
						<td align="center"><input type="checkbox" id="<%=ds.getString("employeeid")%>" name="chkemp" value="<%=ds.getString("email")%>" onclick="setListEmp(this);"></td>
						<td align="center"><%=ds.getString("employeeid")%></td>
						<td >&nbsp;<%=ds.getString("fullname")%></td>
						<td >&nbsp;<%=ds.getString("bu1")%></td>
						<td >&nbsp;<%=ds.getString("bu2")%></td>
						<td align="center"><font class="<%=(Integer.parseInt(ds.getString("lv1_a")) < Integer.parseInt(ds.getString("lv1_w")) )?"warnning":"" %>"><%=ds.getString("lv1_a")%></font>/<%=ds.getString("lv1_w")%></td>
						<td align="center"><font class="<%=(Integer.parseInt(ds.getString("lv2_a")) < Integer.parseInt(ds.getString("lv2_w")) )?"warnning":"" %>"><%=ds.getString("lv2_a")%></font>/<%=ds.getString("lv2_w")%></td>
						<td align="center"><font class="<%=(Integer.parseInt(ds.getString("lv3_a")) < Integer.parseInt(ds.getString("lv3_w")) )?"warnning":"" %>"><%=ds.getString("lv3_a")%></font>/<%=ds.getString("lv3_w")%></td>
						<td align="center"><font class="<%=(Integer.parseInt(ds.getString("lv4_a")) < Integer.parseInt(ds.getString("lv4_w")) )?"warnning":"" %>"><%=ds.getString("lv3_a")%></font>/<%=ds.getString("lv4_w")%></td>
						<td align="center"><font class="<%=(Integer.parseInt(ds.getString("lv5_a")) < Integer.parseInt(ds.getString("lv5_w")) )?"warnning":"" %>"><%=ds.getString("lv3_a")%></font>/<%=ds.getString("lv5_w")%></td>
					</tr>
					<%
							}
							ds.closeConnection();
						}
					%>
				</table>
			</td>
		</tr>
		<tr>
			<td  class="blankspace">&nbsp;</td>
	  </tr>
	  <tr>
			<td  class="blankspace" align="center">
				<a href="javascript:checkAll();"><img src="../IMAGES/BUTTON/SELECTALL.gif" border="0" align="middle"></a>
				<a href="javascript:decheckAll();"><img src="../IMAGES/BUTTON/DESELECTALL.gif" border="0" align="middle"></a>
			</td>
	   </tr>
		<tr>
			<td  class="blankspace">&nbsp;</td>
		</tr>
		<tr>
			<td>
				<table border="1" align="center" class="maxsize" cellpadding="0" cellspacing="0">
					 <tr>
							<td  class="blankspace" colspan="3">&nbsp;</td>
					  </tr>
					<tr>
					  <td width="20%" align="right"><script language="javascript">swapLang("To ");</script>&nbsp;</td>
					  <td width="60%"><textarea name="__condition$to" cols="85" rows="4" readonly><%=(!chk.chkNullString(request.getParameter("__condition$to")).equals(""))?chk.chkNullString(request.getParameter("__condition$to"))+" ":""%></textarea></td>
					  <td width="20%"></td>
					</tr>
					<tr>
					  <td align="right"><script language="javascript">swapLang("From ");</script>&nbsp;</td>
					  <td ><input type="text" name="__condition$from" value = "HRonline"onBlur = "chkEmail(this);"></td>
					  <td >&nbsp;</td>
					</tr>
					<tr>
					  <td align="right"><script language="javascript">swapLang("Subject");</script>&nbsp;</td>
					  <td><input name="__condition$subject" type="text" size="85" value="<%=chk.chkNullString(chkChar.ASCII2Unicode(request.getParameter("__condition$subject")),"แจ้งประเมินผล")%>"></td>
					  <td>&nbsp;</td>
					</tr>
					<tr>
					  <td align="right">&nbsp;</td>
					  <td><textarea name="__condition$message" cols="85" rows="6"><%=chk.chkNullString(chkChar.ASCII2Unicode(request.getParameter("__condition$message")))%></textarea></td>
					  <td>&nbsp;</td>
					</tr>
					<%
      					CscCalendar calendar = new CscCalendar(attach_time);
      					InitialEnvironment environment = new InitialEnvironment("GLOBAL");
      					Downloadfile download = new Downloadfile(environment.getValue("DIRUPLOAD-dir")+attach_time);			
      					HashMap hm = download.listFile();
      					ArrayList file_name = (ArrayList)hm.get("file_name");
      					ArrayList file_size = (ArrayList)hm.get("file_size");
					%>
						<input type="hidden" name="filesize" value="<%=file_name.size()%>">
						<input type="hidden" name="filepath" value="<%=environment.getValue("DIRUPLOAD-dir")+attach_time+"\\"%>">
					<%
      					if(file_name.size()>0){
							String fileList = "";
      						for( int i = 0 ; i < file_name.size() ; i++ ){
					%>
						<input type="hidden" name="fileAttach<%=i%>" value="<%=file_name.get(i)%>">
					<%
      								fileList += file_name.get(i)+" ("+file_size.get(i)+" KB)"+((i < file_name.size()-1 )?", ":"");
							}
					%>
						<tr>
							<td align="right">&nbsp;</td>
							<td colspan="2"><%=fileList%></td>
						</tr>
						<%
      					}
      					%>
					<tr>
						<td align="right">&nbsp;</td>
						<td  colspan="2"><input type="button" name="add_file" value="Attach File" height="10" onclick="goAttach();"></td>
					</tr>
					<tr>
						<td  class="blankspace" colspan="3">&nbsp;</td>
					</tr>
					<tr>
						<td class="blankspace" align="center" colspan="3" id="t_mail">	
							<a href="javascript:clearTo();"><img src="../IMAGES/BUTTON/CLEAR.gif" border="0" align="middle"></a>
							<a href="javascript:send();"><img src="../IMAGES/BUTTON/SEND.gif" border="0" align="middle"></a>
						</td>
					</tr>
					<tr>
						<td  class="blankspace" colspan="3">&nbsp;</td>
					</tr>
				  </table>
			</td>
		</tr>
		<tr>
			<td  class="blankspace">&nbsp;</td>
		</tr>
		<tr> 
			<td  class="bottom"></td>
		</tr>
    </table>
</form>
<script language="JavaScript">restListEmp();</script>
<%
		if (request.getParameter("__cmd") != null && request.getParameter("__cmd").equals("send")) {
%>	
			<script language="javascript">sendMailComp('<%=result%>')</script>
<%
		}
%>
</body>
</html>