<%@ include file="/includes.jsp"%>
<%@ taglib prefix="smvc" uri="http://www.springframework.org/tags/form"%>
    <br/>
    <br/>
    <sec:authorize access="hasRole('ADMIN')">
    <smvc:form action="importUsers.form?${_csrf.parameterName}=${_csrf.token}" method="post" enctype="multipart/form-data" onsubmit="return showPleaseWait1();">
        	<input type="hidden" name="redirectParams" value="<c:out value="${requestScope['javax.servlet.forward.query_string']}" />" />
        <table>
            <tr>
                <td class="error"><smvc:errors></smvc:errors></td>
            </tr>
        </table>
        <fieldset style="width: 500px" class="nobg">
            <legend>Import Users</legend>
            <fieldset>
                <table>
                    <tr>
                        <td>XML File</td>
                        <td><input type="file" id="document" name="document" title="Select an XML file containing eMDT Users" onchange="setFileSize(this);"/></td>
                    </tr>
                    
                    <tr>
                        <td>CSV File</td>
                        <td><input type="file" id="file"  name="file" title="Select an XML file containing eMDT Users" onchange="setFileSize(this);"/></td>
                    </tr>
                    
                </table>
            </fieldset>
            <fieldset class="buttonFieldset">
                <input type="submit" value="Start user import"/>
            </fieldset>
            <c:if test="${'true' eq isAuthenticationLdap}">
             <fieldset>
                <input type="button" onclick="location.href='importldapUsers.form'" value="Import users from Active Directory"/>
            </fieldset>
            </c:if>
            
        </fieldset>
        
        <br/>
        
        <fieldset style="width: 500px" class="nobg">
            <legend>Download CSV File Format</legend>
            <fieldset>
                <table>
                    <tr>
                        <td><a href="../admin/download/ImportUserFormat.csv" target="_blank">CSV Download Link</a> </td>
                        <td></td>
                    </tr>
                </table>
            </fieldset>
        </fieldset>
        
        <br/>
         
          <c:if test="${importResult != null}">
               <fieldset style="width: 500px" class="nobg">
	            	<legend>Import Results</legend>
	              <fieldset style="text-align: left;">
                    <span class="info">
                        <c:if test="${importResult.total == 1 }">There was 1 user in the import file</c:if>
                        <c:if test="${importResult.total != 1 }">There were <c:out value="${importResult.total}"/> users in the import file</c:if>
                        </span>
						<br/>

						Users imported: <c:out value="${importResult.succeeded}"/><br/>
	                     <ol>
		                    <c:forEach  var="msg" items="${importResult.usersImported}" varStatus="status">
				            	<li><c:out value="${msg}"/></li>
		                    </c:forEach>
	                     </ol>
						
	                    <c:if test="${not empty importResult.rolesAdded}">
	                    Roles added:
	                    <ol>
		                    <c:forEach  var="msg" items="${importResult.rolesAdded}" varStatus="status">
		                      <li><c:out value="${msg}"/></li>
		                    </c:forEach>
	                    </ol>
	                    </c:if>  
	                     <c:if test="${not empty importResult.supportingStaffNotAdded}">
	                     <span class="info">It was not possible to assign these supporting staff:</span>
	                     <ol>
		                    <c:forEach  var="msg" items="${importResult.supportingStaffNotAdded}" varStatus="status">
				            	<li><c:out value="${msg}"/></li>
		                    </c:forEach>
	                     </ol>
	                    </c:if>  


	                    <c:if test="${importResult.duplicates != null}">
                        	<c:if test="${importResult.duplicates > 0}">
                        		<span class="warning">Existing users not imported: <c:out value="${importResult.duplicates}"/></span>
                                Users not imported: <br/>
                        		<ol>
	                               <c:forEach var="duplicateName" items="${importResult.duplicateNames}" varStatus="duplicateNameStatus">
		                               	<li> <c:out value="${duplicateName}"/></li>
	                               </c:forEach>
                        		</ol>
	                        </c:if>
	                    </c:if>
                        <c:if test="${importResult.failed != null}">
	                       <c:if test="${importResult.failed > 0}">
		                       <span class="error">Imports which failed: <c:out value="${importResult.failed}"/></span>
		                       <br/>
		                       <ol>
	                             	<c:forEach var="failedReason" items="${importResult.failedReasons}" varStatus="failedReasonStatus">
	                              		<li><c:out value="${failedReason}"/></li>
	                             </c:forEach>
		                       </ol>
	                        </c:if>
	                     </c:if>
                    </div>
                       </fieldset>
        			  </fieldset>
                </c:if>
                
                <br/>
	


                
    </smvc:form></sec:authorize>
