2002-11-12 17:01:16 +00:00
|
|
|
<?php
|
2004-06-30 18:53:35 +00:00
|
|
|
|
2005-02-19 08:06:53 +00:00
|
|
|
require_once("../inc/cache.inc");
|
|
|
|
require_once("../inc/util.inc");
|
2007-07-05 11:14:10 +00:00
|
|
|
require_once("../inc/user.inc");
|
|
|
|
require_once("../inc/host.inc");
|
2007-10-29 16:38:25 +00:00
|
|
|
require_once("../inc/boinc_db.inc");
|
2007-07-05 11:14:10 +00:00
|
|
|
require_once("../inc/translation.inc");
|
|
|
|
|
2007-10-26 03:57:07 +00:00
|
|
|
$config = get_config();
|
|
|
|
$hosts_per_page = parse_config($config, "<hosts_per_page>");
|
|
|
|
if (!$hosts_per_page) {
|
2007-10-28 15:03:14 +00:00
|
|
|
$hosts_per_page = 20;
|
2007-10-26 03:57:07 +00:00
|
|
|
}
|
2007-10-28 15:03:14 +00:00
|
|
|
define ('ITEM_LIMIT', 10000);
|
2007-07-05 11:14:10 +00:00
|
|
|
|
2007-10-28 15:03:14 +00:00
|
|
|
function get_top_hosts($offset, $sort_by) {
|
2007-10-26 03:57:07 +00:00
|
|
|
global $hosts_per_page;
|
2007-10-29 16:38:25 +00:00
|
|
|
$db = BoincDb::get(true);
|
2007-07-05 11:14:10 +00:00
|
|
|
if ($sort_by == "total_credit") {
|
2007-10-28 15:03:14 +00:00
|
|
|
$sort_order = "total_credit desc";
|
2007-07-05 11:14:10 +00:00
|
|
|
} else {
|
|
|
|
$sort_order = "expavg_credit desc";
|
|
|
|
}
|
2007-10-28 15:03:14 +00:00
|
|
|
return BoincHost::enum(null, "order by $sort_order limit $offset, $hosts_per_page");
|
2007-07-05 11:14:10 +00:00
|
|
|
}
|
2004-06-07 03:34:07 +00:00
|
|
|
|
2007-10-28 15:03:14 +00:00
|
|
|
function hosts_to_store($participants){
|
|
|
|
return serialize($participants);
|
2007-07-05 11:14:10 +00:00
|
|
|
}
|
|
|
|
function store_to_hosts($data){
|
|
|
|
return unserialize($data);
|
|
|
|
}
|
2004-04-14 20:55:37 +00:00
|
|
|
|
2005-05-11 10:07:15 +00:00
|
|
|
if (isset($_GET["sort_by"])) {
|
|
|
|
$sort_by = $_GET["sort_by"];
|
|
|
|
} else {
|
|
|
|
$sort_by = "expavg_credit";
|
|
|
|
}
|
2007-07-05 11:14:10 +00:00
|
|
|
|
2005-02-19 08:06:53 +00:00
|
|
|
$offset = get_int("offset", true);
|
|
|
|
if (!$offset) $offset=0;
|
2007-10-26 03:57:07 +00:00
|
|
|
if ($offset % $hosts_per_page) $offset = 0;
|
2004-06-30 18:53:35 +00:00
|
|
|
|
2007-07-05 11:14:10 +00:00
|
|
|
if ($offset < ITEM_LIMIT) {
|
2005-02-19 08:06:53 +00:00
|
|
|
$cache_args = "sort_by=$sort_by&offset=$offset";
|
2007-07-05 11:14:10 +00:00
|
|
|
$cacheddata=get_cached_data(TOP_PAGES_TTL,$cache_args);
|
|
|
|
if ($cacheddata){ //If we have got the data in cache
|
2007-10-28 15:03:14 +00:00
|
|
|
$data = store_to_hosts($cacheddata); // use the cached data
|
2007-07-05 11:14:10 +00:00
|
|
|
} else { //if not do queries etc to generate new data
|
2007-10-28 15:03:14 +00:00
|
|
|
$data = get_top_hosts($offset,$sort_by);
|
|
|
|
set_cache_data(hosts_to_store($data),$cache_args); //save data in cache
|
2007-07-05 11:14:10 +00:00
|
|
|
};
|
2005-02-19 08:06:53 +00:00
|
|
|
} else {
|
2007-07-05 11:14:10 +00:00
|
|
|
error_page("Limit exceeded - Sorry, first ".ITEM_LIMIT." items only");
|
2005-02-19 08:06:53 +00:00
|
|
|
}
|
2002-11-12 17:01:16 +00:00
|
|
|
|
2005-02-19 08:06:53 +00:00
|
|
|
|
2007-07-05 11:14:10 +00:00
|
|
|
//Now display what we've got (either gotten from cache or from DB)
|
|
|
|
page_head(tr(TOP_HOST_TITLE));
|
2005-02-19 08:06:53 +00:00
|
|
|
top_host_table_start($sort_by);
|
2007-07-05 11:14:10 +00:00
|
|
|
$i = 1 + $offset;
|
2007-10-28 15:03:14 +00:00
|
|
|
$n = sizeof($data);
|
|
|
|
foreach($data as $host) {
|
2007-07-05 11:14:10 +00:00
|
|
|
show_host_row($host, $i, false, true);
|
|
|
|
$i++;
|
2005-02-19 08:06:53 +00:00
|
|
|
}
|
2007-07-05 11:14:10 +00:00
|
|
|
echo "</table>\n<p>";
|
2005-02-19 08:06:53 +00:00
|
|
|
if ($offset > 0) {
|
2007-10-26 03:57:07 +00:00
|
|
|
$new_offset = $offset - $hosts_per_page;
|
|
|
|
echo "<a href=top_hosts.php?sort_by=$sort_by&offset=$new_offset>Previous ".$hosts_per_page."</a> | ";
|
2005-02-19 08:06:53 +00:00
|
|
|
|
|
|
|
}
|
2007-10-28 15:03:14 +00:00
|
|
|
if ($n==$hosts_per_page){ //If we aren't on the last page
|
2007-10-26 03:57:07 +00:00
|
|
|
$new_offset = $offset + $hosts_per_page;
|
|
|
|
echo "<a href=top_hosts.php?sort_by=$sort_by&offset=$new_offset>Next ".$hosts_per_page."</a>";
|
2005-02-19 08:06:53 +00:00
|
|
|
}
|
2003-11-30 21:05:57 +00:00
|
|
|
|
2007-07-05 11:14:10 +00:00
|
|
|
page_tail();
|
|
|
|
|
|
|
|
|
2002-11-12 17:01:16 +00:00
|
|
|
?>
|