Beispiel #1
0
function print_solved_challenges($user_id)
{
    validate_id($user_id);
    section_head(lang_get('solved_challenges'));
    $submissions = db_query_fetch_all('
        SELECT
           s.added,
           ((SELECT COUNT(*) FROM submissions AS ss WHERE ss.correct = 1 AND ss.added < s.added AND ss.challenge=s.challenge)+1) AS pos,
           ch.id AS challenge_id,
           ch.available_from,
           ch.title,
           ch.points,
           ca.title AS category_title
        FROM submissions AS s
        LEFT JOIN challenges AS ch ON ch.id = s.challenge
        LEFT JOIN categories AS ca ON ca.id = ch.category
        WHERE
           s.correct = 1 AND
           s.user_id = :user_id AND
           ch.exposed = 1 AND
           ca.exposed = 1
        ORDER BY s.added DESC', array('user_id' => $user_id));
    if (count($submissions)) {
        echo '
      <table class="table table-striped table-hover">
        <thead>
          <tr>
            <th>', lang_get('challenge'), '</th>
            <th>', lang_get('solved'), '</th>
            <th>', lang_get('points'), '</th>
          </tr>
        </thead>
        <tbody>
       ';
        foreach ($submissions as $submission) {
            echo '
              <tr>
                <td>
                    <a href="', CONFIG_SITE_URL, 'challenge?id=', htmlspecialchars($submission['challenge_id']), '">
                    ', htmlspecialchars($submission['title']), '
                    </a> (', htmlspecialchars($submission['category_title']), ')
                </td>

                <td>
                    ', get_position_medal($submission['pos'], true), '
                    ', time_elapsed($submission['added'], $submission['available_from']), ' ', lang_get('after_release'), ' (', date_time($submission['added']), ')
                </td>

                <td>', number_format($submission['points']), '</td>
              </tr>
              ';
        }
        echo '
        </tbody>
      </table>
          ';
    } else {
        message_inline_blue(lang_get('no_challenges_solved'));
    }
}
Beispiel #2
0
    <div class="panel ', $panel_class, ' challenge-container">
        <div class="panel-heading">
            <h4 class="challenge-head">
            <a href="challenge?id=', htmlspecialchars($challenge['id']), '">', htmlspecialchars($challenge['title']), '</a> (', number_format($challenge['points']), 'pts)';
    if ($challenge['correct_submission_added']) {
        $solve_position = db_query_fetch_one('
                    SELECT
                      COUNT(*)+1 AS pos
                    FROM
                      submissions AS s
                    WHERE
                      s.correct = 1 AND
                      s.added < :correct_submission_added AND
                      s.challenge = :challenge_id', array('correct_submission_added' => $challenge['correct_submission_added'], 'challenge_id' => $challenge['id']));
        echo ' <span class="glyphicon glyphicon-ok"></span>';
        echo get_position_medal($solve_position['pos']);
    }
    echo '</h4>';
    if (should_print_metadata($challenge)) {
        print_time_left_tooltip($challenge);
    }
    echo '</div>

    <div class="panel-body">';
    unset($relies_on);
    // if this challenge relies on another being solved, get the related information
    if ($challenge['relies_on']) {
        $relies_on = db_query_fetch_one('
            SELECT
              c.id,
              c.title,
Beispiel #3
0
            <th>Points</th>
          </tr>
        </thead>
        <tbody>
       ';
        foreach ($submissions as $submission) {
            echo '
              <tr>
                <td>
                    <a href="challenge?id=', htmlspecialchars($submission['challenge_id']), '">
                    ', htmlspecialchars($submission['title']), '
                    </a> (', htmlspecialchars($submission['category_title']), ')
                </td>

                <td>
                    ', get_position_medal($submission['pos'], true), '
                    ', time_elapsed($submission['added'], $submission['available_from']), ' after release (', date_time($submission['added']), ')
                </td>

                <td>', number_format($submission['points']), '</td>
              </tr>
              ';
        }
        echo '
        </tbody>
      </table>
          ';
    } else {
        echo '
      <div class="alert alert-info">
          No challenges solved, yet!
        echo 'This challenge has been solved by ', number_format($num_correct_solves / $user_count['num'] * 100, 1), '% of users.';
        echo '
       <table class="challenge-table table table-striped table-hover">
       <thead>
       <tr>
         <th>Position</th>
         <th>Team</th>
         <th>Solved</th>
       </tr>
       </thead>
       <tbody>
       ';
        $i = 1;
        foreach ($submissions as $submission) {
            echo '
              <tr>
                <td>', number_format($i), ' ', get_position_medal($i), '</td>
                <td class="team-name"><a href="user.php?id=', htmlspecialchars($submission['user_id']), '">', htmlspecialchars($submission['team_name']), '</a></td>
                <td>', time_elapsed($submission['added'], $submission['available_from']), ' after release (', date_time($submission['added']), ')</td>
              </tr>
              ';
            $i++;
        }
        echo '
       </tbody>
       </table>
         ';
    }
    cache_end('challenge_' . $_GET['id']);
}
foot();
Beispiel #5
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>';
    }
}
Beispiel #6
0
         $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>Unsolved</i>';
         }
         echo '
             </td>
         </tr>';
     }
     echo '
     </tbody>
     </table>';
 }
 echo '
     </div> <!-- / span6 -->
 </div> <!-- / row -->
Beispiel #7
0
 // and continue to next challenge
 if ($time < $challenge['available_from']) {
     echo '
     <div class="challenge-container">
         <h1><i>Hidden challenge worth ', number_format($challenge['points']), 'pts</i></h1>
         <i>Available in ', time_remaining($challenge['available_from']), ' (from ', date_time($challenge['available_from']), ' until ', date_time($challenge['available_until']), ')</i>
     </div>';
     continue;
 }
 $remaining_submissions = $challenge['num_attempts_allowed'] ? $challenge['num_attempts_allowed'] - $challenge['num_submissions'] : 1;
 echo '
 <div class="challenge-container">
     <h1 class="challenge-head">
     <a href="challenge?id=', htmlspecialchars($challenge['id']), '">', htmlspecialchars($challenge['title']), '</a> (', number_format($challenge['points']), 'pts)';
 if ($challenge['correct']) {
     echo ' <img src="' . CONFIG_SITE_URL . 'img/accept.png" alt="Completed!" title="Completed!" /> ', get_position_medal($challenge['pos']);
 } else {
     if (!$remaining_submissions) {
         echo ' <img src="' . CONFIG_SITE_URL . 'img/stop.png" alt="No more submissions allowed" title="No more submissions allowed" /> ';
     }
 }
 echo '</h1>';
 // write out challenge description
 if ($challenge['description']) {
     echo '
     <div class="challenge-description">
         ', $bbc->parse($challenge['description']), '
     </div> <!-- / challenge-description -->';
 }
 // write out files
 if (cache_start('files_' . $challenge['id'], CONFIG_CACHE_TIME_FILES)) {