<%@ page import="ro.emid.common.db.CategoryAccessDB" %>
<%@ page import="ro.emid.common.types.CategoryCheckData" %>
<%@ page import="ro.emid.common.types.Category" %>
<%@ page import="ro.emid.incidente.IncidenteSessionUtils" %>
<%@ page import="ro.emid.common.constants.AppConstants" %>
<%@ page import="ro.emid.common.constants.RoleConstants" %>

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

<% if (request.getAttribute("act") !=null) {%>
    <script type="text/javascript">
        window.opener.categoriesChecked();
        window.close();
    </script>
<%}else{%>

<style type="text/css">
    .filiala{
        color :#990033;
    }

    .sucursala{
        color: #330099 ;
    }

    .centru{
        color : #006600;
        
    }
</style>

<%
    final CategoryCheckData checkData = IncidenteSessionUtils.getCategoriiSelectate(session);
%>

<TABLE class="gsaptd" align=center border=0 cellPadding=10 cellSpacing=0 width="100%">
    <TBODY>
        <TR>
            <TD>
                <!--Selectate: <span id="countSelected">0</span>-->
                <form name="zaforma" action="<%=AppConstants.APP_NAME%>" method="post" style="margin: 0px">
                    <input type="hidden" name="action" value="saveCheckedCategories" />
                    <div class="treeContainer" id="treeCategorii" style="overflow: auto; height: 530px">
                        <% final Category[] filiale = CategoryAccessDB.getAllCategoriesByParentId( -1);%>
                        <% for (int i = 0; i < filiale.length; i++) {
                            final Category f = filiale[i];
                            if( user.getIeLevel() >= RoleConstants.NIVEL_FILIALA && f.getId() !=  user.getIeFilialaId()) continue; //skip
                        %>
                            <div class="filiala" checkName="filialaId" checkValue="<%=f.getId()%>" checked="<%=ro.emid.common.utils.Util.exists( checkData.getIdFiliale(), f.getId())%>" expanded="<%=IncidenteSessionUtils.getFilialaId( session) == f.getId()%>">
                                <span class="nodeText"><%=f.getName()%></span>
                                <div class="childsContainer">
                                    <% final Category [] sucursale = CategoryAccessDB.getAllCategoriesByParentId( f.getId());%>
                                    <% for (int j = 0; j < sucursale.length; j++) {
                                        final Category s = sucursale[j];
                                        if( user.getIeLevel() >= RoleConstants.NIVEL_SUCURSALA  && s.getId() != user.getIeSucursalaId()) continue;
                                    %>
                                        <div class="sucursala" checkName="sucursalaId" checkValue="<%=s.getId()%>" checked="<%=ro.emid.common.utils.Util.exists( checkData.getIdSucursale(), s.getId())%>" expanded="<%=IncidenteSessionUtils.getSucursalaId( session) == s.getId()%>" >
                                            <span class="nodeText"><%=s.getName()%></span>
                                            <div class="childsContainer">
                                                <% final Category [] centre = CategoryAccessDB.getAllCategoriesByParentId( s.getId());%>
                                                <% for (int k = 0; k < centre.length; k++) {
                                                    final Category c = centre[k];
                                                    if( user.getIeLevel() >= RoleConstants.NIVEL_CENTRU && c.getId() != user.getIeCentruId()) continue;
                                                %>
                                                    <div class="centru" checkName="centruId" checkValue="<%=c.getId()%>" checked="<%=ro.emid.common.utils.Util.exists( checkData.getIdCentre(), c.getId())%>">
                                                        <span class="nodeText"><%=c.getName()%></span>
                                                    </div>
                                                <%}%>
                                            </div>
                                        </div>
                                    <%}%>
                                </div>
                            </div>
                        <%}%>
                    </div>
                    <br>
                    <input type="submit" value="OK">&nbsp;&nbsp;
                    <input type="reset" value="Reset">&nbsp;&nbsp;
                    <input type="button" value="Renunta" onclick="window.close()">
                </form>
            </TD>
        </tr>
    </TBODY>
</TABLE>

<script type="text/javascript">
    var countSelected = 0;
    var treeCategorii = new StaticTree( "treeCategorii", false, true, function( node){
    });
</script>
<%}%>


