Files involved in profile functionality

svn path=/trunk/boinc/; revision=1672
This commit is contained in:
Dan Werthimer 2003-07-11 22:33:59 +00:00
parent 8a7d6df6ec
commit aad5f449d7
9 changed files with 1133 additions and 0 deletions

View File

@ -0,0 +1,21 @@
<?php
require_once("util.inc");
require_once("db.inc");
require_once("project.inc");
require_once("profile.inc");
// TODO: Manually limit max size of stored "big" image.
// Would just need to make getImages scale the "big"
// image if it was above a particular size.
// TODO: Allow users to delete their profiles.
// Perhaps an empty profile submission (including selection
// of the "delete image" checkbox) should be considered
// a delete action for the profile itself?
db_init();
$user = get_logged_in_user(true);
show_profile_creation_page($user);
?>

View File

@ -0,0 +1,53 @@
<?php
require_once("db.inc");
require_once("util.inc");
require_once("project.inc");
require_once("gallery.inc");
db_init();
$user = get_logged_in_user(); // Can't delete your profile unless you're logged in!
// Handle a delete request.
if ($_POST['delete']) {
delete_profile($user);
exit();
}
page_head("Profile Delete Confirmation");
echo "<form action=", $_SERVER['PHP_SELF'], " method=\"POST\">";
start_table_noborder();
row1("Delete your profile");
rowify("
<h2>Are you sure?</h2><p>
Remember that deleted profiles are gone forever and cannot be recovered--you will have to start from scratch if you want another profile in the future.
");
rowify("<br>If you're sure, click the \"Delete\" button below to remove your profile from our database.");
echo "<tr><td align=\"center\"><br><input type=\"submit\" name=\"delete\" value=\"Delete\"></td></tr>";
end_table();
echo "</form>";
page_tail();
function delete_profile($user) {
$result = mysql_query("DELETE FROM profile WHERE userid = $user->id");
if ($result) {
delete_user_pictures($user->id);
page_head("Delete Confirmation");
echo "Your profile has been deleted<br>";
} else {
// TODO: Change this to a standard dialog.
page_head("Deletion Error");
echo "There was a problem deleting your profile.";
}
page_tail();
}
?>

286
html/user/gallery.inc Executable file
View File

@ -0,0 +1,286 @@
<?php
require_once("project.inc");
require_once("profile.inc");
// 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.
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)) { // NUM is supposedly faster than ASSOC.
$userIds[] = $row[0];
}
mysql_free_result($result);
// Randomize the ordering of users.
shuffle($userIds);
$numPages = ceil(count($userIds)/($width * $height));
echo "Generating $numPages pages.<br>";
$count = 0;
for ($page = 1; $page <= $numPages; $page++) {
$file = PROFILE_PATH . "user_gallery_" . $page . ".html";
$descriptor = fopen($file, "w");
page_head("User Picture Gallery: Page $page of $numPages", null, $descriptor);
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) {
fwrite($descriptor, "<td><a href=\"" . MASTER_URL . "view_profile.php?userid=" . $userIds[$count] . "\"><img src=\"" . '../' . IMAGE_PATH . $userIds[$count] . '_sm.jpg' . "\"></a></td>");
$count++;
}
}
fwrite($descriptor, "</tr>\n");
if ($count == $numIds) {
break;
}
}
fwrite($descriptor, "</table>\n");
// Previous and Next links
write_page_links("user_gallery", $page, $numPages, $descriptor);
page_tail($descriptor);
//fwrite($descriptor, "</body></html>");
fclose($descriptor);
}
echo "<br><br><a href=\"" . PROFILE_PATH . "user_gallery_1.html\">Go to the first generated page.</a>";
}
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++;
}
}
mysql_free_result($result);
mysql_free_result($result2);
echo "$numIds users have profiles AND non-null country entries.<br>";
$countries = array_keys($countryMembers);
// Build the pages.
foreach ($countries as $country) {
build_country_page($country, &$countryMembers[$country], 5);
}
// Build the summary page linking to the individual country pages.
// TODO: Pass $countryMembers by reference.
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_page($name, $members, $rows) {
$countryName = $name;
// Make the country name a legal format for a filename.
$name = get_legal_filename($countryName);
$name = ereg_replace(',', '', $name);
$name = ereg_replace(' ', '_', $name);
$numMembers = count($members);
$numPages = ceil(count($members) / (2 * $rows));
echo "<br>$countryName has $numMembers members. - $numPages pages will be generated. <a href=", PROFILE_PATH , "profile_country_" , $name , "_1.html> VIEW</a>";
$count = 0;
for ($page = 1; $page <= $numPages; $page++) {
$filename = PROFILE_PATH . "profile_country_" . $name . "_" . $page . ".html";
$descriptor = fopen($filename, "w");
// TODO: Page header.
//fwrite($descriptor, "<html><body>\n");
page_head("User Profiles from $countryName: Page $page of $numPages", null, $descriptor);
fwrite($descriptor, "<h2>$countryName</h2>\n");
fwrite($descriptor, "Last updated " . gmdate("r") . " UTC<p>\n");
fwrite($descriptor, "<table border=1 cellpadding=5>\n");
for ($row = 0; $row < $rows; $row++) {
if ($count >= $numMembers) {
break;
}
fwrite($descriptor, "<tr>\n");
// Formatting is a table with two columns of user summaries.
for ($col = 0; $col < 2; $col++) {
if ($count < $numMembers) {
fwrite($descriptor, "<td width=7% height=64><center>");
// Only link an image if one exists.
if (file_exists(IMAGE_PATH . $members[$count] . '_sm.jpg')) {
fwrite($descriptor, "<a href=\"" . MASTER_URL . "view_profile.php?userid=" . $members[$count] . "\"><img src=\"" . '../' . IMAGE_PATH . $members[$count] . '_sm.jpg' . "\"></a>");
} else {
fwrite($descriptor, "&nbsp;");
}
fwrite($descriptor, "</center></td><td width=33% height=64>");
fwrite($descriptor, get_profile_summary($members[$count]));
fwrite($descriptor, "</td>");
$count++;
}
else {
// Empty entry.
fwrite($descriptor, "<td width=7% height=64></td><td width=33% height=64></td>");
}
}
fwrite($descriptor, "</tr>\n");
}
fwrite($descriptor, "</table>\n");
$tempFileName = "profile_country_" . $name;
write_page_links($tempFileName, $page, $numPages, $descriptor);
page_tail($descriptor);
fclose($descriptor);
}
}
function get_legal_filename($name) {
$name = ereg_replace(',', '', $name);
return ereg_replace(' ', '_', $name);
}
function get_profile_summary($userid) {
$result = mysql_query("SELECT * FROM profile WHERE userid = $userid");
$result2 = mysql_query("SELECT name FROM user WHERE id = $userid");
if (!$result || !$result2) {
echo "Database error!"; // Change this to a standard error page.
exit();
}
$row = mysql_fetch_assoc($result);
$row2 = mysql_fetch_assoc($result2);
mysql_free_result($result);
mysql_free_result($result2);
if (strlen($row['response1']) != 0) {
$description = "(\"" . substr($row['response1'], 0, MAX_DESC_LENGTH);
if (strlen($row['response1']) >= MAX_DESC_LENGTH) {
$description = $description . "...";
}
$description = $description . "\")";
}
$summary = "<a href=\"" . MASTER_URL . "view_profile.php?userid=" . $userid . "\">" . $row2['name'] . "</a> " . $description;
return $summary;
}
function write_page_links($filename, $currPageNum, $numPages, $descriptor) {
fwrite($descriptor, "<p>Page $currPageNum of $numPages</p>");
$nextPageNum = $currPageNum + 1;
$prevPageNum = $currPageNum - 1;
// Make the 'previous' and 'next' page links as appropriate.
if ($currPageNum > 1) {
fwrite($descriptor, "<a href=$filename" . "_" . $prevPageNum . ".html>Previous Page</a>");
if ($currPageNum != $numPages) {
fwrite($descriptor, " | ");
}
}
if ($currPageNum != $numPages) {
fwrite($descriptor, "<a href=$filename" . "_" . $nextPageNum . ".html>Next Page</a>");
}
fwrite($descriptor, "<p><table border=0>\n<tr>\n<td>Jump to Page:</td>\n");
// Make the individual page links (or a bold non-link for the current page).
for ($i = 1; $i <= $numPages; $i++) {
if ($i != $currPageNum) {
fwrite($descriptor, "<td><a href=$filename" . "_" . $i . ".html>$i</a></td>\n");
} else {
fwrite($descriptor, "<td><b>$i</b></td>\n");
}
}
fwrite($descriptor, "</table>\n");
}
function build_country_summary_page($countryMembers) {
$countries = array_keys($countryMembers);
$filename = PROFILE_PATH . "profile_country.html";
$descriptor = fopen($filename, "w");
echo "<p>Building country summary page...<br>";
page_head("User Profiles by Country", null, $descriptor);
fwrite($descriptor, "<h2>User Profiles by Country</h2>Last updated " . gmdate("r") . " UTC<p>");
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);
}
?>

