no message

git-svn-id: https://svn.coded.pt/svn/SIPRP@458 bb69d46d-e84e-40c8-a05a-06db0d633741
lxbfYeaa
P Santos 21 years ago
parent c66d8fc273
commit 7831f66c38

@ -89,7 +89,7 @@ public class MailerServlet extends HttpServlet
return null; 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 smtp_server = "localhost";
String mailer = "Evolute Mailer"; String mailer = "Evolute Mailer";
@ -97,6 +97,8 @@ public class MailerServlet extends HttpServlet
Properties props = System.getProperties(); Properties props = System.getProperties();
props.put( "mail.smtp.host", smtp_server ); props.put( "mail.smtp.host", smtp_server );
String content_type = ( html ) ? "text/html" : "text/plain";
Session session = Session.getInstance( props, null ); Session session = Session.getInstance( props, null );
Message msg = new MimeMessage( session ); Message msg = new MimeMessage( session );
try try
@ -108,7 +110,7 @@ public class MailerServlet extends HttpServlet
msg.setRecipients( Message.RecipientType.TO, InternetAddress.parse( destination, true ) ); msg.setRecipients( Message.RecipientType.TO, InternetAddress.parse( destination, true ) );
msg.setSubject( subject ); msg.setSubject( subject );
msg.setContent( content.toString(), "text/plain" ); msg.setContent( content.toString(), content_type );
msg.setHeader( "X-Mailer", mailer ); msg.setHeader( "X-Mailer", mailer );
msg.setSentDate( new Date() ); msg.setSentDate( new Date() );

@ -50,7 +50,7 @@ public class RequestServlet extends MailerServlet
String destination = "psantos@evolute.pt"; String destination = "psantos@evolute.pt";
String subject = "Pedido de informação através do site www.siprp.pt"; String subject = "Pedido de informação através do site www.siprp.pt";
// manda mail // manda mail
boolean success = sendMail( from, destination, subject, content ); boolean success = sendMail( from, destination, subject, content, false );
// mostra pagina correspondente // mostra pagina correspondente
out.println( showResultPage( success, "mail/pedido_enviado.html", "mail/pedido_nao_enviado.html" ) ); out.println( showResultPage( success, "mail/pedido_enviado.html", "mail/pedido_nao_enviado.html" ) );

@ -39,21 +39,22 @@ public class ScheduleServlet extends MailerServlet
ServletOutputStream out = res.getOutputStream(); ServletOutputStream out = res.getOutputStream();
res.setContentType( "text/html" ); res.setContentType( "text/html" );
VelocityContext context = new VelocityContext(); Hashtable parameters = new Hashtable();
StringWriter output = new StringWriter();
try
{
Velocity.mergeTemplate( "marcacao/marcacao_menu.html", Velocity.ENCODING_DEFAULT, context, output );
out.println( output.toString() ); // Ir buscar os parametros à sessão
} HttpSession session = req.getSession( false );
catch( Exception e ) 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 ) public void doPost( HttpServletRequest req, HttpServletResponse res )
@ -71,6 +72,7 @@ public class ScheduleServlet extends MailerServlet
if( session == null ) if( session == null )
{ {
// timeout // timeout
out.println( showPage( "marcacao/marcacao_sessao_expirou.html", null ) );
return; return;
} }
@ -85,11 +87,40 @@ public class ScheduleServlet extends MailerServlet
String destination = "psantos@evolute.pt"; String destination = "psantos@evolute.pt";
String subject = "Pedido de marcação de " + marcacao_tipo + " via web"; 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 // manda mail
boolean success = sendMail( null, destination, subject, content ); boolean success = sendMail( null, destination, subject, content, true );
// mostra pagina correspondente // 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;
} }
} }

