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

<%@page import="com.csc.library.utilities.*,com.csc.library.database.DataSet,java.util.*,com.csc.library.utilities.ThaiUtilities" %>
<%@page import="com.csc.library.database.CscConnection" %>
<%@page import="com.sun.org.apache.xerces.internal.impl.dv.util.Base64" %>
<%@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.google.gson.Gson" %>
<%@page import="com.google.gson.GsonBuilder" %>
<%@page import="com.google.gson.reflect.TypeToken" %>
<%@page import="com.csc.library.fputility.MsgPackage" %>
<%@page import="com.csc.library.session.*" %>
<%@page import="com.csc.library.fpprocess.SV_UpdTimeLog" %>

<%
	MsgPackage recdata = new MsgPackage();
		try {

			System.out.print("/**************************************/");
			System.out.print("Update time log page has been called from client");

			boolean isMultipart = ServletFileUpload.isMultipartContent(request);

			System.out.print("/****** is multipart context --> " + isMultipart );
			if(isMultipart){
				System.out.print("Multipart data detected -> ");
				FileItemFactory factory = new DiskFileItemFactory();

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

				// Parse the request
				List 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);
					}
				}

				/* send receive msg to servr */
				MsgPackage rtnmsg = new MsgPackage();
				rtnmsg.setComcode("0");
				if(dataitem.containsKey("data")){

					String rawtimedata = (String) dataitem.get("data");
					System.out.print(rawtimedata);
					recdata = rtnmsg.convStrToMsgPackage(rawtimedata);

					System.out.print("data receive ---> " + recdata);
					SV_UpdTimeLog updt = new SV_UpdTimeLog(recdata);
					updt.run();
				}
				
			}
		} catch(Exception e){
			e.printStackTrace();
		}

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


