package org.ellectra.gui.managebeans;

import java.util.ArrayList;

import java.util.List;
import javax.faces.component.UIData;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.faces.event.ValueChangeEvent;
import javax.xml.ws.WebServiceRef;
import org.ellectra.gui.utils.JSFUtils;
import org.ellectra.wsccfp.CfpCriterionType;
import org.ellectra.wsccretevalforms.AwardCriterionType;
import org.ellectra.wsccretevalforms.CreateEvalFormsService;
import org.ellectra.wschkcallass.CheckAssociationToCallService;
import org.ellectra.wseditaw.UpdateAwCriteriaService;
import org.ellectra.wseditcfp.UpdateCfpCriteriaService;
import org.ellectra.wsviewawcre.ViewAwCriteriaService;
import org.ellectra.wsviewcftct.ViewCfpCriteriaService;

public class conditionforparticipation {
    @WebServiceRef(wsdlLocation = "http://localhost:18181/CheckAssociationToCallService/CheckAssociationToCallPort?wsdl")
    private CheckAssociationToCallService service_5;
    @WebServiceRef(wsdlLocation = "http://localhost:18181/UpdateAwCriteriaService/UpdateAwCriteriaPort?wsdl")
    private UpdateAwCriteriaService service_4;
    @WebServiceRef(wsdlLocation = "http://localhost:18181/UpdateCfpCriteriaService/UpdateCfpCriteriaPort?wsdl")
    private UpdateCfpCriteriaService service_3;
    @WebServiceRef(wsdlLocation = "http://localhost:18181/ViewAwCriteriaService/ViewAwCriteriaPort?wsdl")
    private ViewAwCriteriaService service_2;
    @WebServiceRef(wsdlLocation = "http://localhost:18181/ViewCfpCriteriaService/ViewCfpCriteriaPort?wsdl")
    private ViewCfpCriteriaService service_1;
    @WebServiceRef(wsdlLocation = "http://localhost:18181/CreateEvalFormsService/CreateEvalFormsPort?wsdl")
    private CreateEvalFormsService service;
    String a_cfp1;
    String a_cfp2;
    String a_cfp3;
    String a_cfp4;
    String a_cfp5;
    String a_cfp6;
    String a_cfp7;
    String a_cfp8;
    String a_cfp9_10;
    String a_cfp11_12;
    String a_cfp13_14;
    String a_cfp15_16;
    String a_cfp17;
    String a_cfp18;
    private Double a_cfp19;
    private UIData psData = null;
    private UIData efcData = null;
    private UIData tcData = null;
    private UIData otherData = null;
    private UIData cretiriaL = null;
    ArrayList<cfparticipation> psConditions = new ArrayList();
    ArrayList<cfparticipation> efcConditions = new ArrayList();
    ArrayList<cfparticipation> tcConditions = new ArrayList();
    ArrayList<cfparticipation> otherConditions = new ArrayList();
    ArrayList<evaluationlist> cretirialist = new ArrayList();
    int psNum;
    int efcNum;
    int tcNum;
    int otherNum;
    int crenum;
    String dUserloginname;
    String dUserloginsignature;
    String dUserloginOrganization;
    String dUserloginrole;
    int dUserloginid;
    int mytenderid;
    int mycalloftender;
    //private boolean btnUpdateRendered;
    private String btnAddDisabled; //= "true";

    private void reset() {
        a_cfp9_10 = "MEAT";
        a_cfp11_12 = "2";
        a_cfp13_14 = "2";
        a_cfp15_16 = "1";


        psNum = 2;
        efcNum = 2;
        tcNum = 2;
        otherNum = 0;
        crenum = 0;

        //evaluationlist dd= new evaluationlist("#","Criterion","Type","Weight");
        //cretirialist.add(dd);
        psConditions.clear();
        cfparticipation cfp = new cfparticipation(1, "Country of registration evidence");
        psConditions.add(cfp);
        cfp = new cfparticipation(2, "Non-convinction evidence");
        psConditions.add(cfp);
        efcConditions.clear();
        cfp = new cfparticipation(1, "Latest balance sheet or extracts");
        efcConditions.add(cfp);
        cfp = new cfparticipation(2, "Statement of overall turnover for the past three financial years");
        efcConditions.add(cfp);
        tcConditions.clear();
        cfp = new cfparticipation(1, "List of similar contracts effected in the past three years");
        tcConditions.add(cfp);
        cfp = new cfparticipation(2, "Description of technical facilities and quality control systems");
        tcConditions.add(cfp);

        cretirialist.clear();
    }

