<%
/******************************************************************************
 * Copyright (c) 2000-2005 e-Deal
 *
 * e-Deal S.A.
 * 55 rue Brillat Savarin
 * 75013 Paris
 * France
 *
 * T: +33 (0)1 53 80 80 30
 * F: +33 (0)1 73 01 69 77
 * http://www.e-deal.com
 * 
 * La diffusion de ce code source sous quelque forme que ce soit sans
 * l'autorisation de E-DEAL est interdite.
 *
 * Vous êtes autorisés à modifier ce code source uniquement pour votre usage
 * propre et sous réserve que les mentions de copyright demeurent intactes.
 *
 * Ce code est fourni en l'état. Aucune garantie d'aucune sorte, explicite ou
 * implicite n'est donnée. En aucun cas E-DEAL ne pourra être tenu pour
 * responsable des dommages pouvant résulter de l'utilisation de ce code
 * source.
 ******************************************************************************/
%><%@ page session="true" import="com.edeal.frontline.*,java.util.*,java.text.*"%>
<%@ taglib uri="http://www.e-deal.com/taglib/fl" prefix="fl" %>
<%@ page import="com.edeal.frontline.navigation.FlRequest" %>
<%@ page import="com.edeal.frontline.controller.actions.SelectAction" %>
<%@ page import="com.edeal.frontline.initializers.FormEventInitializer" %>
<%@ page import="com.edeal.frontline.helper.EventBaseHelper.EventCategory" %> 
<jsp:useBean class="com.edeal.frontline.FormBean" id="Form" scope="request"/>
<link href="<fl:webapp/>/css/common_css.jsp" rel="stylesheet" type="text/css">
<%
	final org.apache.commons.logging.Log logger = org.apache.commons.logging.LogFactory.getLog(getClass());
	FlRequest flRequest = new FlRequest(request);
	FlContext context = flRequest.getContext();
	DataDictionary dico = context.getDataDictionary();
	FlLocale locale =  FlLocale.getInstance(session);
	
	String id = null;
	try {
		id = Form.getID();
	} catch(FieldNotInitializedException fnie){
	}
	
	int seqNum = 0;
	try {
		seqNum = Form.getFrmSeqNum();
	} catch (FieldNotInitializedException fnie) {
		seqNum = CounterFactory.getCounter(context , "FormNum");		
	}
	
	DecimalFormat df = locale.getDecimalFormat("0000");
	
	
	
	String frmEventID = null;
	String evtLabel = "";
	String evtCode = "";
	String evtTitle = "";
	EventBean evt = null;

	String typeRefresh = flRequest.getRequestParameterOrAttribute("typeRefresh");
	
	
	try {
		frmEventID = Form.getFrmEventID();
	} catch(FieldNotInitializedException fnie){
	}
	
	if (frmEventID != null) {			 	
		try {
			evt = new EventBean(frmEventID, session);
		} catch(Exception e) {
		}
		
		try {
			evtLabel = evt.getEvtLabel();
		} catch (Exception e){
		}
		
		try {
			evtCode = evt.getEvtCode();
		} catch(Exception e){
		}
		
		evtTitle = evtLabel + " - " + evtCode;
	}	
	
	LinkedHashMap<String, String> listParticipationStatusIDAndDisplay = (LinkedHashMap<String, String>) flRequest.getAttribute(FormEventInitializer.LIST_PARTICIPATION_STATUS);
	if (listParticipationStatusIDAndDisplay == null) {
		listParticipationStatusIDAndDisplay = new LinkedHashMap<String, String>();
	}
	
	//Gestion du titre de la partie Evenement
	if (evtTitle.length() < " - ".length()+1){
		evtTitle = Utils.getMessage(session, "L305F", "Evénement");
	}

	String frmParStatus = null;
	try {
		frmParStatus = Form.getFrmParStatus();
	} catch (FieldNotInitializedException fnie) {
	}
	
	String message=null;
	try{
		message=(String)Form.getCustomProperty("FrmMsgMerci_");
	}catch (FieldNotInitializedException fnie) {
	}
		
