<%
/******************************************************************************
 * 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.FlRequest"%>
<%@ page import="com.edeal.frontline.Utils" %>
<%@ page import="java.util.Hashtable" %>
<%@ page import="java.util.Map" %>
<%@ page import="com.edeal.frontline.navigation.WebUtils" %>
<%@taglib uri="http://www.e-deal.com/taglib/fl" prefix="fl"%>

<%@page import="com.edeal.frontline.navigation.EdealBigTabsNavigation"%>
<%@page import="com.edeal.frontline.navigation.EdealBigTabsNavigation.BigTabsParams"%>
<%@ page import="com.edeal.frontline.ListBean" %>
<%@ page import="com.edeal.frontline.ListBean.SearchZone" %>
<%@ page import="com.edeal.frontline.helper.custom.ListHelper" %>
<%@page import="org.apache.commons.lang.StringUtils"%>
<jsp:useBean id="List" class="com.edeal.frontline.ListBean" scope="request"/>
<%

      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 lc = flRequest.getRequestParameterOrAttribute("lc");
      if (lc == null) {
            lc = flRequest.getRequestParameterOrAttribute("code");
      }
      if (lc == null) {
            lc = "FAQ";
      }
      request.setAttribute("lc", lc);
      String lu = flRequest.getRequestParameterOrAttribute("lu");
      if (lu==null){
            lu ="/list_faqheader.fl?gridName=FAQ";
      }

      String cu = flRequest.getRequestParameterOrAttribute("cu");
      if (cu==null){
            cu ="/list_faqheader_criteria.fl";
      }
      String objTitle = Utils.getMessage(session, "L1055", false, true, "FAQ") ;
      request.setAttribute("obj.title", objTitle);
      String listTitle =  Utils.getMessage(session, "L104F", false, true, "Liste des FAQ");
      request.setAttribute("list.title", listTitle);
      String criteriaTitle =  Utils.getMessage(session, "F6139", false, true, "Liste des FAQ");
      request.setAttribute("criteria.title", criteriaTitle);     

     // search criteria
      String sc = (String)request.getAttribute("sc");
      request.removeAttribute("sc");

      // object uri
     String ou = flRequest.getRequestParameterOrAttribute("ou");

      // id
      Map searchCriteria = new Hashtable();
      if (sc != null) {
            searchCriteria = WebUtils.parseQueryString(sc);
      }
      request.setAttribute("selectedTab", "0");

      String param = flRequest.getRequestParameterOrAttribute("param");
      String paramLngID = flRequest.getSearchCriteria("LngID");
      if ("".equals(paramLngID) || paramLngID == null)
      paramLngID = dico.getRefIdByCode("FaqLngID","FR");
      String paramQuery = flRequest.getSearchCriteria("query");
      String paramCat1 = flRequest.getSearchCriteria("paramCat1");
      String paramCat2 = flRequest.getSearchCriteria("paramCat2");
      String paramCat3 = flRequest.getSearchCriteria("paramCat3");
      String strKeyID = flRequest.getSearchCriteria("KeyID");
      Vector vectKeyID = Utils.explodeList(strKeyID, ";");
      if (vectKeyID==null) vectKeyID = new Vector();
      Vector lngList = dico.getRefList(session,"FaqLngID");
      String nb = flRequest.getSearchCriteria("$$nb");
      String strQuery = "select distinct FahCatLev1 from FAQHeader where not(FahCatLev1 is null) order by FahCatLev1";
      String fields[] = new String[] {"FahCatLev1"};
      Vector listCatNiv1 = null;

      try{
            listCatNiv1 = FAQBean.listSQL(context, fields, strQuery);
      }catch(Exception e){
            listCatNiv1 = new Vector();
     }
  	String SfwID = flRequest.getRequestParameterOrAttribute("SfwID");
	String au = flRequest.getRequestParameterOrAttribute("au");
    //from common/list_criteria.jsp
  	EdealBigTabsNavigation ebtn = new EdealBigTabsNavigation(request);

  	Vector pagination = (Vector)flRequest.getAttribute("Pagination");
  	boolean hasPagination = pagination != null ? pagination.size() > 1 : false;
  	ListBean.SearchZone searchZone = null;
  	ListBean.ResultZone resultZone=null;
  	try {
  		searchZone = List.getSearchZone();
  		resultZone = List.getResultZone();
  	} catch (Exception e) {
  	}
  	String includedListScript=null;
  	if (resultZone!=null) {
  		includedListScript=ListHelper.processXmlListScriptExtension(context, session, resultZone.getScript());
  	}

  	// Is this our first time in here? (ie, we're not navigating back from an object)
  	boolean isFirstTimeIn = !ebtn.isDoList(); 

  	String gridName=Utils.formatToWeb(lc, true);

  	EdealBigTabsNavigation bTabNav = new EdealBigTabsNavigation(request);	
  	bTabNav.setBigTabsParameterValue(BigTabsParams.NameSearchGridJs, "_grid__" + gridName + "_js_");

  	String pageIndex=flRequest.getSearchCriteria("$$idx",gridName,false);
  	pageIndex=StringUtils.isEmpty(pageIndex)?"0":pageIndex;

  	String pagePagination=flRequest.getSearchCriteria("$$nb",gridName,false);
  	pagePagination=StringUtils.isEmpty(pagePagination)?(String)pagination.firstElement():pagePagination;
  	//End common/list_criteria.jsp
  	
%>
<script language="javascript">
	<%= (includedListScript==null)?"":includedListScript %>
	<%@include file="/common/list/list_criteria_js.jsp"%>
	var mandatoryGroups = <%=searchZone.getMandatoryGroupsAsJson()%>;
</script>

<style type="text/css"> 

.objectPosition{
horizontal-align: middle;
margin-left: 87px; 
margin-bottom:20px;
vertical-align: top;
text-align: left;
overflow: hidden;
height: auto;
}

</style>

<script language="javascript">
function doSubmit(){
	strURL = _grid__FAQ_js_.getAjaxUrl();
	params={};
	params["selectedTab"]="1";
      var f = document.forms[0];
      var queryString = "";
      f.sc.value = 'LngID='+f.LngID.value;
	  params["LngID"]=f.LngID.value;
      var keys = "";
      for(var i=0; i<f.KeyID.length; i++){
            if (f.KeyID[i].checked){
                  keys += f.KeyID[i].value;
                  if (i < (f.KeyID.length-1)) keys += ';';      
            }
      }

      if (keys != '') params["KeyID"]=keys;

      if (f.query.value != '') params["query"]=f.query.value;

      if (f.paramCat1.value != ''){
            params["paramCat1"]=f.paramCat1.value;
            if (f.paramCat2 && f.paramCat2.value != ''){
                 params["paramCat2"]=f.paramCat2.value;

                  if (f.paramCat3 && f.paramCat3.value != ''){
                        params["paramCat3"]=f.paramCat3.value;
                  }     

            }

      }     

      var nbFaq = f.$$nb.options[f.$$nb.selectedIndex].value;
   	  _grid__FAQ_js_.callAjaxForHtml(strURL,params,false);    
}


function doCat1Change(){
      var f = document.forms[0];
      if(f.paramCat2 != null)
            f.paramCat2.outerText = '';  
      if(f.paramCat3 != null)
            f.paramCat3.outerText = '';  

      if (f.paramCat1.value!=''){
            document.getElementById('cat2').style.visibility = 'visible';
            var url = '<fl:webapp/>/faqheader_categorie_ajax.fl?paramCat1='+f.paramCat1.value;    
            doAjax(url);

      } else {
            if (f.paramCat2){
                  f.paramCat2.style.visibility = 'hidden';
                  f.paramCat2.value='';
            }

            if (f.paramCat3){
                  f.paramCat3.style.visibility = 'hidden';
                  f.paramCat3.value='';
            }
      }

}

function doCat2Change(){
      var f = document.forms[0];
      if (f.paramCat2.value != '') {
            document.getElementById('cat3').style.visibility = 'visible';
            var url = '<fl:webapp/>/faqheader_categorie_ajax.fl?paramCat1='+f.paramCat1.value+'&paramCat2='+f.paramCat2.value;
            doAjax(url);
      } else {
            f.paramCat3.style.visibility = 'hidden';
            f.paramCat3.value='';
      }
}

function loadFAQ() {
      var f = document.forms[0];
      if (f.paramCat1.value == '') {
            document.getElementById('cat2').style.visibility = 'hidden';
      }

      if (f.paramCat2.value == '') {
            document.getElementById('cat3').style.visibility = 'hidden';
      }
}

 
</script>

<div class="BigTab">
	<%@include file="/common/tabs.jsp" %>
	<div class="BTBody BTBodyL">
		<div class="BTBody BTBodyR">
			<div id="criteriaTableRow"<%= (isFirstTimeIn ? "" : "") %>>
<form action="<fl:webapp/>/list_faqheader.fl" method="get" onsubmit="return doSubmit();">
<input name="$$presentFields" type="hidden" value="">
<input type="hidden" name="lc" value="<%= Utils.formatToWeb(lc, true) %>">
<input type="hidden" name="sc" value="">
<input type="hidden" name="ou" value="<%= Utils.formatToWeb(ou, true) %>">
<input type="hidden" name="cu" value="/list_faqheader_criteria.fl">
<input type="hidden" name="lu" value="/list_faqheader.fl">
<input type="hidden" name="obj.title" value="<%= Utils.getMessage(session, "L1055", false, true, "FAQ") %>">

<table class="container" cellpadding="0">
      <tr>
            <td>
                  <div class="criteriaTableDiv">
                  <table class="container" cellpadding="0">
                        <tr class="fieldline"><td>
                        <div>
                        <table class="container" cellpadding="0">
                             <tr class="fieldline">
                                    <div class="dataLabel" style="margin-bottom:-10px;">
                                    <fl:getMessage code="L0038" alt="Question"/>
                                    </div>
									<div style="margin-left: 85px">
                                         <textarea rows="4" style="width:99%;overflow:auto" name="query"><%=(paramQuery!=null ? paramQuery : "")%></textarea>
                                   </div>
                             </tr>
                        </table>
                        </div>
                        </td></tr>
                        <tr class="fieldline"><td>
                        <table cellpadding="0" class="container">
                             <tr class="fieldline">
                                   <td width="14%">
                                        <fl:label field="FahKeyID"/>
                                   </td>
                                   <td class="dataValue noPaddingLeft">
                                         <table class="container" cellpadding="0">
                                         <%    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 % 4) == 0) { 
                                               %>
                                                     <tr class="fieldline">
                                               <%}%>
                                                     <td class="dataLabel" style="margin-bottom:-10px;" nowrap="nowrap">
                                                     	   <input id="<%= "KeyID" + i %>" name="<%= "KeyID"%>" type="checkbox" value="<%= refID %>"<%= vectKeyID.contains(refID) ? " checked" : "" %>>
                                                           <label for="<%= "KeyID" + i %>"><%= Utils.formatToWeb(refDisp, false) %></label>                                                                      	   
                                                     </td>
                                               <%if((i % 4) == 3) { %>
                                               </tr>
                                         <%}
                                         }
                                         %>    
                                         </table>
                                   </td>
                                   <td width="40%">&nbsp;</td>              
                        </table>
                        </td></tr>
                        <tr class="fieldline"><td>
                        <div>
                        <table>
                             <tr class="fieldline">
                             
                                   <div class="dataLabel" style="margin-bottom:-10px;">
                                         <fl:getMessage code="F303F" alt="Langue"/>
                                   </div>
                                   <div class="objectPosition" >
                                         <select name="LngID">                                                                                                            
                                               <%for(int i=0; i<lngList.size(); i++){
                                                     Vector vectRef = (Vector)lngList.elementAt(i);
                                                     String refID = (String)vectRef.elementAt(0);
                                                     String refDisp = (String)vectRef.elementAt(1);
                                               %>
                                                     <option value="<%=refID%>" <%= paramLngID.equals(refID) ? "selected" : "" %> ><%=refDisp%></option>                    
                                               <%}%>                                                
                                         </select>
                                   </div>                                   
                             </tr>
                        </table>
                        </div>
                  </td></tr>
                  <tr class="fieldline"><td>
                        <table class="container" cellpadding="0">
                             <tr class="fieldline">
                                   <div style="margin-bottom:-10px;" class="dataLabel">
                                   
                                         <fl:getMessage code="F2029" alt="Catégorie"/>
                                   </div>
                                   <div class="objectPosition">
                                         <select name="paramCat1" onchange="doCat1Change()">
                                               <option value="" <%=(paramCat1==null ? "selected" : "")%>></option>
                                               <%
                                               for (int i=0; i<listCatNiv1.size(); i++){
                                                     Hashtable row = (Hashtable) listCatNiv1.get(i);
                                                     String val = (String) row.get("FahCatLev1");
                                               %>
                                               <option value="<%=val%>" <%=val != null && val.equals(paramCat1) ? "selected" : ""%>><%=val%></option>
                                               <%
                                               }
                                               %>
                                         </select>
                                         </div>
                                   </td>
                                   <td class="dataValue" style="width: 20%">
                                         <span id="cat2" <%= (paramCat2 == null ? "style=\"visibility: hidden;\"" : "") %>>
                                               <select name="paramCat2" id="paramCat2">
                                                     <option value="<%= (paramCat2 == null ? "" : paramCat2) %>"><%= (paramCat2 == null ? "" : paramCat2) %></option>
                                               </select>
                                         </span>
                                   </td>
                                   <td class="dataValue" style="width: 20%">
                                         <span id="cat3" <%= (paramCat3 == null ? "style=\"visibility: hidden;\"" : "") %>>
                                               <select name="paramCat3" id="paramCat3">
                                                     <option value="<%= (paramCat3 == null ? "" : paramCat3) %>"><%= (paramCat3 == null ? "" : paramCat3) %></option>
                                               </select>
                                         </span>
                                   </td>
                                   <td style="width: 40%">
                                         &nbsp;
                                   </td>
                             </tr>
                        </table>                
                  </td></tr>
                  </table>
                  </div>
            <td>
            <td class="separation"><div class="separation"></div></td>
        <td valign="top" style="width: 15%;">
            <table class="container" cellpadding="0">
                        <tr>
                             <td colspan="2" style="text-align: left;">
                                   <select name="$$nb" class="criteriaField pagination auto">
                                         <option value="10" <%= nb == null || "10".equals(nb) ? "selected" : "" %> >10&nbsp;/&nbsp;<fl:getMessage code="M60CC" alt="page" /></option>
                                         <option value="20" <%= "20".equals(nb) ? "selected" : "" %> >20&nbsp;/&nbsp;<fl:getMessage code="M60CC" alt="page" /></option>
                                         <option value="50" <%= "50".equals(nb) ? "selected" : "" %> >50&nbsp;/&nbsp;<fl:getMessage code="M60CC" alt="page" /></option>
                                         <option value="All" <%= "All".equals(nb) ? "selected" : "" %> ><fl:getMessage code="L302C" alt="Toutes"/></option>
                                   </select>
                             </td>
                        </tr>
                        <tr class="ligne_separation"><td></td></tr>
                        <tr>
                             <td>
                                 <a href="javascript:doSubmit();"><img src="<fl:webapp/>/icons/ico/valid_green2_long.gif"></a>
                             </td>
                        </tr>
            </table>
        </td>
      </tr>
      <tr class="ligne_separation"><td></td></tr>
</table>
</form>
		</div>
			<div id="searchResult">
		
		
			<h2 <%= (isFirstTimeIn ? "" : "style=\"margin-top: 0px;\"")  %>>
				<span><fl:getMessage code="L200C" alt="Résultat"/> <a id="bShowHideCriteria" href="#" onclick="gGridCriteria.show(this)" class="bHideCriteria">&nbsp;&nbsp;&nbsp;&nbsp;</a></span>
			</h2>

			<fl:grid displayFirst="true" name="FAQ" ajaxUrl="/list_faqheader_ajax.fl">
			</fl:grid>
		</div>
	</div></div>	
	<div id="BTFoot" class="BTFoot">
		<div class="BTFootL"></div>
		<div class="BTFootMiddle">&nbsp;</div>
		<div class="BTFootR"></div>
	</div>
</div>