2003-07-17 23:48:05 +00:00
< ? php
require_once ( " ../html_user/project_specific/project.inc " );
require_once ( " ../html_user/profile.inc " );
require_once ( " ../html_user/util.inc " );
2003-07-28 23:42:09 +00:00
2003-07-17 23:48:05 +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.
2003-07-21 22:46:24 +00:00
// $height: the height of the table of images.
2003-07-17 23:48:05 +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.
2003-08-08 01:03:03 +00:00
while ( $row = mysql_fetch_array ( $result , MYSQL_NUM )) {
2003-07-17 23:48:05 +00:00
$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 ++ ) {
$file = " ../html_user/ " . PROFILE_PATH . " user_gallery_ " . $page . " .html " ;
$descriptor = fopen ( $file , " w " );
2003-07-21 22:46:24 +00:00
page_head ( " User Picture Gallery: Page $page of $numPages " , null , $descriptor );
2003-07-17 23:48:05 +00:00
fwrite ( $descriptor , " <h2>User Profile Pictures</h2>Last updated " . gmdate ( " r " ) . " UTC \n <p>Browse the user profiles by picture. Only user profiles with pictures are listed here. " );
fwrite ( $descriptor , " <table border=1 cellpadding=5> \n " );
for ( $row = 0 ; $row < $height ; $row ++ ) {
fwrite ( $descriptor , " <tr> " );
for ( $col = 0 ; $col < $width ; $col ++ ) {
if ( $count < $numIds ) {
2003-07-28 23:42:09 +00:00
fwrite ( $descriptor , " <td align= \" center \" ><a href= \" " . URL_BASE . " view_profile.php?userid= " . $userIds [ $count ] . " \" ><img src= \" " . '../' . IMAGE_PATH . $userIds [ $count ] . '_sm.jpg' . " \" ></a></td> " );
2003-07-17 23:48:05 +00:00
$count ++ ;
}
}
fwrite ( $descriptor , " </tr> \n " );
if ( $count == $numIds ) {
break ;
}
}
2003-07-21 22:46:24 +00:00
2003-07-17 23:48:05 +00:00
fwrite ( $descriptor , " </table> \n " );
// Previous and Next links
2003-07-21 22:46:24 +00:00
2003-07-17 23:48:05 +00:00
write_page_links ( " user_gallery " , $page , $numPages , $descriptor );
page_tail ( $descriptor );
fclose ( $descriptor );
}
//echo "<br><br><a href=\"" . "../html_user/" .PROFILE_PATH . "user_gallery_1.html\">Go to the first generated page.</a>";
}
// Creates pages grouping user profiles by country. Filenames are of the
2003-07-22 00:38:51 +00:00
// format "profile_country_<country name>_<page number>.html"
2003-07-17 23:48:05 +00:00
// 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' ]) {
2003-07-28 23:42:09 +00:00
$countryMembers [ $row2 [ 'country' ]][] = $row2 [ 'id' ];
$numIds ++ ;
} else {
$countryMembers [ 'Other' ][] = $row2 [ 'id' ];
2003-07-17 23:48:05 +00:00
}
}
mysql_free_result ( $result );
mysql_free_result ( $result2 );
//echo "$numIds users have profiles AND non-null country entries.<br>";
$countries = array_keys ( $countryMembers );
2003-07-28 23:42:09 +00:00
sort ( $countries );
2003-07-17 23:48:05 +00:00
// Build the pages.
// TODO: Define a constant for the desired number of rows per page.
foreach ( $countries as $country ) {
2003-07-22 00:38:51 +00:00
$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/ " );
2003-07-17 23:48:05 +00:00
}
// Build the summary page linking to the individual country pages.
2003-08-14 01:18:09 +00:00
2003-07-17 23:48:05 +00:00
build_country_summary_page ( $countryMembers );
2003-08-14 01:18:09 +00:00
2003-07-17 23:48:05 +00:00
//echo "<br><a href=\"" . "../html_user/" . PROFILE_PATH . "profile_country.html\">View Summary Page</a>";
//echo "<br><br>Done";
}
2003-07-22 00:38:51 +00:00
// Creates pages grouping users by the first letter of their names.
function build_alpha_pages () {
2003-08-14 01:18:09 +00:00
2003-07-22 00:38:51 +00:00
$query = " SELECT * FROM profile " ;
$result = mysql_query ( $query );
$numIds = 0 ;
2003-08-14 01:18:09 +00:00
2003-07-22 00:38:51 +00:00
while ( $row = mysql_fetch_assoc ( $result )) {
$query2 = " SELECT * FROM user WHERE id = " . $row [ 'userid' ];
$result2 = mysql_query ( $query2 );
$row2 = mysql_fetch_assoc ( $result2 );
2003-08-14 01:18:09 +00:00
2003-07-22 00:38:51 +00:00
if ( $row2 [ 'name' ]) {
2003-08-14 01:18:09 +00:00
$name = ltrim ( $row2 [ 'name' ]);
$members [ strtoupper ( $name [ 0 ])][] = $row2 [ 'id' ];
2003-07-22 00:38:51 +00:00
$numIds ++ ;
}
}
2003-08-14 01:18:09 +00:00
2003-07-22 00:38:51 +00:00
mysql_free_result ( $result );
mysql_free_result ( $result2 );
2003-08-14 01:18:09 +00:00
2003-07-22 00:38:51 +00:00
//echo "$numIds users have profiles AND non-null country entries.<br>";
2003-08-14 01:18:09 +00:00
2003-07-22 00:38:51 +00:00
$letters = array_keys ( $members );
2003-08-14 01:18:09 +00:00
2003-07-22 00:38:51 +00:00
foreach ( $letters as $letter ) {
2003-08-14 01:18:09 +00:00
// NOTE: Array indexing is case sensitive.
2003-07-22 00:38:51 +00:00
$filePath = " ../html_user/ " . PROFILE_PATH ;
2003-08-08 01:03:03 +00:00
build_profile_pages ( $members [ $letter ], " User Profiles - Names beginning with $letter " , " Names beginning with $letter " , 5 , 2 , $filePath , " profile_ $letter " );
2003-07-22 00:38:51 +00:00
}
2003-08-14 01:18:09 +00:00
2003-07-22 20:23:24 +00:00
build_alpha_summary_page ( $letters );
2003-07-22 00:38:51 +00:00
}
// A generalized function to produce some number of pages summarizing a
// set of user profiles.
2003-08-08 01:03:03 +00:00
function build_profile_pages ( $members , $pageHead , $pageTitle , $rowsPerPage , $colsPerPage , $filePath , $baseFileName ) {
2003-07-22 00:38:51 +00:00
$numMembers = count ( $members );
$numPerPage = $rowsPerPage * $colsPerPage ;
$numPages = ceil ( count ( $members ) / $numPerPage );
2003-08-14 01:18:09 +00:00
2003-07-22 00:38:51 +00:00
$count = 0 ;
for ( $page = 1 ; $page <= $numPages ; $page ++ ) {
$filename = $filePath . $baseFileName . " _ " . $page . " .html " ;
$descriptor = fopen ( $filename , " w " );
2003-08-14 01:18:09 +00:00
2003-07-22 00:38:51 +00:00
$head = $pageHead . " : Page $page of $numPages " ;
page_head ( $pageHead , null , $descriptor );
2003-08-14 01:18:09 +00:00
2003-07-22 00:38:51 +00:00
fwrite ( $descriptor , " <h2> $pageTitle </h2> \n " );
fwrite ( $descriptor , " Last updated " . gmdate ( " r " ) . " UTC<p> \n " );
2003-08-14 01:18:09 +00:00
2003-07-22 00:38:51 +00:00
$offset = (( $page - 1 ) * $rowsPerPage * $colsPerPage );
2003-08-14 01:18:09 +00:00
2003-08-08 01:03:03 +00:00
show_user_table ( $members , $offset , $numPerPage , $colsPerPage , $descriptor );
2003-08-14 01:18:09 +00:00
2003-07-22 00:38:51 +00:00
write_page_links ( $baseFileName , $page , $numPages , $descriptor );
2003-08-14 01:18:09 +00:00
2003-07-22 00:38:51 +00:00
page_tail ( $descriptor );
fclose ( $descriptor );
}
2003-08-14 01:18:09 +00:00
2003-07-22 00:38:51 +00:00
}
2003-07-17 23:48:05 +00:00
function build_country_summary_page ( $countryMembers ) {
$countries = array_keys ( $countryMembers );
2003-07-21 22:46:24 +00:00
2003-07-17 23:48:05 +00:00
$filename = " ../html_user/ " . PROFILE_PATH . " profile_country.html " ;
$descriptor = fopen ( $filename , " w " );
2003-07-21 22:46:24 +00:00
2003-07-17 23:48:05 +00:00
page_head ( " User Profiles by Country " , null , $descriptor );
fwrite ( $descriptor , " <h2>User Profiles by Country</h2>Last updated " . gmdate ( " r " ) . " UTC<p> " );
2003-07-21 22:46:24 +00:00
2003-07-17 23:48:05 +00:00
fwrite ( $descriptor , " <table border=0> \n " );
fwrite ( $descriptor , " <tr><td><b>Country</b></td><td align= \" center \" ><b>Profiles</b></td></tr> \n " );
foreach ( $countries as $country ) {
$numMembers = count ( $countryMembers [ $country ]);
$name = get_legal_filename ( $country );
fwrite ( $descriptor , " <tr> \n <td><a href= \" profile_country_ " . $name . " _1.html \" > $country </a></td><td align= \" center \" > $numMembers </td></td> \n " );
}
fwrite ( $descriptor , " </table> " );
page_tail ( $descriptor );
fclose ( $descriptor );
}
2003-07-22 20:23:24 +00:00
function build_alpha_summary_page ( $characters ) {
2003-07-22 20:39:57 +00:00
// OK, so it's not quite the alphabet- alphanumerabet is a bad variable name.
2003-07-22 20:36:03 +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' );
2003-08-14 01:18:09 +00:00
2003-07-22 20:36:03 +00:00
$filename = " ../html_user/profile_alpha.html " ;
2003-07-22 20:23:24 +00:00
$descriptor = fopen ( $filename , " w " );
2003-08-14 01:18:09 +00:00
2003-07-22 20:39:57 +00:00
// TODO: Add "Other" to handle non-alphanumeric first characters. Will involve removing elements from $characters as we finish them.
2003-08-14 01:18:09 +00:00
2003-07-22 20:23:24 +00:00
foreach ( $alphabet as $character ) {
if ( in_array ( $character , $characters )) {
2003-07-22 20:36:03 +00:00
fwrite ( $descriptor , " <a href= " . PROFILE_PATH . " profile_ " . $character . " _1.html> $character </a> " );
2003-08-14 01:18:09 +00:00
2003-07-22 20:23:24 +00:00
} else {
fwrite ( $descriptor , " $character " );
}
}
2003-07-22 20:39:57 +00:00
fclose ( $descriptor );
2003-07-22 20:23:24 +00:00
}
2003-08-07 00:39:54 +00:00
function build_uotd_page () {
// Check if the current UOTD has had their 24 hours of fame - if so, pick a new one.
2003-08-14 01:18:09 +00:00
2003-08-07 00:39:54 +00:00
$result = mysql_query ( " SELECT * FROM profile ORDER BY uotd_time DESC LIMIT 1 " );
if ( mysql_num_rows ( $result ) > 0 ) {
$current_uotd = mysql_fetch_assoc ( $result );
2003-08-08 01:03:03 +00:00
$assigned = getdate ( $current_uotd [ 'uotd_time' ]);
$now = getdate ( time ());
if ( $assigned [ 'mday' ] == $now [ 'mday' ]) {
2003-08-07 00:39:54 +00:00
exit ();
}
}
2003-08-08 01:03:03 +00:00
// TODO: Verify that adding RAND() didn't screw this up.
2003-08-14 01:18:09 +00:00
$result = mysql_query ( " SELECT * FROM profile WHERE verification = 1 AND uotd_time IS NULL ORDER BY RAND() " );
2003-08-08 01:03:03 +00:00
// If the number of approved profiles dips below a threshold, email the sys admin every time we pick a new one.
if ( $result && mysql_num_rows ( $result ) < UOTD_THRESHOLD ) {
mail ( SYS_ADMIN_EMAIL , PROJECT . " : User of the Day pool is running low! " , " The pool of approved candidates for User of the Day has reached your assigned threshold: there are now only " . mysql_num_rows ( $result ) . " approved users. \n \n To approve more candidates for User of the Day, direct your web browser to the " . PROJECT . " administration page and click \" Unrated profile \" " );
}
2003-08-14 01:18:09 +00:00
2003-08-07 00:39:54 +00:00
if ( $result && mysql_num_rows ( $result ) == 0 ) {
// If all verified profiles have been selected as UOTD, reshow the one that was shown least recently.
$result = mysql_query ( " SELECT * FROM profile WHERE verification = 1 ORDER BY uotd_time ASC LIMIT 1 " );
}
2003-08-14 01:18:09 +00:00
2003-08-07 00:39:54 +00:00
if ( ! $result || mysql_num_rows ( $result ) == 0 ) {
// No valid users of the day - do something.
exit ();
}
$profile = mysql_fetch_assoc ( $result );
2003-08-14 01:18:09 +00:00
2003-08-07 00:39:54 +00:00
$sql = " SELECT * FROM user where id = " . $profile [ 'userid' ];
$result2 = mysql_query ( $sql );
$user = mysql_fetch_assoc ( $result2 );
2003-08-14 01:18:09 +00:00
2003-08-07 00:39:54 +00:00
$filename = " ../html_user/uotd.html " ;
$descriptor = fopen ( $filename , " w " );
2003-08-14 01:18:09 +00:00
2003-08-07 00:39:54 +00:00
if ( $profile [ 'has_picture' ]) {
fwrite ( $descriptor , " <a href= \" view_profile?userid= " . $user [ 'id' ] . " \" ><img align= \" left \" src= \" " . IMAGE_PATH . $user [ 'id' ] . " _sm.jpg \" </img></a> " );
}
2003-08-14 01:18:09 +00:00
fwrite ( $descriptor , " The " . PROJECT . " User of the Day is <a href= \" view_profile?userid= " . $user [ 'id' ] . " \" > " . $user [ 'name' ] . " </a>! " );
2003-08-07 00:39:54 +00:00
fclose ( $descriptor );
2003-08-14 01:18:09 +00:00
2003-08-07 00:39:54 +00:00
$sql = " UPDATE profile SET uotd_time = " . time () . " WHERE userid = " . $user [ 'id' ];
mysql_query ( $sql );
2003-08-14 01:18:09 +00:00
2003-08-08 01:03:03 +00:00
mail ( $user [ 'email_addr' ], " You're the " . PROJECT . " user of the day! " , " Congratulations! \n \n You've been chosen as the " . PROJECT . " user of the day! Your profile will be featured on the " . PROJECT . " website for the next 24 hours. Thanks again for supporting us- it's members like you that make distributed computing projects like ours such a success. \n \n Best regards and much thanks, \n \n The " . PROJECT . " team. " );
2003-08-07 00:39:54 +00:00
}
2003-07-17 23:48:05 +00:00
?>