<%@page contentType="text/html;  charset=UTF-8;" pageEncoding="UTF-8"  %>

<%@page import="java.io.ByteArrayInputStream" %>
<%@page import="java.io.ByteArrayOutputStream" %>
<%@page import="java.io.File" %>
<%@page import="java.io.IOException" %>
<%@page import="java.io.InputStream" %>
<%@page import="org.apache.commons.fileupload.servlet.ServletFileUpload" %>
<%@page import="org.apache.commons.fileupload.FileItemFactory" %>
<%@page import="org.apache.commons.fileupload.disk.DiskFileItemFactory" %>
<%@page import="org.apache.commons.fileupload.FileItem" %>
<%@page import="com.csc.library.session.*" %>
<%@page import="com.csc.library.utilities.*,com.csc.library.database.DataSet,java.util.*" %>
<%@page import="com.csc.library.database.CscConnection" %>
<%@page import="com.csc.library.fpprocess.*" %>
<%@page import="com.csc.library.fputility.*" %>

<%
	System.out.print("******* get acc info. from server *********");
	MsgPackage recdata = new MsgPackage();
	try {
		boolean isMultipart = ServletFileUpload.isMultipartContent(request);

		if(isMultipart){
			System.out.print("!! Multipart data detected [sv_updempinfo]!!");
			// Create a factory for disk-based file items
			FileItemFactory factory = new DiskFileItemFactory();

			// Create a new file upload handler
			ServletFileUpload upload = new ServletFileUpload(factory);

			// Parse the request
			List /* FileItem */ items = upload.parseRequest(request);

			// Process the uploaded items
			Iterator iter = items.iterator();
			HashMap dataitem = new HashMap();
			while (iter.hasNext()) {
				FileItem item = (FileItem) iter.next();

				if (item.isFormField()) {
					String name = item.getFieldName();
					String value = item.getString();
					dataitem.put(name, value);
					System.out.print("!! Field name : "+ name + " value " + value);
				} else {
					System.out.print("!! File upload detected !!");
					dataitem.put("attchfile", item);
				}
			}

			/* save detail */
			
			long curtime = System.currentTimeMillis();

			if(dataitem.containsKey("data")){
				try {
					System.out.print((String) dataitem.get("data"));
					MsgPackage msgpack = new MsgPackage();
					recdata = msgpack.convStrToMsgPackage((String) dataitem.get("data"));

					/*set default (test used)*/
					//recdata.setDevNo("0000001");
					//recdata.setPassCode("ZBCDFGHJKIUYT");
					//recdata.setCompanyid("100");
					//recdata.setSerialNo("1236547890");
					/*******/
					
					SV_UpdInoutZone updinout = new SV_UpdInoutZone(recdata);
					updinout.run();
				}catch(Exception e){
					System.out.print(e.getMessage());
				}
			}

			if(dataitem.containsKey("attchfile")){
				// leave blank
			}
		}else{
			/* testing process will be sent in normal http get */
			MsgPackage msgpack = new MsgPackage();

			/*set default (test used)*/
			//recdata.setDevNo("0000001");
			//recdata.setPassCode("ZBCDFGHJKIUYT");
			//recdata.setCompanyid("100");
			//recdata.setSerialNo("1236547890");
			/*******/
					
			SV_UpdInoutZone updinout = new SV_UpdInoutZone(recdata);
			updinout.run();
		}
	}catch(Exception e){
		System.out.print(e.getMessage());
	}

	out.print(recdata.getPackage());		
		
%>