    private void resetCfps() {
        psConditions.clear();
        tcConditions.clear();
        efcConditions.clear();
        otherConditions.clear();

        a_cfp1 = "";
        btnAddDisabled = "true";
    }

    public conditionforparticipation() {
        super();

        a_cfp9_10 = "MEAT";
        a_cfp11_12 = "2";
        a_cfp13_14 = "2";
        a_cfp15_16 = "1";


        psNum = 2;
        efcNum = 2;
        tcNum = 2;
        otherNum = 0;
        crenum = 0;

        //evaluationlist dd= new evaluationlist("#","Criterion","Type","Weight");
        //cretirialist.add(dd);

        cfparticipation cfp = new cfparticipation(1, "Country of registration evidence");
        psConditions.add(cfp);
        cfp = new cfparticipation(2, "Non-convinction evidence");
        psConditions.add(cfp);

        cfp = new cfparticipation(1, "Latest balance sheet or extracts");
        efcConditions.add(cfp);
        cfp = new cfparticipation(2, "Statement of overall turnover for the past three financial years");
        efcConditions.add(cfp);

        cfp = new cfparticipation(1, "List of similar contracts effected in the past three years");
        tcConditions.add(cfp);
        cfp = new cfparticipation(2, "Description of technical facilities and quality control systems");
        tcConditions.add(cfp);
    }

    public void addToList(ActionEvent event) {
        cfparticipation con = new cfparticipation();
        con.setCondition(a_cfp1);

        if (a_cfp2.equals("1")) {
            int number = psNum + 1;
            con.setNumber(number);
            psConditions.add(con);
            psNum++;
        } else if (a_cfp2.equals("2")) {
            int number = efcNum + 1;
            con.setNumber(number);
            efcConditions.add(con);
            efcNum++;
        } else if (a_cfp2.equals("3")) {
            int number = tcNum + 1;
            con.setNumber(number);
            tcConditions.add(con);
            tcNum++;
        } else {
            int number = otherNum + 1;
            con.setNumber(number);
            getOtherConditions().add(con);
            otherNum++;
        }
    }

    public void removeFromList(ActionEvent event) {

        for (int i = 0; i < psConditions.size(); i++) {
            cfparticipation ps = psConditions.get(i);
            if (ps.isChecked()) {
                psConditions.remove(ps);

            }
        }

        for (int j = 0; j < efcConditions.size(); j++) {
            cfparticipation efc = efcConditions.get(j);
            if (efc.isChecked()) {
                efcConditions.remove(efc);

            }
        }

        for (int k = 0; k < tcConditions.size(); k++) {
            cfparticipation tc = tcConditions.get(k);
            if (tc.isChecked()) {
                tcConditions.remove(tc);

            }
        }

        for (int m = 0; m < otherConditions.size(); m++) {
            cfparticipation other = otherConditions.get(m);
            if (other.isChecked()) {
                otherConditions.remove(other);

            }
        }
    }

    public void addToListC(ActionEvent event) {
        evaluationlist cre = new evaluationlist();
        cre.setNumber(Integer.toString(crenum));
        cre.setCreditio(a_cfp17);
        cre.setType(a_cfp18);
        cre.setWeight(getA_cfp19());
        crenum = crenum + 1;
        cretirialist.add(cre);
    }

    public void removeFromListC(ActionEvent event) {

        for (int i = 0; i < cretirialist.size(); i++) {
            evaluationlist ps = cretirialist.get(i);
            if (ps.isChecked()) {
                cretirialist.remove(ps);

            }
        }

    }

