function getSubmissionTableString($user_id, $viewmore = true, $viewresults = 10, $viewlink, $page = 0)
{
    // Avoid SQL injections
    if (!filter_var($user_id, FILTER_VALIDATE_INT)) {
        return "";
    } else {
        $user_id = intval($user_id);
    }
    if (!filter_var($page, FILTER_VALIDATE_INT)) {
        $page = 0;
    } else {
        $page = intval($page);
    }
    // Fetch row count
    $rowcount_query = <<<EOT
select
    count(1)
from
    submissions r
    inner join submissions s on s.submission_id = r.submission_id
    inner join users u on u.user_id = s.user_id
where
    u.user_id = {$user_id}
EOT;
    $rowcount_data = mysql_query($rowcount_query);
    if ($rowcount_data) {
        list($rowcount) = mysql_fetch_row($rowcount_data);
    } else {
        $rowcount = 0;
    }
    // Fetch submission data
    $submission_query = <<<EOT
select
    s.status,
    date_format(s.timestamp,'%b %D %H:%i:%S') as timestamp,
    l.name as language
from
    submissions r
    inner join submissions s on s.submission_id = r.submission_id
    inner join users u on u.user_id = s.user_id
    inner join languages l on l.language_id = s.language_id
where
    u.user_id = {$user_id}
    order by s.timestamp desc
EOT;
    if ($viewmore) {
        $submission_query .= " limit {$viewresults}";
    } else {
        if ($page != 0) {
            $submission_query .= " limit {$viewresults} OFFSET " . $viewresults * ($page - 1);
        }
    }
    $submission_results = mysql_query($submission_query);
    // If query fails
    if (!$submission_results || $rowcount == 0) {
        return "<p>No submissions available at this time.</p>";
    }
    // Build table
    $table = "";
    if (!$viewmore) {
        $table .= getPaginationString($page, $rowcount, $viewresults, $viewlink);
    }
    $table .= "<table class=\"submissions\"><thead><tr><th>Submission Time</th><th>Status</th><th>Language</th></tr></thead><tbody>";
    for ($i = 1; $row = mysql_fetch_assoc($submission_results); $i += 1) {
        $status = $row["status"];
        $status_class = $status == 40 ? "success" : ($status == 30 || $status > 40 ? "fail" : "inprogress");
        $status = $status == 10 ? "entry created in db" : ($status == 15 ? "temporary location, awaiting transfer" : ($status == 20 ? "ready to be compiled" : ($status == 24 ? "currently compiling" : ($status == 27 ? "compiled successfully, awaiting testing" : ($status == 30 ? "error receiving submission file" : ($status == 39 ? "garbage collected (<a class=\"error_code\" href=\"submission_errors.php?error={$status}\">more info</a>)" : ($status == 40 ? "successfully entered into contest" : ($status == 50 ? "error while unzipping submission" : ($status == 60 ? "problem with submission file" : ($status == 70 ? "error while compiling submission" : ($status == 80 ? "compiled successfully but failed test cases" : ($status >= 90 ? "submission suspended (<a class=\"error_code\" href=\"submission_errors.php?error={$status}\">more info</a>)" : "Unknown Error"))))))))))));
        $timestamp = $row["timestamp"];
        $language = $row["language"];
        $language_link = urlencode($language);
        $row_class = $i % 2 == 0 ? "even" : "odd";
        $table .= "<tr class=\"{$row_class}\">";
        $table .= "  <td>{$timestamp}</td>";
        $table .= "  <td class=\"{$status_class}\">{$status}</td>";
        $table .= "  <td><a href=\"language_profile.php?lang={$language_link}\">\n            {$language}</a></td>";
        $table .= "</tr>";
    }
    $table .= "</tbody></table>";
    if ($viewmore && $rowcount > $viewresults) {
        $table .= "<a href=\"{$viewlink}\">View More</a>";
    }
    return $table;
}
function getRankingsTableString($user_id, $viewmore = true, $viewresults = 10, $viewlink, $page = 0, $filter = null, $filterparam = null)
{
    // Avoid SQL injections
    if (!filter_var($user_id, FILTER_VALIDATE_INT)) {
        return "";
    } else {
        $user_id = intval($user_id);
    }
    if (!filter_var($page, FILTER_VALIDATE_INT)) {
        $page = 0;
    } else {
        $page = intval($page);
    }
    $user_id = mysql_real_escape_string($user_id);
    $page = mysql_real_escape_string($page);
    $filter = mysql_real_escape_string($filter);
    $filterparam = mysql_real_escape_string($filterparam);
    $page = $_GET["page"];
    if (!filter_var($page, FILTER_VALIDATE_INT)) {
        $page = 1;
    }
    $filter_text = $filter == NULL ? "" : "and {$filter} = '{$filterparam}'";
    /*
        $leaderboard_result = mysql_query("SELECT MAX(leaderboard_id) as id
       FROM leaderboards where complete=1");
        $row = mysql_fetch_assoc($leaderboard_result);
        $leaderboard_id = $row['id'];
    */
    $leaderboard_id = 159501;
    // Fetch row count
    $rowcount_query = <<<EOT
select
    count(1)
from
    rankings r 
    inner join submissions s on s.submission_id = r.submission_id
    inner join users u on u.user_id = s.user_id
    left outer join organizations o on o.org_id = u.org_id
    left outer join countries c on c.country_id = u.country_id
    inner join languages l on l.language_id = s.language_id
where
    leaderboard_id = {$leaderboard_id}
    {$filter_text}
EOT;
    $rowcount_data = mysql_query($rowcount_query);
    if ($rowcount_data) {
        list($rowcount) = mysql_fetch_row($rowcount_data);
    } else {
        $rowcount = 0;
    }
    // Fetch Only Rows Needed For Current Page
    $offset = $viewresults * ($page - 1);
    $rankings_query = <<<EOT
select
    u.user_id,
    u.username,
    s.*,
    r.*,
    c.country_id,
    c.name as country_name,
    c.flag_filename,
    o.org_id,
    o.name as org_name,
    l.language_id as language_id,
    l.name as programming_language,
    round(((r.wins + 0.5*r.draws)/(r.wins+r.draws+r.losses))*100, 2) as rank_percent
from
    rankings r 
    inner join submissions s on s.submission_id = r.submission_id
    inner join users u on u.user_id = s.user_id
    left outer join organizations o on o.org_id = u.org_id
    left outer join countries c on c.country_id = u.country_id
    inner join languages l on l.language_id = s.language_id
where
    leaderboard_id = {$leaderboard_id}
    {$filter_text}
order by
    rank asc
EOT;
    if ($viewmore) {
        $rankings_query .= " limit {$viewresults}";
    } else {
        if ($page != 0) {
            $rankings_query .= " limit {$viewresults} OFFSET " . $viewresults * ($page - 1);
        }
    }
    $rankings_results = mysql_query($rankings_query);
    // If query fails
    if (!$rankings_results || $rowcount == 0) {
        return "<p>Rankings are not available at the moment. Check back soon!</p>";
    }
    $pagination .= getPaginationString($page, $rowcount, $viewresults, $viewlink);
    $table = "";
    if ($filter != NULL) {
        $table .= "<a href=\"rankings.php\">&#0171; Back to Main Leaderboard</a>";
    }
    if (!$viewmore) {
        $table .= $pagination;
    }
    $table .= <<<EOT
<table class="leaderboard">
<thead>
<tr>
  <th>Rank</th>
  <!--<th>Score</th>-->
  <th>Username</th>
  <th>Country</th>
  <th>Organization</th>
  <th>Language</th>
  <th>Elo Score</th>
  <!--<th>Wins</th>-->
  <!--<th>Losses</th>-->
  <!--<th>Draws</th>-->
</tr>
</thead>
<tbody>
EOT;
    $old_score = 999999;
    $old_rank = -1;
    for ($i = 1; $row = mysql_fetch_assoc($rankings_results); $i += 1) {
        $username = htmlentities($row["username"]);
        $programming_language = $row["programming_language"];
        $score = $row["score"];
        $programming_language_link = urlencode($row["programming_language"]);
        $rank = $row["rank"];
        if ($score == $old_score) {
            $rank = $old_rank;
        }
        $old_score = $score;
        $old_rank = $rank;
        $rank = $filter == null ? $rank : $i + $offset . " <span title='Global Rank'>({$rank})</span>";
        $rank_percent = $row["rank_percent"];
        $wins = $row["wins"];
        $losses = $row["losses"];
        $draws = $row["draws"];
        $flag_filename = $row["flag_filename"];
        $country_id = $row["country_id"];
        $country_name = $row["country_name"];
        $country_name = $country_name == NULL ? "Unknown" : htmlentities($country_name);
        $org_name = htmlentities($row["org_name"]);
        $org_id = $row["org_id"];
        $user_id = $row["user_id"];
        $row_class = $i % 2 == 0 ? "even" : "odd";
        $flag_filename = $flag_filename == NULL ? "unk.png" : $flag_filename;
        $flag_filename = "<img alt=\"{$country_name}\" width=\"16\" height=\"11\" title=\"{$country_name}\" src=\"flags/{$flag_filename}\" />";
        if (current_username() == $username) {
            $table .= "  <tr class=\"{$row_class}, user\">\n";
        } else {
            $table .= "  <tr class=\"{$row_class}\">\n";
        }
        $table .= "    <td>{$rank}</td>\n";
        //$table .= "    <td>$rank_percent</td>\n";
        $table .= "    <td><a href=\"profile.php?user_id={$user_id}\">{$username}</a></td>\n";
        $table .= "    <td><a href=\"country_profile.php?country_id={$country_id}\">{$flag_filename}</a></td>";
        $table .= "    <td><a href=\"organization_profile.php?org_id={$org_id}\">{$org_name}</a></td>";
        $table .= "    <td><a href=\"language_profile.php?lang={$programming_language_link}\">{$programming_language}</a></td>";
        $table .= "    <td>{$score}</td>";
        //$table .= "    <td>$wins</td>";
        //$table .= "    <td>$losses</td>";
        //$table .= "    <td>$draws</td>";
        $table .= "  </tr>\n";
    }
    $table .= "</tbody></table>";
    if (!$viewmore) {
        $table .= $pagination;
    }
    if ($viewmore && $rowcount > $viewresults) {
        $table .= "<a href=\"{$viewlink}\">View More</a>";
    }
    return $table;
}
function getGamesTableString($user_id, $viewmore = true, $viewresults = 10, $viewlink, $page = 0)
{
    // Avoid SQL injections
    if (!filter_var($user_id, FILTER_VALIDATE_INT)) {
        return "";
    } else {
        $user_id = intval($user_id);
    }
    if (!filter_var($page, FILTER_VALIDATE_INT)) {
        $page = 0;
    } else {
        $page = intval($page);
    }
    // Fetch user's current submission's id
    $submission_query = <<<EOT
select
    max(s.submission_id) as id
from
    submissions s
where
    s.user_id = {$user_id}
EOT;
    $submission_data = mysql_query($submission_query);
    if ($submission_data) {
        list($submission) = mysql_fetch_row($submission_data);
    } else {
        $submission = -1;
    }
    // Fetch Row Count
    $rowcount_query = <<<EOT
select
    count(1)
from
    games g 
where
    (g.player_one = {$submission} or g.player_two = {$submission})
EOT;
    $rowcount_data = mysql_query($rowcount_query);
    if ($rowcount_data) {
        list($rowcount) = mysql_fetch_row($rowcount_data);
    } else {
        $rowcount = 0;
    }
    // Fetch Game Information For Users Current Submission
    $games_query = <<<EOT
(select
    u.username as opp_name,
    u.user_id as opp_id,
    g.game_id,
    g.draw,
    date_format(g.timestamp,'%b %D %H:%i:%S') as date,
    g.timestamp,
    if( g.draw = 0, 'Win', 'Draw' ) as outcome
    from
    games g USE INDEX (winner_3)
    inner join submissions s USE INDEX (submission_id) on s.submission_id = g.loser
    inner join users u USE INDEX (user_id) on u.user_id = s.user_id
    where g.winner = {$submission}
    )
union
(select
    u.username as opp_name,
    u.user_id as opp_id,
    g.game_id,
    g.draw,
    date_format(g.timestamp,'%b %D %H:%i:%S') as date,
    g.timestamp,
    if( g.draw = 0, 'Loss', 'Draw' ) as outcome
   from
    games g USE INDEX (loser_3)
    inner join submissions s USE INDEX (submission_id) on s.submission_id = g.winner
    inner join users u USE INDEX (user_id) on u.user_id = s.user_id
    where g.loser = {$submission} 
    )
union
(select
    u.username as opp_name,
    u.user_id as opp_id,
    g.game_id,
    g.draw,
    date_format(g.timestamp,'%b %D %H:%i:%S') as date,
    g.timestamp,
    'Draw' as outcome
   from
    games g
    inner join submissions s USE INDEX (submission_id)
        on s.submission_id = g.player_two
    inner join users u USE INDEX (user_id) on u.user_id = s.user_id
    where g.player_one = {$submission} AND g.draw = 1
    )
union
(select
    u.username as opp_name,
    u.user_id as opp_id,
    g.game_id,
    g.draw,
    date_format(g.timestamp,'%b %D %H:%i:%S') as date,
    g.timestamp,
    'Draw' as outcome
   from
    games g
    inner join submissions s USE INDEX (submission_id)
        on s.submission_id = g.player_one
    inner join users u USE INDEX (user_id) on u.user_id = s.user_id
    where g.player_two = {$submission} AND g.draw = 1
    )
order by
    timestamp desc
EOT;
    if ($viewmore) {
        $games_query .= " limit {$viewresults}";
    } else {
        if ($page != 0) {
            $games_query .= " limit {$viewresults} OFFSET " . $viewresults * ($page - 1);
        }
    }
    $games_results = mysql_query($games_query);
    // If query fails
    if (!$games_results || $rowcount == 0) {
        return "<p>No game information available at this time.</p>";
    }
    // Build table
    $table = "";
    if (!$viewmore) {
        $table .= getPaginationString($page, $rowcount, $viewresults, $viewlink);
    }
    $table .= "<table class=\"submissions\"><thead><tr><th>Time</th><th>Opponent</th><th>Outcome</th><th>&nbsp;</th></tr></thead>";
    $table .= "<tbody>";
    for ($i = 1; $row = mysql_fetch_assoc($games_results); $i += 1) {
        $opp_name = htmlspecialchars($row["opp_name"]);
        $opp_id = $row["opp_id"];
        $game_id = $row["game_id"];
        $outcome = $row["outcome"];
        $datetime = $row["date"];
        if ($row["draw"] == 1) {
            $outcome = "Draw";
        }
        if ($outcome == "Win") {
            $outcome_class = "game_win";
        } else {
            if ($outcome == "Loss") {
                $outcome_class = "game_loss";
            } else {
                $outcome_class = "game_draw";
            }
        }
        $timestamp = $row["timestamp"];
        $row_class = $i % 2 == 0 ? "even" : "odd";
        $table .= "  <tr class=\"{$row_class}\">";
        $table .= "    <td>{$datetime}</td>";
        $table .= "    <td><a href=\"profile.php?user_id={$opp_id}\">{$opp_name}</a></td>";
        $table .= "    <td class=\"{$outcome_class}\">{$outcome}</td>";
        $table .= "    <td><a href=\"visualizer.php?game_id={$game_id}\">View Game &gt;&gt;</a></td>";
        $table .= "  </tr>";
    }
    $table .= "</tbody></table>";
    if ($viewmore && $rowcount > $viewresults) {
        $table .= "<a href=\"{$viewlink}\">View More</a>";
    }
    return $table;
}
Example #4
0
function display_user_list()
{
    // if get_query_var('page') defined, use it as page number
    if (get_query_var('page') != '') {
        $page = (int) get_query_var('page');
    } else {
        // by default we show first page
        $page = 1;
    }
    $limit = get_option('wpu_users_per');
    // counting the offset
    $offset = ($page - 1) * $limit;
    // Get the authors from the database ordered by user nicename
    global $wpdb;
    $meta_values = wpu_get_roles();
    $query = "SELECT {$wpdb->users}.ID, {$wpdb->users}.user_nicename FROM {$wpdb->users} INNER JOIN {$wpdb->usermeta} ON {$wpdb->users}.ID = {$wpdb->usermeta}.user_id WHERE {$meta_values} ORDER BY {$wpdb->users}.user_nicename LIMIT {$offset}, {$limit}";
    $author_ids = $wpdb->get_results($query);
    $output = '';
    // Loop through each author
    foreach ($author_ids as $author) {
        // Get user data
        $curauth = get_userdata($author->ID);
        $output .= get_user_listing($curauth);
    }
    echo $output;
    // how many rows we have in database
    $totalitems = $wpdb->get_var("SELECT COUNT(ID) FROM {$wpdb->users} WHERE ID = ANY (SELECT user_id FROM {$wpdb->usermeta} WHERE {$meta_values})");
    $adjacents = 3;
    $concat = wpu_concat_index();
    echo getPaginationString($page, $totalitems, $limit, $adjacents, $concat);
}
if ($exclude_keywords != '') {
    $_url_cs_exclude = "&cs_exclude=" . $exclude_keywords;
} else {
    $_url_cs_exclude = '';
}
if (isset($new) && is_numeric($new)) {
    $newfilter = '&new=' . $new;
} else {
    $newfilter = '&new=1';
}
if ($catid == '') {
    $__category = '&category=' . $catid;
} else {
    $__category = '';
}
$_pages_navigation = getPaginationString($page, $totalitems, $limit, $adjacents = 1, $targetpage = get_option('siteurl'), $pagestring = "?page_id=29" . $newfilter . $brand_group_sql . "&color=" . $color . $__category . $_url_cs . $_url_cs_exact . $_url_cs_any . $_url_cs_exclude . $_url_666 . "&offset=", $filter_list);
echo "<div style='clear:both;'>" . $_pages_navigation . "</div>";
if ($new == '1') {
    //order by new first
    echo product_display_paginated(NULL, $group_type, $group_sql, $search_sql, $offset, $items_on_page, $orderby = '1');
} else {
    //order by best first
    echo product_display_paginated(NULL, $group_type, $group_sql, $search_sql, $offset, $items_on_page);
}
function getPaginationString($page = 1, $totalitems, $limit = 20, $adjacents = 1, $targetpage = "/", $pagestring = "?page=", $filter_list = '')
{
    //function to return the pagination string
    //getPaginationString($page = 1, $totalitems, $limit = 20, $adjacents = 1, $targetpage = get_option('siteurl'), $pagestring = "?brand=".$brandid."&category=".$catid."&offset=".$offset."&cs=".$keywords."&page_id=29");
    //defaults
    if (!$adjacents) {
        $adjacents = 1;
function pagination($offset, $totalitems, $items_on_page)
{
    // PAGINATION
    $page_id = $_GET['page_id'];
    $page = round($offset / $items_on_page) + 1;
    if (isset($_REQUEST['new']) && $_REQUEST['new'] != 1) {
        $totalitems = 400;
    }
    $limit = $items_on_page;
    if (isset($_GET['category']) && is_numeric($_GET['category'])) {
        $catid = $_GET['category'];
    } else {
        $catid = '';
    }
    // Brand filter
    if (isset($_GET['brand']) && is_numeric($_GET['brand'])) {
        $_brand = $_GET['brand'];
        $brand_group_sql = "&amp;brand=" . $_brand;
    } elseif (isset($_POST['brand']) && is_numeric($_POST['brand'])) {
        $_brand = $_POST['brand'];
        $brand_group_sql = "&amp;brand=" . $_brand;
    } else {
        $_brand = '';
        $brand_group_sql = '';
    }
    //$_pages_navigation = getPaginationString($page, $totalitems, $limit, $adjacents = 1, $targetpage = get_option('siteurl'), $pagestring = "?page_id=29".$newfilter.$brand_group_sql."&amp;color=".$color.$__category.$_url_cs.$_url_cs_exact.$_url_cs_any.$_url_cs_exclude.$_url_666."&amp;offset=", $filter_list, $new, $brand_group_sql,$_category,$color_url);
    $_pages_navigation = getPaginationString($page, $totalitems, $limit, $adjacents = 1, $targetpage = get_option('siteurl'), $pagestring = "?" . get_url_vars_amp2() . "offset=");
    if (isset($_GET['cartoonid']) && is_numeric($_GET['cartoonid'])) {
        $output = "";
    } else {
        $output = "<div style='clear:both;'>" . $_pages_navigation . "</div>";
    }
    return $output;
}
Example #7
0

<!-- main start -->
<div id="content">
<div id="contentmiddle">


	<!-- page navigator -->
	<?php 
$totalitems = 200;
if (isset($_GET['offset']) && is_numeric($_GET['offset'])) {
    $page = $_GET['offset'] / 20 + 1;
} else {
    $page = 1;
}
$_pages_navigation = getPaginationString($page, $totalitems, $limit, $adjacents = 1, $targetpage = "index.php", $pagestring = "?" . get_url_vars() . "offset=");
echo $_pages_navigation;
?>
	<!-- ///page navigator -->


<div id="container">
	<div id="slides">
        <!-- Slider -->
        <ul class="bjqs">
			<?php 
echo $licontent;
?>
		</ul>
</div> <!-- ///slides -->
</div> <!-- ///container -->