no message

git-svn-id: https://svn.coded.pt/svn/SIPRP@456 bb69d46d-e84e-40c8-a05a-06db0d633741
lxbfYeaa
P Santos 21 years ago
parent 6d7a5e66aa
commit 3879fe9b3e

@ -0,0 +1,159 @@
/*
* ServletAux.java
*
* Created on 10 de Março de 2005, 12:24
*/
package siprp.pagina;
import java.io.*;
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.servlet.*;
import javax.servlet.http.*;
import org.apache.velocity.*;
import org.apache.velocity.app.*;
/**
*
* @author psantos
*/
public class MailerServlet extends HttpServlet
{
public void init()
{
try
{
String TEMPLATE_DIR = this.getServletContext().getRealPath( "/" ) + "html/";
Properties props = new Properties();
props.setProperty( "file.resource.loader.path", TEMPLATE_DIR );
Velocity.init( props );
}
catch( Exception e )
{
e.printStackTrace();
}
}
protected String createContent( Hashtable parameters, String[] form_fields, String template )
{
VelocityContext context = new VelocityContext();
StringWriter output = new StringWriter();
try
{
for( int i = 0; i < form_fields.length; i++ )
{
context.put( form_fields[ i ], parameters.get( form_fields[ i ] ) );
}
Velocity.mergeTemplate( template, Velocity.ENCODING_DEFAULT, context, output );
return output.toString();
}
catch( Exception e )
{
e.printStackTrace();
}
return null;
}
protected String showResultPage( boolean success, String success_template, String fail_template )
{
VelocityContext context = new VelocityContext();
StringWriter output = new StringWriter();
String template;
if( success )
{
template = success_template;
}
else
{
template = fail_template;
}
try
{
Velocity.mergeTemplate( template, Velocity.ENCODING_DEFAULT, context, output );
return output.toString();
}
catch( Exception e )
{
e.printStackTrace();
}
return null;
}
protected boolean sendMail( String from, String destination, String subject, String content )
{
String smtp_server = "localhost";
String mailer = "Evolute Mailer";
Properties props = System.getProperties();
props.put( "mail.smtp.host", smtp_server );
Session session = Session.getInstance( props, null );
Message msg = new MimeMessage( session );
try
{
if( from != null )
{
msg.setFrom( new InternetAddress( from ) );
}
msg.setRecipients( Message.RecipientType.TO, InternetAddress.parse( destination, true ) );
msg.setSubject( subject );
msg.setContent( content.toString(), "text/plain" );
msg.setHeader( "X-Mailer", mailer );
msg.setSentDate( new Date() );
Transport.send( msg );
return true;
}
catch( Exception e )
{
e.printStackTrace();
}
return false;
}
private String checkParameter( String parameter )
{
if( parameter != null && parameter.trim().length() > 0 )
{
return parameter.trim();
}
return null;
}
protected Hashtable parseParameters( Hashtable parameters )
{
Hashtable tmp = new Hashtable();
String[] element;
String key;
String new_element;
for( Enumeration e = parameters.keys(); e.hasMoreElements(); )
{
key = ( String ) e.nextElement();
element = ( String[] ) parameters.get( key );
if( element != null )
{
new_element = checkParameter( element[ 0 ] );
if( new_element != null )
{
tmp.put( key, new_element );
}
}
}
return tmp;
}
}

