예제 #1
0
function process_form()
{
    // INITIAL DATA FETCHING
    global $school_name, $email;
    // so that the show_form function can use these values later
    $school_name = htmlentities(trim($_POST['school_name']));
    $email = htmlentities($_POST['email']);
    $name_msg = validate_school_name($school_name);
    $recaptcha_msg = validate_recaptcha();
    $email_msg = validate_coach_email($email);
    if ($name_msg !== true) {
        alert($name_msg, -1);
    } else {
        if ($recaptcha_msg !== true) {
            alert($recaptcha_msg, -1);
        } else {
            if ($email_msg !== true) {
                alert($email_msg, -1);
            } else {
                // ** All information has been validated at this point **
                $access_code = generate_code(5);
                // Create database entry
                DB::insert('schools', array('name' => $school_name, 'coach_email' => $email, 'access_code' => $access_code));
                // Get user id (MySQL AUTO_INCREMENT id)
                $id = DB::insertId();
                global $LMT_EMAIL;
                $lmt_year = htmlentities(map_value('year'));
                $lmt_date = htmlentities(map_value('date'));
                // Send the email
                $url = get_site_url() . '/LMT/Registration/Signin?ID=' . $id . '&Code=' . $access_code;
                $subject = "LMT {$lmt_year} Account";
                $body = <<<HEREDOC
To: {$school_name}

Thank you for registering your school for the LMT! The contest will be 
held on [b]{$lmt_date} [/b] at Lexington High School.

You may register teams for LMT {$lmt_year} via the link below. This link will
also enable you to modify teams as long as registration is open.

[b][url]{$url} [/url][/b]

If you have any questions, please contact us at [email]{$LMT_EMAIL} [/email].
HEREDOC;
                lmt_send_email(array($email => $school_name), $subject, $body);
                // Show the post-registration message
                echo <<<HEREDOC
      <h1>Coach Registration</h1>
      
      <div class="text-centered">
        Your account was created. Please check your email inbox for a confirmation email.
      </div>
HEREDOC;
                die;
            }
        }
    }
}
예제 #2
0
function do_change_email()
{
    if ($_POST['xsrf_token'] != $_SESSION['xsrf_token']) {
        trigger_error('XSRF code incorrect', E_USER_ERROR);
    }
    $email = $_POST['coach_email'];
    $row = DB::queryFirstRow('SELECT coach_email FROM schools WHERE school_id=%i', $_GET['ID']);
    if ($email == $row['coach_email']) {
        header('Location: School?ID=' . $_GET['ID']);
        die;
    }
    $email_msg = validate_coach_email($email);
    if ($email_msg !== true) {
        display_school($email_msg, 'document.forms[\'lmtDataSchoolEmail\'].coach_email.focus();');
    }
    DB::update('schools', 'coach_email=%s', 'school_id=%i LIMIT 1', $email, $_GET['ID']);
    alert('Coach email was changed', 1);
    lmt_location('Backstage/Data/School?ID=' . $_GET['ID']);
}