<%/******************************************************************************
 * Copyright (c) 2000-2013 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.synchro.SyncUser.SynchroParamType"%>
<%@page import="com.edeal.frontline.synchro.googleapps.GoogleAppsConstants.GoogleAppsActorOptions"%>
<%@page import="com.edeal.frontline.synchro.SyncUser.EdealActorSynchroParams"%>
<%@page import="com.edeal.frontline.synchro.SyncUser"%>
<%@page import="java.lang.reflect.Method"%>
<%@page import="org.apache.commons.lang.StringUtils"%>
<%@page import="java.util.HashMap"%>
<%@page import="java.util.Iterator"%>
<%@page import="com.edeal.frontline.synchro.webdavex.WebDavExConstants.WebDavExActorSynchroOptions"%>
<%@page import="com.edeal.frontline.synchro.webdavex.WebDavExConstants"%>
<%@page import="com.edeal.frontline.synchro.domino.DominoConstants.DominoActorSynchroParams"%>
<%@page import="com.edeal.frontline.synchro.domino.DominoConstants"%>
<%@page import="com.edeal.frontline.synchro.SyncConstants.ExternalSystemType"%>
<%@page import="com.edeal.frontline.LicenceManager.LicenceType"%>
<%@page import="com.edeal.frontline.synchro.googleapps.GoogleAppsConstants"%>
<%@page import="com.edeal.frontline.synchro.exchwebservice.EWSConstants.ExchangeWSActorSynchroOptions"%>
<%@page import="com.edeal.frontline.helper.BasicHelper"%>
<%@page import="com.edeal.frontline.helper.custom.ActorHelper"%>
<%@page import="com.edeal.frontline.helper.ActorBaseHelper"%>
<%@ 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="com.edeal.frontline.DataDictionary" %>
<%@ page import="com.edeal.frontline.EnterpriseBean" %>
<%@ page import="java.util.Date" %>
<%@ page import="java.util.Hashtable" %>
<%@ page import="com.edeal.frontline.FrontlineException" %>
<%@ page import="com.edeal.frontline.ActorBean" %>
<%@ page import="com.edeal.frontline.SalesInvestBean" %>
<%@ page import="java.util.Vector" %>
<%@ page import="com.edeal.frontline.LicenceManager" %>
<%@ page import="com.edeal.frontline.SiteBean" %>
<%@ page import="com.edeal.frontline.services.cti.CTIServiceClient" %>
<%@ page import="com.edeal.frontline.helper.ContextHelper" %>
<%@taglib uri="http://www.e-deal.com/taglib/fl" prefix="fl" %>
<jsp:useBean class="com.edeal.frontline.ActorBean" id="Actor" 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();
	LicenceManager licenceManager = context.getLicenceManager();
	String id = null;
	try {
		id = Actor.getID();
	} catch (FieldNotInitializedException fnie) {
	}
	
	try {
		Actor.getActEmpSta();
	} catch (FieldNotInitializedException fnie) {
		Actor.setActEmpSta(dico.getRefIdByCode("ActEmpSta", "ACTIF"));
	}
	
	Vector nameCompRef = dico.getRefList(session, "ActCpoID");
	Vector valCompRef = dico.getRefList(session, "ActNcoID");
	//GET THE COUNTRY OF EACH SITE
	
	String actSitID = null;
	try {
		actSitID = Actor.getActSitID();
	} catch (FieldNotInitializedException e) {
	}
	
	String countryIDForFormatTel = null;
	
	String sitIDs = "";
	String sitCtrIDs = "";
	String[] fields = {"SitID", "SitCtrID"};
	Vector vect = SiteBean.listSummary(context, fields);
	
	for (int i = 0; i < vect.size(); i++) {
		Hashtable curCtr = (Hashtable)vect.elementAt(i);
		String sitID = (String)curCtr.get("SitID");
		String idCtr = (String)curCtr.get("SitCtrID");
		
		if (i == 0) {
	sitIDs += "\"" + sitID + "\"";
	sitCtrIDs += "\"" + idCtr + "\"";
		} else {
	sitIDs += "," + "\"" + sitID + "\"";
	sitCtrIDs += "," + "\"" + idCtr + "\"";
		}
		
		if (id != null && id.equals(actSitID)) {
	countryIDForFormatTel = idCtr;
		}
	}

	if (countryIDForFormatTel == null) {
		countryIDForFormatTel = dico.getRefIdByCode("EntCtrID", "FR");
	}

	String actFirstNameOnFocus = "if (this.value == '" + Utils.getMessage(session, "F611C", true, "<Prénom>") +  "') { this.value = ''; }";
	String actNameOnFocus = "if (this.value == '" + Utils.getMessage(session, "F611D", true, "<Nom>") +  "') { this.value = ''; }";
	String actFirstNameOnBlur = "if (this.value == '" + Utils.getMessage(session, "F611C", true, "<Prénom>") +  "') { return true; } if (!this.value) { this.value = '" + Utils.getMessage(session, "F611C", true, "<Prénom>") +  "'; } else { this.value = checkString(this.value, 'capitalize'); }";
	String actNameOnBlur = "if (this.value == '" + Utils.getMessage(session, "F611D", true, "<Nom>") +  "') { return true; } if (!this.value) { this.value = '" + Utils.getMessage(session, "F611D", true, "<Nom>") +  "'; } else { this.value = checkString(this.value, 'upper'); }";

	try {
		id = Actor.getID();
	} catch (FieldNotInitializedException fnie) {
	}	

	try {
		Actor.getActName();
	} catch (FieldNotInitializedException fnie) {
		Actor.setActName(Utils.getMessage(session, "F611D", true, "<Nom>"));
	}	

	try {
		Actor.getActFstName();
	} catch (FieldNotInitializedException fnie) {
		Actor.setActFstName(Utils.getMessage(session, "F611C", true, "<Prénom>"));
	}	

	boolean isSalesInvestActive = SalesInvestBean.isSalesInvestActive(context);
	if (isSalesInvestActive) {
		try {
	Actor.getActCoeffPondComCost();
		}catch (FieldNotInitializedException ex){
	Actor.setActCoeffPondComCost(1);
		}
	}

	String[] softwareCodes = licenceManager.getLicencedSoftwareCodes();
	
	ActorHelper actHelper = null;
	try {
		actHelper = BasicHelper.factory(Actor);
	} catch (FrontlineException e) {
		logger.error("Could not get ActorHelper(?!)", e);
	}

	HashMap<Enum, String> syncOptions = null;
	try {
		syncOptions = actHelper.getActSyncOptions();
	} catch (FrontlineException fe) {
	}

	String syncType;
	try {
		syncType = Actor.getActSyncType();
	} catch (Exception e) {
		syncType = "";
	}

	String actSyncType = null;
	try {
		actSyncType = dico.getRefCode("ActSyncType", syncType);
	} catch (Exception e) {
	}
	
	if (actSyncType == null) {
		syncOptions = new HashMap<Enum, String>();
	}
%>
<script type="text/javascript" language="javascript">
	var sitIDs = new Array(<%=sitIDs%>);
	var sitCtrIDs = new Array(<%=sitCtrIDs%>);
	var eraseFaxOnSubmit = false;
	var syncType = '<%=syncType%>';
	
	function doSyncTypeClick() {
		var f = document.forms[0];
		var syncTypeValue = '';
		for (var cnt = 0; cnt < f.ActSyncType.length; cnt++) {
			if (f.ActSyncType[cnt].checked == true) {
				syncTypeValue = f.ActSyncType[cnt].value;
			}
		}
		
		if (syncType != syncTypeValue) {
			f.ActSyncModel.value = '';
			f.lblActSyncModel.value = '';
			syncType = syncTypeValue; doRefresh();
		}
	}
	
	function computeCompetencies() {
		var result = '';
		for (var i = 0 ; i < <%=nameCompRef.size()%> ; i++) {
			var niv = 'NiveauComp' + i;
			var combo = window.document.forms[0].elements[niv];
			if (i > 0) {
				result += ';';
			}
			result += combo.options[combo.selectedIndex].value;
		}
		return result;
	}
	
	function doAllFormatTel() {
		var f = document.forms[0];
		doFormatTel(f.ActPhone, '<fl:getMessage code="L30B8" alt="Saisie du téléphone" js="true"/> :', f.CountryIDForFormatTel);
		doFormatTel(f.ActMobile, '<fl:getMessage code="L62AB" alt="Saisie du mobile" js="true"/> :', f.CountryIDForFormatTel);
		doFormatTel(f.ActFax, '<fl:getMessage code="L30B9" alt="Saisie du fax" js="true"/> :', f.CountryIDForFormatTel);
	}

	function doActSitIDChange() {
		var f = document.forms[0];
	
		doEpureTel(f.ActPhone, f.ActPhone, f.CountryIDForFormatTel);
		doEpureTel(f.ActMobile, f.ActMobile, f.CountryIDForFormatTel);
		doEpureTel(f.ActFax, f.ActFax, f.CountryIDForFormatTel);
	
		if (f.ActSitID == null || f.ActSitID.value == "") {
			f.CountryIDForFormatTel.value = entCtrID;
	   	} else {
	   		var sitID = f.ActSitID.value;
	   		var posImp = 0;
	   		while ((posImp < sitIDs.length) && (sitIDs[posImp] != sitID)) {
	   			posImp++;
	   		}
	   		f.CountryIDForFormatTel.value = sitCtrIDs[posImp];
		}
		doAllFormatTel();
	}
	
	function doActPhoneChange() {
		var f = document.forms[0];
		var phoneField = f.ActPhone;
		var faxField = f.ActFax;
		var countryField = document.forms[0].CountryIDForFormatTel;
		if (faxField.value == '' && phoneField.value.length > 3) {
			faxField.value = phoneField.value.substring(0, phoneField.value.length - 3);
			eraseFaxOnSubmit = true;
		}
		doFormatTel(phoneField, '<fl:getMessage code="L30B8" alt="Saisie du téléphone" js="true"/> :', countryField);
	}
	
	function doActMobileChange() {
		var f = document.forms[0];
		var mobileField = f.ActMobile;
		var countryField = document.forms[0].CountryIDForFormatTel;
		doFormatTel(mobileField, '<fl:getMessage code="L62AB" alt="Saisie du mobile" js="true"/> :', countryField);
	}
	
	function doActFaxChange() {
		var f = document.forms[0];
		var faxField = f.ActFax;
		var countryField = document.forms[0].CountryIDForFormatTel;
		doFormatTel(faxField, '<fl:getMessage code="L30B9" alt="Saisie du fax" js="true"/> :', countryField);
		eraseFaxOnSubmit = false;
	}
	
	function doZipChange() {
		var f = document.forms[0];
		retrieveCity(f.ActCtrID.options[f.ActCtrID.selectedIndex].value, f.ActZip.value, 'ActCity'); 
	}
	
	function doCountryChange() {
		var f = document.forms[0];
		retrieveCity(f.ActCtrID.options[f.ActCtrID.selectedIndex].value, f.ActZip.value, 'ActCity'); 
	}
	
	function doRefresh() {
		var f = document.forms[0];
		//f.action = '<fl:link url="/refresh_actor.fl?1=1"/>&ActEdit_selectedSTab=' + ActEdit_divIds.indexOf('SYNCHRO');
		f.action = '<fl:link url="/refresh_actor.fl?1=1"/>&ActEdit_selectedSTab=' + $.inArray("SYNCHRO", ActEdit_divIds)

		if (f.ActNcoID)
		f.ActNcoID.value = computeCompetencies();
		
		// Preperation des valeurs des licences
		fillInSyncFields();
		
		// Parse the actSyncOptions fields
		parseActSyncOptions();
		
		doExitConf = false;
		presentFieldsValue();
		document.forms[0].submit();
	}
	
	function doSubmit() {
		var f = document.forms[0];
		if (f.ActLogin && f.ActLogin.value != '') {
			if (f.ActPwd.value == '') {
				alert('<fl:getMessage code="M2032" alt="Veuillez entrer un mot de passe" js="true"/>');
				f.ActPwd.focus();
				return false;
			} else if (f.ActPwd.value != f.confirmActPwd.value) {
				alert('<fl:getMessage code="M2033" alt="Veuillez reconfirmer votre mot de passe" js="true"/>');
				f.confirmActPwd.focus();
				return false;
			}
		}
		if (f.ActNcoID)
			f.ActNcoID.value = computeCompetencies();
		
		if (f.ActFstName && f.ActFstName.value == '<fl:getMessage code="F611C" alt="<Prénom>" js="true"/>') {
			f.ActFstName.value = '';
		}
	
		if (f.ActName && f.ActName.value == '<fl:getMessage code="F611D" alt="<Nom>" js="true"/>') {
			f.ActName.value = '';
		}
		
		if (f.ActName && f.ActName.value == '') {
			document.getElementById('ActName_msg').style.display = "inline";
			alert('<fl:getMessage code="L63B1" alt="Veuillez saisir un nom" js="true"/>');
			f.ActName.focus();
			return false;
		}
		
		if (eraseFaxOnSubmit) {
			f.ActFax.value = '';
		}
		
		if (f.ActMail){
			var actmailVal = f.ActMail.value;
			if (actmailVal != null && actmailVal.length > 0){
				if (!checkEmail(actmailVal)){ 
					alert('<fl:getMessage code="L6631" alt="Veuillez vérifier votre adresse électronique" js="true"/>');
					f.ActMail.focus();
					return false;
				}
			}
		}	
		
		if (f.ActEmpSta.value == '') {
			alert('<fl:getMessage code="M9045" alt="Veuillez choisir un état pour l\'employé" js="true"/>');
			f.ActEmpSta.focus();
			return false;
		}
		
		// Preperation des valeurs des licences
		fillInSyncFields();
		
		// Parse the actSyncOptions fields
		parseActSyncOptions();
		
		return true;
	}
	
	function fillInSyncFields() {
		var f = document.forms[0];
	
		var permLicStr = '';
		var floatLicStr = '';
		
		<%for (String sfwCode : softwareCodes) {%>
			if (f.Lic_<%=sfwCode%>){
				if (f.Lic_<%=sfwCode%>[1].checked) permLicStr = addSfwCode(permLicStr, '<%=sfwCode%>'); 
				if (f.Lic_<%=sfwCode%>[2].checked) floatLicStr = addSfwCode(floatLicStr, '<%=sfwCode%>');
			}
		<%}%>
		
		f.ActPermLics.value = permLicStr;
		f.ActFloatLics.value = floatLicStr;
	}	
	
	function parseActSyncOptions() {
		var str = '';
		var jqueryObj;
		var f = document.forms[0];
		var multivalSep = f.$$multivalSeparator.value;
		
		<%//Iterator<Enum> keys = syncOptions.keySet().iterator();
			for (Enum option : syncOptions.keySet()) {%>
			jqueryObj = $('#ActSyncOpt<%=option.toString()%>');
			if (jqueryObj != null && jqueryObj.val() != '') {
				if (str != '') {
					str += multivalSep;
				}
				
				str += '<%=option.toString()%><%=ActorHelper.ACTOR_SYNCOPTIONS_SEP%>' + jqueryObj.val();
			}
		<%}%>
		
		$('#ActSyncOptions').val(str);
	}

	function addSfwCode(oldCodeStr, codeToAdd) {
		var f = document.forms[0];
	
		if (oldCodeStr != '') {
			oldCodeStr += f.$$multivalSeparator.value;
		}
		
		return (oldCodeStr + codeToAdd);
	}

	function selectModel() {
		var selectUrl = "<fl:webapp/>/select.fl?type=SyncModel&field=ActSyncModel&formIndex=0";
		<%if (StringUtils.isNotEmpty(actSyncType)) {%>
			selectUrl += "&query=" + encodeURIComponent("SymType=<%=Utils.formatToSQL(context, dico.getRefIdByCode("SymType", actSyncType))%>");
		<%}%>
		var win = window.open(selectUrl, 'SelectModel', 'menubar=no,status=no,toolbar=no,scrollbars=yes,resizable=yes,width=500,height=500');
	}
	
	function checkPwdAndSubmit() {
		var f = document.forms[0];

		if (f.ActPwdIsEncrypted.value == "false" && f.ActLogin && f.ActLogin.value != '') {
			if (f.ActPwd.value == '') {
				alert('<fl:getMessage code="M2032" alt="Veuillez entrer un mot de passe" js="true"/>');
				f.ActPwd.focus();
			} else if (f.ActPwd.value != f.confirmActPwd.value) {
				alert('<fl:getMessage code="M2033" alt="Veuillez reconfirmer votre mot de passe" js="true"/>');
				f.confirmActPwd.focus();
			} else {
				var urlStr = '<fl:webapp/>/check_pwd_ajax.fl?login=' + escape(f.ActLogin.value);
				urlStr += '&pwd=' + escape(f.ActPwd.value);
				$.getJSON(urlStr, function(result) {
					if (result != null){
						if (result.status == "OK"){
							doPwdOK();
						} else if (result.status == "KO"){
							alert('<fl:getMessage code="L8280" alt="Le mot de passe ne respecte pas les règles de sécurité." js="true"/>');
						}
					}
			    });
			}
		} else {
			submit();
		}
	}
	function doPwdOK() {
		submit();
	}
</script>
<fl:form action="/save_actor.fl" bean="Actor" multivalSeparator=";">
<input type="hidden" name="ActFloatLics" value="">
<input type="hidden" name="ActPermLics" value="">
<%-- 	the ActPwdIsEncrypted field indicates whether the value in field ActPwd is already encrypted or not :
				the pwd is encrypted if the value comes from the database and has not been changed,
				the pwd is not encrypted if the value has just been changed --%>
<input id="ActPwdIsEncrypted" name="ActPwdIsEncrypted" type="hidden" value="true"/>
<input type="hidden" name="CountryIDForFormatTel" value="<%=countryIDForFormatTel%>">
<fl:bigTabs objectTitle="<%= Utils.getMessage(session, \"L2089\", false, true, \"Acteur\") %>" ou="<%= \"/edit_actor.fl\" + (id != null ? \"?id=\" + id : \"\") %>">
	<table class="container" cellpadding="0">
		<tr>
			<td class="labelTitreFiche"><fl:label field="ActFstName" labelClassName="labelTitreFiche" code="L2094"/></td>
			<td style="padding-left: 10px; width: 75px;"><fl:input name="Actor" property="ActCivID" alt=""/></td>
			<td style="padding-left: 10px;"><fl:input property="ActFstName" onfocus="<%= actFirstNameOnFocus %>" onblur="<%= actFirstNameOnBlur %>"/></td>
			<td style="padding-left: 10px;" nowrap><fl:input property="ActName" onfocus="<%= actNameOnFocus %>" mandatoryMsgCode="M3013" onblur="<%= actNameOnBlur %>"/><span id="ActName_msg" class="mandatory_alert" style="display: none">!</span></td>
		</tr>
		<tr class="ligne_separation"><td></td></tr>
	</table>
	<table class="container" cellpadding="0">
		<tr>
			<td class="column2">
				<table class="container" cellpadding="0">
					<fl:fieldEdit property="ActCode" unicityMsgCode="M60CE" mandatoryMsgCode="L6294"/>
					<fl:fieldEdit property="ActFunction"/>
					<tr class="fieldline">
						<td class="dataLabel" rowspan="5"><fl:label code="L2037"/></td>
						<td class="dataValue"><fl:input property="ActAd1"/></td>
					</tr>
					<tr class="fieldline">
						<td class="dataValue"><fl:input property="ActAd2"/></td>
					</tr>
					<tr class="fieldline">
						<td class="dataValue"><fl:input property="ActAd3"/></td>
					</tr>
					<tr class="fieldline">
						<td class="dataValue">
							<div class="fieldTable" >
								<table class="fieldTable" cellpadding="0">
									<tr>
										<td class="smallFieldPart"><fl:input property="ActZip" onchange="doZipChange();" size="5" width="auto" nodiv="true"/></td>
										<td class="bigFieldPart"><fl:input property="ActCity" onblur="this.value = checkString(this.value, 'upper');" nodiv="true"/></td>
									</tr>
								</table>
							</div>
						</td>
					</tr>					
					<tr class="fieldline">
						<td class="dataValue"><fl:input property="ActCtrID"/></td>
					</tr>
					<TR class="fieldline">
						<td class="dataLabel"><fl:getMessage code="L6558" alt="Fuseau horaire"/></td>
						<td class="dataValue"><fl:input property="ActTzoID" alt=""/></td>
					</TR>
				</table>
			</td>
			<td class="separation"><div class="separation">&nbsp;</div></td>
			<td class="column2">
				<table class="data_column" cellpadding="0">					
					<fl:fieldEdit property="ActPhone" onchange="doActPhoneChange()"/>
					<fl:fieldEdit property="ActMobile" onchange="doActMobileChange()"/>
					<fl:fieldEdit property="ActTymID" alt=""/>
					<fl:fieldEdit property="ActPinWap" />
					<fl:fieldEdit property="ActFax" onchange="doActFaxChange()"/>
					<fl:fieldEdit property="ActMail"/>
					<fl:fieldEdit property="ActLogin" unicityMsgCode="M60DA"/>
					<fl:fieldEdit property="ActPwd" autocomplete="off" type="password" size="30" onblur="javascript:document.forms[0].ActPwdIsEncrypted.value='false';" onchange="javascript:document.forms[0].ActPwdIsEncrypted.value='false';"/>
					<tr class="fieldline">
						<td class="dataLabel">
							<fl:label code="F207D" forInput="confirmActPwd"/>
						</td>
						<td class="dataValue">
							<div class="input text">
								<input id="confirmActPwd" name="confirmActPwd" type="password" value="<fl:getProperty name="Actor" property="ActPwd" alt="" edit="true"/>" autocomplete="off" class="input text" size="30" maxlength="100" >
							</div>
						</td>
					</tr>									
				</table>
			</td>
		</tr>
		<tr class="ligne_separation"><td></td></tr>
		<tr class="ligne_separation"><td></td></tr>
	</table>
	<%
		if (context.getAutoDisplayManager().hasEntry("Actor", "Acteur 1")) {
	%>
	<fl:autodisplay name="Actor" zone="Acteur 1" title="true" edit="true"/>	
	<%
			}
		%>
	<link href="<fl:webapp/>/css/smalltabs_css.jsp" rel="stylesheet" type="text/css">
	<fl:smallTabs name="ActEdit">
		<fl:sTab id="ORGA" title="<%= Utils.getMessage(session, \"L641E\", false, true, \"Organisation\") %>">
			<fl:autodisplay name="Actor" zone="ActorOrga" edit="true"/>
		</fl:sTab>
		<fl:sTab id="ROLES_SOFTWARE" title="<%= Utils.getMessage(session, \"L6482\", false, true, \"Rôles/Logiciels\") %>">
			<table class="data_column" cellpadding="0">
				<tr>
					<td class="column2">
						<table class="data_column" cellpadding="0">
							<%-- <fl:fieldEdit property="ActDashID"/> --%>
							<tr class="fieldline">
								<td class="dataLabel">
									<fl:label field="ActPicFileName" code="F600A"/>
								</td>
								<td class="dataValue">
									<fl:attach name="Actor" colID="ActPicID" multivalSeparator=";" edit="true" allowedExtensions="'jpg', 'jpeg', 'png', 'gif'"/>
								</td>
							</tr>
							<fl:autodisplay name="Actor" zone="ActorRoles" edit="true" tableDivTag="false" />
						</table>
					</td>
					<td class="separation"><div class="separation"></div></td>
					<td class="column2">
						<table class="data_column" cellpadding="0">
							<tr class="fieldline">
								<td width="100%" id="ActAccessSoftware_label" class="dataLabel">
									<fl:label code="L624A" forInput="ActAccessSoftware" />
									<br>
								<%
									Vector permLics;
															try {
																permLics = Actor.getActPermLics();
															} catch (FieldNotInitializedException e) {
																permLics = new Vector();
															}
															
															Vector flotLics;
															try {
																flotLics = Actor.getActFloatLics();
															} catch (FieldNotInitializedException e) {
																flotLics = new Vector();
															}

															String permStr = Utils.getMessage(session, "L6601", "Permanente");
															String floatStr = Utils.getMessage(session, "L6602", "Flottante");
															String permNAStr = Utils.getMessage(session, "L6603", "Pas des licences permanentes disponible");
															String floatNAStr = Utils.getMessage(session, "L6604", "Pas des licences flottantes disponible");
															String pattribStr = Utils.getMessage(session, "L6605", "Pas attribuée");
								%>
									<table border="0" cellpadding="0" cellspacing="0" width="100%" align="center">
									<%
										for (String softCode : softwareCodes) {
											// Check if the given software is a valid one, meaning it's found in
											// the licence file and if at least one Perm lics or Float lics in licence file
											if(licenceManager.availableSoftwareCode(softCode)){
																	String softName = licenceManager.getLicencedSoftwareName(softCode);
																	String display = (softName == null ? softCode : softName + " (" + softCode + ")");
																	boolean hasPermLic = permLics.contains(softCode);
																	boolean hasFloatLic = flotLics.contains(softCode);
																	
																	boolean canAddPerm = licenceManager.canAddUser(id, softCode, LicenceManager.LicenceType.PermanentLicence);
																	boolean canAddFloat = licenceManager.canAddUser(id, softCode, LicenceManager.LicenceType.FloatingLicence);
									%>
										<tr valign="top">
											<td class="dataLabel" width="40%"><span title="<%=display%>"><%=display%></span></td>
											<td class="dataLabel" width="20%"><input class="checkbox" type="radio" name="<%="Lic_" + softCode%>" value="pasAttrib"<%=!(hasPermLic || hasFloatLic) ? " checked" : ""%>><span id="<%="LicNA_" + softCode%>_label" for="<%="Lic_" + softCode%>" title="<%=pattribStr%>"><%=pattribStr%></span></td>
											<td class="dataLabel" width="20%"><input class="checkbox" type="radio" <%=canAddPerm ? "" : "disabled=\"true\""%> name="<%="Lic_" + softCode%>" value="perm"<%=hasPermLic ? " checked" : ""%>><span id="<%="LicPerm_" + softCode%>_label" for="<%="Lic_" + softCode%>" title="<%=canAddPerm ? permStr : permNAStr%>"><%=permStr%></span></td>
											<td class="dataLabel" width="20%"><input class="checkbox" type="radio" <%=canAddFloat ? "" : "disabled=\"true\""%> name="<%="Lic_" + softCode%>" value="float"<%=hasFloatLic ? " checked" : ""%>><span id="<%="LicFlt_" + softCode%>_label" for="<%="Lic_" + softCode%>" title="<%=canAddFloat ? floatStr : floatNAStr%>"><%=floatStr%></span></td>
										</tr>
									
								<%
											}
																		}
																	%>
									</table>
								</td>
							</tr>
						</table>
					</td>
				</tr>
			</table>
		</fl:sTab>
		<fl:sTab id="SALES" title="<%= Utils.getMessage(session, \"L60F4\", false, true, \"Sales\") %>">
			<table class="data_column" cellpadding="0">
				<tr>
					<td class="column2">
						<table class="data_column" cellpadding="0">
							<fl:fieldRead property="ActDoneBus" />
							<fl:fieldRead property="ActWonBus" />
							<fl:fieldRead property="ActRunBus" />
							<fl:fieldRead property="ActVolWon" postText="&nbsp;%"/>
							<fl:fieldRead property="ActValWon" postText="&nbsp;%"/>
						</table>
					</td>
					<td class="separation"><div class="separation"></div></td>
					<td class="column2">
						<table class="data_column" cellpadding="0">
							<fl:fieldRead property="ActCAWon" postText="&nbsp;&euro;"/>
							<fl:fieldRead property="ActCALost" postText="&nbsp;&euro;"/>
							<fl:fieldEdit property="ActAim"/>
							<fl:fieldEdit property="ActCoeffPondComCost"/>
							<fl:fieldEdit property="ActSector" multivalSeparator=";"/>
						</table>
					</td>
				</tr>
			</table>	
		</fl:sTab>
		<%-- Insert a CTI tab if there is a known CTI provider that needs specific actor fields. --%>
		<%
			CTIServiceClient cti = null;
			boolean isVocalcomCTI = false;
			boolean isCCACTI = false;
			boolean isGenesysCTI = false;
			boolean isC3TCTI = false;
			try {
				cti = (CTIServiceClient)context.getServiceManager().getServiceClient(session, "CTI");
				isVocalcomCTI = ("vocalcom".equalsIgnoreCase(cti.getImplementation().getProviderId()));
				isCCACTI = ("cca".equalsIgnoreCase(cti.getImplementation().getProviderId()));
				isGenesysCTI = ("genesys".equalsIgnoreCase(cti.getImplementation().getProviderId()));
				isC3TCTI = ("C3T".equalsIgnoreCase(cti.getImplementation().getProviderId()));
			} catch (Exception e) {
				logger.warn("Error in CTI service :\nMessage : " + e.getMessage() + "\nCause : " + e.getCause());
			}
			   	if (cti != null && isVocalcomCTI) {
		%>
		<fl:sTab id="CTI" title="CTI" visible="<%= isVocalcomCTI %>">
			<div>
				<fl:autodisplay name="Actor" zone="ActorCTIVocalcom" edit="true" title="true"/>
			</div>
		</fl:sTab>
		<%
			} else if (cti != null && isCCACTI) {
		%>
			<fl:sTab id="CTI" title="CTI" visible="<%= isCCACTI %>">
				<table class="data_column" cellpadding="0">
					<tr valign="top">
						<td class="transparent" style="text-align: right"><fl:getMessage code="LFFFF" alt="CCA N° d'agent"/></td>
						<td><fl:input property="ActCCANumAgent_" alt=""/></td>
						<td class="transparent" style="text-align: right"><fl:getMessage code="LFFFF" alt="CCA groupe de traitement"/></td>
						<td><fl:input property="ActCCAProcGroup_" alt=""/></td>
						<td class="transparent" style="text-align: right"><fl:getMessage code="LFFFF" alt="CCA mot de passe"/></td>
						<td><fl:input property="ActCCAPassword_" alt="" type="password"/></td>
					</tr>
				</table>
			</fl:sTab>
		<%
			} else if (cti != null && isGenesysCTI) {
		%>
		<fl:sTab id="CTI" title="CTI" visible="<%= isGenesysCTI %>">
			<div>
				<fl:autodisplay name="Actor" zone="Profil Genesys" edit="true" />
			</div>
		</fl:sTab>
		<%
			} else if (cti != null && isC3TCTI) {
				%>
				<fl:sTab id="CTI" title="CTI" visible="<%= isC3TCTI %>">
					<table class="data_column" cellpadding="0">
						<fl:fieldEdit property="ActC3TAgentLogin_" alt="Identifiant de l'agent I-Reflet"/>
						<fl:fieldEdit property="ActC3TAgentPassword_" alt="Mot de passe de l'agent I-Reflet"/>
					</table>
				</fl:sTab>
		<%}%>
		<fl:sTab id="SERVICE" title="<%= Utils.getMessage(session, \"F0048\", false, true, \"Service\") %>" displayGroup="SERVICE">
			<table class="data_column" cellpadding="0">
				<tr>
					<td class="column2">
						<table class="data_column" cellpadding="0">
							<fl:fieldEdit property="ActCsoID"/>
						</table>
					</td>
					<td class="separation"><div class="separation"></div></td>
					<td class="column2">
						<table class="data_column" cellpadding="0">
							<%
							Vector idValObject = null;
							Vector idCompObject = null;
							try {
								idValObject = Actor.getActNcoID();
							} catch (FieldNotInitializedException ex) {
								idValObject = new Vector();
							}
							try {
								idCompObject = Actor.getActCpoID();
							} catch (FieldNotInitializedException ex) {
								idCompObject = new Vector();
							}
							String hiddenIdComp = "";
							String hiddenValues = "";
							for (int i = 0; i < nameCompRef.size(); i++) {
								Vector currComp = (Vector) nameCompRef.elementAt(i);
								String currCompID = (String) currComp.elementAt(0);
								String currCompName = (String) currComp.elementAt(1);
								int index=idCompObject.indexOf(currCompID);
								String currObjectValue;
								try {
									if (index >= 0) {
										currObjectValue = (String)idValObject.elementAt(index);
									} else {
										currObjectValue = dico.getRefIdByCode("ActNcoID", "ZERO");
									}
								} catch (Exception e) {
									currObjectValue = "0";
								}
								hiddenIdComp += (i == 0 ? "" : ";" ) + currCompID;
								hiddenValues += (i == 0 ? "" : ";" ) + currObjectValue;
						%>
								<tr class="fieldline">
									<td class="dataLabel"><label for="NiveauComp<%= i %>"><%= currCompName %></label></td>
									<td class="dataValue">
										<div class="input select"><select class="input select" id="NiveauComp<%= i %>" name="NiveauComp<%= i %>"><%
									 		for (int j = 0; j < valCompRef.size(); j++) {
												Vector currVal = (Vector) valCompRef.elementAt(j); %>
											<option value="<%= (String)currVal.elementAt(0) %>"<% if(currObjectValue.equals((String)currVal.elementAt(0))) { %> selected<% } %>><%= ((Double)currVal.elementAt(1)).intValue() %></option><%
											} %>
										</select></div>
									</td>
								</tr>
						<%	} %>
						</table>
					</td>
				</tr>
			</table>
			<input name="ActCpoID" type="hidden" value="<%= hiddenIdComp %>">
			<input name="ActNcoID" type="hidden" value="<%= hiddenValues %>">
			<input name="NbComp" type="hidden" value="<%= nameCompRef.size() %>">
		</fl:sTab>
		<fl:sTab id="SYNCHRO" title="<%= Utils.getMessage(session, \"L6422\", false, true, \"Synchronisation\") %>">
			<input type="hidden" id="ActSyncOptions" name="ActSyncOptions" value="<fl:getProperty name="Actor" property="ActSyncOptions" alt="" />" >
			<table class="container" cellpadding="0">
				<tr>
					<td class="column2">
						<table class="data_column" cellpadding="0">
							<fl:fieldEdit property="ActSyncType" alt="" type="buttons" onclick="doSyncTypeClick();"/>
						</table>
					</td>
					<td class="separation"><div class="separation"></div></td>
					<td class="column2">
						<table class="data_column" cellpadding="0">
							<fl:fieldEdit property="ActSyncModel" selectUrl="javascript:selectModel();"/>
						</table>
					</td>
				</tr>
			<% if (syncOptions != null) {
				Iterator<Enum> iter = syncOptions.keySet().iterator();
				while (iter.hasNext()) {
					Enum key1 = iter.next();
					String value1 = StringUtils.defaultIfEmpty(syncOptions.get(key1), "");
					String msgCode;
					String msgCodeDefault;
					SynchroParamType type1 = null;
					SynchroParamType type2 = null;
					
					try {
						Method meth = key1.getClass().getMethod("getMsgCode");
						msgCode = (String)meth.invoke(key1);
					} catch (Exception e) {
						msgCode = "XXXXX";
					}
					
					try {
						Method meth = key1.getClass().getMethod("getMsgCodeDefault");
						msgCodeDefault = (String)meth.invoke(key1);
					} catch (Exception e) {
						msgCodeDefault = "XXXXX";
					}
					
					try {
						Method meth = key1.getClass().getMethod("getParamType");
						type1 = (SynchroParamType)meth.invoke(key1);
					} catch (Exception e) {
					}
					
					String msg1 = Utils.getMessage(session, msgCode, msgCodeDefault);
					
					Enum key2 = null;
					String value2 = "";
					String msg2 = null;
					
					if (iter.hasNext()) {
						key2 = iter.next();
						value2 = StringUtils.defaultIfEmpty(syncOptions.get(key2), "");
						
						try {
							Method meth = key2.getClass().getMethod("getMsgCode");
							msgCode = (String)meth.invoke(key2);
						} catch (Exception e) {
							msgCode = "XXXXX";
						}
						
						try {
							Method meth = key2.getClass().getMethod("getMsgCodeDefault");
							msgCodeDefault = (String)meth.invoke(key2);
						} catch (Exception e) {
							msgCodeDefault = "XXXXX";
						}
						
						try {
							Method meth = key2.getClass().getMethod("getParamType");
							type2 = (SynchroParamType)meth.invoke(key2);
						} catch (Exception e) {
						}
						
						msg2 = Utils.getMessage(session, msgCode, msgCodeDefault);
					}
			%>
				<tr>
					<td class="column2">
						<table class="data_column" cellpadding="0">
							<tr class="fieldline">
								<td id="ActSyncOpt<%= key1 %>_label" class="dataLabel"><div><label for="ActSyncOpt<%= key1 %>" title="<%= msg1 %>"><%= msg1 %></label></div></td>
								<td id="ActSyncOpt<%= key1 %>_value" class="dataValue"><div><input id="ActSyncOpt<%= key1 %>" name="ActSyncOpt<%= key1 %>" type="<%= (type1 == null ? "text" : type1.toString()) %>" value="<%= value1 %>" class="input text"></div></td>
							</tr>
						</table>
					</td>
					<td class="separation"><div class="separation"></div></td>
					<td class="column2">
						<table class="data_column" cellpadding="0">
							<tr class="fieldline">
								<% if (key2 != null) { %>
									<td id="ActSyncOpt<%= key2 %>_label" class="dataLabel"><div><label for="ActSyncOpt<%= key2 %>" title="<%= msg2 %>"><%= msg2 %></label></div></td>
									<td id="ActSyncOpt<%= key2 %>_value" class="dataValue"><div><input id="ActSyncOpt<%= key2 %>" name="ActSyncOpt<%= key2 %>" type="<%= (type2 == null ? "text" : type2.toString()) %>" value="<%= value2 %>" class="input text"></div></td>
								<% } else { %>
									<td>&nbsp;</td><td>&nbsp;</td>
								<% } %>
							</tr>
						</table>
					</td>
				</tr>
				<% }	
			} %>
			</table>
		</fl:sTab>
		<fl:sTab id="ACTOR2" title="<%= context.getAutoDisplayManager().getTitle(session, \"Actor\", \"Acteur 2\") %>" visible="<%= context.getAutoDisplayManager().hasEntry(\"Actor\", \"Acteur 2\") %>">
			<fl:autodisplay name="Actor" zone="Acteur 2" edit="true"/>
		</fl:sTab>
		<fl:sTab id="ACTOR3" title="<%= context.getAutoDisplayManager().getTitle(session, \"Actor\", \"Acteur 3\") %>" visible="<%= context.getAutoDisplayManager().hasEntry(\"Actor\", \"Acteur 3\") %>">
			<fl:autodisplay name="Actor" zone="Acteur 3" edit="true"/>
		</fl:sTab>
	</fl:smallTabs>
</fl:bigTabs>
</fl:form>
