<%
/******************************************************************************
 * 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.
 ******************************************************************************/
/****
* Cette page sert a selectionner un eventment pour un questionnaire
***/
%><%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%@ page import="com.edeal.frontline.navigation.FlRequest" %>
<%@ page import="java.util.Hashtable" %>
<%@ page import="java.util.Vector" %>
<%@ page import="com.edeal.frontline.FlContext" %>
<%@ page import="com.edeal.frontline.DataDictionary" %>
<%@ page import="com.edeal.frontline.Utils" %>
<%@ page import="com.edeal.frontline.navigation.WebUtils" %>
<%@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 evtID = flRequest.getRequestParameterOrAttribute("EvtID");
String field = flRequest.getParameter("field");
String query = flRequest.getParameter("query");
String unattached = flRequest.getRequestParameterOrAttribute("unattached");
String reftype = flRequest.getRequestParameterOrAttribute("reftype");
String formIndex = flRequest.getParameter("formIndex");
Vector vectFld = (Vector)flRequest.getAttribute("vectFld");
vectFld = vectFld == null ? new Vector() : vectFld;
Vector vectRefs = (Vector)flRequest.getAttribute("vectRefs");
vectRefs = vectRefs == null ? new Vector() : vectRefs;
try {
	Integer.parseInt(formIndex);
} catch (NumberFormatException nfe) {
	formIndex = "0";
}
formIndex = formIndex != null && !"".equals(formIndex) ? formIndex : "0";
%><html>
	<head>
		<link rel="stylesheet" type="text/css" href="<fl:link url="/css/grid/edeal_grid_css.jsp"/>">
		<link rel="stylesheet" type="text/css" href="<fl:link url="/common/select/select_css.jsp"/>">
		<link rel="stylesheet" type="text/css" href="<fl:webapp/>/css/common_css.jsp" type="text/css">
		<script type="text/javascript" src="<fl:link url="/js/edeal/libraries/jquery/jquery.js"/>"></script>
		<script type="text/javascript" src="<fl:link url="/js/ajax/sarissa.js"/>"></script>
		<script type="text/javascript" src="<fl:link url="/js/ajax/ajax.js"/>"></script>
	  	<script type="text/javascript" language="javascript" src="<fl:webapp/>/js/ac/fobAC_js.jsp"></script>
		<script type="text/javascript" language="javascript">
		function doSelect(id, display) {
			var win = window.top.opener;
			var f = win.document.forms[<%= formIndex %>];
			f.<%= field %>.value = id;
			f.lbl<%= field %>.value = display;
			if(win.do<%= field %>Change) {
				win.do<%= field %>Change();
			}
			window.top.close();
		}
		function doOnLoad(){
			_grid__select_js_.render();
		}
		function doSubmit() {
			var e = document.forms[0].elements;
			var strURL = _grid__select_js_.getAjaxUrl();
		<%if (unattached!=null){%>
			strURL +='&unattached='+'<%=unattached%>';
		<%}%>
		
		<%if (reftype!=null){
		
		%>
			strURL +='&reftype='+'<%=reftype%>';			
			
		<%}%>
		
		
		<%
			for(int i = 0; i < vectFld.size(); i++) {
				Hashtable row = (Hashtable)vectFld.elementAt(i);
				Vector vect = (Vector)row.get("fld");
				for(int j = 0; j < vect.size(); j++) {
					String currField = (String)vect.elementAt(j);
					if (!vectRefs.contains(currField)) {
		%>	strURL += '&<%= WebUtils.urlEncode(context, currField) %>=' + encodeURIComponent(e['query<%= (i + 1) %>'].value).split('+').join('%2b');
		<%
					} else {
		%>	strURL += '&<%= WebUtils.urlEncode(context, currField) %>=' + encodeURIComponent(e['query<%= (i + 1) %>'].options[e['query<%= (i + 1) %>'].selectedIndex].value).split('+').join('%2b');
		<%
					}
				}
			}
		
		%>	
		//doAjax(strURL);
		_grid__select_js_.callAjaxForHtml(strURL,null,true,false,null,true);
		}
		</script>
	</head>
	<body onload="document.forms[0].query1.focus()">
					<form action="javascript:doSubmit()">
					<input type="hidden" name="EvtID" value="<%=evtID%>"/>
		<table class="global" cellpadding="0">
			<tr>
				<td class="header_top_left"></td>
				<td class="header_top_middle"></td>
				<td class="header_top_right"></td>
			</tr>
			<tr>
				<td class="header_center_left"></td>
				<td class="header_center_middle title">
						<div style="display: inline"><%
for(int i = 0; i < vectFld.size(); i++) {
	Hashtable row = (Hashtable)vectFld.elementAt(i);
	String strDisplay = (String)row.get("disp");
	Vector vectField = (Vector)row.get("fld");
	String currField = null;
	if (vectField != null && vectField.size() > 0) {
		currField = (String)vectField.elementAt(0);
	}
%>
							<div class="criteria">
								<span class="criteria_label"><%= Utils.formatToWeb(strDisplay, false) %></span><%
		if (currField != null && vectRefs.contains(currField)) {
%>
								<span class="criteria_field">
									<select id="query<%= (i + 1) %>" name="query<%= (i + 1) %>">
										<option value=""></option><%
			String fldSql = currField;
			int idx = currField.lastIndexOf(":");
			if (idx != -1) {
				fldSql = currField.substring(idx + 1);
			}
			Vector dispRef = dico.getRefList(session, fldSql);
			if (dispRef != null && dispRef.size() > 0) {
				for (int j = 0; j < dispRef.size(); j++) {
					Vector line = (Vector)dispRef.elementAt(j);
					String refID = (String)line.elementAt(0);
					Object refDisp = line.elementAt(1);
%>
										<option value="<%= Utils.formatToWeb(refID, true) %>"><%= Utils.formatToWeb(refDisp, true) %></option><%
				}
			}
%>
									</select>
								</span><%
		} else {
%>
								<span class="criteria_field"><input id="query<%= (i + 1) %>" name="query<%= (i + 1) %>" type="text" size="20" value=""></span><%
		}
%>
							</div><%
	}

%>
						</div>
						<input type="image" src="<fl:link url="/icons/ico/valid_green2_long.gif"/>" class="search_button_new">
				</td>
				<td class="header_center_right"></td>
			</tr>
			<tr>
				<td class="header_bottom_left"></td>
				<td class="header_bottom_middle"></td>
				<td class="header_bottom_right"></td>
			</tr>
			<tr>
				<td class="body_left"></td>
				<td class="body_middle">
					<div style="height:290px">
						<fl:grid name="select" hidePage="true" width="100%" height="280px" ajaxUrl="<%= \"/select_event_list.fl?EvtID=\"+evtID+(query == null ? \"\" : \"&query=\" + WebUtils.urlEncode(context, query))%>"></fl:grid>
					</div>
				</td>	
				<td class="body_right"></td>
			</tr>
			<tr>
				<td class="body_bottom_left"></td>
				<td class="body_bottom_middle"><img src="<fl:link url="/icons/popup/pop14.gif"/>" width="9" height="18"></td>
				<td class="body_bottom_right"></td>
			</tr>
		</table>
		<div id="waiting" style="display:none"><fl:getMessage code="L639B" alt="Chargement ..."/></div>
		</form>
	</body>
</html>
