<?xml version="1.0" encoding="UTF-8"?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.0">
    <jsp:directive.page contentType="text/html;charset=UTF-8"/>
    <jsp:directive.page import="edu.ucsb.nceas.metacat.clientview.ClientViewHelper"/>
    <jsp:directive.page import="edu.ucsb.nceas.metacat.clientview.ClientView"/>
    
    <jsp:declaration>
        private ClientViewHelper            clientViewHelper;
        private String                      message;
    </jsp:declaration>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
            <script type="text/javascript">
                function allowUploadSubmit(formObj) {
                    var     result = true;

                    if (isEmpty(formObj.elements["metaFileName"])) {
                        result = false;
                        alert("Metadata file name is required");
                    }
                    return(result);
                }
                
                function isEmpty(aTextField) {
                    var value = trim(aTextField.value);
                    var result = ((value.length == 0) || (value == null));
                    return(result);
                }

		function trim(stringToTrim) {
			return(stringToTrim.replace(/^\s+|\s+$/g,""));
		}
            </script>
            
            <jsp:scriptlet>
                clientViewHelper = ClientViewHelper.clientViewHelperInstance(request);
            </jsp:scriptlet>
            <link href="saeon.css" rel="stylesheet" type="text/css" />
        </head>    
        <body>
            <jsp:useBean id="clientViewBean" scope="session" class="edu.ucsb.nceas.metacat.clientview.ClientView"/>
            <jsp:setProperty name="clientViewBean" property="*"/>
            
            <h2>Data Package Upload</h2>
            
            <p class="regtext">
            	Spatial metadata files (FGDC-compliant) and associated shape or raster files can be uploaded to the repository.
            </p>
            
                <jsp:scriptlet>
                    message = clientViewHelper.clientRequest(request, response);
                    if (clientViewHelper.isLoggedIn()) {
                </jsp:scriptlet>
                
                <jsp:scriptlet>
					if ( message != null) {
				</jsp:scriptlet>
	                <p class="emphasis">
						<jsp:expression>
							message
						</jsp:expression>
					</p>
				 <jsp:scriptlet>
					}
				</jsp:scriptlet>	
	                
                <form name="uploadForm" method="post" action="./upload.jsp" enctype="multipart/form-data" onsubmit="return allowUploadSubmit(this)">
                    <input name="returnfield" type="hidden" value="distinfo/stdorder/digform/digtopt/onlinopt/computer/networka/networkr"/>
                    <input name="pathExpr" type="hidden" value="/metadata/distinfo/resdesc"/>
                    <input name="action" type="hidden" value="Upload"/>
                    
                    <!-- Set the pathValue to the username (the scope) -->
                    <jsp:element name="input">
                        <jsp:attribute name="name">pathValue</jsp:attribute>
                        <jsp:attribute name="type">hidden</jsp:attribute>
                        <jsp:attribute name="value"><jsp:getProperty name="clientViewBean" property="username"/></jsp:attribute>
                    </jsp:element>
                    
                    
                    <table>
                        <tr>
                            <td colspan="2">
                            	<h3>Metadata File <span class="regtext">(required)</span></h3>
                                <p class="regtext">Enter the Meta Data File (*.xml) 
                                    <input name="publicAccess" type="checkbox" checked=''/> Grant public read access
                                </p>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2" align="right">
                                <input name="metaFileName" accept="xml" type="file" size="60" value="" />
                            </td>
                        </tr>
                        <!-- Data fields -->
                        <tr>
                            <td colspan="2">
                                <h3>Supporting Data Files <span class="regtext">(optional)</span></h3>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                <p class="regtext">Enter Data File 1 (*.shp)</p>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2" align="right">
                                <input name="dataFileName" type="file" size="60" />
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                <p class="regtext">Enter Data File 2 (*.dbf)</p>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2" align="right">
                                <input name="dataFileName" type="file" size="60" />
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                <p class="regtext">Enter Data File 3 (*.sbx)</p>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2" align="right">
                                <input name="dataFileName" type="file" size="60" />
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                <p class="regtext">Enter Data File 4 (*.idx)</p>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2" align="right">
                                <input name="dataFileName" type="file" size="60" />
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                <p class="regtext">Enter Data File 5 (*.XXX)</p>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2" align="right">
                                <input name="dataFileName" type="file" size="60" />
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2" align="center">
                                <br/>
                            </td>
                        </tr>
                        <tr>
                            <td align="left">
                                <span class="regtext">
                                	<jsp:expression>
                                	clientViewBean.getMessage(ClientView.UPLOAD_MESSAGE)
                                	</jsp:expression>
                                </span>
                            </td>
                            <td align="right">
                                <input name="submit" value="Upload" type="submit" class="button_login"/>
                            </td>
                        </tr>
                    </table>
                </form>
                
                <jsp:scriptlet>
                    } else {
                </jsp:scriptlet>
                
                <p class="emphasis">
                    You must be logged into your user account before uploading a data set.
                </p>
                
                <jsp:scriptlet>
                    }
                </jsp:scriptlet>
                
                <p class="regtext">
                    <form action="./index.jsp" method="post">
                        <input type="submit" class="button_login" value=" &lt; Back"/>
                    </form>
                </p>
        </body>
    </html>
</jsp:root>
