<?php
/*
    Template Name: Signup Page
*/
?>
<?php get_header();?>
            <div id="main">
            	<div id="fullContent">
					<div class="singlePost">
                    	<?php if(have_posts()) : while(have_posts()) : the_post('');?>
                    	<div class="article mainBorder">
                        	<div class="articleDetails">
                            	<div class="articleTitle">
                                    <h1><?php the_title(); ?></h1>
                                </div><!--End articleTitle-->
                            </div><!--End Article Details-->
                            <div class="articleContent">
                            	<?php the_content(); ?>
                            </div><!--End ArticleContent-->
                            <div class="singuppage">
                                <?php
								
								/* Load registration file. */
								require_once( ABSPATH . WPINC . '/registration.php' );
								
								/* Check if users can register. */
								$registration = get_option( 'users_can_register' );
								
								/* If user registered, input info. */
								if ( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) && $_POST['action'] == 'adduser' ) {
									$user_pass = wp_generate_password();
									$userdata = array(
										'user_pass' => $user_pass,
										'user_login' => esc_attr( $_POST['user_name'] ),
										'first_name' => esc_attr( $_POST['first_name'] ),
										'last_name' => esc_attr( $_POST['last_name'] ),
										'nickname' => esc_attr( $_POST['nickname'] ),
										'user_email' => esc_attr( $_POST['email'] ),
										'user_url' => esc_attr( $_POST['website'] ),
										'aim' => esc_attr( $_POST['aim'] ),
										'yim' => esc_attr( $_POST['yim'] ),
										'jabber' => esc_attr( $_POST['jabber'] ),
										'description' => esc_attr( $_POST['description'] ),
										'role' => get_option( 'default_role' ),
									);
									
									if ( !$userdata['user_login'] )
										$error = __('A username is required for registration.', 'lioit');
									elseif ( username_exists($userdata['user_login']) )
										$error = __('Sorry, that username already exists!', 'lioit');
									
									elseif ( !is_email($userdata['user_email'], true) )
										$error = __('You must enter a valid email address.', 'lioit');
									elseif ( email_exists($userdata['user_email']) )
										$error = __('Sorry, that email address is already used!', 'lioit');
									
									else{
										$new_user = wp_insert_user( $userdata );
										wp_new_user_notification($new_user, $user_pass);
										
										update_user_meta( $new_user, 'twitter', esc_attr( $_POST['twitter']  ) );
										update_user_meta( $new_user, 'google',   esc_attr( $_POST['google']    ) );
										update_user_meta( $new_user, 'pinterest',           $_POST['pinterest']    );
										update_user_meta( $new_user, 'facebook',   esc_attr( $_POST['facebook']    ) );
										update_user_meta( $new_user, 'linkedin',           $_POST['linkedin']    );
										update_user_meta( $new_user, 'flickr',   esc_attr( $_POST['flickr']    ) );
										update_user_meta( $new_user, 'youtube',   esc_attr( $_POST['youtube']    ) );
									}
								
								}
								 
								
								 
								   
								   
								
								   
								
								?>
								
						
										<?php if ( is_user_logged_in() && !current_user_can( 'create_users' ) ) : ?>
								
											<div class="sidebox">
                                            <h3>Welcome, <?php echo $user_identity; ?></h3>
                                            <div class="usericon">
                                                <?php global $userdata; get_currentuserinfo(); echo get_avatar($userdata->ID, 60); ?>
                                    
                                            </div>
                                            <div class="userinfo">
                                               <p class="log-in-out alert">
												<?php printf( __('You are logged in as <a href="%1$s" title="%2$s">%2$s</a>.  You don\'t need another account.', 'lioit'), get_author_posts_url( $curauth->ID ), $user_identity ); ?> <a href="<?php echo wp_logout_url( get_permalink() ); ?>" title="<?php _e('Log out of this account', 'lioit'); ?>"><?php _e('Logout &raquo;', 'lioit'); ?></a>
                                                </p><!-- .log-in-out .alert -->
                                            </div>
                                        </div>
								
										
											<?php elseif ( $new_user ) : ?>					
                                            <p class="alert">
											<?php
                                                if ( current_user_can( 'create_users' ) )
                                                    printf( __('A user account for %1$s has been created.', 'lioit'), $_POST['user-name'] );
                                                else 
                                                    printf( __('Thank you for registering, %1$s.', 'lioit'), $_POST['user-name'] );
                                                    printf( __('<br/>Please check your email address. That\'s where you\'ll recieve your login password.<br/> (It might go into your spam folder)', 'lioit') );
                                            ?>
                                            </p><!-- .alert -->
                                
                                        <?php else : ?>
                                
                                            <?php if ( $error ) : ?>
                                                <p class="error">
                                                    <?php echo $error; ?>
                                                </p><!-- .error -->
                                            <?php endif; ?>
                                
                                            <?php if ( current_user_can( 'create_users' ) && $registration ) : ?>
                                                <p class="alert">
                                                    <?php _e('Users can register themselves or you can manually create users here.', 'lioit'); ?>
                                                </p><!-- .alert -->
                                            <?php elseif ( current_user_can( 'create_users' ) ) : ?>
                                                <p class="alert">
                                                    <?php _e('Users cannot currently register themselves, but you can manually create users here.', 'lioit'); ?>
                                                </p><!-- .alert -->
                                            <?php endif; ?>
                                
                                            <?php if ( $registration || current_user_can( 'create_users' ) ) : ?>
                                
                                            <form method="post" id="adduser" class="user-forms" action="http://<?php echo $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; ?>">
											
											
												<strong>Name</strong>
												
												<p class="form-username">
													<label for="user_name"><?php _e('Username *', 'lioit'); ?></label>
													<input class="text-input" name="user_name" type="text" id="user_name" value="<?php if ( $error ) echo esc_html( $_POST['user_name'], 1 ); ?>" />
												</p><!-- .form-username -->
												
												<p class="first_name">
													<label for="first_name"><?php _e('First Name', 'lioit'); ?></label>
													<input class="text-input" name="first_name" type="text" id="first_name" value="<?php if ( $error ) echo esc_html( $_POST['first_name'], 1 ); ?>" />
												</p><!-- .first_name -->
												
												<p class="last_name">
													<label for="last_name"><?php _e('Latst Name', 'lioit'); ?></label>
													<input class="text-input" name="last_name" type="text" id="last_name" value="<?php if ( $error ) echo esc_html( $_POST['last_name'], 1 ); ?>" />
												</p><!-- .last_name -->
												
												<p class="nickname">
													<label for="nickname"><?php _e('Nickname', 'lioit'); ?></label>
													<input class="text-input" name="nickname" type="text" id="nickname" value="<?php if ( $error ) echo esc_html( $_POST['nickname'], 1 ); ?>" />
												</p><!-- .nickname -->
												
												<strong>Contact Info</strong>
												
												<p class="form-email">
                                                    <label for="email"><?php _e('E-mail (required)', 'lioit'); ?></label>
                                                    <input class="text-input" name="email" type="text" id="email" value="<?php if ( $error ) echo esc_html( $_POST['email'], 1 ); ?>" />
                                                </p><!-- .form-email -->
                                                
                                                <p class="form-website">
                                                    <label for="website"><?php _e('Website', 'lioit'); ?></label>
                                                    <input class="text-input" name="website" type="text" id="website" value="<?php if ( $error ) echo esc_html( $_POST['website'], 1 ); ?>" />
                                                </p><!-- .form-website -->
												
												<p class="form-aim">
													<label for="aim"><?php _e('AIM', 'lioit'); ?></label>
													<input class="text-input" name="aim" type="text" id="aim" value="<?php if ( $error ) echo esc_html( $_POST['aim'], 1 ); ?>" />
												</p><!-- .form-aim -->
												
												<p class="form-yim">
													<label for="yim"><?php _e('Yahoo IM', 'lioit'); ?></label>
													<input class="text-input" name="yim" type="text" id="yim" value="<?php if ( $error ) echo esc_html( $_POST['yim'], 1 ); ?>" />
												</p><!-- .form-yim -->
												
												<p class="form-jabber">
													<label for="jabber"><?php _e('Jabber / Google Talk', 'lioit'); ?></label>
													<input class="text-input" name="jabber" type="text" id="jabber" value="<?php if ( $error ) echo esc_html( $_POST['jabber'], 1 ); ?>" />
												</p><!-- .form-jabber -->
												
												<strong>About Yourself</strong>
												
												<p class="form-description">
                                                    <label for="description"><?php _e('Biographical Info', 'lioit'); ?></label>
                                                    <textarea class="text-input" name="description" id="description" rows="5" cols="30"><?php if ( $error ) echo esc_html( $_POST['description'], 1 ); ?></textarea>
                                                </p><!-- .form-description -->
												
												<strong>Social Networks</strong>
												
												<p class="form-twitter">
													<label for="twitter"><?php _e('Twitter Url', 'lioit'); ?></label>
													<input class="text-input" name="twitter" type="text" id="twitter" value="<?php if ( $error ) echo esc_html( $_POST['twitter'], 1 ); ?>" />
												</p><!-- .form-twitter -->
                                                <p class="form-google">
													<label for="google"><?php _e('Google + URL', 'lioit'); ?></label>
													<input class="text-input" name="google" type="text" id="google" value="<?php if ( $error ) echo esc_html( $_POST['google'], 1 ); ?>" />
												</p><!-- .form-twitter -->
                                                <p class="form-facebook">
													<label for="facebook"><?php _e('FaceBook URL', 'lioit'); ?></label>
													<input class="text-input" name="facebook" type="text" id="facebook" value="<?php if ( $error ) echo esc_html( $_POST['facebook'], 1 ); ?>" />
												</p><!-- .form-twitter -->
                                                <p class="form-linkedin">
													<label for="linkedin"><?php _e('linkedIn URL', 'lioit'); ?></label>
													<input class="text-input" name="linkedin" type="text" id="linkedin" value="<?php if ( $error ) echo esc_html( $_POST['linkedin'], 1 ); ?>" />
												</p><!-- .form-twitter -->
                                                <p class="form-flickr">
													<label for="flickr"><?php _e('Flickr URL', 'lioit'); ?></label>
													<input class="text-input" name="flickr" type="text" id="flickr" value="<?php if ( $error ) echo esc_html( $_POST['flickr'], 1 ); ?>" />
												</p><!-- .form-twitter -->
                                                <p class="form-youtube">
													<label for="youtube"><?php _e('YouTube URL', 'lioit'); ?></label>
													<input class="text-input" name="youtube" type="text" id="youtube" value="<?php if ( $error ) echo esc_html( $_POST['youtube'], 1 ); ?>" />
												</p><!-- .form-twitter -->
                                                <p class="form-pinterest">
													<label for="pinterest"><?php _e('Pinterest URL', 'lioit'); ?></label>
													<input class="text-input" name="pinterest" type="text" id="pinterest" value="<?php if ( $error ) echo esc_html( $_POST['pinterest'], 1 ); ?>" />
												</p><!-- .form-twitter -->
												
												
												
												
												
											
								
												<p class="form-submit">
													<?php echo $referer; ?>
                                                    <input name="adduser" type="submit" id="addusersub" class="submit button btnMainColor" value="<?php if ( current_user_can( 'create_users' ) ) _e('Add User', 'lioit'); else _e('Register', 'lioit'); ?>" />
                                                    <?php wp_nonce_field( 'add-user' ) ?>
                                                    <input name="action" type="hidden" id="action" value="adduser" />
                                                </p><!-- .form-submit -->
								
											</form><!-- #adduser -->
								
											<?php endif; ?>
								
										<?php endif; ?>
											
								
								
								
								
								
								</div>
                        </div><!--End article-->
                        <?php comments_template('', true); ?>
                        <?php endwhile; ?>
						<?php  else:  ?>
                        <?php  endif; ?>
                    </div><!--End ContentBox-->
                </div><!--End Main Content-->
            </div><!--End Main-->
            <?php require Lioit_TM . '/lio.php';?>
        </div><!--End Content-->
<?php get_footer();?>