<%@ page import="ro.emid.common.db.AccessDB" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.LinkedList" %>
<%@ page import="ro.emid.callcenter.util.OpenDataImporter" %>
<%@ page import="ro.emid.common.constants.AppConstants" %>

<%@ include file="../declaratii.jsp"%>

<%
    final String action = request.getParameter("a");
    if( "updateNomenclator".equals( action) ){
        final String []tipNom = request.getParameterValues("update");

        final List tables = new LinkedList();
        if( tipNom != null && tipNom.length > 0) for (int i = 0; i < tipNom.length; i++) {
            final String _tn = tipNom[i];

            if( _tn.equals("judete")){
                tables.add( "DEPTOS");
            }else if( _tn.equals( "municipii")){
                tables.add( "MUNICIPIOS");
            }else if( _tn.equals( "localitati")){
                tables.add( "LOCALIDADES");
            }else if( _tn.equals("strazi")){
                tables.add( "CALLEJERO");
            }else if( _tn.equals("tipuri")){
                tables.add( "TIPOS");
            }
        }

        if( tables.size() > 0){

            OpenDataImporter.importData( (String[]) tables.toArray(new String[ tables.size()]));

        }
    }

    final long countJudeteEmid = AccessDB.getCount2( "syncNomOpen.countJudete", "Count judete EMID", "");
    final long countJudeteOpen = AccessDB.getCount2Open( "syncNomOpen.countJudete", "Count judete OPEN", "");

    final long countMunicipiiEmid = AccessDB.getCount2( "syncNomOpen.countMunicipii", "Count municipii EMID", "");
    final long countMunicipiiOpen = AccessDB.getCount2Open("syncNomOpen.countMunicipii", "Count municipii OPEN", "");

    final long countLocalitatiEmid = AccessDB.getCount2( "syncNomOpen.countLocalitati", "Count localitati EMID", "");
    final long countLocalitatiOpen = AccessDB.getCount2Open( "syncNomOpen.countLocalitati", "Count localitati OPEN", "");

    final long countStraziEmid = AccessDB.getCount2( "syncNomOpen.countStrazi", "Count strazi EMID", "");
    final long countStraziOpen = AccessDB.getCount2Open( "syncNomOpen.countStrazi", "Count strazi OPEN", "");

    final long countTiposEmid = AccessDB.getCount2( "syncNomOpen.countTipuri", "Count tipuri EMID", "");
    final long countTiposOpen = AccessDB.getCount2Open( "syncNomOpen.countTipuri", "Count tipuri OPEN", "");
%>


<div class="spacer"></div>
<b>Actualizare nomenclatoare Open</b>

<br/>
<br/>

<form action="<%=AppConstants.APP_NAME%>?action=syncLocalitatiOpen&a=updateNomenclator" method="post" >
<table border="1">
    <thead>
        <th>&nbsp;</th>
        <th> Nomenclator </th>
        <th> Count EMID </th>
        <th> Count OPEN </th>
    </thead>
    <tbody>
        <tr class="<%=( countJudeteEmid != countJudeteOpen ? "red" : "")%>">
            <td><input type="checkbox" value="judete" name="update"></td>
            <td>1. Judete (DEPTOS) </td>
            <td align="right"> <%=countJudeteEmid%> </td>
            <td align="right"> <%=countJudeteOpen%> </td>
        </tr>

        <tr class="<%=( countMunicipiiEmid != countMunicipiiOpen ? "red" : "")%>">
            <td><input type="checkbox" value="municipii" name="update"></td>
            <td>2. Municipii/Comune (MUNICIPIOS) </td>
            <td align="right"> <%=countMunicipiiEmid%> </td>
            <td align="right"> <%=countMunicipiiOpen%> </td>
        </tr>

        <tr class="<%=( countLocalitatiEmid != countLocalitatiOpen ? "red" : "")%>">
            <td><input type="checkbox" value="localitati" name="update"></td>
            <td>3. Localitati/Sate (LOCALIDADES) </td>
            <td align="right"> <%=countLocalitatiEmid%> </td>
            <td align="right"> <%=countLocalitatiOpen%> </td>
        </tr>

        <tr class="<%=( countStraziEmid != countStraziOpen ? "red" : "")%>">
            <td><input type="checkbox" value="strazi" name="update"></td>
            <td>4. Strazi (CALLEJERO) </td>
            <td align="right"> <%=countStraziEmid%> </td>
            <td align="right"> <%=countStraziOpen%> </td>
        </tr>

        <tr class="<%=( countTiposEmid != countTiposOpen ? "red" : "")%>">
            <td><input type="checkbox" value="tipuri" name="update"></td>
            <td>5. Tipuri (TIPOS) </td>
            <td align="right"> <%=countTiposEmid%> </td>
            <td align="right"> <%=countTiposOpen%> </td>
        </tr>
    </tbody>
</table>
<div class="spacer"></div>
<input type="submit" value="Actualizare">

</form>

<div class="spacer"></div>
<span style="font-size:12px">
    Nota: <br/>
    &nbsp;&nbsp;&nbsp;- Prin actualizarea nomenclatoarelor se intelege copierea datelor din Open in Emid.<br/>
    &nbsp;&nbsp;&nbsp;- Selectati tipul de nomenclator si dati click pe buton Actualizare<br/>
</span>

<style type="text/css">
    .red{
        color: red;
    }
</style>

