<?php
function wp_forest_do_register(){
global $wpdb, $wp_query;
		
if (!is_array($wp_query->query_vars))
$wp_query->query_vars = array();
		
header('Content-Type: '.get_bloginfo('html_type').'; charset='.get_bloginfo('charset'));
session_start();

switch($_REQUEST["action"] ) {	
case 'register':
require_once( ABSPATH . WPINC . '/registration-functions.php');

$user_login = sanitize_user( str_replace(" ","",$_POST['user_login']) );
$user_email = trim($_POST['user_email']);
			
$sanitized_user_login = $user_login;
$errors = register_new_user_themehive($user_login, $user_email);
if (!is_wp_error($errors)) 
{	
$ok_reg = 1;						
}	
									
if ( 1 == $ok_reg ) 
{//continues after the break; 
		
get_header();
?>
	
<div class="page-info">
<div class="main-container">
<div id="breadcrumbs">
<?php dimox_breadcrumbs(); ?>
</div>

<h1 class="page-title">        
<?php _e("Register",'WpForest'); ?> - <?php  bloginfo('name'); ?>  
</h1>
</div>
</div>

<div id='main_wrapper'>  
<div id="wrapper">
<div class="main-container">
<div class="left-content">	 
<div class="box_title"><?php _e('Registration Complete','WpForest') ?></div>
<p><?php printf(__('Username: %s','WpForest'), "<strong>" . wp_specialchars($user_login) . "</strong>") ?><br />
<?php printf(__('Password: %s','WpForest'), '<strong>' . __('emailed to you','WpForest') . '</strong>') ?> <br />
<?php printf(__('E-mail: %s','WpForest'), "<strong>" . wp_specialchars($user_email) . "</strong>") ?><br /><br />
<?php _e("Please check your <strong>Junk Mail</strong> if your account information does not appear within 5 minutes.",'WpForest'); ?>
</p>

<p class="submit"><a href="wp-login.php"><?php _e('Login', 'WpForest'); ?> &raquo;</a></p>
</diiv>
</div></div></div></div>
<?php
get_footer();
		
die();
break;
}//continued from the error check above
		
default:
get_header();
?>

<div class="page-info">
<div class="main-container">
<div id="breadcrumbs">
<?php dimox_breadcrumbs(); ?>
</div>
<h1 class="page-title">        
<?php _e("Register",'WpForest'); ?> - <?php bloginfo('name'); ?>  
</h1>
</div>

<div id="item-tabs">
<ul>
<li class="selected">
<div></div>
<a href="<?php echo site_url(); ?>/wp-register.php">Create Account</a>
</li>    <li class="last">
<div></div>
<a href="<?php echo site_url(); ?>/wp-login.php">Sign In</a>
<div class="last"></div></li>
</ul>
</div>
 </div>

<div id='main_wrapper'>  
<div id="wrapper">
<div class="main-container">
<div class="left-content">
<h2 class="underlined"><?php _e("Register",'WpForest'); ?></h2>
<div class="custom-form">
<?php if ( isset($errors) ) : ?>
<div class="error flash">
<ul>
<?php
foreach($errors as $error) {
if(count($error) > 0) {
							
foreach($error as $e) echo "<li>".$e[0]."</li>";
}
}
?>
</ul>
</div>
<?php endif; ?>
  
<form method="post" action="wp-register.php" id="loginform">
<input type="hidden" name="action" value="register" />	

<fieldset style="border:1px solid#fff;">
<label for="register-username"><?php _e('Username:','WpForest') ?></label>
<input type="text" class="do_input" name="user_login" id="user_login" size="30" maxlength="20" value="<?php echo wp_specialchars($user_login); ?>" />						
</fieldset>

<fieldset style="border:1px solid#fff;">					 
<label for="register-email"><?php _e('E-mail:','WpForest') ?></label>
<input type="text" class="do_input" name="user_email" id="user_email" size="30" maxlength="100" value="<?php echo wp_specialchars($user_email); ?>" />
</fieldset>

<?php do_action('register_form'); ?>

<p><label for="submitbtn">&nbsp;</label>
<?php _e('A password will be emailed to you.','WpForest') ?></p>
	
<p class="submit">
<label for="submitbtn">&nbsp;</label>
<input type="submit" class="submit_bottom" value="<?php _e('Register','WpForest') ?>" id="submit" name="submit" />
</p>
							
<label for="register-email"><?php _e('Go to:'); ?></label>
		  							         
<div class="form-submit">
<p>
<small>
  <a href="<?php echo site_url(); ?>/" title="<?php _e('Are you lost?','WpForest') ?>"><?php _e('Home','WpForest') ?></a> | 
<a href="<?php echo site_url(); ?>/wp-login.php"><?php _e('Login','WpForest') ?></a> | 
<a href="<?php echo site_url(); ?>/wp-login.php?action=lostpassword" title="<?php _e('Password Lost?','WpForest') ?>"><?php _e('Lost your password?','WpForest') ?></a>
</small>
</p>
</div> 
</div>		  
</div>
<link rel="stylesheet" type="text/css" href="<?php bloginfo('template_directory'); ?>/css/login-register-sidebar.css" media="screen" /> 
<div class="login-register-sidebar">
<h2 class="login-register-sidebar-heading">Why Sign Up?</h2>
<div class="login-register-sidebar-container-box">
<p>
It only takes a couple of minutes to create an account.
</br>
Your account will let you:
</p>

<ul class="login-register-sidebar-list">
<li>Deposit Cash &amp; Download Files</li>
<li>Have Your Own Profile Page</li>
<li>Chat on the Forums</li>
<li>Sell Your Own Work</li>
<li>Refer Members to Make Money</li>
</ul>
<br />
<p>
It's Free!
</p>  
</div></div>
</div></div></div>
<div class='clear'/>												           
<?php
get_footer();
die();
break;
case 'registration=disabled':
get_header();
?>


<div class="box_title"><?php _e('Registration Disabled','WpForest') ?></div>
                                                  
<p><?php _e('User registration is currently not allowed.','WpForest') ?><br />
<a href="<?php echo get_settings('home'); ?>/" title="<?php _e('Go back to the blog','WpForest') ?>"><?php _e('Home','WpForest') ?></a>
</p>

<?php
get_footer();
die();
break;
}
}
//===================================================================

