.html"
// Also creates a summary page listing all countries which have profiled
// members, the number of such members, and links to the created pages for
// each country.
function build_country_pages() {
$query = "SELECT * 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 ($row = mysql_fetch_assoc($result)) {
$query2 = "SELECT * FROM user WHERE id = " . $row['userid'];
$result2 = mysql_query($query2);
$row2 = mysql_fetch_assoc($result2);
if ($row2['country']) {
$countryMembers[$row2['country']][] = $row2['id'];
$numIds++;
} else {
$countryMembers['Other'][] = $row2['id'];
}
}
mysql_free_result($result);
mysql_free_result($result2);
//echo "$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);
$filePath = "../html_user/" . PROFILE_PATH;
build_profile_pages($countryMembers[$country], "User Profiles from $country", $country, 5, 2, $filePath, $baseFileName, "../html_user/");
}
// Build the summary page linking to the individual country pages.
build_country_summary_page($countryMembers);
//echo "
View Summary Page";
//echo "
Done";
}
// Creates pages grouping users by the first letter of their names.
function build_alpha_pages() {
$query = "SELECT * FROM profile";
$result = mysql_query($query);
$numIds = 0;
while ($row = mysql_fetch_assoc($result)) {
$query2 = "SELECT * FROM user WHERE id = " . $row['userid'];
$result2 = mysql_query($query2);
$row2 = mysql_fetch_assoc($result2);
if ($row2['name']) {
$members[$row2['name'][0]][] = $row2['id'];
$numIds++;
}
}
mysql_free_result($result);
mysql_free_result($result2);
//echo "$numIds users have profiles AND non-null country entries.
";
$letters = array_keys($members);
foreach ($letters as $letter) {
// TODO: Make sure array indexing is not case sensitive.
$letter = strtoupper($letter);
$filePath = "../html_user/" . PROFILE_PATH;
build_profile_pages($members[$letter], "User Profiles - Names beginning with $letter", "Names beginning with $letter", 5, 2, $filePath, "profile_$letter", "../html_user/");
}
build_alpha_summary_page($letters);
}
// A generalized function to produce some number of pages summarizing a
// set of user profiles.
function build_profile_pages($members, $pageHead, $pageTitle, $rowsPerPage, $colsPerPage, $filePath, $baseFileName, $pathMod=NULL) {
$numMembers = count($members);
$numPerPage = $rowsPerPage * $colsPerPage;
$numPages = ceil(count($members) / $numPerPage);
$count = 0;
for ($page = 1; $page <= $numPages; $page++) {
$filename = $filePath . $baseFileName . "_" . $page . ".html";
$descriptor = fopen($filename, "w");
$head = $pageHead . ": Page $page of $numPages";
page_head($pageHead, null, $descriptor);
fwrite($descriptor, "$pageTitle
\n");
fwrite($descriptor, "Last updated " . gmdate("r") . " UTC\n");
$offset = (($page-1) * $rowsPerPage * $colsPerPage);
show_user_table($members, $offset, $numPerPage, $colsPerPage, $descriptor, $pathMod);
write_page_links($baseFileName, $page, $numPages, $descriptor);
page_tail($descriptor);
fclose($descriptor);
}
}
function build_country_summary_page($countryMembers) {
$countries = array_keys($countryMembers);
$filename = "../html_user/" . PROFILE_PATH . "profile_country.html";
$descriptor = fopen($filename, "w");
page_head("User Profiles by Country", null, $descriptor);
fwrite($descriptor, "
User Profiles by Country
Last updated " . gmdate("r") . " UTC");
fwrite($descriptor, "
\n");
fwrite($descriptor, "Country | Profiles |
\n");
foreach ($countries as $country) {
$numMembers = count($countryMembers[$country]);
$name = get_legal_filename($country);
fwrite($descriptor, "\n$country | $numMembers | \n");
}
fwrite($descriptor, "
");
page_tail($descriptor);
fclose($descriptor);
}
function build_alpha_summary_page($characters) {
// OK, so it's not quite the alphabet- alphanumerabet is a bad variable name.
$alphabet = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','0','1','2','3','4','5','6','7','8','9');
$filename = "../html_user/profile_alpha.html";
$descriptor = fopen($filename, "w");
// TODO: Add "Other" to handle non-alphanumeric first characters. Will involve removing elements from $characters as we finish them.
foreach ($alphabet as $character) {
if (in_array($character, $characters)) {
fwrite($descriptor, "$character ");
} else {
fwrite($descriptor, "$character ");
}
}
fclose($descriptor);
}
?>