%>
<script type="text/javascript" language="javascript">
	
	function doRefresh(){	
	
	var f = document.forms[0];
	
	doExitConf = false;
	var url = "<fl:link url="/refresh_form.fl"/>&typeRefresh=Refresh";
	f.typeRefresh.value = 'Refresh';
	f.action = url;
	
	var i;
		for (i = 0 ; i < f.Links.length ; i++) {
			f.LinksTexts.value += (i==0 ? "" : "|") + f.Links.options[i].text;
			f.LinksValues.value += (i==0 ? "" : "|") + f.Links.options[i].value;
		}

	f.submit();
	}
	
	function doSubmit() {
	var mf = document.forms[0];
	
		for (i = 0 ; i < mf.Links.length ; i++) {
			mf.LinksTexts.value += (i==0 ? "" : "|") + mf.Links.options[i].text;
			mf.LinksValues.value += (i==0 ? "" : "|") + mf.Links.options[i].value;
		}
		
		beforeSubmit();
		
		return true;
	}
	


</script>


<fl:form action="/save_form.fl" bean="Form">

<fl:bigTabs objectTitle="<%=Utils.getMessage(session, \"L63EE\", false, true, \"Questionnaire\")%>" ou="<%=\"/edit_form.fl\"+(id != null ? \"?id=\"+id : \"id\")%>">
	<div>
	<input type="hidden" name="typeRefresh" />
		<table class="container" cellpadding="0">
			<input type="hidden" name="typeRefresh" />
			<tr>
				<td colspan="3">
					<table class="container" cellpadding="0">
						<tr class="fieldline">
							<td class="labelTitreFiche">
								<fl:label field="FrmLabel" labelClassName="titreFiche"/>
							</td>
							<td class="fieldTitreFiche">
								<fl:input property="FrmLabel" mandatoryMsgCode="L63EF"/>
							</td>
						</tr>
					</table>
				</td>
			</tr>
			<tr><td colspan="3" class="ligne_separation"/></tr>
			<tr>
				<td class="column2">
					<table class="container" cellpadding="0">			
						<tr class="fieldline">
							<td class="dataLabel"><fl:getMessage code="F202D" alt="Numéro"/></td>
							<td class="dataValue"><input type="hidden" name="FrmSeqNum" value="<%= "" + seqNum %>"><%= df.format((long)seqNum) %></td>
						</tr>
						<fl:fieldEdit property="FrmTypID_" mandatoryMsgCode="" alt=""/>
						<fl:fieldEdit property="FrmLngID" />
						<%-- <fl:fieldEdit property="FrmCategory"/>
						<fl:fieldEdit property="FrmTabMode"/> --%>
					</table>
				</td>
				<td class="separation"><div class="separation"></div></td>
				<td class="column2">
					<table class="container" cellpadding="0">
						<fl:fieldEdit property="FrmStatus"/>				
						<fl:fieldEdit property="FrmAvailableFromDt"/>
						<fl:fieldEdit property="FrmAvailableToDt"/>
						<fl:fieldEdit property="FrmIsPublic"/>					
					</table>
				</td>
		</tr>		
		<tr><td colspan="3" class="ligne_separation"/></tr>
		</table>
<link href="<fl:webapp/>/css/smalltabs_css.jsp" rel="stylesheet" type="text/css">

