<%@page import="ro.emid.common.db.CategoryAccessDB" %>
<%@page import="java.util.Date" %>
<%@ page import="ro.emid.common.types.Category"%>
<%@ page import="ro.emid.common.types.Incident"%>
<%@ page import="ro.emid.common.utils.ObjectUtils" %>
<%@ page import="ro.emid.common.db.AccessDB" %>
<%@ page import="ro.emid.incidente.IncidenteSessionUtils" %>

<%
    IncidenteSessionUtils.removeFormatia(session);

    long centruId = ObjectUtils.getLongValue(request.getParameter("centruId"), -2);
    if (centruId > 0) {
        IncidenteSessionUtils.setCentruId(session, centruId);
    } else {
        centruId = IncidenteSessionUtils.getCentruId(session);
    }
%>
<%@include file="declaratii.jsp"%>
<%
    centruExploatare.setShowAsLink(false);
%>

<TABLE border=0 cellPading=0 cellSpacing=0 width="100%">
    <TR>
        <TD>
           <%@ include file="../header-localizare.jsp"%>
        </TD>
        <TD align="RIGHT">
            <%--<A href="javascript: alert('[to-do]');" class="link">Lista ultimelor 10 incidente per total</A>--%>
            <%--<IMG alt=FAQ border=0 width=12 height=13 hspace=3 src="<%= AppConstants.WEB_RESOURCE_PATH + "/images/icon_mini_search.gif" %>">--%>
        </TD>
    </TR>
</TABLE>
<TABLE border=0 cellPadding=2 cellSpacing=1 width="100%" class="gSAPTHEAD" style="BACKGROUND-COLOR: white">
    <TR>
        <TH class="gsapthead" colSpan=2 height=25 noWrap><%=sucursala.isCuSectiiSiCentre() ? "Centre de Exploatare" : "Formatii de lucru"%> Electrica:</TH>
        <TH class="gsapthead" noWrap width=60>Nr.incidente</TH>
        <TH class="gsapthead" noWrap width=150>Ultimul incident</TH>
    </TR>
    <% final Category[] formatiiLucru = CategoryAccessDB.getAllCategoriesByParentId( centruId);
        if (null == formatiiLucru || formatiiLucru.length == 0) {%>
    <TR>
        <TD>
            Nu sunt formatii de lucru definite ...
        </TD>
    </TR>
    <%} else for(int i=0; i<formatiiLucru.length; i++) {
        final String td_color;
        if (i%2 == 0) { td_color = "BACKGROUND-COLOR: #CACADF"; }
        else { td_color = "BACKGROUND-COLOR: #D9D9E8";}%>
    <TR>
        <TD style="<%=td_color%>" align=middle height=50 vAlign=center><IMG
                height=25
                src="<%= AppConstants.WEB_RESOURCE_PATH + "/images/folder_big.gif" %>"
                width=46></TD>
        <TD style="<%=td_color%>" class="row1" height=50 width="100%">
            <A class="link" href="<%=AppConstants.APP_NAME%>?action=showEvenimente&formatiaId=<%=formatiiLucru[i].getId()%>"><%=formatiiLucru[i].getName()%></A>&nbsp;
            <%=(formatiiLucru[i].getDescription() == null) ? "": '-' + formatiiLucru[i].getDescription()%>
        </TD>
        <TD style="<%=td_color%>" align=middle class=row2 height=50 vAlign=center>
            <SPAN class=gensmall><%=AccessDB.getCount("incidente", " AND FORMATIA_DE_LUCRU_ID=" + formatiiLucru[i].getId())%></SPAN>
        </TD>
        <TD style="<%=td_color%>" align=middle class=row2 height=50 noWrap vAlign=center><SPAN class=gensmall>
                <%
                    final String[] zilele_saptamanii = {"Duminica", "Luni", "Marti", "Miercuri", "Joi", "Vineri", "Sambata"};
                    int year = 0;
                    int day_of_week = 0;
                    Date data = null;
                    final Incident inc = null;
                    if (inc != null) {
                        data = inc.getDataProducere();
                        day_of_week = data.getDay();
                        year = data.getYear();
                    } else year = 0;
                %>
                <%=(year == 0) ? "neintrodusa" : zilele_saptamanii[day_of_week] + ", " +sdf1.format(data)%>
               </SPAN>
        </TD>
    </TR>
    <%}%>
</TABLE>
 
