<?PHP
$_OPTIMIZATION["title"] = $lang['register']['title'];
if(isset($_SESSION["user_id"])){ Header("Location: /account"); return; }

?>

                <?PHP
                # Регистрация
				function curlRequest($url)
{
    $ch = curl_init();
    $getUrl = $url;
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLOPT_URL, $getUrl);
    curl_setopt($ch, CURLOPT_TIMEOUT, 80);
    
    $response = curl_exec($ch);
    return $response;
    
    curl_close($ch);
    
}
                $csrfCheck = $func->csrfVerify();
				$alea=rand(1,2);
				if ($alea==1){
					$a_t ='a_t';
				}
				else {
					$a_t ='b_t';
				}
                if(isset($_POST["signup"]) and $csrfCheck == TRUE){
                    $validate = GUMP::is_valid($_POST, array(
                        
                        'login1' => 'required|alpha_numeric|max_len,20|min_len,4',
                        'email1' => 'required|valid_email',
                        'password1' => 'required|max_len,20|min_len,4|alpha_numeric',
                        'repass' => 'required|max_len,20|min_len,4|alpha_numeric',
                    ));

                    if($validate === true) {
                        $captcha = $_POST["captcha"];
                        $email = $_POST["email1"];
                        $login = $_POST["login1"];
                        $password = $_POST["password1"];
                        $securePass = $func->md5Password($_POST["password1"]);
                        $repass  = $_POST["repass"];

                        if(isset($_POST['g-recaptcha-response']) ){
							
							$createGoogleUrl = 'https://www.google.com/recaptcha/api/siteverify?secret=6LeOuC8iAAAAAMVjsmhqRvgKdRJ3VxjZ5ricZz2H&response='.$_POST['g-recaptcha-response'];
		$verifyRecaptcha = curlRequest($createGoogleUrl);
		$decodeGoogleResponse = json_decode($verifyRecaptcha,true);
 
        if($decodeGoogleResponse['success'] == 1)
		{
                            
                            $ip = $func->UserIP;
                            $rules = isset($_POST["rules"]) ? true : false;
                            $time = time();
                            $referer_id = (isset($_COOKIE["i"]) AND intval($_COOKIE["i"]) > 0 AND intval($_COOKIE["i"]) < 1000000) ? intval($_COOKIE["i"]) : 1;
                            $referer_name = "";
                            if($referer_id != 1){
                                $db->Query("SELECT user FROM db_users_a WHERE id = '$referer_id' LIMIT 1");
                                if($db->NumRows() > 0){$referer_name = $db->FetchRow();}
                                else{ $referer_id = 1; $referer_name = "Admin"; }
                            }else{ $referer_id = 1; $referer_name = "Admin"; }
                            if($rules){
                                if($email !== false){
                                    if($login !== false){
                                        if($password !== false){
                                            if($password == $repass){
                                                $db->Query("SELECT COUNT(*) FROM db_users_a WHERE user = '$login'");
                                                if($db->FetchRow() == 0){
                                                    # Регаем пользователя
                                                    $db->Query("INSERT INTO db_users_a (user, email, pass, referer, referer_id, date_reg, ip) VALUES ('$login','{$email}','$securePass','$referer_name','$referer_id','$time',INET_ATON('$ip'))");
                                                    $lid = $db->LastInsert();
                                                    $db->Query("INSERT INTO db_users_b (id, user, $a_t, last_sbor) VALUES ('$lid','$login','1', '".time()."')");
                                                    # Вставляем статистику
                                                    $db->Query("UPDATE db_stats SET all_users = all_users +1 WHERE id = '1'");
                                                    # Отправляем на почту
                                                    $sender = new Isender;
                                                    $sender -> SendAfterReg($login,$email, $password);
                                                    $_SESSION["user_id"] = $lid;
                                                    $_SESSION["user"] = $login;
                                                    $_SESSION["referer_id"] = $referer_id;
                                                    Header("Location: /account");
                                                    ?></section>
                                                        <div class="clr"></div>
                                                    <?PHP
                                                    return;
                                                    }else {$showError = $lang['error_messages']['usernameInUse']; echo "<script type='text/javascript'>$(document).ready(function(){show_message('{$showError}',3,6000); }); </script>";}
                                                }else  { $showError = $lang['error_messages']['passwordMatch']; echo "<script type='text/javascript'>$(document).ready(function(){show_message('{$showError}',3,6000); }); </script>";}
                                            }else { $showError = $lang['error_messages']['emptyPassword']; echo "<script type='text/javascript'>$(document).ready(function(){show_message('{$showError}',3,6000); }); </script>";}
                                        }else { $showError = $lang['error_messages']['emptyLogin']; echo "<script type='text/javascript'>$(document).ready(function(){show_message('{$showError}',3,6000); }); </script>";}
                                    }else { $showError = $lang['error_messages']['emailInvalid']; echo "<script type='text/javascript'>$(document).ready(function(){show_message('{$showError}',3,6000); }); </script>";}
                                }else { $showError = $lang['error_messages']['tosConfirm']; echo "<script type='text/javascript'>$(document).ready(function(){show_message('{$showError}',3,6000); }); </script>";}
		}else {
			$showError = 'Invalid Captcha'; echo "<script type='text/javascript'>$(document).ready(function(){show_message('{$showError}',3,6000); }); </script>";
			
		}


		   }else {$showError = $lang['error_messages']['captcha']; echo "<script type='text/javascript'>$(document).ready(function(){show_message('{$showError}',3,6000); }); </script>";}
                    }else{
                        $showError = $lang['error_messages']['invalidData']; echo "<script type='text/javascript'>$(document).ready(function(){show_message('{$showError}',3,6000); }); </script>";
                    }
                }
                ?>
                

