<%@page import="com.csc.library.utilities.MyLog"%>
<%@page import="java.util.StringTokenizer"%>
<%@page import="com.csc.upload.FileInfo"%>
<%@page import="java.util.Hashtable"%>
<%@page import="com.csc.library.session.InitialEnvironment"%>
<%@page import="com.csc.library.utilities.UProfile"%>
<%@page contentType="text/html; charset=UTF-8"%>
<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("export-dir");
  String folder = "APPRAISAL/NEW_APPRAISAL";
  String tempdir = filePath + "UPLOAD/" + folder + "/";
  String lang = upload.getUProfile().get("lang");

  request.setAttribute("dir", request.getParameter("dir"));
  String browser_name = request.getRequestURI();  
  String status = "";
  Hashtable ht = new Hashtable(); 
  String dir = "";
  String table = "";
  String xml = "";
  String fileFullPath = "";
  String fileName = "";
  String msg = "";
  
  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("upload");
      fileFullPath = f.file.toString();      
      
      StringTokenizer str = new StringTokenizer(fileFullPath, "\\");
      while (str.hasMoreTokens()) {
            fileName = str.nextToken();             
        }
      msg = "Upload completed";
      MyLog.debug(upload, upload.getUProfile(), "^^Nut Freedom^^==>> fileFullPath===" + fileFullPath);
  } catch (Exception e) { 
            e.printStackTrace();
            msg = "Incomplete upload";
  }
%>
<script>
    function getUrlParam(paramName) {
        var reParam = new RegExp('(?:[\?&]|&amp;)' + paramName + '=([^&]+)', 'i');
        var match = window.location.search.match(reParam);

        return (match && match.length > 1) ? match[1] : '';
    }
    var funcNum = getUrlParam('CKEditorFuncNum');


    window.parent.CKEDITOR.tools.callFunction(funcNum, '../UPLOAD/<%=folder%>/<%=fileName%>', '<%=msg%>');
</script>