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

<%
		MsgPackage rtnmsg = new MsgPackage();
		MsgPackage mypck = new MsgPackage();

		try {

			System.out.print("/**************************************/");
			System.out.print("get course page has been called from client");

			boolean isMultipart = ServletFileUpload.isMultipartContent(request);

			if(isMultipart){
				System.out.print("!! Multipart data detected !!");
				// 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();
				long curtime = System.currentTimeMillis();
				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 !!");
					}
				}

				/* send receive msg to servr */
				if(dataitem.containsKey("data")){

					String rawtimedata = (String) dataitem.get("data");
					//out.print(rawtimedata);
					mypck = rtnmsg.convStrToMsgPackage(rawtimedata);
					/* use mypck to save into db */

					SV_UpdCourseStatus svg = new SV_UpdCourseStatus(mypck);
					svg.run();
					System.out.print("--- get task return data ---");
					System.out.print("encrypted --> " + mypck.getPackage());
					
				}
			}else{
				String rawdata = "3MZQRXhf/47bqFSe7VivPy0YNAI6l8JStEguhmWomxcHmJx66jXnMXVXVelUSBgpc5HkcpY1856hRhwrgrvyEkXFRSaDIuDh65AinSYMtsgdp7/D/uKOI0uKgipvicVpPA4uPwYg0rIVM3oY6Ft0ELTkKXosOqR52iRReuy/EkNC/PlnX0pVf4BC3gqjFSiWz1LuMbeEUUFeq0/szw669mRp7svozSaH3OAJ8966bIyCrO+utwjKYEvHdxwl9/u3/+2DfNmC+b7/cfOvcV2NIiTUidcGoR8EezQzRxC5H6vwMscOCVibwrLb8EfXwBHT9iVWIh8dlhUxR6JWlecoXje6qtBl51HbBAN1yiGJJSE+P+g3Tal/v9oHTvpbjUfPvuZeFtPdgmFuKpOevUzMiWYLDDyxGilX6zq4r8N51Ww42SueacAxK4w6gG9szUAx8YDZyHt1XCpeyJII9ZcaRKBZriP35xsZSIb0UXY9LiR+4Y/ypD3NltWtnGftbsoevxgg10+Fz5CIOct4A2UjVo2CPn+LGH5oAzlN0gBS/TNiDFK/mbTUWgka45tEmG8VZjgxUNFIhHAdO20sbL9PqDONPgCFq8udAf0tP7Fy4Em2UnK/1mcGqtj8Q7a/FCv7oEBm770JKLIA/c1AifCfop14T6QzNRYFFHa3eE5FOH6gHo0L5HZ1gCFNbZnaOd7EQ7TDWDt8KVwdRMA3D3fjLZgU0hPM2hdfTOeceTIKaG4VhhvYApPFni7AZyu2OgTiVlBUiOqBDh1ufBbHsbriMnOShpAC3RwdtaXMo1h3xAaFwmXuoBCyhEbo21sV5QQ3cTJpafEoGBru2C5jO7i/mP+jBMqu9cj7hRMpSjd3QrZ+gsbdiANUE50qa1/xs9kimkwMyIuc2aVT2/J7Vp3/xOb5Pm9W3BK4pVQeLom1tmmdElI8urzlCW8GzANJHasTjcrAWDQSnf2wiKtlrWwItcQjLeYKfciv6W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+uHu6Y0QvQ80m1VImgqpBKnO4RyPBXdvJAPquPbhwn5MK8Oefh4kAG1f5Y9YIo1PpLHaUwAPxR76NHx2Djj9ggBpZC9zBdJF0ghxeKLC1mo7JsBuO45bwfpnM6X0RYlNnyhUrpl0HWT4PY3wjBkDZorFXOfqq7+YDFvLtamGCnY2XQ9ipcCQw39q0ISj7GZi8q76GuVvoRSyH2yX4yE9FcBUBNqZSJ7vyleKido9CIkH7pemG/vDCgm7UmQjB0SMxzMRiduHI8iJgpJpgplIToAMoQEM488SdVqOCjCIcpQgbOaH+sd6LIex1LaSCzPb3zsCA8btQzZa8TFmM9wM7xD5MVB35URX0j3AcDG2ykw8jFtXq6SZlaDgm6v57iRbe0nc+p9wEfrB5VclJw3wCZbWUO39aFwalYyLdWtCUze2p+KVqCrX+8X1tKjAgSIM1Mu9uWNe4arMv86eGpoadX0YZ4ABbttlSX+y67U5bxc5rTJXnJCfDGd0G7G3vO4EkJtW5MDu7HrLyzKBe8tMBRqEAj26ZtThYHijohBByYjeOmK7/VWWCRF25K9+azNxnW9WILuHImDyeSbOoY1rVJOlPSQeYOuoRoY/ZublRe5CHwnVwOBGmzfopFQ4G8h1AA4llIpW+uyMWnrM/C1G0Wt4+zKWkNKA8mlZWPMG6diEc0QFV4RkQMzjdZwRzyo72mistRLPCe9sluzBvE6kS3sDco1XPYRDVSBHX1FAD0iJI8RQ1YC4BzsQS/oiyjJex8Xw/Ux";

				mypck = rtnmsg.convStrToMsgPackage(rawdata);

				SV_UpdCourseStatus svg = new SV_UpdCourseStatus(mypck);
				svg.run();

				System.out.print("--- get task return data ---");
				System.out.print("encrypted --> " + mypck.getPackage());
			}
		} catch(Exception e){
			e.printStackTrace();
		}

		out.print(mypck.getPackage());
		//System.out.print("------- success ----" + mypck.getPackage());
%>