<fl:smallTabs name="FormQuestDetails" >
	<fl:sTab id="formEvent" title="<%= Utils.getMessage(session, \"F2022\", false, true, \"Evénements\") %>">
		<table class="container" cellpadding="0">			
			<tr class="fieldline">
				<td class="column2">
					<table class="container" cellpadding="0">	
						<tr class="fieldline">
							<td class="dataLabel"><fl:getMessage code="F2022" alt="Evénements"/></td>
							<td class="dataValue">
								<input type="hidden" name="mandatory" value="lblFrmEventID">
								<input type="hidden" id="mandatory.lblFrmEventID" name="mandatory.lblFrmEventID" value="<fl:getMessage code="M60D9" alt="Veuillez spécifier un événement"/>">
								<input type="hidden" name="FrmEventID" value="<fl:getProperty name="Form" property="FrmEventID" alt="" edit="true"/>"/> 
								<input name="lblFrmEventID" type="text" onfocus="this.blur();" value="<%= evtLabel %>" readonly class="input text" />
								<a href="javascript:var win = window.open('<fl:webapp/>/select_event.fl?field=FrmEventID&formIndex=0&unattached=1&EvtID=<%= frmEventID %>', 'SelectEvent', 'menubar=no,status=no,toolbar=no,scrollbars=yes,resizable=yes,width=<%= SelectAction.SELECT_WINDOW_WIDTH %>,height=370')">
									<img src="<fl:webapp/>/icons/ico/rechercher.gif" align="top" border="0" width="17" height="17" alt="S&eacute;lectionner">
								</a>
								<a href="javascript: clearEvent();">
									<img src="<fl:webapp/>/icons/ico/supprimer.gif" align="top" border="0" width="17" height="17" alt="Vider le champ">
								</a>							
								<span id="lblFrmEventID_msg" class="mandatory_alert" style="display: none">!</span>
								<br><span class="comment"><fl:getMessage code="M6111" alt="Les événements déjà attachées à une questionnaire ne seront pas disponibles"/></span>
							</td>
						</tr>
					</table>
				</td>				
			</tr>			
			<tr>
				<td class="column2">
					<table class="container" cellpadding="0">																								
						<tr class="fieldline">
					  		<td class="dataLabel" id="FrmParStatus_label"><div><label title="Participation" for="FrmParStatus"><fl:getMessage code="L8186" alt="Participation"/></label></div></td>
							<td class="dataValue">
								<div>
									<select name="FrmParStatus" class="input select">
										<option value=""></option>
<%
									Iterator iter2 = listParticipationStatusIDAndDisplay.keySet().iterator();
									while (iter2.hasNext()) {
										String statusID = (String) iter2.next();
										String statusDisplay = (String) listParticipationStatusIDAndDisplay.get(statusID);
%> 
											<option value="<%= statusID %>" <%= statusID.equals(frmParStatus) ? "selected" : "" %>><%= Utils.formatToWeb(statusDisplay, true) %></option> 
<%
									}
