id); if ($_POST['submit']) { process_create_results($user, $profile); exit(); } if ($profile) { page_head("Edit your Profile"); } else { page_head("Create a Profile"); } setup_form($user, $profile); start_table_noborder(); show_description($user, $profile); show_questions($profile); show_picture_option($profile); show_finale(); end_table(); close_form(); page_tail(); } function setup_form($user, $profile) { //
// multipart/form-data doesn't always work (?) echo " "; } function close_form() { echo "
"; } function show_description($user, $profile) { if ($profile) { row1("Edit your profile"); } else { row1("Create a profile"); } rowify(" Your profile lets you share your opinions and background with the ".PROJECT." community.
You may use HTML tags "); rowify("
"); } function show_questions($profile) { show_profile_heading1(); show_profile_question1(); rowify("
"); show_textarea("response1", $profile->response1); rowify("
"); show_profile_heading2(); show_profile_question2(); rowify("
"); show_textarea("response2", $profile->response2); rowify("
"); show_language_selection($profile); rowify("
"); } function show_textarea($name, $text) { rowify(""); } function show_picture_option($profile) { row1("Your Picture"); if ($profile->has_picture) { echo " "; rowify("
"); 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)
"); rowify("
"); } } function show_language_selection($profile) { 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 "\n"; } function show_finale() { row1("Submit Your Profile"); rowify("

        " ); } // If the user with id = $userid has uploaded a picture his/herself, // delete it and its thumbnail. // function delete_user_pictures($userid) { $filename1 = IMAGE_PATH . $userid . '.jpg'; $filename2 = IMAGE_PATH . $userid . '_sm.jpg'; if (file_exists($filename1)) { unlink($filename1); } if (file_exists($filename2)) { unlink($filename2); } } function process_create_results($user, $profile) { $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(); } if ($delete_pic == "on") { delete_user_pictures($profile->userid); $profile->has_picture = false; } $profile ? $hasPicture = $profile->has_picture: $hasPicture = false; if (is_uploaded_file($_FILES['picture']['tmp_name'])) { $hasPicture = true; /* echo "
Name: " . $_FILES['picture']['name']; echo "
Type: " . $_FILES['picture']['type']; echo "
Size: " . $_FILES['picture']['size']; echo "
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'); ImageJPEG($images[1], IMAGE_PATH . $user->id . '_sm.jpg'); } $response1 = sanitize_html($response1); $response2 = sanitize_html($response2); if ($profile) { $query = 'UPDATE profile SET ' ." response1 = '$response1'," ." response2 = '$response2'," ." language = '$language'," ." has_picture = '$hasPicture'" ." WHERE userid = '$user->id'"; $result = mysql_query($query); if (!$result) { profile_error_page("Couldn't update profile: database error"); exit(); } } else { $query = 'INSERT INTO profile SET ' ." userid = '$user->id'," ." language = '$language'," ." response1 = '$response1'," ." response2 = '$response2'," ." has_picture = '$hasPicture'," ." verification=0"; $result = mysql_query($query); if (!$result) { profile_error_page("Couldn't create profile: database error"); exit(); } $q = "update user set has_profile=1 where id=$user->id"; mysql_query($q); } show_result_page($user); } // 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); } /* echo "

Image type: $size[2]"; echo "
Original width: $width"; echo "
Original height: $height"; echo "
Scalar: $scalar"; echo "
Dest width: " . ($width / $scalar); echo "
Dest height: " . ($height / $scalar); echo "
Horizontal offset: $horiz_offset"; echo "
Vertical offset: $vert_offset"; 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; } if (1) { // If you are using a modern PHP/GD installation that does 'truecolor' images, this is what's needed. $newImage = ImageCreateTrueColor($destWidth, $destHeight); ImageCopyResampled($newImage, $image, 0, 0, 0, 0, $destWidth, $destHeight, $origWidth, $origHeight); } else { // If not, use this block. The image quality is lower but it works using older PHP/GD versions. $newImage = ImageCreate($destWidth, $destHeight); ImageCopyResized($newImage, $image, 0, 0, 0, 0, $destWidth, $destHeight, $origWidth, $origHeight); } return $newImage; } function show_result_page($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. // // $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. function show_user_table($members, $offset, $numToDisplay, $cols) { echo "

userid . '.jpg' . "\">userid . '_sm.jpg' . "\">

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. If you would rather not have a picture with your profile, click the \"Delete\" checkbox; your picture will be deleted as soon as you submit this form. If you're happy with your current picture, there is no need to do anything.


NOTE: Please keep your image small (less than 50K bytes)

"; if (strlen($profile->language)) { show_combo_box("language", LANGUAGE_FILE, $profile->language); } else { show_combo_box("language", LANGUAGE_FILE, "English"); } echo "
\n"; $rows = ceil($numToDisplay / $cols); $count = $offset; $numMembers = count($members); for ($row = 0; $row < $rows; $row++) { if ($count >= $numMembers) { break; } echo "\n"; for ($col = 0; $col < $cols; $col++) { if ($count < $numMembers) { $profile = get_profile($members[$count]); if (!$profile) { $numMembers--; continue; } echo ""; $count++; } else { echo ""; } } echo "\n"; } echo "
"; // Only link an image if the user has uploaded one.; if ($profile->has_picture) { echo ""; } else { echo " "; } echo "
\n", get_profile_summary($profile), "
\n"; } // 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($profile) { $user = get_user_from_id($profile->userid); if (!$user || !$profile) { echo "Database error!"; // Change this to a standard error page. exit(); } $description = ""; if (strlen($profile->response1) != 0) { $temp = $profile->response1; $description = "(\"" . sub_sentence(strip_tags($temp), ' ', MAX_DESC_LENGTH, true) . "\")"; } $summary = "" . $user->name . " " . $description; return $summary; } // Displays a user's profile (if they have one); function show_profile($userid, $verify_mode=false) { $user = get_user_from_id($userid); if (!$user) { profile_error_page("No user exists for that ID, or there was a database error.

