/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package phaselistener;

import analiseacidentestrabalho.Utilizador;
import global.Global;
import javax.faces.application.NavigationHandler;
import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;
import javax.faces.event.PhaseEvent;
import javax.faces.event.PhaseId;
import javax.faces.event.PhaseListener;
import javax.servlet.http.HttpServletRequest;
import analiseacidentestrabalho.SessionBean1;
import utils.JSFUtils;
import utils.Logos;

/**
 *
 * @author lluis
 */
public class MainPhaseListener implements PhaseListener{
    private boolean firstEntry = true;
            
    public void afterPhase(PhaseEvent pe) {

        
    }

    public void beforePhase(PhaseEvent pe) {
       if(pe.getPhaseId() == PhaseId.RENDER_RESPONSE)
       {
            FacesContext fc = pe.getFacesContext();           
            SessionBean1 session = JSFUtils.getSessionBean(fc);           

            
            Utilizador u = session.getCurrentUser();

            
            //insert logos
            
            //Integer empresaId = u.getEmpresa_id();
            Integer empresaId = new Integer(32);            
            //System.out.println("LOGO EMPRESA ID : " + empresaId.toString());
            Logos logos = new Logos();
            String logourl = logos.getLogo(fc, empresaId);
            //System.out.println("LOGO URL : " + logourl);            
            session.setLogoEmpresaUrl(logourl);
        }
    }

    public PhaseId getPhaseId() {
        return PhaseId.ANY_PHASE;
    }

}