function register_new_user_themehive( $user_login, $user_email ) {
$errors = new WP_Error();
$sanitized_user_login = sanitize_user( $user_login );
$user_email = apply_filters( 'user_registration_email', $user_email );

// Check the username
if ( $sanitized_user_login == '' ) {
$errors->add( 'empty_username', __( '<strong>ERROR</strong>: Please enter a username.', 'WpForest' ) );
} elseif ( ! validate_username( $user_login ) ) {
$errors->add( 'invalid_username', __( '<strong>ERROR</strong>: This username is invalid because it uses illegal characters. Please enter a valid username.', 'WpForest' ) );
$sanitized_user_login = '';
} elseif ( username_exists( $sanitized_user_login ) ) {
$errors->add( 'username_exists', __( '<strong>ERROR</strong>: This username is already registered, please choose another one.', 'WpForest' ) );
}

// Check the e-mail address
if ( $user_email == '' ) {
$errors->add( 'empty_email', __( '<strong>ERROR</strong>: Please type your e-mail address.', 'WpForest' ) );
} elseif ( ! is_email( $user_email ) ) {
$errors->add( 'invalid_email', __( '<strong>ERROR</strong>: The email address isn&#8217;t correct.', 'WpForest' ) );
$user_email = '';
} elseif ( email_exists( $user_email ) ) {
$errors->add( 'email_exists', __( '<strong>ERROR</strong>: This email is already registered, please choose another one.', 'WpForest' ) );
}

do_action( 'register_post', $sanitized_user_login, $user_email, $errors );

$errors = apply_filters( 'registration_errors', $errors, $sanitized_user_login, $user_email );

if ( $errors->get_error_code() )
return $errors;

$user_pass = wp_generate_password( 12, false);
$user_id = wp_create_user( $sanitized_user_login, $user_pass, $user_email );
if ( ! $user_id ) {
$errors->add( 'registerfail', sprintf( __( '<strong>ERROR</strong>: Couldn&#8217;t register you... please contact the <a href="mailto:%s">webmaster</a> !', 'WpForest' ), get_option( 'admin_email' ) ) );
return $errors;
}
if ($_COOKIE['AFFILIATE_NAME']) {
$click_id   = $_COOKIE['AFFILIATE_NAME'];
$id=jobTheme_get_userid_from_username($click_id);
$reg_dt        = date('Y-m-d h:i:s');        
global $wpdb;
$s = "insert into ".$wpdb->prefix."wpforest_aff (affiliate_id,signup,hit_dt)
values('$id','1','$reg_dt')";	
$wpdb->query($s);
}
update_user_meta( $user_id, 'credits','0' ); 
update_user_option( $user_id, 'default_password_nag', true, true ); //Set up the Password change nag.
wp_new_user_notification( $user_id, $user_pass );
return $user_id;
}
?>