------------------------------------------------------------
Listing 7: add-appointment.html

<!-- -*- mmm-classes: mason -*- -->
<HTML>

% # Make sure that we got all required name-value pairs
% unless ($begin_month and $begin_year and $begin_day and
%         $end_month and $end_year and $end_day and $email and $notes) {

    <Head>
        <Title>Missing information!</Title>
    </Head>

    <Body>
    <H1>Missing information!</H1>

    <P>Sorry, but you need to provide us with the beginning and ending
    dates and times of your appointment, as well as some notes about
    it.</P>

% # Make sure that the e-mail address looks somewhat valid
% } elsif ($email !~ /[.\w]+@\w+\.\w{2,3}/) {
                                                  
    <Head>
        <Title>Bad e-mail address!</Title>
    </Head>

    <Body>
        <H1>Bad e-mail address!</H1>

    <P>Sorry, but the provided e-mail address does not look legal.</P>

% # If we made it this far, try to create the appointment

% } else {

<%perl>
# Set the current person by e-mail address
my $set_person_successfully =
    $people->set_current_person_by_email($email);
</%perl>

% if ($set_person_successfully) {

<%perl>
                             
% if ($added_appointment_successfully) {

    <Head>
    <Title>Sucess!</Title>
    </Head>

    <Body>
    <H1>Success!</H1>

    <P>We successfully added your appointment.</P>

% } else {

    <Head>
    <Title>Error!</Title>
    </Head>

    <Body>
    <H1>Error!</H1>

    <P>We were unable to add your appointment.</P>
                                                            
% }

% }

% }

</Body>
</HTML>

<%init>
use People;
use Appointments;
my $people = new People;
my $appointments = new Appointments;
</%init>

<%args>
$email

$begin_day
$begin_month
$begin_year 
$begin_hour
$begin_minute

$end_day
$end_month
$end_year
$end_hour
$end_minute

$notes
</%args>
              