    public void GetSessionVariables() {

        dUserloginname = (String) JSFUtils.retrieveOnSession(FacesContext.getCurrentInstance(), "LOGINUSER");
        dUserloginsignature = (String) JSFUtils.retrieveOnSession(FacesContext.getCurrentInstance(), "LOGINSIGNATURE");
        dUserloginOrganization = (String) JSFUtils.retrieveOnSession(FacesContext.getCurrentInstance(), "LOGINORGANIZATION");
        dUserloginrole = (String) JSFUtils.retrieveOnSession(FacesContext.getCurrentInstance(), "LOGINROLE");
        String szTemp = (String) JSFUtils.retrieveOnSession(FacesContext.getCurrentInstance(), "LOGINUSERID");
        dUserloginid = Integer.valueOf(szTemp).intValue();
        szTemp = (String) JSFUtils.retrieveOnSession(FacesContext.getCurrentInstance(), "TENDERIDI");
        mytenderid = Integer.valueOf(szTemp).intValue();
        szTemp = (String) JSFUtils.retrieveOnSession(FacesContext.getCurrentInstance(), "CALLTENDERID");
        mycalloftender = Integer.valueOf(szTemp).intValue();

    }

    public String saveall() {
        //System.err.print("start");
        GetSessionVariables();
        try {
            //  System.err.print("inside try");
            org.ellectra.wsccretevalforms.CreateEvalFormsPortType port = service.getCreateEvalFormsPort();

            org.ellectra.wsccretevalforms.CreateEvalFormsRequest part1 = new org.ellectra.wsccretevalforms.CreateEvalFormsRequest();
            //System.err.print("start set");
            part1.setActorSignature(dUserloginsignature);
            part1.setCallForTenderID(mycalloftender);
            //System.err.print("start set 1");
            if (a_cfp11_12.equalsIgnoreCase("1")) {
                part1.setEAuction(true);
            } else {
                part1.setEAuction(false);            //System.err.print("start set 2");
            }
            if (a_cfp13_14.equalsIgnoreCase("2")) {
                part1.setStatedInCN(true);
            } else {
                part1.setStatedInCN(false);            //System.err.print("start set 3");
            }
            if (a_cfp15_16.equalsIgnoreCase("1")) {
                part1.setWeightedForMEAT(true);
            } else {
                part1.setWeightedForMEAT(false);            //if(a_cfp15_16.equalsIgnoreCase("1"))
            //System.err.print("start set 4");    
            }
            part1.setEvaluationMethodType(a_cfp9_10);
            //System.err.print("start set 4.1");
            List<org.ellectra.wsccretevalforms.CfpCriterionType> dlocalist = part1.getCfpCriterion();
            List<org.ellectra.wsccretevalforms.AwardCriterionType> dlocal2 = part1.getAwardCriterion();
            //System.err.print("start set 5");
            for (int io = 0; io < otherConditions.size(); io++) {
                //  System.err.print("start set 5 - a");
                org.ellectra.wsccretevalforms.CfpCriterionType ditem = new org.ellectra.wsccretevalforms.CfpCriterionType();
                // System.err.print("start set 5 -b ");
                ditem.setCondition(otherConditions.get(io).getCondition());
                ditem.setConditionType("OTHER");
                ditem.setMinLevel(false);
                //System.err.print("start set 5 - c");
                dlocalist.add(ditem);
            }
            //System.err.print("start set 6");
            //ECONOMIC_FINANCIAL_CAPACITY , ,TECHNICAL_CAPACITY
            for (int io = 0; io < psConditions.size(); io++) {
                org.ellectra.wsccretevalforms.CfpCriterionType ditem = new org.ellectra.wsccretevalforms.CfpCriterionType();
                ditem.setCondition(psConditions.get(io).getCondition());
                ditem.setConditionType("PERSONAL_SITUATION");
                ditem.setMinLevel(false);
                dlocalist.add(ditem);
            }
            //System.err.print("start set 7");
            for (int io = 0; io < tcConditions.size(); io++) {
                org.ellectra.wsccretevalforms.CfpCriterionType ditem = new org.ellectra.wsccretevalforms.CfpCriterionType();
                ditem.setCondition(tcConditions.get(io).getCondition());
                ditem.setConditionType("TECHNICAL_CAPACITY");
                ditem.setMinLevel(false);
                dlocalist.add(ditem);
            }
//System.err.print("start set 8");
            for (int io = 0; io < efcConditions.size(); io++) {
                org.ellectra.wsccretevalforms.CfpCriterionType ditem = new org.ellectra.wsccretevalforms.CfpCriterionType();
                ditem.setCondition(efcConditions.get(io).getCondition());
                ditem.setConditionType("ECONOMIC_FINANCIAL_CAPACITY");
                ditem.setMinLevel(false);
                dlocalist.add(ditem);
            }
//FINANCIAL ,TECHNICAL
//System.err.print("start set 9");
            for (int ii = 0; ii < cretirialist.size(); ii++) {
                org.ellectra.wsccretevalforms.AwardCriterionType ditemaw = new org.ellectra.wsccretevalforms.AwardCriterionType();
                ditemaw.setCriterion(cretirialist.get(ii).getCreditio());
                ditemaw.setWeight(Double.valueOf(cretirialist.get(ii).getWeight()));
                ditemaw.setCriterionType(cretirialist.get(ii).getType());
                dlocal2.add(ditemaw);
            }
//System.err.print("start set 10 - call ws");
            org.ellectra.wsccretevalforms.CreateEvalFormsResponse result = port.createEvalFormsOperation(part1);
            reset();
        } catch (Exception ex) {
            // TODO handle custom exceptions here
            reset();
            return "fail";
        }
//System.err.print("finish ok");
        return "createevalformsback";
    }

