forked from Coded/SIPRP
git-svn-id: https://svn.coded.pt/svn/SIPRP@539 bb69d46d-e84e-40c8-a05a-06db0d633741
parent
e3e04304f9
commit
7706717e75
@ -1,38 +0,0 @@
|
||||
/*
|
||||
* GlobalConstant.java
|
||||
*
|
||||
* Created on 27 de Abril de 2005, 18:20
|
||||
*/
|
||||
|
||||
package siprp.pagina;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author fpalma
|
||||
*/
|
||||
public interface GlobalConstants
|
||||
{
|
||||
// BD
|
||||
public static final String bdHost = "127.0.0.1";
|
||||
public static final String bdPort = "5436";
|
||||
public static final String bdUsername = "siprp";
|
||||
public static final String bdPassword = "";
|
||||
public static final String bdDriver = "org.postgresql.Driver";
|
||||
public static final String bdUrl = "jdbc:postgresql://" + bdHost + ":" + bdPort + "/siprp";
|
||||
|
||||
public static final String bdLocalHost = "127.0.0.1";
|
||||
public static final String bdLocalPort = "5436";
|
||||
public static final String bdLocalUsername = "siprp";
|
||||
public static final String bdLocalPassword = "";
|
||||
public static final String bdLocalDriver = "org.postgresql.Driver";
|
||||
public static final String bdLocalUrl = "jdbc:postgresql://" + bdHost + ":" + bdPort + "/siprp_local_3";
|
||||
|
||||
public static final String DEFAULT_EMAIL = "geral@siprp.pt";
|
||||
|
||||
public static final int TIPO_MARCACAO_EXAMES = 0;
|
||||
public static final int TIPO_MARCACAO_CONSULTA = 1;
|
||||
|
||||
public static final Integer ESTADO_POR_REALIZAR = new Integer( 0 );
|
||||
public static final Integer ESTADO_PARCIALMENTE_REALIZADO = new Integer( 1 );
|
||||
public static final Integer ESTADO_REALIZADO = new Integer( 2 );
|
||||
}
|
||||
@ -1,240 +0,0 @@
|
||||
/*
|
||||
* ServletAux.java
|
||||
*
|
||||
* Created on 10 de Março de 2005, 12:24
|
||||
*/
|
||||
|
||||
package siprp.pagina;
|
||||
|
||||
import javax.activation.*;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
import javax.mail.*;
|
||||
import javax.mail.internet.*;
|
||||
import javax.servlet.*;
|
||||
import javax.servlet.http.*;
|
||||
import java.sql.*;
|
||||
|
||||
import org.apache.commons.mail.*;
|
||||
import org.apache.velocity.*;
|
||||
import org.apache.velocity.app.*;
|
||||
|
||||
import com.evolute.utils.arrays.*;
|
||||
/**
|
||||
*
|
||||
* @author psantos
|
||||
*/
|
||||
public class MailerServlet extends HttpServlet
|
||||
implements GlobalConstants
|
||||
{
|
||||
public static final String EMAIL = "email";
|
||||
public static final String EMAIL_MARCACAO = "email_marcacao";
|
||||
public static final String EMAIL_RECRUTAMENTO = "email_recrutamento";
|
||||
|
||||
protected static Hashtable PROPERTIES;
|
||||
|
||||
public void init()
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
String TEMPLATE_DIR = this.getServletContext().getRealPath( "/" ) + "html/";
|
||||
|
||||
Properties props = new Properties();
|
||||
props.setProperty( "file.resource.loader.path", TEMPLATE_DIR );
|
||||
Velocity.init( props );
|
||||
if( PROPERTIES == null )
|
||||
{
|
||||
Class.forName(bdDriver);
|
||||
Connection con = DriverManager.getConnection( bdUrl, bdUsername, bdPassword );
|
||||
Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
|
||||
ResultSet2DArray array = new ResultSet2DArray(
|
||||
stmt.executeQuery( "Select name, value FROM properties;" ) );
|
||||
PROPERTIES = new Hashtable();
|
||||
for( int n = 0; n < array.columnLength(); n++ )
|
||||
{
|
||||
PROPERTIES.put( array.get( n, 0 ), array.get( n, 1 ) );
|
||||
}
|
||||
con.close();
|
||||
}
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
protected String createContent( Hashtable parameters, String[] form_fields, String template )
|
||||
{
|
||||
VelocityContext context = new VelocityContext();
|
||||
StringWriter output = new StringWriter();
|
||||
|
||||
try
|
||||
{
|
||||
for( int i = 0; i < form_fields.length; i++ )
|
||||
{
|
||||
context.put( form_fields[ i ], parameters.get( form_fields[ i ] ) );
|
||||
}
|
||||
|
||||
Velocity.mergeTemplate( template, Velocity.ENCODING_DEFAULT, context, output );
|
||||
|
||||
return output.toString();
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected String showResultPage( boolean success, String success_template, String fail_template )
|
||||
{
|
||||
VelocityContext context = new VelocityContext();
|
||||
StringWriter output = new StringWriter();
|
||||
String template;
|
||||
if( success )
|
||||
{
|
||||
template = success_template;
|
||||
}
|
||||
else
|
||||
{
|
||||
template = fail_template;
|
||||
}
|
||||
try
|
||||
{
|
||||
Velocity.mergeTemplate( template, Velocity.ENCODING_DEFAULT, context, output );
|
||||
return output.toString();
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected boolean sendMail( String from, String destination, String subject, String content, boolean html )
|
||||
{
|
||||
String smtp_server = "localhost";
|
||||
String mailer = "Evolute Mailer";
|
||||
|
||||
Properties props = System.getProperties();
|
||||
props.put( "mail.smtp.host", smtp_server );
|
||||
|
||||
String content_type = ( html ) ? "text/html" : "text/plain";
|
||||
|
||||
Session session = Session.getInstance( props, null );
|
||||
Message msg = new MimeMessage( session );
|
||||
try
|
||||
{
|
||||
if( from != null )
|
||||
{
|
||||
msg.setFrom( new InternetAddress( from ) );
|
||||
}
|
||||
msg.setRecipients( Message.RecipientType.TO, InternetAddress.parse( destination, true ) );
|
||||
msg.setSubject( subject );
|
||||
|
||||
msg.setContent( content.toString(), content_type );
|
||||
|
||||
msg.setHeader( "X-Mailer", mailer );
|
||||
msg.setSentDate( new java.util.Date() );
|
||||
Transport.send( msg );
|
||||
|
||||
return true;
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean sendMail( String from, String destination, String subject, String content, boolean html,
|
||||
String filename, byte attachment[], String type )
|
||||
{
|
||||
String smtp_server = "localhost";
|
||||
String mailer = "Evolute Mailer";
|
||||
|
||||
Properties props = System.getProperties();
|
||||
props.put( "mail.smtp.host", smtp_server );
|
||||
|
||||
String content_type = ( html ) ? "text/html" : "text/plain";
|
||||
|
||||
Session session = Session.getInstance( props, null );
|
||||
Message msg = new MimeMessage( session );
|
||||
try
|
||||
{
|
||||
if( from != null )
|
||||
{
|
||||
msg.setFrom( new InternetAddress( from ) );
|
||||
}
|
||||
msg.setRecipients( Message.RecipientType.TO, InternetAddress.parse( destination, true ) );
|
||||
msg.setSubject( subject );
|
||||
msg.setHeader( "X-Mailer", mailer );
|
||||
msg.setSentDate( new java.util.Date() );
|
||||
|
||||
Multipart multipart = new MimeMultipart();
|
||||
BodyPart messageBodyPart = new MimeBodyPart();
|
||||
messageBodyPart.setContent( content.toString(), content_type );
|
||||
multipart.addBodyPart(messageBodyPart);
|
||||
|
||||
messageBodyPart = new MimeBodyPart();
|
||||
// messageBodyPart.setDataHandler(
|
||||
// new DataHandler( new ByteArrayDataSource( attachment, "/siprpWeb/test.txt" )));
|
||||
messageBodyPart.setContent( attachment, content_type );
|
||||
DataSource source = new ByteArrayDataSource(attachment, type);
|
||||
messageBodyPart.setDataHandler(
|
||||
new DataHandler(source));
|
||||
messageBodyPart.setFileName(filename);
|
||||
|
||||
multipart.addBodyPart(messageBodyPart);
|
||||
msg.setContent(multipart);
|
||||
|
||||
Transport.send( msg );
|
||||
|
||||
return true;
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private String checkParameter( String parameter )
|
||||
{
|
||||
if( parameter != null && parameter.trim().length() > 0 )
|
||||
{
|
||||
return parameter.trim();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected Hashtable parseParameters( Hashtable parameters )
|
||||
{
|
||||
Hashtable tmp = new Hashtable();
|
||||
String[] element;
|
||||
String key;
|
||||
String new_element;
|
||||
for( Enumeration e = parameters.keys(); e.hasMoreElements(); )
|
||||
{
|
||||
key = ( String ) e.nextElement();
|
||||
element = ( String[] ) parameters.get( key );
|
||||
if( element != null )
|
||||
{
|
||||
new_element = checkParameter( element[ 0 ] );
|
||||
if( new_element != null )
|
||||
{
|
||||
tmp.put( key, new_element );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return tmp;
|
||||
}
|
||||
}
|
||||
@ -1,168 +0,0 @@
|
||||
/*
|
||||
* NewsServlet.java
|
||||
*
|
||||
* Created on 20 de Maio de 2005, 17:48
|
||||
*/
|
||||
|
||||
package siprp.pagina;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import javax.servlet.*;
|
||||
import javax.servlet.http.*;
|
||||
import java.sql.*;
|
||||
import org.apache.velocity.*;
|
||||
import org.apache.velocity.app.*;
|
||||
|
||||
import com.evolute.utils.*;
|
||||
import com.evolute.utils.arrays.*;
|
||||
import com.evolute.utils.db.*;
|
||||
import com.evolute.utils.sql.*;
|
||||
import com.evolute.utils.strings.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author lflores
|
||||
*/
|
||||
public class NewsServlet extends HttpServlet
|
||||
implements GlobalConstants
|
||||
{
|
||||
private static DBManager DBM = null;
|
||||
|
||||
private static final Select SELECT = new Select( new String[]{ "not_noticias" },
|
||||
new String[]{"data", "noticia"}, new Field( "id" ).in(
|
||||
new Field( "( SELECT MAX( id ) FROM not_noticias )" ) ) );
|
||||
|
||||
private SQLExecuter executer = null;
|
||||
|
||||
private static boolean velocityInit = false;
|
||||
|
||||
public void init()
|
||||
{
|
||||
if( !velocityInit )
|
||||
{
|
||||
try
|
||||
{
|
||||
String TEMPLATE_DIR = this.getServletContext().getRealPath( "/" ) + "html/";
|
||||
|
||||
Properties props = new Properties();
|
||||
props.setProperty( "file.resource.loader.path", TEMPLATE_DIR );
|
||||
Velocity.init( props );
|
||||
}
|
||||
catch( Exception ex )
|
||||
{
|
||||
ex.printStackTrace();
|
||||
}
|
||||
velocityInit = true;
|
||||
}
|
||||
|
||||
if( DBM != null )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
DBM = new JDBCManager( bdUrl + "?prepareThreshold=1",
|
||||
bdUsername, bdPassword , 8, 8, 0, new SQLQuery[] {} );
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void close()
|
||||
{
|
||||
try
|
||||
{
|
||||
DBM.close();
|
||||
DBM = null;
|
||||
}
|
||||
catch( Exception ex )
|
||||
{
|
||||
// we come here after an error
|
||||
// so we discard this exception
|
||||
}
|
||||
}
|
||||
|
||||
private String getNews()
|
||||
{
|
||||
//System.err.println( "NEWS: BEGIN" );
|
||||
try
|
||||
{
|
||||
if( executer == null )
|
||||
{
|
||||
executer = ( SQLExecuter )DBM.getSharedExecuter();
|
||||
}
|
||||
Virtual2DArray array = executer.executeQuery( SELECT );
|
||||
Object o[][] = array.getObjects();
|
||||
if( o != null && o.length > 0 )
|
||||
{
|
||||
//System.err.println( "NEWS: " + o[ 0 ][ 0 ].toString() );
|
||||
return
|
||||
//o[ 0 ][ 0 ].toString() +
|
||||
StringConverter.unicodeToHTML( o[ 0 ][ 1 ].toString() );
|
||||
}
|
||||
}
|
||||
catch( Exception ex )
|
||||
{
|
||||
//System.err.println( "NEWS: EX" );
|
||||
ex.printStackTrace();
|
||||
close();
|
||||
}
|
||||
//System.err.println( "NEWS: END" );
|
||||
return null;
|
||||
}
|
||||
|
||||
public void doGet( HttpServletRequest req, HttpServletResponse res )
|
||||
throws IOException
|
||||
{
|
||||
//System.err.println( "NEWS: GET BEGIN" );
|
||||
init();
|
||||
//System.err.println( "NEWS: AF INIT" );
|
||||
ServletOutputStream out = res.getOutputStream();
|
||||
// String queryString = req.getQueryString();
|
||||
res.setContentType( "text/html" );
|
||||
String news = getNews();
|
||||
Hashtable parameters = new Hashtable();
|
||||
if( news == null )
|
||||
{
|
||||
parameters.put( "noticias", "" );
|
||||
}
|
||||
else
|
||||
{
|
||||
parameters.put( "noticias", news );
|
||||
}
|
||||
//System.err.println( "NEWS: BF SHOW" );
|
||||
out.println( showPage( "noticias/mostrar_noticias.html", parameters ) );
|
||||
}
|
||||
|
||||
private String showPage( String page, Hashtable parameters )
|
||||
{
|
||||
VelocityContext context = new VelocityContext();
|
||||
StringWriter output = new StringWriter();
|
||||
|
||||
try
|
||||
{
|
||||
if( parameters != null )
|
||||
{
|
||||
String key;
|
||||
for( Enumeration e = parameters.keys(); e.hasMoreElements(); )
|
||||
{
|
||||
key = ( String ) e.nextElement();
|
||||
context.put( key, parameters.get( key ) );
|
||||
}
|
||||
}
|
||||
|
||||
Velocity.mergeTemplate( page, Velocity.ENCODING_DEFAULT, context, output );
|
||||
|
||||
return output.toString();
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -1,127 +0,0 @@
|
||||
/*
|
||||
* RequestServlet.java
|
||||
*
|
||||
* Created on 4 de Março de 2005, 18:19
|
||||
*/
|
||||
|
||||
package siprp.pagina;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
import javax.servlet.*;
|
||||
import javax.servlet.http.*;
|
||||
|
||||
import org.apache.commons.fileupload.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author psantos
|
||||
*/
|
||||
public class RecruitServlet extends MailerServlet
|
||||
{
|
||||
private final static String REC_FUNCAO = "rec_funcao";
|
||||
private final static String REC_NOME = "rec_nome";
|
||||
private final static String REC_MORADA = "rec_morada";
|
||||
private final static String REC_TELEFONE = "rec_telefone";
|
||||
private final static String REC_EMAIL = "rec_email";
|
||||
private final static String REC_CV = "rec_cv";
|
||||
|
||||
private final static String[] FORM_FIELDS = new String[]{
|
||||
REC_FUNCAO, REC_NOME, REC_MORADA,
|
||||
REC_TELEFONE, REC_EMAIL, REC_CV
|
||||
};
|
||||
|
||||
public void doPost( HttpServletRequest req, HttpServletResponse res )
|
||||
throws IOException
|
||||
{
|
||||
Hashtable parameters;
|
||||
String fileName = "";
|
||||
String type = "";
|
||||
byte file[] = new byte[0];
|
||||
boolean isMultipart = FileUpload.isMultipartContent( req );
|
||||
|
||||
ServletOutputStream out = res.getOutputStream();
|
||||
res.setContentType( "text/html" );
|
||||
|
||||
if( isMultipart )
|
||||
{
|
||||
parameters = new Hashtable();
|
||||
DiskFileUpload upload = new DiskFileUpload();
|
||||
upload.setSizeThreshold(1000000);
|
||||
upload.setSizeMax(1000000);
|
||||
List items;
|
||||
try
|
||||
{
|
||||
items = upload.parseRequest(req);
|
||||
}
|
||||
catch( FileUploadException ex )
|
||||
{
|
||||
out.println( showResultPage( false, "mail/pedido_enviado.html", "mail/pedido_nao_enviado.html" ) );
|
||||
return;
|
||||
}
|
||||
Iterator iter = items.iterator();
|
||||
while( iter.hasNext() )
|
||||
{
|
||||
FileItem item = (FileItem) iter.next();
|
||||
|
||||
if (item.isFormField())
|
||||
{
|
||||
String name = item.getFieldName();
|
||||
String value = item.getString();
|
||||
parameters.put( name, value );
|
||||
}
|
||||
else
|
||||
{
|
||||
String fieldName = item.getFieldName();
|
||||
fileName = item.getName();
|
||||
file = item.get();
|
||||
if( file == null || file.length == 0 )
|
||||
{
|
||||
isMultipart = false;
|
||||
}
|
||||
type = item.getContentType();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
parameters = parseParameters( new Hashtable( req.getParameterMap() ) );
|
||||
}
|
||||
String content = createContent( parameters, FORM_FIELDS, "mail/envio_cv.txt" );
|
||||
|
||||
String email = DEFAULT_EMAIL;
|
||||
if( PROPERTIES != null && PROPERTIES.containsKey( EMAIL_RECRUTAMENTO ) )
|
||||
{
|
||||
email = ( String ) PROPERTIES.get( EMAIL_RECRUTAMENTO );
|
||||
}
|
||||
String from = email;
|
||||
String destination = email;
|
||||
String subject = "Envio de CV através do site www.siprp.pt";
|
||||
// manda mail
|
||||
boolean success;
|
||||
String nome = ( String ) parameters.get( REC_NOME );
|
||||
String telefone = ( String ) parameters.get( REC_TELEFONE );
|
||||
String mail = ( String ) parameters.get( REC_EMAIL );
|
||||
if( nome == null || nome.trim().length() == 0 || telefone == null || telefone.trim().length() == 0 ||
|
||||
mail == null || mail.trim().length() == 0 || mail.indexOf( '@' ) == -1 )
|
||||
{
|
||||
System.out.println( "nome: " + nome + " teefone: " + telefone + " email : " + email );
|
||||
success = false;
|
||||
}
|
||||
else if( isMultipart )
|
||||
{
|
||||
System.out.println( "Multipart" );
|
||||
success = sendMail( from, destination, subject, content, false, fileName, file, type );
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println( "Normal" );
|
||||
success = sendMail( from, destination, subject, content, false );
|
||||
}
|
||||
|
||||
// mostra pagina correspondente
|
||||
|
||||
out.println( showResultPage( success, "mail/cv_enviado.html", "mail/cv_nao_enviado.html" ) );
|
||||
}
|
||||
}
|
||||
@ -1,121 +0,0 @@
|
||||
/*
|
||||
* RelatorioServlet.java
|
||||
*
|
||||
* Created on 27 de Abril de 2005, 16:16
|
||||
*/
|
||||
|
||||
package siprp.pagina;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
import javax.servlet.*;
|
||||
import javax.servlet.http.*;
|
||||
|
||||
import org.apache.velocity.*;
|
||||
import org.apache.velocity.app.*;
|
||||
/**
|
||||
*
|
||||
* @author fpalma
|
||||
*/
|
||||
public class RelatorioServlet extends MailerServlet
|
||||
{
|
||||
private final static String EMPRESA = "empresa";
|
||||
private final static String EMAIL_EMPRESA = "email_empresa";
|
||||
private final static String ANO = "ano";
|
||||
|
||||
private final static String[] FORM_FIELDS = new String[]{
|
||||
EMPRESA, ANO, EMAIL_EMPRESA };
|
||||
|
||||
public void doGet( HttpServletRequest req, HttpServletResponse res )
|
||||
throws IOException
|
||||
{
|
||||
ServletOutputStream out = res.getOutputStream();
|
||||
String queryString = req.getQueryString();
|
||||
res.setContentType( "text/html" );
|
||||
|
||||
Hashtable parameters = new Hashtable();
|
||||
|
||||
// Ir buscar os parametros à sessão
|
||||
HttpSession session = req.getSession( false );
|
||||
if( session == null )
|
||||
{
|
||||
// timeout
|
||||
out.println( showPage( "relatorio/pedido_sessao_expirou.html", null ) );
|
||||
return;
|
||||
}
|
||||
|
||||
out.println( showPage( "relatorio/pedido_relatorio.html", parameters ) );
|
||||
}
|
||||
|
||||
public void doPost( HttpServletRequest req, HttpServletResponse res )
|
||||
throws IOException
|
||||
{
|
||||
ServletOutputStream out = res.getOutputStream();
|
||||
String queryString = req.getQueryString();
|
||||
res.setContentType( "text/html" );
|
||||
|
||||
// Info de marcacao
|
||||
// Dados que vem no pedido: marcacao_tipo, data, hora
|
||||
Hashtable parameters = parseParameters( new Hashtable( req.getParameterMap() ) );
|
||||
|
||||
// Ir buscar o resto dos parametros à sessão
|
||||
HttpSession session = req.getSession( false );
|
||||
if( session == null )
|
||||
{
|
||||
// timeout
|
||||
out.println( showPage( "relatorio/pedido_sessao_expirou.html", null ) );
|
||||
return;
|
||||
}
|
||||
|
||||
parameters.put( EMPRESA, session.getAttribute( siprpServlet.sessionCompanyName ) );
|
||||
String from = ( String ) session.getAttribute( siprpServlet.sessionCompanyEmail );
|
||||
|
||||
String email = DEFAULT_EMAIL;
|
||||
if( PROPERTIES != null && PROPERTIES.containsKey( EMAIL ) )
|
||||
{
|
||||
email = ( String ) PROPERTIES.get( EMAIL );
|
||||
}
|
||||
String destination = email;
|
||||
String subject = "Pedido de envio de relatorio via web";
|
||||
if( parameters.get( ANO ) == null )
|
||||
{
|
||||
parameters.put( ANO, "corrente" );
|
||||
}
|
||||
String content = createContent( parameters, FORM_FIELDS, "relatorio/pedido.html" );
|
||||
// manda mail
|
||||
boolean success = sendMail( from, destination, subject, content, true );
|
||||
|
||||
// mostra pagina correspondente
|
||||
out.println( showResultPage( success, "relatorio/pedido_enviado.html", "relatorio/pedido_nao_enviado.html" ) );
|
||||
}
|
||||
|
||||
private String showPage( String page, Hashtable parameters )
|
||||
{
|
||||
VelocityContext context = new VelocityContext();
|
||||
StringWriter output = new StringWriter();
|
||||
|
||||
try
|
||||
{
|
||||
if( parameters != null )
|
||||
{
|
||||
String key;
|
||||
for( Enumeration e = parameters.keys(); e.hasMoreElements(); )
|
||||
{
|
||||
key = ( String ) e.nextElement();
|
||||
context.put( key, parameters.get( key ) );
|
||||
}
|
||||
}
|
||||
|
||||
Velocity.mergeTemplate( page, Velocity.ENCODING_DEFAULT, context, output );
|
||||
|
||||
return output.toString();
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -1,63 +0,0 @@
|
||||
/*
|
||||
* RequestServlet.java
|
||||
*
|
||||
* Created on 4 de Março de 2005, 18:19
|
||||
*/
|
||||
|
||||
package siprp.pagina;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
import javax.servlet.*;
|
||||
import javax.servlet.http.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author psantos
|
||||
*/
|
||||
public class RequestServlet extends MailerServlet
|
||||
{
|
||||
private final static String REQUEST_NAME = "request_name";
|
||||
private final static String REQUEST_PHONE = "request_phone";
|
||||
private final static String REQUEST_EMAIL = "request_email";
|
||||
private final static String REQUEST_DETAILS = "request_details";
|
||||
|
||||
private final static String[] FORM_FIELDS = new String[]{
|
||||
REQUEST_NAME, REQUEST_PHONE,
|
||||
REQUEST_EMAIL, REQUEST_DETAILS
|
||||
};
|
||||
|
||||
public void doPost( HttpServletRequest req, HttpServletResponse res )
|
||||
throws IOException
|
||||
{
|
||||
ServletOutputStream out = res.getOutputStream();
|
||||
res.setContentType( "text/html" );
|
||||
|
||||
/*
|
||||
parametros:
|
||||
request_name
|
||||
request_phone
|
||||
request_email
|
||||
request_details
|
||||
*/
|
||||
// recebe info de contacto
|
||||
Hashtable parameters = parseParameters( new Hashtable( req.getParameterMap() ) );
|
||||
|
||||
String content = createContent( parameters, FORM_FIELDS, "mail/pedido_informacao.txt" );
|
||||
|
||||
String from = ( String ) parameters.get( REQUEST_EMAIL );
|
||||
String email = DEFAULT_EMAIL;
|
||||
if( PROPERTIES != null && PROPERTIES.containsKey( EMAIL ) )
|
||||
{
|
||||
email = ( String ) PROPERTIES.get( EMAIL );
|
||||
}
|
||||
String destination = email;
|
||||
String subject = "Pedido de informação através do site www.siprp.pt";
|
||||
// manda mail
|
||||
boolean success = sendMail( from, destination, subject, content, false );
|
||||
|
||||
// mostra pagina correspondente
|
||||
out.println( showResultPage( success, "mail/pedido_enviado.html", "mail/pedido_nao_enviado.html" ) );
|
||||
}
|
||||
}
|
||||
@ -1,142 +0,0 @@
|
||||
/*
|
||||
* ScheduleServlet.java
|
||||
*
|
||||
* Created on 10 de Março de 2005, 12:22
|
||||
*/
|
||||
|
||||
package siprp.pagina;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
import javax.servlet.*;
|
||||
import javax.servlet.http.*;
|
||||
|
||||
import org.apache.velocity.*;
|
||||
import org.apache.velocity.app.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author psantos
|
||||
*/
|
||||
public class ScheduleServlet extends MailerServlet
|
||||
{
|
||||
private final static String EMPRESA = "empresa";
|
||||
private final static String ESTABELECIMENTO = "estabelecimento";
|
||||
private final static String FUNCIONARIO = "funcionario";
|
||||
private final static String MARCACAO_TIPO = "marcacao_tipo";
|
||||
private final static String DATA = "data";
|
||||
private final static String HORA = "hora";
|
||||
private final static String EMAIL_EMPRESA = "email_empresa";
|
||||
|
||||
private final static String[] FORM_FIELDS = new String[]{
|
||||
EMPRESA, ESTABELECIMENTO, FUNCIONARIO,
|
||||
MARCACAO_TIPO, DATA, HORA, EMAIL_EMPRESA
|
||||
};
|
||||
|
||||
public void doGet( HttpServletRequest req, HttpServletResponse res )
|
||||
throws IOException
|
||||
{
|
||||
ServletOutputStream out = res.getOutputStream();
|
||||
String queryString = req.getQueryString();
|
||||
res.setContentType( "text/html" );
|
||||
|
||||
Hashtable parameters = new Hashtable();
|
||||
|
||||
// Ir buscar os parametros à sessão
|
||||
HttpSession session = req.getSession( false );
|
||||
if( session == null )
|
||||
{
|
||||
// timeout
|
||||
out.println( showPage( "marcacao/marcacao_sessao_expirou.html", null ) );
|
||||
return;
|
||||
}
|
||||
|
||||
parameters.put( EMPRESA, session.getAttribute( siprpServlet.sessionCompanyName ) );
|
||||
parameters.put( ESTABELECIMENTO, session.getAttribute( "session_estabelecimento_nome" ) );
|
||||
parameters.put( FUNCIONARIO, session.getAttribute( "session_funcionario_nome" ) );
|
||||
|
||||
String tokens[] = queryString.split( "[?]" );
|
||||
if( tokens.length > 0 && tokens[ tokens.length - 1 ].equals( "consulta" ) )
|
||||
{
|
||||
out.println( showPage( "marcacao/marcacao_consulta.html", parameters ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
out.println( showPage( "marcacao/marcacao_exame.html", parameters ) );
|
||||
}
|
||||
}
|
||||
|
||||
public void doPost( HttpServletRequest req, HttpServletResponse res )
|
||||
throws IOException
|
||||
{
|
||||
ServletOutputStream out = res.getOutputStream();
|
||||
String queryString = req.getQueryString();
|
||||
res.setContentType( "text/html" );
|
||||
|
||||
// Info de marcacao
|
||||
// Dados que vem no pedido: marcacao_tipo, data, hora
|
||||
Hashtable parameters = parseParameters( new Hashtable( req.getParameterMap() ) );
|
||||
|
||||
// Ir buscar o resto dos parametros à sessão
|
||||
HttpSession session = req.getSession( false );
|
||||
if( session == null )
|
||||
{
|
||||
// timeout
|
||||
out.println( showPage( "marcacao/marcacao_sessao_expirou.html", null ) );
|
||||
return;
|
||||
}
|
||||
|
||||
parameters.put( EMPRESA, session.getAttribute( siprpServlet.sessionCompanyName ) );
|
||||
parameters.put( ESTABELECIMENTO, session.getAttribute( "session_estabelecimento_nome" ) );
|
||||
parameters.put( FUNCIONARIO, session.getAttribute( "session_funcionario_nome" ) );
|
||||
//parameters.put( session.getAttribute( "session_funcionario_numero" ) );
|
||||
|
||||
String from = ( String ) session.getAttribute( siprpServlet.sessionCompanyEmail );
|
||||
|
||||
String marcacao_tipo = ( String )parameters.get( MARCACAO_TIPO );
|
||||
|
||||
String email = DEFAULT_EMAIL;
|
||||
if( PROPERTIES != null && PROPERTIES.containsKey( EMAIL_MARCACAO ) )
|
||||
{
|
||||
email = ( String ) PROPERTIES.get( EMAIL_MARCACAO );
|
||||
}
|
||||
String destination = email;
|
||||
String subject = "Pedido de marca\u00e7\u00e3o de " + marcacao_tipo + " via web";
|
||||
String content = createContent( parameters, FORM_FIELDS, "marcacao/marcacao.html" );
|
||||
// manda mail
|
||||
boolean success = sendMail( from, destination, subject, content, true );
|
||||
|
||||
// mostra pagina correspondente
|
||||
out.println( showResultPage( success, "marcacao/marcacao_enviada.html", "marcacao/marcacao_nao_enviada.html" ) );
|
||||
}
|
||||
|
||||
private String showPage( String page, Hashtable parameters )
|
||||
{
|
||||
VelocityContext context = new VelocityContext();
|
||||
StringWriter output = new StringWriter();
|
||||
|
||||
try
|
||||
{
|
||||
if( parameters != null )
|
||||
{
|
||||
String key;
|
||||
for( Enumeration e = parameters.keys(); e.hasMoreElements(); )
|
||||
{
|
||||
key = ( String ) e.nextElement();
|
||||
context.put( key, parameters.get( key ) );
|
||||
}
|
||||
}
|
||||
|
||||
Velocity.mergeTemplate( page, Velocity.ENCODING_DEFAULT, context, output );
|
||||
|
||||
return output.toString();
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -1,113 +0,0 @@
|
||||
package siprp.pagina;
|
||||
|
||||
import com.evolute.utils.arrays.*;
|
||||
import com.evolute.utils.strings.*;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import java.sql.*;
|
||||
import java.lang.reflect.Array;
|
||||
import javax.servlet.*;
|
||||
import javax.servlet.http.*;
|
||||
import org.apache.velocity.*;
|
||||
import org.apache.velocity.app.*;
|
||||
|
||||
public class doGetListaEmpresas extends siprpServlet{
|
||||
|
||||
/** Creates a new instance of doGetListaEmpresas */
|
||||
public doGetListaEmpresas(HttpServletRequest req, HttpServletResponse res) throws IOException
|
||||
{
|
||||
ServletOutputStream out = res.getOutputStream();
|
||||
Connection con = null ;
|
||||
Statement stmt = null ;
|
||||
ResultSet2DArray rs;
|
||||
StringBuffer dbQuery;
|
||||
String userRole="", temp="";
|
||||
HttpSession session = req.getSession(false);
|
||||
Vector links = new Vector();
|
||||
Vector desc = new Vector();
|
||||
String empresa_nome;
|
||||
try
|
||||
{
|
||||
userRole = (String)session.getAttribute(super.sessionUserRole);
|
||||
empresa_nome = ( String ) session.getAttribute( sessionCompanyName );
|
||||
|
||||
if (userRole == null)
|
||||
{
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
if ( userRole.equals ( super.superUserRole ) )
|
||||
{
|
||||
empresa_nome = null;
|
||||
Class.forName(super.bdDriver);
|
||||
con = DriverManager.getConnection( bdLocalUrl, bdLocalUsername, bdLocalPassword );
|
||||
dbQuery = new StringBuffer();
|
||||
dbQuery.append( "SELECT id, designacao_social, designacao_social_plain FROM empresas WHERE inactivo <> 'y' ORDER BY designacao_social_plain" );
|
||||
stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
|
||||
rs = new ResultSet2DArray( stmt.executeQuery( dbQuery.toString()) );
|
||||
|
||||
int index=0;
|
||||
int max = rs.columnLength();
|
||||
|
||||
while ( index < max )
|
||||
{
|
||||
String str = (String)rs.get(index,1);
|
||||
if( str != null && str.trim().length() > 0 )
|
||||
{
|
||||
temp=""+rs.get(index,0); // converter de int para String
|
||||
dbQuery = new StringBuffer();
|
||||
dbQuery.append("/"+super.servletName+"/?"+temp); // contruir url
|
||||
links.add(dbQuery.toString());
|
||||
desc.add((String)rs.get(index,1));
|
||||
}
|
||||
++index;
|
||||
}
|
||||
stmt.close();
|
||||
con.close();
|
||||
|
||||
|
||||
session.setAttribute( sessionEstabelecimentoId, null );
|
||||
|
||||
HashMap hmValues = new HashMap();
|
||||
//hmValues.put( "empresa_nome", session.getAttribute( sessionCompanyName ) );
|
||||
hmValues.put( "empresa_nome", empresa_nome );
|
||||
hmValues.put( "empresa_id", session.getAttribute( sessionEmpresaId ) );
|
||||
hmValues.put( "estabelecimento_id", session.getAttribute( sessionEstabelecimentoId ) );
|
||||
hmValues.put( "userRole", userRole );
|
||||
hmValues.put( "userName", session.getAttribute( sessionUser ) );
|
||||
hmValues.put( msgTemplate , super.msgListaEmpresas ) ;
|
||||
hmValues.put( templateUserRole, userRole);
|
||||
hmValues.put( templateQuery, super.queryStringEmpresas );
|
||||
hmValues.put( templateVector1,links);
|
||||
hmValues.put( templateVector2,desc);
|
||||
hmValues.put( templateVector3,null);
|
||||
out.println( mergeTemplate( hmValues, super.authenticatedUserTemplate));
|
||||
|
||||
|
||||
//out.println( mergeTemplate( super.msgListaEmpresas, userRole, super.queryStringEmpresas, links, desc, null, super.authenticatedUserTemplate) );
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
out.println( mergeTemplate( super.msgAcessoNegado , userRole, super.errorTemplate) );
|
||||
}
|
||||
|
||||
}
|
||||
catch ( IllegalStateException e ) // session timeout
|
||||
{
|
||||
e.printStackTrace();
|
||||
out.println( mergeTemplate(msgSessionTimeout, super.errorTemplate) );
|
||||
}
|
||||
catch ( SQLException e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
out.println( mergeTemplate( super.msgErroBd , super.errorTemplate) );
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
out.println( mergeTemplate( super.msgGenericError , userRole, super.errorTemplate) );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,105 +0,0 @@
|
||||
package siprp.pagina;
|
||||
|
||||
import com.evolute.utils.arrays.*;
|
||||
import com.evolute.utils.strings.*;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import java.sql.*;
|
||||
import java.lang.reflect.Array;
|
||||
import javax.servlet.*;
|
||||
import javax.servlet.http.*;
|
||||
import org.apache.velocity.*;
|
||||
import org.apache.velocity.app.*;
|
||||
|
||||
public class doGetListaEstabelecimentos extends siprpServlet{
|
||||
|
||||
/** Creates a new instance of doGetListaEstabelecimentos */
|
||||
public doGetListaEstabelecimentos(HttpServletRequest req, HttpServletResponse res) throws IOException
|
||||
{
|
||||
ServletOutputStream out = res.getOutputStream();
|
||||
Connection con = null ;
|
||||
Statement stmt = null ;
|
||||
ResultSet2DArray rs;
|
||||
StringBuffer dbQuery, sBuffer;
|
||||
String userRole, empresaId, temp;
|
||||
HttpSession session = req.getSession(false);
|
||||
Vector links = new Vector();
|
||||
Vector desc = new Vector();
|
||||
try
|
||||
{
|
||||
userRole = (String)session.getAttribute(super.sessionUserRole);
|
||||
empresaId = (String)session.getAttribute(super.sessionEmpresaId);
|
||||
|
||||
if ( userRole.equals ( super.superUserRole ) || userRole.equals ( empresaId ) )
|
||||
{
|
||||
Class.forName(super.bdDriver);
|
||||
con = DriverManager.getConnection( bdLocalUrl, bdLocalUsername, bdLocalPassword );
|
||||
dbQuery = new StringBuffer();
|
||||
dbQuery.append( " SELECT id, nome, nome_plain FROM estabelecimentos WHERE inactivo <> 'y' AND empresa_id = '"+empresaId+"' order by nome_plain" );
|
||||
stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
|
||||
rs = new ResultSet2DArray( stmt.executeQuery( dbQuery.toString()) );
|
||||
|
||||
int index=0;
|
||||
int max = rs.columnLength();
|
||||
|
||||
while ( index < max )
|
||||
{
|
||||
temp=""+rs.get(index,0); // converter de int para String
|
||||
dbQuery = new StringBuffer();
|
||||
dbQuery.append("/"+super.servletName+"/?"+empresaId+"/"+temp); // contruir url
|
||||
links.add(dbQuery.toString());
|
||||
desc.add((String)rs.get(index,1));
|
||||
++index;
|
||||
}
|
||||
sBuffer = new StringBuffer();
|
||||
sBuffer.append("<b>"+super.nomeEmpresa(con,empresaId)+"</b>");
|
||||
|
||||
if( userRole.equals( "manager" ) )
|
||||
{
|
||||
session.setAttribute( sessionCompanyName, nomeEmpresa( con, ( String ) session.getAttribute( sessionEmpresaId ) ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
session.setAttribute( sessionCompanyName, nomeEmpresa( con, userRole ) );
|
||||
}
|
||||
|
||||
session.setAttribute( sessionCompanyEmail, emailEmpresa( con, empresaId ) );
|
||||
|
||||
session.setAttribute( sessionEstabelecimentoId, null );
|
||||
|
||||
HashMap hmValues = new HashMap();
|
||||
hmValues.put( "empresa_nome", session.getAttribute( sessionCompanyName ) );
|
||||
hmValues.put( "empresa_id", session.getAttribute( sessionEmpresaId ) );
|
||||
hmValues.put( "estabelecimento_id", session.getAttribute( sessionEstabelecimentoId ) );
|
||||
hmValues.put( "userRole", userRole );
|
||||
hmValues.put( "userName", session.getAttribute( sessionUser ) );
|
||||
hmValues.put( msgTemplate , sBuffer.toString() ) ;
|
||||
hmValues.put( templateUserRole, userRole);
|
||||
hmValues.put( templateQuery, super.queryStringEstabelecimentos );
|
||||
hmValues.put( templateVector1,links);
|
||||
hmValues.put( templateVector2,desc);
|
||||
hmValues.put( templateVector3,null);
|
||||
out.println( mergeTemplate( hmValues, super.authenticatedUserTemplate));
|
||||
|
||||
// out.println( mergeTemplate( sBuffer.toString(), userRole, super.queryStringEstabelecimentos, links, desc, null, super.authenticatedUserTemplate) );
|
||||
stmt.close();
|
||||
con.close();
|
||||
}
|
||||
else
|
||||
{
|
||||
out.println( mergeTemplate( super.msgAcessoNegado , userRole, super.errorTemplate) );
|
||||
}
|
||||
}
|
||||
catch ( SQLException e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
out.println( mergeTemplate( super.msgErroBd , super.errorTemplate) );
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
out.println( mergeTemplate( super.msgGenericError , super.errorTemplate) );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,299 +0,0 @@
|
||||
package siprp.pagina;
|
||||
|
||||
import com.evolute.utils.arrays.*;
|
||||
import com.evolute.utils.strings.*;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import java.sql.*;
|
||||
import java.lang.reflect.Array;
|
||||
import javax.servlet.*;
|
||||
import javax.servlet.http.*;
|
||||
import org.apache.velocity.*;
|
||||
import org.apache.velocity.app.*;
|
||||
|
||||
public class doGetListaTrabalhadores extends siprpServlet{
|
||||
|
||||
/** Creates a new instance of doGetListaTrabalhadores */
|
||||
public doGetListaTrabalhadores(HttpServletRequest req, HttpServletResponse res, String query) throws IOException
|
||||
{
|
||||
boolean print = false;
|
||||
if( query != null )
|
||||
{
|
||||
print = query.indexOf( "_print" ) != -1;
|
||||
if( query.indexOf( "trabalhadores_tudo" ) == 0 )
|
||||
{
|
||||
new doGetListaTrabalhadoresTudo( req, res, print );
|
||||
return;
|
||||
}
|
||||
else if( query.indexOf( "trabalhadores_pendentes" ) == 0 )
|
||||
{
|
||||
new doGetListaTrabalhadoresPendentes( req, res, print );
|
||||
return;
|
||||
}
|
||||
}
|
||||
ServletOutputStream out = res.getOutputStream();
|
||||
Connection con = null ;
|
||||
Statement stmt = null ;
|
||||
ResultSet2DArray rs, rsTrab;
|
||||
StringBuffer sBuffer;
|
||||
String userRole, empresaId, estabelecimentoId, temp;
|
||||
HttpSession session = req.getSession(false);
|
||||
Vector links = new Vector();
|
||||
Vector desc = new Vector();
|
||||
Vector descAdicional = new Vector();
|
||||
java.util.Date today = new java.util.Date();
|
||||
try
|
||||
{
|
||||
userRole = (String)session.getAttribute(super.sessionUserRole);
|
||||
empresaId = (String)session.getAttribute(super.sessionEmpresaId);
|
||||
estabelecimentoId = (String)session.getAttribute(super.sessionEstabelecimentoId);
|
||||
|
||||
if ( userRole.equals ( super.superUserRole ) || userRole.equals ( empresaId ) )
|
||||
{
|
||||
Class.forName(super.bdDriver);
|
||||
con = DriverManager.getConnection( bdLocalUrl, bdLocalUsername, bdLocalPassword );
|
||||
if ( super.verificaEstabelecimento(con, empresaId, estabelecimentoId) ) // estabelecimento pertence à empresa ??
|
||||
{
|
||||
//Class.forName(super.bdDriver);
|
||||
//con = DriverManager.getConnection( super.bdUrl, super.bdUsername, super.bdPassword );
|
||||
String dbQuery = "SELECT id, nome, nome_plain FROM trabalhadores WHERE inactivo <> 'y' AND data_demissao IS NULL AND estabelecimento_id = '"+estabelecimentoId+"' ORDER BY nome_plain";
|
||||
stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
|
||||
rsTrab = new ResultSet2DArray( stmt.executeQuery( dbQuery ) );
|
||||
rsTrab.getObjects();
|
||||
stmt.close();
|
||||
|
||||
final int max = rsTrab.columnLength();
|
||||
|
||||
for ( int index = 0; index < max; index++ )
|
||||
{
|
||||
Integer id = (Integer)rsTrab.get(index,0);
|
||||
String link = "/"+super.servletName+"/?"+empresaId+"/"+estabelecimentoId+"/"+id;
|
||||
links.add(link);
|
||||
HashMap trabalhador = new HashMap();
|
||||
trabalhador.put( "Nome", (String)rsTrab.get(index,1) );
|
||||
|
||||
|
||||
dbQuery = "SELECT id, data, estado FROM marcacoes_trabalhador "
|
||||
+ "WHERE tipo = 1 and trabalhador_id = " + id
|
||||
+ " ORDER BY data DESC";
|
||||
stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
|
||||
rs = new ResultSet2DArray( stmt.executeQuery( dbQuery ) );
|
||||
rs.getObjects();
|
||||
stmt.close();
|
||||
if( rs.columnLength() > 0 )
|
||||
{
|
||||
java.util.Date dataConsulta2 = ( java.util.Date ) rs.get( 0, 1 );
|
||||
Integer estado2 = ( Integer ) rs.get( 0, 2 );
|
||||
java.util.Date dataConsulta1;
|
||||
// java.util.Date dataRelatorio1;
|
||||
// java.util.Date dataRelatorio2 = (java.util.Date) rs.get( 0, 3 );
|
||||
Integer estado1;
|
||||
String realizada1 = "";
|
||||
String realizada2 = "";
|
||||
if( rs.columnLength() >= 2 )
|
||||
{
|
||||
dataConsulta1 = ( java.util.Date ) rs.get( 1, 1 );
|
||||
estado1 = ( Integer ) rs.get( 1, 2 );
|
||||
// dataRelatorio1 = (java.util.Date) rs.get( 1, 3 );
|
||||
}
|
||||
else
|
||||
{
|
||||
dataConsulta1 = dataConsulta2;
|
||||
estado1 = estado2;
|
||||
// dataRelatorio1 = dataRelatorio2;
|
||||
}
|
||||
if( ESTADO_REALIZADO.equals( estado2 ) || today.after( dataConsulta2 ) )
|
||||
{
|
||||
trabalhador.put( "ultima_consulta", dataConsulta2 );
|
||||
if( estado2.equals( ESTADO_POR_REALIZAR ) )
|
||||
{
|
||||
realizada2 = "não";
|
||||
}
|
||||
else if( estado2.equals( ESTADO_REALIZADO ) )
|
||||
{
|
||||
realizada2 = "sim";
|
||||
}
|
||||
trabalhador.put( "realizada", realizada2 );
|
||||
trabalhador.put( "proxima_consulta", "" );
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
for( int c = 1; c < rs.columnLength(); c++ )
|
||||
{
|
||||
java.util.Date dataTemp = ( java.util.Date ) rs.get( c, 1 );
|
||||
dataConsulta1 = dataTemp;
|
||||
estado1 = ( Integer ) rs.get( c, 2 );
|
||||
if( dataTemp.after( today ) )
|
||||
{
|
||||
dataConsulta2 = dataTemp;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch( Exception ex )
|
||||
{
|
||||
ex.printStackTrace();
|
||||
}
|
||||
trabalhador.put( "proxima_consulta", dataConsulta2 );
|
||||
|
||||
if( !dataConsulta2.equals( dataConsulta1 ) )
|
||||
{
|
||||
if( estado1.equals( ESTADO_POR_REALIZAR ) )
|
||||
{
|
||||
realizada1 = "não";
|
||||
}
|
||||
else if( estado1.equals( ESTADO_REALIZADO ) )
|
||||
{
|
||||
realizada1 = "sim";
|
||||
}
|
||||
trabalhador.put( "realizada", realizada1 );
|
||||
trabalhador.put( "ultima_consulta", dataConsulta1 );
|
||||
}
|
||||
else
|
||||
{
|
||||
trabalhador.put( "ultima_consulta", "" );
|
||||
trabalhador.put( "realizada", null );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
trabalhador.put( "ultima_consulta", "" );
|
||||
trabalhador.put( "realizada", null );
|
||||
trabalhador.put( "proxima_consulta", "" );
|
||||
}
|
||||
|
||||
|
||||
dbQuery = "SELECT id, data, estado FROM marcacoes_trabalhador "
|
||||
+ "WHERE tipo = 0 and trabalhador_id = " + id
|
||||
+ " ORDER BY data DESC";
|
||||
stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
|
||||
rs = new ResultSet2DArray( stmt.executeQuery( dbQuery ) );
|
||||
rs.getObjects();
|
||||
stmt.close();
|
||||
if( rs.columnLength() > 0 )
|
||||
{
|
||||
java.util.Date dataConsulta2 = ( java.util.Date ) rs.get( 0, 1 );
|
||||
Integer estado2 = ( Integer ) rs.get( 0, 2 );
|
||||
Integer estado1;
|
||||
java.util.Date dataConsulta1;
|
||||
// java.util.Date dataRelatorio1;
|
||||
// java.util.Date dataRelatorio2 = (java.util.Date) rs.get( 0, 3 );
|
||||
String realizada1 = "";
|
||||
String realizada2 = "";
|
||||
if( rs.columnLength() >= 2 )
|
||||
{
|
||||
dataConsulta1 = ( java.util.Date ) rs.get( 1, 1 );
|
||||
estado1 = ( Integer ) rs.get( 1, 2 );
|
||||
// dataRelatorio1 = (java.util.Date) rs.get( 1, 3 );
|
||||
}
|
||||
else
|
||||
{
|
||||
dataConsulta1 = dataConsulta2;
|
||||
estado1 = estado2;
|
||||
// dataRelatorio1 = dataRelatorio2;
|
||||
}
|
||||
if( ESTADO_REALIZADO.equals( estado2 ) || today.after( dataConsulta2 ) )
|
||||
{
|
||||
trabalhador.put( "ultimo_exame", dataConsulta2 );
|
||||
if( estado2.equals( ESTADO_POR_REALIZAR ) )
|
||||
{
|
||||
realizada2 = "não";
|
||||
}
|
||||
else if( estado2.equals( ESTADO_REALIZADO ) )
|
||||
{
|
||||
realizada2 = "sim";
|
||||
}
|
||||
trabalhador.put( "realizado", realizada2 );
|
||||
trabalhador.put( "proximo_exame", "" );
|
||||
}
|
||||
else
|
||||
{
|
||||
trabalhador.put( "proximo_exame", dataConsulta2 );
|
||||
if( !dataConsulta2.equals( dataConsulta1 ) )
|
||||
{
|
||||
if( estado1.equals( ESTADO_POR_REALIZAR ) )
|
||||
{
|
||||
realizada1 = "não";
|
||||
}
|
||||
else if( estado1.equals( ESTADO_REALIZADO ) )
|
||||
{
|
||||
realizada1 = "sim";
|
||||
}
|
||||
trabalhador.put( "realizado", realizada1 );
|
||||
trabalhador.put( "ultimo_exame", dataConsulta1 );
|
||||
}
|
||||
else
|
||||
{
|
||||
trabalhador.put( "ultimo_exame", "" );
|
||||
trabalhador.put( "realizado", null );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
trabalhador.put( "ultimo_exame", "" );
|
||||
trabalhador.put( "realizado", null );
|
||||
trabalhador.put( "proximo_exame", "" );
|
||||
}
|
||||
|
||||
desc.add( trabalhador );
|
||||
}
|
||||
|
||||
|
||||
sBuffer = new StringBuffer();
|
||||
sBuffer.append("<b>"+super.nomeEmpresa(con,empresaId)+"</b><br><br><i>"
|
||||
+super.nomeEstabelecimento(con, estabelecimentoId)+"</i>" );
|
||||
|
||||
HashMap hmValues = new HashMap();
|
||||
hmValues.put( "empresa_nome", session.getAttribute( sessionCompanyName ) );
|
||||
hmValues.put( "empresa_id", session.getAttribute( sessionEmpresaId ) );
|
||||
hmValues.put( "estabelecimento_nome", super.nomeEstabelecimento( con, estabelecimentoId ) );
|
||||
hmValues.put( "estabelecimento_id", estabelecimentoId );
|
||||
hmValues.put( "userRole", userRole );
|
||||
hmValues.put( "userName", session.getAttribute( sessionUser ) );
|
||||
hmValues.put( msgTemplate , sBuffer.toString() ) ;
|
||||
hmValues.put( templateUserRole, userRole);
|
||||
hmValues.put( templateQuery, super.queryStringTrabalhadores );
|
||||
hmValues.put( templateVector1,links);
|
||||
hmValues.put( templateVector2,desc);
|
||||
hmValues.put( templateVector3,null);
|
||||
if( !print )
|
||||
{
|
||||
out.println( mergeTemplate( hmValues, super.authenticatedUserTemplate));
|
||||
}
|
||||
else
|
||||
{
|
||||
out.println( mergeTemplate( hmValues, super.authenticatedUserPrintTemplate));
|
||||
}
|
||||
// out.println( mergeTemplate( sBuffer.toString(), userRole, super.queryStringTrabalhadores, links, desc, null, super.authenticatedUserTemplate) );
|
||||
}
|
||||
else // est não pertence à empresa
|
||||
{
|
||||
out.println( mergeTemplate( super.msgLinkFormatError , userRole, super.errorTemplate) );
|
||||
}
|
||||
con.close();
|
||||
}
|
||||
else // Role não permite ver esta informação
|
||||
{
|
||||
out.println( mergeTemplate( super.msgAcessoNegado , userRole, super.errorTemplate) );
|
||||
}
|
||||
}
|
||||
catch ( SQLException e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
out.println( mergeTemplate( super.msgErroBd , super.errorTemplate) );
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
out.println( mergeTemplate( super.msgGenericError , super.errorTemplate) );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,879 +0,0 @@
|
||||
/*
|
||||
* doGetListaTrabalhadoresPendentes.java
|
||||
*
|
||||
* Created on 22 de Abril de 2005, 15:56
|
||||
*/
|
||||
|
||||
package siprp.pagina;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Array;
|
||||
import javax.servlet.*;
|
||||
import javax.servlet.http.*;
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
|
||||
import org.apache.velocity.*;
|
||||
import org.apache.velocity.app.*;
|
||||
|
||||
import com.evolute.utils.arrays.*;
|
||||
import com.evolute.utils.data.*;
|
||||
import com.evolute.utils.db.*;
|
||||
import com.evolute.utils.sql.*;
|
||||
import com.evolute.utils.strings.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author fpalma
|
||||
*/
|
||||
public class doGetListaTrabalhadoresPendentes
|
||||
extends siprpServlet
|
||||
{
|
||||
private static final long TRES_MESES = 3L * 30L * 24L * 60L * 60L * 1000L;
|
||||
private static final long CATORZE_DIAS = 14L * 24L * 60L * 60L * 1000L;
|
||||
|
||||
protected static final int ESTADO_NAO_APLICAVEL = 0;
|
||||
protected static final int ESTADO_PENDENTE = 1;
|
||||
protected static final int ESTADO_MARCADO = 2;
|
||||
protected static final int ESTADO_TRATADO = 3;
|
||||
|
||||
protected static int MOTIVO_ADMISSAO = 1;
|
||||
protected static int MOTIVO_PERIODICA = 2;
|
||||
protected static int MOTIVO_OCASIONAL = 3;
|
||||
protected static int MOTIVO_PERIODICA_INICIAL = 5;
|
||||
|
||||
protected static final Hashtable CORES_ESTADOS = new Hashtable();
|
||||
protected static final Hashtable TEXTOS_ESTADOS = new Hashtable();
|
||||
static
|
||||
{
|
||||
CORES_ESTADOS.put( new Integer( ESTADO_NAO_APLICAVEL ), "white" );
|
||||
CORES_ESTADOS.put( new Integer( ESTADO_PENDENTE ), "red" );
|
||||
CORES_ESTADOS.put( new Integer( ESTADO_MARCADO ), "yellow" );
|
||||
CORES_ESTADOS.put( new Integer( ESTADO_TRATADO ), "green" );
|
||||
|
||||
TEXTOS_ESTADOS.put( new Integer( ESTADO_NAO_APLICAVEL ), "n.a." );
|
||||
TEXTOS_ESTADOS.put( new Integer( ESTADO_PENDENTE ), "pendente" );
|
||||
TEXTOS_ESTADOS.put( new Integer( ESTADO_MARCADO ), "pendente" );
|
||||
// TEXTOS_ESTADOS.put( new Integer( ESTADO_TRATADO ), "green" );
|
||||
}
|
||||
|
||||
protected java.sql.Date today;
|
||||
protected long todayMillis;
|
||||
|
||||
/** Creates a new instance of doGetListaTrabalhadores */
|
||||
// public doGetListaTrabalhadoresPendentes(HttpServletRequest req, HttpServletResponse res, boolean print)
|
||||
// throws IOException
|
||||
// {
|
||||
// ServletOutputStream out = res.getOutputStream();
|
||||
// Connection con = null ;
|
||||
// Statement stmt = null ;
|
||||
// ResultSet2DArray rs;
|
||||
// StringBuffer dbQuery, sBuffer;
|
||||
// String userRole, empresaId, estabelecimentoId, temp;
|
||||
// HttpSession session = req.getSession(false);
|
||||
// Vector links = new Vector();
|
||||
// Vector desc = new Vector();
|
||||
// Vector descAdicional = new Vector();
|
||||
//// today = new java.util.Date();
|
||||
//// todayMillis = today.getTime();
|
||||
//
|
||||
// try
|
||||
// {
|
||||
// stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
|
||||
// rs = new ResultSet2DArray( stmt.executeQuery( "SELECT CURRENT_DATE" ) );
|
||||
// today = ( java.sql.Date ) rs.get( 0, 0 );
|
||||
// stmt.close();
|
||||
// todayMillis = today.getTime();
|
||||
//
|
||||
// userRole = (String)session.getAttribute(super.sessionUserRole);
|
||||
// empresaId = (String)session.getAttribute(super.sessionEmpresaId);
|
||||
// estabelecimentoId = (String)session.getAttribute(super.sessionEstabelecimentoId);
|
||||
//
|
||||
// if ( userRole.equals ( super.superUserRole ) || userRole.equals ( empresaId ) )
|
||||
// {
|
||||
// Class.forName(super.bdDriver);
|
||||
// con = DriverManager.getConnection( bdLocalUrl, bdLocalUsername, bdLocalPassword );
|
||||
// if ( super.verificaEstabelecimento(con, empresaId, estabelecimentoId) ) // estabelecimento pertence à empresa ??
|
||||
// {
|
||||
// //Class.forName(super.bdDriver);
|
||||
// //con = DriverManager.getConnection( super.bdUrl, super.bdUsername, super.bdPassword );
|
||||
// dbQuery = new StringBuffer();
|
||||
// dbQuery.append( "SELECT trabalhadores.id, trabalhadores.nome, "
|
||||
// + "marcacoes_trabalhador.tipo, marcacoes_trabalhador.data, marcacoes_trabalhador.estado, "
|
||||
// + " trabalhadores.nome_plain, marcacoes_trabalhador.motivo "
|
||||
// + "FROM trabalhadores LEFT JOIN marcacoes_trabalhador ON ( marcacoes_trabalhador.trabalhador_id = trabalhadores.id )"
|
||||
// + "WHERE estabelecimento_id = " + estabelecimentoId
|
||||
// + " AND trabalhadores.inactivo <> 'y' AND data_demissao IS NULL "
|
||||
// + " AND marcacoes_trabalhador.estado NOT IN ( 3, 4, 5) "
|
||||
// + "ORDER BY 6, 3, 4 DESC " );
|
||||
// // dbQuery.append( "SELECT id, nome, ( ultima_consulta IS NOT NULL AND realizada = 'y' ),"
|
||||
// // + " ( ultimo_exame IS NOT NULL AND realizado = 'y' ),"
|
||||
// // + " proxima_consulta IS NOT NULL, proximo_exame IS NOT NULL, "
|
||||
// // + " ( proxima_consulta IS NOT NULL AND proxima_consulta - current_date <= 14 ), "
|
||||
// // + " ( proximo_exame IS NOT NULL AND proximo_exame - current_date <= 14 )"
|
||||
// // + " FROM trabalhadores "
|
||||
// // + " WHERE estabelecimento_id = '"+estabelecimentoId+"'"
|
||||
// // + " AND ( ultima_consulta IS NULL OR realizada = 'n' OR"
|
||||
// // + " ( proxima_consulta IS NOT NULL AND proxima_consulta - current_date <= 14 )"
|
||||
// // + " OR ( proximo_exame IS NOT NULL AND proximo_exame - current_date <= 14 ) )"
|
||||
// // + " ORDER BY nome" );
|
||||
// stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
|
||||
// rs = new ResultSet2DArray( stmt.executeQuery( dbQuery.toString()) );
|
||||
//
|
||||
// int index=0;
|
||||
// int max = rs.columnLength();
|
||||
//
|
||||
// Integer trabalhadorID = new Integer( -1 );
|
||||
// String nomeTrabalhador = "";
|
||||
// Vector consultas = new Vector();
|
||||
// Vector exames = new Vector();
|
||||
//
|
||||
// for ( index = 0; index <= max; index++ )
|
||||
// {
|
||||
// Integer id = index < max ? ( Integer ) rs.get( index, 0 ) : new Integer( -1 );
|
||||
// if( !id.equals( trabalhadorID ) )
|
||||
// {
|
||||
// Object listaConsultas[][] = ( Object[][] ) consultas.toArray( new Object[consultas.size()][3] );
|
||||
// Object listaExames[][] = ( Object[][] ) exames.toArray( new Object[exames.size()][3] );
|
||||
// if( trabalhadorID.intValue() > -1 &&
|
||||
// verificarTrabalhador( listaConsultas, listaExames ) )
|
||||
// {
|
||||
// temp=""+rs.get(index - 1,0); // converter de int para String
|
||||
// dbQuery = new StringBuffer();
|
||||
// dbQuery.append("/"+super.servletName+"/?"+empresaId+"/"+estabelecimentoId+"/"+temp); // contruir url
|
||||
// links.add(dbQuery.toString());
|
||||
// desc.add( criarDadosTrabalhador( con, trabalhadorID, nomeTrabalhador, listaConsultas, listaExames ) );
|
||||
// }
|
||||
// exames.clear();
|
||||
// consultas.clear();
|
||||
// }
|
||||
// if( index == max )
|
||||
// {
|
||||
// break;
|
||||
// }
|
||||
// Integer tipo = ( Integer ) rs.get( index, 2 );
|
||||
//
|
||||
// String nome = ( String ) rs.get( index, 1 );
|
||||
// java.util.Date data = ( java.util.Date ) rs.get( index, 3 );
|
||||
// Integer estado = ( Integer ) rs.get( index, 4 );
|
||||
// Integer motivo = ( Integer ) rs.get( index, 6 );
|
||||
// trabalhadorID = id;
|
||||
// nomeTrabalhador = nome;
|
||||
// Object marcacao[] = new Object[]{ data, estado, motivo };
|
||||
// if( tipo == null )
|
||||
// {
|
||||
// continue;
|
||||
// }
|
||||
// switch( tipo.intValue() )
|
||||
// {
|
||||
// case TIPO_MARCACAO_EXAMES:
|
||||
// exames.add( marcacao );
|
||||
// break;
|
||||
//
|
||||
// case TIPO_MARCACAO_CONSULTA:
|
||||
// consultas.add( marcacao );
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// stmt.close();
|
||||
//
|
||||
// sBuffer = new StringBuffer();
|
||||
// sBuffer.append("<b>"+super.nomeEmpresa(con,empresaId)+"</b><br><br><i>"
|
||||
// +super.nomeEstabelecimento(con, estabelecimentoId)+"</i>" );
|
||||
//
|
||||
// HashMap hmValues = new HashMap();
|
||||
// hmValues.put( "empresa_nome", session.getAttribute( sessionCompanyName ) );
|
||||
// hmValues.put( "empresa_id", session.getAttribute( sessionEmpresaId ) );
|
||||
// hmValues.put( "estabelecimento_nome", super.nomeEstabelecimento( con, estabelecimentoId ) );
|
||||
// hmValues.put( "estabelecimento_id", estabelecimentoId );
|
||||
// hmValues.put( "userRole", userRole );
|
||||
// hmValues.put( "userName", session.getAttribute( sessionUser ) );
|
||||
// hmValues.put( msgTemplate , sBuffer.toString() ) ;
|
||||
// hmValues.put( templateUserRole, userRole);
|
||||
// hmValues.put( templateQuery, "trabalhadores_pendentes" );
|
||||
// hmValues.put( templateVector1,links);
|
||||
// hmValues.put( templateVector2,desc);
|
||||
// hmValues.put( templateVector3,null);
|
||||
// if( !print )
|
||||
// {
|
||||
// out.println( mergeTemplate( hmValues, super.authenticatedUserTemplate));
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// out.println( mergeTemplate( hmValues, super.authenticatedUserPrintTemplate));
|
||||
// }
|
||||
//// out.println( mergeTemplate( sBuffer.toString(), userRole, super.queryStringTrabalhadores, links, desc, null, super.authenticatedUserTemplate) );
|
||||
// }
|
||||
// else // est não pertence à empresa
|
||||
// {
|
||||
// out.println( mergeTemplate( super.msgLinkFormatError , userRole, super.errorTemplate) );
|
||||
// }
|
||||
// con.close();
|
||||
// }
|
||||
// else // Role não permite ver esta informação
|
||||
// {
|
||||
// out.println( mergeTemplate( super.msgAcessoNegado , userRole, super.errorTemplate) );
|
||||
// }
|
||||
// }
|
||||
// catch ( SQLException e )
|
||||
// {
|
||||
// e.printStackTrace();
|
||||
// out.println( mergeTemplate( super.msgErroBd , super.errorTemplate) );
|
||||
// }
|
||||
// catch ( Exception e )
|
||||
// {
|
||||
// e.printStackTrace();
|
||||
// out.println( mergeTemplate( super.msgGenericError , super.errorTemplate) );
|
||||
// }
|
||||
// }
|
||||
|
||||
public doGetListaTrabalhadoresPendentes(HttpServletRequest req, HttpServletResponse res, boolean print )
|
||||
throws IOException
|
||||
{
|
||||
ServletOutputStream out = res.getOutputStream();
|
||||
String userRole, empresaId, estabelecimentoId;
|
||||
HttpSession session = req.getSession(false);
|
||||
Vector links = new Vector();
|
||||
Vector desc = new Vector();
|
||||
Vector descAdicional = new Vector();
|
||||
// today = new java.util.Date();
|
||||
// todayMillis = today.getTime();
|
||||
|
||||
try
|
||||
{
|
||||
Executer executer = getExecuter();
|
||||
Virtual2DArray array = executer.executeQuery( new Select( "SELECT CURRENT_DATE" ) );
|
||||
today = ( java.sql.Date ) array.get( 0, 0 );
|
||||
todayMillis = today.getTime();
|
||||
|
||||
userRole = (String)session.getAttribute(sessionUserRole);
|
||||
empresaId = (String)session.getAttribute(sessionEmpresaId);
|
||||
estabelecimentoId = (String)session.getAttribute(sessionEstabelecimentoId);
|
||||
|
||||
if ( userRole.equals ( superUserRole ) || userRole.equals ( empresaId ) )
|
||||
{
|
||||
if ( verificaEstabelecimento(null, empresaId, estabelecimentoId) ) // estabelecimento pertence à empresa ??
|
||||
{
|
||||
//Class.forName(super.bdDriver);
|
||||
//con = DriverManager.getConnection( super.bdUrl, super.bdUsername, super.bdPassword );
|
||||
String query = "( SELECT trabalhadores.id, trabalhadores.nome, "
|
||||
+ "marcacoes_trabalhador.tipo, marcacoes_trabalhador.data, marcacoes_trabalhador.estado, "
|
||||
+ " trabalhadores.nome_plain, marcacoes_trabalhador.motivo, marcacoes_trabalhador.data "
|
||||
+ "FROM trabalhadores LEFT JOIN marcacoes_trabalhador ON ( marcacoes_trabalhador.trabalhador_id = trabalhadores.id ) "
|
||||
+ "WHERE estabelecimento_id = " + estabelecimentoId
|
||||
+ " AND trabalhadores.inactivo <> 'y' AND data_demissao IS NULL "
|
||||
+ " AND marcacoes_trabalhador.estado NOT IN ( 3, 4, 5) "
|
||||
+ " AND marcacoes_trabalhador.tipo = " + TIPO_MARCACAO_CONSULTA
|
||||
+ " AND marcacoes_trabalhador.motivo <> " + MOTIVO_OCASIONAL + " )"
|
||||
+ " UNION "
|
||||
+ "( SELECT trabalhadores.id, trabalhadores.nome, "
|
||||
+ "marcacoes_trabalhador.tipo, marcacoes_trabalhador.data, marcacoes_trabalhador.estado, "
|
||||
+ " trabalhadores.nome_plain, marcacoes_trabalhador.motivo, marcacoes_trabalhador.data + 90 "
|
||||
+ "FROM trabalhadores LEFT JOIN marcacoes_trabalhador ON ( marcacoes_trabalhador.trabalhador_id = trabalhadores.id ) "
|
||||
+ "WHERE estabelecimento_id = " + estabelecimentoId
|
||||
+ " AND trabalhadores.inactivo <> 'y' AND data_demissao IS NULL "
|
||||
+ " AND marcacoes_trabalhador.estado NOT IN ( 3, 4, 5) "
|
||||
+ " AND marcacoes_trabalhador.tipo = " + TIPO_MARCACAO_EXAMES + " )"
|
||||
+ "ORDER BY 6, 8, 3 DESC ";
|
||||
array = executer.executeQuery( new Select( query ) );
|
||||
|
||||
query = "SELECT trabalhadores.id, trabalhadores.nome, "
|
||||
+ "marcacoes_trabalhador.tipo, marcacoes_trabalhador.data, marcacoes_trabalhador.estado, "
|
||||
+ " trabalhadores.nome_plain, marcacoes_trabalhador.motivo, marcacoes_trabalhador.data "
|
||||
+ "FROM trabalhadores LEFT JOIN marcacoes_trabalhador ON ( marcacoes_trabalhador.trabalhador_id = trabalhadores.id ) "
|
||||
+ "WHERE estabelecimento_id = " + estabelecimentoId
|
||||
+ " AND trabalhadores.inactivo <> 'y' AND data_demissao IS NULL "
|
||||
+ " AND marcacoes_trabalhador.estado NOT IN ( 3, 4, 5) "
|
||||
+ " AND marcacoes_trabalhador.tipo = " + TIPO_MARCACAO_CONSULTA
|
||||
+ " AND marcacoes_trabalhador.motivo = " + MOTIVO_OCASIONAL
|
||||
+ " ORDER BY 6, 8, 3 DESC";
|
||||
Virtual2DArray ocasionaisArray = executer.executeQuery( new Select( query ) );
|
||||
|
||||
query = "SELECT trabalhadores.id, trabalhadores.nome "
|
||||
+ "FROM trabalhadores "
|
||||
+ "WHERE estabelecimento_id = " + estabelecimentoId
|
||||
+ " AND trabalhadores.inactivo <> 'y' AND data_demissao IS NULL;";
|
||||
Virtual2DArray trabalhadoresArray = executer.executeQuery( new Select( query ) );
|
||||
|
||||
Hashtable marcacoesPorID = new Hashtable();
|
||||
Hashtable ocasionaisPorID = new Hashtable();
|
||||
Hashtable nomesPorID = new Hashtable();
|
||||
for( int n = 0; n < trabalhadoresArray.columnLength(); n++ )
|
||||
{
|
||||
nomesPorID.put( trabalhadoresArray.get( n, 0 ), trabalhadoresArray.get( n, 1 ) );
|
||||
}
|
||||
|
||||
preencherMarcacoes( array, nomesPorID, marcacoesPorID );
|
||||
preencherMarcacoes( ocasionaisArray, nomesPorID, ocasionaisPorID );
|
||||
|
||||
Integer ids[] = ( Integer[] ) nomesPorID.keySet().toArray( new Integer[0] );
|
||||
IDObject trabalhadores[] = new IDObject[ ids.length ];
|
||||
for( int n = 0; n < ids.length; n++ )
|
||||
{
|
||||
trabalhadores[ n ] = new MappableObject( ids[ n ], nomesPorID.get( ids[ n ] ) );
|
||||
}
|
||||
Arrays.sort( trabalhadores, new Comparator(){
|
||||
public int compare( Object o1, Object o2 )
|
||||
{
|
||||
String nome1 = StringPlainer.convertString( o1.toString() );
|
||||
String nome2 = StringPlainer.convertString( o2.toString() );
|
||||
return nome1.compareTo( nome2 );
|
||||
}
|
||||
} );
|
||||
|
||||
for( int n = 0; n < trabalhadores.length; n++ )
|
||||
{
|
||||
Object marcacoes[][];
|
||||
if( marcacoesPorID.containsKey( trabalhadores[ n ].getID() ) )
|
||||
{
|
||||
marcacoes = ( Object[][] ) ( ( Vector )marcacoesPorID.get( trabalhadores[ n ].getID() ) ).toArray( new Object[ 0 ][] );
|
||||
}
|
||||
else
|
||||
{
|
||||
marcacoes = new Object[0][];
|
||||
}
|
||||
Object ocasionais[][];
|
||||
if( ocasionaisPorID.containsKey( trabalhadores[ n ].getID() ) )
|
||||
{
|
||||
ocasionais = ( Object[][] ) ( ( Vector )ocasionaisPorID.get( trabalhadores[ n ].getID() ) ).toArray( new Object[ 0 ][] );
|
||||
}
|
||||
else
|
||||
{
|
||||
ocasionais = new Object[ 0 ][];
|
||||
}
|
||||
Object agrupadas[][] = agruparMarcacoes( marcacoes, ocasionais );
|
||||
acrescentarTrabalhador( empresaId, estabelecimentoId,
|
||||
trabalhadores[ n ], null,
|
||||
agrupadas, links, desc,
|
||||
perfilTemConsultas( trabalhadores[ n ].getID(), new Integer( empresaId ) ),
|
||||
perfilTemExames( trabalhadores[ n ].getID(), new Integer( empresaId ) ) );
|
||||
}
|
||||
|
||||
HashMap hmValues = new HashMap();
|
||||
hmValues.put( "empresa_nome", session.getAttribute( sessionCompanyName ) );
|
||||
hmValues.put( "empresa_id", session.getAttribute( sessionEmpresaId ) );
|
||||
hmValues.put( "estabelecimento_nome", nomeEstabelecimento( null, estabelecimentoId ) );
|
||||
hmValues.put( "estabelecimento_id", estabelecimentoId );
|
||||
hmValues.put( "userRole", userRole );
|
||||
hmValues.put( "userName", session.getAttribute( sessionUser ) );
|
||||
hmValues.put( msgTemplate , "<b>"+nomeEmpresa(null,empresaId)+"</b><br><br><i>"
|
||||
+nomeEstabelecimento(null, estabelecimentoId)+"</i>" ) ;
|
||||
hmValues.put( templateUserRole, userRole);
|
||||
hmValues.put( templateQuery, "trabalhadores_pendentes" );
|
||||
hmValues.put( templateVector1,links);
|
||||
hmValues.put( templateVector2,desc);
|
||||
hmValues.put( templateVector3,null);
|
||||
if( !print )
|
||||
{
|
||||
out.println( mergeTemplate( hmValues, super.authenticatedUserTemplate));
|
||||
}
|
||||
else
|
||||
{
|
||||
out.println( mergeTemplate( hmValues, super.authenticatedUserPrintTemplate));
|
||||
}
|
||||
// out.println( mergeTemplate( sBuffer.toString(), userRole, super.queryStringTrabalhadores, links, desc, null, super.authenticatedUserTemplate) );
|
||||
}
|
||||
else // est não pertence à empresa
|
||||
{
|
||||
out.println( mergeTemplate( super.msgLinkFormatError , userRole, super.errorTemplate) );
|
||||
}
|
||||
}
|
||||
else // Role não permite ver esta informação
|
||||
{
|
||||
out.println( mergeTemplate( super.msgAcessoNegado , userRole, super.errorTemplate) );
|
||||
}
|
||||
}
|
||||
catch ( SQLException e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
out.println( mergeTemplate( super.msgErroBd , super.errorTemplate) );
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
out.println( mergeTemplate( super.msgGenericError , super.errorTemplate) );
|
||||
}
|
||||
}
|
||||
|
||||
protected void preencherMarcacoes( Virtual2DArray array, Hashtable nomesPorID, Hashtable marcacoesPorID )
|
||||
{
|
||||
int max = array.columnLength();
|
||||
for( int index = 0; index < max; index++ )
|
||||
{
|
||||
Integer id = index < max ? ( Integer ) array.get( index, 0 ) : new Integer( -1 );
|
||||
Integer tipo = ( Integer ) array.get( index, 2 );
|
||||
String nome = ( String ) array.get( index, 1 );
|
||||
java.util.Date data = ( java.util.Date ) array.get( index, 3 );
|
||||
Integer estado = ( Integer ) array.get( index, 4 );
|
||||
Integer motivo = ( Integer ) array.get( index, 6 );
|
||||
if( !marcacoesPorID.containsKey( id ) )
|
||||
{
|
||||
nomesPorID.put( id, nome );
|
||||
marcacoesPorID.put( id, new Vector() );
|
||||
}
|
||||
if( data != null )
|
||||
{
|
||||
Object marcacao[] = new Object[]{ data, estado, motivo, tipo };
|
||||
( ( Vector ) marcacoesPorID.get( id ) ).add( marcacao );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected Object[][] agruparMarcacoes( Object marcacoes[][], Object ocasionais[][] )
|
||||
{
|
||||
long tresMeses = TRES_MESES;
|
||||
java.util.Date dataExame = null;
|
||||
Integer estadoExame = null;
|
||||
java.util.Date dataConsulta = null;
|
||||
Integer motivoConsulta = null;
|
||||
Integer estadoConsulta = null;
|
||||
Object grupo[] = null;
|
||||
Vector grupos = new Vector();
|
||||
|
||||
if( marcacoes != null )
|
||||
{
|
||||
for( int n = 0; n < marcacoes.length; n++ )
|
||||
{
|
||||
if( grupo == null )
|
||||
{
|
||||
grupo = new Object[ 5 ];
|
||||
dataExame = null;
|
||||
estadoExame = null;
|
||||
dataConsulta = null;
|
||||
motivoConsulta = null;
|
||||
estadoConsulta = null;
|
||||
grupos.add( grupo );
|
||||
}
|
||||
|
||||
java.util.Date data = ( java.util.Date ) marcacoes[ n ][ 0 ];
|
||||
Integer estado = ( Integer ) marcacoes[ n ][ 1 ];
|
||||
Integer motivo = ( Integer ) marcacoes[ n ][ 2 ];
|
||||
Integer tipo = ( Integer ) marcacoes[ n ][ 3 ];
|
||||
switch( tipo.intValue() )
|
||||
{
|
||||
case TIPO_MARCACAO_EXAMES:
|
||||
if( dataConsulta == null &&
|
||||
( dataExame == null || estadoExame.intValue() < 2 ) )
|
||||
{
|
||||
dataExame = data;
|
||||
estadoExame = estado;
|
||||
}
|
||||
else if( dataConsulta != null && Math.abs( dataConsulta.getTime() - data.getTime() ) < tresMeses )
|
||||
{
|
||||
dataExame = data;
|
||||
estadoExame = estado;
|
||||
}
|
||||
else
|
||||
{
|
||||
grupo = null;
|
||||
n--;
|
||||
}
|
||||
if( grupo != null )
|
||||
{
|
||||
grupo[ 3 ] = dataExame;
|
||||
grupo[ 4 ] = estadoExame;
|
||||
}
|
||||
break;
|
||||
|
||||
case TIPO_MARCACAO_CONSULTA:
|
||||
if( dataExame == null || Math.abs( dataExame.getTime() - data.getTime() ) < tresMeses )
|
||||
{
|
||||
dataConsulta = data;
|
||||
estadoConsulta = estado;
|
||||
motivoConsulta = motivo;
|
||||
}
|
||||
else
|
||||
{
|
||||
grupo = null;
|
||||
n--;
|
||||
}
|
||||
if( grupo != null )
|
||||
{
|
||||
grupo[ 0 ] = dataConsulta;
|
||||
grupo[ 1 ] = estadoConsulta;
|
||||
grupo[ 2 ] = motivoConsulta;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if( ocasionais != null )
|
||||
{
|
||||
for( int n = 0; n < ocasionais.length; n++ )
|
||||
{
|
||||
grupo = new Object[ 5 ];
|
||||
for( int i = 0; i < 3; i++ )
|
||||
{
|
||||
grupo[ i ] = ocasionais[ n ][ i ];
|
||||
}
|
||||
grupos.add( grupo );
|
||||
}
|
||||
}
|
||||
|
||||
Object agrupadas[][] = ( Object[][] ) grupos.toArray( new Object[ grupos.size() ][] );
|
||||
Arrays.sort( agrupadas, new Comparator(){
|
||||
public int compare( Object o1, Object o2 )
|
||||
{
|
||||
Object g1[] = ( Object[] ) o1;
|
||||
Object g2[] = ( Object[] ) o2;
|
||||
java.util.Date d1 = ( java.util.Date ) ( g1[ 0 ] != null ? g1[ 0 ] : g1[ 3 ] );
|
||||
java.util.Date d2 = ( java.util.Date ) ( g2[ 0 ] != null ? g2[ 0 ] : g2[ 3 ] );
|
||||
return d2.compareTo( d1 );
|
||||
}
|
||||
} );
|
||||
return agrupadas;
|
||||
}
|
||||
|
||||
protected void acrescentarTrabalhador( String empresaID, String estabelecimentoID,
|
||||
IDObject trabalhador, java.util.Date dataFicha,
|
||||
Object marcacoes[][], Vector links, Vector dados,
|
||||
boolean perfilConsultas, boolean perfilExames )
|
||||
{
|
||||
int estado[] = new int[ 2 ];
|
||||
int index = 0;
|
||||
boolean pendente = false;
|
||||
if( marcacoes.length == 0 )
|
||||
{
|
||||
estado[ 0 ] = perfilConsultas ? ESTADO_PENDENTE : ESTADO_NAO_APLICAVEL;
|
||||
estado[ 1 ] = perfilExames ? ESTADO_PENDENTE : ESTADO_NAO_APLICAVEL;
|
||||
}
|
||||
else
|
||||
{
|
||||
java.util.Date dataConsulta;
|
||||
java.util.Date dataExame;
|
||||
index = -1;
|
||||
for( ; index + 1 < marcacoes.length; index++ )
|
||||
{
|
||||
int n = index + 1;
|
||||
dataConsulta = ( java.util.Date ) marcacoes[ n ][ 0 ];
|
||||
dataExame = ( java.util.Date ) marcacoes[ n ][ 3 ];
|
||||
boolean temConsulta = dataConsulta != null;
|
||||
boolean consultaAntiga = temConsulta && dataConsulta.before( today );
|
||||
boolean temExame = dataExame != null;
|
||||
boolean exameAntigo = temExame && dataExame.before( today );
|
||||
|
||||
if( ( temConsulta && consultaAntiga && temExame && exameAntigo ) ||
|
||||
( temConsulta && consultaAntiga && !temExame && !exameAntigo ) ||
|
||||
( !temConsulta && !consultaAntiga && temExame && exameAntigo ) )
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if( index == -1 )
|
||||
{
|
||||
index = 0;
|
||||
}
|
||||
// else if( index < marcacoes.length - 1 )
|
||||
// {
|
||||
// index = 0;
|
||||
// }
|
||||
for( ; index < marcacoes.length; index++ )
|
||||
{
|
||||
dataConsulta = ( java.util.Date ) marcacoes[ index ][ 0 ];
|
||||
dataExame = ( java.util.Date ) marcacoes[ index ][ 3 ];
|
||||
boolean temConsulta = dataConsulta != null;
|
||||
long diffConsulta = temConsulta ? dataConsulta.getTime() - today.getTime() : 0;
|
||||
boolean temExame = dataExame != null;
|
||||
long diffExame = temExame ? dataExame.getTime() - today.getTime() : 0;
|
||||
if( ( temConsulta && diffConsulta < CATORZE_DIAS ) || ( temExame && diffExame < CATORZE_DIAS ) )
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if( index >= marcacoes.length )
|
||||
{
|
||||
index = marcacoes.length - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( marcacoes.length > 1 )
|
||||
{
|
||||
dataConsulta = ( java.util.Date ) marcacoes[ index ][ 0 ];
|
||||
dataExame = ( java.util.Date ) marcacoes[ index ][ 3 ];
|
||||
Calendar calToday = Calendar.getInstance();
|
||||
calToday.setTime( today );
|
||||
calToday.add( Calendar.YEAR, -2 );
|
||||
if( ( dataConsulta != null && dataConsulta.before( calToday.getTime() ) )
|
||||
|| ( dataConsulta == null && dataExame != null && dataExame.before( calToday.getTime() ) ) )
|
||||
{
|
||||
if( index > 0 )
|
||||
{
|
||||
index--;
|
||||
}
|
||||
else
|
||||
{
|
||||
pendente = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
dataConsulta = ( java.util.Date ) marcacoes[ index ][ 0 ];
|
||||
Integer estadoConsulta = ( Integer ) marcacoes[ index ][ 1 ];
|
||||
Integer motivoConsulta = ( Integer ) marcacoes[ index ][ 2 ];
|
||||
dataExame = ( java.util.Date ) marcacoes[ index ][ 3 ];
|
||||
Integer estadoExame = ( Integer ) marcacoes[ index ][ 4 ];
|
||||
if( perfilConsultas )
|
||||
{
|
||||
if( dataConsulta == null || pendente )
|
||||
{
|
||||
estado[ 0 ] = ESTADO_PENDENTE;
|
||||
}
|
||||
else if( estadoConsulta == null || estadoConsulta.intValue() != 2 )
|
||||
{
|
||||
estado[ 0 ] = ESTADO_MARCADO;
|
||||
}
|
||||
else
|
||||
{
|
||||
estado[ 0 ] = ESTADO_TRATADO;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
estado[ 0 ] = ESTADO_NAO_APLICAVEL;
|
||||
}
|
||||
if( perfilExames )
|
||||
{
|
||||
if( dataExame == null || pendente )
|
||||
{
|
||||
if( motivoConsulta != null && motivoConsulta.intValue() != MOTIVO_OCASIONAL )
|
||||
{
|
||||
estado[ 1 ] = ESTADO_PENDENTE;
|
||||
}
|
||||
else
|
||||
{
|
||||
estado[ 1 ] = ESTADO_NAO_APLICAVEL;
|
||||
}
|
||||
}
|
||||
else if( estadoExame == null || estadoExame.intValue() != 2 )
|
||||
{
|
||||
estado[ 1 ] = ESTADO_MARCADO;
|
||||
}
|
||||
else
|
||||
{
|
||||
estado[ 1 ] = ESTADO_TRATADO;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
estado[ 1 ] = ESTADO_NAO_APLICAVEL;
|
||||
}
|
||||
}
|
||||
if( estado[ 0 ] == 1 || estado[ 0 ] == 2 ||
|
||||
estado[ 1 ] == 1 || estado[ 1 ] == 2 )
|
||||
{
|
||||
links.add( "/"+servletName+"/?"+empresaID+"/"+estabelecimentoID+"/"+trabalhador.getID() );
|
||||
HashMap dadosTrabalhador = new HashMap();
|
||||
dadosTrabalhador.put( "Nome", trabalhador.toString() );
|
||||
dadosTrabalhador.put( "Consulta", CORES_ESTADOS.get( new Integer( estado[ 0 ] ) ) );
|
||||
Object text = TEXTOS_ESTADOS.get( new Integer( estado[ 0 ] ) );
|
||||
dadosTrabalhador.put( "Consulta_estado", text != null ? text : marcacoes[ index ][ 0 ] );
|
||||
dadosTrabalhador.put( "Exame", CORES_ESTADOS.get( new Integer( estado[ 1 ] ) ) );
|
||||
text = TEXTOS_ESTADOS.get( new Integer( estado[ 1 ] ) );
|
||||
dadosTrabalhador.put( "Exame_estado", text != null ? text : marcacoes[ index ][ 3 ] );
|
||||
dados.add( dadosTrabalhador );
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean perfilTemConsultas( Integer trabalhadorID, Integer empresaID )
|
||||
throws Exception
|
||||
{
|
||||
Executer executer = getExecuter();
|
||||
String query = "SELECT a_consultas, b_consultas FROM empresas WHERE id = " + empresaID;
|
||||
Virtual2DArray array = executer.executeQuery( new Select( query ) );
|
||||
boolean consultas[] = new boolean[]{ "y".equals( array.get( 0, 0 ) ), "n".equals( array.get( 0, 0 ) ) };
|
||||
query = "SELECT perfil FROM trabalhadores WHERE id = " + trabalhadorID;
|
||||
array = executer.executeQuery( new Select( query ) );
|
||||
Integer perfil = ( Integer )array.get( 0, 0 );
|
||||
if( perfil != null )
|
||||
{
|
||||
return consultas[ perfil.intValue() - 1 ];
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean perfilTemExames( Integer trabalhadorID, Integer empresaID )
|
||||
throws Exception
|
||||
{
|
||||
Executer executer = getExecuter();
|
||||
String query = "SELECT a_exames, b_exames FROM empresas WHERE id = " + empresaID;
|
||||
Virtual2DArray array = executer.executeQuery( new Select( query ) );
|
||||
boolean consultas[] = new boolean[]{ "y".equals( array.get( 0, 0 ) ), "n".equals( array.get( 0, 0 ) ) };
|
||||
query = "SELECT perfil FROM trabalhadores WHERE id = " + trabalhadorID;
|
||||
array = executer.executeQuery( new Select( query ) );
|
||||
Integer perfil = ( Integer )array.get( 0, 0 );
|
||||
if( perfil != null )
|
||||
{
|
||||
return consultas[ perfil.intValue() - 1 ];
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// protected boolean verificarTrabalhador( Object consultas[][], Object exames[][] )
|
||||
// {
|
||||
// boolean estadoConsultas = false;
|
||||
// boolean estadoExames = ( exames.length == 0 ) || ( ( java.util.Date )exames[ 0 ][ 0 ] ).before(today) ||
|
||||
// ( ( ( ( java.util.Date )exames[ 0 ][ 0 ] ).getTime() - todayMillis ) / 86400000 > 14 );
|
||||
// if( consultas.length > 0 )
|
||||
// {
|
||||
// int anterior;
|
||||
// int proxima;
|
||||
// if( ( (java.util.Date) consultas[ 0 ][ 0 ] ).after( today ) )
|
||||
// {
|
||||
// proxima = 0;
|
||||
// if( consultas.length >= 2 )
|
||||
// {
|
||||
// anterior = 1;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// anterior = -1;
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// proxima = -1;
|
||||
// anterior = 0;
|
||||
// }
|
||||
// estadoConsultas = anterior >= 0 && "y".equals( consultas[ anterior ][ 1 ] ) &&
|
||||
// ( proxima == -1 || ( ( ( java.util.Date )consultas[ proxima ][ 0 ] ).getTime() - todayMillis ) / 86400000 > 14 );
|
||||
// }
|
||||
// return !(estadoConsultas && estadoExames);
|
||||
// }
|
||||
|
||||
// protected HashMap criarDadosTrabalhador( Integer id, String nome,
|
||||
// Object consultas[][], Object exames[][] )
|
||||
// throws Exception
|
||||
// {
|
||||
//// dbQuery.append( "SELECT id, nome, ( ultima_consulta IS NOT NULL AND realizada = 'y' ),"
|
||||
//// + " ( ultimo_exame IS NOT NULL AND realizado = 'y' ),"
|
||||
//// + " proxima_consulta IS NOT NULL, proximo_exame IS NOT NULL, "
|
||||
//// + " ( proxima_consulta IS NOT NULL AND proxima_consulta - current_date <= 14 ), "
|
||||
//// + " ( proximo_exame IS NOT NULL AND proximo_exame - current_date <= 14 )"
|
||||
//// + " FROM trabalhadores "
|
||||
//// + " WHERE estabelecimento_id = '"+estabelecimentoId+"'"
|
||||
//// + " AND ( ultima_consulta IS NULL OR realizada = 'n' OR"
|
||||
//// + " ( proxima_consulta IS NOT NULL AND proxima_consulta - current_date <= 14 )"
|
||||
//// + " OR ( proximo_exame IS NOT NULL AND proximo_exame - current_date <= 14 ) )"
|
||||
//// + " ORDER BY nome" );
|
||||
// HashMap trabalhador = new HashMap();
|
||||
// trabalhador.put( "Nome", nome );
|
||||
// boolean uc = false;
|
||||
// boolean ue = false;
|
||||
// boolean pc = false;
|
||||
// boolean pe = false;
|
||||
// boolean quase_c = false;
|
||||
// boolean quase_e = false;
|
||||
// java.util.Date consultaAnterior = null;
|
||||
// java.util.Date exameAnterior = null;
|
||||
// if( consultas.length > 0 )
|
||||
// {
|
||||
// int anterior;
|
||||
// int proxima;
|
||||
// if( ( (java.util.Date) consultas[ 0 ][ 0 ] ).after( today ) )
|
||||
// {
|
||||
// proxima = 0;
|
||||
// if( consultas.length >= 2 )
|
||||
// {
|
||||
// anterior = 1;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// anterior = -1;
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// proxima = -1;
|
||||
// anterior = 0;
|
||||
// }
|
||||
// long diff = proxima > -1 ? ( ( ( java.util.Date )consultas[ proxima ][ 0 ] ).getTime() - todayMillis ) / 86400000 : 15;
|
||||
// uc = anterior > -1 && "y".equals( consultas[ anterior ][ 1 ] );
|
||||
// if( uc )
|
||||
// {
|
||||
// consultaAnterior = ( java.util.Date ) consultas[ anterior ][ 0 ];
|
||||
// }
|
||||
// pc = proxima > -1;
|
||||
// quase_c = pc && diff <= 14;
|
||||
// }
|
||||
//
|
||||
// if( exames.length > 0 )
|
||||
// {
|
||||
// int anterior;
|
||||
// int proximo;
|
||||
// if( ( (java.util.Date) exames[ 0 ][ 0 ] ).after( today ) )
|
||||
// {
|
||||
// proximo = 0;
|
||||
// if( exames.length >= 2 )
|
||||
// {
|
||||
// anterior = 1;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// anterior = -1;
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// proximo = -1;
|
||||
// anterior = 0;
|
||||
// }
|
||||
// long diff = proximo > -1 ? ( ( ( java.util.Date )exames[ proximo ][ 0 ] ).getTime() - todayMillis ) / 86400000 : 15;
|
||||
// ue = anterior > -1 && "y".equals( exames[ anterior ][ 1 ] );
|
||||
// if( ue )
|
||||
// {
|
||||
// exameAnterior = ( java.util.Date ) exames[ anterior ][ 0 ];
|
||||
// }
|
||||
// pe = proximo > -1;
|
||||
// quase_e = pe && diff <= 14;
|
||||
// }
|
||||
//
|
||||
// if( quase_c )
|
||||
// {
|
||||
// trabalhador.put( "Consulta", "yellow" );
|
||||
// trabalhador.put( "Consulta_estado", "pendente" );
|
||||
// }
|
||||
// else if( uc )
|
||||
// {
|
||||
// trabalhador.put( "Consulta", "green" );
|
||||
// trabalhador.put( "Consulta_estado", consultaAnterior );
|
||||
// }
|
||||
// else if( pc )
|
||||
// {
|
||||
// trabalhador.put( "Consulta", "yellow" );
|
||||
// trabalhador.put( "Consulta_estado", "pendente" );
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// trabalhador.put( "Consulta", "red" );
|
||||
// trabalhador.put( "Consulta_estado", "pendente" );
|
||||
// }
|
||||
//
|
||||
// if( quase_e )
|
||||
// {
|
||||
// trabalhador.put( "Exame", "yellow" );
|
||||
// trabalhador.put( "Exame_estado", "pendente" );
|
||||
// }
|
||||
// else if( ue )
|
||||
// {
|
||||
// trabalhador.put( "Exame", "green" );
|
||||
// trabalhador.put( "Exame_estado", exameAnterior );
|
||||
// }
|
||||
// else if( pe )
|
||||
// {
|
||||
// trabalhador.put( "Exame", "yellow" );
|
||||
// trabalhador.put( "Exame_estado", "pendente" );
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// trabalhador.put( "Exame", "red" );
|
||||
// trabalhador.put( "Exame_estado", "pendente" );
|
||||
// }
|
||||
// return trabalhador;
|
||||
// }
|
||||
}
|
||||
@ -1,255 +0,0 @@
|
||||
/*
|
||||
* doGetListaTrabalhadoresTudo.java
|
||||
*
|
||||
* Created on 21 de Abril de 2005, 17:35
|
||||
*/
|
||||
|
||||
package siprp.pagina;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import java.sql.*;
|
||||
import java.lang.reflect.Array;
|
||||
import javax.servlet.*;
|
||||
import javax.servlet.http.*;
|
||||
|
||||
import org.apache.velocity.*;
|
||||
import org.apache.velocity.app.*;
|
||||
|
||||
|
||||
import com.evolute.utils.arrays.*;
|
||||
import com.evolute.utils.db.*;
|
||||
import com.evolute.utils.sql.*;
|
||||
import com.evolute.utils.strings.*;
|
||||
/**
|
||||
*
|
||||
* @author fpalma
|
||||
*/
|
||||
public class doGetListaTrabalhadoresTudo
|
||||
extends siprpServlet
|
||||
implements GlobalConstants
|
||||
{
|
||||
protected java.util.Date today;
|
||||
protected long todayMillis;
|
||||
|
||||
/** Creates a new instance of doGetListaTrabalhadores */
|
||||
public doGetListaTrabalhadoresTudo(HttpServletRequest req, HttpServletResponse res, boolean print) throws IOException
|
||||
{
|
||||
ServletOutputStream out = res.getOutputStream();
|
||||
Connection con = null ;
|
||||
Statement stmt = null ;
|
||||
ResultSet2DArray rs;
|
||||
StringBuffer dbQuery, sBuffer;
|
||||
String userRole, empresaId, estabelecimentoId, temp;
|
||||
HttpSession session = req.getSession(false);
|
||||
Vector links = new Vector();
|
||||
Vector desc = new Vector();
|
||||
Vector descAdicional = new Vector();
|
||||
today = new java.util.Date();
|
||||
todayMillis = today.getTime();
|
||||
|
||||
try
|
||||
{
|
||||
userRole = (String)session.getAttribute(super.sessionUserRole);
|
||||
empresaId = (String)session.getAttribute(super.sessionEmpresaId);
|
||||
estabelecimentoId = (String)session.getAttribute(super.sessionEstabelecimentoId);
|
||||
|
||||
if ( userRole.equals ( super.superUserRole ) || userRole.equals ( empresaId ) )
|
||||
{
|
||||
Class.forName(super.bdDriver);
|
||||
con = DriverManager.getConnection( bdLocalUrl, bdLocalUsername, bdLocalPassword );
|
||||
if ( super.verificaEstabelecimento(con, empresaId, estabelecimentoId) ) // estabelecimento pertence à empresa ??
|
||||
{
|
||||
//Class.forName(super.bdDriver);
|
||||
//con = DriverManager.getConnection( super.bdUrl, super.bdUsername, super.bdPassword );
|
||||
dbQuery = new StringBuffer();
|
||||
// dbQuery.append( "SELECT id, nome, data_ficha FROM trabalhadores "
|
||||
// + "WHERE estabelecimento_id = '"+estabelecimentoId+"'"
|
||||
// + " AND ultima_consulta IS NOT NULL AND realizada = 'y' AND"
|
||||
// + " ( proxima_consulta IS NULL OR proxima_consulta - current_date > 14 )"
|
||||
// + " AND ( proximo_exame IS NULL OR proximo_exame - current_date > 14 )"
|
||||
// + " ORDER BY nome" );
|
||||
dbQuery.append( "SELECT trabalhadores.id, trabalhadores.nome, "
|
||||
+ "marcacoes_trabalhador.tipo, marcacoes_trabalhador.data, marcacoes_trabalhador.estado, "
|
||||
+ " trabalhadores.nome_plain "
|
||||
+ "FROM trabalhadores, marcacoes_trabalhador "
|
||||
+ "WHERE estabelecimento_id = " + estabelecimentoId
|
||||
+ " AND marcacoes_trabalhador.trabalhador_id = trabalhadores.id "
|
||||
+ " AND trabalhadores.inactivo <> 'y' AND data_demissao IS NULL "
|
||||
+ "ORDER BY 6, 3, 4 DESC " );
|
||||
stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
|
||||
rs = new ResultSet2DArray( stmt.executeQuery( dbQuery.toString()) );
|
||||
|
||||
int index=0;
|
||||
int max = rs.columnLength();
|
||||
|
||||
Integer trabalhadorID = new Integer( -1 );
|
||||
String nomeTrabalhador = "";
|
||||
Vector consultas = new Vector();
|
||||
Vector exames = new Vector();
|
||||
|
||||
for ( index = 0; index <= max; index++ )
|
||||
{
|
||||
Integer id = index < max ? ( Integer ) rs.get( index, 0 ) : new Integer( -1 );
|
||||
if( !id.equals( trabalhadorID ) )
|
||||
{
|
||||
Object listaConsultas[][] = ( Object[][] ) consultas.toArray( new Object[consultas.size()][2] );
|
||||
Object listaExames[][] = ( Object[][] ) exames.toArray( new Object[exames.size()][2] );
|
||||
if( trabalhadorID.intValue() > -1 &&
|
||||
verificarTrabalhador( listaConsultas, listaExames ) )
|
||||
{
|
||||
temp=""+rs.get(index - 1,0); // converter de int para String
|
||||
java.util.Date dataUltimaConsulta = null;
|
||||
for( int c = 0; c < listaConsultas.length; c++ )
|
||||
{
|
||||
if( new Integer( 2 ).equals( listaConsultas[ c ][ 1 ] ) )
|
||||
{
|
||||
dataUltimaConsulta = ( java.util.Date ) listaConsultas[ c ][ 0 ];
|
||||
break;
|
||||
}
|
||||
}
|
||||
HashMap dadosTrabalhador = criarDadosTrabalhador( trabalhadorID, nomeTrabalhador, dataUltimaConsulta );
|
||||
if( dadosTrabalhador != null )
|
||||
{
|
||||
dbQuery = new StringBuffer();
|
||||
dbQuery.append("/"+super.servletName+"/?"+empresaId+"/"+estabelecimentoId+"/"+temp); // construir url
|
||||
links.add(dbQuery.toString());
|
||||
desc.add( dadosTrabalhador );
|
||||
}
|
||||
}
|
||||
exames.clear();
|
||||
consultas.clear();
|
||||
}
|
||||
if( index == max )
|
||||
{
|
||||
break;
|
||||
}
|
||||
Integer tipo = ( Integer ) rs.get( index, 2 );
|
||||
String nome = ( String ) rs.get( index, 1 );
|
||||
java.util.Date data = ( java.util.Date ) rs.get( index, 3 );
|
||||
Integer estado = ( Integer ) rs.get( index, 4 );
|
||||
trabalhadorID = id;
|
||||
nomeTrabalhador = nome;
|
||||
Object marcacao[] = new Object[]{ data, estado };
|
||||
switch( tipo.intValue() )
|
||||
{
|
||||
case TIPO_MARCACAO_EXAMES:
|
||||
exames.add( marcacao );
|
||||
break;
|
||||
|
||||
case TIPO_MARCACAO_CONSULTA:
|
||||
consultas.add( marcacao );
|
||||
break;
|
||||
}
|
||||
}
|
||||
stmt.close();
|
||||
|
||||
sBuffer = new StringBuffer();
|
||||
sBuffer.append("<b>"+super.nomeEmpresa(con,empresaId)+"</b><br><br><i>"
|
||||
+super.nomeEstabelecimento(con, estabelecimentoId)+"</i>" );
|
||||
|
||||
HashMap hmValues = new HashMap();
|
||||
hmValues.put( "empresa_nome", session.getAttribute( sessionCompanyName ) );
|
||||
hmValues.put( "empresa_id", session.getAttribute( sessionEmpresaId ) );
|
||||
hmValues.put( "estabelecimento_nome", super.nomeEstabelecimento( con, estabelecimentoId ) );
|
||||
hmValues.put( "estabelecimento_id", estabelecimentoId );
|
||||
hmValues.put( "userRole", userRole );
|
||||
hmValues.put( "userName", session.getAttribute( sessionUser ) );
|
||||
hmValues.put( msgTemplate , sBuffer.toString() ) ;
|
||||
hmValues.put( templateUserRole, userRole);
|
||||
hmValues.put( templateQuery, "trabalhadores_tudo" );
|
||||
hmValues.put( templateVector1,links);
|
||||
hmValues.put( templateVector2,desc);
|
||||
hmValues.put( templateVector3,null);
|
||||
if( !print )
|
||||
{
|
||||
out.println( mergeTemplate( hmValues, super.authenticatedUserTemplate));
|
||||
}
|
||||
else
|
||||
{
|
||||
out.println( mergeTemplate( hmValues, super.authenticatedUserPrintTemplate));
|
||||
}
|
||||
// out.println( mergeTemplate( sBuffer.toString(), userRole, super.queryStringTrabalhadores, links, desc, null, super.authenticatedUserTemplate) );
|
||||
}
|
||||
else // est não pertence à empresa
|
||||
{
|
||||
out.println( mergeTemplate( super.msgLinkFormatError , userRole, super.errorTemplate) );
|
||||
}
|
||||
con.close();
|
||||
}
|
||||
else // Role não permite ver esta informação
|
||||
{
|
||||
out.println( mergeTemplate( super.msgAcessoNegado , userRole, super.errorTemplate) );
|
||||
}
|
||||
}
|
||||
catch ( SQLException e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
out.println( mergeTemplate( super.msgErroBd , super.errorTemplate) );
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
out.println( mergeTemplate( super.msgGenericError , super.errorTemplate) );
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean verificarTrabalhador( Object consultas[][], Object exames[][] )
|
||||
{
|
||||
boolean estadoConsultas = false;
|
||||
boolean estadoExames = ( exames.length == 0 ) || ( ( java.util.Date )exames[ 0 ][ 0 ] ).before(today) ||
|
||||
( ( ( ( java.util.Date )exames[ 0 ][ 0 ] ).getTime() - todayMillis ) / 86400000 > 14 );
|
||||
if( consultas.length > 0 )
|
||||
{
|
||||
int anterior;
|
||||
int proxima;
|
||||
if( ( (java.util.Date) consultas[ 0 ][ 0 ] ).after( today ) )
|
||||
{
|
||||
proxima = 0;
|
||||
if( consultas.length >= 2 )
|
||||
{
|
||||
anterior = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
anterior = -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
proxima = -1;
|
||||
anterior = 0;
|
||||
}
|
||||
estadoConsultas = anterior >= 0 && new Integer( 2 ).equals( consultas[ anterior ][ 1 ] ) &&
|
||||
( proxima == -1 || ( ( ( java.util.Date )consultas[ proxima ][ 0 ] ).getTime() - todayMillis ) / 86400000 > 14 );
|
||||
}
|
||||
return estadoConsultas && estadoExames;
|
||||
}
|
||||
|
||||
protected HashMap criarDadosTrabalhador( Integer id, String nome, java.util.Date ultimaConsulta )
|
||||
throws Exception
|
||||
{
|
||||
Executer executer = getExecuter();
|
||||
HashMap trabalhador = new HashMap();
|
||||
trabalhador.put( "Nome", nome );
|
||||
Select select =
|
||||
new Select( new String[]{ "exames" }, new String[]{ "data" },
|
||||
new Field( "trabalhador_id" ).isEqual( id ).and(
|
||||
new Field( "data" ).isGreaterOrEqual( ultimaConsulta ) ),
|
||||
new String[]{ "data" }, null );
|
||||
|
||||
// Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
|
||||
// ResultSet2DArray rs = new ResultSet2DArray( stmt.executeQuery( select.toString() ) );
|
||||
Virtual2DArray rs = executer.executeQuery( select );
|
||||
Object data_ficha = rs.columnLength() > 0 ? rs.get( 0, 0 ) : null;
|
||||
// stmt.close();
|
||||
if( data_ficha == null )
|
||||
{
|
||||
return null;
|
||||
// data_ficha = "";
|
||||
}
|
||||
trabalhador.put( "Data", data_ficha );
|
||||
return trabalhador;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,324 +0,0 @@
|
||||
package siprp.pagina;
|
||||
|
||||
import com.evolute.utils.arrays.*;
|
||||
import com.evolute.utils.strings.*;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import java.sql.*;
|
||||
import java.lang.reflect.Array;
|
||||
import javax.servlet.*;
|
||||
import javax.servlet.http.*;
|
||||
import org.apache.velocity.*;
|
||||
import org.apache.velocity.app.*;
|
||||
|
||||
public class doGetTrabalhador extends siprpServlet
|
||||
{
|
||||
|
||||
/** Creates a new instance of doGetTrabalhador */
|
||||
public doGetTrabalhador(HttpServletRequest req, HttpServletResponse res) throws IOException
|
||||
{
|
||||
ServletOutputStream out = res.getOutputStream();
|
||||
Connection con = null ;
|
||||
Statement stmt = null ;
|
||||
ResultSet2DArray rs;
|
||||
StringBuffer dbQuery, sBuffer;
|
||||
String userRole, empresaId, estabelecimentoId, trabalhadorId, temp;
|
||||
HttpSession session = req.getSession(false);
|
||||
Vector names = new Vector();
|
||||
Vector values = new Vector();
|
||||
java.util.Date today = new java.util.Date();
|
||||
|
||||
try
|
||||
{
|
||||
userRole = (String)session.getAttribute(super.sessionUserRole);
|
||||
empresaId = (String)session.getAttribute(super.sessionEmpresaId);
|
||||
estabelecimentoId = (String)session.getAttribute(super.sessionEstabelecimentoId);
|
||||
trabalhadorId = (String)session.getAttribute(super.sessionTrabalhadorId);
|
||||
|
||||
Class.forName(super.bdDriver);
|
||||
con = DriverManager.getConnection( bdLocalUrl, bdLocalUsername, bdLocalPassword );
|
||||
|
||||
if ( ( userRole.equals ( super.superUserRole ) || userRole.equals ( empresaId ) )
|
||||
&& super.verificaEstabelecimento(con, empresaId, estabelecimentoId)
|
||||
&& super.verificaTrabalhador(con, estabelecimentoId, trabalhadorId) )
|
||||
{
|
||||
|
||||
dbQuery = new StringBuffer();
|
||||
dbQuery.append( " SELECT sexo, categoria, data_nascimento, nome, numero_mecanografico "
|
||||
+ "FROM trabalhadores where id='"+trabalhadorId+"'");
|
||||
stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
|
||||
rs = new ResultSet2DArray( stmt.executeQuery( dbQuery.toString()) );
|
||||
|
||||
// int index=0;
|
||||
// int max = super.trabalhadorDescFields.length;
|
||||
|
||||
HashMap hmFuncionario = new HashMap();
|
||||
if( rs.columnLength() > 0 )
|
||||
{
|
||||
String tmp;
|
||||
hmFuncionario.put( "sexo", rs.get( 0, "sexo" ) );
|
||||
hmFuncionario.put( "categoria", rs.get( 0, "categoria" ) );
|
||||
hmFuncionario.put( "data_nascimento", rs.get( 0, "data_nascimento" ) );
|
||||
hmFuncionario.put( "nome", rs.get( 0, "nome" ) );
|
||||
hmFuncionario.put( "numero", rs.get( 0, "numero_mecanografico" ) );
|
||||
stmt.close();
|
||||
|
||||
String query = "SELECT id, data, estado, data_relatorio FROM marcacoes_trabalhador "
|
||||
+ "WHERE tipo = 0 and trabalhador_id = " + trabalhadorId
|
||||
+ " ORDER BY data DESC";
|
||||
stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
|
||||
rs = new ResultSet2DArray( stmt.executeQuery( query ) );
|
||||
if( rs.columnLength() > 0 )
|
||||
{
|
||||
java.util.Date dataExame2 = ( java.util.Date ) rs.get( 0, 1 );
|
||||
Integer estado1;
|
||||
Integer estado2 = ( Integer ) rs.get( 0, 2 );
|
||||
java.util.Date dataExame1;
|
||||
String realizado1 = "";
|
||||
String realizado2 = "";
|
||||
if( rs.columnLength() > 1 )
|
||||
{
|
||||
dataExame1 = ( java.util.Date ) rs.get( 1, 1 );
|
||||
estado1 = ( Integer ) rs.get( 1, 2 );
|
||||
}
|
||||
else
|
||||
{
|
||||
dataExame1 = dataExame2;
|
||||
estado1 = estado2;
|
||||
}
|
||||
if( ESTADO_REALIZADO.equals( estado2 ) || ESTADO_PARCIALMENTE_REALIZADO.equals( estado2 )
|
||||
|| today.after( dataExame2 ) )
|
||||
{
|
||||
hmFuncionario.put( "ultimo_exame", dataExame2 );
|
||||
if( estado2.equals( ESTADO_REALIZADO ) || estado2.equals( ESTADO_PARCIALMENTE_REALIZADO ) )
|
||||
{
|
||||
realizado2 = "sim";
|
||||
}
|
||||
else
|
||||
{
|
||||
realizado2 = "não";
|
||||
}
|
||||
hmFuncionario.put( "realizado", realizado2 );
|
||||
hmFuncionario.put( "proximo_exame", null );
|
||||
}
|
||||
else
|
||||
{
|
||||
hmFuncionario.put( "proximo_exame", dataExame2 );
|
||||
if( !dataExame2.equals( dataExame1 ) )
|
||||
{
|
||||
hmFuncionario.put( "ultimo_exame", dataExame1 );
|
||||
if( estado1.equals( ESTADO_REALIZADO ) || estado1.equals( ESTADO_PARCIALMENTE_REALIZADO ) )
|
||||
{
|
||||
realizado1 = "sim";
|
||||
}
|
||||
else
|
||||
{
|
||||
realizado1 = "não";
|
||||
}
|
||||
hmFuncionario.put( "realizado", realizado1 );
|
||||
}
|
||||
else
|
||||
{
|
||||
hmFuncionario.put( "ultimo_exame", null );
|
||||
hmFuncionario.put( "realizado", null );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
hmFuncionario.put( "ultimo_exame", null );
|
||||
hmFuncionario.put( "realizado", null );
|
||||
hmFuncionario.put( "proximo_exame", null );
|
||||
}
|
||||
stmt.close();
|
||||
|
||||
query = "SELECT MAX(id) FROM exames WHERE trabalhador_id = " + trabalhadorId + " AND inactivo <> 'y'";
|
||||
stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
|
||||
rs = new ResultSet2DArray( stmt.executeQuery( query ) );
|
||||
Integer fichaId = null;
|
||||
if( rs.columnLength() > 0 )
|
||||
{
|
||||
fichaId = ( Integer ) rs.get( 0, 0 );
|
||||
}
|
||||
stmt.close();
|
||||
|
||||
if( fichaId != null )
|
||||
{
|
||||
query = "SELECT data, resultado FROM exames WHERE id = " + fichaId;
|
||||
stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
|
||||
rs = new ResultSet2DArray( stmt.executeQuery( query ) );
|
||||
Integer resultadoFicha = (Integer) rs.get( 0, 1 );
|
||||
stmt.close();
|
||||
if( resultadoFicha != null )
|
||||
{
|
||||
switch( resultadoFicha.intValue() )
|
||||
{
|
||||
case 1:
|
||||
hmFuncionario.put( "resultado", "Apto" );
|
||||
break;
|
||||
case 2:
|
||||
hmFuncionario.put( "resultado", "Apto Condicionalmente" );
|
||||
break;
|
||||
case 3:
|
||||
hmFuncionario.put( "resultado", "Inapto Temporariamente" );
|
||||
break;
|
||||
case 4:
|
||||
hmFuncionario.put( "resultado", "Inapto Definitivamente" );
|
||||
break;
|
||||
default:
|
||||
hmFuncionario.put( "resultado", null );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
hmFuncionario.put( "resultado", null );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
hmFuncionario.put( "resultado", null );
|
||||
}
|
||||
|
||||
query = "SELECT id, data, estado FROM marcacoes_trabalhador "
|
||||
+ "WHERE tipo = 1 and trabalhador_id = " + trabalhadorId
|
||||
+ " ORDER BY data DESC";
|
||||
stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
|
||||
rs = new ResultSet2DArray( stmt.executeQuery( query ) );
|
||||
if( rs.columnLength() > 0 )
|
||||
{
|
||||
java.util.Date dataConsulta2 = ( java.util.Date ) rs.get( 0, 1 );
|
||||
Integer estado1;
|
||||
Integer estado2 = ( Integer ) rs.get( 0, 2 );
|
||||
java.util.Date dataConsulta1;
|
||||
// java.util.Date dataRelatorio1;
|
||||
// java.util.Date dataRelatorio2 = (java.util.Date) rs.get( 0, 3 );
|
||||
String realizada1 = "";
|
||||
String realizada2 = "";
|
||||
if( rs.columnLength() >= 2 )
|
||||
{
|
||||
dataConsulta1 = ( java.util.Date ) rs.get( 1, 1 );
|
||||
estado1 = ( Integer ) rs.get( 1, 2 );
|
||||
// dataRelatorio1 = (java.util.Date) rs.get( 1, 3 );
|
||||
}
|
||||
else
|
||||
{
|
||||
dataConsulta1 = dataConsulta2;
|
||||
estado1 = estado2;
|
||||
// dataRelatorio1 = dataRelatorio2;
|
||||
}
|
||||
if( ESTADO_REALIZADO.equals( estado2 ) || today.after( dataConsulta2 ) )
|
||||
{
|
||||
hmFuncionario.put( "ultima_consulta", dataConsulta2 );
|
||||
if( estado2.equals( ESTADO_REALIZADO ) )
|
||||
{
|
||||
realizada2 = "sim";
|
||||
}
|
||||
else
|
||||
{
|
||||
realizada2 = "não";
|
||||
}
|
||||
hmFuncionario.put( "realizada", realizada2 );
|
||||
hmFuncionario.put( "proxima_consulta", null );
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
for( int c = 1; c < rs.columnLength(); c++ )
|
||||
{
|
||||
java.util.Date dataTemp = ( java.util.Date ) rs.get( c, 1 );
|
||||
dataConsulta1 = dataTemp;
|
||||
estado1 = ( Integer ) rs.get( c, 2 );
|
||||
if( dataTemp.after( today ) )
|
||||
{
|
||||
dataConsulta2 = dataTemp;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch( Exception ex )
|
||||
{
|
||||
ex.printStackTrace();
|
||||
}
|
||||
hmFuncionario.put( "proxima_consulta", dataConsulta2 );
|
||||
if( !dataConsulta2.equals( dataConsulta1 ) )
|
||||
{
|
||||
if( estado1.equals( ESTADO_REALIZADO ) )
|
||||
{
|
||||
realizada1 = "sim";
|
||||
}
|
||||
else
|
||||
{
|
||||
realizada1 = "não";
|
||||
}
|
||||
hmFuncionario.put( "realizada", realizada1 );
|
||||
hmFuncionario.put( "ultima_consulta", dataConsulta1 );
|
||||
}
|
||||
else
|
||||
{
|
||||
hmFuncionario.put( "ultima_consulta", null );
|
||||
hmFuncionario.put( "realizada", null );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
hmFuncionario.put( "ultima_consulta", null );
|
||||
hmFuncionario.put( "realizada", null );
|
||||
hmFuncionario.put( "proxima_consulta", null );
|
||||
}
|
||||
stmt.close();
|
||||
}
|
||||
|
||||
sBuffer = new StringBuffer();
|
||||
sBuffer.append("<b>"+super.nomeEmpresa(con,empresaId)+"</b><br><br><i>"
|
||||
+super.nomeEstabelecimento(con, estabelecimentoId)+"</i>" );
|
||||
|
||||
HashMap hmValues = new HashMap();
|
||||
hmValues.put( "empresa_nome", session.getAttribute( sessionCompanyName ) );
|
||||
hmValues.put( "empresa_id", session.getAttribute( sessionEmpresaId ) );
|
||||
hmValues.put( "estabelecimento_nome", super.nomeEstabelecimento( con, estabelecimentoId ) );
|
||||
|
||||
/*Dados para marcacao de consulta/exame*/
|
||||
session.setAttribute( "session_estabelecimento_nome", hmValues.get( "estabelecimento_nome" ) );
|
||||
session.setAttribute( "session_funcionario_nome", hmFuncionario.get( "nome" ) );
|
||||
session.setAttribute( "session_funcionario_numero", hmFuncionario.get( "numero" ) );
|
||||
|
||||
hmValues.put( "estabelecimento_id", estabelecimentoId );
|
||||
hmValues.put( "userRole", userRole );
|
||||
hmValues.put( "userName", session.getAttribute( sessionUser ) );
|
||||
hmValues.put( msgTemplate , sBuffer.toString() ) ;
|
||||
hmValues.put( templateUserRole, userRole);
|
||||
hmValues.put( templateQuery, super.queryStringTrabalhador );
|
||||
hmValues.put( "funcionario", hmFuncionario );
|
||||
//hmValues.put( templateVector1,names);
|
||||
//hmValues.put( templateVector2,values);
|
||||
//hmValues.put( templateVector3,null);
|
||||
out.println( mergeTemplate( hmValues, super.authenticatedUserTemplate));
|
||||
|
||||
// out.println( mergeTemplate( sBuffer.toString(), userRole, super.queryStringTrabalhador, names, values, null, super.authenticatedUserTemplate) );
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
out.println( mergeTemplate( super.msgLinkFormatError , userRole, super.errorTemplate) );
|
||||
}
|
||||
con.close();
|
||||
}
|
||||
catch ( SQLException e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
out.println( mergeTemplate( super.msgErroBd , super.errorTemplate) );
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
out.println( mergeTemplate( super.msgGenericError , super.errorTemplate) );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,122 +0,0 @@
|
||||
package siprp.pagina;
|
||||
|
||||
import com.evolute.utils.arrays.*;
|
||||
import com.evolute.utils.strings.*;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import java.sql.*;
|
||||
import java.lang.reflect.Array;
|
||||
import javax.servlet.*;
|
||||
import javax.servlet.http.*;
|
||||
import org.apache.velocity.*;
|
||||
import org.apache.velocity.app.*;
|
||||
|
||||
public class doPostLogin extends siprpServlet
|
||||
{
|
||||
|
||||
/** Creates a new instance of doPostLogin */
|
||||
public doPostLogin(HttpServletRequest req, HttpServletResponse res) throws IOException
|
||||
{
|
||||
System.out.println( "doPostLogin()" );
|
||||
ServletOutputStream out = res.getOutputStream();
|
||||
StringBuffer dbQuery;
|
||||
ResultSet2DArray rs;
|
||||
Connection con = null ;
|
||||
Statement stmt = null ;
|
||||
String user, userRole, password;
|
||||
|
||||
try
|
||||
{
|
||||
user = req.getParameter("user");
|
||||
password = req.getParameter("password");
|
||||
|
||||
if (user.equals(""))
|
||||
{
|
||||
out.println( mergeTemplate( msgErroNoUser, errorTemplate) );
|
||||
}
|
||||
else
|
||||
{
|
||||
Class.forName(bdDriver);
|
||||
con = DriverManager.getConnection( bdUrl, bdUsername, bdPassword );
|
||||
dbQuery = new StringBuffer();
|
||||
dbQuery.append( "SELECT password FROM users WHERE username = '"+user+"'");
|
||||
|
||||
stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
|
||||
rs = new ResultSet2DArray( stmt.executeQuery( dbQuery.toString()) );
|
||||
|
||||
|
||||
if ( rs.columnLength() > 0 && password.equals((String)rs.get(0,0)))
|
||||
{
|
||||
// Obter Role
|
||||
|
||||
dbQuery = new StringBuffer();
|
||||
dbQuery.append( "SELECT role FROM roles WHERE username = '"+user+"'");
|
||||
stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
|
||||
|
||||
rs = new ResultSet2DArray( stmt.executeQuery( dbQuery.toString()) );
|
||||
userRole = (String)rs.get(0,0);
|
||||
|
||||
// UPDATE HTTP SESSION
|
||||
HttpSession session = req.getSession(true);
|
||||
session.setMaxInactiveInterval(sessionTimeout);
|
||||
|
||||
session.setAttribute(sessionUser, user);
|
||||
session.setAttribute(sessionUserRole, userRole);
|
||||
session.setAttribute(sessionPassword, password);
|
||||
|
||||
HashMap hmValues = new HashMap();
|
||||
session.setAttribute( sessionEmpresaId, userRole );
|
||||
if( userRole.equals( "manager" ) )
|
||||
{
|
||||
// session.setAttribute( sessionCompanyName, nomeEmpresa( con, "" + session.getAttribute( sessionEmpresaId ) ) );
|
||||
session.setAttribute( sessionCompanyName, null );
|
||||
session.setAttribute( sessionEstabelecimentoId, null );
|
||||
//hmValues.put( templateQuery, super.queryStringEmpresas );
|
||||
new doGetListaEmpresas( req, res );
|
||||
}
|
||||
else
|
||||
{
|
||||
session.setAttribute( sessionCompanyName,
|
||||
nomeEmpresa( DriverManager.getConnection( bdLocalUrl, bdLocalUsername, bdLocalPassword ),
|
||||
userRole ) );
|
||||
session.setAttribute( sessionEstabelecimentoId, "-1" );
|
||||
//hmValues.put( templateQuery, super.queryStringEstabelecimentos );
|
||||
new doGetListaEstabelecimentos( req, res );
|
||||
}
|
||||
stmt.close();
|
||||
con.close();
|
||||
|
||||
hmValues.put( "empresa_nome", session.getAttribute( sessionCompanyName ) );
|
||||
hmValues.put( "empresa_id", session.getAttribute( sessionEmpresaId ) );
|
||||
hmValues.put( "estabelecimento_id", session.getAttribute( sessionEstabelecimentoId ) );
|
||||
hmValues.put( "userRole", userRole );
|
||||
hmValues.put( "userName", user );
|
||||
//out.println( mergeTemplate( hmValues, super.authenticatedUserTemplate));
|
||||
|
||||
//out.println( mergeTemplate( user, userRole, super.authenticatedUserTemplate));
|
||||
}
|
||||
else
|
||||
{
|
||||
out.println( mergeTemplate( msgErroAuthFail, super.errorTemplate) );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch ( SQLException e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
out.println( mergeTemplate( msgErroBd , super.errorTemplate) );
|
||||
}
|
||||
catch ( IllegalStateException e ) // session timeout
|
||||
{
|
||||
e.printStackTrace();
|
||||
out.println( mergeTemplate(msgSessionTimeout, super.errorTemplate) );
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
out.println( mergeTemplate( msgGenericError , super.errorTemplate) );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,648 +0,0 @@
|
||||
package siprp.pagina;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Array;
|
||||
import javax.servlet.*;
|
||||
import javax.servlet.http.*;
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
|
||||
import org.apache.velocity.*;
|
||||
import org.apache.velocity.app.*;
|
||||
|
||||
import com.evolute.utils.*;
|
||||
import com.evolute.utils.arrays.*;
|
||||
import com.evolute.utils.db.*;
|
||||
import com.evolute.utils.sql.*;
|
||||
import com.evolute.utils.strings.*;
|
||||
|
||||
public class siprpServlet extends HttpServlet
|
||||
implements GlobalConstants
|
||||
{
|
||||
// MSG
|
||||
public static final String msgErroNoUser = "Tem+de+especificar+um+utilizador.";
|
||||
public static final String msgErroAuthFail = "Utilizador+inexistente+e/ou+Password+errada.";
|
||||
public static final String msgErroBd = "Erro+na+ligaç&atiolde;o+à+base+de+dados.";
|
||||
public static final String msgGenericError = "Erro";
|
||||
public static final String msgListaEmpresas = "Empresas";
|
||||
public static final String msgAcessoNegado = "Acesso+Negado.";
|
||||
public static final String msgLinkFormatError ="URL+inválido.";
|
||||
public static final String msgLogin = "Login";
|
||||
public static final String msgNovaPasswordErrada="Erro+ao+criar+a+nova+password,+nova+password+inválida.";
|
||||
public static final String msgButtonNotSuported = "funcionalidade+ainda+não+suportada.";
|
||||
public static final String msgSessionTimeout = "Por+razões+de+segurança+o+tempo+da+sua+sessão+expirou<br>"
|
||||
+ "Por+favor+efectue+novamente+o+seu+login.<br>";
|
||||
|
||||
// Templates - Nomes e valores
|
||||
//public static final String loginTemplate = "login.html";
|
||||
|
||||
public static final String indexTemplate = "index.html";
|
||||
public static final String authenticatedUserTemplate = "user.html";
|
||||
public static final String authenticatedUserPrintTemplate = "user_print.html";
|
||||
public static final String errorTemplate = "frame_erro.html";
|
||||
public static final String innerErrorTemplate = "erro.html";
|
||||
|
||||
public static final String mainTemplate = "main.html";
|
||||
//public static final String criticalErrorTemplate = "critical.html";
|
||||
public static final String templateVector1 ="v1";
|
||||
public static final String templateVector2 ="v2";
|
||||
public static final String templateVector3 ="v3";
|
||||
public static final String templateUserRole ="userRole";
|
||||
public static final String msgTemplate ="msg";
|
||||
public static final String templateQuery ="query";
|
||||
public static final String buttonPressedTemplate ="buttonPressed";
|
||||
|
||||
// Query Strings , usadas para na template do velocity saber o que mostar
|
||||
public static final String queryStringErro = "erro";
|
||||
public static final String queryStringEmpresas = "empresas";
|
||||
public static final String queryStringEstabelecimentos="estabelecimentos";
|
||||
public static final String queryStringTrabalhadores ="trabalhadores";
|
||||
public static final String queryStringTrabalhador ="trabalhador";
|
||||
|
||||
//Botoes, saber qual o botao escholido, campo value dos forms
|
||||
public static final String botaoLogin = "Entrar";
|
||||
public static final String botaoMarcarProximoExame = "Marcar Exame";
|
||||
|
||||
// Var da Session
|
||||
public static final String sessionUser="user";
|
||||
public static final String sessionUserRole="userRole";
|
||||
public static final String sessionPassword="password";
|
||||
public static final String sessionEmpresaId="empresaId";
|
||||
public static final String sessionEstabelecimentoId="estabelecimentoId";
|
||||
public static final String sessionTrabalhadorId="trabalhadorId";
|
||||
public static final String sessionCompanyName = "sessionCompanyName";
|
||||
public static final String sessionCompanyEmail = "sessionCompanyEmail";
|
||||
public static final int sessionTimeout = 3600; // segundos
|
||||
|
||||
public static final String servletName="siprpWeb";
|
||||
public static final String superUserRole="manager";
|
||||
|
||||
// // BD
|
||||
// public static final String bdHost = "127.0.0.1";
|
||||
// public static final String bdPort = "5436";
|
||||
// public static final String bdUsername = "siprp";
|
||||
// public static final String bdPassword = "";
|
||||
// public static final String bdDriver = "org.postgresql.Driver";
|
||||
// public static final String bdUrl = "jdbc:postgresql://" + bdHost + ":" + bdPort + "/siprp";
|
||||
|
||||
public static final String bdEmpresaIdRef = "id"; // campo que contem id da empresa
|
||||
public static final String bdEmpresaNomeRef = "designacao_social"; // campo que contem nome da empresa
|
||||
public static final String bdEstIdRef = "id"; // campo que contem nome do estabelecimento
|
||||
public static final String bdEstNomeRef = "nome"; // campo que contem nome do estabelecimento
|
||||
public static final String bdTrabIdRef = "id"; // campo que contem id do trabalhador
|
||||
public static final String bdTrabNomeRef = "nome"; // campo que contem nome do trabalhador
|
||||
public static final String bdNullString = ""; // String a mostrar quando o campo lido da BD é null
|
||||
public static final String bdEmailEmpresa = "email"; // campo que contem email da empresa
|
||||
|
||||
protected static ServletContext CONTEXT;
|
||||
|
||||
// Arrays
|
||||
public static final String[][] trabalhadorDescFields = new String [][]
|
||||
{ // nome que o user ve, nome do campo na tabela
|
||||
{"Nome", "nome"},
|
||||
{"Nº", "numero_mecanografico",},
|
||||
{"\u00DAltimo Exame", "ultimo_exame"},
|
||||
{"Realizado", "realizado"},
|
||||
{"Pr\u00F3ximo Exame", "proximo_exame"},
|
||||
{"\u00DAltima Consulta", "ultima_consulta"},
|
||||
{"Realizada", "realizada"},
|
||||
{"Pr\u00F3xima Consulta", "proxima_consulta"}
|
||||
};
|
||||
|
||||
public void init()
|
||||
{
|
||||
|
||||
try {
|
||||
CONTEXT = this.getServletContext();
|
||||
String TEMPLATE_DIR = this.getServletContext().getRealPath( "/" ) + "html/";
|
||||
System.out.println( "DIR: " + TEMPLATE_DIR );
|
||||
Properties props = new Properties();
|
||||
props.setProperty( "file.resource.loader.path", TEMPLATE_DIR );
|
||||
Velocity.init( props );
|
||||
Class.forName(bdDriver);
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void doGet( HttpServletRequest req, HttpServletResponse res )
|
||||
throws IOException
|
||||
{
|
||||
String queryString = req.getQueryString();
|
||||
String backUri = req.getRequestURI();
|
||||
ServletOutputStream out = res.getOutputStream();
|
||||
res.setContentType( "text/html" );
|
||||
try
|
||||
{
|
||||
System.out.println( "query: " + queryString );
|
||||
HttpSession session = req.getSession(true);
|
||||
session.setMaxInactiveInterval(sessionTimeout);
|
||||
|
||||
if ( queryString == null ) // Reload, 1º vez, etc ...
|
||||
{
|
||||
session.invalidate();
|
||||
out.println( mergeTemplate ( msgLogin, indexTemplate ) ) ;
|
||||
}
|
||||
else if ( session.isNew() && !( queryString.indexOf(queryStringErro) == 0 ) ) // session timeout
|
||||
{
|
||||
session.invalidate();
|
||||
out.println( mergeTemplate( msgGenericError , errorTemplate ) );
|
||||
// doErro(queryString, out);
|
||||
}
|
||||
else if ( queryString.equals(queryStringEmpresas) ) // Listar Empresas
|
||||
{
|
||||
new doGetListaEmpresas(req,res);
|
||||
}
|
||||
else if ( queryString.indexOf(queryStringErro) == 0 ) // Listar Empresas
|
||||
{
|
||||
// System.out.println( "entrou" );
|
||||
doErro(queryString, out);
|
||||
}
|
||||
else // interpretar query string
|
||||
{
|
||||
String empresa = null, estabelecimento=null, trabalhador=null;
|
||||
String query = null;
|
||||
int checkInt;
|
||||
|
||||
StringTokenizer sToken = new StringTokenizer(queryString,"/") ;
|
||||
empresa = sToken.nextToken(); // empresa ID
|
||||
checkInt = Integer.parseInt(empresa); // check int, NumberFormatException
|
||||
|
||||
if (sToken.hasMoreElements())
|
||||
{
|
||||
estabelecimento = sToken.nextToken(); // estabelecimento ID
|
||||
checkInt = Integer.parseInt(estabelecimento); // check int, NumberFormatException
|
||||
if (sToken.hasMoreElements())
|
||||
{
|
||||
trabalhador = sToken.nextToken(); // trabalhador ID
|
||||
try
|
||||
{
|
||||
checkInt = Integer.parseInt(trabalhador); // check int, NumberFormatException
|
||||
}
|
||||
catch( NumberFormatException nfex )
|
||||
{
|
||||
query = trabalhador;
|
||||
if( query.indexOf( "trabalhadores_tudo" ) != 0 && query.indexOf( "trabalhadores_pendentes" ) != 0 &&
|
||||
query.indexOf( "_print" ) == -1 )
|
||||
{
|
||||
throw nfex;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( estabelecimento == null ) // empresa query
|
||||
{
|
||||
session.setAttribute(sessionEmpresaId, empresa); // update HTTP Session
|
||||
|
||||
new doGetListaEstabelecimentos(req,res);
|
||||
|
||||
//out.println( mergeTemplate ( empresa, loginTemplate ) ) ;
|
||||
}
|
||||
else if ( trabalhador == null || query != null ) // estabelecimento query
|
||||
{
|
||||
session.setAttribute(sessionEmpresaId, empresa); // update HTTP Session
|
||||
session.setAttribute(sessionEstabelecimentoId, estabelecimento);
|
||||
|
||||
new doGetListaTrabalhadores(req,res, query);
|
||||
|
||||
//out.println( mergeTemplate ( " chama oGetListaTrabalhadores", loginTemplate ) ) ;
|
||||
}
|
||||
else // trabalhador query
|
||||
{
|
||||
session.setAttribute(sessionEmpresaId, empresa); // update HTTP Session
|
||||
session.setAttribute(sessionEstabelecimentoId, estabelecimento);
|
||||
session.setAttribute(sessionTrabalhadorId, trabalhador);
|
||||
|
||||
new doGetTrabalhador(req,res);
|
||||
|
||||
//out.println( mergeTemplate ( trabalhador, loginTemplate ) ) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch ( NumberFormatException e ) // argumentos invalidos
|
||||
{
|
||||
e.printStackTrace();
|
||||
out.println( mergeTemplate( msgLinkFormatError, backUri, errorTemplate) );
|
||||
}
|
||||
catch ( IllegalStateException e ) // session timeout
|
||||
{
|
||||
e.printStackTrace();
|
||||
out.println( mergeTemplate(msgSessionTimeout, errorTemplate) );
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
// out.println( mergeTemplate( msgGenericError , backUri, errorTemplate ) );
|
||||
out.println( mergeTemplate( msgGenericError , errorTemplate ) );
|
||||
}
|
||||
// System.out.println( "fim - " + queryString + " bu " + backUri );
|
||||
}
|
||||
|
||||
public void doPost(HttpServletRequest req, HttpServletResponse res)
|
||||
throws IOException
|
||||
{
|
||||
ServletOutputStream out = res.getOutputStream();
|
||||
//StringBuffer dbQuery;
|
||||
//ResultSet2DArray rs;
|
||||
//Connection con = null ;
|
||||
//Statement stmt = null ;
|
||||
//String user, userRole, password;
|
||||
String buttonPressed = req.getParameter("form");
|
||||
|
||||
try
|
||||
{
|
||||
if ( buttonPressed.equals(botaoLogin))
|
||||
{
|
||||
new doPostLogin(req,res);
|
||||
}
|
||||
else
|
||||
{
|
||||
out.println( mergeTemplate( msgButtonNotSuported, errorTemplate) );
|
||||
}
|
||||
}
|
||||
/*catch ( SQLException e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
out.println( mergeTemplate( msgErroBd , criticalErrorTemplate) );
|
||||
}*/
|
||||
catch ( IllegalStateException e ) // session timeout
|
||||
{
|
||||
e.printStackTrace();
|
||||
out.println( mergeTemplate(msgSessionTimeout, errorTemplate) );
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
out.println( mergeTemplate( msgGenericError , errorTemplate) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public String mergeTemplate( HashMap values, String template )
|
||||
{
|
||||
VelocityContext context = new VelocityContext();
|
||||
StringWriter output = new StringWriter();
|
||||
|
||||
try
|
||||
{
|
||||
for( Iterator i = values.keySet().iterator(); i.hasNext(); )
|
||||
{
|
||||
String key = ( String ) i.next();
|
||||
context.put ( key, values.get( key ) ) ;
|
||||
}
|
||||
|
||||
Velocity.mergeTemplate(template, Velocity.ENCODING_DEFAULT, context, output );
|
||||
return output.toString();
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String mergeTemplate (String msg, String template ) // #1
|
||||
{
|
||||
VelocityContext context = new VelocityContext();
|
||||
StringWriter output = new StringWriter();
|
||||
|
||||
try
|
||||
{
|
||||
context.put ( msgTemplate , msg ) ;
|
||||
Velocity.mergeTemplate(template, Velocity.ENCODING_DEFAULT, context, output );
|
||||
return output.toString();
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String mergeTemplate (String msg, String userRole, String template ) // #1
|
||||
{
|
||||
|
||||
VelocityContext context = new VelocityContext();
|
||||
StringWriter output = new StringWriter();
|
||||
|
||||
try
|
||||
{
|
||||
context.put ( msgTemplate , msg ) ;
|
||||
context.put ( templateUserRole, userRole);
|
||||
Velocity.mergeTemplate(template, Velocity.ENCODING_DEFAULT, context, output );
|
||||
return output.toString();
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String mergeTemplate ( String msg, String userRole, String querySelected, Vector vector1, Vector vector2, Vector vector3, String template ) // #2
|
||||
{
|
||||
|
||||
VelocityContext context = new VelocityContext();
|
||||
StringWriter output = new StringWriter();
|
||||
|
||||
try
|
||||
{
|
||||
context.put ( msgTemplate , msg ) ;
|
||||
context.put ( templateUserRole, userRole);
|
||||
context.put ( templateQuery, querySelected );
|
||||
context.put ( templateVector1,vector1);
|
||||
context.put ( templateVector2,vector2);
|
||||
context.put ( templateVector3,vector3);
|
||||
Velocity.mergeTemplate(template, Velocity.ENCODING_DEFAULT, context, output );
|
||||
return output.toString();
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void destroy()
|
||||
{
|
||||
}
|
||||
|
||||
public void handleSessionTimeout(HttpServletResponse res, String template)
|
||||
throws IOException
|
||||
{
|
||||
ServletOutputStream out = res.getOutputStream();
|
||||
try
|
||||
{
|
||||
out.println( mergeTemplate( msgSessionTimeout, template) );
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public boolean verificaEstabelecimento(Connection con, java.lang.String empresaId, java.lang.String estabelecimentoId)
|
||||
// verifica se o establecimento pertence à empresa
|
||||
{
|
||||
//Connection con = null ;
|
||||
Statement stmt = null ;
|
||||
Virtual2DArray rs;
|
||||
String query;
|
||||
try
|
||||
{
|
||||
//con = DriverManager.getConnection( bdUrl, bdUsername, bdPassword );
|
||||
query = "SELECT empresa_id FROM estabelecimentos where id='"+estabelecimentoId+"'";
|
||||
if( con != null )
|
||||
{
|
||||
stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
|
||||
rs = new ResultSet2DArray( stmt.executeQuery( query ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
rs = getExecuter().executeQuery( new Select( query ) );
|
||||
}
|
||||
String temp=""+rs.get(0,0); // converter de int para String
|
||||
if( con != null )
|
||||
{
|
||||
stmt.close();
|
||||
}
|
||||
if ( empresaId.equals(temp) ) // estabelecimento pertence à empresa
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean verificaTrabalhador(Connection con, java.lang.String estabelecimentoId, java.lang.String trabalhadorId)
|
||||
// verifica se o trabalhador pertence ao estabelecimento
|
||||
{
|
||||
//Connection con = null ;
|
||||
Statement stmt = null ;
|
||||
ResultSet2DArray rs;
|
||||
StringBuffer dbQuery;
|
||||
try
|
||||
{
|
||||
//con = DriverManager.getConnection( bdUrl, bdUsername, bdPassword );
|
||||
dbQuery = new StringBuffer();
|
||||
dbQuery.append( "SELECT estabelecimento_id FROM trabalhadores where id='"+trabalhadorId+"'");
|
||||
stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
|
||||
rs = new ResultSet2DArray( stmt.executeQuery( dbQuery.toString()) );
|
||||
String temp=""+rs.get(0,0); // converter de int para String
|
||||
stmt.close();
|
||||
if ( estabelecimentoId.equals(temp) ) // estabelecimento pertence à empresa
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void closeSqlCon(Connection con)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (con != null ) con.close();
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public String emailEmpresa(Connection con, String empresaId)
|
||||
{
|
||||
Statement stmt = null ;
|
||||
ResultSet2DArray rs;
|
||||
StringBuffer dbQuery;
|
||||
String returnString;
|
||||
|
||||
try
|
||||
{
|
||||
dbQuery = new StringBuffer();
|
||||
dbQuery.append( "SELECT email FROM empresas, contactos "
|
||||
+ "WHERE empresas.id ='"+empresaId+"' AND empresas.contacto_1 = contactos.id");
|
||||
stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
|
||||
rs = new ResultSet2DArray( stmt.executeQuery( dbQuery.toString()) );
|
||||
if( rs.columnLength() > 0 )
|
||||
{
|
||||
returnString = (String)rs.get(0,0);
|
||||
stmt.close();
|
||||
return returnString;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String nomeEmpresa(Connection con, String empresaId)
|
||||
{
|
||||
Statement stmt = null ;
|
||||
Virtual2DArray rs;
|
||||
String returnString;
|
||||
|
||||
try
|
||||
{
|
||||
String query = "SELECT designacao_social FROM empresas WHERE id ='"+empresaId+"'";
|
||||
if( con != null )
|
||||
{
|
||||
stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
|
||||
rs = new ResultSet2DArray( stmt.executeQuery( query ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
rs = getExecuter().executeQuery( new Select( query ) );
|
||||
}
|
||||
if( rs.columnLength() > 0 )
|
||||
{
|
||||
returnString = (String)rs.get(0,0);
|
||||
if( con != null )
|
||||
{
|
||||
stmt.close();
|
||||
}
|
||||
return returnString;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String nomeEstabelecimento(Connection con, java.lang.String estabelecimentoId)
|
||||
{
|
||||
Statement stmt = null ;
|
||||
Virtual2DArray rs;
|
||||
StringBuffer dbQuery;
|
||||
String returnString;
|
||||
|
||||
try
|
||||
{
|
||||
String query = "SELECT nome FROM estabelecimentos WHERE id ='"+estabelecimentoId+"'";
|
||||
if( con != null )
|
||||
{
|
||||
stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
|
||||
rs = new ResultSet2DArray( stmt.executeQuery( query ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
rs = getExecuter().executeQuery( new Select( query ) );
|
||||
}
|
||||
if( rs.columnLength() > 0 )
|
||||
{
|
||||
returnString = (String)rs.get(0,0);
|
||||
if( con != null )
|
||||
{
|
||||
stmt.close();
|
||||
}
|
||||
return returnString;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String nomeTrabalhador(Connection con, java.lang.String trabalhadorId)
|
||||
{
|
||||
Statement stmt = null ;
|
||||
ResultSet2DArray rs;
|
||||
StringBuffer dbQuery;
|
||||
String returnString;
|
||||
|
||||
try
|
||||
{
|
||||
dbQuery = new StringBuffer();
|
||||
dbQuery.append( "SELECT nome FROM trabalhadores where id='"+trabalhadorId+"'");
|
||||
stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
|
||||
rs = new ResultSet2DArray( stmt.executeQuery( dbQuery.toString()) );
|
||||
if( rs.columnLength() > 0 )
|
||||
{
|
||||
returnString = (String)rs.get(0,0);
|
||||
stmt.close();
|
||||
return returnString;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void doErro( String queryString, ServletOutputStream out )
|
||||
throws Exception
|
||||
{
|
||||
String split[] = queryString.split( "=" );
|
||||
String err;
|
||||
if( split.length > 1 )
|
||||
{
|
||||
err = split[ 1 ];
|
||||
}
|
||||
else
|
||||
{
|
||||
err = "Erro";
|
||||
}
|
||||
err = err.replace( '+', ' ' );
|
||||
out.println( mergeTemplate( err, innerErrorTemplate) );
|
||||
}
|
||||
|
||||
protected Executer getExecuter()
|
||||
throws Exception
|
||||
{
|
||||
ServletContext context = CONTEXT;
|
||||
DBManager dbm = ( DBManager ) context.getAttribute( Singleton.DEFAULT_DBMANAGER );
|
||||
if( dbm == null )
|
||||
{
|
||||
dbm = new JDBCManager( bdLocalUrl, bdLocalUsername, bdLocalPassword , 500, 499, 1, null );
|
||||
context.setAttribute( Singleton.DEFAULT_DBMANAGER, dbm );
|
||||
}
|
||||
return dbm.getSharedExecuter();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,46 +0,0 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
|
||||
<!DOCTYPE web-app
|
||||
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
|
||||
"http://java.sun.com/dtd/web-app_2_3.dtd">
|
||||
|
||||
<web-app>
|
||||
<display-name>SIPRP WEB</display-name>
|
||||
<description>SIPRP WEB</description>
|
||||
<servlet>
|
||||
<servlet-name>SIPRP WEB</servlet-name>
|
||||
<servlet-class>siprp.pagina.siprpServlet</servlet-class>
|
||||
</servlet>
|
||||
<servlet-mapping>
|
||||
<servlet-name>SIPRP WEB</servlet-name>
|
||||
<url-pattern>/index.html</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
<servlet>
|
||||
<servlet-name>Request</servlet-name>
|
||||
<servlet-class>siprp.pagina.RequestServlet</servlet-class>
|
||||
</servlet>
|
||||
<servlet-mapping>
|
||||
<servlet-name>Request</servlet-name>
|
||||
<url-pattern>/request</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
<servlet>
|
||||
<servlet-name>Schedule</servlet-name>
|
||||
<servlet-class>siprp.pagina.ScheduleServlet</servlet-class>
|
||||
</servlet>
|
||||
<servlet-mapping>
|
||||
<servlet-name>Schedule</servlet-name>
|
||||
<url-pattern>/schedule</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
<servlet>
|
||||
<servlet-name>Relatorio</servlet-name>
|
||||
<servlet-class>siprp.pagina.RelatorioServlet</servlet-class>
|
||||
</servlet>
|
||||
<servlet-mapping>
|
||||
<servlet-name>Relatorio</servlet-name>
|
||||
<url-pattern>/relatorio</url-pattern>
|
||||
</servlet-mapping>
|
||||
</web-app>
|
||||
|
||||
Loading…
Reference in new issue