From 7831f66c38c8a560c15b11fd82f13f14a70804c0 Mon Sep 17 00:00:00 2001 From: P Santos Date: Fri, 11 Mar 2005 16:59:44 +0000 Subject: [PATCH] no message git-svn-id: https://svn.coded.pt/svn/SIPRP@458 bb69d46d-e84e-40c8-a05a-06db0d633741 --- .../classes/siprp/pagina/MailerServlet.java | 6 +- .../classes/siprp/pagina/RequestServlet.java | 2 +- .../classes/siprp/pagina/ScheduleServlet.java | 59 ++++++++++++++----- trunk/html/css/funcs.js | 4 +- trunk/html/marcacao/marcacao.html | 13 ++++ trunk/html/marcacao/marcacao_enviada.html | 11 ++++ trunk/html/marcacao/marcacao_menu.html | 38 +++++++----- trunk/html/marcacao/marcacao_nao_enviada.html | 11 ++++ .../marcacao/marcacao_sessao_expirou.html | 11 ++++ trunk/html/user.html | 4 +- 10 files changed, 123 insertions(+), 36 deletions(-) create mode 100644 trunk/html/marcacao/marcacao.html create mode 100644 trunk/html/marcacao/marcacao_enviada.html create mode 100644 trunk/html/marcacao/marcacao_nao_enviada.html create mode 100644 trunk/html/marcacao/marcacao_sessao_expirou.html diff --git a/trunk/WEB-INF/classes/siprp/pagina/MailerServlet.java b/trunk/WEB-INF/classes/siprp/pagina/MailerServlet.java index 6ee441ee..8f6d6690 100644 --- a/trunk/WEB-INF/classes/siprp/pagina/MailerServlet.java +++ b/trunk/WEB-INF/classes/siprp/pagina/MailerServlet.java @@ -89,7 +89,7 @@ public class MailerServlet extends HttpServlet return null; } - protected boolean sendMail( String from, String destination, String subject, String content ) + protected boolean sendMail( String from, String destination, String subject, String content, boolean html ) { String smtp_server = "localhost"; String mailer = "Evolute Mailer"; @@ -97,6 +97,8 @@ public class MailerServlet extends HttpServlet 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 @@ -108,7 +110,7 @@ public class MailerServlet extends HttpServlet msg.setRecipients( Message.RecipientType.TO, InternetAddress.parse( destination, true ) ); msg.setSubject( subject ); - msg.setContent( content.toString(), "text/plain" ); + msg.setContent( content.toString(), content_type ); msg.setHeader( "X-Mailer", mailer ); msg.setSentDate( new Date() ); diff --git a/trunk/WEB-INF/classes/siprp/pagina/RequestServlet.java b/trunk/WEB-INF/classes/siprp/pagina/RequestServlet.java index 6bedce77..4257daca 100644 --- a/trunk/WEB-INF/classes/siprp/pagina/RequestServlet.java +++ b/trunk/WEB-INF/classes/siprp/pagina/RequestServlet.java @@ -50,7 +50,7 @@ public class RequestServlet extends MailerServlet String destination = "psantos@evolute.pt"; String subject = "Pedido de informação através do site www.siprp.pt"; // manda mail - boolean success = sendMail( from, destination, subject, content ); + boolean success = sendMail( from, destination, subject, content, false ); // mostra pagina correspondente out.println( showResultPage( success, "mail/pedido_enviado.html", "mail/pedido_nao_enviado.html" ) ); diff --git a/trunk/WEB-INF/classes/siprp/pagina/ScheduleServlet.java b/trunk/WEB-INF/classes/siprp/pagina/ScheduleServlet.java index b4de0e39..ef35993c 100644 --- a/trunk/WEB-INF/classes/siprp/pagina/ScheduleServlet.java +++ b/trunk/WEB-INF/classes/siprp/pagina/ScheduleServlet.java @@ -39,21 +39,22 @@ public class ScheduleServlet extends MailerServlet 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 ); + Hashtable parameters = new Hashtable(); - out.println( output.toString() ); - } - catch( Exception e ) + // Ir buscar os parametros à sessão + HttpSession session = req.getSession( false ); + if( session == null ) { - e.printStackTrace(); + // timeout + out.println( showPage( "marcacao/marcacao_sessao_expirou.html", null ) ); + return; } - return; + parameters.put( EMPRESA, session.getAttribute( siprpServlet.sessionCompanyName ) ); + parameters.put( ESTABELECIMENTO, session.getAttribute( "session_estabelecimento_nome" ) ); + parameters.put( FUNCIONARIO, session.getAttribute( "session_funcionario_nome" ) ); + + out.println( showPage( "marcacao/marcacao_menu.html", parameters ) ); } public void doPost( HttpServletRequest req, HttpServletResponse res ) @@ -71,6 +72,7 @@ public class ScheduleServlet extends MailerServlet if( session == null ) { // timeout + out.println( showPage( "marcacao/marcacao_sessao_expirou.html", null ) ); return; } @@ -85,11 +87,40 @@ public class ScheduleServlet extends MailerServlet 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" ); + String content = createContent( parameters, FORM_FIELDS, "marcacao/marcacao.html" ); // manda mail - boolean success = sendMail( null, destination, subject, content ); + boolean success = sendMail( null, destination, subject, content, true ); // mostra pagina correspondente - out.println( showResultPage( success, "marcacaco/marcacao_enviada.html", "marcacaco/marcacao_nao_enviada.html" ) ); + 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; } } diff --git a/trunk/html/css/funcs.js b/trunk/html/css/funcs.js index 512e0fb6..099f6df4 100644 --- a/trunk/html/css/funcs.js +++ b/trunk/html/css/funcs.js @@ -50,8 +50,8 @@ function isValid( element, type ) window.setTimeout( "document.getElementById( '" + element.name + "' ).focus()", 1 ); return false; } - hora_value = element.value.split( "/" ); - if( date_value[ 0 ] > 23 || date_value[ 1 ] > 59 ) + time_value = element.value.split( ":" ); + if( time_value[ 0 ] > 23 || time_value[ 1 ] > 59 ) { alert( "Hora inválida." ); window.setTimeout( "document.getElementById( '" + element.name + "').focus()", 1 ); diff --git a/trunk/html/marcacao/marcacao.html b/trunk/html/marcacao/marcacao.html new file mode 100644 index 00000000..b549c435 --- /dev/null +++ b/trunk/html/marcacao/marcacao.html @@ -0,0 +1,13 @@ + + + + +Empresa: $empresa
+Estabelecimento: $estabelecimento
+Funcionário: $funcionario
+
+$marcacao_tipo no dia $data#if( $marcacao_tipo == 'Consulta' ) às $hora#end.
+
+Email de resposta
+ + diff --git a/trunk/html/marcacao/marcacao_enviada.html b/trunk/html/marcacao/marcacao_enviada.html new file mode 100644 index 00000000..481963aa --- /dev/null +++ b/trunk/html/marcacao/marcacao_enviada.html @@ -0,0 +1,11 @@ + + + + + Marcação de consulta / exame + + + + O pedido de marcação foi enviado com sucesso. + + diff --git a/trunk/html/marcacao/marcacao_menu.html b/trunk/html/marcacao/marcacao_menu.html index 7dc978c4..0c605749 100644 --- a/trunk/html/marcacao/marcacao_menu.html +++ b/trunk/html/marcacao/marcacao_menu.html @@ -3,48 +3,56 @@ Marcação de consulta / exame +
- +
- + + + - + - + - - diff --git a/trunk/html/marcacao/marcacao_nao_enviada.html b/trunk/html/marcacao/marcacao_nao_enviada.html new file mode 100644 index 00000000..5621b521 --- /dev/null +++ b/trunk/html/marcacao/marcacao_nao_enviada.html @@ -0,0 +1,11 @@ + + + + + Marcação de consulta / exame + + + + Ocorreu um erro a enviar o pedido de marcação. + + diff --git a/trunk/html/marcacao/marcacao_sessao_expirou.html b/trunk/html/marcacao/marcacao_sessao_expirou.html new file mode 100644 index 00000000..3a84b5fc --- /dev/null +++ b/trunk/html/marcacao/marcacao_sessao_expirou.html @@ -0,0 +1,11 @@ + + + + + Sessão expirou + + + + A sua sessão expirou. Para efectuar uma marcação, autentique-se novamente. + + diff --git a/trunk/html/user.html b/trunk/html/user.html index ec73f84f..86b5be4c 100644 --- a/trunk/html/user.html +++ b/trunk/html/user.html @@ -128,7 +128,7 @@ td.box6 @@ -246,7 +246,7 @@ td.box6 - +
- Ola - Ola + + Marcação para:
+ $funcionario +
Consulta Exame
- Data:dd/mm/aaaa - Data:dd/mm/aaaa
- Hora:hh:mm - Hora:hh:mm
+ Nota: a marcação está sujeita a confirmação via email.
+
$!funcionario.ultimo_exame $!funcionario.realizado $!funcionario.proximo_exame $!funcionario.ultima_consulta $!funcionario.realizada $!funcionario.proxima_consulta MarcarMarcar
#else