    public String createconditions() {
        a_cfp9_10 = "MEAT";
        a_cfp11_12 = "2";
        a_cfp13_14 = "2";
        a_cfp15_16 = "1";


        psNum = 2;
        efcNum = 2;
        tcNum = 2;
        otherNum = 0;
        crenum = 0;

        //evaluationlist dd= new evaluationlist("#","Criterion","Type","Weight");
        //cretirialist.add(dd);
        psConditions.clear();
        efcConditions.clear();
        otherConditions.clear();
        tcConditions.clear();
        
        cretirialist.clear();
        
        cfparticipation cfp = new cfparticipation(1, "Country of registration evidence");
        psConditions.add(cfp);
        cfp = new cfparticipation(2, "Non-convinction evidence");
        psConditions.add(cfp);

        cfp = new cfparticipation(1, "Latest balance sheet or extracts");
        efcConditions.add(cfp);
        cfp = new cfparticipation(2, "Statement of overall turnover for the past three financial years");
        efcConditions.add(cfp);

        cfp = new cfparticipation(1, "List of similar contracts effected in the past three years");
        tcConditions.add(cfp);
        cfp = new cfparticipation(2, "Description of technical facilities and quality control systems");
        tcConditions.add(cfp);
        return "createevalforms";
    }

    public String vieweditaw() {
        GetSessionVariables();
        cretirialist.clear();

        try { // Call Web Service Operation
            org.ellectra.wsviewawcre.ViewAwCriteriaPortType port = service_2.getViewAwCriteriaPort();
            // TODO initialize WS operation arguments here
            org.ellectra.wsviewawcre.ViewAwCriteriaRequest part1 = new org.ellectra.wsviewawcre.ViewAwCriteriaRequest();
            part1.setActorSignature(dUserloginsignature);
            part1.setCallForTenderID(mycalloftender);
            // TODO process result here
            org.ellectra.wsviewawcre.ViewAwCriteriaResponse result = port.viewAwCriteriaOperation(part1);
            a_cfp9_10 = result.getEvaluationMethodType();
            if (result.isEAuction())
                a_cfp11_12 = "1";
            else
                a_cfp11_12 = "2";
            
            if (result.isStatedInCN())
                a_cfp13_14 = "2";
            else
                a_cfp13_14 = "1";  
            
            if (result.isWeightedForMEAT())
                a_cfp15_16 = "1";
            else
                a_cfp15_16 = "2";
            
            List<org.ellectra.wsviewawcre.AwardCriterionType> dd = result.getAwardCriterion();
            for (int il = 0; il < dd.size(); il++) {
                org.ellectra.wsviewawcre.AwardCriterionType ditem = new org.ellectra.wsviewawcre.AwardCriterionType();
                ditem = dd.get(il);
                evaluationlist o = new evaluationlist();
                o.setCreditio(ditem.getCriterion());
                o.setType(ditem.getCriterionType());
                o.setWeight(ditem.getWeight());
                //String.valueOf(il)

                cretirialist.add(o);
            }

        //System.out.println("Result = "+result);
        } catch (Exception ex) {
            // TODO handle custom exceptions here
            System.out.println("Result error on view aw= " + ex.getLocalizedMessage());
        }
        return "gotoawedit";
    }