@ -50,8 +50,8 @@ function isValid( element, type )
window.setTimeout( "document.getElementById( '" + element.name + "' ).focus()", 1 ); window.setTimeout( "document.getElementById( '" + element.name + "' ).focus()", 1 );
return false; return false;
} }
hora_value = element.value.split( "/" ); time_value = element.value.split( ":" );
if( date_value[ 0 ] > 23 || date_value[ 1 ] > 59 ) if( time_value[ 0 ] > 23 || time_value[ 1 ] > 59 )
{ {
alert( "Hora inválida." ); alert( "Hora inválida." );
window.setTimeout( "document.getElementById( '" + element.name + "').focus()", 1 ); window.setTimeout( "document.getElementById( '" + element.name + "').focus()", 1 );

@ -0,0 +1,13 @@
<html>
<head>
</head>
<body>
Empresa: $empresa<br>
Estabelecimento: $estabelecimento<br>
Funcionário: $funcionario<br>
<br>
$marcacao_tipo no dia $data#if( $marcacao_tipo == 'Consulta' ) às $hora#end.<br>
<br>
Email de resposta<br>
</body>
</html>

@ -0,0 +1,11 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Marca&ccedil;&atilde;o de consulta / exame</title>
<link rel="stylesheet" href="/siprpWeb/html/css/style.css" type="text/css">
</head>
<body class='text'>
O pedido de marca&ccedil;&atilde;o foi enviado com sucesso.
</body>
</html>

@ -3,48 +3,56 @@
<html> <html>
<head> <head>
<title>Marca&ccedil;&atilde;o de consulta / exame</title> <title>Marca&ccedil;&atilde;o de consulta / exame</title>
<link rel="stylesheet" href="/siprpWeb/html/css/style.css" type="text/css">
</head> </head>
<script language="javascript" src="/siprpWeb/html/css/funcs.js"></script> <script language="javascript" src="/siprpWeb/html/css/funcs.js"></script>
<script> <script>
function validateForm() function validateForm()
{ {
alert( document.f.ola.value ); checked = -1;
if( document.f.marcacao_tipo.value == null ) for( i = 0; i < document.f.marcacao_tipo.length; i++ )
{
if( document.f.marcacao_tipo[ i ].checked )
{
checked = i;
}
}
if( checked == -1 )
{ {
alert( "Tem que escolher o tipo de marcação." ); alert( "Tem que escolher o tipo de marcação." );
return false; return false;
} }
return isValid( document.f.data, 0 ) && isValid( document.f.hora, 1 ) ; return isValid( document.f.data, 0 ) && ( checked == 1 || isValid( document.f.hora, 1 ) );
} }
</script> </script>
<body> <body>
<form method='post' action='/siprpWeb/schedule' name='f'> <form method='post' action='/siprpWeb/schedule' name='f'>
<table> <table class='text'>
<tr> <tr>
<td> <td colspan='2'>
<input type='radio' id='ola' name='ola' value='ola'>Ola Marca&ccedil;&atilde;o para:<br>
<input type='radio' id='ola' name='ola' value='adeus'>Ola $funcionario
</td>
</tr>
<tr>
<td colspan='2'>
<input type='radio' id='marcacao_tipo' name='marcacao_tipo' value='Consulta' onclick='document.getElementById( "hora" ).disabled = false;'>Consulta <input type='radio' id='marcacao_tipo' name='marcacao_tipo' value='Consulta' onclick='document.getElementById( "hora" ).disabled = false;'>Consulta
<input type='radio' id='marcacao_tipo' name='marcacao_tipo' value='Exame' onclick='document.getElementById( "hora" ).disabled = true;'>Exame <input type='radio' id='marcacao_tipo' name='marcacao_tipo' value='Exame' onclick='document.getElementById( "hora" ).disabled = true;'>Exame
</td> </td>
</tr> </tr>
<tr> <tr>
<td> <td>Data:</td><td><input type='text' id='data' name='data'>dd/mm/aaaa</td>
Data:<input type='text' id='data' name='data'>dd/mm/aaaa
</td>
</tr> </tr>
<tr> <tr>
<td> <td>Hora:</td><td><input type='text' id='hora' name='hora'>hh:mm</td>
Hora:<input type='text' id='hora' name='hora'>hh:mm
</td>
</tr> </tr>
<tr> <tr>
<td> <td colspan='2'>
Nota: a marca&ccedil;&atilde;o est&aacute; sujeita a confirma&ccedil;&atilde;o via email. Nota: a marca&ccedil;&atilde;o est&aacute; sujeita a confirma&ccedil;&atilde;o via email.
</td> </td>
</tr> </tr>
<tr> <tr>
<td> <td colspan='2'>
<input type='submit' value='Marcar' onclick='return validateForm()'> <input type='submit' value='Marcar' onclick='return validateForm()'>
</td> </td>
</tr> </tr>

@ -0,0 +1,11 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Marca&ccedil;&atilde;o de consulta / exame</title>
<link rel="stylesheet" href="/siprpWeb/html/css/style.css" type="text/css">
</head>
<body class='text'>
Ocorreu um erro a enviar o pedido de marca&ccedil;&atilde;o.
</body>
</html>

@ -0,0 +1,11 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Sess&atilde;o expirou</title>
<link rel="stylesheet" href="/siprpWeb/html/css/style.css" type="text/css">
</head>
<body class='text'>
A sua sess&atilde;o expirou. Para efectuar uma marca&ccedil;&atilde;o, autentique-se novamente.
</body>
</html>

@ -128,7 +128,7 @@ td.box6
<script> <script>
function marcacaoWindow() function marcacaoWindow()
{ {
wnd = window.open( "schedule", "marcacao_window", "menubar=0, resizeable=0, width=350, height=250, top=100, left=450" ); wnd = window.open( "schedule", "marcacao_window", "menubar=0, resizeable=0, width=400, height=250, top=100, left=450" );
wnd.focus(); wnd.focus();
} }
</script> </script>
@ -246,7 +246,7 @@ td.box6
</tr> </tr>
<tr align='center'> <tr align='center'>
<td class='box5'>$!funcionario.ultimo_exame&nbsp;</td><td class='box6'>$!funcionario.realizado&nbsp;</td><td class='box6'>$!funcionario.proximo_exame&nbsp;</td><td class='box6'>$!funcionario.ultima_consulta&nbsp;</td><td class='box6'>$!funcionario.realizada&nbsp;</td><td class='box6'>$!funcionario.proxima_consulta&nbsp;</td> <td class='box5'>$!funcionario.ultimo_exame&nbsp;</td><td class='box6'>$!funcionario.realizado&nbsp;</td><td class='box6'>$!funcionario.proximo_exame&nbsp;</td><td class='box6'>$!funcionario.ultima_consulta&nbsp;</td><td class='box6'>$!funcionario.realizada&nbsp;</td><td class='box6'>$!funcionario.proxima_consulta&nbsp;</td>
<td class='box6'><a class='text' href='' onclick='marcacaoWindow()'>Marcar</a></td> <td class='box6'><a class='text' href='javascript:marcacaoWindow();'>Marcar</a></td>
</tr> </tr>
</table> </table>
#else #else

Loading…
Cancel
Save