<script src="https://www.google.com/recaptcha/api.js" async defer></script> 

   <section class="main races">
    <div class="wrapper-constrained">
        <div class="content-wrapper flex">
            <div class="perfpage doublewindow">
                <input type="hidden" id="sdd24" dKey="17">
                <input type="hidden" id="sdd48" dKey="23">
                <!--<div class="pinfo2">
                    <div class="picon"></div>
                    <div class="pcont">
                        Never register multiple accounts! The system quickly detects them and they will be blocked! <br/><br/>Please follow the rules of the game.                    </div>
                </div>-->
                <div class="content-a">
                	<div class="container elven">
	                    <div class="decor big"></div>
	                    <h3><span>Authorization</span></h3>
	                    <div class="container-inner">
	                        <h2>You can Login if you are already registered.</h2>
	                        <form action="/account" method="post">
		                        <div class="form-login">
		                        	<div class="fcell-l">
		                        		<img src="/images/character_elf_min.png" />
		                        	</div>
		                        	<div class="fcell-r">
		                        		<img src="/images/character_human_min.png" />
		                        	</div>
		                        	<div class="fcell-m">
		                        		<div class="form-row">
	                                        <label for="plogin">Your Email</label>
	                                        <input name="email" type="text" placeholder="Email">
	                                    </div>
	                                    <div class="form-row">
	                                    	<label for="ppass">Your password</label>
	                                        <input name="password" type="password" placeholder="Your password">
	                                    </div>
                                       
		                        	</div>
		                        	<div class="form-row">
                                        <button type="submit" class="btn big-button">Log In</button>
                                    </div>
                                    <div class="form-row">
                                        <p><small><b><a href="">Forgot your password?</a></b></small></p>
                                    </div>
		                        </div>
		                    </form>
	                        
	                    </div>
	                    <div class="decor middle"></div>
	                    <div class="decor left"></div>
	                    <div class="decor right"></div>
	                </div>
                </div>
				<div class="pc-message elven" id="msgw1">								
	        <div class="msg-type sm-success"></div>
	        <div class="content">Simple Text Message</div> 
	        <div class="decor middle"></div>
            <div class="decor left"></div>
            <div class="decor right"></div>
	    </div>           
                <div class="content-b">
                	<div class="container elven rcontenta" rcl1="4">
	                    <div class="decor"></div>
	                    <h3><span>Registration</span></h3>
	                    <div class="container-inner">
                            <form method="post" id="reg_form">
                                <h2>First Time Cash Empire?</h2>
                                <h4>Register and start Making Real Money! It`s absolutely Free. Also you`ll get one building  as a gift!</h4>
                                <div class="form-reg">
                                    
                                    <div class="form-row">
                                        <label for="email">Your Email <span class="st-red">*</span>&nbsp;<small class="st-red">Please, enter your real Email for your safety</small></label>
                                        <input type="text" name="email1" placeholder="" />
                                    </div>
                                    <div class="form-row">
                                        <label for="email">Your username <span class="st-red">*</span>&nbsp;<small class="st-red">Only letters and numbers are accepted </small></label>
                                        <input type="text" name="login1" placeholder="Username" />
                                    </div>
                                    <div class="form-row">
                                        <label for="pass">Your password <span class="st-red">*</span></label>
                                        <input type="password" name="password1" placeholder="Your password" />
                                    </div>
                                    <div class="form-row">
                                        <label for="pass2">Confirm password <span class="st-red">*</span></label>
                                        <input type="password" name="repass" placeholder="" />
                                    </div>
                                    

                                    <div class="form-row">
                                        <label>I confirm that I am 18 years old                                        <div class="checker">
                                            <input type="checkbox" name="age" />
                                        </div>
                                        </label>
                                    </div>
                                    <div class="form-row">
                                        <label>I agree to the  <a href="/rules" target="_blank">Terms of Service</a>
                                        <div class="checker">
                                            <input type="checkbox" name="rules" value="1" />
                                        </div>
                                        </label>
                                    </div>
                                    <div class="form-row st-center">
                                         
                        
						
						            <div class="g-recaptcha" data-sitekey="6LeOuC8iAAAAAIPcOPPZs66PjazEap9-uLJgTvPQ"></div>
                                                      
										</div>
                                    
                                    <div class="form-row st-center">
                                        <button id="register_btn" name="signup" type="submit" class="btn big-button">Register</button>
                                    </div>
                                </div>
                            </form>
	                    </div>
	                    <div class="decor middle"></div>
	                    <div class="decor left"></div>
	                    <div class="decor right"></div>
	                </div>
                </div>
            </div>
        </div>
    </div>


</section>
    <div class="superhero_info_min">
        <div class="info_text">
            <b>Never register multiple accounts! The system quickly detects them and they will be blocked! <br/><br/>Please follow the rules of the game.</b>
        </div>
        <div id="cboxClose" class="close_btn"></div>
    </div>
        
    <script>
        setTimeout(function() {
            $('.superhero_info_min').addClass('slideLeft');
        },5000);
        $('.superhero_info_min .close_btn').on('click', function() {
            $('.superhero_info_min').removeClass('slideLeft');
            $('.superhero_info_min').css('visibility','hidden');
        });
        setTimeout(function(){var rd=$('.rcontenta').attr('rcl1'); var d32=parseInt($('#sdd24').attr('dKey') - parseInt(rd)); var d64=parseInt($('#sdd48').attr('dKey') - parseInt(rd));  $('.ans_a1').html(d32);$('.ans_b1').html(d64)},3000);
        
    </script> 
