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 "
";
}
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 user profile you can share your opinions and background
with the entire ".PROJECT." community.
");
rowify(" ");
}
function show_questions() {
show_profile_heading1();
show_profile_question1();
rowify(" ");
show_textarea('response1');
rowify(" ");
show_profile_heading2();
show_profile_question2();
rowify(" ");
show_textarea('response2');
rowify(" ");
show_language_selection();
rowify(" ");
}
function show_textarea($name) {
global $profile_info;
rowify("");
}
function show_picture_option() {
global $profile_info;
row1("Your Picture");
if ($profile_info['has_picture']) {
echo "
Delete
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.
NOTE: Please keep your image small (less than 50K bytes)
";
end_table();
echo "";
}
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!)
NOTE: Please keep your image small (less than 50K bytes)
");
}
}
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 "
View result";
*/
return array($image, $smallImage);
}
function scale_image($image, $origWidth, $origHeight, $targetWidth, $targetHeight) {
// If the image is already smaller than the target dimensions, just return it.
if ($origWidth <= $targetWidth && $origHeight <= $targetHeight) {
return $image;
}
($origWidth > $origHeight)? $scalar = ($origWidth / $targetWidth) : $scalar = ($origHeight / $targetHeight);
if ($scalar != 0) {
$destWidth = $origWidth / $scalar;
$destHeight = $origHeight / $scalar;
} else {
$destWidth = $origWidth;
$destHeight = $origHeight;
}
$newImage = ImageCreateTrueColor($destWidth, $destHeight);
ImageCopyResampled($newImage, $image, 0, 0, 0, 0, $destWidth, $destHeight, $origWidth, $origHeight);
return $newImage;
}
function show_result_page() {
global $user;
page_head("Profile Saved");
echo "
Congratulations!
Your profile was successfully entered into our database.
id>View your profile
";
page_tail();
}
// Builds a summary table of user profiles, writing it to $descriptor if it is
// available, or echoing if it is not.
//
// $members is an array of userIDs;
// $offset indicates which entry to begin the table with
// $numToDisplay indicates how many profiles to display in this table
// $cols indicates how many profile summaries should be written per row
// $descriptor is an optional file descriptor to write the table to.
// $pathMod is an optional path which is prepended to the image path. Useful
// when the image path is not relative to the directory from which this
// function is called.
function show_user_table($members, $offset, $numToDisplay, $cols, $descriptor=null, $pathMod=null) {
// TODO: Would be nice if we could open a stream to stdout to avoid
// all the redundant $descriptor checks. Once the server is running
// PHP 5+, might want to try switching over to fprintf(...).
if ($descriptor) {
fwrite($descriptor, "
";
}
// Formatting is a table with two columns of user summaries.
for ($col = 0; $col < $cols; $col++) {
if ($count < $numMembers) {
if ($descriptor) {
fwrite($descriptor, "
");
} else {
echo "
";
}
// Only link an image if one exists.
if (file_exists($pathMod . IMAGE_PATH . $members[$count] . '_sm.jpg')) {
if ($descriptor) {
fwrite($descriptor, "");
} else {
echo "";
}
} else {
if ($descriptor) {
fwrite($descriptor, " ");
} else {
echo " ";
}
}
if ($descriptor) {
fwrite($descriptor, "
";
}
}
// Generates a string containing:
// 1) the name of the user with ID == $userid, with a link to a view of their profile;
// 2) the first MAX_DESC_LENGTH characters from the response1 field of said user's profile.
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);
$description = "";
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 = "" . $row2['name'] . " " . $description;
return $summary;
}
?>