<?php
/*****
join.php:
This file displays a 'registration' form and allows users to register a new user account on the site.

author: jez hancock
email: munk@munk.me.uk
date: 15/10/2002
*****/
include_once("config.php");

// Check user not logged in already:
checkLoggedIn("no");

// page title:
$title="Member Registration Page";

if(
$_POST["submit"]){
    
// info submitted, check it:
    // Check login, password and password2 are not empty:
    # field_validator($field_descr, $field_data, $field_type, $min_length="", $max_length="", $field_required=1) {
    
field_validator("login name"$_POST["login"], "alphanumeric"415);
    
field_validator("password"$_POST["password"], "string"415);
    
field_validator("confirmation password"$_POST["password2"], "string"415);
    
    
// Check that password and password2 match:
    
if(strcmp($_POST["password"], $_POST["password2"])) {
        
$messages[]="Your passwords did not match";
    }

    
// Check if login id exists already in 'users' table:
    
if(getRow("users""login"$_POST["login"])) {
        
$messages[]="Login ID \"".$_POST["login"]."\" already exists.  Try another.";
    }

    
// No errors!
    
if(empty($messages)) {
        
// registration ok, get user id and update db with new info:
        
if($_POST["login"]!="test"){
            
newUser($_POST["login"], $_POST["password"]);
        }

        
// essentially log user in:
        
cleanMemberSession($_POST["login"], $_POST["password"]);

        
// and redirect to members page:
        
header("Location: members.php?".session_name()."=".session_id());
        exit;
    }
}
?>
<html>
<head>
<title><?php print $title ?></title>
<?php doCSS()?>
</head>
<body>
<h1><?php print $title?></h1>
<?php
//Check if $message is set, and output it if it is:
!empty($messages) ? displayErrors($messages) : "";
?>
<form action="<?=$_SERVER["PHP_SELF"]?>" method="POST">
<table>
<tr><td>Login:</td><td><input type="text" name="login" value="<?php print $_POST["login"?>" maxlength="15"></td></tr>
<tr><td>Password:</td><td><input type="password" name="password" value="" maxlength="15"></td></tr>
<tr><td>Confirm password:</td><td><input type="password" name="password2" value="" maxlength="15"></td></tr>
<tr><td>&nbsp;</td><td><input name="submit" type="submit" value="Submit"></td></tr>
</table>
</form>
</body>
</html>