Ejemplo n.º 1
0
function challenges($categories)
{
    $now = time();
    $num_participating_users = get_num_participating_users();
    foreach ($categories as $category) {
        echo '
        <table class="team-table table table-striped table-hover">
          <thead>
            <tr>
              <th>', htmlspecialchars($category['title']), '</th>
              <th class="center">', lang_get('points'), '</th>
              <th class="center"><span class="has-tooltip" data-toggle="tooltip" data-placement="top" title="% of actively participating users">', lang_get('percentage_solvers'), '</span></th>
              <th>', lang_get('first_solvers'), '</th>
            </tr>
          </thead>
          <tbody>
         ';
        $challenges = db_query_fetch_all('
            SELECT
               id,
               title,
               points,
               available_from
            FROM challenges
            WHERE
              available_from < ' . $now . ' AND
              category = :category AND
              exposed = 1
            ORDER BY points ASC', array('category' => $category['id']));
        foreach ($challenges as $challenge) {
            $num_solvers = db_count_num('submissions', array('correct' => 1, 'challenge' => $challenge['id']));
            echo '
            <tr>
                <td>
                    <a href="challenge?id=', htmlspecialchars($challenge['id']), '">', htmlspecialchars($challenge['title']), '</a>
                </td>

                <td class="center">
                    ', number_format($challenge['points']), '
                </td>

                <td class="center">
                    ', number_format($num_solvers / $num_participating_users * 100), '%
                </td>

                <td class="team-name">';
            $users = db_query_fetch_all('
                SELECT
                   u.id,
                   u.team_name
                FROM users AS u
                JOIN submissions AS s ON s.user_id = u.id
                WHERE
                   u.competing = 1 AND
                   s.correct = 1 AND
                   s.challenge = :challenge
                ORDER BY s.added ASC
                LIMIT 3', array('challenge' => $challenge['id']));
            if (count($users)) {
                $pos = 1;
                foreach ($users as $user) {
                    echo get_position_medal($pos++), '<a href="user?id=', htmlspecialchars($user['id']), '">', htmlspecialchars($user['team_name']), '</a><br />';
                }
            } else {
                echo '<i>', lang_get('unsolved'), '</i>';
            }
            echo '
                </td>
            </tr>';
        }
        echo '
        </tbody>
        </table>';
    }
}
Ejemplo n.º 2
0
         s.added,
         c.available_from
       FROM users AS u
       LEFT JOIN submissions AS s ON s.user_id = u.id
       LEFT JOIN challenges AS c ON c.id = s.challenge
       WHERE
          u.competing = 1 AND
          s.challenge = :id AND
          s.correct = 1
       ORDER BY s.added ASC', array('id' => $_GET['id']));
 section_head($challenge['title']);
 $num_correct_solves = count($submissions);
 if (!$num_correct_solves) {
     echo lang_get('challenge_not_solved');
 } else {
     $user_count = get_num_participating_users();
     echo lang_get('challenge_solved_by_percentage', array('solve_percentage' => number_format($num_correct_solves / $user_count['num'] * 100, 1)));
     echo '
    <table class="challenge-table table table-striped table-hover">
    <thead>
    <tr>
      <th>', lang_get('position'), '</th>
      <th>', lang_get('team'), '</th>
      <th>', lang_get('solved'), '</th>
    </tr>
    </thead>
    <tbody>
    ';
     $i = 1;
     foreach ($submissions as $submission) {
         echo '