    public String viewedit() {
        GetSessionVariables();
        resetCfps();
        try {
            org.ellectra.wsviewcftct.ViewCfpCriteriaPortType port = service_1.getViewCfpCriteriaPort();
            // TODO initialize WS operation arguments here
            org.ellectra.wsviewcftct.ViewCfpCriteriaRequest part1 = new org.ellectra.wsviewcftct.ViewCfpCriteriaRequest();
            part1.setActorSignature(dUserloginsignature);
            part1.setCallForTenderID(mycalloftender);

            org.ellectra.wsviewcftct.ViewCfpCriteriaResponse result = port.viewCfpCriteriaOperation(part1);
            /// fill up the stuff
            List<org.ellectra.wsviewcftct.CfpCriterionType> ddd = result.getCfpCriterion();
            for (int t = 0; t < ddd.size(); t++) {
                org.ellectra.wsviewcftct.CfpCriterionType ditem = new org.ellectra.wsviewcftct.CfpCriterionType();
                ditem = ddd.get(t);

                if (ditem.getConditionType().equalsIgnoreCase("PERSONAL_SITUATION")) {
                    cfparticipation dd1 = new cfparticipation();
                    dd1.setCondition(ditem.getCondition());
                    dd1.setId(ditem.getCfpID());
                    dd1.setNumber(ditem.getCfpID());
                    psConditions.add(dd1);
                }
                if (ditem.getConditionType().equalsIgnoreCase("ECONOMIC_FINANCIAL_CAPACITY")) {
                    cfparticipation dd1 = new cfparticipation();
                    dd1.setCondition(ditem.getCondition());
                    dd1.setId(ditem.getCfpID());
                    dd1.setNumber(ditem.getCfpID());
                    efcConditions.add(dd1);
                }

                if (ditem.getConditionType().equalsIgnoreCase("TECHNICAL_CAPACITY")) {
                    cfparticipation dd1 = new cfparticipation();
                    dd1.setCondition(ditem.getCondition());
                    dd1.setId(ditem.getCfpID());
                    dd1.setNumber(ditem.getCfpID());
                    tcConditions.add(dd1);
                }

                if (ditem.getConditionType().equalsIgnoreCase("OTHER")) {
                    cfparticipation dd1 = new cfparticipation();
                    dd1.setCondition(ditem.getCondition());
                    dd1.setId(ditem.getCfpID());
                    dd1.setNumber(ditem.getCfpID());
                    otherConditions.add(dd1);
                }

            //;
            //PERSONAL_SITUATION
            //ECONOMIC_FINANCIAL_CAPACITY
            //TECHNICAL_CAPACITY
            //OTHER

            }
        } catch (Exception ex) {
            // TODO handle custom exceptions here
        }

        return "gotocfpedit";
    }

