<%@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.*,com.csc.library.cscimport.MyImport;"%>
<jsp:useBean id="upload" class="com.csc.library.system.Task" scope="page"/>
<jsp:useBean id="hmul" class="com.csc.upload.HttpMultiPartParser" scope="page"/>
<%
upload.setChannel(request,response);
upload.checkProfile();
UProfile u=upload.getUProfile();

InitialEnvironment en = new InitialEnvironment("GLOBAL");
String filePath=en.getValue("dirimport-dir");

String tempdir = ".";

request.setAttribute("dir", request.getParameter("dir"));
String browser_name = request.getRequestURI();
String status="";
Hashtable ht=new Hashtable();
String dir="";
String table = "ttimetemp";
String xml="";

%>

<%
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);
		ht = hmul.processData(request.getInputStream(), bound, tempdir);
		hmul.uploadFiles(ht);
		u.set("upload","true");
		dir=(String) ht.get("dir");
		xml=(String) ht.get("__xml");

		FileInfo f = (FileInfo) ht.get("myFile");
		String fileFullPath = f.file.toString();
		String fileName="";
		StringTokenizer str = new StringTokenizer(fileFullPath, "\\");
		while (str.hasMoreTokens()) {
			fileName = str.nextToken();
		}

		response.sendRedirect("TAU128_IMPORT.jsp?__fileName="+fileName+"&__cmd=process_data&__xml="+xml);
	}
	catch (Exception e){ e.printStackTrace(); }
}
%>
<%
	/*if (u.get("upload").toString().equalsIgnoreCase("true")) {
		u.set("upload","false");
		try {
			FileInfo f = (FileInfo) ht.get("myFile");
			String fileFullPath = f.file.toString();
			String fileName="";
			StringTokenizer str = new StringTokenizer(fileFullPath, "\\");
			while (str.hasMoreTokens()) {
				fileName = str.nextToken();
			}

			String xmlPath =en.getValue("import-dir");
			String importPath =en.getValue("dirimport-dir");

			DbRecord rec = new InitialRecord(u).getDbRecord(table);
		  	rec.setColumn("*");
		  	MyImport myImp = new MyImport(rec, importPath + fileName, xmlPath +"xml/"+ xml);
		  	myImp.process();
			status="Import Successful";

		}
	    catch (Exception ex) {
			status = ex.getMessage();
    	}
	} else u.set("upload","true");	*/
%>
<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/bootstrap.css" rel="stylesheet"  type="text/css"/>
		<link href="../CSS/bootstrap_csc_backend.css" rel="stylesheet"  type="text/css"/>
		<script type="text/javascript" src="../JS/jquery-2.1.3.min.js"></script>
		<script type='text/javascript' src="../JS/bootstrap.js"></script>
		<script language="JavaScript" src="../JS/SCREEN.js"></script>
		<script language="javascript">setLang('<%=upload.getUProfile().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(".txt")>-1){
						submit();
					}else if(stdstr.indexOf(".TXT")>-1){
						submit();
					}else if(stdstr.indexOf(".csv")>-1){
						submit();
					}else if(stdstr.indexOf(".CSV")>-1){
						submit();
					}else if(stdstr.indexOf(".dat")>-1){
						submit();
					}else if(stdstr.indexOf(".DAT")>-1){
						submit();
					}else if(stdstr.indexOf(".Txt")>-1){
						submit();
					}else if(stdstr.toUpperCase().indexOf(".TAF")>-1){
						submit();
					}else{
						alert(MyCode[81]);
					}
				} else if (myFile.value.length==0)
				alert(MyCode[80]);
			}
		}

		function notInput(){
			with(document.cscform){
				alert(myFile.value);
				myFile.value="5";
			}
		}
		//-->
		</script>

	</head>
	<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
		<form  name="cscform"  enctype="multipart/form-data" method="POST" >

			<br/>
			<div align="center">
				<table  cellpadding="0"  cellspacing="0">
					<tr >
						<td class="header">TAU128,&nbsp;<script language="javascript">swapLang("Import Swipe Card");</script>&nbsp;</td>
					</tr>
					<tr>
						<td colspan="2">
							<table width="630" border="0">
								<tr>
									<td colspan="2"></td>
								</tr>
								<tr>
									<td class="columnlabel"><script language="javascript">swapLang("File");</script>&nbsp;</td>
									<td>
										<input type="hidden"name="__screen"  value="upload"/>
										<input type="hidden" name="dir" value="<%=filePath%>"/>
										<input type="file" name="myFile" onKeyDown="javascript:notInput();"/>
									</td>
								</tr>
								<tr>
									<td class="columnlabel"><script language="javascript">swapLang("Format");</script>&nbsp;</td>
									<td>
										<select name="__xml">
											<!--<option value="TTIMETEMP_VIV.xml"><script language="javascript">swapLang("VIV");</script></option>
											<option value="TTIMETEMP_OEI.xml"><script language="javascript">swapLang("OEI");</script></option>
											<option value="TTIMETEMP_DAD.xml"><script language="javascript">swapLang("DAD");</script></option>-->
											<option value="TTIMETEMP_SENA.xml"><script language="javascript">swapLang("SENA");</script></option>
											<option value="TTIMETEMP_LANDMARK.xml"><script language="javascript">swapLang("LANDMARK");</script></option>
											<option value="TTIMETEMP_RIKEN.xml">Riken</option>
											<option value="TTIMETEMP_CKT.xml">CKT</option>
											<option value="TTIMETEMP_TAFF.xml">TAFF</option>
											<option value="TTIMETEMP_AREEYA.xml">AREEYA</option>
											<option value="TTIMETEMP_ZEEME.xml">ZEEME</option>
											<option value="TTIMETEMP_ZEEME_LOCATION.xml">ZEEME With Location</option>
										</select>
									</td>
								</tr>
								<tr>
									<td class="buttonline" colspan="7">
										<div align="center">
											<button type="button" class="btn btn-primary width100" swlang code="SW013181" onClick="checktype();">Upload</button>
										</div>
									</td>
								</tr>
								<!--tr>
									<td colspan="2" ></td>
								</tr>
								<tr>
									<td class="columnlabel"><script language="javascript">swapLang("Import Status");</script>&nbsp;</td>
									<td><%//=status%></td>
								</tr-->
								<tr>
									<td colspan="2" class="blankspace"  ></td>
								</tr>
							</table>
						</td>
					</tr>
					<tr>
						<td class="bottom"></td>
					</tr>
				</table>
			</div>
		</form>
	</body>
</html>