function show_page() { if (scoring_is_enabled()) { $message = '<div class="error">Score entry is still enabled! Disable it <a href="../Scoring/Refrigerator">here</a>.</div><br />'; } lmt_page_header('Top Scorers'); echo <<<HEREDOC <h1>Top Scorers</h1> {$message} <div class="text-centered b"> <span class="noPrint"> <a href="Full">Full Results</a> <a href="Print">Scores for Coaches</a> <br /><br /> </span> <span class="red">Reminder: Do not copy data locally!</span><br /> Ties are listed in random order. <br /><br /> </div> <h2>Top 5 Individuals by Individual Round</h2> <table class="contrasting"> <tr> <th>Place</th> <th>Name</th> <th>School</th> <th>Individual Round</th> </tr> HEREDOC; score_guts(); // INDIVIDUAL ROUND $query = 'SELECT id, individuals.name AS name, (SELECT name FROM schools WHERE school_id=teams.school) AS school_name, ' . 'RAND() AS rand, score_individual FROM individuals LEFT JOIN teams ON team=teams.team_id WHERE individuals.deleted="0" AND attendance="1" ORDER BY score_individual DESC, rand'; $result = DB::queryRaw($query); $row = mysqli_fetch_assoc($result); $place = 0; $num = 0; $last_score = null; while ($row) { $num++; if ($row['score_individual'] != $last_score) { $place = $num; } $last_score = $row['score_individual']; if ($place > 5) { break; } $id = htmlentities($row['id']); $name = htmlentities($row['name']); $school = htmlentities($row['school_name']); if ($school == '') { $school = '<span class="i">None</span>'; } $score_individual = htmlentities($row['score_individual']); echo <<<HEREDOC <tr> <td>{$place}</td> <td><a href="../Data/Individual?ID={$id}">{$name}</a></td> <td>{$school}</td> <td class="b">{$score_individual}</td> </tr> HEREDOC; $row = mysqli_fetch_assoc($result); } echo " </table>\n"; // Theme ROUND echo <<<HEREDOC <h2>Top 5 Individuals by Theme Round</h2> <table class="contrasting"> <tr> <th>Place</th> <th>Name</th> <th>School</th> <th>Theme Round</th> </tr> HEREDOC; $query = 'SELECT id, individuals.name AS name, (SELECT name FROM schools WHERE school_id=teams.school) AS school_name, ' . 'RAND() AS rand, score_theme FROM individuals LEFT JOIN teams ON team=teams.team_id WHERE individuals.deleted="0" AND attendance="1" ORDER BY score_theme DESC, rand'; $result = DB::queryRaw($query); $row = mysqli_fetch_assoc($result); $place = 0; $num = 0; $last_score = null; while ($row) { $num++; if ($row['score_theme'] != $last_score) { $place = $num; } $last_score = $row['score_theme']; if ($place > 5) { break; } $id = htmlentities($row['id']); $name = htmlentities($row['name']); $school = htmlentities($row['school_name']); if ($school == '') { $school = '<span class="i">None</span>'; } $score_theme = htmlentities($row['score_theme']); echo <<<HEREDOC <tr> <td>{$place}</td> <td><a href="../Data/Individual?ID={$id}">{$name}</a></td> <td>{$school}</td> <td class="b">{$score_theme}</td> </tr> HEREDOC; $row = mysqli_fetch_assoc($result); } echo " </table>\n"; // INDIVIDUAL COMPOSITE echo <<<HEREDOC <h2>Top 10 Individuals by Composite</h2> <table class="contrasting"> <tr> <th>Place</th> <th>Name</th> <th>School</th> <th>Composite</th> </tr> HEREDOC; $query = individual_composite('id, individuals.name AS name, (SELECT name FROM schools WHERE school_id=teams.school) AS school_name, ' . 'RAND() AS rand,', 'LEFT JOIN teams ON team=teams.team_id WHERE individuals.deleted="0" AND attendance="1" ORDER BY score_composite DESC, rand'); $result = DB::queryRaw($query); $row = mysqli_fetch_assoc($result); $place = 0; $num = 0; $last_score = null; while ($row) { $num++; if ($row['score_composite'] != $last_score) { $place = $num; } $last_score = $row['score_composite']; if ($place > 10) { break; } $id = htmlentities($row['id']); $name = htmlentities($row['name']); $school = htmlentities($row['school_name']); if ($school == '') { $school = '<span class="i">None</span>'; } $score_composite = htmlentities($row['score_composite']); echo <<<HEREDOC <tr> <td>{$place}</td> <td><a href="../Data/Individual?ID={$id}">{$name}</a></td> <td>{$school}</td> <td class="b">{$score_composite}</td> </tr> HEREDOC; $row = mysqli_fetch_assoc($result); } echo " </table>\n"; // TEAM ROUND echo <<<HEREDOC <h2>Top 5 Teams by Team Round</h2> <table class="contrasting"> <tr> <th>Place</th> <th>Team Name</th> <th>Team Round</th> </tr> HEREDOC; $query = 'SELECT team_id, name, IFNULL(score_team_short, 0) + IFNULL(score_team_long, 0) AS score_team, RAND() AS rand FROM teams WHERE deleted="0" ORDER BY score_team DESC, rand'; $result = DB::queryRaw($query); $row = mysqli_fetch_assoc($result); $place = 0; $num = 0; $last_score = null; while ($row) { $num++; if ($row['score_team'] != $last_score) { $place = $num; } $last_score = $row['score_team']; if ($place > 5) { break; } $id = htmlentities($row['team_id']); $name = htmlentities($row['name']); $score_team = htmlentities($row['score_team']); if (is_null($row['score_team'])) { $score_team = '<span class="i">None</span>'; } echo <<<HEREDOC <tr> <td>{$place}</td> <td><a href="../Data/Team?ID={$id}">{$name}</a></td> <td class="b">{$score_team}</td> </tr> HEREDOC; $row = mysqli_fetch_assoc($result); } echo " </table>\n"; // GUTS ROUND echo <<<HEREDOC <h2>Top 5 Teams by Guts Round</h2> <table class="contrasting"> <tr> <th>Place</th> <th>Team Name</th> <th>Guts Round</th> </tr> HEREDOC; $query = 'SELECT team_id, name, score_guts, RAND() AS rand FROM teams WHERE deleted="0" ORDER BY score_guts DESC, rand'; $result = DB::queryRaw($query); $row = mysqli_fetch_assoc($result); $place = 0; $num = 0; $last_score = null; while ($row) { $num++; if ($row['score_guts'] != $last_score) { $place = $num; } $last_score = $row['score_guts']; if ($place > 5) { break; } $id = htmlentities($row['team_id']); $name = htmlentities($row['name']); $score_guts = htmlentities($row['score_guts']); if (is_null($row['score_guts'])) { $score_guts = '<span class="i">None</span>'; } echo <<<HEREDOC <tr> <td>{$place}</td> <td><a href="../Data/Team?ID={$id}">{$name}</a></td> <td class="b">{$score_guts}</td> </tr> HEREDOC; $row = mysqli_fetch_assoc($result); } echo " </table>\n"; // TEAM COMPOSITE echo <<<HEREDOC <h2>Top 5 Teams by Composite</h2> <table class="contrasting"> <tr> <th>Place</th> <th>Team Name</th> <th>Team Round</th> <th>Guts Round</th> <th>Composite</th> </tr> HEREDOC; $query = team_composite('team_id, name, IFNULL(score_team_short, 0) + IFNULL(score_team_long, 0) AS score_team, score_guts, RAND() AS rand,', 'WHERE deleted="0" ORDER BY team_composite DESC, rand'); $result = DB::queryRaw($query); $row = mysqli_fetch_assoc($result); $place = 0; $num = 0; $last_score = null; while ($row) { $num++; if ($row['team_composite'] != $last_score) { $place = $num; } $last_score = $row['team_composite']; if ($place > 5) { break; } $id = htmlentities($row['team_id']); $name = htmlentities($row['name']); $score_team = htmlentities($row['score_team']); $score_guts = htmlentities($row['score_guts']); $score_composite = htmlentities($row['team_composite']); if (is_null($row['score_team'])) { $score_team = '<span class="i">None</span>'; } if (is_null($row['score_guts'])) { $score_guts = '<span class="i">None</span>'; } echo <<<HEREDOC <tr> <td>{$place}</td> <td><a href="../Data/Team?ID={$id}">{$name}</a></td> <td>{$score_team}</td> <td>{$score_guts}</td> <td class="b">{$score_composite}</td> </tr> HEREDOC; $row = mysqli_fetch_assoc($result); } echo " </table>\n"; die; }
function display_individual($err, $selected_field) { $row = DB::queryFirstRow('SELECT individuals.*, teams.name AS team_name, (SELECT name AS school_name FROM schools WHERE schools.school_id=teams.school) AS school_name' . ' FROM individuals LEFT JOIN teams ON individuals.team=teams.team_id' . ' WHERE id=%i', $_GET['ID']); $name = htmlentities($row['name']); $school = htmlentities($row['school_name']); if ($row['grade'] == '6') { $grade6_sel = ' selected="selected"'; } else { if ($row['grade'] == '7') { $grade7_sel = ' selected="selected"'; } else { if ($row['grade'] == '8') { $grade8_sel = ' selected="selected"'; } } } $email = htmlentities($row['email']); if ($email != '') { $email_link = "\n <div class=\"halfbreak\"></div> <a href=\"mailto:{$email}\" rel=\"external\">Send Email</a>"; $school = 'Unaffiliated'; } $attendance = htmlentities($row['attendance']) ? 'Present' : 'Absent'; $team_id = htmlentities($row['team']); $team_link = '<a href="Team?ID=' . $team_id . '">' . htmlentities($row['team_name']) . '</a>'; if ($team_id == -1) { $team_link = '<span class="b">Not Assigned</span>'; } $teams_dropdown = make_teams_dropdown($team_id); if ($school == '') { $school = 'None'; } $individualround_checked = is_null($row['score_individual']) ? '' : ' checked="checked"'; $individualround_score = htmlentities($row['score_individual']); $themeround_checked = is_null($row['score_theme']) ? '' : ' checked="checked"'; $themeround_score = htmlentities($row['score_theme']); $row2 = DB::queryFirstRow(individual_composite('', 'WHERE id="' . mysqli_real_escape_string(DB::get(), $_GET['ID']) . '"')); $composite_score = $row2['score_composite']; if (is_null($composite_score)) { $composite_score = 'None'; } else { $composite_score = htmlentities($composite_score); } if (!isset($scoring_warning)) { $scoring_warning = ''; } if (!isset($grade7_sel)) { $grade7_sel = ''; } if (!isset($grade8_sel)) { $grade8_sel = ''; } if (!isset($email_link)) { $email_link = ''; } if (!isset($scoring_freeze)) { $scoring_freeze = ''; } global $body_onload; $body_onload = $selected_field . 'nullboxSetState(-1);externalLinks();'; global $use_rel_external_script; $use_rel_external_script = true; global $javascript; $javascript = <<<HEREDOC function nullboxSetState(isClick) { if (document.forms['lmtDataIndividualRoundScore'].hasValue.checked) { document.forms['lmtDataIndividualRoundScore'].score.disabled = false; if (isClick == 1) document.forms['lmtDataIndividualRoundScore'].score.focus(); } else document.forms['lmtDataIndividualRoundScore'].score.disabled = true; if (document.forms['lmtDataThemeRoundScore'].hasValue.checked) { document.forms['lmtDataThemeRoundScore'].score.disabled = false; if (isClick == 2) document.forms['lmtDataThemeRoundScore'].score.focus(); } else document.forms['lmtDataThemeRoundScore'].score.disabled = true; } HEREDOC; if ($err != '') { $err = "\n <div class=\"error\">{$err}</div><br />\n"; } if (!scoring_is_enabled()) { $scoring_warning = "\n " . '<div class="text-centered">Note: Scoring has been frozen, so results may not be changed.</div><br /><br />'; $scoring_freeze = 'disabled="disabled" '; } lmt_page_header($name); echo <<<HEREDOC <h1>Individual</h1> {$scoring_warning} <table> <tr> <td>Name:</td> <td> <form id="lmtDataIndividualName" method="post" action="{$_SERVER['REQUEST_URI']}"><div> <input type="text" name="name" size="25" maxlength="25" value="{$name}" /> <input type="hidden" name="xsrf_token" value="{$_SESSION['xsrf_token']}" /> <input type="submit" name="lmtDataIndividual_changeName" value="Change" /> </div></form> </td> </tr><tr> <td>Grade:</td> <td> <form id="lmtDataIndividualGrade" method="post" action="{$_SERVER['REQUEST_URI']}"><div> <select name="grade"> <option value="6"{$grade6_sel}>Sixth</option> <option value="7"{$grade7_sel}>Seventh</option> <option value="8"{$grade8_sel}>Eighth</option> </select> <input type="hidden" name="xsrf_token" value="{$_SESSION['xsrf_token']}" /> <input type="submit" name="lmtDataIndividual_changeGrade" value="Change" /> </div></form> </td> </tr><tr> <td>Email:</td> <td> <form id="lmtDataIndividualEmail" method="post" action="{$_SERVER['REQUEST_URI']}"><div> <input type="text" name="email" size="25" value="{$email}" /> <input type="hidden" name="xsrf_token" value="{$_SESSION['xsrf_token']}" /> <input type="submit" name="lmtDataIndividual_changeEmail" value="Change" />{$email_link} </div></form> </td> </tr><tr> <td>Attendance:</td> <td> <form id="lmtDataIndividualAttendance" method="post" action="{$_SERVER['REQUEST_URI']}"><div> <span class="b">{$attendance}</span> <input type="hidden" name="currentAttendance" value="{$attendance}" /> <input type="hidden" name="xsrf_token" value="{$_SESSION['xsrf_token']}" /> <input type="submit" name="lmtDataIndividual_changeAttendance" value="Change" /> </div></form> <br /> </td> </tr><tr> <td>Team:</td> <td> {$team_link} <div class="halfbreak"></div> <form id="lmtDataIndividualTeam" method="post" action="{$_SERVER['REQUEST_URI']}"><div> {$teams_dropdown} <input type="hidden" name="xsrf_token" value="{$_SESSION['xsrf_token']}" /> <input type="submit" name="lmtDataIndividual_changeTeam" value="Change" /> </div></form> </td> </tr><tr> <td>School:</td> <td><span class="b">{$school}</span><br /><br /></td> </tr><tr> <td>Individual Round Score:</td> <td> <form id="lmtDataIndividualRoundScore" method="post" action="{$_SERVER['REQUEST_URI']}"><div> <input type="checkbox" name="hasValue" value="Yes" onchange="nullboxSetState(1);"{$individualround_checked}/> <input type="text" name="score" size="25" value="{$individualround_score}" /> <input type="hidden" name="xsrf_token" value="{$_SESSION['xsrf_token']}" /> <input type="submit" name="lmtDataIndividual_changeIndividualRound" value="Change" {$scoring_freeze}/> </div></form> </td> </tr><tr> <td>Theme Round Score:</td> <td> <form id="lmtDataThemeRoundScore" method="post" action="{$_SERVER['REQUEST_URI']}"><div> <input type="checkbox" name="hasValue" value="Yes" onchange="nullboxSetState(2);"{$themeround_checked}/> <input type="text" name="score" size="25" value="{$themeround_score}" /> <input type="hidden" name="xsrf_token" value="{$_SESSION['xsrf_token']}" /> <input type="submit" name="lmtDataIndividual_changeThemeRound" value="Change" {$scoring_freeze}/> </div></form> </td> </tr><tr> <td>Composite Score:</td> <td><span class="b">{$composite_score}</span><br /><br /></td> </tr><tr> <td>Delete:</td> <td> <form method="post" action="{$_SERVER['REQUEST_URI']}"><div> <input type="submit" name="lmtDataIndividual_delete" value="Delete Member" /> </div></form> </td> </tr> </table> HEREDOC; die; }