atcApply.php 11.1 KB
<?php
session_start();
require_once 'classes/realops.php';
$get = new Get();
$stats = new Stats();
$set = new Set();
date_default_timezone_set('Australia/Sydney');
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <?php include 'sections/header.php'; ?>
</head>
<body>
<div class="wrapper">
    <?php include 'sections/navbar.php' ?>
    <div class="container" id="realops-container">
        <div class="row">
            <article class="col-sm-12 panel panel-default" id="realops-body">
                <div class="page-header">
                    <h2>ATC Application Form</h2>
                </div>

                <?php if(isset($_POST['firstName']) && !$get->isATC($_SESSION['vatsimID']))
                {
                    $set->atcApplication($_SESSION['vatsimID'], $_POST['firstName'], $_POST['lastName'], $_POST['email'], $_POST['rating'], $_POST['position1'], $_POST['position2'], $_POST['position3'], serialize($_POST['shifts']))
                ?>
                    <div class="alert alert-success" role="alert"><strong>Success! </strong>Your application has been submitted and in the queue.</div>
                    <a href="index.php" class="btn btn-info">Go Home</a>
                    <?php
                }
                else if($get->isATC($_SESSION['vatsimID']))
                {
                    ?>
                <div class="alert alert-success" role="alert"><strong>Success! </strong>Your application has been submitted and in the queue.</div>
                    <a href="index.php" class="btn btn-info">Go Home</a>
                <?php 
            }
                else if($_GET['failed'] == 1)
                { ?>
                <div class="alert alert-danger" role="alert"><strong>Failed. </strong>Please try again.</div>
                <?php
                }
                else if(empty($_SESSION['firstName']))
                { ?>
                    <h2>You must be logged in to apply for ATC</h2>
                    <a href="sso/index.php?redirect=/slots.php" class="btn btn-success loginButton" id="2" data-toggle="modal" data-target="#realops-login-info">Login to Apply</a>
                <?php }
                else
                { ?>
                <form id="defaultForm" method="post" action="atcApply.php?success=1" class="form-horizontal" >
                    <p class="help-block"> Your name, email address and ATC rating have been pre-populated with information from VATSIM. If any of this information is incorrect, please submit your application and <a href="contact.php">contact us with the correct details</a></p>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">Name</label>
                        <div class="col-sm-4">
                            <input type="text" readonly class="form-control" name="firstName" placeholder="First name" value="<?php echo $_SESSION['firstName'] ?>" />
                        </div>
                        <div class="col-sm-4">
                            <input type="text" readonly class="form-control" name="lastName" placeholder="Last name" value="<?php echo $_SESSION['lastName'] ?>" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">Email Address</label>
                        <div class="col-sm-5">
                            <input type="text" readonly class="form-control" name="email" value="<?php echo $_SESSION['email']; ?>" />
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-3 control-label">Controller Rating</label>
                        <div class="col-sm-5">
                            <input type="text" readonly class="form-control" name="rating" value="<?php echo $_SESSION['rating'] ?>" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">Preferred ATC Position 1:</label>
                        <div class="col-sm-5">
                            <select name="position1" class="form-control">
                                <option disabled selected>Please choose...</option>
                                <option value="TWR">SY TWR (DEL, GND, TWR)</option>
                                <option value="TMA">SY TMA (APP, DEP)</option>
                                <option value="ENR">Enroute (CTR)</option>
                            </select>

                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">Preferred ATC Position 2:</label>
                        <div class="col-sm-5">
                            <select name="position2" class="form-control">
                                <option disabled selected>Please choose...</option>
                                <option value="TWR">SY TWR (DEL, GND, TWR)</option>
                                <option value="TMA">SY TMA (APP, DEP)</option>
                                <option value="ENR">Enroute (CTR)</option>
                            </select>

                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">Preferred ATC Position 3:</label>
                        <div class="col-sm-5">
                            <select name="position3" class="form-control">
                                <option disabled selected>Please choose...</option>
                                <option value="TWR">SY TWR (DEL, GND, TWR)</option>
                                <option value="TMA">SY TMA (APP, DEP)</option>
                                <option value="ENR">Enroute (CTR)</option>
                            </select>

                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-3 control-label">Shift Availability:</label>
                        <div class="col-sm-5">
                            <div class="checkbox">
                                <label>
                                    <input type="checkbox" name="shifts[]" value="04">0400z-0600z
                                </label>
                            </div>
                            <div class="checkbox">
                                <label>
                                    <input type="checkbox" name="shifts[]" value="06">0600z-0800z
                                </label>
                            </div>
                            <div class="checkbox">
                                <label>
                                    <input type="checkbox" name="shifts[]" value="08">0800z-1000z
                                </label>
                            </div>
                            <div class="checkbox">
                                <label>
                                    <input type="checkbox" name="shifts[]" value="10"> 1000z-1200z
                                </label>
                            </div>
                        </div>

                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label" id="captchaOperation"></label>
                        <div class="col-sm-2">
                            <input type="text" class="form-control" name="captcha" />
                        </div>
                    </div>

                    <div class="form-group">
                        <div class="col-sm-9 col-sm-offset-3">
                            <button type="submit" class="btn btn-primary" name="signup" value="Sign up">Submit Application</button>
                        </div>
                    </div>

                </form>
                <?php } ?>
            </div>
        </div>
    </div>



</article>
</div><!-- /.row -->
</div><!-- /.container -->
</div><!-- /.wrapper -->
<?php include 'sections/footer.php'; ?>
<script type="text/javascript">
    $(document).ready(function() {
        // Generate a simple captcha
        function randomNumber(min, max) {
            return Math.floor(Math.random() * (max - min + 1) + min);
        };
        $('#captchaOperation').html([randomNumber(1, 10), '+', randomNumber(1, 10), '='].join(' '));

        $('#defaultForm').formValidation({
            message: 'This value is not valid',
            icon: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                firstName: {
                    row: '.col-sm-4',
                    validators: {
                        notEmpty: {
                            message: 'The first name is required'
                        }
                    }
                },
                lastName: {
                    row: '.col-sm-4',
                    validators: {
                        notEmpty: {
                            message: 'The last name is required'
                        }
                    }
                },
                rating: {
                    message: 'The rating is not valid',
                    validators: {
                        notEmpty: {
                            message: 'The rating is required'
                        }
                    }
                },
                position1: {
                    message: 'The position 1 is not valid',
                    validators: {
                        notEmpty: {
                            message: 'You must select a position'
                        }
                    }
                },
                'shifts[]': {
                    validators: {
                        choice: {
                            min: 1,
                            message: 'Please choose more than 1 shift'
                        }
                    }
                },
                email: {
                    validators: {
                        notEmpty: {
                            message: 'The email address is required'
                        },
                        emailAddress: {
                            message: 'The input is not a valid email address'
                        }
                    }
                },
                captcha: {
                    validators: {
                        callback: {
                            message: 'Wrong answer',
                            callback: function(value, validator, $field) {
                                var items = $('#captchaOperation').html().split(' '), sum = parseInt(items[0]) + parseInt(items[2]);
                                return value == sum;
                            }
                        }
                    }
                }
            }
        });
    });
</script>