function build_country_pages()
{
    $query = "select userid from profile";
    $result = mysql_query($query);
    $numIds = 0;
    // Build a multi-dimensional array of countries,
    // each element of which contains an array
    // of the userids who belong to those countries.
    // Format: array[country][index] = userid.
    while ($profile = mysql_fetch_object($result)) {
        $user = lookup_user_id($profile->userid);
        if (!$user) {
            continue;
        }
        if ($user->country) {
            $countryMembers[$user->country][] = $user->id;
            $numIds++;
        } else {
            $countryMembers['Other'][] = $user->id;
        }
    }
    mysql_free_result($result);
    //echo "$numIds users have profiles AND non-null country entries.<br>";
    $countries = array_keys($countryMembers);
    sort($countries);
    // Build the pages.
    // TODO: Define a constant for the desired number of rows per page.
    foreach ($countries as $country) {
        $baseFileName = "profile_country_" . get_legal_filename($country);
        $filePath = PROFILE_PATH;
        build_profile_pages($countryMembers[$country], "User Profiles from {$country}", $country, 5, 2, $filePath, $baseFileName, "../html/");
    }
    // Build the summary page linking to the individual country pages.
    build_country_summary_page($countryMembers);
    //echo "<br><a href=\"" . PROFILE_PATH . "profile_country.html\">View Summary Page</a>";
    //echo "<br><br>Done";
}
function build_country_pages()
{
    print_debug_msg("Beginning to build country pages...");
    $profiles = BoincProfile::enum_fields('userid');
    $numIds = 0;
    $countryMembers = array();
    // Build a multi-dimensional array of countries,
    // each element of which contains an array
    // of the userids who belong to those countries.
    // Format: array[country][index] = userid.
    foreach ($profiles as $profile) {
        $user = BoincUser::lookup_id($profile->userid);
        if (!$user) {
            continue;
        }
        // maybe we should delete the profile if user is non-existent anymore?
        if ($user->country) {
            $countryMembers[$user->country][] = $user->id;
            $numIds++;
        } else {
            $countryMembers['Other'][] = $user->id;
        }
    }
    print_debug_msg("{$numIds} users have profiles AND non-null country entries.");
    $countries = array_keys($countryMembers);
    sort($countries);
    // Build the pages.
    // TODO: Define a constant for the desired number of rows per page.
    foreach ($countries as $country) {
        $baseFileName = "profile_country_" . get_legal_filename($country);
        build_profile_pages($countryMembers[$country], "User Profiles from {$country}", $country, 5, 2, PROFILE_PATH, $baseFileName);
    }
    // Build the summary page linking to the individual country pages.
    build_country_summary_page($countryMembers);
    print_debug_msg("done building country pages");
}