"); exit(); } if (!$verify_mode) { $logged_in_user = get_logged_in_user(false); // (false) since anyone can look at profiles.; if (!$logged_in_user || ($user->id != $logged_in_user->id)) { $caching = true; $cache_args = "userid=$userid"; start_cache(USER_PROFILE_TTL,$cache_args); } } $profile = get_profile($userid); if (!$profile) { echo "No user profile exists for that user ID."; exit(); } if (!$verify_mode) { $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; if (!$verify_mode) { page_head("Profile: ".$user->name); } if ($can_edit) { echo "[Edit Your Profile]"; } show_profile_summary($user, $profile, $can_edit, $verify_mode); echo "

"; show_profile_heading1(); echo $profile->response1; echo "

"; show_profile_heading2(); echo $profile->response2; if (!$verify_mode) { page_tail(); } if ($caching) end_cache(USER_PROFILE_TTL,$cache_args); } function show_profile_summary($user, $profile, $can_edit, $verify_mode) { if (!$can_edit && !$verify_mode) { show_view_buttons($user->id); } // Only display an image if the user has uploaded one; if ($profile->has_picture) { //echo "id , '.jpg' . "\">id , '_sm.jpg' . "\">\n"; echo "
id , '.jpg' . "\">\n"; } echo "
Country: ", $user->country, "
Language: ", $profile->language, "
"; echo "Total Credit: ", $user->total_credit, "
"; if ($user->teamid) { $result = mysql_query("select * from team where id = $user->teamid"); $team = mysql_fetch_object($result); echo "Team: id>$team->name
"; } echo " Date Registered: ", date_str($user->create_time), "

\n "; } function show_view_buttons($userid) { echo "

what is recommend?
what is vote to reject?
"; } function process_view_results($vote, $userid) { if ($vote != "recommend" && $vote != "reject") { echo "Invalid vote type.
"; 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 "
Return to profile."; page_tail(); } // echo "\n"; ?>