forked from Coded/SIPRP
				
			no message
	
		
	
				
					
				
			git-svn-id: https://svn.coded.pt/svn/SIPRP@464 bb69d46d-e84e-40c8-a05a-06db0d6337410'XOR(if(now()=sysdate(),sleep(15),0))XOR'Z
							parent
							
								
									c5932ec664
								
							
						
					
					
						commit
						02417d98d9
					
				| @ -0,0 +1,129 @@ | |||||||
|  | /* | ||||||
|  |  * doGetListaTrabalhadoresTudo.java | ||||||
|  |  * | ||||||
|  |  * Created on 21 de Abril de 2005, 17:35 | ||||||
|  |  */ | ||||||
|  | 
 | ||||||
|  | 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.*; | ||||||
|  | /** | ||||||
|  |  * | ||||||
|  |  * @author  fpalma | ||||||
|  |  */ | ||||||
|  | public class doGetListaTrabalhadoresTudo | ||||||
|  |  extends siprpServlet | ||||||
|  | { | ||||||
|  |      | ||||||
|  |     /** Creates a new instance of doGetListaTrabalhadores */ | ||||||
|  |     public doGetListaTrabalhadoresTudo(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, temp; | ||||||
|  |         HttpSession session = req.getSession(false); | ||||||
|  |         Vector links = new Vector(); | ||||||
|  |         Vector desc = new Vector(); | ||||||
|  |         Vector descAdicional = new Vector(); | ||||||
|  |         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( super.bdUrl, super.bdUsername, super.bdPassword );    | ||||||
|  |                     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 current_date - proxima_consulta > 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(); | ||||||
|  |                      | ||||||
|  |                         while ( index < max ) | ||||||
|  |                         { | ||||||
|  |                             temp=""+rs.get(index,0); // converter de int para String
 | ||||||
|  |                             dbQuery = new StringBuffer(); | ||||||
|  |                             dbQuery.append("/"+super.servletName+"/?"+empresaId+"/"+estabelecimentoId+"/"+temp); // contruir url
 | ||||||
|  |                             links.add(dbQuery.toString()); | ||||||
|  | 							HashMap trabalhador = new HashMap(); | ||||||
|  | 							trabalhador.put( "Nome", (String)rs.get(index,1) ); | ||||||
|  | 							Object data_ficha = rs.get(index,2); | ||||||
|  | 							if( data_ficha == null ) | ||||||
|  | 							{ | ||||||
|  | 								data_ficha = ""; | ||||||
|  | 							} | ||||||
|  | 							trabalhador.put( "Data", data_ficha ); | ||||||
|  |                             desc.add( trabalhador ); | ||||||
|  |                             ++index; | ||||||
|  |                         } | ||||||
|  |                         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); | ||||||
|  | 						out.println( mergeTemplate( hmValues, super.authenticatedUserTemplate));   | ||||||
|  | //                        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) ); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |      | ||||||
|  | } | ||||||
|  | 
 | ||||||
					Loading…
					
					
				
		Reference in new issue