Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Register
- {
- private $dob = null,
- $day = null,
- $month = null,
- $year = null,
- $gender = 'male',
- $username = 'Guest',
- $password = null,
- $email = null,
- $secCode = null,
- $minAge = 11,
- $maxAge = 100;
- private $step = 1,
- $errorMessage = null,
- $currentPage = null,
- $bgClass = null;
- public function __construct()
- {
- global $Smarty;
- $this->currentPage = $_GET['page'];
- $this->_setData();
- $this->_findValidPage();
- if( $_POST )
- {
- $this->_processData();
- }
- $Smarty->assign('step', $this->grabData('step') );
- $Smarty->assign('bodyClass', $this->grabData('bgClass') );
- $Smarty->assign('error', $this->grabData('errorMessage') );
- }
- public function grabSession( $key )
- {
- return ($_SESSION[$key] ? $_SESSION[$key] : false);
- }
- public function setSession( $key, $value = '' )
- {
- $_SESSION[$key] = $value;
- }
- public function grabData( $key, $value = '' )
- {
- if( $value )
- {
- $this->$key = $value;
- return $value;
- }
- else
- {
- return $this->$key ? $this->$key : false;
- }
- }
- private function _setData()
- {
- if( $_SESSION )
- {
- foreach( $_SESSION as $key => $value )
- {
- $this->$key = $value;
- }
- }
- if( $_POST )
- {
- foreach( $_POST as $key => $value )
- {
- $key = str_replace('bean_', '', $key);
- $this->$key = $value;
- }
- }
- }
- private function _findValidPage( )
- {
- switch( $this->grabSession('step') )
- {
- default:
- $this->setSession('step', 1);
- $this->redirect();
- break;
- case 1:
- if( $this->currentPage != 'start' )
- {
- if( !$this->grabData('dob') || $this->grabData('bean_gender') )
- {
- $this->redirect();
- }
- }
- $this->grabData('bgClass', 'background-agegate');
- $this->grabData('template', 'start');
- break;
- case 2:
- if( $this->currentPage != 'email_password' )
- {
- if( !$this->grabData('email') || !$this->grabData('password') )
- {
- $this->redirect('email_password');
- }
- }
- $this->grabData('bgClass', 'background-accountdetails-'.$this->grabData('gender') );
- $this->grabData('template', 'email_password');
- break;
- }
- }
- private function redirect( $pageName = 'start' )
- {
- header('Location: /quickregister/' . $pageName );
- }
- private function _processData()
- {
- switch( $this->grabData('step') )
- {
- case 1:
- if( $this->gender != 'male' )
- {
- $this->gender = 'female';
- }
- else
- {
- $this->gender = 'male';
- }
- $this->setSession('gender', $this->gender);
- foreach( array ( 'day', 'month', 'year' ) as $check )
- {
- if( $this->grabData( $check ) )
- {
- $this->dob .= $this->$check . ( $check == 'year' ?: '-' );
- }
- else
- {
- $this->errorMessage = 'Please supply a valid birthdate.';
- break;
- }
- }
- if( !$this->errorMessage ){ $this->setSession('step', 2); $this->redirect('password_email'); }
- break;
- case 2:
- if( strlen( $this->password ) >= 5 && strlen( $this->password ) <= 20 )
- {
- $this->errorMessage = '';
- }
- break;
- }
- }
- }
Add Comment
Please, Sign In to add comment