@ -0,0 +1,95 @@
/*
* 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" ) );
}
}

@ -15,3 +15,50 @@ function showhide( id )
}
}
}
function isValidDate( year, month, day )
{
return day > 0 && ( day <= [, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][ month ] ||
day == 29 && month == 2 && year % 4 == 0 && ( year % 100 > 0 || year % 400 == 0 ) );
}
function isValid( element, type )
{
switch( type )
{
// date
case 0:
if( element.value.search( /^\d\d?\/\d\d?\/\d{1,4}$/ ) != 0 )
{
alert( "Formato da data incorrecto." );
window.setTimeout( "document.getElementById( '" + element.name + "').focus()", 1 );
return false;
}
date_value = element.value.split( "/" );
if( ! isValidDate( date_value[ 2 ], date_value[ 1 ], date_value[ 0 ] ) )
{
alert( "Data inválida." );
window.setTimeout( "document.getElementById( '" + element.name + "').focus()", 1 );
return false;
}
break;
// integer
case 1:
if( element.value.search( /^\d\d:\d\d$/ ) != 0 )
{
alert( "Formato da hora incorrecto." );
window.setTimeout( "document.getElementById( '" + element.name + "' ).focus()", 1 );
return false;
}
hora_value = element.value.split( "/" );
if( date_value[ 0 ] > 23 || date_value[ 1 ] > 59 )
{
alert( "Hora inválida." );
window.setTimeout( "document.getElementById( '" + element.name + "').focus()", 1 );
return false;
}
break;
}
return true;
}

@ -0,0 +1,7 @@
Empresa: $empresa
Estabelecimento: $estabelecimento
Funcionário: $funcionario
$marcacao_tipo no dia $data#if( $marcacao_tipo == 'Consulta' ) às $hora#end.
Email de resposta

@ -0,0 +1,54 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Marca&ccedil;&atilde;o de consulta / exame</title>
</head>
<script language="javascript" src="/siprpWeb/html/css/funcs.js"></script>
<script>
function validateForm()
{
alert( document.f.ola.value );
if( document.f.marcacao_tipo.value == null )
{
alert( "Tem que escolher o tipo de marcação." );
return false;
}
return isValid( document.f.data, 0 ) && isValid( document.f.hora, 1 ) ;
}
</script>
<body>
<form method='post' action='/siprpWeb/schedule' name='f'>
<table>
<tr>
<td>
<input type='radio' id='ola' name='ola' value='ola'>Ola
<input type='radio' id='ola' name='ola' value='adeus'>Ola
<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
</td>
</tr>
<tr>
<td>
Data:<input type='text' id='data' name='data'>dd/mm/aaaa
</td>
</tr>
<tr>
<td>
Hora:<input type='text' id='hora' name='hora'>hh:mm
</td>
</tr>
<tr>
<td>
Nota: a marca&ccedil;&atilde;o est&aacute; sujeita a confirma&ccedil;&atilde;o via email.
</td>
</tr>
<tr>
<td>
<input type='submit' value='Marcar' onclick='return validateForm()'>
</td>
</tr>
</table>
</form>
</body>
</html>

@ -89,6 +89,7 @@ a.text:active
font-size: 10pt;
font-weight: bold;
text-decoration: none;
cursor: pointer;
}
a.text:hover
@ -123,6 +124,14 @@ td.box6
border-width: 1px 1px 1px 0px;
}
</style>
<script language="javascript" src="/siprpWeb/html/css/funcs.js"></script>
<script>
function marcacaoWindow()
{
wnd = window.open( "schedule", "marcacao_window", "menubar=0, resizeable=0, width=350, height=250, top=100, left=450" );
wnd.focus();
}
</script>
<body>
<table style="width: 760px; height: 623px; background-image: url(/siprpWeb/html/images/fundo.jpg); background-repeat: no-repeat;" align='center' >
<tbody>
@ -236,13 +245,10 @@ td.box6
<td width='14%'>&Uacute;ltimo Exame</td><td width='14%'>Realizado</td><td width='14%'>Pr&oacute;ximo Exame</td><td width='14%'>&Uacute;ltima Consulta</td><td width='14%'>Realizada</td><td width='14%'>Pr&oacute;xima Consulta</td><td>Marca&ccedil;&atilde;o</td>
</tr>
<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='box6'>&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>
</tr>
</table>
##<form method="post">
## <input type="submit" name="form" value="Marcar Exame"/>
## <input type="submit" name="form" value="Marcar Consulta"/>
##</form>
#else
#foreach( $element in $v1 )
#set ( $counter = $velocityCount - 1 )

Loading…
Cancel
Save