2005-02-19 08:06:53 +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");
|
2005-06-23 20:34:53 +00:00
|
|
|
require_once("../inc/user.inc");
|
2005-08-16 09:20:25 +00:00
|
|
|
require_once("../inc/db.inc");
|
2005-06-23 20:34:53 +00:00
|
|
|
require_once("../inc/translation.inc");
|
|
|
|
|
|
|
|
define (ITEMS_PER_PAGE, 20);
|
|
|
|
define (ITEM_LIMIT,10000);
|
|
|
|
|
2005-08-16 09:20:25 +00:00
|
|
|
|
|
|
|
|
2005-06-23 20:34:53 +00:00
|
|
|
function get_top_participants($offset,$sort_by){ //Possibly move this to db.inc at some point...
|
|
|
|
if ($sort_by == "total_credit") {
|
|
|
|
$sort_order = "total_credit desc";
|
|
|
|
} else {
|
|
|
|
$sort_order = "expavg_credit desc";
|
|
|
|
}
|
|
|
|
$res=mysql_query("select * from user order by $sort_order limit $offset,".ITEMS_PER_PAGE);
|
|
|
|
while ($arr[]=mysql_fetch_object($res)){};
|
|
|
|
return $arr;
|
|
|
|
}
|
2004-06-07 03:34:07 +00:00
|
|
|
|
2005-08-16 09:20:25 +00:00
|
|
|
function participants_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
|
2005-06-23 20:34:53 +00:00
|
|
|
}
|
|
|
|
function store_to_participants($data){
|
|
|
|
return unserialize($data);
|
|
|
|
}
|
2004-06-07 03:34:07 +00:00
|
|
|
|
2005-05-11 10:26:53 +00:00
|
|
|
if (isset($_GET["sort_by"])) {
|
|
|
|
$sort_by = $_GET["sort_by"];
|
|
|
|
} else {
|
|
|
|
$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;
|
2006-09-13 03:39:30 +00:00
|
|
|
if ($offset % ITEMS_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);
|
2005-06-23 20:34:53 +00:00
|
|
|
if ($cacheddata){ //If we have got the data in cache
|
|
|
|
$data = store_to_participants($cacheddata); // use the cached data
|
|
|
|
} else { //if not do queries etc to generate new data
|
2005-08-16 09:20:25 +00:00
|
|
|
db_init();
|
2005-06-23 20:34:53 +00:00
|
|
|
$data = get_top_participants($offset,$sort_by);
|
|
|
|
set_cache_data(participants_to_store($data),$cache_args); //save data in cache
|
|
|
|
};
|
2005-02-19 08:06:53 +00:00
|
|
|
} else {
|
2005-06-23 20:34:53 +00:00
|
|
|
error_page("Limit exceeded - Sorry, first ".ITEM_LIMIT." items only");
|
2005-02-19 08:06:53 +00:00
|
|
|
}
|
2004-04-14 20:55:37 +00:00
|
|
|
|
2005-02-19 08:06:53 +00:00
|
|
|
|
2005-06-23 20:34:53 +00:00
|
|
|
//Now display what we've got (either gotten from cache or from DB)
|
|
|
|
page_head(tr(TOP_PARTICIPANT_TITLE));
|
2005-02-19 08:06:53 +00:00
|
|
|
user_table_start($sort_by);
|
|
|
|
$i = 1 + $offset;
|
2005-06-23 20:34:53 +00:00
|
|
|
$o = 0;
|
|
|
|
while ($user = $data[$o]) {
|
2005-08-16 09:20:25 +00:00
|
|
|
show_user_row($user, $i);
|
|
|
|
$i++;
|
2005-06-23 20:34:53 +00:00
|
|
|
$o++;
|
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) {
|
2005-06-23 20:34:53 +00:00
|
|
|
$new_offset = $offset - ITEMS_PER_PAGE;
|
|
|
|
echo "<a href=top_users.php?sort_by=$sort_by&offset=$new_offset>Previous ".ITEMS_PER_PAGE."</a> | ";
|
2004-06-07 03:34:07 +00:00
|
|
|
|
2005-02-19 08:06:53 +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_users.php?sort_by=$sort_by&offset=$new_offset>Next ".ITEMS_PER_PAGE."</a>";
|
|
|
|
}
|
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
|
|
|
|
|
|
|
?>
|