<%@ include file="/includes.jsp"%>
<%@ taglib prefix="smvc" uri="http://www.springframework.org/tags/form"%>
	<script type="text/javascript">
		function submitForm(form, type){
			var exportProblem = document.getElementById("exportProblem");
			
			if(type == "LISTS"){
				form.exportList.value = true;
			}else{
				form.exportList.value = false;
			}
			form.submit();
			if (exportProblem)
				exportProblem.style.display = "none";
			return false;
		}
	</script>
	<br/>
	<br/>
	<sec:authorize access="hasRole('ADMIN')">
	<c:if test="${!empty exportProblem}" >
		<div id="exportProblem">
		<fieldset style="width: 380px" class="nobg" >
			<table align = "left">
				<tr><td>
					<span class="error" >
						<c:choose>
							<c:when test="${exportProblem == 'noFormsSelected'}">
								 Please select a form to export.
							</c:when>
							<c:when test="${exportProblem == 'noListToExport'}">
								There are no lists associated to the selected forms.
							</c:when>
						</c:choose>
					</span>
				</td></tr>
			</table>
		</fieldset>
		</div>
	</c:if>		
	<form action="exportFormDefinitions.form">
		<input type="hidden" name="<c:out value="${_csrf.parameterName}"/>" value="<c:out value="${_csrf.token}" />" />
		<fieldset style="width: 380px" class="nobg">
			<legend>Export Form Definitions</legend>
			<div class="diy-fieldset">
				<fieldset>
					<table width="100%">
						<tr>
							<td valign="top">Select form definitions to export
							</td>
						</tr>
						<tr>
							<td>
								<select name="formDefIds" multiple="multiple" size="10">
									<c:forEach var="group" items="${emdt.formDomain.children}">
										<optgroup label="<c:out value="${group.label }"/>">
											<c:forEach var="form" items="${group.children}">
												<option value="<c:out value="${form.id }" />"><c:out value="${form.label }"/></option>
											</c:forEach>
										</optgroup>
									</c:forEach>
								</select>
								<br/>(Tip: use the Ctrl key to select more than one item)
							</td>
						</tr>
					</table>
				</fieldset>
			</div>
			
		<input type="hidden" name="exportList" value="false" /> 
			<fieldset class="buttonFieldset">
			<table align="right" border="0" width="100%">
					<tr>
						<td align="left">							
							<div align="left">
								This will export the selected form definitions.
								</div>
						</td>
						<td align="right">
							<input type="submit" value="Export Forms..." onclick="return submitForm(this.form,'FORM');"/>
						</td>
					</tr>
				</table>
				
			</fieldset>
			<fieldset class="buttonFieldset">
				<table align="right" border="0" width="100%">
					<tr>
						<td align="left">							
							<div align="left">
								This will export the lists associated to the selected form definitions.
								</div>
						</td>
						<td align="right">
							<input type="button" value="Export Lists" onclick="return submitForm(this.form,'LISTS');"/>
						</td>
					</tr>
				</table>
				
			</fieldset>
			
		</fieldset>
	</form></sec:authorize>
