Location: PHPKode > projects > Kwalbum > kwalbum/pages/RegisterPage.php
<?php
/* 2.1: 2008-10-04
 * 2.0 created: 2008-08-14
 */
require_once 'include/IPage.php';

class RegisterPage implements IPage
{
	private $codeGood;
	
	function GetHead(& $title)
	{
		if (empty($_POST))
		{
			$this->codeGood = false;
			// set image verification string
			$REGcharstr = '';
			for($i = 0; $i < 6; $i++)
			{
				switch(rand(1, 2))
				{
					case 1: $REGcharstr.=chr(rand(49,57));  break; // 1-9
					case 2: default: $REGcharstr.=chr(rand(65,90));  break; // A-Z
				}
			}
			session_start();
			$_SESSION['REGcharstr'] = $REGcharstr;
			session_write_close();
		}
		else
		{
			require_once 'include/JoinValidate.php';
			$validator = new JoinValidate();
			$code = $_POST['txtCode'];
			$this->codeGood = $validator->validateAJAX($code, 'txtCode');
		}
		
		$title = 'Register';
		return '<script type="text/javascript" src="ajax/join.js"></script>';
	}

	function ShowBody()
	{
		if (USER_ID)
		{
			echo '<p class="error">You are already logged in.  Log out before registering.</p>';
			return;
		}
		global $URLP, $DB;

		$errorsExist = false;
		$created = false;
		$canLogin = false;

		$nameError = 'hidden';
		$titleError = 'hidden';
		$emailError = 'hidden';
		$pass1Error = 'hidden';
		$pass2Error = 'hidden';
		$codeError = 'hidden';
		if (empty($_POST))
		{
			$name='';
			$title='';
			$email='';
			$code='';
		}
		else
		{
			require_once 'include/JoinValidate.php';

			$name=$_POST['txtName'];
			$title=$_POST['txtTitle'];
			$email=$_POST['txtEmail'];
			$pass1 = $_POST['txtPass1'];
			$pass2 = $_POST['txtPass2'];
			$code = $_POST['txtCode'];

			// validate input
			$validator = new JoinValidate();
			if (!$validator->validateAJAX($name, 'txtName'))
			{
				$nameError = 'error';
				$errorsExist = true;
			}
			if (!$validator->validateAJAX($title, 'txtTitle'))
			{
				$titleError = 'error';
				$errorsExist = true;
			}
			if (!$validator->validateAJAX($email, 'txtEmail'))
			{
				$emailError = 'error';
				$errorsExist = true;
			}
			if (!$validator->validateAJAX($pass1, 'txtPass1'))
			{
				$pass1Error = 'error';
				$errorsExist = true;
			}
			if ($pass1 != $pass2)
			{
				$pass2Error = 'error';
				$errorsExist = true;
			}
			if (!$this->codeGood)
			{
				$codeError = 'error';
				$errorsExist = true;
			}

			if (!$errorsExist)
			{
				$date = date('Y-m-d H:i:s');

				// create user item
				$insertData = array('UserName'=>$name, 'UserTitle'=>$title, 'UserEmail'=>$email,
					'UserPassword'=>sha1($pass1));
				if (false !== $DB->Insert(USER_TABLE, $insertData))
					$created = true;
			}
		}

		if ($created)
		{
			echo 'Your account has been created successfully and you can now <a href="'.$URLP->GetExtendedURL().'p=Login">login here</a>.<br/>';
		}
		else
		{
			require 'RegisterPage.html.php';
		}
	}
}
?>
Return current item: Kwalbum