% if ($message) {
% }
Add a person
Add a course
%#
%# ========================================================================
%#
<%args>
$action => ''
$name => ''
$phone => ''
$title => ''
$time => ''
$term => ''
$place => ''
$credits => ''
%args>
%#
<%init>
our $dggRegistrar;
my $message = '';
if ($action =~ /person/){
if (not $name or not $phone){
$message = "Oops - please give both a name and phone number.";
}
elsif ($name !~ /^[\w -.]*$/){
$message = "Oops - please use only alpha-numerics, spaces, and underbars for name.";
}
elsif ($phone !~ /^[\d -]*$/){
$message = "Oops - please use only numbers, spaces, and hyphens for phone.";
}
else {
$dggRegistrar->addPerson( name => $name, phone => $phone );
if ($dggRegistrar->getError){
$message = "Oops - database error: '" . $dggRegistrar->error . "'\n";
}
else {
$message = "OK, '$name' has been added to the database.";
$name = '';
$phone = '';
}
}
}
elsif ($action =~ /course/){
if (not $title or not $time or not $term or not $place or not $credits){
$message = "Oops - please include all course information.";
}
else {
$dggRegistrar->addCourse( title => $title, time => $time, term => $term, place => $place, credits => $credits );
if ($dggRegistrar->getError){
$message = "Oops - database error: '" . $dggRegistrar->error . "'\n";
}
else {
$message = "OK, '$title' has been added to the database.";
$title = '';
$time = '';
$term = '';
$place = '';
$credits = '';
}
}
}
%init>