<?php
	Template::Show('login_temp_head.php');

	/* Add 4 closing div tags in the end of this page */

	/*
		<!-- END Login Form -->
    </div>
    <!-- END Login Block -->
</div>
</div>
</div>

</div>

<!-- Login Container -->

<!-- END Login Container --> */


?>
        <form class="form-horizontal form-bordered form-control-borderless" action="<?php echo url('/registration');?>" method="post">
        	<?php

        	$entrance = Config::Get('REQUIRE_ENTRANCE_EXAM');
        	if($entrance == 1) {
        		session_start();
        		$email = htmlentities($_SESSION['email']);
        		$email_type = 'text';
        		$disabled = '';
        	} else {
        		$email_type = 'text';
        		$disabled = '';
        	}


        	?>
        	<!-- The Hidden values go here -->
        	<input type="hidden" name="code" value="<?php echo REGISTRATION_MAIN_AIRLINE; ?>" />

        	 <div class="form-group">
                <div class="col-xs-6">
                    <div class="input-group">
                    	<span class="input-group-addon"><i class="fa fa-envelope"></i></span>
                        <input class="form-control" type="<?php echo $email_type; ?>" id="email" name="email" placeholder="Email" value="<?php if(isset($_SESSION['email'])) { echo htmlentities($_SESSION['email']); } ?>" <?php echo $disabled; ?>>
                    </div>
                </div>

            </div>
            <div class="form-group">

                <div class="col-xs-6">
                    <div class="input-group">
                    	<span class="input-group-addon"><i class="gi gi-user"></i></span>
                        <input class="form-control" type="text" id="firstname" name="firstname" placeholder="First Name" value="<?php echo Vars::POST('firstname');?>" >
                    </div>
                </div>

                <div class="col-xs-6">
                    <div class="input-group">
                        <input class="form-control" type="text" id="lastname" name="lastname" placeholder="Last Name">
                    </div>
                </div>
            </div>

            <div class="form-group">
                <div class="form-material">
					<div class="col-xs-6">
						<label for="arricao">Location</label>
						<select class="select-chosen" name="location" id="location">
							<?php
								$ip = $_SERVER['REMOTE_ADDR'];
								$url = "http://ipinfo.io/{$ip}/json";
					$ch = curl_init($url);
					curl_setopt($ch, CURLOPT_ENCODING,"");
					curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
					curl_setopt($ch, CURLOPT_HEADER, true);
					curl_setopt($ch, CURLINFO_HEADER_OUT, true);
					curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
					curl_setopt($ch, CURLOPT_FILETIME, true);
					curl_setopt($ch, CURLOPT_USERAGENT,"Mozilla/5.0 (Windows NT 5.1; rv:32.0) Gecko/20100101 Firefox/32.0");
					curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 100);
					curl_setopt($ch, CURLOPT_VERBOSE, true);
					curl_setopt($ch, CURLOPT_AUTOREFERER, true);
					curl_setopt($ch, CURLOPT_TIMEOUT,100);
					curl_setopt($ch, CURLOPT_FAILONERROR,true);
					$details = curl_exec($ch);
					$details = json_decode($details);
					$resultStatus = curl_getinfo($ch, CURLINFO_HTTP_CODE);
					if ($resultStatus == 200 || $resultStatus == 204) {
						$visitor_country =  $details->country;
					} else if ($resultStatus == 429) {
						$visitor_country = 'Unable to determine location. Error Code '.$resultStatus;
					} else {
						$visitor_country = 'Unable to determine location. Error Code '.$resultStatus;
					}
								$visitor_country =  $details->country;


								foreach($country_list as $countryCode=>$countryName) {
									if(Vars::POST('location') == $countryCode) {
									    $sel = 'selected="selected"';
									} elseif($visitor_country == $countryCode) {
									    $sel = 'selected="selected"';
									}
									else {
									    $sel = '';
									}
									echo '<option value="'.$countryCode.'" '.$sel.'>'.$countryName.'</option>';
								}

							?>
						</select>
					</div>
				</div>

            	<div class="form-material">
					<div class="col-xs-6">
						<label for="arricao">Hub</label>
						<select class="select-chosen" name="hub" id="hub">
							<?php
							foreach($hub_list as $hub) {
								echo '<option value="'.$hub->icao.'">'.$hub->icao.' - ' . $hub->name .'</option>';
							}
							?>
						</select>
					</div>
				</div>
            </div>

             <?php
                      //Put this in a seperate template. Shows the Custom Fields for registration
                      Template::Show('registration_customfields.tpl');
                  ?>



            <div class="form-group">
                <div class="col-xs-6">
                    <div class="input-group">
                    	<span class="input-group-addon"><i class="gi gi-asterisk"></i></span>
                        <input class="form-control" id="password" type="password" name="password1" placeholder="Enter Password" value="">
                    </div>
                </div>
                <div class="col-xs-6">
                    <div class="input-group">
                    	<span class="input-group-addon"><i class="gi gi-asterisk"></i></span>
                        <input class="form-control" type="password" name="password2" placeholder="Confirm Password" value="">
                    </div>
                </div>
            </div>
            <div class="form-group">
                <div class="col-xs-7 col-sm-8 text-center">
		            <?php if(isset($captcha_error)){echo '<p class="error">'.$captcha_error.'</p>';} ?>
		            <div class="g-recaptcha" data-sitekey="<?php echo Config::Get('RECAPTCHA_PUBLIC_KEY');?>"></div>
		            <script type="text/javascript" src="https://www.google.com/recaptcha/api.js?hl=<?php echo $lang;?>">
		            </script>
                </div>

            </div>
            <div class="form-group form-actions">
        		<div class="col-xs-6">
            		<a href="#modal-terms" data-toggle="modal" class="register-terms">Terms</a>
            		<label class="switch switch-primary" data-toggle="tooltip" title="Agree to the terms">
                		<input type="checkbox" id="register-terms" name="register-terms">
                		<span></span>
            		</label>
        		</div>
        		<div class="col-xs-6 text-right">
            		<input type="submit" name="submit" class="btn btn-sm btn-success" value="Register" />
        		</div>
    		</div>
    		<div class="form-group">
        		<div class="col-xs-12 text-center">
            		<small>Do you have an account?</small> <a href="<?php echo url('/login'); ?>" id="link-register"><small>Login</small></a>
        		</div>
    		</div>
        </form>
	<!-- END Login Form -->
    </div>
    <!-- END Login Block -->
