Пример #1
0
function show_page()
{
    global $EXPORT_STR;
    //$EXPORT_STR=true makes it return a string of all the code. (and not echo anything)
    if (!$EXPORT_STR) {
        lmt_page_header('Export');
        echo <<<HEREDOC
<h1>Export</h1>

HEREDOC;
    }
    $code = '<h3>Results</h3>';
    score_guts();
    // INDIVIDUAL ROUND
    $indiv_query = 'SELECT individuals.name AS name, (SELECT name FROM schools WHERE school_id=teams.school) AS school_name, IFNULL(%l,0) AS score FROM (individuals LEFT JOIN teams ON team=teams.team_id) WHERE individuals.deleted="0" AND teams.deleted="0" AND individuals.attendance="1" ORDER BY score DESC, RAND()';
    $rankings = array(array('Top Individuals in Individual Round', str_replace('%l', 'score_individual', $indiv_query), 10), array('Top Individuals in Theme Round', str_replace('%l', 'score_theme', $indiv_query), 10), array('Top Individuals Overall', str_replace('%l', '(score_individual + score_theme)', $indiv_query), 10));
    foreach ($rankings as $rankparams) {
        $title = $rankparams[0];
        $query = $rankparams[1];
        $maxrank = $rankparams[2];
        $code .= '<h4>' . htmlentities($title) . '</h4>' . "\n" . '<table class="contrasting"><tr><th>Place</th><th>Name</th><th>School</th><th>Score</th></tr>';
        $result = DB::query($query);
        $prev_score = NULL;
        //Null never equals anything.
        foreach ($result as $ind => $row) {
            $name = htmlentities($row['name']);
            $school = htmlentities($row['school_name']);
            if ($school == '') {
                $school = '<span class="i">None</span>';
            }
            $score = intval($row['score']);
            //Finding the rank
            if ($prev_score != $score) {
                $prev_rank = $rank = $ind + 1;
            }
            //If score is below, set it to the actual ranking.
            //If it's tied, leave the ranking as it was.
            $prev_score = $score;
            //update previous score.
            if ($rank > $maxrank) {
                break;
            }
            //Only specified number of top places.
            $code .= "  <tr>\n    <td>{$rank}</td>\n    <td>{$name}</td>\n    <td>{$school}</td>\n    <td>{$score}</td>\n  </tr>\n";
        }
        $code .= "</table>\n";
    }
    //selecting individuals' name, school, individual score, from individuals left-joined with teams
    // TEAM ROUND
    $code .= '<h4>Top Teams in Team Round</h4><table class="contrasting"><tr><th>Place</th><th>Team</th><th>School</th><th>Score</th></tr>';
    $query = 'SELECT team_id, name, IFNULL(score_team_short, 0) + IFNULL(score_team_long, 0) AS score_team, (SELECT name FROM schools WHERE schools.school_id=teams.school) AS school_name, RAND() AS rand FROM teams WHERE deleted="0" ORDER BY score_team DESC, rand';
    $result = DB::queryRaw($query);
    $row = mysqli_fetch_assoc($result);
    $place = 1;
    $num = 0;
    $last_score = null;
    while ($row) {
        $num++;
        if ($row['score_team'] != $last_score) {
            $place = $num;
        }
        $last_score = $row['score_team'];
        if ($place > 10) {
            break;
        }
        $id = htmlentities($row['team_id']);
        $name = htmlentities($row['name']);
        $school_name = htmlentities($row['school_name']);
        $score_team = htmlentities($row['score_team']);
        if (is_null($row['score_team'])) {
            $score_team = '<span class="i">None</span>';
        }
        $code .= <<<HEREDOC
  <tr>
    <td>{$place}</td>
    <td>{$name}</td>
    <td>{$school_name}</td>
    <td>{$score_team}</td>
  </tr>

HEREDOC;
        $row = mysqli_fetch_assoc($result);
    }
    $code .= "</table>\n";
    // GUTS ROUND
    $code .= <<<HEREDOC
<h4>Top Teams in Guts Round</h4>
<table class="contrasting">
  <tr>
    <th>Place</th>
    <th>Team</th>
    <th>School</th>
    <th>Score</th>
  </tr>

HEREDOC;
    $query = 'SELECT team_id, name, score_guts, (SELECT name FROM schools WHERE schools.school_id=teams.school) AS school_name, 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 > 10) {
            break;
        }
        $id = htmlentities($row['team_id']);
        $name = htmlentities($row['name']);
        $school_name = htmlentities($row['school_name']);
        $score_guts = htmlentities($row['score_guts']);
        if (is_null($row['score_guts'])) {
            $score_guts = '<span class="i">None</span>';
        }
        $code .= <<<HEREDOC
  <tr>
    <td>{$place}</td>
    <td>{$name}</td>
    <td>{$school_name}</td>
    <td>{$score_guts}</td>
  </tr>

