Example #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;
            }
        }
    }
}
Example #2
0
function do_change_name()
{
    if ($_POST['xsrf_token'] != $_SESSION['xsrf_token']) {
        trigger_error('XSRF code incorrect', E_USER_ERROR);
    }
    $name = $_POST['school_name'];
    $name_msg = validate_school_name($name);
    if ($name_msg !== true) {
        display_school($name_msg, 'document.forms[\'lmtDataSchoolName\'].school_name.focus();');
    }
    DB::update('schools', 'name=%s', 'school_id=%i AND name <> %s LIMIT 1', $name, $_GET['ID'], $name);
    global $LMT_DB;
    if (mysqli_affected_rows($LMT_DB) == 1) {
        $row = DB::queryFirstRow('SELECT COUNT(*) FROM schools WHERE name=%s AND school_id <> %i AND deleted="0"', $name, $_GET['ID']);
        if ($row['COUNT(*)'] > 0) {
            alert('School name was changed. WARNING: Another school has the same name.', 1);
        } else {
            alert('School name was changed', 1);
        }
    }
    lmt_location('Backstage/Data/School?ID=' . $_GET['ID']);
}