/* * 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[] FORM_FIELDS = new String[]{ EMPRESA, ESTABELECIMENTO, FUNCIONARIO, MARCACAO_TIPO, DATA, HORA }; public void doGet( HttpServletRequest req, HttpServletResponse res ) throws IOException { ServletOutputStream out = res.getOutputStream(); res.setContentType( "text/html" ); VelocityContext context = new VelocityContext(); StringWriter output = new StringWriter(); try { Velocity.mergeTemplate( "marcacao/marcacao_menu.html", Velocity.ENCODING_DEFAULT, context, output ); out.println( output.toString() ); } catch( Exception e ) { e.printStackTrace(); } return; } public void doPost( HttpServletRequest req, HttpServletResponse res ) throws IOException { ServletOutputStream out = res.getOutputStream(); 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 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 = MAIL DA EMPRESA String marcacao_tipo = ( String )parameters.get( MARCACAO_TIPO ); String destination = "psantos@evolute.pt"; String subject = "Pedido de marcação de " + marcacao_tipo + " via web"; String content = createContent( parameters, FORM_FIELDS, "marcacao/marcacao.txt" ); // manda mail boolean success = sendMail( null, destination, subject, content ); // mostra pagina correspondente out.println( showResultPage( success, "marcacaco/marcacao_enviada.html", "marcacaco/marcacao_nao_enviada.html" ) ); } }