2002-11-12 17:01:16 +00:00
|
|
|
<?php
|
2008-08-05 22:43:14 +00:00
|
|
|
// This file is part of BOINC.
|
|
|
|
// http://boinc.berkeley.edu
|
|
|
|
// Copyright (C) 2008 University of California
|
|
|
|
//
|
|
|
|
// BOINC is free software; you can redistribute it and/or modify it
|
|
|
|
// under the terms of the GNU Lesser General Public License
|
|
|
|
// as published by the Free Software Foundation,
|
|
|
|
// either version 3 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// BOINC is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
// See the GNU Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
|
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
|
|
|
|
2011-02-09 22:11:34 +00:00
|
|
|
check_get_args(array("sort_by", "offset"));
|
|
|
|
|
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
|
|
|
}
|
2008-09-16 23:06:37 +00:00
|
|
|
|
2007-07-05 11:14:10 +00:00
|
|
|
function store_to_hosts($data){
|
|
|
|
return unserialize($data);
|
|
|
|
}
|
2004-04-14 20:55:37 +00:00
|
|
|
|
2008-09-16 23:06:37 +00:00
|
|
|
$sort_by = get_str("sort_by", true);
|
|
|
|
switch ($sort_by) {
|
|
|
|
case "total_credit":
|
|
|
|
case "expavg_credit":
|
|
|
|
break;
|
|
|
|
default:
|
2005-05-11 10:07:15 +00:00
|
|
|
$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
|
|
|
|
2009-03-05 22:12:21 +00:00
|
|
|
if ($offset >= ITEM_LIMIT) {
|
2010-02-16 01:06:03 +00:00
|
|
|
error_page(tra("Limit exceeded - Sorry, first %1 items only", ITEM_LIMIT));
|
2005-02-19 08:06:53 +00:00
|
|
|
}
|
2002-11-12 17:01:16 +00:00
|
|
|
|
2009-03-05 22:12:21 +00:00
|
|
|
$cache_args = "sort_by=$sort_by&offset=$offset";
|
|
|
|
$cacheddata = get_cached_data(TOP_PAGES_TTL, $cache_args);
|
|
|
|
if ($cacheddata){
|
|
|
|
$data = store_to_hosts($cacheddata);
|
|
|
|
} else {
|
|
|
|
$data = get_top_hosts($offset,$sort_by);
|
2011-03-12 15:36:58 +00:00
|
|
|
set_cached_data(TOP_PAGES_TTL, hosts_to_store($data), $cache_args);
|
2009-03-05 22:12:21 +00:00
|
|
|
};
|
|
|
|
|
2005-02-19 08:06:53 +00:00
|
|
|
|
2009-03-05 22:12:21 +00:00
|
|
|
// Now display what we've got (either gotten from cache or from DB)
|
|
|
|
//
|
2007-11-02 14:43:02 +00:00
|
|
|
page_head(tra("Top hosts"));
|
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;
|
2010-02-16 01:06:03 +00:00
|
|
|
echo "<a href=top_hosts.php?sort_by=$sort_by&offset=$new_offset>".tra("Previous %1", $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;
|
2010-02-16 01:06:03 +00:00
|
|
|
echo "<a href=top_hosts.php?sort_by=$sort_by&offset=$new_offset>".tra("Next %1", $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
|
|
|
?>
|