|
|
|
|
@ -20,19 +20,93 @@ import org.apache.velocity.app.*;
|
|
|
|
|
*/
|
|
|
|
|
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";
|
|
|
|
|
|
|
|
|
|
/** Creates a new instance of RelatorioServlet */
|
|
|
|
|
public RelatorioServlet()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
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 destination = "fpalma@evolute.pt";
|
|
|
|
|
String subject = "Pedido de envio de relatório via web";
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|