<%
/******************************************************************************
 * Copyright (c) 2000-2004 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.
 *
 * CVS Info for $RCSfile$
 *
 * $Revision$
 * $Author$                  $Date$
 ******************************************************************************/
%>
<%@page session="true" import="com.edeal.frontline.*,java.util.*,com.edeal.frontline.navigation.*"%>
<%@taglib uri="http://www.e-deal.com/taglib/fl" prefix="fl" %>

<%
	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();
	
	
	String cat1 = flRequest.getRequestParameterOrAttribute("cat1");

	FAQHeaderBean obj = (FAQHeaderBean)request.getAttribute("FAQHeader");
	try {
		obj.getFahCreID();
	} catch (FieldNotInitializedException ex) {
		obj.setFahCreID((String)session.getAttribute("actorID"));
	}
	
	try{
		obj.getFahActID();
	}catch(FieldNotInitializedException fnie){
		obj.setFahActID((String)session.getAttribute("actorID"));
	}
	

	String fahID = null;
	try {
		fahID = obj.getID();
	} catch (FieldNotInitializedException ex) {
		fahID = flRequest.getRequestParameterOrAttribute("id");
	}

	Hashtable FAQList = new Hashtable();

		// FAQ déjà rattaché au header
	try {
	String[][] query = {{"FaqFahID = " + Utils.formatToSQL(context, obj.getID())}};
	Vector vectFAQList = FAQBean.list(context, query);
	for(int i = 0; i < vectFAQList.size(); i++) {
		FAQBean faq = (FAQBean)vectFAQList.elementAt(i);
		try {
			FAQList.put(faq.getFaqLngID(), faq);
		} catch (FieldNotInitializedException ex) {
		}
	}
	} catch (FieldNotInitializedException ex) {
	
	}
	
	// A mettre dans un initialiseur
	SolicitationBean solBean = null;
	String solID = Utils.getRequestParameter(context, request, "SolID");
	String cat =null;
	if(solID != null) {
		try {
			solBean = new SolicitationBean(solID, session);
			String catSol = solBean.getSolCatID();
			if (catSol!= null) cat = (String) dico.getRefDisp(session, "SolCatID",catSol);
			if (cat != null) obj.setFahCatLev1(cat);
		} catch (Exception ex) {
		}
	}
%>

<title><fl:getMessage code="L2025" alt="E-DEAL"/></title>

<link href="<fl:webapp/>/css/smalltabs_css.jsp" rel="stylesheet" type="text/css">
<script language="JavaScript">
var submitFlag = false;
function doSubmit() {
	var f = document.forms[0];
	if (f.FahCatLev1.value =='') {
		if (f.FahCatLev2.value =='') {
			if (f.FahCatLev3.value =='') {
				return false;
			}else {
				return false;
			}
		}else {
			return false;
		}
	} else {
		if (f.FahCatLev2.value =='') {
			if (f.FahCatLev3.value =='') {
				if(!submitFlag) {
					presentFieldsValue();
					return true;
				}
			}else {
			 	window.alert("<fl:getMessage code="M6005" alt="Veuillez choisir categorie 2" js="true"/>");
				return false;
			}
		}else {
				presentFieldsValue();
				return true;
			//}
		}
	}
}



function doSearchCat(field) {
	var win = window.open('<fl:webapp/>/select_faq_cat.fl?field='+field, 'SelectCat', 'menubar=no,status=no,toolbar=no,scrollbars=yes,resizable=yes,width=450,height=450');
}

function delCat(field){
	document.getElementById(field).value='';
}

</script>

<body>
<fl:bigTabs objectTitle="<%=Utils.getMessage(session, \"L1055\", false, true, \"FAQ\")%>" ou="<%=\"edit_faqheader.fl\"+(fahID!=null ? \"?id=\"+fahID :\"\")%>">

<form method="post" action="<%=flRequest.computeURL("/save_faqheader.fl")%>">
		<input name="id" type="hidden" value="<fl:getProperty name="FAQHeader" property="FahID" alt=""/>">
		<input name="$$presentFields" type="hidden" value="">		
		<input name="FahActID" type="hidden" value="<fl:getProperty name="FAQHeader" property="FahActID" alt=""/>">

<table class="container" cellpadding="0">
	<tr class="fieldline">
		<td class="labelTitreFiche"><fl:label field="FahCatLev1" labelClassName="titreFiche"/></td>
		<td class="fieldTitreFiche">
			<fl:input property="FahCatLev1" mandatoryMsgCode="M1012" />			
		</td>
		<td class="dataLabel">
			&nbsp;
			<a href="javascript:doSearchCat('FahCatLev1')"><img src="<fl:webapp/>/icons/ico/rechercher.gif" alt="<fl:getMessage code="A3053" alt="Choisir une catégorie"/>" align="middle"></a>
			<a href="javascript:delCat('FahCatLev1');"><img src="<fl:webapp/>/icons/ico/supprimer.gif" alt="" align="middle"></a>
		</td>
	</tr>
	<tr class="ligne_separation"><td colspan="3">&nbsp;</td></tr>
</table>

