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 " );
require_once ( " ../inc/translation.inc " );
define ( ITEMS_PER_PAGE , 20 );
define ( ITEM_LIMIT , 10000 );
function get_top_participants ( $offset , $sort_by ){ //Possibly move this to db.inc at some point...
db_init ();
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-06-23 20:34:53 +00:00
function participants_to_store ( $participants ){ //These converter functions are here in case we later decide to use something else than serializing to save temp data
return serialize ( $participants );
}
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 ;
if ( $offset % $n ) $offset = 0 ;
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-06-23 20:34:53 +00:00
$cacheddata = get_cached_data ( 10 , $cache_args );
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
require_once ( " ../inc/db.inc " );
require_once ( " ../inc/user.inc " );
$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 ]) {
2003-09-08 00:12:37 +00:00
if ( $sort_by == " total_credit " ) {
2005-02-19 08:06:53 +00:00
show_user_row ( $user , $i );
$i ++ ;
2003-09-08 00:12:37 +00:00
} else {
2005-02-19 08:06:53 +00:00
if ( ! user_inactive_ndays ( $user , 7 )) {
2004-11-01 23:10:02 +00:00
show_user_row ( $user , $i );
$i ++ ;
}
2002-11-08 17:21:45 +00:00
}
2005-06-23 20:34:53 +00:00
$o ++ ;
2005-02-19 08:06:53 +00:00
}
echo " </table> \n " ;
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-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 >Next " . ITEMS_PER_PAGE . " </a> " ;
page_tail ();
2004-04-14 20:55:37 +00:00
2005-02-19 08:06:53 +00:00
?>