<%-- 
    Document   : BulkFileUpload
    Created on : Sep 26, 2018, 4:48:59 PM
    Author     : 1004242
--%>


<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Bulk File Upload</title>
        <link rel="shortcut icon" href="${pageContext.request.contextPath}/img/favicon.ico" type="image/x-icon" />
        <link rel="stylesheet" type="text/css" href="/PacsApplication/css/TableCSSCode.css" />
        <link rel="stylesheet" type="text/css" href="/PacsApplication/css/styles.css?pacs=<%=((new java.util.Date()).getTime())%>"/>
        <link rel="stylesheet" type="text/css" href="/PacsApplication/css/ButtonAndText.css?pacs=<%=((new java.util.Date()).getTime())%>" />
        <link rel="stylesheet" type="text/css" href="/PacsApplication/css/info.css?pacs=<%=((new java.util.Date()).getTime())%>" />
        <script src="${pageContext.request.contextPath}/js/Calendar.js?pacs=<%=((new java.util.Date()).getTime())%>"></script>
        <script type="text/javascript" src="${pageContext.request.contextPath}/jquery-ui-1.10.4.custom/development-bundle/jquery-1.10.2.js?pacs=<%=((new java.util.Date()).getTime())%>"></script>
        <script type="text/javascript" src="/PacsApplication/chromejs/chrome.js?pacs=<%=((new java.util.Date()).getTime())%>"></script>
        <script type="text/javascript" src="/PacsApplication/js/iFrame_killer.js"></script>

    </head>
    <script>
        function sendFileToServer(temp)
        {
            if(temp==1){
                var fileName= document.getElementById("fileChooser").value
                var fileNameSplit=fileName.split('.');
                if(fileNameSplit[1]!="csv"){
                    alert("Please choose .csv file only.");
                    return;
                }
                else{
                    
                    var formUploadMultiPart = document.getElementById("BulkFileIdUpload");
                    formUploadMultiPart.action = '/PacsApplication/BulkFileUploadServlet';
                    formUploadMultiPart.submit();
                }
            }
            else if(temp==2)
            {
                var formDownloadNormal = document.getElementById("BulkFileIdDownload");
                formDownloadNormal.action = '/PacsApplication/BulkFileUploadServlet';
                formDownloadNormal.submit();
            }
            else if(temp==3)
            {
                if( BulkFileReport.fileId.value == ""  )
                {
                    alert("Please provide File Id.");
                    BulkFileReport.fileId.focus();
                    return false;
                }

                var formDownloadReport = document.getElementById("BulkFileReport");
                formDownloadReport.reportPath.value = "/Reports/Bulk_txn_report";
                formDownloadReport.reportName.value = "Bulk Transaction Report";
                formDownloadReport.DOWNLOAD.value = "P";
                formDownloadReport.action = '/PacsApplication/ExcelReportServlet';
                formDownloadReport.submit();
            }
            else if(temp==4){
                var fileName= document.getElementById("AccMapFile").value
                var fileNameSplit=fileName.split('.');
                if(fileNameSplit[1]!="prt"){
                    alert("Please choose .prt file only.");
                    return;
                }
                else{
                    //alert('inside temp 4');
                   // document.BulkAccMapUpload.submit();
                    //$('#actionMap').val('Map');
                    var formUploadMultiPartMap = document.getElementById("BulkAccMapUpload");
                    formUploadMultiPartMap.action = '/PacsApplication/BulkFileUploadServlet';
                    formUploadMultiPartMap.submit();
                }
            }
            else if(temp==5)
            {
                var formDownloadNormal = document.getElementById("ManualDownload");
                formDownloadNormal.action = '/PacsApplication/BulkFileUploadServlet';
                formDownloadNormal.submit();
            }
            else if(temp==6)
            {
                var formDownloadNormal = document.getElementById("CBSBulkManual");
                formDownloadNormal.action = '/PacsApplication/BulkFileUploadServlet';
                formDownloadNormal.submit();
            }
        }

        function toggleDiv(temp)
        {
            document.getElementById("errorMessageTag").innerHTML="";
            if(temp == 1 && document.getElementById("FileTypeId").value == 'Def'){
                alert("Please select an option first.");
            }
            else if (temp == 1 && document.getElementById("FileTypeId").value == 'Upload'){
                document.getElementById("UploadDiv").style.display='block';
                document.getElementById("SelectDiv").style.display='none';
            }
            else if(temp == 1 && document.getElementById("FileTypeId").value == 'Download'){
                document.getElementById("ReportDiv").style.display='block';
                document.getElementById("SelectDiv").style.display='none';
            } else if(temp == 1 && document.getElementById("FileTypeId").value == 'Map'){
                document.getElementById("UploadAccMap").style.display='block';
                document.getElementById("SelectDiv").style.display='none';
            }
            else if(temp==2 ){
                document.getElementById("ReportDiv").style.display='none';
                document.getElementById("SelectDiv").style.display='block';
            }
            else if(temp==3 ){
                document.getElementById("UploadDiv").style.display='none';
                document.getElementById("SelectDiv").style.display='block';
            } else if(temp==4 ){
                document.getElementById("UploadAccMap").style.display='none';
                document.getElementById("SelectDiv").style.display='block';
            }
            else if(temp==5 ){
                document.getElementById("ReportDiv").style.display='none';
                document.getElementById("SelectDiv").style.display='block';
            }
        }
        function popup_bulkFile(width, height, fileId) {
            if (window.innerWidth) {
                LeftPosition = (window.innerWidth - width) / 2;
                TopPosition = ((window.innerHeight - height) / 2) - 20;
            }
            else {
                LeftPosition = (parseInt(window.screen.width) - width) / 2;
                TopPosition = ((parseInt(window.screen.height) - height) / 2) - 20;
            }
            attr = 'resizable=yes,scrollbars=yes,width=' + width + ',height=' +
                height + ',screenX=300,screenY=200,left=' + LeftPosition + ',top=' +
                TopPosition + '';
            var screenName = "BulkFileUpload.jsp";
            var lovKey = "bulkReport";
            popWin = open('${pageContext.request.contextPath}/CommonSearchInfoLOVNew.jsp?fileId=' + fileId + '&screenName=' + screenName + '&lovKey=' + lovKey, 'bulkReport', attr);
            popWin.focus();

        }
        
        // to restrict back button
            history.pushState(null, null, location.href);
            window.addEventListener('popstate', function(event) {
                history.pushState(null, null, location.href);
            });
            
    </script>


               <%
             String error_msg = "";
             Object error = request.getAttribute("message");
             if (error != null) {
                 error_msg = error.toString();
             }
        %>

    <body>

        <jsp:include page="MenuHead_Deposit.jsp" flush="true" />
        <br>
        <fieldset style="border-color: black; background-image: url('/PacsApplication/img/download.jpg'); border-width: 3px">
            <legend style="padding: 8px; border-radius: 20px; background-color: #006600; color: white">Bulk File Upload</legend>
            <center>
                
                <div id="SelectDiv">
                    <%if (!error_msg.equalsIgnoreCase("")) {%>
                <center><div class="info" id="errorMessage"><center><%= error_msg%></center></div></center>
                <% }%>
                    <table>
                        <tr>
                            <td>Select Operation:</td>
                            <td>
                                <select id="FileTypeId" name="FileType" onchange="toggleDiv(1)">
                                    <option value="Def" selected> --Select-- </option>
                                    <option value="Upload" >Upload Bulk File</option>
                                    <option value="Download" >Generate Bulk File Process Report</option>
                                    <%--<option value="Map" >Bulk Account Mapping</option>--%>
                                </select>
                            </td>
                        </tr>
                    </table>
                </div>
            </center>
            <div id="UploadDiv" style="display:none">
                <form name="BulkFile" id="BulkFileIdUpload" action="" method="post" enctype="multipart/form-data">
                    <center>


                        Select file to upload:
                        <input type="file" name="dataFile" id="fileChooser"/><br/><font color="blue" >*Supported File type: csv</font><br/><br/>
                        <input type="button" value="Upload" id ="FileTypeIdUpload" name="FileType" onclick="sendFileToServer(1)"/>
                        <input type="button" value="Back" id ="BackIdU" name="BackIdUButton" onclick="toggleDiv(3)"/>



                    </center>
                </form>

                <form name="BulkFileSample" id="BulkFileIdDownload" action="" method="post" >
                    <input type="hidden" id="actionId" value="Download" name="actionTag">
                    <input type="button" value="Download Sample File" id ="FileTypeIdDownload" name="FileType" onclick="sendFileToServer(2)" style="float: right"/>
                </form>

                <form name="ManualFileSample" id="ManualDownload" action="" method="post" >
                    <input type="hidden" id="actionId" value="Manual" name="actionTag">
                    <input type="button" value="Download Manual File" id ="ManualDownload" name="FileType" onclick="sendFileToServer(5)" style="float: right"/>
                </form>
            </div>

            <div id="UploadAccMap" style="display:none">
                <form name="BulkAccMapUpload" id="BulkAccMapUpload" action="" method="post" enctype="multipart/form-data">
                    <center>


                        Select file to upload:
                        <input type="file" name="AccMapFile" id="AccMapFile"/><br/><font color="blue" >*Supported File type: csv</font><br/><br/>
                        <input type="button" value="Upload" id ="AccMapUpload" name="AccMapUpload" onclick="sendFileToServer(4)"/>
                        <input type="button" value="Back" id ="BackAccMap" name="BackAccMap" onclick="toggleDiv(4)"/>

                        <input type="hidden" id="actionMapId" value="Map" name="actionMap">

                    </center>
                </form>
                <form name="CBSBulkManual" id="CBSBulkManual" action="" method="post" >
                    <input type="hidden" id="actionId" value="CBSBULK" name="actionTag">
                    <input type="button" value="Download CBS Bulk Manual File" id ="CBSBulkManual" name="FileType" onclick="sendFileToServer(6)" style="float: right"/>
                </form>

            </div>

            <div id="ReportDiv" style="display:none">
                <form name="BulkFileReport" id="BulkFileReport" action="" method="post" >
                    <center>
                        <td>File Id<font color="red" >*</font>:</td>
                        <td><input type="text" name="fileId" id="fileId" style="text-align:right;" onkeypress='return event.charCode >= 48 && event.charCode <= 57' /></td>
                        <td><input type="button"  value="Search" onclick="javascript:popup_bulkFile(750, 250,document.BulkFileReport.fileId.value);"/></td>
                        <br><br>
                        <input type="button" value="Download Bulk Report" id ="ReportDownload" name="ReportType" onclick="sendFileToServer(3)" style="float: center"/>
                        <input type="button" value="Back" id ="BackIdU" name="BackIdUButton" onclick="toggleDiv(2)"/>

                        <input type="hidden" name="reportPath" value=""/>
                        <input type="hidden" name="reportName" value=""/>
                        <input type="hidden" name="DOWNLOAD" value=""/>
                    </center>
                </form>
                <br><br>
            </div>
            <div id="errorMessageTag"style="color: #FF0000;">${errorMessageBulk}</div>
        </fieldset>
    </body>
</html>