    public String updateCfps() {
        GetSessionVariables();

        //CHECK CALL CLOSE DATE TO EDIT
        try {
            org.ellectra.wseditcfp.UpdateCfpCriteriaPortType port = service_3.getUpdateCfpCriteriaPort();
            org.ellectra.wseditcfp.UpdateCfpCriteriaRequest part1 = new org.ellectra.wseditcfp.UpdateCfpCriteriaRequest();
            part1.setActorSignature(dUserloginsignature);
            part1.setCallForTenderID(mycalloftender);
            List<org.ellectra.wseditcfp.CfpCriterionType> dlocalist = part1.getCfpCriterion();

            for (int i = 0; i < psConditions.size(); i++) {
                org.ellectra.wseditcfp.CfpCriterionType psCondition = new org.ellectra.wseditcfp.CfpCriterionType();
                cfparticipation ditem = psConditions.get(i);

                psCondition.setCondition(ditem.getCondition());
                psCondition.setConditionType("PERSONAL_SITUATION");
                psCondition.setMinLevel(false);

                dlocalist.add(psCondition);
            }
            for (int j = 0; j < tcConditions.size(); j++) {
                org.ellectra.wseditcfp.CfpCriterionType tcCondition = new org.ellectra.wseditcfp.CfpCriterionType();
                cfparticipation ditem = tcConditions.get(j);

                tcCondition.setCondition(ditem.getCondition());
                tcCondition.setConditionType("TECHNICAL_CAPACITY");
                tcCondition.setMinLevel(false);

                dlocalist.add(tcCondition);
            }
            for (int k = 0; k < efcConditions.size(); k++) {
                org.ellectra.wseditcfp.CfpCriterionType efcCondition = new org.ellectra.wseditcfp.CfpCriterionType();
                cfparticipation ditem = efcConditions.get(k);

                efcCondition.setCondition(ditem.getCondition());
                efcCondition.setConditionType("ECONOMIC_FINANCIAL_CAPACITY");
                efcCondition.setMinLevel(false);

                dlocalist.add(efcCondition);
            }
            for (int m = 0; m < otherConditions.size(); m++) {
                org.ellectra.wseditcfp.CfpCriterionType otherCondition = new org.ellectra.wseditcfp.CfpCriterionType();
                cfparticipation ditem = otherConditions.get(m);

                otherCondition.setCondition(ditem.getCondition());
                otherCondition.setConditionType("OTHER");
                otherCondition.setMinLevel(false);

                dlocalist.add(otherCondition);
            }


            // TODO process result here
            org.ellectra.wseditcfp.UpdateCfpCriteriaResponse result = port.updateCfpCriteriaOperation(part1);
            resetCfps();
        } catch (Exception ex) {
            // TODO handle custom exceptions here
            resetCfps();
            ex.printStackTrace();
        }

        return "backToCall";
    }

    public String updateAwCriteria() {
        GetSessionVariables();

        //CHECK CALL CLOSE DATE TO EDIT
        try { 
            org.ellectra.wseditaw.UpdateAwCriteriaPortType port = service_4.getUpdateAwCriteriaPort();
            org.ellectra.wseditaw.UpdateAwCriteriaRequest part1 = new org.ellectra.wseditaw.UpdateAwCriteriaRequest();
            part1.setActorSignature(dUserloginsignature);
            part1.setCallForTenderID(mycalloftender);
            
            if (a_cfp11_12.equalsIgnoreCase("1")) {
                part1.setEAuction(true);
            } else {
                part1.setEAuction(false);            
            }
            if (a_cfp13_14.equalsIgnoreCase("2")) {
                part1.setStatedInCN(true);
            } else {
                part1.setStatedInCN(false);            
            }
            if (a_cfp15_16.equalsIgnoreCase("1")) {
                part1.setWeightedForMEAT(true);
            } else {
                part1.setWeightedForMEAT(false); 
            }
            part1.setEvaluationMethodType(a_cfp9_10);
            
            
            List<org.ellectra.wseditaw.AwardCriterionType> dlocalist = part1.getAwardCriterion();
            
            for (int i = 0; i < cretirialist.size(); i++) {
                org.ellectra.wseditaw.AwardCriterionType criterion = new org.ellectra.wseditaw.AwardCriterionType();
                evaluationlist ditem = cretirialist.get(i);
                
                criterion.setCriterion(ditem.getCreditio());
                criterion.setCriterionType(ditem.getType());
                criterion.setWeight(ditem.getWeight());
                
                dlocalist.add(criterion);
            }

            // TODO process result here
            org.ellectra.wseditaw.UpdateAwCriteriaResponse result = port.updateAwCriteriaOperation(part1);
            //resetwhatneeded
        } catch (Exception ex) {
            // TODO handle custom exceptions here
            //resetwhatneeded
            ex.printStackTrace();
        }

        return "backToCall";
    }
    
