diff --git a/checkin_notes b/checkin_notes index c955db0c5f..f971da39ed 100644 --- a/checkin_notes +++ b/checkin_notes @@ -9935,3 +9935,14 @@ David 25 Oct 2007 db_update.php user/ bossa_get_job.php + +David 25 Oct 2007 + - user web: added optional , and + elements to config.xml; + determine the number of entries to show per page + in top user/team/host lists + + html/user/ + top_users.php + top_teams.php + top_hosts.php diff --git a/html/user/top_hosts.php b/html/user/top_hosts.php index 678c3a9609..b94bf1e966 100644 --- a/html/user/top_hosts.php +++ b/html/user/top_hosts.php @@ -7,18 +7,22 @@ require_once("../inc/host.inc"); require_once("../inc/db.inc"); require_once("../inc/translation.inc"); -define (ITEMS_PER_PAGE, 20); +$config = get_config(); +$hosts_per_page = parse_config($config, ""); +if (!$hosts_per_page) { + $hosts_per_page = 20; +} define (ITEM_LIMIT,10000); - - -function get_top_hosts($offset,$sort_by){ //Possibly move this to db.inc at some point... +//Possibly move this to db.inc at some point... +function get_top_hosts($offset,$sort_by){ + global $hosts_per_page; if ($sort_by == "total_credit") { $sort_order = "total_credit desc"; } else { $sort_order = "expavg_credit desc"; } - $res=mysql_query("select * from host order by $sort_order limit $offset,".ITEMS_PER_PAGE); + $res=mysql_query("select * from host order by $sort_order limit $offset,".$hosts_per_page); echo mysql_error(); while ($arr[]=mysql_fetch_object($res)){}; return $arr; @@ -39,7 +43,7 @@ if (isset($_GET["sort_by"])) { $offset = get_int("offset", true); if (!$offset) $offset=0; -if ($offset % ITEMS_PER_PAGE) $offset = 0; +if ($offset % $hosts_per_page) $offset = 0; if ($offset < ITEM_LIMIT) { $cache_args = "sort_by=$sort_by&offset=$offset"; @@ -68,13 +72,13 @@ while ($host = $data[$o]) { } echo "\n

"; if ($offset > 0) { - $new_offset = $offset - ITEMS_PER_PAGE; - echo "Previous ".ITEMS_PER_PAGE." | "; + $new_offset = $offset - $hosts_per_page; + echo "Previous ".$hosts_per_page." | "; } -if ($o==ITEMS_PER_PAGE){ //If we aren't on the last page - $new_offset = $offset + ITEMS_PER_PAGE; - echo "Next ".ITEMS_PER_PAGE.""; +if ($o==$hosts_per_page){ //If we aren't on the last page + $new_offset = $offset + $hosts_per_page; + echo "Next ".$hosts_per_page.""; } page_tail(); diff --git a/html/user/top_teams.php b/html/user/top_teams.php index e1123e29cf..0abc07dfd4 100644 --- a/html/user/top_teams.php +++ b/html/user/top_teams.php @@ -6,12 +6,16 @@ require_once("../inc/team.inc"); require_once("../inc/db.inc"); require_once("../inc/translation.inc"); -define (ITEMS_PER_PAGE, 20); +$config = get_config(); +$teams_per_page = parse_config($config, ""); +if (!$teams_per_page) { + $teams_per_page = 20; +} define (ITEM_LIMIT,10000); - - -function get_top_teams($offset,$sort_by,$type=""){ //Possibly move this to db.inc at some point... +//Possibly move this to db.inc at some point... +function get_top_teams($offset,$sort_by,$type=""){ + global $teams_per_page; if ($type){ $type_sql = "where type=".(int)$type; } @@ -20,7 +24,7 @@ function get_top_teams($offset,$sort_by,$type=""){ //Possibly move this to db.in } else { $sort_order = "expavg_credit desc"; } - $res=mysql_query("select * from team $type_sql order by $sort_order limit $offset,".ITEMS_PER_PAGE); + $res = mysql_query("select * from team $type_sql order by $sort_order limit $offset,".$teams_per_page); while ($arr[]=mysql_fetch_object($res)){}; return $arr; } @@ -51,17 +55,18 @@ if ($type) { $type_name = team_type_name($type); } - $offset = get_int("offset", true); if (!$offset) $offset=0; -if ($offset % ITEMS_PER_PAGE) $offset = 0; +if ($offset % $teams_per_page) $offset = 0; if ($offset < ITEM_LIMIT) { $cache_args = "sort_by=$sort_by&offset=$offset&type=$type"; $cacheddata = get_cached_data(TOP_PAGES_TTL,$cache_args); - if ($cacheddata){ //If we have got the data in cache + //If we have got the data in cache + if ($cacheddata){ $data = store_to_teams($cacheddata); // use the cached data - } else { //if not do queries etc to generate new data + } else { + //if not do queries etc to generate new data db_init(true); $data = get_top_teams($offset,$sort_by,$type); @@ -71,7 +76,8 @@ if ($offset < ITEM_LIMIT) { $data[$o]->nusers = team_count_nusers($team->id); $o++; } - set_cache_data(teams_to_store($data),$cache_args); //save data in cache + //save data in cache + set_cache_data(teams_to_store($data),$cache_args); } } else { error_page("Limit exceeded - Sorry, first ".ITEM_LIMIT." items only"); @@ -91,13 +97,13 @@ while ($team = $data[$o]) { } echo "\n

"; if ($offset > 0) { - $new_offset = $offset - ITEMS_PER_PAGE; - echo "Previous ".ITEMS_PER_PAGE." | "; + $new_offset = $offset - $teams_per_page; + echo "Previous ".$teams_per_page." | "; } -if ($o==ITEMS_PER_PAGE){ //If we aren't on the last page - $new_offset = $offset + ITEMS_PER_PAGE; - echo "Next ".ITEMS_PER_PAGE.""; +if ($o==$teams_per_page){ //If we aren't on the last page + $new_offset = $offset + $teams_per_page; + echo "Next ".$teams_per_page.""; } page_tail(); diff --git a/html/user/top_users.php b/html/user/top_users.php index 45ca9a4abc..909e9ca2e2 100644 --- a/html/user/top_users.php +++ b/html/user/top_users.php @@ -6,24 +6,31 @@ require_once("../inc/user.inc"); require_once("../inc/db.inc"); require_once("../inc/translation.inc"); -define (ITEMS_PER_PAGE, 20); -define (ITEM_LIMIT,10000); +$config = get_config(); +$users_per_page = parse_config($config, ""); +if (!$users_per_page) { + $users_per_page = 20; +} +define (ITEM_LIMIT, 10000); - - -function get_top_participants($offset,$sort_by){ //Possibly move this to db.inc at some point... +// move this to db.inc at some point... +function get_top_participants($offset,$sort_by) { + global $users_per_page; if ($sort_by == "total_credit") { - $sort_order = "total_credit desc"; + $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); + $res = mysql_query("select * from user order by $sort_order limit $offset,".$users_per_page); while ($arr[]=mysql_fetch_object($res)){}; return $arr; } -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 +// These converter functions are here in case we later decide to use something +// else than serializing to save temp data +// +function participants_to_store($participants){ + return serialize($participants); } function store_to_participants($data){ return unserialize($data); @@ -37,24 +44,30 @@ if (isset($_GET["sort_by"])) { $offset = get_int("offset", true); if (!$offset) $offset=0; -if ($offset % ITEMS_PER_PAGE) $offset = 0; +if ($offset % $users_per_page) $offset = 0; if ($offset < ITEM_LIMIT) { $cache_args = "sort_by=$sort_by&offset=$offset"; $cacheddata=get_cached_data(TOP_PAGES_TTL,$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 - db_init(true); - $data = get_top_participants($offset,$sort_by); - set_cache_data(participants_to_store($data),$cache_args); //save data in cache - }; + + // Do we have the data in cache? + // + if ($cacheddata){ + $data = store_to_participants($cacheddata); // use the cached data + } else { + //if not do queries etc to generate new data + db_init(true); + $data = get_top_participants($offset,$sort_by); + + //save data in cache + // + set_cache_data(participants_to_store($data),$cache_args); + } } else { error_page("Limit exceeded - Sorry, first ".ITEM_LIMIT." items only"); } - -//Now display what we've got (either gotten from cache or from DB) +// Now display what we've got (either gotten from cache or from DB) page_head(tr(TOP_PARTICIPANT_TITLE)); user_table_start($sort_by); $i = 1 + $offset; @@ -66,16 +79,15 @@ while ($user = $data[$o]) { } echo "\n

"; if ($offset > 0) { - $new_offset = $offset - ITEMS_PER_PAGE; - echo "Previous ".ITEMS_PER_PAGE." | "; + $new_offset = $offset - $users_per_page; + echo "Previous ".$users_per_page." | "; } -if ($o==ITEMS_PER_PAGE){ //If we aren't on the last page - $new_offset = $offset + ITEMS_PER_PAGE; - echo "Next ".ITEMS_PER_PAGE.""; +if ($o==$users_per_page){ //If we aren't on the last page + $new_offset = $offset + $users_per_page; + echo "Next ".$users_per_page.""; } page_tail(); - ?>