package Error;

# NOTE: If control comes into here (i.e., if you call a function in
# here), then you will *not* get control back.  Any new functions
# added here should follow that, or be put into General.pm.

# Subroutines found here:
#     * AlreadyRegistered: generated when an reg conflict is attempted
#     * BadEmailAddress: not of the form aoeu@aoeu.aoeu.aoeu.aoeu etc
#     * BadNameSpecification: only [a-z -,] is allowed
#     * BlankNameSpecification: hey, fill in the field!
#     * BlankSchoolSpecification: need to fill/click on a school
#     * CantOpenFile
#     * CantGetConstants: can't read the Constants file
#     * Croak: generic error utility
#     * FileNotFound
#     * NotEnoughNumbers: used when assigning numbers
#     * PrintErrorMessage
#     * RegistrationIsClosed: can't register unless it's open
#     * RegistrationStillOpen: can't assign numbers unless closed
#     * TBA_Overspecification: can't click on TBA and specify fields

# The exact error message is constructed for us and passed in as $_[0].
sub AlreadyRegistered {
  General::log("Error::AlreadyRegistered");
  select(STDOUT);
  print "<HTML><HEAD><TITLE> ".Constants::get(ERROR_TITLE).
    " </TITLE></HEAD>\n";
  print Constants::get(BODY_TAG)."\n";
  print "<h1 align=center> ".Constants::get(ERROR_TITLE)." </h1>\n";
  print Constants::get(ERROR_MSG8)."<p>\n";
  print $_[0]."<p>\n";
  General::PrintHTMLTail();
  exit(1);
}

sub BadEmailAddress {
  my $msg=$_[0];

  General::log("Error::BadEmailAddress...");
  select(STDOUT);
  print "<HTML>\n";
  print "<HEAD><TITLE> OpenImpetus ".Constants::get(ERROR_TITLE).
    " </TITLE></HEAD>\n";
  print Constants::get(BODY_TAG)."\n";
  print "<h1 align=center> ".Constants::get(ERROR_TITLE)." </h1>\n";
  print Constants::get(ERROR_MSG5)." '".$msg."'<p>\n";
  General::PrintHTMLTail();
  exit(1);
}

sub BadNameSpecification {
  my $msg=$_[0];

  General::log("Error::BadNameSpecification...");
  select(STDOUT);
  print "<HTML>\n";
  print "<HEAD><TITLE> OpenImpetus ".Constants::get(ERROR_TITLE).
    " </TITLE></HEAD>\n";
  print Constants::get(BODY_TAG)."\n";
  print "<h1 align=center> ".Constants::get(ERROR_TITLE)." </h1>\n";
  print Constants::get(ERROR_MSG6)." '".$msg."'<p>\n";
  print Constants::get(ERROR_MSG27)."<p>\n";
  General::PrintHTMLTail();
  exit(1);
}

sub BlankNameSpecification {
  my $fname=$_[0];

  General::log("Error::BlankNameSpecification...");
  select(STDOUT);
  print "<HTML>\n";
  print "<HEAD><TITLE> OpenImpetus ".Constants::get(ERROR_TITLE).
    " </TITLE></HEAD>\n";
  print Constants::get(BODY_TAG)."\n";
  print "<h1 align=center> ".Constants::get(ERROR_TITLE)." </h1>\n";
  print Constants::get(ERROR_MSG29)."<p>\n";
  if ($fname) {
    print Constants::get(ERROR_MSG30)."<p>\n";
  } else {
    print Constants::get(ERROR_MSG31)."<p>\n";
  }
  General::PrintHTMLTail();
  exit(1);
}

sub BlankSchoolSpecification {
  General::log("Error::BadNameSpecification...");
  select(STDOUT);
  print "<HTML>\n";
  print "<HEAD><TITLE> OpenImpetus ".Constants::get(ERROR_TITLE).
    " </TITLE></HEAD>\n";
  print Constants::get(BODY_TAG)."\n";
  print "<h1 align=center> ".Constants::get(ERROR_TITLE)." </h1>\n";
  print Constants::get(ERROR_MSG26)."<p>\n";
  General::PrintHTMLTail();
  exit(1);
}


sub CantOpenFile {
  my $msg;

  $msg=$_[0];

  select(STDOUT);
  General::log("Error::CantOpenFile: $msg");
  print "<HTML>\n";
  print "<HEAD><TITLE> OpenImpetus ".Constants::get(ERROR_TITLE).
    " </TITLE></HEAD>\n";
  print Constants::get(BODY_TAG)."\n";
  print "<h1 align=center> ".Constants::get(ERROR_TITLE)." </h1>\n";
  print Constants::get(ERROR_MSG24).": '".$msg."'<p>\n";
  General::PrintHTMLTail();
  exit(1);
}