HEREDOC;
        $row = mysqli_fetch_assoc($result);
    }
    $code .= "</table>\n";
    // TEAM COMPOSITE
    $code .= <<<HEREDOC
<h4>Top Teams Overall</h4>
<table class="contrasting">
  <tr>
    <th>Place</th>
    <th>Team</th>
    <th>School</th>
    <th>Score</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, (SELECT name FROM schools WHERE schools.school_id=teams.school) AS school_name,', '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 > 10) {
            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']);
        $school_name = htmlentities($row['school_name']);
        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>';
        }
        $code .= <<<HEREDOC
  <tr>
    <td>{$place}</td>
    <td>{$name}</td>
    <td>{$school_name}</td>
    <td>{$score_composite}</td>
  </tr>

HEREDOC;
        $row = mysqli_fetch_assoc($result);
    }
    $code .= "</table>\n";
    if ($EXPORT_STR) {
        return $code;
    } else {
        echo "Exported results (to paste into website page):<br><textarea cols='100' rows='10' onclick='this.setSelectionRange(0, this.value.length)'>" . str_replace(' ', '&nbsp;', htmlentities($code)) . "</textarea>{$code}";
    }
}
Пример #2
0
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>&nbsp;&nbsp;
          <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;
}
Пример #3
0
function display_team($err, $selected_field)
{
    score_guts();
    $row = DB::queryFirstRow('SELECT teams.*, schools.name AS school_name, schools.coach_email FROM teams LEFT JOIN schools ON teams.school=schools.school_id' . ' WHERE team_id="' . mysqli_real_escape_string(DB::get(), $_GET['ID']) . '"');
    $team_name = htmlentities($row['name']);
    $school_name = htmlentities($row['school_name']);
    $school_id = htmlentities($row['school']);
    $coach_email = '<a href="mailto:' . htmlentities($row['coach_email']) . '" rel="external">' . htmlentities($row['coach_email']) . '</a>';
    if ($school_id == '-1') {
        $school_link = '<span class="b">Individuals</span>';
        $coach_email = '<span class="b">None</span>';
    } else {
        $school_link = '<a href="School?ID=' . $school_id . '">' . $school_name . '</a>';
    }
    $schools_dropdown = make_schools_dropdown($school_id);
    $members_list = make_members_list();
    $teamround_short_checked = is_null($row['score_team_short']) ? '' : ' checked="checked"';
    $teamround_short_score = htmlentities($row['score_team_short']);
    $teamround_long_checked = is_null($row['score_team_long']) ? '' : ' checked="checked"';
    $teamround_long_score = htmlentities($row['score_team_long']);
    $row2 = DB::queryFirstRow(team_composite('', 'WHERE team_id="' . mysqli_real_escape_string(DB::get(), $_GET['ID']) . '"'));
    $composite_score = $row2['team_composite'];
    if (is_null($composite_score)) {
        $composite_score = 'None';
    } else {
        $composite_score = htmlentities($composite_score);
    }
    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['lmtDataTeamRoundShortScore'].teamRoundShortHasValue.checked) {
          document.forms['lmtDataTeamRoundShortScore'].teamRoundShortScore.disabled = false;
          if (isClick == 1)
            document.forms['lmtDataTeamRoundShortScore'].teamRoundShortScore.focus();
        }
        else
          document.forms['lmtDataTeamRoundShortScore'].teamRoundShortScore.disabled = true;
        
        if (document.forms['lmtDataTeamRoundLongScore'].teamRoundLongHasValue.checked) {
          document.forms['lmtDataTeamRoundLongScore'].teamRoundLongScore.disabled = false;
          if (isClick == 2)
            document.forms['lmtDataTeamRoundLongScore'].teamRoundLongScore.focus();
        }
        else
          document.forms['lmtDataTeamRoundLongScore'].teamRoundLongScore.disabled = true;
      }
