<%@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.*" %>
<%@page import="com.google.gson.Gson" %>
<%@page import="com.google.gson.GsonBuilder" %>

<%
	MsgPackage recdata = new MsgPackage();

	try {
		System.out.print("!! Get munu page has been call !!");
		boolean isMultipart = ServletFileUpload.isMultipartContent(request);

		if(isMultipart){
			System.out.print("!! Multipart data detected [sv_getmenu]!!");
			// 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("input upd emp info --> " + (String) dataitem.get("data"));
					MsgPackage msgpack = new MsgPackage();
					recdata = msgpack.convStrToMsgPackage((String) dataitem.get("data"));
					
					SV_GetEmpMenu genmenu = new SV_GetEmpMenu(recdata);
					genmenu.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 */
			//String str = "{\"devno\":\"001\",\"passcode\":\"dddddddd\",\"companyid\":\"100\",\"comcode\":\"\",\"serialno\":\"SN000001\",\"authtype\":\"\",\"install\":false,\"logserv1\":\"\",\"logserv2\":\"\",\"datserv\":\"\",\"dev_loc\":\"\",\"dev_long\":\"\",\"dev_lat\":\"\",\"authen\":false,\"fpid\":0,\"empid\":\"0013\",\"positionid\":\"\",\"fpfilename\":\"\",\"servClock\":\"\",\"tasklist\":[],\"emplist\":[],\"timelist\":[],\"accinfolist\":[],\"empfp\":[],\"lang\":\"\",\"msg\":\"\",\"condition\":\"\",\"status\":\"0\",\"fptp\":null,\"taskcond\":null,\"chksum\":15569,\"chksumfp\":0,\"isValidPackage\":true,\"reqTimeAttdata\":{\"start_date\":\"\",\"end_date\":\"\",\"arrTimeAtt\":[],\"arrReason\":[],\"sendto_id\":\"\",\"sendto_name\":\"\",\"employeeid\":\"\",\"status\":false,\"msg\":\"\"},\"reqOT\":{\"arrOT\":[],\"sendto_id\":\"\",\"sendto_name\":\"\",\"employeeid\":\"\",\"status\":false,\"msg\":\"\"},\"reqLeave\":{\"lvtype\":null,\"lvdesc\":null,\"f_day\":false,\"f_halfday\":false,\"f_fhalf\":false,\"f_shalf\":false,\"f_hour\":false,\"lvreqstatus\":false,\"d_start_date\":null,\"d_end_date\":null,\"fs_start_date\":null,\"h_start_date\":null,\"h_start_time\":null,\"h_end_date\":null,\"h_end_time\":null,\"remark\":null,\"lmsg\":null,\"ltypeprop\":[],\"lsprop\":[],\"sendto_id\":\"\",\"sendto_name\":\"\",\"employeeid\":\"\",\"status\":false,\"msg\":\"\"}}";
			
			String str = "3MZQRXhf/45pyUkCezZ9GiIYMDtYzfkQgkxtAGYt7uc3tMaSTir6uzD1pChNEx3QvxJ1JYmInR2zHcNsCa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H2Ey9KDkc042CQSdBz5Kxo6x0SOwu3fBOWWxN5PBBLTsk8/sf271eTnHgF3F4eUotmtEpan4MbCavpZSvZxyrcOCP0dEdCGSiDaGv0Cx/0RW0OEV3y3e8mTsSPuJxgY//9UvBwOcM28hOQU+krp9F+hxbQW7n43/B3VpAscAvaRG1+Uqv6MFLNQDQqmIEuUav3ePNbuZi4EhsPyZkzQCZHdFqGjZumyD3BzhXJA1xE/UhvHEp32YAgwx+AgeeSHSvbRBCkjDaZo1KuNlGQo/c6a9Myw+N06VQXvrgbw78TTW5adxp7k+Kka2+8wJ/d/AzwylWVrP/FCxls3jCdI1kyPKI";
			MsgPackage msgpack = new MsgPackage();
			recdata = msgpack.convStrToMsgPackage(str);
					
			SV_GetEmpMenu genmenu = new SV_GetEmpMenu(recdata);
			genmenu.run();

			//out.print(msgpack.EncryptData(str));
		}
	}catch(Exception e){
		System.out.print("xxx"+e.getMessage());
	}

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