%>										
									</select>
								</div>
							</td>
						</tr>								
					</table>
				</td>
				<td class="separation"><div class="separation"></div></td>
				<td class="column2">	
					<table class="data_column" cellpadding="0">													
						<fl:fieldEdit property="FrmParStatusRule"/>
					</table>	
				</td>							
			</tr>	
		</table>										
	</fl:sTab>
	<fl:sTab id="formQuest" title="<%= Utils.getMessage(session, \"L0038\", false, true, \"Question\") + \"/\" + Utils.getMessage(session, \"L613E\", false, true, \"Paragaraphe\")%>">
		<table class="container" cellpadding="0">
			<tr class="fieldline">
				<td class="">
					<table class="container" cellpadding="0">	
							<tr class="fieldline">
								<td class="dataValue">													
									<input type="hidden" name="LinksValues" >
									<input type="hidden" name="toEvalSelectLinks" value=""><input type="hidden" name="LinksKeys">
									<input type="hidden" name="LinksTexts" >
									<select id="Links" name="Links" size="12" onFocus="if (window.document.forms[0].toEvalSelectLinks.value != '') {eval(window.document.forms[0].toEvalSelectLinks.value); window.document.forms[0].toEvalSelectLinks.value = ''}" style="width: 100%">
									<%
										String linksValues = Utils.getRequestParameter(context, request, "LinksValues");
										String linksTexts = Utils.getRequestParameter(context, request, "LinksTexts");
										if (typeRefresh != null && "Refresh".equals(typeRefresh)) {
											Vector linksValuesVec = Utils.explodeList(linksValues , "|");
											Vector linksTextsVec = Utils.explodeList(linksTexts , "|");
											for (int i=0 ; i<linksValuesVec.size() ; i++) {
												String curVal = (String) linksValuesVec.elementAt(i);
												String curTxt = (String) linksTextsVec.elementAt(i);
									%>			
									<option value="<%= curVal %>"><%= curTxt %></option>
											<%}
											}else 
												if (id != null){
												String[][] query = {{"LfqFormID = " + Utils.formatToSQL(context, id)}};
												String[] fields = {"LfqID" , "LfqFormQuestionID" , "LfqFormQuestionID:FqtLabel", "LfqParagraph", "LfqPosition"};
												String[] orderBy = {"LfqPosition"};
												
												Vector linksList = LinkFormQuestionBean.listSummary(session , fields, query, orderBy);
													if (linksList != null && linksList.size() > 0) {
														for (int i = 0 ; i < linksList.size() ; i++) {
															Hashtable curLink = (Hashtable) linksList.elementAt(i);
															String curLfqFormQuestionID = (String) curLink.get("LfqFormQuestionID");
															String curLfqParagraph = (String) curLink.get("LfqParagraph");
															String fqtLabel = (String) curLink.get("LfqFormQuestionID:FqtLabel");
														%>			
															<option value="<%= curLfqFormQuestionID == null ? curLfqParagraph : curLfqFormQuestionID %>"><%= curLfqFormQuestionID == null ? Utils.getMessage(session, "L616E", "(P)") + " " + curLfqParagraph : Utils.getMessage(session, "L616F", "(Q)") + " " + fqtLabel %></option>
														<%
														}
													}
												}																	
											%>
											
									</select>
									
									</td>
									<td width="5px"></td>
									<td class="dataLabel">
										<input type="text" name="ParagraphText" style="margin-bottom: 5px; width: 80%;"><br>
										<fl:getMessage code="L613E" alt="Paragraphe"/>
										&nbsp;<a href="javascript:addParagraph()">
										<img src="<fl:webapp/>/icons/ico/creer.gif"></a><br><br>
										<fl:getMessage code="L606D" alt="Questions"/>
										<a href="javascript:var win = window.open('<fl:webapp/>/select_link.fl?type=FormQuestion&field=FqtID&formIndex=0', 'LinkSelect', 'menubar=no,status=no,toolbar=no,scrollbars=no,resizable=yes,width=760,height=380')">
											<img src="<fl:webapp/>/icons/ico/rechercher.gif" border="0" height="17" alt="S&eacute;lectionner">
										</a>
									</td>
								</tr>								
								<tr class="fieldline">
									<td class="dataValue" colspan="3">
										<a href="javascript:moveLineUp()"><img src="<fl:webapp/>/icons/ico/flecheH.gif"></a>
										<a href="javascript:removeLine()"><img src="<fl:webapp/>/icons/ico/supprimer.gif"></a>
										<a href="javascript:moveLineDown()"><img src="<fl:webapp/>/icons/ico/flecheB.gif"></a>
									</td>
								</tr>
							</table>
					</td>
				</tr>
		</table>
	</fl:sTab>
	<fl:sTab id="FormIntroConc" title="<%= Utils.getMessage(session, \"F619E\", \"Introduction\") + \"/\" + Utils.getMessage(session, \"F619D\", \"Conclusion\") %>">
	<table class="container" cellpadding="0">
			<tr>
				<td colspan="3">		
					<fl:fieldEdit name="Form" property="FrmWebIntro" alt="&nbsp;"/>
					<fl:fieldEdit name="Form" property="FrmWebConclusion" alt="&nbsp;"/>
					<fl:fieldEdit name="Form" property="FrmWebTermsOfUse" alt="&nbsp;"/>
					
					<fl:fieldEdit name="Form" property="FrmMsgMerci_" alt="&nbsp;"/>
					<!-- <input type="text" name="FrmMsgMerci_"/>
					<textarea name="FrmMsgMerci_"cols="30" rows="4"></textarea>
					<input type="submit" value="Enregistrer"> -->
					
				</td>						
			</tr>
		</table>
	</fl:sTab>
	<fl:sTab id="FormHeadFoot" title="<%= Utils.getMessage(session, \"F61A0\", \"En-tête\") + \"/\" + Utils.getMessage(session, \"F61A1\", \"Pied de page\") %>">
	<table class="container" cellpadding="0">
			<tr>
				<td colspan="3">		
					<fl:fieldEdit name="Form" property="FrmWebHeader" alt="&nbsp;"/>
					<fl:fieldEdit name="Form" property="FrmWebFooter" alt="&nbsp;" />
				</td>						
			</tr>
		</table>
	</fl:sTab>
	
	
	<fl:sTab id="FormDetails" title="<%= Utils.getMessage(session, \"F2024\", true, \"Notes\") %>">
		<fl:input property="FrmDetails" rows="6" width="100%"/>		
	</fl:sTab>	
		
</fl:smallTabs>				
	
	</div>
</fl:bigTabs>
</fl:form>