</div>
</div>
</div>

</div>

<!-- Login Container -->

<!-- END Login Container -->
<!-- Modal Terms -->
<div id="modal-terms" class="modal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">Terms &amp; Conditions</h4>
            </div>
            <div class="modal-body">
                <h4><strong><?php echo SITE_NAME?> Terms &amp; Conditions</strong></h4>
                <p>1.) We understand flight sim glitches & problems.</p>
                <p>2.) Members must be at least 13 years of age.</p>
                <p>3.) Members must be able to complete at least one flight per calendar month.</p>
                <p>4.) The pilot must submit their real identity and a valid e-mail address.</p>
                <p>5.) We reserve the right to remove any member for any reason whatsoever felt necessary for the greater good of <?php echo SITE_NAME?> and the wider community.</p>
                <p>6.) Members must not be abusive, threatening, or discriminatory towards any other member. Failure to comply with this condition may result in dismissal from <?php echo SITE_NAME?> without notice or the possibility of appeal.</p>
                <p>7.) Although there is no obligation to fly on a network, we encourage all our pilots to fly on VATSIM and/or IVAO.</p>
                <h4><strong>Flight Rules</strong></h4>
                <p>1.) Our landing rate goal is -600 fpm or less.</p>
                <p>2.) Time acceleration, slewing, unlimited fuel & inflight refueling are not allowed.</p>
                <p>3.) Changing aircraft after starting SmartCars is not allowed.</p>
                <p>4.) Flights may be paused at any time for as long as a pilot wishes. (The exception is Microsoft Flight Simulator 2020 where the maximum pause length is only 15 minutes. Longer breaks must be reported to the staff)</p>
                <p>5.) Diverts are allowed.</p>
            </div>
        </div>
    </div>
</div>
<!-- END Modal Terms -->
