<?
include('../Code/confHeader.inc');
$Conf -> connect();
//
// In all cases, we need to look up the account information
// to determine if the user is registered.
//
if ( IsSet($firstEmail) ) {
  $Me -> lookupByEmail($firstEmail, $Conf);
} else {
  $Me -> invalidate();
}
?>

<html>

<? $Conf->header("Account Regisration") ?>

<body>

<? if ($Me -> valid() ) {
  $Conf->errorMsg(
		  "That email address ($firstEmail) is already registered. "
		  . "If you've forgotten your password, <a href=\"login.php\"> return "
		  . "to the login form </a> and request that your password be sent "
		  . "to you. Otherwise, double-check your email address and use another account.");
  //
  // Don't leave them registered as the other person..
  //
  $Me -> invalidate();
} else if ($firstEmail != $secondEmail) {
  $Conf->errorMsg("The first and second email you entered do not match. "
		  . " Hit back and try again ");
  exit();
} else if (!IsSet($firstEmail) || $firstEmail == "") {
  $Conf->errorMsg("You must specify an email address. "
		  . "Please hit BACK and correct this problem");
  exit();
} else {
    //
    // Update Me
    //
    $Me -> initialize($firstName, $lastName, $firstEmail, $affiliation,
                      $street1, $street2, $city, $state, $zip, $country,
		      $phone, $fax);
    $result = $Me -> addToDB($Conf);
    //
    if (DB::isError($result)) {
      $Conf->errorMsg("There was some problem adding your account. "
		      . "The error message was " . $result->getMessage() . " "
		      . " Please try again. ");
    } else {
      $Conf->confirmMsg("An account for $firstEmail was successfully created. ");

      $Conf->infoMsg( "A piece of email containing "
		      . "the password was sent. When it is received, "
		      . "it can be used to login </a> ");

      $Me -> sendAccountInfo($Conf);

      $Conf->log("Created account", $Me);

    }
}
?>

<? $Conf->footer() ?>

</body>
</html>
