<%
/******************************************************************************
 * 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 language="java"%>
<%@ page import="com.edeal.frontline.navigation.FlRequest" %>
<%@ page import="com.edeal.frontline.Utils" %>
<%@ page import="java.util.Hashtable" %>
<%@ page import="com.edeal.frontline.DataDictionary" %>
<%@ page import="com.edeal.frontline.FlContext" %>
<%@ page import="java.util.Map" %>
<%@ page import="com.edeal.frontline.navigation.WebUtils" %>
<%@ page import="com.edeal.frontline.ActorBean" %>
<%@ page import="com.edeal.frontline.AccessDeniedException" %>
<%@ page import="com.edeal.frontline.FlLocale" %>
<%@ page import="java.util.Iterator" %>
<%@ page import="java.util.Vector" %>
<%@ page import="com.edeal.frontline.PersonBean" %>
<%@ 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 pIntType = flRequest.getRequestParameterOrAttribute("IntType");
	if(pIntType == null) {
		pIntType = "0";
	}

	String salesModel = context.getContextParameter("SalesModel");
	boolean isB2C = "B2C".equals(salesModel);

	String actName = flRequest.getRequestParameterOrAttribute("ActName");
	String actID = flRequest.getRequestParameterOrAttribute("actID");
	if (actID == null) {
		actID = (String)session.getAttribute("actorID");
	}
	
	String actSesName = null;
	try  {
		ActorBean actBean = new ActorBean(actID, session);
		actSesName = actBean.toString();
	}catch (AccessDeniedException ex) {
	}

	String perID = flRequest.getRequestParameterOrAttribute("OppPerID");
	String perName = null;
	try  {
		if (perID != null) {
			PersonBean perBean = new PersonBean(perID, session);
			perName = perBean.toString();
		}
	} catch (AccessDeniedException ex) {
	}

	// List code
	String lc = flRequest.getRequestParameterOrAttribute("lc");
	if (lc == null) {
		lc = flRequest.getRequestParameterOrAttribute("code");
	}
	if (lc == null) {
		lc = "OPPORTUNITY";
	}
	request.setAttribute("lc", lc);
	// search criteria
	String sc = flRequest.getRequestParameterOrAttribute("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 nb = flRequest.getSearchCriteria("$$nb");

	String crit = flRequest.getParameter("Crit");
	if (crit == null) {
		crit = "num";
	}
	
	String statusTyp = flRequest.getParameter("StatusTyp");
	String oppTitle;
	if ("WON".equals(statusTyp)) {
		oppTitle = Utils.getMessage(session, "L6025", "Opportunités signées");
	} else if ("LST".equals(statusTyp)) {
		oppTitle = Utils.getMessage(session, "L6026", "Opportunités perdues");
	} else if ("SLP".equals(statusTyp)) {
		oppTitle = Utils.getMessage(session, "L63D4", "Opportunités en sommeil");
	} else {
		statusTyp = "RUN";
		oppTitle = Utils.getMessage(session, "L304B" , "Opportunités en cours");
	}
	
	int critCount = 0;
	String SfwID = flRequest.getRequestParameterOrAttribute("SfwID");
%>
<script type="text/javascript" language="javascript" src="<fl:webapp/>/js/jsOnload.jsp"></script>
<script language="javascript">
	function doChangeActor() {
		var fenetreChoix = window.open('<fl:webapp/>/select.fl?type=Actor&field=OppActID' , 'ChoixActeur' , 'menubar=no,status=no,toolbar=no,scrollbars=yes,resizable=yes,width=<%= SelectAction.SELECT_WINDOW_WIDTH %>,height=350');
	}
	
	function doChangePerson() {
		var fenetreChoix = window.open('<fl:webapp/>/select.fl?type=Person&field=OppPerID' , 'ChoixPersonne' , 'menubar=no,status=no,toolbar=no,scrollbars=yes,resizable=yes,width=<%= SelectAction.SELECT_WINDOW_WIDTH %>,height=350');
	}

	function doOppSubmit() {
	
		// This is an ugly hack. If we're currently doing an autocomplete operation,
		// we want to "catch" an enter keypress, so as not to submit the form prematurely
		try {
			if (acCurHighlightedDiv != null) {
				return false;
			}
		} catch (error) {
		}
		
		var f = document.forms[0];
		var sc = '$$nb=' + f.$$nb.options[f.$$nb.selectedIndex].value;
		
		if (f.OppEntID.value != '') {
			sc += '&OppEntID=' + f.OppEntID.value;
		}
		
		if (f.OppPerID.value != '') {
			sc += '&OppPerID=' + f.OppPerID.value;
		}
		
		if (f.OppActID.value != '') {
			sc += '&OppActID=' + f.OppActID.value;
		}
		
		if (f.Etat.selectedIndex != 0) {
			sc += '&Etat=' + f.Etat.options[f.Etat.selectedIndex].value;
		}
		
		if (f.OppNumRef.value != '<fl:getMessage code="L6139" alt="<Numéro>" js="true"/>') {
			sc += '&OppNumRef=' + f.OppNumRef.value;
		}	
		
		if (f.OppDate1.value != '') {
			sc += '&OppDate1=' + f.OppDate1.value;
		}
		
		if (f.OppDate2.value != '') {
			sc += '&OppDate2=' + f.OppDate2.value;
		}
		
		f.sc.value = sc;
		return true;
	}
</script>
<form action="<fl:webapp/>/list_opportunity.fl" method="post" onsubmit="return doOppSubmit();">
<%
//if coming from the agenda, store these values.
String nbAgenda = flRequest.getRequestParameterOrAttribute("nbAgenda");
if (nbAgenda != null) { %>
	<input type=hidden name="nbAgenda" value="<%=nbAgenda%>">		
<% } %>
<%
String initDate = flRequest.getRequestParameterOrAttribute("initDate");
if (initDate != null) { %>
	<input type=hidden name="initDate" value="<%=initDate%>">		
<% } %>
<input type="hidden" name="cu" value="/list_opportunity_criteria.fl">
<input type="hidden" name="lc" value="<%= Utils.formatToWeb(lc, true) %>">
<input type="hidden" name="lu" value="/list_opportunity.fl">
<input type="hidden" name="sc" value="">
<input type="hidden" name="ou" value="<%= Utils.formatToWeb(ou, true) %>">
<input type="hidden" name="obj.title" value="<fl:getMessage code="L3025" alt="Opportunité"/>">
<input type="hidden" name="list.title" value="<fl:getMessage code="L63C3" alt="Liste des opportunités"/>">
<input type="hidden" name="criteria.title" value="<fl:getMessage code="L6475" alt="Recherche opportunité"/>">
<% if (SfwID != null) { %>
	<input type="hidden" name="SfwID" value="<%= SfwID %>">
<% } %>
<input name="ChoixVue" type="hidden" value=""/>
<fl:bigTabs criteriaTitle="<%= Utils.getMessage(session, \"L6475\", false, true, \"Recherche opportunité\") %>">
	<table class="container">
		<tr>
			<td>
				<div class="criteriaTableDiv">
					<% if (!isB2C) { %>
						<input id="OppEntID" name="OppEntID" type="hidden" value="">
						<input id="lblOppEntID" name="lblOppEntID" class="criteriaField" onfocus="displayOnFocus(this);" type="text" value="&lt;<fl:getMessage code="F002B" alt="Entreprise"/>&gt;" autocomplete="off">
						<a href="javascript:var win = window.open('<fl:webapp/>/select.fl?type=Enterprise&field=OppEntID', 'SelectEnterprise', 'menubar=no,status=no,toolbar=no,scrollbars=yes,resizable=yes,width=<%= SelectAction.SELECT_WINDOW_WIDTH %>,height=500')" tabindex="3"><img src="<fl:webapp/>/icons/ico/rechercher.gif" border="0" width="17" height="17"></a>
						<a href="javascript:var f = window.document.forms[0]; f.OppEntID.value = ''; f.lblOppEntID.value = '<<fl:getMessage code="F002B" alt="Entreprise"/>>'; void('')" tabindex="4"><img src="<fl:webapp/>/icons/ico/supprimer.gif" border="0" width="17" height="17"></a>
						<script language="javascript">runOnTime("installFobAC(document.forms[0].lblOppEntID);", 200);</script>
					<%
							critCount++;
						}
					%>
					<% if (isB2C || salesModel.equalsIgnoreCase("MIXTE")) { %>
						<input id="OppPerID" name="OppPerID" type="hidden" value="">
						<input id="lblOppPerID" name="lblOppPerID" class="criteriaField<%= (critCount == 0) ? "" : " leftMargin10" %>" onfocus="displayOnFocus(this);" type="text" value="&lt;<fl:getMessage code="F002E" alt="Personne"/>&gt;" autocomplete="off">
						<a href="javascript:var win = window.open('<fl:webapp/>/select.fl?type=Person&field=OppPerID', 'SelectPerson', 'menubar=no,status=no,toolbar=no,scrollbars=yes,resizable=yes,width=<%= SelectAction.SELECT_WINDOW_WIDTH %>,height=500')" tabindex="3"><img src="<fl:webapp/>/icons/ico/rechercher.gif" class="icon"></a>
						<a href="javascript:var f = window.document.forms[0]; f.OppPerID.value = ''; f.lblOppPerID.value = '<<fl:getMessage code="F002E" alt="Personne"/>>'; void('')" tabindex="4"><img src="<fl:webapp/>/icons/ico/supprimer.gif" class="icon"></a>
						<script language="javascript">runOnTime("installFobAC(document.forms[0].lblOppPerID);", 200);</script>
					<%
							critCount++;
						}
					%>
					<span class="criteriaLabel<%= (critCount == 0) ? "" : " leftMargin10" %>"><fl:getMessage code="L2089" alt="Acteur"/>&nbsp;</span><input type="hidden" name="OppActID" value="<%= actID %>"><input type="text" class="criteriaField" name="lblOppActID" value="<%= actSesName %>" onfocus="this.blur();" readonly>&nbsp;<a href="javascript:doChangeActor();"><img src="<fl:webapp/>/icons/ico/rechercher.gif" class="icon" alt="<fl:getMessage code="A3004" alt="Choisir un acteur"/>"></a> 
					<% critCount++; %>
					<% if (critCount > 2) { critCount = 0; %><br><br><% } %>
					<select class="criteriaField<%= (critCount == 0) ? "" : " leftMargin10" %>" name="Etat">
						<option value="">&lt;<fl:getMessage code="F206F" alt="Etat"/>&gt;</option>
						<%
							Vector statusID = dico.getRefList(FlLocale.getInstance(session), "OppStoID");
							Vector row;
							Iterator iter = statusID.iterator();
							while (iter.hasNext()) {
								row = (Vector) iter.next();
						%>
							<option value="<%= row.elementAt(0) %>"><%= row.elementAt(1) %></option>
						<% } %>
					</select>
					<% critCount++; %>
					<% if (critCount > 2) { critCount = 0; %><br><br><% } %>
					<input class="criteriaField<%= (critCount == 0) ? "" : " leftMargin10" %>" type="text" name="OppNumRef" value="<fl:getMessage code="L6139" alt="<Numéro>"/>" size="37" onfocus="this.select()" onblur="if (this.value == '') this.value = '<fl:getMessage code="L6139" alt="<Numéro>"/>';"> 
					<% critCount++; %>
					<% if (critCount != 1) { critCount = 0; %><br><br><% } %>
					<span class="criteriaLabel<%= (critCount == 0) ? "" : " leftMargin10" %>"><fl:getMessage code="L6216" alt="Signable du"/>&nbsp;</span><input class="criteriaField" size="9" type="text" name="OppDate1" size="10" onFocus="this.select()" onBlur="if (this.value != '') { ctrlDateField(this, '<fl:getMessage code="M202B" alt="Format de date incorrect. Veuillez corriger." js="true"/>')}">&nbsp;<a href="javascript:openCalendar(document.forms[0].OppDate1);" onMouseOver="window.status='<fl:getMessage code="A2000" alt="Afficher le calendrier" js="true"/>';return true;" onMouseOut="window.status=' '; return true"><img src="<fl:webapp/>/icons/ico/clock_neutre.gif" border="0" width="15" height="15"></a><span class="criteriaLabel">&nbsp;<fl:getMessage code="L3127" alt="au"/>&nbsp;<input class="criteriaField" type="text" name="OppDate2" size="10" onFocus="this.select()" onBlur="if (this.value != '') { ctrlDateField(this, '<fl:getMessage code="M202B" alt="Format de date incorrect. Veuillez corriger." js="true"/>')}">&nbsp;</span><a href="javascript:openCalendar(document.forms[0].OppDate2);" onMouseOver="window.status='<fl:getMessage code="A2000" alt="Afficher le calendrier" js="true"/>';return true;" onMouseOut="window.status=' '; return true"><img src="<fl:webapp/>/icons/ico/clock_neutre.gif" border="0" width="15" height="15"></a>
				</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">
									<option value="20" <%= nb == null || "20".equals(nb) ? "selected" : "" %> >20&nbsp;/&nbsp;<fl:getMessage code="M60CC" alt="page" /></option>
									<option value="10" <%= "10".equals(nb) ? "selected" : "" %> >10&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 style="vertical-align: middle;">
							<td>
								<input type="image" src="<fl:webapp/>/icons/ico/valid_green2_long.gif" border="0"  tabindex="999" align="left">
							</td>
						</tr>
                    </table>
                </td>
		</tr>
	</table>
</fl:bigTabs>
</form>
