<?php
require('../setClassPath.php');
require_once('ui/Component.php');
require_once('util/Util.php');

$edit = ($_GET['edit'] == '1');
$mf = 'u';
if ($_GET['gg'] == '7')
    $mf = 'm';
else if ($_GET['gg'] == '5')
    $mf = 'f';

session_start();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Create an Account</title>
<link type="text/css" rel="stylesheet" href="/css/main.css">
<link type="text/css" rel="stylesheet" href="/css/join.css">
</head>
<body>
<div id="body">
<div id="widetop">
  <h1>Create an Account</h1>

<?php
if (!$edit)
    echo '<p class="lg">Please complete the form below to create your account at Would I Date You.  Once you have an account, you\'ll be able to create your compatability quiz! This site is <b>100% free</b> to use, now and always. And your privacy is protected.<br><br>All fields are required except your picture.</p>';
else {
    echo '<p class="lg">Please correct the following errors!</p><ul>';
    $name       = $_SESSION['tmpName'];
    $logdata = '';
    if (strlen($name) < 3) {
        echo '<li>The name you enter must be at least three characters long.</li>';
        $logdata .= '|name '. $name .' short';
    }
    if (!Util::validateAlphaNumeric($name)) {
        echo '<li>The name you enter must contain only letters, numbers, spaces, dashes or periods.</li>';
        $logdata .= '|name '. $name .' invalid';
    }
    if ($_SESSION['tmpNameTaken']) {
        echo '<li>The name you requested is already taken.</li>';
        $logdata .= '|name '. $name .' taken';
    }
    $first      = $_SESSION['tmpFirst'];
    if (strlen($first) < 2) {
        echo '<li>Your real first name must be at least two characters long.</li>';
        $logdata .= '|first '. $first .' short';
    }
    if (!Util::validateAlphaNumeric($first)) {
        echo '<li>Your real first name must contain only letters, numbers, spaces, dashes or periods.</li>';
        $logdata .= '|first '. $first .' invalid';
    }
    $password   = $_SESSION['tmpPassword'];
    if (strlen($password) < 6) {
        echo '<li>Your password must be lat least six characters long.</li>';
        $logdata .= '|pw '. $password .' short';
    }
    $email      = $_SESSION['tmpEmail'];
    if (!Util::validateEmailAddr($email)) { 
        echo '<li>The email address you entered doesn\'t appear to be valid.</li>';
        $logdata .= '|email '. $email .' invalid';
    }
    $email2  = $_SESSION['tmpEmail2'];
    if ($email != $email2) {
        echo '<li>Both email fields have to match. See, this is why we ask for it twice!</li>';
        $logdata .= '|emails dont match';
    }
    $zipcode    = $_SESSION['tmpZipcode'];
    $locationId = $_SESSION['tmpLocation'];
    if (intval($locationId) < 1) {
        echo '<li>We could not identify that zip code. Please correct it or choose one nearby.</li>';
        $logdata .= '|zip '. $zipcode .' not found';
    }
    $gender     = $_SESSION['tmpGender'];
    if ($gender != 'M' && $gender != 'F') {
        echo '<li>Please select either male or female.</li>';
        $logdata .= '|select gender';
    }
    $birthday   = $_SESSION['tmpBirthday'];
    if (!Util::validateDateFormat($birthday)) {
        echo '<li>Please correct the date formatting of your birthday.</li>';
        $logdata .= '|bday '. $birthday .' invalid';
    }
    echo '</ul>';
}
?>
</div>

<!--<img src="/i/couple2b.jpg" alt="Happy Couple" id="joincouple">-->
<div style="float: left; font-size: 0.8em; padding: 5px; width: 140px; margin: 0 10px 0 0; border: 1px solid #000; text-align: center; background-color: #bcd8ee;">
  <b>Recently-Joined Members</b><br><br>
