1<?php 2// This file is part of BOINC. 3// http://boinc.berkeley.edu 4// Copyright (C) 2008 University of California 5// 6// BOINC is free software; you can redistribute it and/or modify it 7// under the terms of the GNU Lesser General Public License 8// as published by the Free Software Foundation, 9// either version 3 of the License, or (at your option) any later version. 10// 11// BOINC is distributed in the hope that it will be useful, 12// but WITHOUT ANY WARRANTY; without even the implied warranty of 13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 14// See the GNU Lesser General Public License for more details. 15// 16// You should have received a copy of the GNU Lesser General Public License 17// along with BOINC. If not, see <http://www.gnu.org/licenses/>. 18 19require_once("../inc/cache.inc"); 20require_once("../inc/util.inc"); 21require_once("../inc/user.inc"); 22require_once("../inc/boinc_db.inc"); 23 24check_get_args(array("sort_by", "offset")); 25 26$config = get_config(); 27$users_per_page = parse_config($config, "<users_per_page>"); 28if (!$users_per_page) { 29 $users_per_page = 20; 30} 31define ('ITEM_LIMIT', 10000); 32 33function get_top_participants($offset, $sort_by) { 34 global $users_per_page; 35 $db = BoincDb::get(true); 36 if ($sort_by == "total_credit") { 37 $sort_order = "total_credit desc"; 38 } else { 39 $sort_order = "expavg_credit desc"; 40 } 41 return BoincUser::enum(null, "order by $sort_order limit $offset,$users_per_page"); 42} 43 44function user_table_start($sort_by) { 45 start_table('table-striped'); 46 $x = array(); 47 $x[] = tra("Rank"); 48 $x[] = tra("Name"); 49 if ($sort_by == "total_credit") { 50 $x[] = "<a href=top_users.php?sort_by=expavg_credit>".tra("Recent average credit")."</a>"; 51 $x[] = tra("Total credit"); 52 } else { 53 $x[] = tra("Recent average credit"); 54 $x[] = "<a href=top_users.php?sort_by=total_credit>".tra("Total credit")."</a>"; 55 } 56 $x[] = tra("Country"); 57 $x[] = tra("Participant since"); 58 $a = array(null, null, ALIGN_RIGHT, ALIGN_RIGHT, null, null); 59 row_heading_array($x, $a); 60} 61 62function show_user_row($user, $i) { 63 echo " 64 <tr> 65 <td>$i</td> 66 <td>", user_links($user, BADGE_HEIGHT_MEDIUM), "</td> 67 <td align=right>", format_credit_large($user->expavg_credit), "</td> 68 <td align=right>", format_credit_large($user->total_credit), "</td> 69 <td>", $user->country, "</td> 70 <td>", time_str($user->create_time),"</td> 71 </tr> 72 "; 73} 74 75$sort_by = get_str("sort_by", true); 76switch ($sort_by) { 77case "total_credit": 78case "expavg_credit": 79 break; 80default: 81 $sort_by = "expavg_credit"; 82} 83 84$offset = get_int("offset", true); 85if (!$offset) $offset=0; 86if ($offset % $users_per_page) $offset = 0; 87 88if ($offset < ITEM_LIMIT) { 89 $cache_args = "sort_by=$sort_by&offset=$offset"; 90 $cacheddata = get_cached_data(TOP_PAGES_TTL,$cache_args); 91 92 // Do we have the data in cache? 93 // 94 if ($cacheddata){ 95 $data = unserialize($cacheddata); // use the cached data 96 } else { 97 //if not do queries etc to generate new data 98 $data = get_top_participants($offset, $sort_by); 99 100 //save data in cache 101 // 102 set_cached_data(TOP_PAGES_TTL, serialize($data),$cache_args); 103 } 104} else { 105 error_page(tra("Limit exceeded - Sorry, first %1 items only", ITEM_LIMIT)); 106} 107 108// Now display what we've got (either gotten from cache or from DB) 109page_head(tra("Top participants")); 110user_table_start($sort_by); 111$i = 1 + $offset; 112$n = sizeof($data); 113foreach ($data as $user) { 114 show_user_row($user, $i); 115 $i++; 116} 117 118end_table(); 119 120if ($offset > 0) { 121 $new_offset = $offset - $users_per_page; 122 echo "<a href=top_users.php?sort_by=$sort_by&offset=$new_offset>".tra("Previous %1", $users_per_page)."</a> · "; 123 124} 125if ($n==$users_per_page){ //If we aren't on the last page 126 $new_offset = $offset + $users_per_page; 127 echo "<a href=top_users.php?sort_by=$sort_by&offset=$new_offset>".tra("Next %1", $users_per_page)."</a>"; 128} 129 130page_tail(); 131 132?> 133