   /**
     * Return TRUE if user (from session) is associated to call (from session) 
     * @return
     */
    public boolean userAssociatedToCall() {
        GetSessionVariables();
        try {
            org.ellectra.wschkcallass.CheckAssociationToCallPortType port = service_5.getCheckAssociationToCallPort();
            org.ellectra.wschkcallass.CheckAssociationToCallRequest part1 = new org.ellectra.wschkcallass.CheckAssociationToCallRequest();
            part1.setCallForTendersID(mycalloftender);
            part1.setUserAccountID(dUserloginid);
            // TODO process result here
            org.ellectra.wschkcallass.CheckAssociationToCallResponse result = port.checkAssociationToCallOperation(part1);
            
            boolean associated = result.isReturn();
            String associatedAs = result.getAssociatedAs();
            if (associated && associatedAs.contains("ADMINISTRATIVE")) {
                return true;
            }
        } catch (Exception ex) {
            // TODO handle custom exceptions here
            System.err.print("CFP: CALL ASSOCIATION EXCEPTION");
            ex.printStackTrace();
            return false;
        }
        return false;
    }

    public String back() { 
        a_cfp1 = "";
        btnAddDisabled = "true";
        a_cfp17 = "";
        //a_cfp19 = "";
        java.lang.String Poa = (java.lang.String) org.ellectra.gui.utils.JSFUtils.retrieveOnSession(javax.faces.context.FacesContext.getCurrentInstance(), "LOGINROLEPOA");
        
        if (Poa.equalsIgnoreCase("POA") && userAssociatedToCall())
            return "backToCall";
        else
            return "backToCallpope";
    }

//    public boolean isBtnUpdateRendered() {
//        java.lang.String Poa = (java.lang.String) org.ellectra.gui.utils.JSFUtils.retrieveOnSession(javax.faces.context.FacesContext.getCurrentInstance(), "LOGINROLEPOA");
//        if (Poa.equalsIgnoreCase("POA"))
//            btnUpdateRendered = true;
//        else
//            btnUpdateRendered = false;
//        
//        return btnUpdateRendered;
//    }
//
//    public void setBtnUpdateRendered(boolean btnUpdateRendered) {
//        this.btnUpdateRendered = btnUpdateRendered;
//    }

    public void conditionWritten(ValueChangeEvent event) {
        a_cfp1 = (String) event.getNewValue();
        FacesContext context = FacesContext.getCurrentInstance();
        context.renderResponse();
    }

    public String getBtnAddDisabled() {
        if (a_cfp1 != null) {
          if (a_cfp1.length() > 1)
                btnAddDisabled = "false";
            else
                btnAddDisabled = "true";
        }
        else
            btnAddDisabled = "true";
        
        return btnAddDisabled;
    }

    public void setBtnAddDisabled(String btnAddDisabled) {
        this.btnAddDisabled = btnAddDisabled;
    }

    public UIData getPsData() {
        return psData;
    }

    public void setPsData(UIData psData) {
        this.psData = psData;
    }

    public UIData getEfcData() {
        return efcData;
    }

    public void setEfcData(UIData efcData) {
        this.efcData = efcData;
    }

    public UIData getTcData() {
        return tcData;
    }

    public void setTcData(UIData tcData) {
        this.tcData = tcData;
    }

    public UIData getOtherData() {
        return otherData;
    }

    public void setOtherData(UIData otherData) {
        this.otherData = otherData;
    }

    public ArrayList<cfparticipation> getPsConditions() {
        return psConditions;
    }

    public void setPsConditions(ArrayList<cfparticipation> conditions) {
        this.psConditions = conditions;
    }

    public ArrayList<cfparticipation> getEfcConditions() {
        return efcConditions;
    }

    public void setEfcConditions(ArrayList<cfparticipation> efcConditions) {
        this.efcConditions = efcConditions;
    }

    public ArrayList<cfparticipation> getTcConditions() {
        return tcConditions;
    }

    public void setTcConditions(ArrayList<cfparticipation> tcConditions) {
        this.tcConditions = tcConditions;
    }