View File

@ -0,0 +1,14 @@
<?php
require_once("gallery.inc");
require_once("util.inc");
require_once("db.inc");
db_init();
page_head("Generate Profile Gallery");
build_country_pages();
page_tail();
?>

View File

@ -0,0 +1,15 @@
<?php
require_once("gallery.inc");
require_once("profile.inc");
require_once("util.inc");
require_once("db.inc");
db_init();
page_head("Generate Profile Gallery");
build_picture_pages(GALLERY_WIDTH, GALLERY_HEIGHT);
page_tail();
?>

188
html/user/languages.txt Normal file
View File

@ -0,0 +1,188 @@
Abkhazian
Afar
Afrikaans
Albanian
Amharic
Arabic
Armenian
Assamese
Aymara
Azebaijani
Bahasa Indonesia
Bangla
Bashkir
Basque
Bengali
Bhutanese
Bhutani
Bihari
Bislama
Breton
Bulgarian
Burmese
Byelorussian
Cambodian
Catalan
Chinese
chiShona
Choson-o
Corsican
Croat
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Faeroese
Faroese
Fiji
Fijian
Finnish
French
Frisian
Scots
Gaelic
Galician
Galla
Georgian
German
Greek
Greenlandic
Guaraní
Gujarati
Gujerati
Hausa
Hebrew
Hindi
Hungarian
Icelandic
Indonesian
Interlingua
Interlingue
Inupiak
Inuktitut
Irish
isiXhosa
isiZulu
Italian
Japanese
Javanese
Kannada
Kashmiri
Kazakh
kinyaRuanda
Kinyarwanda
Kirghiz
Kirundi
kiRundi
kiSwahili
Korean
Kurdish
Lao
Laothian
Latin
Latvian
Lettish
Lingala
liNgala
Lithuanian
Macedonian
Malagasy
Malay
Malayalam
Magyar
Mahrati
Maltese
Maori
Marathi
Moldavian
Mongolian
Nauru
Nepalese
Nepali
Nihongo
Norwegian
Occitan
Oriya
(Afan)Oromo
Pashto
Persian
Pha Xa Lao
Polish
Portuguese
Punjabi
Pushto
Pushtu
Quechua
Rhaeto-Romance
Rhaeto-Romanic
Romanian
Romansch
Rumanian
Russian
Samoan
Sangho
Sango-Ngbandi
Sanskrit
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Shona
Sindhi inghalese
Sinhalese
siSuthu
Siswati
siSwati
Slovak
Slovene
Slovenian
Somali
Spanish
Sundanese
Suomi
Swahili
Swedish
Tagalog
Tajik
Tajiki
Tamil
Tartar
Tatar
Telegu
Telugu
Thai
Tibetan
Tigrinya
Tonga
Tshi
Tsonga
Turcoman
Turkish
Turkmen
Turkoman
Twi
Uigur
Uighur
Ukrainian
Urdu
Usbeg
Usbek
Uyghur
Uzbeg
Uzbek
Vietnamese
Volapük
Welsh
Wolof
Xhosa
Xosa
Yiddish
Yoruba
Zhuang
Zimany Kurdy
Zulu
Other

