2004-02-02 23:34:39 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require_once("../project/project.inc");
|
|
|
|
require_once("../inc/profile.inc");
|
|
|
|
require_once("../inc/util.inc");
|
2004-05-11 22:49:23 +00:00
|
|
|
require_once("../inc/uotd.inc");
|
2004-02-02 23:34:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
$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');
|
|
|
|
|
2004-06-15 18:50:57 +00:00
|
|
|
|
2005-02-13 06:13:33 +00:00
|
|
|
// Generates a standard set of links between associated multi-page documents.
|
|
|
|
// All linked files must be of the form "$filename_<page number>.html".
|
|
|
|
|
|
|
|
function write_page_links($filename, $currPageNum, $numPages) {
|
|
|
|
echo "<p>Page $currPageNum of $numPages</p>";
|
|
|
|
|
|
|
|
$nextPageNum = $currPageNum + 1;
|
|
|
|
$prevPageNum = $currPageNum - 1;
|
|
|
|
|
|
|
|
// Make the 'previous' and 'next' page links as appropriate.
|
|
|
|
if ($currPageNum > 1) {
|
2005-04-11 18:24:36 +00:00
|
|
|
echo "<a href={$filename}_{$prevPageNum}.html>Previous page</a>";
|
2005-02-13 06:13:33 +00:00
|
|
|
|
|
|
|
if ($currPageNum != $numPages) {
|
|
|
|
echo " | ";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($currPageNum != $numPages) {
|
2005-04-11 18:24:36 +00:00
|
|
|
echo "<a href={$filename}_{$nextPageNum}.html>Next page</a>";
|
2005-02-13 06:13:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
echo "<p>Jump to Page:\n";
|
|
|
|
|
|
|
|
// Make the individual page links (or a bold non-link for the current page).
|
|
|
|
//
|
|
|
|
for ($i = 1; $i <= $numPages; $i++) {
|
|
|
|
if ($i != $currPageNum) {
|
|
|
|
echo "<a href={$filename}_{$i}.html>$i</a>\n";
|
|
|
|
} else {
|
|
|
|
echo "<b>$i</b>\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2004-02-02 23:34:39 +00:00
|
|
|
// Generates the html files which comprise the photo gallery.
|
|
|
|
// $room: which gallery to generate (user, computer).
|
|
|
|
// $width: the width of the table of images.
|
|
|
|
// $height: the height of the table of images.
|
2004-05-09 22:17:54 +00:00
|
|
|
//
|
2004-02-02 23:34:39 +00:00
|
|
|
function build_picture_pages($width, $height) {
|
|
|
|
|
|
|
|
// TODO: Add support for a computer image gallery.
|
|
|
|
|
|
|
|
// TODO: Should we eliminate the has_picture flag? Doesn't really
|
|
|
|
// seem necessary when we're building static pages- could just use
|
|
|
|
// file_exists on the username...
|
|
|
|
|
|
|
|
// TODO: Standardize "Last modified" string to a function call (util.inc).
|
|
|
|
|
|
|
|
$query = "SELECT userid FROM profile WHERE has_picture = 1";
|
|
|
|
$result = mysql_query($query);
|
|
|
|
$numIds = mysql_num_rows($result);
|
|
|
|
|
|
|
|
//echo "Result has $numIds rows.<br>";
|
|
|
|
|
|
|
|
// Build an array of IDs of all users with pictures in their profiles.
|
|
|
|
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
|
|
|
|
$userIds[] = $row[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
mysql_free_result($result);
|
|
|
|
|
|
|
|
if (count($userIds) > 0) {
|
|
|
|
// Randomize the ordering of users.
|
|
|
|
shuffle($userIds);
|
|
|
|
}
|
|
|
|
|
|
|
|
$numPages = ceil(count($userIds)/($width * $height));
|
|
|
|
|
|
|
|
// Make sure that a page is generated even when no profiles with pictures
|
|
|
|
// exist in order to avoid 404 errors from the profile_menu page.
|
|
|
|
|
|
|
|
if ($numPages == 0) {
|
|
|
|
$numPages = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
//echo "Generating $numPages pages.<br>";
|
|
|
|
|
|
|
|
$count = 0;
|
|
|
|
|
|
|
|
for ($page = 1; $page <= $numPages; $page++) {
|
2004-06-15 18:50:57 +00:00
|
|
|
$filename = PROFILE_PATH . "user_gallery_" . $page . ".html";
|
|
|
|
open_output_buffer();
|
2004-02-02 23:34:39 +00:00
|
|
|
|
2005-04-11 18:24:36 +00:00
|
|
|
page_head("Profile gallery: page $page of $numPages");
|
2004-02-02 23:34:39 +00:00
|
|
|
|
2004-06-15 18:50:57 +00:00
|
|
|
echo "Last updated ", pretty_time_str(time()),
|
|
|
|
"\n<p>Browse the user profiles by picture.
|
|
|
|
Only user profiles with pictures are listed here.";
|
2004-02-02 23:34:39 +00:00
|
|
|
|
2004-06-15 18:50:57 +00:00
|
|
|
|
|
|
|
echo "<table class=bordered border=1 cellpadding=5\n";
|
2004-02-02 23:34:39 +00:00
|
|
|
|
|
|
|
for ($row = 0; $row < $height; $row++) {
|
2004-06-15 18:50:57 +00:00
|
|
|
echo "<tr>";
|
2004-02-02 23:34:39 +00:00
|
|
|
for ($col = 0; $col < $width; $col++) {
|
|
|
|
if ($count < $numIds) {
|
2004-06-15 18:50:57 +00:00
|
|
|
echo "<td class=bordered align=\"center\"><a href=\"",
|
|
|
|
URL_BASE, "view_profile.php?userid=",
|
|
|
|
$userIds[$count], "\"><img src=\"",
|
|
|
|
URL_BASE, IMAGE_URL, $userIds[$count],
|
|
|
|
"_sm.jpg\"></a></td>";
|
|
|
|
|
2004-02-02 23:34:39 +00:00
|
|
|
$count++;
|
|
|
|
}
|
|
|
|
}
|
2004-06-15 18:50:57 +00:00
|
|
|
echo "</tr>\n";
|
2004-02-02 23:34:39 +00:00
|
|
|
if ($count == $numIds) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-06-15 18:50:57 +00:00
|
|
|
echo "</table>\n";
|
2004-02-02 23:34:39 +00:00
|
|
|
|
|
|
|
// Previous and Next links
|
|
|
|
|
2004-06-15 18:50:57 +00:00
|
|
|
write_page_links("user_gallery", $page, $numPages);
|
2004-02-02 23:34:39 +00:00
|
|
|
|
2004-06-15 18:50:57 +00:00
|
|
|
page_tail(false);
|
2004-02-02 23:34:39 +00:00
|
|
|
|
2004-06-15 18:50:57 +00:00
|
|
|
close_output_buffer($filename);
|
2004-02-02 23:34:39 +00:00
|
|
|
}
|
|
|
|
|
2004-02-24 06:47:23 +00:00
|
|
|
//echo "<br><br><a href=\"" .PROFILE_PATH . "user_gallery_1.html\">Go to the first generated page.</a>";
|
2004-02-02 23:34:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Creates pages grouping user profiles by country. Filenames are of the
|
|
|
|
// format "profile_country_<country name>_<page number>.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() {
|
2004-06-07 03:34:07 +00:00
|
|
|
$query = "select * from profile";
|
2004-02-02 23:34:39 +00:00
|
|
|
$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)) {
|
2004-06-07 03:34:07 +00:00
|
|
|
$user = lookup_user_id($profile->userid);
|
|
|
|
if ($user->country) {
|
|
|
|
$countryMembers[$user->country][] = $user->id;
|
2004-02-02 23:34:39 +00:00
|
|
|
$numIds++;
|
2004-06-15 22:55:54 +00:00
|
|
|
} else if ($user) {
|
2004-06-07 03:34:07 +00:00
|
|
|
$countryMembers['Other'][] = $user->id;
|
2004-02-02 23:34:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2004-02-10 07:02:38 +00:00
|
|
|
$filePath = PROFILE_PATH;
|
2004-02-02 23:34:39 +00:00
|
|
|
build_profile_pages(
|
|
|
|
$countryMembers[$country],
|
|
|
|
"User Profiles from $country", $country, 5, 2,
|
2004-02-10 07:02:38 +00:00
|
|
|
$filePath, $baseFileName, "../html/"
|
2004-02-02 23:34:39 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Build the summary page linking to the individual country pages.
|
|
|
|
|
|
|
|
build_country_summary_page($countryMembers);
|
|
|
|
|
2004-02-24 06:47:23 +00:00
|
|
|
//echo "<br><a href=\"" . PROFILE_PATH . "profile_country.html\">View Summary Page</a>";
|
2004-02-02 23:34:39 +00:00
|
|
|
//echo "<br><br>Done";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Creates pages grouping users by the first letter of their names.
|
|
|
|
|
|
|
|
function build_alpha_pages() {
|
|
|
|
global $alphabet;
|
|
|
|
|
2004-06-07 03:34:07 +00:00
|
|
|
$query = "select * from profile";
|
2004-02-02 23:34:39 +00:00
|
|
|
$result = mysql_query($query);
|
|
|
|
$numIds = 0;
|
|
|
|
|
2004-06-07 03:34:07 +00:00
|
|
|
while ($profile = mysql_fetch_object($result)) {
|
|
|
|
$user = lookup_user_id($profile->userid);
|
2004-02-02 23:34:39 +00:00
|
|
|
|
2004-06-07 03:34:07 +00:00
|
|
|
if ($user->name) {
|
|
|
|
$name = ltrim($user->name);
|
|
|
|
$members[strtoupper($name[0])][] = $user->id;
|
2004-02-02 23:34:39 +00:00
|
|
|
$numIds++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mysql_free_result($result);
|
|
|
|
|
|
|
|
//echo "$numIds users have profiles AND non-null country entries.<br>";
|
|
|
|
|
|
|
|
$letters = array_keys($members);
|
|
|
|
|
|
|
|
foreach ($letters as $letter) {
|
|
|
|
// NOTE: Array indexing is case sensitive.
|
2004-02-10 07:02:38 +00:00
|
|
|
$filePath = PROFILE_PATH;
|
2004-02-02 23:34:39 +00:00
|
|
|
if (in_array($letter, $alphabet)) {
|
|
|
|
build_profile_pages(
|
|
|
|
$members[$letter],
|
|
|
|
"User Profiles - Names beginning with $letter",
|
|
|
|
"Names beginning with $letter", 5, 2, $filePath,
|
|
|
|
"profile_$letter"
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
build_profile_pages(
|
|
|
|
$members[$letter],
|
|
|
|
"User Profiles - Names beginning with other characters",
|
|
|
|
"Names beginning with other characters", 5, 2, $filePath,
|
|
|
|
"profile_other"
|
|
|
|
);
|
|
|
|
}
|
2004-06-15 22:55:54 +00:00
|
|
|
$letters_used[$letter] = 1;
|
2004-02-02 23:34:39 +00:00
|
|
|
}
|
|
|
|
|
2004-06-15 22:55:54 +00:00
|
|
|
build_alpha_summary_page($letters_used);
|
2004-02-02 23:34:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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) {
|
|
|
|
$numMembers = count($members);
|
|
|
|
$numPerPage = $rowsPerPage * $colsPerPage;
|
|
|
|
$numPages = ceil(count($members) / $numPerPage);
|
|
|
|
|
|
|
|
$count = 0;
|
|
|
|
|
|
|
|
for ($page = 1; $page <= $numPages; $page++) {
|
|
|
|
|
|
|
|
$filename = $filePath . $baseFileName . "_" . $page . ".html";
|
2004-06-15 18:50:57 +00:00
|
|
|
open_output_buffer();
|
2004-02-02 23:34:39 +00:00
|
|
|
|
|
|
|
$head = $pageHead . ": Page $page of $numPages";
|
2004-06-15 18:50:57 +00:00
|
|
|
page_head($pageTitle);
|
2004-02-02 23:34:39 +00:00
|
|
|
|
2004-06-15 18:50:57 +00:00
|
|
|
echo "Last updated ", pretty_time_str(time()), "<p>\n";
|
2004-02-02 23:34:39 +00:00
|
|
|
|
|
|
|
$offset = (($page-1) * $rowsPerPage * $colsPerPage);
|
|
|
|
|
2004-06-15 18:50:57 +00:00
|
|
|
show_user_table($members, $offset, $numPerPage, $colsPerPage);
|
|
|
|
|
|
|
|
write_page_links($baseFileName, $page, $numPages);
|
2004-02-02 23:34:39 +00:00
|
|
|
|
2004-06-15 18:50:57 +00:00
|
|
|
page_tail(false);
|
2004-02-02 23:34:39 +00:00
|
|
|
|
2004-06-15 18:50:57 +00:00
|
|
|
close_output_buffer($filename);
|
2004-02-02 23:34:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function build_country_summary_page($countryMembers) {
|
|
|
|
$countries = array_keys($countryMembers);
|
|
|
|
|
2004-02-10 07:02:38 +00:00
|
|
|
$filename = PROFILE_PATH . "profile_country.html";
|
2004-06-15 18:50:57 +00:00
|
|
|
open_output_buffer();
|
2004-02-02 23:34:39 +00:00
|
|
|
|
2004-06-15 18:50:57 +00:00
|
|
|
page_head("User Profiles by Country");
|
|
|
|
echo "Last updated " . pretty_time_str(time()) . "<p>";
|
2004-02-02 23:34:39 +00:00
|
|
|
|
2004-06-15 18:50:57 +00:00
|
|
|
echo "<table border=0>\n";
|
|
|
|
echo "<tr><td><b>Country</b></td><td align=\"center\"><b>Profiles</b></td></tr>\n";
|
2004-02-02 23:34:39 +00:00
|
|
|
|
|
|
|
foreach ($countries as $country) {
|
|
|
|
$numMembers = count($countryMembers[$country]);
|
|
|
|
$name = get_legal_filename($country);
|
|
|
|
|
2004-06-15 18:50:57 +00:00
|
|
|
echo "<tr>\n<td><a href=\"profile_country_",
|
|
|
|
"{$name}_1.html\">$country</a></td><td align=\"center\">$numMembers</td></td>\n";
|
2004-02-02 23:34:39 +00:00
|
|
|
}
|
|
|
|
|
2004-06-15 18:50:57 +00:00
|
|
|
echo "</table>";
|
|
|
|
page_tail(false);
|
2004-02-02 23:34:39 +00:00
|
|
|
|
2004-06-15 18:50:57 +00:00
|
|
|
close_output_buffer($filename);
|
2004-02-02 23:34:39 +00:00
|
|
|
}
|
|
|
|
|
2004-06-15 22:55:54 +00:00
|
|
|
function build_alpha_summary_page($characters_used) {
|
2004-02-02 23:34:39 +00:00
|
|
|
global $alphabet;
|
|
|
|
|
2004-02-10 07:02:38 +00:00
|
|
|
$filename = PROFILE_PATH."profile_alpha.html";
|
2004-06-15 18:50:57 +00:00
|
|
|
open_output_buffer();
|
2004-02-02 23:34:39 +00:00
|
|
|
|
|
|
|
foreach ($alphabet as $character) {
|
2004-06-15 22:55:54 +00:00
|
|
|
if (isset($characters_used[$character])) {
|
2004-06-15 18:50:57 +00:00
|
|
|
echo "<a href=", URL_BASE, PROFILE_URL, "profile_{$character}_1.html>$character</a> ";
|
2004-06-15 22:55:54 +00:00
|
|
|
unset($characters_used[$character]);
|
2004-02-02 23:34:39 +00:00
|
|
|
} else {
|
2004-06-15 18:50:57 +00:00
|
|
|
echo "$character ";
|
2004-02-02 23:34:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Link to the 'Other' page if necessary.
|
2004-06-15 22:55:54 +00:00
|
|
|
if (!empty($characters_used)) {
|
2004-06-15 18:50:57 +00:00
|
|
|
echo "<a href=", URL_BASE, PROFILE_URL, "profile_other_1.html>Other</a> ";
|
2004-02-02 23:34:39 +00:00
|
|
|
}
|
2004-06-15 18:50:57 +00:00
|
|
|
close_output_buffer($filename);
|
2004-02-02 23:34:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
?>
|