%
/******************************************************************************
 * 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"%>
<%@ page import="com.edeal.frontline.navigation.FlRequest" %>
<%@ page import="com.edeal.frontline.FlContext" %>
<%@ page import="com.edeal.frontline.Utils" %>
<%@ page import="com.edeal.frontline.FieldNotInitializedException" %>
<%@ page import="java.util.Date" %>
<%@ page import="java.util.Vector" %>
<%@ page import="com.edeal.frontline.ActorBean" %>
<%@ page import="java.util.Calendar" %>
<%@ page import="com.edeal.frontline.DataDictionary" %>
<%@ page import="com.edeal.frontline.FlLocale" %>
<%@ page import="com.edeal.frontline.FrontlineException" %>
<%@ page import="com.edeal.frontline.FieldBean" %>
<%@ page import="com.edeal.frontline.ObjectsBean" %>
<%@ page import="com.edeal.frontline.controller.actions.SelectAction" %>
<%@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 paramRootFld = flRequest.getRequestParameterOrAttribute("RootFld");
String paramCtrID = flRequest.getRequestParameterOrAttribute("CtrID");
String paramGrpID = flRequest.getRequestParameterOrAttribute("GrpID");
String selectedTab = flRequest.getRequestParameterOrAttribute("selectedTab");
String src = flRequest.getRequestParameterOrAttribute("Src");
String id = null;
try {
	id = Criteria.getID();
} catch (FieldNotInitializedException fnie) {
}
String selectedStr = "";
try {
	selectedStr = Criteria.getCriFldID();
} catch (FieldNotInitializedException fnie) {}
String table = null;
try {
	table = dico.getTable("id", Criteria.getCriFobID()).getObjSql();
} catch (FrontlineException fe) {}
String fldID = null;
try {
	fldID = Criteria.getCriFldID();
} catch (FieldNotInitializedException fnie) {}
String criOpe = null;
try {
	criOpe = Criteria.getCriOpe();
} catch (FieldNotInitializedException fnie) {}
boolean hasField = fldID != null;
FieldBean fld = null;
String[] ctlOpe = {};
String fldType = null;
boolean isOpeSelected = false;
boolean isValueNeeded = true;
boolean isMultival = false;
boolean isControledByRef = false;
boolean isControledByFob = false;
boolean isMultipleValues = false;
boolean isBoolean = false;
boolean isDate = false;
boolean isDecimal = false;
boolean isInteger = false;
boolean isNumeric = false;
boolean isText = false;
if(hasField) {
	fld = dico.getFieldByID(fldID);
	try {
		isControledByRef = (fld.getFldTabID() != null);
	} catch (FieldNotInitializedException ex) {
	}
	try {
		isControledByFob = (fld.getFldFobID() != null);
	} catch (FieldNotInitializedException ex) {
	}
	if (fld.isBoolean()) {
		ctlOpe = new String[]{"=", "<>"};
		isBoolean = true;
	} else if (fld.isDate() || fld.isTime() || fld.isDateTime()) {
		ctlOpe = new String[]{"=", "<>", "<", ">", "<=", ">=", "exist"};
		isDate = true;
	} else if (fld.isFloat() || fld.isDouble()) {
		ctlOpe = new String[]{"=", "<>", "<", ">", "<=", ">=", "in", "exist"};
		isDecimal = true;
		isNumeric = true;
	} else if (fld.isInteger() ||  fld.isLong() ||  fld.isByte() ||  fld.isShort()) {
		ctlOpe = new String[]{"=", "<>", "<", ">", "<=", ">=", "in", "exist"};
		isInteger = true;
		isNumeric = true;
	} else if (fld.isString()) {
		ctlOpe = new String[]{"=", "<>", "like", "in", "begin", "exist"};
		isText = true;
	}
	if(fld.isFldMultival()) {
		ctlOpe = new String[]{"=", "contains", "exist"};
		isMultipleValues = true;
	} else if(isControledByRef || isControledByFob) {
		ctlOpe = new String[]{"=", "<>", "in", "exist"};
	}
}
Vector vectChx = new Vector();
try {
	vectChx = Criteria.getCriChx();
} catch (FieldNotInitializedException fnie) {
}
if (hasField) {
	for (int i = 0; i < ctlOpe.length; i++) {
		try {
			String opeID = dico.getRefIdByCode("CriOpe", ctlOpe[i]);
			String opeDisp = (String)dico.getRefDisp(session, "CriOpe", opeID);
	
			isMultipleValues = isMultipleValues || (opeID.equals(criOpe) && "in".equals(ctlOpe[i]));
			if(opeID.equals(criOpe)) {
				isOpeSelected = true;
				isValueNeeded = !"exist".equals(ctlOpe[i]);
			}
		} catch (Exception ex) {
		}
	}
}
String actionUrl = "save_criteria_create.fl";
FieldBean fldBean =  null;
String objID = null;
String objName = null;
ObjectsBean objBean = null;	
String pageName=null;
if (id != null) {
	actionUrl = "save_criteria_edit.fl";
} else{	
	try{
		fldBean = dico.getFieldByName(paramRootFld);
	}catch(FrontlineException fe){}
	
		if (fldBean!=null){
			try{
				objID = fldBean.getFldObjID();
			}catch(FieldNotInitializedException fNe){}
			
			if (objID!=null){
				try{
					objBean = new ObjectsBean(objID, session);
				}catch(FrontlineException e){}
				if (objBean!=null){
					try{
						String radName = objBean.getObjRadical();
						if (radName!=null && !"".equals(radName)){											
							if (radName.equals("Sel")){
								pageName = "/edit_selection.fl";						
							}
							//Ajouter ici les autres radicaux pour la redirection
							
						}
					}catch(Exception e){}				
				}
			}
		}
	}
	
%>
	 CRM
	
	
	
	
	
	
	
	
	
		"/>
		
		
		
<% if(paramGrpID != null) { %>
		
<% } %>
<% if(paramRootFld != null) { %>
		
<% } %>
<% if(paramCtrID != null) { %>
		
<% } 
%>
		
			" ignoreList="true">
				
					
						| <% if (!hasField) {%> | <% } else {%> |  |  | <% if (isOpeSelected && isValueNeeded) { %>
							
							<% } %><% } %> | 
					
						| <% if (!hasField) { %> | <% } else {%> |  |  | <% if (isOpeSelected && isValueNeeded) { %>
								<% 
								if (isControledByFob) {
									ObjectsBean ctlFob = dico.getTable("id", fld.getFldFobID());
									if (isMultipleValues) {
%>							"> <% } %> ">  ">
<%
									} else {
%>							">
							" style="width: 100%" readonly="readonly" onfocus="this.blur();">  ">  ">
<%
									}
								} else if (isControledByRef) {
									Vector vectRef = dico.getRefList(session, fld.getFldSql());
%>							
								<% } else if (isDate) {
									String strDate = "";
									String strTime = "";
									if(vectChx.size() > 0) {
										java.util.Date date = Utils.formatDateFromWeb(session, (String)vectChx.firstElement());
										strDate = Utils.formatToWebDate(session, date, true);
										strTime = Utils.formatToWebTime(session, date, true).substring(0, 5);
									}
%>							');">
							';return true;" onMouseOut="window.status=' '; return true">  ');">
							
								<% } else if (isNumeric) { %>
								 " size="40" style="width: 100%">
							       
<%
									if (isMultipleValues) {
%> <%
									}
								}
							   else if (isText) { %>
								 " size="40" style="width: 100%">
							       
<%
									if (isMultipleValues) {
%>
 <%
									}
								 
								} else if (isBoolean) { %>
							
								<% } %>
							<% } else if (isOpeSelected) { %>
							
							<% } %>
 | 
					|  |