323
html/user/profile.inc Normal file
View File

@ -0,0 +1,323 @@
<?php
require_once("util.inc");
require_once("project.inc");
// TODO: Determine if we can always assume these will be the same number.
define('SMALL_IMG_WIDTH', 64);
define('SMALL_IMG_HEIGHT', 64);
define('MAX_IMG_WIDTH', 800);
define('MAX_IMG_HEIGHT', 600);
define('MAX_DESC_LENGTH', 80);
define('GALLERY_WIDTH', 7);
define('GALLERY_HEIGHT', 4);
$user = NULL;
$profile_info = NULL;
function show_profile_creation_page($usr) {
global $user;
global $profile_info;
$user = $usr;
// If the user already has a profile, fill in the fields with their current values.
$result = mysql_query("SELECT * FROM profile WHERE userid = $user->id");
if ($result) {
$profile_info = mysql_fetch_array($result, MYSQL_ASSOC);
}
setup_form();
$profile_info?page_head("Edit your Profile"):page_head("Create a Profile");
start_table_noborder();
show_description();
show_questions();
show_picture_option();
show_finale();
end_table();
close_form();
page_tail();
}
function setup_form() {
if ($_POST['submit']) {
process_results();
exit();
}
echo "
<form action=", $_SERVER['PHP_SELF'], " method=\"POST\", ENCTYPE=\"multipart/form-data\">
";
}
function close_form() {
echo "</form>";
}
function show_description() {
global $profile_info;
global $user;
$profile_info?row1("Edit User Profile: " . $user->name):row1("Create a User Profile");
rowify("
By creating a <b>user profile</b> you can share your opinions and background
with the entire ".PROJECT." community.
");
rowify("<br>");
}
function show_questions() {
show_profile_heading1();
show_profile_question1();
rowify("<br>");
show_textarea('response1');
rowify("<br>");
show_profile_heading2();
show_profile_question2();
rowify("<br>");
show_textarea('response2');
rowify("<br>");
show_language_selection();
rowify("<br>");
}
function show_textarea($name) {
global $profile_info;
rowify("<textarea name=\"$name\" cols=80 rows=20>" . $profile_info[$name] . "</textarea>");
}
function show_picture_option() {
global $profile_info;
row1("Your Picture");
if ($profile_info['has_picture']) {
echo "
<tr><td colspan=2>
<table border=0 cellpadding=5
<tr>
<td><a href=\"" . IMAGE_PATH . $profile_info['userid'] . '.jpg' . "\"><img src=\"" . IMAGE_PATH . $profile_info['userid'] . '_sm.jpg' . "\"></a><p>
<input type=\"checkbox\" name=\"delete_pic\">Delete
</td>
<td>You have previously uploaded a picture of yourself to accompany your profile, shown at left.
If you would like to replace it, please click the \"Browse\" button and select the JPEG or PNG file
you would like to use instead. (No animated GIFs, please!) If you would rather not have a picture
with your profile, click the \"Delete\" checkbox. If you like your current picture, there is no need
to do anything.<p>
<input name=\"picture\" type=\"file\"><br>
<font size=2><b>NOTE: </b>Please keep your image small (less than 50K bytes)<br></font></td>
</tr>";
end_table();
echo "</td></tr>";
}
else {
rowify("
Do you have a picture of yourself on your computer?
If you would like us to include it with your profile,
please click the \"Browse\" button and select the JPEG or PNG file
you want to send. (No animated GIFs, please!)<br>
<input name=\"picture\" type=\"file\"><br>
<font size=2><b>NOTE: </b>Please keep your image small (less than 50K bytes)<br></font>
</td></tr>
");
}
}
function show_language_selection() {
global $profile_info;
row1("Select Your Primary Language");
rowify("Selecting a language will help others with the same language preference to find each others' profiles and message board postings.");
echo "<tr><td>";
if ($profile_info) {
show_combo_box("language", LANGUAGE_FILE, $profile_info['language']);
} else {
show_combo_box("language", LANGUAGE_FILE, "English");
}
echo "</td></tr>\n";
}
function show_finale() {
row1("Submit Your Profile");
rowify("
<br><input type=\"submit\" value=\"Submit\" name=\"submit\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type=\"reset\" value=\"Clear\" name=\"clear\">");
}
function process_results() {
global $user;
global $profile_info;
$response1 = $_POST['response1'];
$response2 = $_POST['response2'];
$language = $_POST['language'];
$delete_pic = $_POST['delete_pic'];
if (strlen($response1)==0 &&
strlen($response2)==0 &&
$delete_pic != "on" &&
!is_uploaded_file($_FILES['picture']['tmp_name'])) {
profile_error_page("Your profile submission was empty.");
exit();
}
// TODO: Having the delete checkbox and pic file form might confuse users.
// Should figure out a better way to handle this. Also might want to
// present some sort of verification dialog (javascript).
if ($delete_pic == "on") {
delete_user_pictures($profile_info['userid']);
$profile_info['has_picture'] = false;
}
$profile_info ? $hasPicture = $profile_info['has_picture']: $hasPicture = false;
if (is_uploaded_file($_FILES['picture']['tmp_name'])) {
$hasPicture = true;
/*
echo "<br>Name: " . $_FILES['picture']['name'];
echo "<br>Type: " . $_FILES['picture']['type'];
echo "<br>Size: " . $_FILES['picture']['size'];
echo "<br>Temp name: " . $_FILES['picture']['tmp_name'];
*/
$images = getImages($_FILES['picture']['tmp_name']);
// Write the original image file to disk.
// TODO: define a constant for image quality.
ImageJPEG($images[0], IMAGE_PATH . $user->id . '.jpg', 10);
ImageJPEG($images[1], IMAGE_PATH . $user->id . '_sm.jpg', 10);
}
if ($profile_info) {
$query = 'UPDATE profile SET '
." response1 = '$response1',"
." response2 = '$response2',"
." language = '$language',"
." has_picture = '$hasPicture'"
." WHERE userid = '$user->id'";
} else {
$query = 'INSERT INTO profile SET '
." userid = '$user->id',"
." language = '$language',"
." response1 = '$response1',"
." response2 = '$response2',"
." has_picture = '$hasPicture'";
}
$result = mysql_query($query);
if (!$result) {
profile_error_page("Couldn't create profile: database error!");
exit();
}
show_result_page();
}
// Returns an array containing:
// [0]: The original image refered to by $fileName if its dimensions are
// less than MAX_IMG_WIDTH x MAX_IMG_HEIGHT, or a version scaled to
// those dimensions if it was too large.
// [1]: A scaled version of the above.
function getImages($fileName) {
$size = getImageSize($fileName);
// Determine if the filetype uploaded is supported.
// TODO: Change these to constants.
switch($size[2]) {
case '2': // JPEG
$image = imageCreateFromJPEG($fileName);
break;
case '3': // PNG
$image = imageCreateFromPNG($fileName);
break;
default:
profile_error_page("The format of your uploaded image is not supported by our system.");
exit();
}
$width = $size[0];
$height = $size[1];
$smallImage = scale_image($image, $width, $height, SMALL_IMG_WIDTH, SMALL_IMG_HEIGHT);
if ($width > MAX_IMG_WIDTH || $height > MAX_IMG_HEIGHT) {
$image = scale_image($image, $width, $height, MAX_IMG_WIDTH, MAX_IMG_HEIGHT);
}
/*($width > $height)? $scalar = ($width / SMALL_IMG_WIDTH) : $scalar = ($height / SMALL_IMG_HEIGHT);
$dest_width = $width / $scalar;
$dest_height = $height / $scalar;
$horiz_offset = (SMALL_IMG_WIDTH - $dest_width) / 2;
$vert_offset = (SMALL_IMG_HEIGHT - $dest_height) / 2;
// TODO: Switch once GD 2.0+ is installed.
//$smallImage = ImageCreateTrueColor(SMALL_IMG_WIDTH, SMALL_IMG_HEIGHT);
$smallImage = ImageCreate(SMALL_IMG_WIDTH, SMALL_IMG_HEIGHT);
// TODO: Switch once GD 2.0+ is installed.
//ImageCopyResampled($smallImage, $image, $horiz_offset, $vert_offset, 0, 0, $dest_width, $dest_height, $width, $height);
ImageCopyResized($smallImage, $image, $horiz_offset, $vert_offset, 0, 0, $dest_width, $dest_height, $width, $height);
*/
/*
echo "<br><br>Image type: $size[2]";
echo "<br>Original width: $width";
echo "<br>Original height: $height";
echo "<br>Scalar: $scalar";
echo "<br>Dest width: " . ($width / $scalar);
echo "<br>Dest height: " . ($height / $scalar);
echo "<br>Horizontal offset: $horiz_offset";
echo "<br>Vertical offset: $vert_offset";
echo "<br><br><a href=\"images/user_profile/test.jpg\">View result</a>";
*/
return array($image, $smallImage);
}
function scale_image($image, $origWidth, $origHeight, $targetWidth, $targetHeight) {
($origWidth > $origHeight)? $scalar = ($origWidth / $targetWidth) : $scalar = ($height / $targetHeight);
$dest_width = $origWidth / $scalar;
$dest_height = $origHeight / $scalar;
$horiz_offset = ($targetWidth - $dest_width) / 2;
$vert_offset = ($targetHeight - $dest_height) / 2;
// TODO: Switch once GD 2.0+ is installed.
//$newImage = ImageCreateTrueColor($targetWidth, $targetHeight);
$newImage = ImageCreate($targetWidth, $targetHeight);
// TODO: Switch once GD 2.0+ is installed.
//ImageCopyResampled($newImage, $image, $horiz_offset, $vert_offset, 0, 0, $dest_width, $dest_height, $origWidth, $origHeight);
ImageCopyResized($newImage, $image, $horiz_offset, $vert_offset, 0, 0, $dest_width, $dest_height, $origWidth, $origHeight);
return $newImage;
}
function show_result_page() {
global $user;
page_head("Profile Saved");
echo "
<h1>Congratulations!</h1><p>
Your profile was successfully entered into our database.<br><br>
<a href=view_profile.php?userid=$user->id>View your profile</a><br>
";
page_tail();
}
?>

View File

@ -0,0 +1,81 @@
<?php
require_once("util.inc");
require_once("project.inc");
db_init();
if ($_GET['cmd']) {
execute_command();
exit();
}
page_head("Profile Zone");
start_table_noborder();
row1("User Profiles");
rowify("
<ul>
<li>View the <a href=" . PROFILE_PATH . "user_gallery_1.html>User Picture Gallery</a>. <a href=generate_picture_pages.php>[Generate]</a>
<li>Browse profiles <a href=" . PROFILE_PATH . "profile_country.html>by country</a>. <a href=generate_country_pages.php>[Generate]</a>
<li>Browse profiles <a href=" . $_SERVER['PHP_SELF'] . "?cmd=rand>at random</a>,
<a href=" . $_SERVER['PHP_SELF'] . "?cmd=rand&pic=1>at random with pictures</a>, or
<a href=" . $_SERVER['PHP_SELF'] . "?cmd=rand&pic=0>at random without pictures</a>.
<li>Alphabetical profile listings:<br>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<BR>
</ul>");
row1("Search");
end_table();
echo "
<form action=", $_SERVER['PHP_SELF'], " method=\"GET\">
<input type=\"hidden\" name=\"cmd\" value=\"search\">
<input type=\"text\" name=\"name\">
<input type=\"submit\" value=\"Submit\">
</form>";
end_table();
page_tail();
function execute_command() {
// Request for a random profile.
if ($_GET['cmd'] == "rand") {
if ($_GET['pic']) {
if ($_GET['pic'] == 0) {
$result = mysql_query("SELECT userid FROM profile WHERE has_picture = 0");
} else if ($_GET['pic'] == 1) {
$result = mysql_query("SELECT userid FROM profile WHERE has_picture = 1");
}
} else {
$result = mysql_query("SELECT userid FROM profile");
}
while ($row = mysql_fetch_row($result)) {
$userIds[] = $row[0];
}
shuffle($userIds);
header("Location: " . MASTER_URL . "view_profile.php?userid=" . $userIds[0]);
exit();
}
else if ($_GET['cmd'] == "search") {
if ($_GET['name']) {
$result = mysql_query("SELECT id FROM user WHERE name = " . $_GET['name']);
if ($result) {
while ($row = mysql_fetch_row($result)) {
echo "<br>ID ", $row['0'], " has a name that matches your query.";
}
} else {
echo "No names matched your query.<br>";
}
}
}
}
?>

152
html/user/view_profile.php Normal file
View File

@ -0,0 +1,152 @@
<?php
require_once("project.inc");
require_once("util.inc");
require_once("db.inc");
// TODO: Fix javascript popup tables- they are currently wrapping past
// the edge of the screen.
db_init();
$userid = $_GET['userid'];
if (!$userid) {
profile_error_page("No user ID was specified.<p>");
exit();
}
$user = get_user_from_id($userid);
if (!$user) {
profile_error_page("No user exists for that ID, or there was a database error.<p>");
exit();
}
// Check for recommendation or rejection votes.
if ($_POST['recommend']) {
process_results("recommend");
exit();
} else if ($_POST['reject']) {
process_results("reject");
exit();
}
$result = mysql_query("SELECT * FROM profile WHERE userid = $user->id");
if ($result) {
$profile_info = mysql_fetch_array($result, MYSQL_ASSOC);
}
else {
profile_error_page("No profile exists for that user, or there was a database error.<p>");
exit();
}
$logged_in_user = get_logged_in_user(false); // (false) since anyone can look at profiles.
$can_edit = $logged_in_user && $user->id == $logged_in_user->id;
page_head("User Profile: ".$user->name);
if ($can_edit) {
echo "<a href=create_profile.php>[Edit Your Profile]</a>";
}
start_table_noborder();
echo "<tr><td>";
show_profile_summary();
echo "</tr></td>";
show_profile_heading1();
echo "<tr><td>", $profile_info['response1'], "<br><br></td></tr>";
show_profile_heading2();
echo "<tr><td>", $profile_info['response2'], "</td></tr>";
end_table();
page_tail();
function show_profile_summary() {
global $user;
global $profile_info;
global $can_edit;
echo "
<table border=0 cellpadding = 1 width=100%>\n
<tr><td><h1>$user->name</h1></td><td align=\"center\">";
if (!$can_edit) {
show_buttons();
}
echo "</td></tr>\n<tr><td colspan=\"2\">\n";
// Only display an image if the user has uploaded one.
if (file_exists(IMAGE_PATH . $user->id . '_sm.jpg')) {
echo "
<a href=\"" , IMAGE_PATH , $user->id , '.jpg' . "\"><img align=left vspace=6 hspace=9 src=\"" , IMAGE_PATH , $user->id , '_sm.jpg' . "\"></a>\n";
}
echo "
<font size=\"-1\">
<b>Country:</b> ", $user->country, "&nbsp&nbsp<b>Language:</b> ", $profile_info['language'], "<br>
<b>Email:</b> <a href=\"mailto:", $user->email_addr, "\">", $user->email_addr, "</a><br>
<b>Total Credit:</b> ", $user->total_credit, "<br>";
if ($user->teamid) {
$result = mysql_query("select * from team where id = $user->teamid");
$team = mysql_fetch_object($result);
echo "<b>Team:</b> <a href=team_display.php?teamid=$team->id>$team->name</a><br>";
}
echo "
<b>Date Registered:</b> ", date_str($user->create_time), "
</font>
</td></tr>
</table>
<br>\n";
}
function show_buttons() {
global $userid;
echo "
<form action=", $_SERVER['PHP_SELF'], "?userid=$userid method=\"POST\">
<input type=\"submit\" name=\"recommend\" value=\"RECOMMEND\">
<font size=-1><a href=\"javascript:;\" onClick=\"window.open ('explanation.php?val=recommend','_blank','width=350,height=200,left=50,top=150,menubar=0,directories=0,scrollbars=0,resizable=0,status=0')\">what is recommend?</a></font>
<br>
<input type=\"submit\" name=\"reject\" value=\"VOTE TO REJECT\">
<font size=-1><a href=\"javascript:;\" onClick=\"window.open ('explanation.php?val=reject','_blank','width=350,height=200,left=50,top=150,menubar=0,directories=0,scrollbars=0,resizable=0,status=0')\">what is vote to reject?</a></font>
</form>
";
}
function process_results($vote) {
global $userid;
if ($vote != "recommend" && $vote != "reject") {
echo "Invalid vote type.<br>";
exit();
}
$result = mysql_query("SELECT * FROM profile WHERE userid = $userid");
$profile = mysql_fetch_array($result);
$newValue = $profile[$vote] + 1;
$newresult = mysql_query("UPDATE profile SET $vote = $newValue WHERE userid = $userid");
page_head("Vote Recorded");
start_table_noborder();
row1("Thank you");
if ($vote == "recommend") {
rowify("Your recommendation has been recorded.");
} else {
rowify("Your vote to reject has been recorded.");
}
end_table();
echo "<br><a href=\"view_profile.php?userid=", $userid ,"\">Return to profile.</a>";
page_tail();
}
?>