<%@page contentType="text/html; charset=UTF-8"%>
<%@page import="com.csc.library.entry.HelpEntry,com.csc.library.system.*,com.csc.library.utilities.*"%>
<%@ page import="com.csc.library.entry.*,com.csc.library.database.*,com.csc.library.session.*"  %>
<%@page import="java.util.*,java.net.*,java.io.*,com.csc.upload.*"%>
<jsp:useBean id="hmul" class="com.csc.upload.HttpMultiPartParser" scope="page"/>
<jsp:useBean id="CI002" class="com.csc.library.system.Task" scope="page"/>
<%

	CI002.setChannel(request,response);
	CI002.checkProfile();
	UProfile u=CI002.getUProfile();

 	InitialEnvironment en = new InitialEnvironment("GLOBAL");
    String picturePath=en.getValue("comprofile-dir");

	String tempdir = ".";

	request.setAttribute("dir", request.getParameter("dir"));
	String browser_name = request.getRequestURI();
	CheckNull chk =new CheckNull();
	
	//out.println(">>>"+ request.getParameter("__attachfile1"));
%>

<%
    session.setAttribute("finishUpload","false");
	if ((request.getContentType()!=null)&&(request.getContentType().toLowerCase().startsWith("multipart"))){
		response.setContentType("text/html");
		try{
			int bstart = request.getContentType().lastIndexOf("oundary=");
			String bound = request.getContentType().substring(bstart+8);
			Hashtable ht = hmul.processData(request.getInputStream(), bound, tempdir);
        	hmul.uploadFiles(ht);						
			session.setAttribute("finishUpload","true");
		}
		catch (Exception e){ }
	}
%>

<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">
<link href="../CSS/MENU.css" rel="stylesheet" type="text/css">
<script  language="JavaScript" src="../JS/SCREEN.js"></script>
<script src="../JS/VIEWCALENDAR.js"></script>
<script language='javascript'>setLang('<%=u.get("lang")%>');</script>
<script language="JavaScript" >
<!--
function checktype(){
	var stdstr="";
    with(document.cscform){
		if(myFile.value.length>0){
			stdstr=myFile.value.substring(myFile.value.lastIndexOf("\\")+1,myFile.value.length);
			if((stdstr.indexOf(".zip")>-1)||(stdstr.indexOf(".txt")>-1)){
				submit(); 
			}else{
				//alert("กรุณาเลือกไฟล์ (.zip) หรือ ไฟล์ (.txt) เท่านั้น");
				alert(MyCode[56]);
			}
		} else if (myFile.value.length==0)
			//alert("กรุณาเลือกไฟล์ก่อน");
			alert(MyCode[57]);
	}
}

function checkImagesFile(obj){
	var stdstr="";
		if(obj.length>0){
			stdstr=obj.substring(obj.lastIndexOf("\\")+1,obj.length);
			if((stdstr.toLowerCase().indexOf(".jpg")>-1)||(stdstr.toLowerCase().indexOf(".jpeg")>-1)||(stdstr.toLowerCase().indexOf(".gif")>-1)||(stdstr.toLowerCase().indexOf(".png")>-1)||(stdstr.toLowerCase().indexOf(".tif")>-1)||(stdstr.toLowerCase().indexOf(".bmp")>-1)){
				return true; 
			}else{
				//alert("กรุณาเลือกไฟล์ให้ถูกกับการใช้งานเท่านั้น");
				alert(MyCode[59]);
				 return false;
			}
		} 			

}

function checkFilename(obj){
	var stdstr="";
		if(obj.length>0){
			stdstr=obj.substring(obj.lastIndexOf("\\")+1,obj.length);
		}
		return stdstr;
}