<?php
if ($mf == 'u') {
    if (rand(0, 99) < 50) {
?>
  <span style="font-size: 1.2em">Nessa</span><br>
  <img src="/pic/080329/18/e0e.jpg" alt="member Nessa" style="border: 1px solid #000;"><br>
  21f - Escanaba, MI<br><br>
<?php
    }
    else {
?>
  <span style="font-size: 1.2em">XxxVianaxxX</span><br>
  <img src="/pic/080330/29/40b.bmp" alt="member XxxVianaxxX" style="border: 1px solid #000;"><br>
  22f - Naples, FL<br><br>
<?php
    }
    if (rand(0, 99) < 50) {
?>
  <span style="font-size: 1.2em">usaf86</span><br>
  <img src="/pic/080329/16/708.jpg" alt="member usaf86" style="border: 1px solid #000;"><br>
  21m - Killeen, TX<br><br>
<?php
    }
    else {
?>
  <span style="font-size: 1.2em">Snipehunter</span><br>
  <img src="/pic/080403/67/23f.jpg" alt="member Snipehunter" style="border: 1px solid #000;"><br>
  22m - Portland, OR<br><br>
<?php
    }
}
else if ($mf == 'm') {
?>
  <span style="font-size: 1.2em">coco jnell</span><br>
  <img src="/pic/080331/39/d4f.jpg" alt="member coco jnell" style="border: 1px solid #000;"><br>
  35f - Torrance, CA<br><br>

  <span style="font-size: 1.2em">Jean</span><br>
  <img src="/pic/080402/63/e5d.jpg" alt="member Jean" style="border: 1px solid #000;"><br>
  23f - Phoenix, AZ<br><br>
<?php
}
else {
?>
  <span style="font-size: 1.2em">usaf86</span><br>
  <img src="/pic/080329/16/708.jpg" alt="member usaf86" style="border: 1px solid #000;"><br>
  21m - Killeen, TX<br><br>

  <span style="font-size: 1.2em">Snipehunter</span><br>
  <img src="/pic/080403/67/23f.jpg" alt="member Snipehunter" style="border: 1px solid #000;"><br>
  22m - Portland, OR<br><br>
<?php
}
?>

  Complete your registration to interact with our growing membership!
</div>

<form action="join1_update.html" method="post" enctype="multipart/form-data" id="join" style="float: right;">
  <div class="fline">
    <label for="name">Enter a name for yourself:</label><input type="text" name="name" size="20" maxlength="25" value="<?= (isset($name) ? htmlentities($name, ENT_COMPAT) : $_SESSION['myName']) ?>">
  </div>
  <div class="fline">
    <label for="first">What is your <i>real</i> first name?</label><input type="text" name="first" size="20" maxlength="20" value="<?= htmlentities($first, ENT_COMPAT) ?>">
  </div>
  <div class="fline">
    <label for="password">Enter a password:</label><input type="password" name="password" size="20" maxlength="25" value="<?= htmlentities($password, ENT_COMPAT) ?>">
  </div>
  <div class="fline">
    <label for="email">What is your email address?</label><input type="text" name="email" size="30" maxlength="80" value="<?= htmlentities($email, ENT_COMPAT) ?>">
  </div>
  <div class="fline">
    <label for="email2">Re-enter email address:</label><input type="text" name="email2" size="20" maxlength="25" value="<?= htmlentities($email2, ENT_COMPAT) ?>">
  </div>
  <div class="fline">
    <label for="zipcode">Enter your zip code:</label><input type="text" name="zipcode" size="5" maxlength="5" style="width: 80px;" value="<?= htmlentities($zipcode, ENT_COMPAT) ?>">
  </div>
  <div class="fline">
    <label for="gender">Are you male or female?</label><input type="radio" name="gender" value="M" class="rad"<?= ($gender == 'M' ? ' checked' : '') ?>> Male <input type="radio" name="gender" value="F" class="rad"<?= ($gender == 'F' ? ' checked' : '') ?>> female
  </div>
  <div class="fline">
    <label for="birthday">Enter your birthday:</label><input type="text" name="birthday" size="8" maxlength="10" style="width: 120px;" value="<?= htmlentities($birthday, ENT_COMPAT) ?>"> <span class="dtfmt">MM/DD/YYYY</span>
  </div>
  <div class="fline">
    <label for="mypic">Upload a pic of yourself:</label><input type="file" name="mypic" size="30" class="fi">
  </div>
  <div class="fline">
    <input type="submit" value="Create Account" class="btn">
  </div>
</form>

<?php
$ui = Component::getInstance();
$ui->drawHeader($_SESSION['user']);
$ui->drawFooter($logdata);
?>
</div>
</body>
</html>