<table class="container" cellpadding="0">	
	<tr class="fieldline">
		<td class="column2">		
			<table class="container" cellpadding="0">
				<tr class="fieldline">
					<td class="dataLabel"><fl:label field="FahCatLev2"/></td>
					<td class="dataValue noPaddingLeft">
						<fl:input property="FahCatLev2"/>					
					</td>
					<td class="dataLabel">
					&nbsp;
						<a href="javascript:doSearchCat('FahCatLev2')"><img src="<fl:webapp/>/icons/ico/rechercher.gif" alt="<fl:getMessage code="A3053" alt="Choisir une catégorie"/>" align="middle"></a>
						<a href="javascript:delCat('FahCatLev2');"><img src="<fl:webapp/>/icons/ico/supprimer.gif" alt="" align="middle"></a>
					</td>
				</tr>
				<tr class="fieldline">
					<td class="dataLabel"><fl:label field="FahCatLev3"/></td>
					<td class="dataValue noPaddingLeft">
						<fl:input property="FahCatLev3"/>
					</td>
					<td class="dataLabel">
					&nbsp;
						<a href="javascript:doSearchCat('FahCatLev3')"><img src="<fl:webapp/>/icons/ico/rechercher.gif" alt="<fl:getMessage code="A3053" alt="Choisir une catégorie"/>" align="middle"></a>
						<a href="javascript:delCat('FahCatLev3');"><img src="<fl:webapp/>/icons/ico/supprimer.gif" alt="" align="middle"></a>
					</td>
				</tr>				
			</table>
		</td>
		<td class="separation"><div class="separation"></div></td>
		<td class="column2">
			<table class="container">
				<fl:fieldRead property="FahActID" bean="true" href="true" disp="<%=flRequest.computeURL(\"/read_actor.fl\", false, false, true)%>"/>			
				<tr class="fieldline">
					<td class="dataLabel"><fl:label field="FahKeyID"/></td>
					<td class="dataValue noPaddingLeft">
						<table class="container" cellpadding="0">												
						<%
							Vector vectChecked = null;
							try {
								vectChecked = obj.getFahKeyID();
							} catch (FieldNotInitializedException ex) {
								vectChecked = new Vector();
							}
							Vector vectRefList = dico.getRefList(session, "FahKeyID");
							for(int i = 0; i < vectRefList.size(); i++) {
								Vector vectRef = (Vector)vectRefList.elementAt(i);
								String refID = (String)vectRef.elementAt(0);
								String refDisp = (String)vectRef.elementAt(1);
								if((i % 2) == 0) { 
						%>
							<tr>
						<%
						} 
						%>
								<td class="dataValue"><input name="FahKeyID" type="checkbox" value="<%= refID %>"<%= vectChecked.contains(refID) ? " checked" : "" %>><%= Utils.formatToWeb(refDisp, false) %></td>
						<%
								if((i % 2) == 1) { 
						%>
							</tr>
						<%
								}
							}
							if(vectRefList.size() > 0 && (vectRefList.size() % 2) != 0) { 
						%>
							</tr>
						<%
						} 
						%>
						</table>
					</td>
				</tr>
			</table>
		</td>
	</tr>	
	<tr class="ligne_separation"><td colspan="3">&nbsp;</td></tr>
</table>

<fl:smallTabs name="faqQR">
<%
	Vector vectLngList = dico.getRefList(session, "FaqLngID");
	FAQBean curFaq = null;
	String curFaqID = null;
	String curFaqQuestion = null;
	String curFaqResponse = null;	
		
	for(int i = 0; i < vectLngList.size(); i++) {
	
		Vector vectLng = (Vector)vectLngList.elementAt(i);
		String lngID = (String)vectLng.elementAt(0);
		String lngDisp = (String)vectLng.elementAt(1);
		if(FAQList.get(lngID) != null) {
			curFaq = (FAQBean) FAQList.get(lngID);
			
			try{
				curFaqID = curFaq.getID();
			}catch(Exception e){
				curFaqID="";
			}
						
			try{
				curFaqQuestion = curFaq.getFaqQuestion();
			}catch(Exception e){
				curFaqQuestion="";	
			}			
			
			try{
				curFaqResponse = curFaq.getFaqResponse();
			}catch(Exception e){
				curFaqResponse = "";
			}
						
		}else{
			 curFaqID = "";
			 curFaqQuestion = "";
			 curFaqResponse = "";
		}		
		
		
%>
	<fl:sTab id="<%=\"STFaq\"+lngDisp%>" title="<%=lngDisp%>">
		<div>
			<input type="hidden" name="<%="FaqID"+lngID%>" value="<%=curFaqID%>">
			<table class="container" cellpadding="0">			
				<tr class="fieldline">
					<td class="titreInterneSmalltabs"><fl:getMessage code="L606D" alt="Questions"/></td>
				</tr>
				<tr>	
					<td class="dataValue noPaddingLeft">
						<textarea rows="5" cols="100" style="width: 100%" name="<%="FaqQ"+lngID%>"><%=curFaqQuestion%></textarea>
					</td>
				</tr>
				<tr class="ligne_separation"><td></td></tr>
				<tr class="ligne_separation_couleur"><td></td></tr>
				<tr class="ligne_separation"><td></td></tr>
				<tr>
					<td class="titreInterneSmalltabs"><fl:getMessage code="L641B" alt="Réponse"/></td>
				</tr>			
				<tr>							
					<td class="dataValue noPaddingLeft">
						<textarea rows="5" cols="100" style="width: 100%" name="<%="FaqR"+lngID%>"><%=curFaqResponse%></textarea>
					</td>
				</tr>
			</table>
		</div>
	</fl:sTab>

<%	} %>


</fl:smallTabs>
</form>

</fl:bigTabs>
</body>
<%
/******************************************************************************
 * 
 *
 * m.ichahane@e-deal.ma : 2006/08/25 20:00:10 : Mustapha
 * 
 *
 *****************************************************************************/
 %>
