<%@ page errorPage="errorPage.jsp" language="java" session="true" contentType="text/html;charset=ISO-8859-2" %>
<%@ page pageEncoding="UTF-8"%>
<%@ page import="com.etixpert.evolution.gui.servlets.*"%>
<%@ page import="java.util.*"%>
<%@ page import="com.etixpert.evolution.gui.servlets.*"%>
<%@ include file="header.jsp" %>
<%@ include file="check.jsp" %>
<%
	response.setLocale(Locale.GERMAN);
	response.setContentType("text/html; charset=iso-8859-2");
	request.setCharacterEncoding("ISO-8859-2");
%>
<%!
public String getVal(String name, HttpSession session) {
	Map m = (Map)session.getAttribute("downline_etiketten.jsp");
	if (m == null) return "";
	String[] vals = (String[])m.get(name);
	if (vals != null && vals.length>0 && vals[0] != null) return vals[0];
	return "";
}

public String generateSortByOptions(HttpSession session) {
	StringBuffer sb = new StringBuffer();
	sb.append("<option value=\"postcode\">PLZ</option>");
	sb.append("<option value=\"d.id\">Distr ID</option>");
	sb.append("<option value=\"lastname\">Nachname</option>");
	return sb.toString();
}

public String getDefaultRootID(HttpSession session) {
	String loggedID = (String)session.getAttribute("USER_LOGGED_ID");
	int id = Integer.parseInt(loggedID);
	if (id<1000) return "0";
	else return loggedID;
}

public boolean hasDistrFrom(String country_code) throws Exception{
	if (country_code.equals("AT") || country_code.equals("DE")) return true;
	ObjectSearch os = new ObjectSearch("distributor", "id");
	os.setCondition("country_code = ?");
	List res = os.search(new Object[] {country_code});
	if (res.size()>0) return true;
	else return false;
}

public String getCountryOptions(HttpSession session) throws Exception{
	StringBuffer sb = new StringBuffer("");
	Country[] countries = FormHelper.getCountries();
	
	for (int i = 0; i < countries.length; i++) {
		String selected="";
		if (!hasDistrFrom(countries[i].country_code)) continue;
		//if (getVal("countryID", session).equals(countries[i].country_code)) selected=" selected";
		sb.append("<option"+selected+" value=\""+ countries[i].country_post_code + "\">"+countries[i].name+"</option>");
		
	}
	return sb.toString();
}
%>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2">
<link href="main_stat.css" rel="stylesheet" type="text/css">
<SCRIPT LANGUAGE="JavaScript">
<!-- JavaScript code hiding
	function simpleLink(origLink) {
		parent.mainFrame.location = origLink;
	}


	function link(origLink){
		if (top.mainFrame.document.forms.length == 0) {
			simpleLink(origLink);
			return;
		}
		else {
			if (top.mainFrame.document.forms[0].saveState == null) {
				simpleLink(origLink); 
				return;
			}
			top.mainFrame.document.forms[0].saveState.value = top.mainFrame.self.location.pathname;
			top.mainFrame.document.forms[0].link.value = origLink;
			top.mainFrame.document.forms[0].submit();
		}
	}

	function link0(origLink){
		top.mainFrame.document.forms[0].pageAction.value = '';
		if (top.mainFrame.document.forms.length == 0) {
			simpleLink(origLink);
			return;
		}
		else {
			if (top.mainFrame.document.forms[0].saveState == null) {
				simpleLink(origLink); 
				return;
			}
			top.mainFrame.document.forms[0].saveState.value = top.mainFrame.self.location.pathname;
			top.mainFrame.document.forms[0].link.value = origLink;
			top.mainFrame.document.forms[0].submit();
		}
	}

	
 function putFocus(formInst, elementInst) {
  if (document.forms.length > 0) {
   document.forms[formInst].elements[elementInst].focus();
  }
 }
// -->
</SCRIPT>
</head>
<%
	boolean admin = false;
	boolean distributor = false;
	boolean customer = false;
	if	(session.getAttribute("admin")!=null) admin = true;
	if	(session.getAttribute("customer")!=null) customer = true;
		if	(session.getAttribute("distributor")!=null) distributor = true;
%>
<body onLoad="putFocus(0,3);">
<form action="process/downline_etiketten.jsp" method="get">
<br><input type="hidden" name="saveState"/>
<input type="hidden" name="pageAction"/>
<input type="hidden" name="link" value="process/downline_etiketten.jsp"/>
<label for="rootID"><fmt:message key="ROOT_ID"/>:</label>
<input name="rootID" value="<%=getDefaultRootID(session)%>"/><br>
<label for="sortBy"><fmt:message key="SORT_BY"/>:</label>
<select name="sortBy"><%=generateSortByOptions(session)%></select><br>
<label for"email"><fmt:message key="NULL_EMAIL"/>:</label>
<input type="checkbox" checked name="email" value="yes"><br>
<label for"email_display"><fmt:message key="EMAIL_ETIKETTEN"/>:</label>
<input type="checkbox" name="email_display" value="yes"><br>
<label>&nbsp;</label><label>&nbsp;</label><label>Beraterart:</label><br>
<label>Kunde</label><input type="checkbox" checked name="role" value="100">
<label>VIP Kunde</label><input type="checkbox" checked name="role" value="200">
<label>Distributor</label><input type="checkbox" checked name="role" value="300">
<label>Consultant</label><input type="checkbox" checked name="role" value="400"><br>
<label>Teamleader</label><input type="checkbox" checked name="role" value="500">
<label>Manager</label><input type="checkbox" checked name="role" value="600">
<label>Sales Manager</label><input type="checkbox" checked name="role" value="700">
<label>Executive Manager</label><input type="checkbox" checked name="role" value="800"><br>
<label>Director</label><input type="checkbox" checked name="role" value="900">
<label>Executive Director</label><input type="checkbox" checked name="role" value="1000">
<label>Vizerpr&auml;sident</label><input type="checkbox" checked name="role" value="1100">
<label>Royal Diamond</label><input type="checkbox" name="role" checked value="1200"><br>
<label>Royal Platin</label><input type="checkbox" name="role" checked value="1300">
<label>Pr&auml;sident</label><input type="checkbox" name="role" checked value="1400">
<label>Partner</label><input type="checkbox" name="pids" checked value="1">
<label>Partner-Network</label><input type="checkbox" name="pids" checked value="2">
<br>
<br>
<label><fmt:message key="COUNTRY"/>:</label><select name="countryID"><option value="all">Gesamt</option><%=getCountryOptions(session)%></select><br>
<label for="title1"><fmt:message key="TITLE1"/>:</label>
<input maxlength="45" size="50" name="title1" value="<%=getVal("title1", session)%>"/><br>
<label for="title2"><fmt:message key="TITLE2"/>:</label>
<input maxlength="45" size="50" name="title2" value="<%=getVal("title2", session)%>"/><br>
<label>&nbsp;</label>
<a href="javascript:top.mainFrame.document.forms[0].pageAction.value = 'print_downline'; link('process/downline_etiketten.jsp');">
<fmt:message key="PRINT"/></a>
</form>
</body></html>