function setFileName(){
    /* window.opener.document.cscform.__attachfile1.value=checkFilename(document.cscform.__attachfile1.value);
    window.opener.document.cscform.__attachfile2.value=checkFilename(document.cscform.__attachfile2.value);
    window.opener.document.cscform.__attachfile3.value=checkFilename(document.cscform.__attachfile3.value);
    window.opener.document.cscform.__attachfile4.value=checkFilename(document.cscform.__attachfile4.value);*/
	
	var file1 = document.cscform.__attachfile1.value;
	var file2 = document.cscform.__attachfile2.value;
	var file3 = document.cscform.__attachfile3.value;
	var file4 = document.cscform.__attachfile4.value;

	if(file1.length>0&&checkFilename(file1)) window.opener.document.cscform.__attachfile1.value=checkFilename(file1);
	if(file2.length>0&&checkFilename(file2)) window.opener.document.cscform.__attachfile2.value=checkFilename(file2);
	if(file3.length>0&&checkFilename(file3)) window.opener.document.cscform.__attachfile3.value=checkFilename(file3);
	if(file4.length>0&&checkFilename(file4)) window.opener.document.cscform.__attachfile4.value=checkFilename(file4);


	document.cscform.submit();
}

function  uploadfile(){
	//alert(1);
	setFileName();
//	alert(2);
//	window.close();
}


function closeUpload(){
     var flag ="<%=session.getAttribute("finishUpload")%>";
	 if(flag=="true"){
	     window.close();
	 }
}
</script>

</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" >
<script language="javascript">closeUpload();</script>
<form  name="cscform"  enctype="multipart/form-data"  method="POST">
			

<!----------BEGIN CSC INITIAL ZONE ------------------------>

<%//=screen.InitialVariable()%>

<!----------END CSC INITIAL ZONE -------------------------->

<input  type="hidden" name="__cmd"  value=""> 
			<input type="hidden" name="__screen" value="CI002"> 
			<input type="hidden" name="__companyid" value="<%=u.get("companyid")%>"> 
			<input type="hidden" name="__language" value ="<%=u.get("lang")%>"> 
			
  <div align="center">

  	<br>
  	<br>
  	<br>	
	<div align="center">
 	<table  cellpadding="0"  cellspacing="0">
    <tr > 
    	<td  class="header">CI002,&nbsp;<script language="javascript">swapLang("Company profile");</script>&nbsp;</td>
   	</tr>
    <tr > 
    	<td  colspan="2">
			<table width="630" border="0">
            <tr> 
              	<td colspan="3"><input type="hidden" name="dir" value="<%=picturePath%>">
           	    <input type="hidden"name="__screen"  value="upload"></td>
            </tr>
            <tr>
              <td width="102" ><div align="right"><script language="javascript">swapLang("Attach file");</script></div></td>
              <td width="346">&nbsp;
              <input type="file" name="__attachfile1"></td>
              <td width="108">&nbsp;</td>
            </tr>
            <tr>
              <td ><div align="right"><script language="javascript">swapLang("Attach file");</script></div></td>
              <td>&nbsp;
              <input type="file" name="__attachfile2"></td>
              <td>&nbsp;</td>
            </tr>
            <tr>
              <td ><div align="right"><script language="javascript">swapLang("Attach file");</script></div></td>
              <td>&nbsp;
              <input type="file" name="__attachfile3"></td>
              <td>&nbsp;</td>
            </tr>
            <tr>
              <td ><div align="right"><script language="javascript">swapLang("Attach file");</script></div></td>
              <td>&nbsp;
              <input type="file" name="__attachfile4"></td>
              <td>&nbsp;</td>
            </tr>
            <tr>
              <td colspan="3"><div align="center"><a href="javascript:uploadfile();"><img src="../IMAGES/BUTTON/UPLOAD.gif" border="0"></a></div></td>
            </tr>
            <tr> 
             	<td colspan="3">&nbsp;</td>
            </tr>
      		</table> 
		</td>
   	</tr>
    <tr> 
    	<td  class="bottom"></td>
  	</tr>	  
    </table>
  </div>
</form>
</body>
</html>