forked from Coded/SIPRP
				
			
			You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							143 lines
						
					
					
						
							4.2 KiB
						
					
					
				
			
		
		
	
	
							143 lines
						
					
					
						
							4.2 KiB
						
					
					
				/*
 | 
						|
 * 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;
 | 
						|
	}
 | 
						|
}
 |