<%
/******************************************************************************
 * Copyright (c) 2000-2004 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" import="com.edeal.frontline.*,java.util.*"%>
<%@ page import="com.edeal.frontline.navigation.FlRequest" %>
<%@ page import="com.edeal.frontline.FlContext" %>
<%@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();
	String salesModel = context.getContextParameter("SalesModel");
	
	DataDictionary dico = context.getDataDictionary();
	PopulationBean obj = (PopulationBean)request.getAttribute("Population");
	String id = obj.getID();
	String selID = null;
	String sjoID = null;
	boolean popIsSil = false;
	
	try {popIsSil = obj.isPopIsSil(); } catch (FieldNotInitializedException ex) {}
	int popType = 0;
	try { selID = obj.getPopSelID(); } catch (FieldNotInitializedException ex) {}
	try { sjoID = obj.getPopSjoID(); } catch (FieldNotInitializedException ex) {}
	try { popType = obj.getPopType(); } catch (FieldNotInitializedException ex) {}
	boolean moreThan50entries = true;
	try {
		moreThan50entries = obj.getPopTotNbr() > 50;
	} catch (FieldNotInitializedException e) {
	}
	
	PopulationBean population = null;
	boolean accessSupp = false;
	boolean accessCreate = false;
	try {
		population = new PopulationBean(id, session);
		accessSupp = population.enforceAccess(AccessControlManager.DELETE);
		accessCreate = population.enforceAccess(AccessControlManager.CREATE);
	} catch (AccessDeniedException e) {}
	
	boolean canCreatePopulationEntry = false;
	canCreatePopulationEntry = new PopulationEntryBean(session).enforceAccess(AccessControlManager.CREATE);
	
	String key = (String) context.getContextParameter("GoogleMapKey");
	boolean isMapAvailable = false;
	if (key != null && !"".equals(key)) {
		isMapAvailable = true;
	}
%>

<script language="JavaScript">


function doImportFile() {
	window.open('<fl:link url="<%= \"/import_populationv2.fl?id=\" + id %>" list="false"/>', 'import<%= id %>', 'width=500,height=280,scrollbars,resizable');
}

function doRefreshPopulation() {
	doBackgroundAjax("<fl:webapp/>/refresh_population_ajax.fl?id=<%=id%>");
}

// function doDelete() {
// 	if (window.confirm('<fl:getMessage code="M2004" alt="Etes-vous sûr de vouloir supprimer?" js="true"/>') == true) {
// 		<%
// 		String str = flRequest.computeURL("/delete_object_ajax.fl?type=Population&id="+id);
// 		%>
// 		doAjax('', waitNredirect);
// 	}
// }

function doDelete() {
	if (window.confirm('<fl:getMessage code="M2004" alt="Etes-vous sûr de vouloir supprimer?" js="true"/>') == true) {
		window.location = '<%=flRequest.computeURL("/delete_population.fl?id="+id)%>';
	}
}
function waitNredirect(arrIndex) {
// 	hideWaiting();
	if (eDealXmlhttpArr[arrIndex].readyState == 4){
		window.location = '<fl:link url="/list_criteria.fl?lc=POP_V2"/>'; 
	}
}
</script>
<fl:access name="Population" operation="edit">
	<tr>
		<td class="actions_cell_left"></td>
		<td>
			<div class="actions_tablecell_1">
				<a href="<fl:link url="<%= \"/edit_populationv2.fl?PopType=\" + popType + ( id != null ? \"&id=\" + id : \"\") %>" list="true"/>">
					<p class="actions_tabletext"><fl:getMessage code="A0008" alt="Modifier"/></p>
				</a>
			</div>
		</td>
		<td class="actions_cell_right"></td>
	</tr>
	<tr>
		<td class="actions_cell_left"></td>
		<td class="actions_tablecell_seperator"></td>
		<td class="actions_cell_right"></td>
	</tr>
</fl:access>
<fl:access name="Population" operation="delete">
	<tr>
		<td class="actions_cell_left"></td>
		<td>
			<div class="actions_tablecell_1">
				<a href="javascript:doDelete()">
					<p class="actions_tabletext"><fl:getMessage code="A0007" alt="Supprimer"/></p>
				</a>
			</div>
		</td>
		<td class="actions_cell_right"></td>
	</tr>
	<tr>
		<td class="actions_cell_left"></td>
		<td class="actions_tablecell_seperator"></td>
		<td class="actions_cell_right"></td>
	</tr>
</fl:access>
<fl:access name="Population" operation="edit">
	<tr>
		<td class="actions_cell_left"></td>
		<td>
			<div class="actions_tablecell_1">
				<a href="javascript:doRefreshPopulation()" list="false"/>
					<p class="actions_tabletext"><fl:getMessage code="L7050" alt="Rafraîchir"/></p>
				</a>
			</div>
		</td>
		<td class="actions_cell_right"></td>
	</tr>
	<tr>
		<td class="actions_cell_left"></td>
		<td class="actions_tablecell_seperator"></td>
		<td class="actions_cell_right"></td>
	</tr>
</fl:access>
<%if (popIsSil){ %>
<fl:access name="PopulationEntry" operation="create">
	<tr>
		<td class="actions_cell_left"></td>
		<td>
			<div class="actions_tablecell_1">
				<a href="javascript:doImportFile()">
					<p class="actions_tabletext"><fl:getMessage code="A0015" alt="Importer"/></p>
				</a>
			</div>
		</td>
		<td class="actions_cell_right"></td>
	</tr>
	<tr>
		<td class="actions_cell_left"></td>
		<td class="actions_tablecell_seperator"></td>
		<td class="actions_cell_right"></td>
	</tr>
</fl:access>
<%} %>
	<tr>
		<td class="actions_cell_left"></td>
		<td>
			<div class="actions_tablecell_1">
				<a href="<fl:link url="<%=\"/populationv2_actions.fl?id=\"+ id %>" />">
					<p class="actions_tabletext"><fl:getMessage code="A0010" alt="actions"/></p>
				</a>
			</div>
		</td>
		<td class="actions_cell_right"></td>
	</tr>
	<tr>
		<td class="actions_cell_left"></td>
		<td class="actions_tablecell_seperator"></td>
		<td class="actions_cell_right"></td>
	</tr>
<fl:access name="Population" operation="create">
	<fl:access name="Population" operation="read">
	<tr>
		<td class="actions_cell_left"></td>
		<td>
			<div class="actions_tablecell_1">
				<a href="<fl:link url="<%= \"/populationv2_sample.fl?id=\" + id %>"/>">
					<p class="actions_tabletext"><fl:getMessage code="L615E" alt="Echantillonage"/></p>
				</a>
			</div>
		</td>
		<td class="actions_cell_right"></td>
	</tr>
	<tr>
		<td class="actions_cell_left"></td>
		<td class="actions_tablecell_seperator"></td>
		<td class="actions_cell_right"></td>
	</tr>
	<tr>
		<td class="actions_cell_left"></td>
		<td>
			<div class="actions_tablecell_1">
				<a href="<fl:link url="<%= \"/populationv2_split.fl?id=\" + id %>"/>">
					<p class="actions_tabletext"><fl:getMessage code="L615D" alt="Découpage"/></p>
				</a>
			</div>
		</td>
		<td class="actions_cell_right"></td>
	</tr>
	<%if (isMapAvailable){ %>
	<tr>
		<td class="actions_cell_left"></td>
		<td class="actions_tablecell_seperator"></td>
		<td class="actions_cell_right"></td>
	</tr>
	<tr>
		<td class="actions_cell_left"></td>
		<td>
			<div class="actions_tablecell_1">
				<a href="#" onClick="window.open('populationv2_geotag.fl?id=<%=id%>', 'map', 'width=1024,height=768,scrollbars,resizable');">
					<p class="actions_tabletext"><fl:getMessage code="L80B7" alt="Géolocaliser"/></p>
				</a>
			</div>
		</td>
		<td class="actions_cell_right"></td>
	</tr>
	<%}%>
	</fl:access>
</fl:access>
