<%@ page import="ro.emid.common.db.AdEntryAccessDB" %>
<%@ page import="ro.emid.common.db.framework.DatabaseException" %>
<%@ page import="ro.emid.common.types.AdEntry" %>
<%@ page import="ro.emid.common.utils.ObjectUtils" %>

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

<respmesg>
    <%
        try{
            final int AN = ObjectUtils.getIntValue( request.getParameter("AN"), -1);
            final int LUNA = ObjectUtils.getIntValue( request.getParameter("LUNA"), -1);

            final String strValue = ObjectUtils.getStringValue( request.getParameter("newValue"));
            
            final double value = ObjectUtils.getDoubleValue( request.getParameter("newValue"), -1);

            final String inputId    = ObjectUtils.getStringValue(request.getParameter("inputId"));
            final String spanTextId = ObjectUtils.getStringValue(request.getParameter("spanTextId"));

            AdEntry entry = null;

            //todo:
            long idFiliala = -1; //SessionUtils.getFilialaId(session)

            try {
                entry = AdEntryAccessDB.getEntry( idFiliala, AN, LUNA);
            } catch (DatabaseException e) {
                e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
            }

            String replyValue = "";
            if( strValue.trim().length() == 0 && entry != null){
                //delete facem
                AdEntryAccessDB.delete( entry);
            }else{
                // save or update facem
                if( entry == null) entry = new AdEntry();

                entry.setFilialaId(SessionUtils.getFilialaId( session));
                entry.setAn( AN );
                entry.setLuna( LUNA );
                entry.setValue( value);
                replyValue = String.valueOf(value);

                AdEntryAccessDB.save( entry);
                try{
    //                String text = "";
    //                ActionLogger.LogNomenclator(ActionLogger.ACTION_EDIT, user.getUsername(), text);
                }catch (Exception e){}
            }
    %>
    {
        inputId : "<%=ro.emid.common.utils.Util.escapeToJs(inputId)%>",
        spanTextId : "<%=ro.emid.common.utils.Util.escapeToJs(spanTextId)%>",
        value : "<%=ro.emid.common.utils.Util.escapeToJs(replyValue)%>"
    }
    <%}catch( Exception t){%>
        <%=t.getMessage()%>
    <%}%>
</respmesg>


