<% /******************************************************************************
 * Copyright (c) 2000-2012 E-DEAL
 *
 * E-DEAL S.A.
 * 41, rue Périer
 * 92120 Montrouge
 * France
 *
 * T: +33 (0)1 73 03 29 80
 * 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.WebOperationBean" %>
<%@ page import="com.edeal.frontline.Utils" %>
<%@ page import="com.edeal.frontline.DataDictionary" %>
<%@ page import="com.edeal.frontline.FlContext" %>
<%@ page import="java.util.Hashtable" %>
<%@ page import="java.util.Vector" %>
<%@ page import="java.text.DecimalFormat" %>
<%@ page import="com.edeal.frontline.SalesInvestBean" %>
<%@ page import="com.edeal.frontline.FlLocale" %>
<%@ page import="com.edeal.frontline.FieldNotInitializedException" %>
<%@ page import="com.edeal.frontline.helper.EventBaseHelper.EventCategory" %> 
<%@ taglib uri="http://www.e-deal.com/taglib/fl" prefix="fl" %>
<jsp:useBean class="com.edeal.frontline.EventBean" id="Event" 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 id = null;
	try {
		id = Event.getID();
	} catch (FieldNotInitializedException e) {
	}
	boolean isSalesInvest = false;
	try {
		isSalesInvest = Event.isEvtIsSalesInvest();
	} catch (FieldNotInitializedException e) {
	}
	
	String evtCity = null;
	try {
		evtCity = Event.getEvtCity();
	} catch (FieldNotInitializedException e){
	}
	
	String evtZip = null;
	try {
		evtZip = Event.getEvtZip();
	} catch (FieldNotInitializedException e) {
	}
	
	String eventCategoryID = null;
	try {
		eventCategoryID = Event.getEvtCategory();
	} catch (FieldNotInitializedException e) {
	}

	String eventCategory = null;
	try {
		eventCategory = (String) dico.getRefDisp("Ect", "Te2", eventCategoryID);
	} catch (Exception e) {
	}
	
	boolean isActiveSalesInvest = SalesInvestBean.isSalesInvestActive(context);
	
	
	Vector formList = (Vector)flRequest.getAttribute("formList");
	Vector scriptList = (Vector)flRequest.getAttribute("scriptList");
	
	if (formList == null) {
		formList = new Vector();
	}
	
	if (scriptList == null) {
		scriptList = new Vector();
	}
	
	DecimalFormat df = FlLocale.getInstance(session).getDecimalFormat("#,##0.##");
	DecimalFormat df2 = FlLocale.getInstance(session).getDecimalFormat("0000");

	Vector eventActors = null;
	try {
		eventActors = Event.getEvtActors();
	} catch (FieldNotInitializedException e) {
	}
	
	int evtQuota = 0;
	try {
		evtQuota = Event.getEvtQuota();
	} catch (FieldNotInitializedException e) {
	}
%>

<script language="javascript" src="<fl:webapp/>/js/edeal/libraries/jqplot/1.0.8/excanvas.min.js" type="text/javascript"/><!-- comment --></script>
<script src="<fl:webapp/>/js/edeal/libraries/jqplot/1.0.8/jquery.jqplot.min.js" type="text/javascript"/><!-- comment --></script>
<script src="<fl:webapp/>/js/edeal/libraries/jqplot/1.0.8/plugins/jqplot.pieRenderer.min.js" type="text/javascript"/><!-- comment --></script>
<link href="<fl:webapp/>/js/edeal/libraries/jqplot/1.0.8/jquery.jqplot.css" rel="stylesheet" type="text/css"/>

<script language="javascript">
	function refreshGuestLst() {
		_grid__GUESTLST_js_.render()
	}
	
	function refreshPopFilles() {
		_grid__PPF_EMB_js_.render()
	}
	<fl:access operation="create" name="Population">
		function createPopulation(type, statusID) {
			var attr = '&statusType=' + type;
			if (statusID != '') {
				attr = attr + '&statusID=' + statusID;
			}
			window.open('<fl:link url="<%= \"/generate_pop_from_event_start.fl?id=\" + id %>"/>' + attr, 'gen<%= id %>', 'width=700,height=240,left=150,top=150,menubar=no,status=no,resizable=yes,toolbar=no,location=no');
		}
	</fl:access>
	
	function doInscription() {
		window.open('<fl:webapp/>/edit_personevent.fl?initEvtID=<%= id == null ? "" : id %>' , 'Inscription', 'width=800,height=300,menubar=no,status=no,toolbar=no,scrollbars=auto,resizable=no');
	}
	
	function loadGraph() {
		$.getJSON('<fl:webapp/>/get_event_graph.fl?id=<%= id %>', function(result) {
			if (result != null) {
				<%--[{"TYPE":"PARTICIPATION","STATUS":[["Venu",0],["Absent",0],["Excusé",0],["Intéressé",0],["Pas  intéressé",0],["Souhaite RDV",0],["Souhaite brochure",0],["Souhaite inscription",0],["NPAI",0],["Injoignable",0]]},{"TYPE":"INSCRIPTION","STATUS":[["A valider",0],["Ecarté",0],["Invité",0],["Viendra",1],["Ne viendra pas",1],["Ne sait pas",0],["A contacter",0],["A envoyer",0],["Envoyé",0],["A cliqué",0]]}]--%>
				plotGraph('chartInscription', result[1].STATUS);
				if (result[0] && result[0].STATUS) {
 					plotGraph('chartParticipation', result[0].STATUS);
 				}
			} 
		});
	}
	
	function plotGraph(graphID, jsonData) {
	  $.jqplot (graphID, [jsonData], 
	    { 
	      seriesDefaults: {
	        // Make this a pie chart.
	        renderer: $.jqplot.PieRenderer, 
	        rendererOptions: {
	          // Put data labels on the pie slices.
	          // By default, labels show the percentage of the slice.
	          showDataLabels: true
	        }
	      }, 
	      legend: { show:true }
	    }
	  );
	}
	
	function doOnLoad() {
	<%-- var data = [
	    ['Heavy Industry', 12],['Retail', 9], ['Light Industry', 14], 
	    ['Out of home', 16],['Commuting', 7], ['Orientation', 9]
	  ];
	  plotGraph('chartInscription', data);
	  plotGraph('chartParticipation', data); --%>
	  loadGraph();
	  loadStatistic();
	  loadNbrOccupedPlace();
	}	
	
	function loadStatistic() {
		$.getJSON('<fl:webapp/>/get_event_statistics.fl?id=<%= id %>', function(result) {
			if (result != null) {
				$("#stats_inscriptions").html(result[0].INSCRIPTION);
	 			$("#stats_participations").html(result[1].PARTICIPATION);	
			} 
		});
	}
	
	function doRefreshEvents() {
		refreshEvent()
		loadGraph();
	  	loadStatistic();
	}
	//EVTTMK
	//EVTQST
	//EVTOTHER
	function refreshEventTMK() {
		_grid__EVTTMK_js_.renderWithCriteria({"PvtEventID" : "<%= id %>"})
	}
	
	function refreshEventQST() {
		_grid__EVTQST_js_.renderWithCriteria({"PvtEventID" : "<%= id %>"})
	}
	
	function refreshEventOTHER() {
		_grid__EVTOTHER_js_.renderWithCriteria({"PvtEventID" : "<%= id %>"})
	}
	
	function refreshEvent() {
		
	<% if (EventCategory.TMK.toString().equals(eventCategory)) { %>	
		refreshEventTMK();
	<% } else if (EventCategory.QST.toString().equals(eventCategory)) { %>
		refreshEventQST();
	<% } else { %>
		loadNbrOccupedPlace();
		refreshEventOTHER();
	<% } %>	
	}
	
	function doAssignCall() {
	<% if (eventActors == null) { %>
		alert('<fl:getMessage code="M9041" alt="Merci de renseigner le champ \\u0022Agent(s)\\u0022" js="true"/>');
		return;
	<% } %>
		assignCall();
	}
		
	function assignCall() {
		jQuery.openPopupLayer({
			name: "WaitingPopup",
			width: "auto",
			height: "auto",
			url: "<fl:webapp/>/waiting_operation_popup.fl",
			success : function(result) {
				$.ajax({
					   type: "POST",
					   url: "<fl:webapp/>/assign_call.fl?evtID=<%= id %>",
					   timeout: 20000,
					   contentType: "application/json;charset=utf-8",
					   dataType: 'json',
					   success: analyseResponse
					});
				}
		});
	}			
	function analyseResponse(data) {
		if (data != null) {
			if (data.status == "OK") {
				$("#waiting_popup").attr("src", "<fl:webapp/>/js/progressbar/images/success.png");
				$("#detail_popup").html("<fl:getMessage code="L81A0" alt="L\\\'affectation s\\\'est terminé avec succès" js="true"/>");
			} else if (data.status == "KO") {
				$("#waiting_popup").attr("src", "<fl:webapp/>/js/progressbar/images/failure.png");
				$("#detail_popup").html("");
				$("#error_popup").html(decodeURIComponent(data.detail));
			} else {
				$("#waiting_popup").attr("src", "<fl:webapp/>/js/progressbar/images/failure.png");
			}	
		}
	}
	
	function loadNbrOccupedPlace() {
		var ajaxURL = '<fl:webapp/>/get_personevent_count.fl?id=<%= id %>';
		doAjax(ajaxURL, nbOccupedCallBack);
	}
	
	function nbOccupedCallBack(index) {
		if (eDealXmlhttpArr[index].readyState == 4) {
			var nbPar = eval(eDealXmlhttpArr[index].responseText);
			var perPart = 0;
			if (<%= evtQuota %> > 0) {
				perPart = nbPar/<%= evtQuota %> ;
			}	
			$("#nbPart").html(nbPar);
			if (perPart >= 0.7) {
				$("#nbPart").css('color', 'red');
				$("#nbPart").css('font-wight', 'bold');
			} else {
				$("#nbPart").css('color', 'black')
				$("#nbPart").css('font-wight', 'normal');
			}
			hideWaiting();
		}
	}
	function editMarkedEvent(PvtID) {
		window.open('<fl:webapp/>/edit_personevent.fl?id=' + PvtID , 'Inscription', 'width=765,height=300,menubar=no,status=no,toolbar=no,scrollbars=auto,resizable=no');
	}
	
	function deleteMarkedEvent(PvtID) {
		if (confirm('<fl:getMessage code="M6102" alt="Etes-vous sûr de vouloir supprimer ce marquage ?" js="true"/>')) {
			doAjax('<fl:webapp/>/delete_object_ajax.fl?type=PersonEvent&id=' + PvtID , delPvtCallback);
		}
	}
	
	function delPvtCallback(arrIndex){
		if (eDealXmlhttpArr[arrIndex].readyState == 4) {
			hideWaiting();
			eval(eDealXmlhttpArr[arrIndex].responseText);
			setTimeout('refreshEvent()', 10);
		}
	}

	function refreshInteraction() {
		_grid__INTT_EMB_js_.render();
	}
	
	function previewScriptResponse(id, hasNotes, perID){
		window.open('<fl:webapp/>/read_scriptresponse.fl?scriptID='+id+'&preview=0&lsePosition=0&hasNotes='+hasNotes+'&perID='+perID, 'PreviewFormResponse' , 'menubar=no,status=no,toolbar=no,scrollbars=no,resizable=yes,width=800,height=500');
	}
</script>

<fl:bigTabs objectTitle="<%= Utils.getMessage(session, \"L305F\", \"Evénement\") %>" ou="<%=\"/read_event.fl?id=\" + id %>" >
	<table class="container" cellpadding="0">
		<tr>
			<td class="titreFiche" colspan="3">
				<fl:getProperty name="Event" property="EvtLabel" alt=""/>
			</td>
		</tr>
		<tr class="ligne_separation"><td></td></tr>
		<tr class="fieldline">
			<td class="column2">
				<table class="container" cellpadding="0">
					<fl:fieldRead property="EvtCode"/>
					<fl:fieldRead property="EvtDate"/>
					<fl:fieldRead property="EvtEndDate"/>
<%
			if (EventCategory.TMK.toString().equals(eventCategory)) { %>			
					
<% 			} 
 			if (EventCategory.MEET.toString().equals(eventCategory)) { %>
 					<fl:fieldRead property="EvtActors" bean="true" disp="<%= flRequest.computeURL(\"/read_actor.fl\") %>"/>
					<fl:fieldRead property="EvtQuota"/>			
		<%
			if (evtQuota > 0) {
		%>
			<tr>
				<td class="dataLabel"><%= Utils.getMessage(session, "L81ED", "Nombre de participants") %></td>
				<td class="dataValue" id="nbPart"></td>
			</tr>
		<% 		
				} 
		%>			
<% 			} %>					
				</table>
			</td>
			<td class="separation"><div class="separation"></div></td>
			<td class="column2">
				<table class="container" cellpadding="0">
					<fl:fieldRead property="EvtCategorie_"/>
					<%if ( EventCategory.MEET.toString().equals(eventCategory)) { %>	
					<fl:fieldRead property="EvtTiers_" separator="<br>" bean="true" href="true" disp="<%= flRequest.computeURL(\"/read_enterprise.fl\") %>"/>
					<%} %>
					<fl:fieldRead property="EvtStatut_"/>
					<% if (scriptList.size() > 0) { %>
						<tr class="fieldline">
							<td id="EvtTool_label" class="dataLabel"><fl:label code="F6086" label="Outil"/></td>
							<td id="EvtTool_value" class="dataValue">
							<%
								Hashtable row = (Hashtable)scriptList.elementAt(0);
								Integer cScrSeqNumI = (Integer) row.get("ScrSeqNum");
								int cScrSeqNum = 0;
								if (cScrSeqNumI != null) {
									cScrSeqNum = cScrSeqNumI.intValue();
								}
							%>
								<div><a href="<fl:link url="<%= \"/read_script.fl?id=\" + (String)row.get(\"ScrID\") %>"/>" title="<fl:getMessage code="L61EA" alt="Script"/> <%= df2.format((long) cScrSeqNum) + " - " + (String)row.get("ScrLabel") %>"><fl:getMessage code="L61EA" alt="Script"/>&nbsp;<%= df2.format((long) cScrSeqNum) + " - " + (String)row.get("ScrLabel") %></a></div>
							</td>
						</tr>
					<% } else if (formList.size() > 0) { %>
						<tr>
							<td id="EvtTool_label" class="dataLabel"><fl:label code="F6086" label="Outil"/></td>
							<td id="EvtTool_value" class="dataValue">
							<%
								Hashtable row = (Hashtable)formList.elementAt(0);
								Integer cFrmSeqNumI = (Integer) row.get("FrmSeqNum");
								int cFrmSeqNum = 0;
								if (cFrmSeqNumI != null) {
									cFrmSeqNum = cFrmSeqNumI.intValue();
								}
							%>
								<div><a href="<fl:link url="<%= \"/read_form.fl?id=\" + (String)row.get(\"FrmID\") %>"/>" title="<fl:getMessage code="L613C" alt="Questionnaire"/> <%= df2.format((long) cFrmSeqNum) + " - " + (String)row.get("FrmLabel") %>"><fl:getMessage code="L613C" alt="Questionnaire"/>&nbsp;<%= df2.format((long) cFrmSeqNum) + " - " + (String)row.get("FrmLabel") %></a>
							</td>
						</tr>
					<% } else if (isActiveSalesInvest && isSalesInvest) { %>
						<fl:fieldRead property="EvtIsSalesInvest" valueCodeIfTrue="L2005" valueCodeIfFalse="L2006"/>
						<fl:fieldRead property="EvtAvgAmountInvest" postText="&euro;"/>	
					<% } else { %>
						<tr>
							<td class="dataLabel">&nbsp;</td>
							<td class="dataValue">&nbsp;</td>
						</tr>
					<% } %>
					
					
<% 			if (EventCategory.MEET.toString().equals(eventCategory)) { %>					
					<tr class="fieldline">
						<td id="Evt.Address_label" class="dataLabel"><fl:label code="F2012" label="Adresse"/></td>
						<td id="Evt.Address_value" class="dataValue">
							<div>
								<fl:getProperty name="Event" property="EvtAd1" alt="" postText="<br>"/>
								<fl:getProperty name="Event" property="EvtAd2" alt="" postText="<br>"/>
								<fl:getProperty name="Event" property="EvtAd3" alt="" postText="<br>"/>
								<fl:getProperty name="Event" property="EvtZip" alt="" postText="&nbsp;"/><fl:getProperty name="Event" property="EvtCity" alt="" postText=""/><% try { Event.getEvtZip(); Event.getEvtCity(); %><br><% } catch(FieldNotInitializedException e) { try { Event.getEvtCity(); %><br><% } catch (FieldNotInitializedException ex) {}} %>
								<fl:getProperty name="Event" property="EvtCtrID" alt="&nbsp;" preText="<%= (evtCity == null && evtZip != null) ? \"<br>\" : \"\"%>"/>
							</div>
						</td>
					</tr>
<% 			} %>								
				</table>	
			</td>
		</tr>
	</table>
	<fl:notes name="EvtRemarks" title="<%= Utils.getMessage(session, \"F2024\", \"Notes\") %>" nbPix="35"><fl:getProperty name="Event" property="EvtRemarks" alt="&nbsp;" edit="false" /></fl:notes>
<link href="<fl:webapp/>/css/smalltabs_css.jsp" rel="stylesheet" type="text/css">
<fl:smallTabs name="EventTabs">
<fl:sTab id="SYNTHESE" title="<%= Utils.getMessage(session, \"L6382\", false, true, \"Synthèse\") %>">

	<table class="container" cellpadding="0">
		<tr class="fieldline">
			<td class="column2">
				<table class="container">
					<tr>
						<td class="titreInterneSmalltabs">
							<fl:getMessage code="L8187" alt="Inscriptions"/> 
						</td>
					</tr>	
					<tr>
						<td colspan="2">
							<div id="chartInscription"></div>
						</td>		
					</tr>
					<tr>	
						<td>
							<div class="edealGrid">
								<div id="grid-data" class="data">
									<table cellpadding="0" id="stats_inscriptions">
										<%-- Inscription table will be here --%>						
									</table>
								</div>
							</div>
						</td>
					</tr>	
				</table>
			</td>
		
			<td class="separation"><div class="separation"></div></td>
			<td class="column2">	
				<table class="container">
					<tr>
						<td class="titreInterneSmalltabs">
							<fl:getMessage code="L8186" alt="Participation"/>
						</td>
					</tr>
					<tr style="vertical-align: top">
						<td colspan="2">
							<div id="chartParticipation"></div>
						</td>
					</tr>
					<tr>	
						<td>
							<div class="edealGrid">
								<div id="grid-data" class="data">
									<table cellpadding="0" id="stats_participations" >
										<%-- Participation table will be here --%>
									</table>
								</div>
							</div>
						</td>
					</tr>	
				</table>
			</td>		
		</tr>
	</table>

	</fl:sTab>
	<fl:sTab id="PARTICIPANTS" title="<%= Utils.getMessage(session, \"F6121\", false, true, \"Cibles\") %>" onselect="refreshEvent();">							 
		<table class="container" cellpadding="0">
		<% if (EventCategory.QST.toString().equals(eventCategory)) { %>	
			<tr>
				<td colspan="3">
					<fl:grid  name="EVTQST" ajaxUrl="/embedded_list_ajax_criteria.fl"/>
				</td>
			</tr>
		<% } else if (EventCategory.TMK.toString().equals(eventCategory)) { %>
			<tr>
				<td colspan="3">
					<fl:grid  name="EVTTMK" ajaxUrl="/embedded_list_ajax_criteria.fl"/>	
				</td>
			</tr>
		<% } else {
		%>		
			<tr>
				<td colspan="3">
					<fl:grid name="EVTOTHER" ajaxUrl="/embedded_list_ajax_criteria.fl"/>	
				</td>
			</tr>
		<% 
			} 
		%>

		</table>
  	</fl:sTab>
	<fl:sTab id="EVENT1" title="<%= context.getAutoDisplayManager().getTitle(session, \"Event\", \"Evénement 1\") %>" visible="<%= context.getAutoDisplayManager().hasEntry(\"Event\", \"Evénement 1\") %>">
		<fl:autodisplay name="Event" zone="Evénement 1"/>
	</fl:sTab>
	<%/*
	<!-- 
	<fl:sTab id="GuestLst" title="Utils.getMessage(session, \"L65CE\", true, \"Validations\")" onselect="refreshGuestLst();">	
		<fl:grid name="GUESTLST" ajaxUrl="\"/embedded_list_ajax.fl?GliEvtID=\" + id"/>					
  	</fl:sTab>
  	 -->	
	*/
	%>
  	<fl:sTab id="POPULATIONS_FILLES" title="<%= Utils.getMessage(session, \"L6037\", true, \"Populations\") %>" onselect="refreshPopFilles();">
		<fl:grid name="PPF_EMB" ajaxUrl="<%= \"/embedded_list_ajax.fl?PopEvtID=\" + id %>" />	
	</fl:sTab>	
	<fl:sTab id="RETURNS" title="<%= Utils.getMessage(session, \"L2039\", true, \"Interactions\") %>" onselect="refreshInteraction();">
		<fl:grid name="INTT_EMB" ajaxUrl="<%= \"/embedded_list_ajax.fl?code=INTT_EMB&IntPvtID:PvtEventID=\" + id %>"/>
	</fl:sTab>
</fl:smallTabs>

</fl:bigTabs>