    public ArrayList<cfparticipation> getOtherConditions() {
        return otherConditions;
    }

    public void setOtherConditions(ArrayList<cfparticipation> otherConditions) {
        this.otherConditions = otherConditions;
    }

    public String getA_cfp1() {
        return a_cfp1;
    }

    public void setA_cfp1(String a_cfp1) {
        this.a_cfp1 = a_cfp1;
    }

    public String getA_cfp2() {
        return a_cfp2;
    }

    public void setA_cfp2(String a_cfp2) {
        this.a_cfp2 = a_cfp2;
    }

    public String getA_cfp3() {
        return a_cfp3;
    }

    public void setA_cfp3(String a_cfp3) {
        this.a_cfp3 = a_cfp3;
    }

    public String getA_cfp4() {
        return a_cfp4;
    }

    public void setA_cfp4(String a_cfp4) {
        this.a_cfp4 = a_cfp4;
    }

    public String getA_cfp5() {
        return a_cfp5;
    }

    public void setA_cfp5(String a_cfp5) {
        this.a_cfp5 = a_cfp5;
    }

    public String getA_cfp6() {
        return a_cfp6;
    }

    public void setA_cfp6(String a_cfp6) {
        this.a_cfp6 = a_cfp6;
    }

    public String getA_cfp7() {
        return a_cfp7;
    }

    public void setA_cfp7(String a_cfp7) {
        this.a_cfp7 = a_cfp7;
    }

    public String getA_cfp8() {
        return a_cfp8;
    }

    public void setA_cfp8(String a_cfp8) {
        this.a_cfp8 = a_cfp8;
    }

    public String getA_cfp9_10() {
        return a_cfp9_10;
    }

    public void setA_cfp9_10(String a_cfp9_10) {
        this.a_cfp9_10 = a_cfp9_10;
    }

    public String getA_cfp11_12() {
        return a_cfp11_12;
    }

    public void setA_cfp11_12(String a_cfp11_12) {
        this.a_cfp11_12 = a_cfp11_12;
    }

    public String getA_cfp13_14() {
        return a_cfp13_14;
    }

    public void setA_cfp13_14(String a_cfp13_14) {
        this.a_cfp13_14 = a_cfp13_14;
    }

    public String getA_cfp15_16() {
        return a_cfp15_16;
    }

    public void setA_cfp15_16(String a_cfp15_16) {
        this.a_cfp15_16 = a_cfp15_16;
    }

    public String getA_cfp17() {
        return a_cfp17;
    }

    public void setA_cfp17(String a_cfp17) {
        this.a_cfp17 = a_cfp17;
    }

    public String getA_cfp18() {
        return a_cfp18;
    }

    public void setA_cfp18(String a_cfp18) {
        this.a_cfp18 = a_cfp18;
    }

    public UIData getCretiriaL() {
        return cretiriaL;
    }

    public void setCretiriaL(UIData cretiriaL) {
        this.cretiriaL = cretiriaL;
    }

    public ArrayList<evaluationlist> getCretirialist() {
        return cretirialist;
    }

    public void setCretirialist(ArrayList<evaluationlist> cretirialist) {
        this.cretirialist = cretirialist;
    }

    public int getPsNum() {
        return psNum;
    }

    public void setPsNum(int psNum) {
        this.psNum = psNum;
    }

    public int getEfcNum() {
        return efcNum;
    }

    public void setEfcNum(int efcNum) {
        this.efcNum = efcNum;
    }

    public int getTcNum() {
        return tcNum;
    }

    public void setTcNum(int tcNum) {
        this.tcNum = tcNum;
    }

    public int getOtherNum() {
        return otherNum;
    }

    public void setOtherNum(int otherNum) {
        this.otherNum = otherNum;
    }

    public int getCrenum() {
        return crenum;
    }

    public void setCrenum(int crenum) {
        this.crenum = crenum;
    }

    public Double getA_cfp19() {
        return a_cfp19;
    }

    public void setA_cfp19(Double a_cfp19) {
        this.a_cfp19 = a_cfp19;
    }
}
