示例#1
0
function show_page()
{
    global $header_noprint;
    $header_noprint = true;
    lmt_page_header('Score Sheets');
    $message = '';
    $lmt_year = intval(map_value('year'));
    $lmt_nextyear = $lmt_year + 1;
    $lmt_archive_url = URL::lmt() . "/{$lmt_year}_Archive";
    if (scoring_is_enabled()) {
        $message = '<div class="error noPrint">Score entry is still enabled! Disable it <a href="../Scoring/Refrigerator">here</a>.</div><br />';
    }
    echo <<<HEREDOC
      <h1 class="noPrint">Score Emails</h1>
      {$message}
\t  
\t  <style>textarea{width: 100%;height: 400px;}</style>
\t  
\t\t<form method="post" action="{$_SERVER['REQUEST_URI']}">
\t\t\t<input type="hidden" name="xsrf_token" value="{$_SESSION['xsrf_token']}"/>
\t\t\t<input type="submit" name="Send" value="Send All Emails"/>
\t\t</form>
      
      <div>

HEREDOC;
    $individuals = DB::query('SELECT individuals.name as ind_name, individuals.grade as grade, ' . 'IFNULL(score_team_short, 0) + IFNULL(score_team_long, 0) AS score_team, ' . 'score_guts, teams.name AS team_name, score_individual as score_ind, score_theme, email ' . 'FROM individuals LEFT JOIN teams ON team=team_id ' . 'WHERE email != "" AND individuals.deleted = 0 ORDER BY ind_name');
    foreach ($individuals as $ind) {
        $if_not_eighth = "";
        if ($ind['grade'] != 8) {
            ", and we hope to see you at LMT {$lmt_nextyear}";
        }
        $body = <<<HEREDOC
Hello,

Thanks for coming to LMT {$lmt_year}; here are your individual results!
[b]Name:[/b] {$ind['ind_name']}
[b]Individual Score:[/b] {$ind['score_ind']}
[b]Theme Score:[/b] {$ind['score_theme']}

As an unaffiliated individual, you were also placed onto a team. Here's how you did:
[b]Team Name:[/b] {$ind['team_name']}
[b]Team Round Score:[/b] {$ind['score_team']}
[b]Guts Round Score:[/b] {$ind['score_guts']}

You can also find useful things such as overall results, photos, and problems and solutions at [url]{$lmt_archive_url}[/url].

Finally, we'd love to hear from you! Any feedback at all about how we did this year and how we might improve for next year is greatly appreciated.

Thanks for coming{$if_not_eighth}!
LHS Math Team Captains
HEREDOC;
        if (array_key_exists('Send', $_POST) && $_POST['xsrf_token'] == $_SESSION['xsrf_token']) {
            echo $ind['email'];
            $err = lmt_send_email($ind['email'], "Scores!", $body);
            if ($err !== true) {
                alert($err, -1);
                return;
            } else {
                alert("Sent to {$ind['email']}", 1);
            }
        }
        echo "<h2>{$ind['email']}</h2><div style='border:solid 1px #000'>" . BBCode($body) . "</div>";
    }
    $teams = DB::query('SELECT team_id, IFNULL(score_team_short, 0) + IFNULL(score_team_long, 0) AS score_team, ' . ' score_guts, teams.name AS team_name, teams.school AS school_id,' . ' schools.name AS school_name, coach_email ' . ' FROM teams RIGHT JOIN schools ON teams.school=schools.school_id ' . ' WHERE teams.deleted=0 ORDER BY school_name, team_name');
    for ($i = -1; $i + 1 < count($teams);) {
        $body = '';
        do {
            $i++;
            $team = $teams[$i];
            $school = htmlentities($team['school_name']);
            $coach_email = htmlentities($team['coach_email']);
            $team_id = htmlentities($team['team_id']);
            $team_name = htmlentities($team['team_name']);
            $score_team = htmlentities($team['score_team']);
            $score_guts = htmlentities($team['score_guts']);
            if ($body == '') {
                $body = <<<HEREDOC
Hello,

Thanks for coming to LMT {$lmt_year}; here are the results for your team(s)!

[b]School Name:[/b] {$school}

HEREDOC;
            }
            if (is_null($team['score_team'])) {
                $score_team = 'NONE';
            }
            if (is_null($team['score_guts'])) {
                $score_guts = 'NONE';
            }
            $body .= <<<HEREDOC

[b]Team Name:[/b] {$team_name}
[b]Team Round Score:[/b] {$score_team}
[b]Guts Round Score:[/b] {$score_guts}
HEREDOC;
            $members = DB::query('SELECT name, score_individual, score_theme, email FROM individuals WHERE team=%i AND deleted="0" ORDER BY name', $team_id);
            if (count($members) == 0) {
                $body .= "\n\nNo Team Members\n";
            } else {
                $body .= "\n\n[b]Individual Scores: Individual Round, Theme Round[/b]\n";
            }
            foreach ($members as $member) {
                $name = htmlentities($member['name']);
                $score_individual = htmlentities($member['score_individual']);
                $score_theme = htmlentities($member['score_theme']);
                if (is_null($member['score_individual'])) {
                    $score_individual = 'NONE';
                }
                if (is_null($member['score_theme'])) {
                    $score_theme = 'NONE';
                }
                $indiv_msg = '';
                if ($member['email'] != '') {
                    $indiv_msg = ' (Unaffiliated Individual)';
                }
                $body .= "{$name}{$indiv_msg}: {$score_individual}, {$score_theme}\n";
            }
            $body .= "\n";
        } while ($i + 1 < count($teams) && $teams[$i]['coach_email'] == $teams[$i + 1]['coach_email']);
        $body .= <<<HEREDOC

You can also find useful things such as overall results, photos, and problems and solutions at [url]{$lmt_archive_url}[/url].

Finally, we'd love to hear from you! Any feedback at all about how we did this year and how we might improve for next year is greatly appreciated.

Thanks for coming, and we hope to see you at LMT {$lmt_nextyear}!
LHS Math Team Captains
HEREDOC;
        if (array_key_exists('Send', $_POST) && $_POST['xsrf_token'] == $_SESSION['xsrf_token']) {
            echo $coach_email;
            $err = lmt_send_email($coach_email, "Scores!", $body);
            if ($err !== true) {
                alert($err, -1);
                return;
            } else {
                alert("Sent to {$coach_email}", 1);
            }
        }
        echo "<h2>{$coach_email}</h2><div style='border:solid 1px #000'>" . BBCode($body) . "</div>";
    }
    echo "      </div>";
}
示例#2
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;
            }
        }
    }
}
示例#3
0
function process_form()
{
    // INITIAL DATA FETCHING
    global $name, $email, $grade;
    // so that the show_form function can use these values later
    $name = htmlentities(ucwords(trim($_POST['name'])));
    $name = preg_replace('/\\s\\s+/', ' ', $name);
    $name = preg_replace('/\\-+/', '-', $name);
    $email = htmlentities($_POST['email']);
    $grade = $_POST['grade'];
    $name_msg = validate_name($name);
    if ($name_msg !== true) {
        show_form($name_msg, 'name');
    }
    $grade_msg = validate_grade($grade);
    if ($grade_msg !== true) {
        show_form($grade_msg, 'grade');
    }
    $recaptcha_msg = validate_recaptcha();
    if ($recaptcha_msg !== true) {
        show_form($recaptcha_msg, 'recaptcha_response_field');
    }
    $email_msg = validate_email($email);
    if ($email_msg !== true) {
        show_form($email_msg, 'email');
    }
    // ** All information has been validated at this point **
    // Create database entry
    DB::insert('individuals', array('name' => $name, 'grade' => $grade, 'email' => $email));
    $id = DB::insertId();
    //Get AUTO_INCREMENT id
    // Start outputting the top part of the page, to make it seem responsive while we send the email
    lmt_page_header('Individual Registration');
    // Send the email
    $lmt_year = htmlentities(map_value('year'));
    $lmt_date = htmlentities(map_value('date'));
    $cost = htmlentities(map_value('indiv_cost'));
    $url = get_site_url() . '/LMT';
    global $LMT_EMAIL;
    $subject = "LMT {$lmt_year} Registration Receipt";
    $body = <<<HEREDOC
Hi {$name},
You have successfully registered as an individual for LMT {$lmt_year}!

[b]Please print out this email and bring it to the competition
along with the registration fee of {$cost}[/b].

Date: [b]{$lmt_date}[/b]
Location: Lexington High School [url]http://www.lhsmath.org/LMT/Location[/url]

If you have any questions, please contact us at [email]{$LMT_EMAIL}[/email].
______________________________________________________________

Registration: [b]Individual[/b]
ID: [b]{$id}[/b]
Name: [b]{$name}[/b]
Email: [b]{$email}[/b]
Grade: [b]{$grade}[/b]
______________________________________________________________
HEREDOC;
    lmt_send_email(array($email => $name), $subject, $body);
    // Show the post-registration message
    echo <<<HEREDOC
      <h1>Individual Registration</h1>
      
      <div class="text-centered">
        You have successfully registered for LMT {$lmt_year}! An email has been sent with more information.
      </div>
HEREDOC;
}
示例#4
0
function do_resend_login()
{
    if ($_POST['xsrf_token'] != $_SESSION['xsrf_token']) {
        trigger_error('XSRF code incorrect', E_USER_ERROR);
    }
    $row = DB::queryFirstRow('SELECT school_id, name, coach_email, access_code FROM schools WHERE school_id="' . $_GET['ID'] . '"');
    $school_name = $row['name'];
    $email = $row['coach_email'];
    $url = get_site_url() . '/LMT/Registration/Signin?ID=' . $row['school_id'] . '&Code=' . $row['access_code'];
    global $LMT_EMAIL;
    $to = array($email => $school_name);
    $subject = 'LMT Account';
    $body = <<<HEREDOC
To: {$school_name}

You may register teams for the LMT by clicking the link below. This link will
also enable you to modify teams as long as registration is open.

{$url}
HEREDOC;
    lmt_send_email($to, $subject, $body);
    alert('The login information was resent to ' . htmlentities($email), 1);
    lmt_location('Backstage/Data/School?ID=' . $_GET['ID']);
}