forked from Coded/SIPRP
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
185 lines
6.1 KiB
185 lines
6.1 KiB
/*
|
|
* Global.java
|
|
*
|
|
* Created on November 23, 2007, 10:08 AM
|
|
*
|
|
* To change this template, choose Tools | Template Manager
|
|
* and open the template in the editor.
|
|
*/
|
|
|
|
package global;
|
|
|
|
import beans.Utilizador;
|
|
//import com.sun.org.apache.bcel.internal.generic.GETFIELD;
|
|
import com.evolute.utils.error.ErrorLogger;
|
|
import java.io.File;
|
|
import java.io.FileInputStream;
|
|
import java.io.FileOutputStream;
|
|
import java.io.InputStream;
|
|
import java.io.OutputStream;
|
|
import javax.faces.context.ExternalContext;
|
|
import javax.faces.context.FacesContext;
|
|
import javax.servlet.ServletOutputStream;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpSession;
|
|
import utils.JSFUtils;
|
|
|
|
/**
|
|
*
|
|
* @author lluis2
|
|
*/
|
|
public class Global
|
|
{
|
|
public final static int ESTADO_SEG = 1;
|
|
public final static int ESTADO_RH1 = 2;
|
|
public final static int ESTADO_HS = 3;
|
|
public final static int ESTADO_RH2 = 4;
|
|
//public final static int ESTADO_MEDICINA = 5;
|
|
public final static int ESTADO_CONSOLIDACAO = 5;
|
|
//public final static int ESTADO_ASSINATURAS = 7;
|
|
public final static int ESTADO_ASSINATURA_SEG = 6;
|
|
public final static int ESTADO_ASSINATURA_RH = 7;
|
|
//public final static int ESTADO_IMPRESSAO = 8;
|
|
public final static int ESTADO_FECHAR = 8;
|
|
public final static int ESTADO_CONCLUIDO = 9;
|
|
|
|
|
|
public final static int ESTADO_ASSINATURA_1 = 1;
|
|
public final static int ESTADO_ASSINATURA_2 = 2;
|
|
public final static int ESTADO_ASSINATURA_3 = 3;
|
|
|
|
public final static int TIPO_UTILIZADOR_SEGURANCA = 1;
|
|
public final static int TIPO_UTILIZADOR_RH = 2;
|
|
public final static int TIPO_UTILIZADOR_HS = 3;
|
|
public final static int TIPO_UTILIZADOR_MEDICO = 5;
|
|
public final static int TIPO_UTILIZADOR_GESTOR = 6;
|
|
public final static int TIPO_UTILIZADOR_DIRECTOR_GERAL_RH = 7;
|
|
public final static int TIPO_UTILIZADOR_DIRECTOR_SIPRP = 8;
|
|
public final static int TIPO_UTILIZADOR_DIRECTOR_LOJA = 9;
|
|
public final static int TIPO_UTILIZADOR_DIRECTOR_NACIONAL_SEGURANCA = 10;
|
|
|
|
public final static int AUCHAN = 32;
|
|
|
|
|
|
public final static String ENDERECO_ENVIO = "acidentes.auchan@siprp.pt";
|
|
//public final static String ENDERECO_ENVIO = "lluis@evolute.pt"; //testes
|
|
|
|
public final static String IMAGE_FOLDER = "/home/siprp/imagens_acidentes";
|
|
//public final static String IMAGE_FOLDER = "/home/lluis/imagens_acidentes";
|
|
public final static String RESOURCES_IMAGE_FOLDER = "/resources/images";
|
|
|
|
public static final String PDF_FOLDER_URL = "/resources/pdf";
|
|
|
|
|
|
// public static final String PLANOS_ACTUACAO_URL = "http://localhost:8080/PlanosActuacao/faces/ListaPlanos.jsp"; //testes
|
|
//public static final String PLANOS_ACTUACAO_URL = "http://192.168.111.24:8084/PlanosActuacao/faces/ListaPlanos.jsp"; //testes portatil
|
|
public static final String PLANOS_ACTUACAO_URL = "https://www.siprp.pt/PlanosActuacao/faces/ListaPlanos.jsp"; //real
|
|
|
|
public static final String LOGOS_FOLDER = "/resources/images";
|
|
|
|
/** Creates a new instance of Global */
|
|
public Global() {
|
|
}
|
|
|
|
public void copyImage(File fSource, File fDest)
|
|
{
|
|
try
|
|
{
|
|
InputStream in = new FileInputStream(fSource);
|
|
OutputStream out = new FileOutputStream(fDest);
|
|
|
|
// Transfer bytes from in to out
|
|
byte[] buf = new byte[1024];
|
|
int len;
|
|
while ((len = in.read(buf)) > 0) {
|
|
out.write(buf, 0, len);
|
|
}
|
|
in.close();
|
|
out.close();
|
|
}
|
|
catch(Exception ex)
|
|
{
|
|
ErrorLogger.logException( ex );
|
|
}
|
|
}
|
|
|
|
public void deleteFolderFiles(File folder)
|
|
{
|
|
File files[] = folder.listFiles();
|
|
for(int i=0;i<files.length;i++)
|
|
{
|
|
if(files[i].isFile())
|
|
{
|
|
files[i].delete();
|
|
}
|
|
}
|
|
}
|
|
|
|
public void showPdf(String pdfFilePath) throws Exception
|
|
{
|
|
|
|
File pdfFile = new File(pdfFilePath);
|
|
FileInputStream fis = new FileInputStream(pdfFile);
|
|
byte[] buf = new byte[(int)pdfFile.length()];
|
|
while ((fis.read(buf)) > 0)
|
|
{
|
|
//fos.write(buf, 0, buf.length);
|
|
}
|
|
fis.close();
|
|
FacesContext ctx = FacesContext.getCurrentInstance();
|
|
if (!ctx.getResponseComplete())
|
|
{
|
|
HttpServletResponse response = (HttpServletResponse)ctx.getExternalContext().getResponse();
|
|
String contentType = "application/pdf";
|
|
response.setContentType(contentType);
|
|
response.setHeader("Content-Disposition","attachment;filename=\"" + "Ajuda.pdf" + "\"");
|
|
|
|
ServletOutputStream out = response.getOutputStream();
|
|
|
|
//out.write(model.getInfo().getBytes());
|
|
out.write(buf, 0, buf.length);
|
|
out.flush();
|
|
out.close();
|
|
ctx.responseComplete();
|
|
ctx.release();
|
|
}
|
|
}
|
|
|
|
|
|
public static void redirectToPlanos( FacesContext fc, Utilizador currentUser )
|
|
{
|
|
if ( fc != null )
|
|
{
|
|
String url = Global.PLANOS_ACTUACAO_URL;
|
|
// String url = "http://localhost:8084/PlanosActuacao/faces/ListaPlanos.jsp";
|
|
|
|
ExternalContext ec = fc.getExternalContext();
|
|
if ( ec != null )
|
|
{
|
|
HttpSession session = ( HttpSession ) ec.getSession( false );
|
|
if ( session != null )
|
|
{
|
|
url += "?sessionID=" + session.getId();
|
|
|
|
int userType = currentUser == null ? -1 : currentUser.getTipo() == null ? -1 : currentUser.getTipo().intValue();
|
|
if ( userType == Global.TIPO_UTILIZADOR_GESTOR )
|
|
{
|
|
url += "&estab_gestor=" + currentUser.getEstabelecimento_gestor();
|
|
}
|
|
|
|
try
|
|
{
|
|
System.out.println( "\tRedirecting to : " + url );
|
|
JSFUtils.redirect( fc, url );
|
|
}
|
|
catch ( Exception e )
|
|
{
|
|
ErrorLogger.logException( e );
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|