2004-12-08 22:05:56 +00:00
|
|
|
<?php
|
2004-06-30 18:53:35 +00:00
|
|
|
|
2004-12-08 22:05:56 +00:00
|
|
|
require_once("../inc/cache.inc");
|
|
|
|
require_once("../inc/util.inc");
|
|
|
|
require_once("../inc/team.inc");
|
2005-08-16 09:20:25 +00:00
|
|
|
require_once("../inc/db.inc");
|
|
|
|
require_once("../inc/translation.inc");
|
|
|
|
|
|
|
|
define (ITEMS_PER_PAGE, 20);
|
|
|
|
define (ITEM_LIMIT,10000);
|
2004-06-30 18:53:35 +00:00
|
|
|
|
2005-08-16 09:20:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
function get_top_teams($offset,$sort_by,$type=""){ //Possibly move this to db.inc at some point...
|
|
|
|
if ($type){
|
|
|
|
$type_sql = "where type=".(int)$type;
|
|
|
|
}
|
|
|
|
if ($sort_by == "total_credit") {
|
|
|
|
$sort_order = "total_credit desc";
|
|
|
|
} else {
|
|
|
|
$sort_order = "expavg_credit desc";
|
|
|
|
}
|
|
|
|
$res=mysql_query("select * from team $type_sql order by $sort_order limit $offset,".ITEMS_PER_PAGE);
|
|
|
|
while ($arr[]=mysql_fetch_object($res)){};
|
|
|
|
return $arr;
|
|
|
|
}
|
|
|
|
|
|
|
|
function teams_to_store($participants){ //These converter functions are here in case we later decide to use something
|
|
|
|
return serialize($participants); //else than serializing to save temp data
|
|
|
|
}
|
|
|
|
function store_to_teams($data){
|
|
|
|
return unserialize($data);
|
|
|
|
}
|
2004-06-07 03:34:07 +00:00
|
|
|
|
2005-05-11 10:03:27 +00:00
|
|
|
if (isset($_GET["sort_by"])) {
|
|
|
|
$sort_by = $_GET["sort_by"];
|
|
|
|
} else {
|
|
|
|
$sort_by = "expavg_credit";
|
|
|
|
}
|
2005-08-16 09:20:25 +00:00
|
|
|
|
2005-02-19 08:06:53 +00:00
|
|
|
$type = get_int("type", true);
|
2004-12-08 22:05:56 +00:00
|
|
|
if ($type < 1 || $type > 7) {
|
|
|
|
$type = null;
|
|
|
|
}
|
2005-08-16 09:20:25 +00:00
|
|
|
$type_url="";$type_sql="";$type_name="";
|
2004-12-08 22:05:56 +00:00
|
|
|
if ($type) {
|
|
|
|
$type_url = "&type=$type";
|
|
|
|
$type_name = team_type_name($type);
|
|
|
|
}
|
2004-06-30 18:53:35 +00:00
|
|
|
|
2005-08-16 09:20:25 +00:00
|
|
|
|
|
|
|
$offset = get_int("offset", true);
|
|
|
|
if (!$offset) $offset=0;
|
2004-12-08 22:05:56 +00:00
|
|
|
if ($offset % $n) $offset = 0;
|
2003-09-08 00:04:55 +00:00
|
|
|
|
2005-08-16 09:20:25 +00:00
|
|
|
if ($offset < ITEM_LIMIT) {
|
|
|
|
$cache_args = "sort_by=$sort_by&offset=$offset&type=$type";
|
|
|
|
$cacheddata=get_cached_data(TOP_PAGES_TTL,$cache_args);
|
|
|
|
if ($cacheddata){ //If we have got the data in cache
|
|
|
|
$data = store_to_teams($cacheddata); // use the cached data
|
|
|
|
} else { //if not do queries etc to generate new data
|
|
|
|
db_init();
|
|
|
|
$data = get_top_teams($offset,$sort_by,$type);
|
|
|
|
set_cache_data(teams_to_store($data),$cache_args); //save data in cache
|
|
|
|
};
|
2004-12-08 22:05:56 +00:00
|
|
|
} else {
|
2005-08-16 09:20:25 +00:00
|
|
|
error_page("Limit exceeded - Sorry, first ".ITEM_LIMIT." items only");
|
2004-12-08 22:05:56 +00:00
|
|
|
}
|
2002-11-11 19:40:22 +00:00
|
|
|
|
2004-12-08 22:05:56 +00:00
|
|
|
|
2005-08-16 09:20:25 +00:00
|
|
|
//Now display what we've got (either gotten from cache or from DB)
|
|
|
|
page_head(sprintf(tr(TOP_TEAMS_TITLE),$type_name));
|
2004-12-08 22:05:56 +00:00
|
|
|
start_table();
|
2005-08-16 09:20:25 +00:00
|
|
|
team_table_start($sort_by,$type_url);
|
|
|
|
$i = 1 + $offset;
|
|
|
|
$o = 0;
|
|
|
|
while ($team = $data[$o]) {
|
|
|
|
show_team_row($team, $i);
|
|
|
|
$i++;
|
|
|
|
$o++;
|
2004-12-08 22:05:56 +00:00
|
|
|
}
|
2005-08-16 09:20:25 +00:00
|
|
|
echo "</table>\n<p>";
|
2004-12-08 22:05:56 +00:00
|
|
|
if ($offset > 0) {
|
2005-08-16 09:20:25 +00:00
|
|
|
$new_offset = $offset - ITEMS_PER_PAGE;
|
|
|
|
echo "<a href=top_teams.php?sort_by=$sort_by&offset=$new_offset".$type_url.">Previous ".ITEMS_PER_PAGE."</a> | ";
|
2004-06-07 03:34:07 +00:00
|
|
|
|
2004-12-08 22:05:56 +00:00
|
|
|
}
|
2005-09-07 16:00:27 +00:00
|
|
|
if ($o==ITEMS_PER_PAGE){ //If we aren't on the last page
|
|
|
|
$new_offset = $offset + ITEMS_PER_PAGE;
|
|
|
|
echo "<a href=top_teams.php?sort_by=$sort_by&offset=$new_offset".$type_url.">Next ".ITEMS_PER_PAGE."</a>";
|
|
|
|
}
|
2005-08-16 09:20:25 +00:00
|
|
|
page_tail();
|
2004-06-07 03:34:07 +00:00
|
|
|
|
2004-04-14 20:55:37 +00:00
|
|
|
|
2004-12-08 22:05:56 +00:00
|
|
|
?>
|