sub CantGetConstants {
  my $path;

  $path=$_[0];

  select(STDOUT);
  General::log("Error::CantGetConstants: $path");
  print "<HTML>\n";
  print "<HEAD><TITLE> OpenImpetus Error </TITLE></HEAD>\n";
  print "<BODY>\n";
  print "<h1 align=center> OpenImpetus Error </h1>\n";
  print "Can't open the Constants file: '".$path."'<p>\n";
  General::PrintHTMLTail();
  exit(1);
}

# Generic failure message.
sub Croak {
  my $msg=$_[0];

  General::log("Error::Croak: $msg");
  select(STDOUT);
  print "<HTML>\n";
  print "<HEAD><TITLE> OpenImpetus ".Constants::get(ERROR_TITLE).
    " </TITLE></HEAD>\n";
  print Constants::get(BODY_TAG)."\n";
  print "<h1 align=center> ".Constants::get(ERROR_TITLE)." </h1>\n";
  print Constants::get(ERROR_MSG22).": '".$msg."'<p>\n";
  General::PrintHTMLTail();
  exit(2);
}

sub FileNotFound {
  my $msg=$_[0];
  General::log("Error::FileNotFound: $msg");
  select(STDOUT);
  print "<HTML>\n";
  print "<HEAD><TITLE> OpenImpetus ".Constants::get(ERROR_TITLE).
    " </TITLE></HEAD>\n";
  print Constants::get(BODY_TAG)."\n";
  print "<h1 align=center> ".Constants::get(ERROR_TITLE)." </h1>\n";
  print Constants::get(ERROR_MSG23).": '".$msg."'<p>\n";
  General::PrintHTMLTail();
  exit(1);
}

sub NotEnoughNumbers {
  General::log("Error::NotEnoughNumbers");
  select(STDOUT);
  print "<HTML>\n";
  print "<HEAD><TITLE> OpenImpetus ".Constants::get(ERROR_TITLE).
    " </TITLE></HEAD>\n";
  print Constants::get(BODY_TAG)."\n";
  print "<h1 align=center> ".Constants::get(ERROR_TITLE)." </h1>\n";
  print "Not enough numbers.\n";
  General::PrintHTMLTail();
  exit(1);
}

sub PrintErrorMessage {
  General::log("Error::PrintErrorMessage");
  select(STDOUT);
  print "<HTML><HEAD><TITLE> ".Constants::get(ERROR_TITLE).
    " </TITLE></HEAD>\n";
  print Constants::get(BODY_TAG)."\n";
  print "<h1 align=center> ".Constants::get(ERROR_TITLE)." </h1>\n";
  print $_[0]."<p>\n";
  General::PrintHTMLTail();
  exit(1);
}

sub RegistrationIsClosed {
  General::log("Error::RegistrationIsClosed");
  select(STDOUT);
  print "<HTML><HEAD><TITLE> ".Constants::get(ERROR_TITLE).
    " </TITLE></HEAD>\n";
  print Constants::get(BODY_TAG)."\n";
  print "<h1 align=center> ".Constants::get(ERROR_TITLE)." </h1>\n";
  print Constants::get(ERROR_MSG28)."<p>\n";
  print $_[0]."<p>\n";
  General::PrintHTMLTail();
  exit(1);
}

sub RegistrationStillOpen {
  General::log("Error::RegistrationStillOpen");
  select(STDOUT);
  print "<HTML><HEAD><TITLE> ".Constants::get(ERROR_TITLE).
    " </TITLE></HEAD>\n";
  print Constants::get(BODY_TAG)."\n";
  print "<h1 align=center> ".Constants::get(ERROR_TITLE)." </h1>\n";
  print Constants::get(ERROR_MSG15)."<p>\n";
  print $_[0]."<p>\n";
  General::PrintHTMLTail();
  exit(1);
}

sub TBA_Overspecification {
  General::log("Error::TBA_Overspecification");
  select(STDOUT);
  print "<HTML><HEAD><TITLE> ".Constants::get(ERROR_TITLE).
    " </TITLE></HEAD>\n";
  print Constants::get(BODY_TAG)."\n";
  print "<h1 align=center> ".Constants::get(ERROR_TITLE)." </h1>\n";
  print Constants::get(ERROR_MSG25)."<p>\n";
  General::PrintHTMLTail();
  exit(1);
}

1;
