2005-02-19 08:06:53 +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");
|
2005-06-23 20:34:53 +00:00
|
|
|
require_once("../inc/user.inc");
|
2007-10-29 16:38:25 +00:00
|
|
|
require_once("../inc/boinc_db.inc");
|
2005-06-23 20:34:53 +00:00
|
|
|
|
2007-10-26 03:57:07 +00:00
|
|
|
$config = get_config();
|
|
|
|
$users_per_page = parse_config($config, "<users_per_page>");
|
|
|
|
if (!$users_per_page) {
|
|
|
|
$users_per_page = 20;
|
|
|
|
}
|
2007-10-29 16:38:25 +00:00
|
|
|
define ('ITEM_LIMIT', 10000);
|
2005-08-16 09:20:25 +00:00
|
|
|
|
2007-11-05 23:55:33 +00:00
|
|
|
function get_top_participants($offset, $sort_by) {
|
2007-10-26 03:57:07 +00:00
|
|
|
global $users_per_page;
|
2007-10-29 16:38:25 +00:00
|
|
|
$db = BoincDb::get(true);
|
2005-06-23 20:34:53 +00:00
|
|
|
if ($sort_by == "total_credit") {
|
2007-10-26 03:57:07 +00:00
|
|
|
$sort_order = "total_credit desc";
|
2005-06-23 20:34:53 +00:00
|
|
|
} else {
|
|
|
|
$sort_order = "expavg_credit desc";
|
|
|
|
}
|
2007-10-29 16:38:25 +00:00
|
|
|
return BoincUser::enum(null, "order by $sort_order limit $offset,$users_per_page");
|
2005-06-23 20:34:53 +00:00
|
|
|
}
|
2004-06-07 03:34:07 +00:00
|
|
|
|
2007-11-05 23:55:33 +00:00
|
|
|
function user_table_start($sort_by) {
|
|
|
|
start_table();
|
|
|
|
echo "
|
|
|
|
<tr>
|
|
|
|
<th>".tra("Rank")."</th>
|
|
|
|
<th>".tra("Name")."</th>
|
|
|
|
";
|
|
|
|
if ($sort_by == "total_credit") {
|
|
|
|
echo "
|
|
|
|
<th><a href=top_users.php?sort_by=expavg_credit>".tra("Recent average credit")."</a></th>
|
|
|
|
<th>".tra("Total credit")."</th>
|
|
|
|
";
|
|
|
|
} else {
|
|
|
|
echo "
|
|
|
|
<th>".tra("Recent average credit")."</th>
|
|
|
|
<th><a href=top_users.php?sort_by=total_credit>".tra("Total credit")."</a></th>
|
|
|
|
";
|
|
|
|
}
|
|
|
|
echo "
|
|
|
|
<th>".tra("Country")."</th>
|
|
|
|
<th>".tra("Participant since")."</th>
|
|
|
|
</tr>
|
|
|
|
";
|
2005-06-23 20:34:53 +00:00
|
|
|
}
|
2007-11-05 23:55:33 +00:00
|
|
|
|
|
|
|
function show_user_row($user, $i) {
|
|
|
|
echo "
|
|
|
|
<tr class=row1>
|
|
|
|
<td>$i</td>
|
|
|
|
<td>", user_links($user), "</td>
|
2009-01-30 22:30:35 +00:00
|
|
|
<td align=right>", format_credit_large($user->expavg_credit), "</td>
|
2007-11-05 23:55:33 +00:00
|
|
|
<td align=right>", format_credit_large($user->total_credit), "</td>
|
|
|
|
<td>", $user->country, "</td>
|
|
|
|
<td>", time_str($user->create_time),"</td>
|
|
|
|
</tr>
|
|
|
|
";
|
2005-06-23 20:34:53 +00:00
|
|
|
}
|
2004-06-07 03:34:07 +00:00
|
|
|
|
2008-09-07 07:40:56 +00:00
|
|
|
$sort_by = get_str("sort_by", true);
|
|
|
|
switch ($sort_by) {
|
|
|
|
case "total_credit":
|
|
|
|
case "expavg_credit":
|
|
|
|
break;
|
|
|
|
default:
|
2005-05-11 10:26:53 +00:00
|
|
|
$sort_by = "expavg_credit";
|
|
|
|
}
|
2005-06-23 20:34:53 +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 % $users_per_page) $offset = 0;
|
2005-02-19 08:06:53 +00:00
|
|
|
|
2005-06-23 20:34:53 +00:00
|
|
|
if ($offset < ITEM_LIMIT) {
|
2005-02-19 08:06:53 +00:00
|
|
|
$cache_args = "sort_by=$sort_by&offset=$offset";
|
2005-08-16 09:20:25 +00:00
|
|
|
$cacheddata=get_cached_data(TOP_PAGES_TTL,$cache_args);
|
2007-10-26 03:57:07 +00:00
|
|
|
|
|
|
|
// Do we have the data in cache?
|
|
|
|
//
|
|
|
|
if ($cacheddata){
|
2007-11-05 23:55:33 +00:00
|
|
|
$data = unserialize($cacheddata); // use the cached data
|
2007-10-26 03:57:07 +00:00
|
|
|
} else {
|
|
|
|
//if not do queries etc to generate new data
|
2007-10-29 16:38:25 +00:00
|
|
|
$data = get_top_participants($offset, $sort_by);
|
2007-10-26 03:57:07 +00:00
|
|
|
|
|
|
|
//save data in cache
|
|
|
|
//
|
2007-11-05 23:55:33 +00:00
|
|
|
set_cache_data(serialize($data),$cache_args);
|
2007-10-26 03:57:07 +00:00
|
|
|
}
|
2005-02-19 08:06:53 +00:00
|
|
|
} else {
|
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
|
|
|
}
|
2004-04-14 20:55:37 +00:00
|
|
|
|
2007-10-26 03:57:07 +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 participants"));
|
2005-02-19 08:06:53 +00:00
|
|
|
user_table_start($sort_by);
|
|
|
|
$i = 1 + $offset;
|
2007-10-29 16:38:25 +00:00
|
|
|
$n = sizeof($data);
|
|
|
|
foreach ($data as $user) {
|
2005-08-16 09:20:25 +00:00
|
|
|
show_user_row($user, $i);
|
|
|
|
$i++;
|
2005-02-19 08:06:53 +00:00
|
|
|
}
|
2005-08-16 09:20:25 +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 - $users_per_page;
|
2010-02-16 01:06:03 +00:00
|
|
|
echo "<a href=top_users.php?sort_by=$sort_by&offset=$new_offset>".tra("Previous %1", $users_per_page)."</a> | ";
|
2004-06-07 03:34:07 +00:00
|
|
|
|
2005-02-19 08:06:53 +00:00
|
|
|
}
|
2007-10-29 16:38:25 +00:00
|
|
|
if ($n==$users_per_page){ //If we aren't on the last page
|
2007-10-26 03:57:07 +00:00
|
|
|
$new_offset = $offset + $users_per_page;
|
2010-02-16 01:06:03 +00:00
|
|
|
echo "<a href=top_users.php?sort_by=$sort_by&offset=$new_offset>".tra("Next %1", $users_per_page)."</a>";
|
2005-09-07 16:00:27 +00:00
|
|
|
}
|
2005-06-23 20:34:53 +00:00
|
|
|
|
|
|
|
page_tail();
|
2004-04-14 20:55:37 +00:00
|
|
|
|
2005-02-19 08:06:53 +00:00
|
|
|
?>
|