<%@ page import="ro.emid.administrare.util.logger.LogEntryConstants" %>
<%@ page import="ro.emid.common.constants.GlobalAppConstants" %>
<%@ page import="ro.emid.common.logger.ObjectType" %>
<%@ page import="ro.emid.common.logger.UserAction" %>
<%@ page import="ro.emid.common.types.LogEntryLPD" %>
<%@ page import="ro.emid.common.utils.RequestUtils" %>
<%@ page import="ro.emid.common.utils.StringUtils" %>

<%@ page import="ro.emid.common.utils.pagination.PaginationData" %>
<%@ page import="ro.emid.common.utils.sort.SortController" %>
<%@ page import="ro.emid.common.utils.sort.SortData" %>
<%@ page import="java.util.Date" %>
<%@ page import="java.util.List" %>
<%@ page import="ro.emid.common.constants.AppConstants" %>


<SPAN style="FONT-SIZE: 12px; FONT-WEIGHT: bold">
    Log-uri
    &nbsp;&nbsp;&nbsp;<a class="link" href="<%=AppConstants.APP_NAME%>?action=showLogs" style="font-size:12">Incidente</a>
    &nbsp;&nbsp;&nbsp;<a class="link" href="<%=AppConstants.APP_NAME%>?action=showLogs" style="font-size:12">Callcenter / Deranjamente</a>
    &nbsp;&nbsp;&nbsp;<a class="link" href="<%=AppConstants.APP_NAME%>?action=showLogsLPD" style="font-size:12">Lucrari Programate</a>
    &nbsp;&nbsp;&nbsp;<a class="link" href="<%=AppConstants.APP_NAME%>?action=showLogsLPD" style="font-size:12">Operatiuni Dispecer</a>
</SPAN>
<br />

<%
  /**
     * showLogs
     * @see
     */

    final Date dataStart = (Date) request.getAttribute("r.data_start");
    final Date dataStop  = (Date) request.getAttribute("r.data_stop");

    final SortData sd = (SortData) request.getAttribute("sortData");
    final PaginationData pd = (PaginationData) request.getAttribute("paginationData");

    final List list = (List) request.getAttribute("list");
%>


<table border=0>
    <tr><td>
        <div class="spacer">&nbsp;</div>
        <form action="<%=GlobalAppConstants.APP_NAME%>?action=showLogsLPD" method="post">
            <%=SortController.initSort(sd)%>
            <table class="gsaptd" width="100%">
              <tr><td>

                  Utilizator :
                    <input type="text" name="user" size="18" value="<%=RequestUtils.getString( request, "user")%>" /> 
                  &nbsp;&nbsp;

                  Data :
                    &nbsp;&nbsp;<input type="text" id="data_start" name="data_start" size="18" value="<%=AppConstants.formatx( dataStart)%>" /> <a href="#" id="trigger_data_start" ><img src="<%=AppConstants.WEB_RESOURCE_PATH%>/images/cal.gif" width="16" height="16" border="0" alt="Apasa pt. a selecta data."></a>
                    -
                    &nbsp;&nbsp;<input type="text" id="data_stop" name="data_stop" size="18" value="<%=AppConstants.formatx( dataStop)%>" /> <a href="#" id="trigger_data_stop" ><img src="<%=AppConstants.WEB_RESOURCE_PATH%>/images/cal.gif" width="16" height="16" border="0" alt="Apasa pt. a selecta data."></a>

                  

                  <input type="submit" value="Afiseaza">
              </td></tr>
            </table>
        </form>
    </td></tr>
    <tr><td>
        <table cellpadding=2 cellspacing=1 class="table">
            <thead>
                <tr>
                    <th nowrap width="1%" height=25><%=SortController.printSortableColumn("Data:", LogEntryConstants.SQL.DATA, sd)%></th>
                    <th nowrap width="2%"><%=SortController.printSortableColumn("Utilizator:", LogEntryConstants.SQL.AUTOR, sd)%></th>
                    <th nowrap height=25>Log</th>
                    <th nowrap height=25 width="1%">&nbsp;</th>
                </tr>
            </thead>
            <tbody>
            <% if( list == null || list.size() == 0){ %>
                <tr>
                    <td colspan="5" class="no-data">Nu exista date ...</td>
                </tr>
            <% } else for (int i = 0; i < list.size(); i++) {
                final LogEntryLPD log = (LogEntryLPD) list.get(i); %>

                <tr>
                    <td align="center" nowrap><%=GlobalAppConstants.format(log.getData())%></td>
                    <td align="center" nowrap><%=GlobalAppConstants.format(log.getAutor())%></td>

                    <% if(StringUtils.isZeroLength( log.getAction())){ %>

                        <td>
                            action is null !
                        </td>
                        <td>&nbsp;</td>

                    <% } else if( UserAction.LOGIN.equals( log.getAction())){%>

                        <td>
                            a intrat in aplicatie
                        </td>
                        <td>

                        </td>

                    <% } else if( UserAction.INSERT.equals( log.getAction())){ %>

                        <td>

                            <%  final String objType = ObjectType.Util.getCoolObjectType( log.getObjectType()); %>
                            a inserat <%=objType%> <%=log.getDescriere()%>

                        </td>
                        <td>
                            <% if( ObjectType.EVENIMENT.equals( log.getObjectType())){ %>
                                [<a class="link" href="<%=GlobalAppConstants.APP_NAME%>?action=showIstoricEveniment&idEveniment=<%=log.getObjectId()%>">Istoric</a>]
                            <% } %>

                            <% if( ObjectType.LUCRARE.equals( log.getObjectType())){ %>
                                [<a class="link" href="<%=GlobalAppConstants.APP_NAME%>?action=showIstoricLucrare&idLucrare=<%=log.getObjectId()%>">Istoric</a>]
                            <% } %>
                        </td>


                    <% } else if( UserAction.EDIT.equals( log.getAction())){ %>

                        <td>
                            <%  final String objType = ObjectType.Util.getCoolObjectType( log.getObjectType()); %>
                            a editat <%=objType%> <%=log.getDescriere()%>
                        </td>
                        <td>
                            <% if( ObjectType.EVENIMENT.equals( log.getObjectType())){ %>
                                [<a class="link" href="<%=GlobalAppConstants.APP_NAME%>?action=showIstoricEveniment&idEveniment=<%=log.getObjectId()%>">Istoric</a>]
                            <% } %>

                            <% if( ObjectType.LUCRARE.equals( log.getObjectType())){ %>
                                [<a class="link" href="<%=GlobalAppConstants.APP_NAME%>?action=showIstoricLucrare&idLucrare=<%=log.getObjectId()%>">Istoric</a>]
                            <% } %>
                        </td>


                    <% } else if( UserAction.DELETE.equals( log.getAction())){ %>

                        <td>
                            <%  final String objType = ObjectType.Util.getCoolObjectType( log.getObjectType()); %>
                            a sters <%=objType%> <%=log.getDescriere()%>
                        </td>
                        <td></td>

                    <% } %>
                </tr>
            <% } %>
            </tbody>
        </table>
    </td></tr>
</table>


<script type="text/javascript">

    Calendar.setup({
        inputField  : "data_start",         // ID of the input field
        ifFormat    : "%d.%m.%Y %H:%M",       // the date format
        button      : "trigger_data_start",         // ID of the button
        showsTime   : true
    });

    Calendar.setup({
        inputField  : "data_stop",         // ID of the input field
        ifFormat    : "%d.%m.%Y %H:%M",       // the date format
        button      : "trigger_data_stop",         // ID of the button
        showsTime   : true
    });
</script>