HEREDOC;
    if ($err != '') {
        $err = "\n        <div class=\"error\">{$err}</div><br />\n";
    }
    $id = htmlentities($_GET['ID']);
    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($team_name);
    echo <<<HEREDOC
      <h1>Team</h1>
      {$scoring_warning}
      <table>
        <tr>
          <td>Team Name:</td>
          <td>
            <form id="lmtDataTeamName" method="post" action="{$_SERVER['REQUEST_URI']}"><div>
              <input type="text" name="team_name" size="25" maxlength="25" value="{$team_name}" />
              <input type="hidden" name="xsrf_token" value="{$_SESSION['xsrf_token']}" />
              <input type="submit" name="lmtDataTeam_changeName" value="Change" />
            </div></form>
            <br />
          </td>
        </tr><tr>
          <td>School:</td>
          <td>
            {$school_link}
            <div class="halfbreak"></div>
            <form id="lmtDataTeamSchool" method="post" action="{$_SERVER['REQUEST_URI']}"><div>
{$schools_dropdown}
              <input type="hidden" name="xsrf_token" value="{$_SESSION['xsrf_token']}" />
              <input type="submit" name="lmtDataTeam_changeSchool" value="Change" />
            </div></form>
          </td>
        </tr><tr>
          <td>Coach's Email:</td>
          <td>{$coach_email}<br /><br /></td>
        </tr><tr>
          <td>Team Round Short Score:</td>
          <td>
            <form id="lmtDataTeamRoundShortScore" method="post" action="{$_SERVER['REQUEST_URI']}"><div>
              <input type="checkbox" name="teamRoundShortHasValue" value="Yes" onchange="nullboxSetState(1);"{$teamround_short_checked}/>
              <input type="text" name="teamRoundShortScore" size="25" value="{$teamround_short_score}" />
              <input type="hidden" name="xsrf_token" value="{$_SESSION['xsrf_token']}" />
              <input type="submit" name="lmtDataTeam_changeTeamRoundShort" value="Change" {$scoring_freeze}/>
            </div></form>
          </td>
        </tr><tr>
          <td>Team Round Long Score:</td>
          <td>
            <form id="lmtDataTeamRoundLongScore" method="post" action="{$_SERVER['REQUEST_URI']}"><div>
              <input type="checkbox" name="teamRoundLongHasValue" value="Yes" onchange="nullboxSetState(2);"{$teamround_long_checked}/>
              <input type="text" name="teamRoundLongScore" size="25" value="{$teamround_long_score}" />
              <input type="hidden" name="xsrf_token" value="{$_SESSION['xsrf_token']}" />
              <input type="submit" name="lmtDataTeam_changeTeamRoundLong" value="Change" {$scoring_freeze}/>
            </div></form>
          </td>
        </tr><tr>
          <td>Guts Round Score:</td>
          <td><a href="../Guts/Full?ID={$id}">View &amp; Edit</a></td>
        </tr><tr>
          <td>Composite Score:</td>
          <td><span class="b">{$composite_score}</span><br /><br /></td>
        </tr><tr>
          <td>Members:</td>
          <td>
{$members_list}              <br />
          </td>
        </tr><tr>
          <td>Delete:</td>
          <td>
            <form method="post" action="{$_SERVER['REQUEST_URI']}"><div>
              <input type="submit" name="lmtDataTeam_delete" value="Delete Team &amp; Members" />
            </div></form>
          </td>
        </tr>
      </table>
HEREDOC;
    die;
}