2004-02-02 23:34:39 +00:00
|
|
|
<?php
|
2005-01-24 13:17:49 +00:00
|
|
|
$cvs_version_tracker[]="\$Id$"; //Generated automatically - do not edit
|
2004-02-02 23:34:39 +00:00
|
|
|
|
|
|
|
require_once("../inc/db.inc");
|
|
|
|
require_once("../inc/util.inc");
|
|
|
|
require_once("../inc/sanitize_html.inc");
|
2004-07-22 23:42:50 +00:00
|
|
|
require_once("../inc/cache.inc");
|
2005-04-08 00:06:52 +00:00
|
|
|
require_once("../inc/user.inc");
|
2005-10-01 01:39:32 +00:00
|
|
|
require_once("../inc/translation.inc");
|
2005-10-14 00:05:41 +00:00
|
|
|
require_once("../inc/text_transform.inc");
|
|
|
|
require_once("../inc/db_forum.inc");
|
2004-02-02 23:34:39 +00:00
|
|
|
|
|
|
|
define('SMALL_IMG_WIDTH', 64);
|
|
|
|
define('SMALL_IMG_HEIGHT', 64);
|
|
|
|
|
|
|
|
define('MAX_IMG_WIDTH', 800);
|
|
|
|
define('MAX_IMG_HEIGHT', 600);
|
|
|
|
|
|
|
|
define('MAX_DESC_LENGTH', 90);
|
|
|
|
|
|
|
|
define('GALLERY_WIDTH', 7);
|
|
|
|
define('GALLERY_HEIGHT', 4);
|
|
|
|
|
2005-09-26 20:01:01 +00:00
|
|
|
function profile_screening() {
|
|
|
|
$config = get_config();
|
|
|
|
return parse_bool($config, "profile_screening");
|
|
|
|
}
|
|
|
|
|
2005-09-25 05:47:48 +00:00
|
|
|
function profile_error_page($str) {
|
|
|
|
page_head("Profile error");
|
|
|
|
echo "$str<br>\n";
|
|
|
|
echo "<p>Click your browser's <b>Back</b> button to try again.\n<p>\n";
|
|
|
|
page_tail();
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
2005-02-13 06:13:33 +00:00
|
|
|
// output a select form item with the given name,
|
|
|
|
// from a list of newline-delineated items from the text file.
|
|
|
|
// If $selection is provided, and if it matches one of the entries in the file,
|
|
|
|
// it will be selected by default.
|
|
|
|
//
|
|
|
|
function show_combo_box($name, $filename, $selection=null) {
|
|
|
|
if (!file_exists($filename)) {
|
|
|
|
echo "ERROR: $filename does not exist! Cannot create combo box.<br>";
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
echo "<select name=\"$name\">\n";
|
|
|
|
|
|
|
|
$file = fopen($filename, "r");
|
|
|
|
|
|
|
|
while ($line = trim(fgets($file, 1024))) {
|
|
|
|
if ($line == $selection) {
|
|
|
|
echo "<option SELECTED value=\"$line\">$line\n";
|
|
|
|
} else {
|
|
|
|
echo "<option value=\"$line\">$line\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
echo "</select>\n";
|
|
|
|
fclose($file);
|
|
|
|
}
|
|
|
|
|
2004-05-30 21:47:11 +00:00
|
|
|
function get_profile($userid) {
|
|
|
|
$result = mysql_query("SELECT * FROM profile WHERE userid = $userid");
|
2004-06-15 22:55:54 +00:00
|
|
|
if (!$result) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2004-05-30 21:47:11 +00:00
|
|
|
$profile = mysql_fetch_object($result);
|
|
|
|
mysql_free_result($result);
|
|
|
|
return $profile;
|
|
|
|
}
|
2004-02-02 23:34:39 +00:00
|
|
|
|
2004-05-30 21:47:11 +00:00
|
|
|
function show_profile_creation_page($user) {
|
2004-03-24 22:53:47 +00:00
|
|
|
// If the user already has a profile,
|
|
|
|
// fill in the fields with their current values.
|
2004-05-30 21:47:11 +00:00
|
|
|
//
|
|
|
|
$profile = get_profile($user->id);
|
2005-10-01 18:30:15 +00:00
|
|
|
if (isset($_POST['submit']) && $_POST['submit']) {
|
2006-02-17 22:01:22 +00:00
|
|
|
process_create_profile($user, $profile);
|
2004-05-30 21:47:11 +00:00
|
|
|
exit();
|
2004-02-02 23:34:39 +00:00
|
|
|
}
|
|
|
|
|
2004-05-30 21:47:11 +00:00
|
|
|
if ($profile) {
|
2005-01-30 20:15:18 +00:00
|
|
|
page_head("Edit your profile");
|
2004-05-30 21:47:11 +00:00
|
|
|
} else {
|
2005-01-30 20:15:18 +00:00
|
|
|
page_head("Create a profile");
|
2004-05-30 21:47:11 +00:00
|
|
|
}
|
|
|
|
|
2005-01-09 09:07:22 +00:00
|
|
|
echo "
|
|
|
|
<form action=", $_SERVER['PHP_SELF'], " method=\"POST\", ENCTYPE=\"multipart/form-data\">
|
|
|
|
";
|
2004-02-02 23:34:39 +00:00
|
|
|
start_table_noborder();
|
2005-01-30 20:15:18 +00:00
|
|
|
show_description();
|
2004-05-30 21:47:11 +00:00
|
|
|
show_questions($profile);
|
|
|
|
show_picture_option($profile);
|
2005-01-30 20:15:18 +00:00
|
|
|
show_submit();
|
2004-02-02 23:34:39 +00:00
|
|
|
end_table();
|
|
|
|
echo "</form>";
|
2005-01-09 09:07:22 +00:00
|
|
|
page_tail();
|
2004-02-02 23:34:39 +00:00
|
|
|
}
|
|
|
|
|
2005-01-30 20:15:18 +00:00
|
|
|
function show_description() {
|
|
|
|
echo "
|
|
|
|
<p>
|
|
|
|
Your <b>profile</b> lets you share your opinions and background
|
|
|
|
with the ".PROJECT." community.
|
|
|
|
<p>
|
|
|
|
";
|
2004-02-02 23:34:39 +00:00
|
|
|
}
|
|
|
|
|
2004-05-30 21:47:11 +00:00
|
|
|
function show_questions($profile) {
|
2005-01-09 09:07:22 +00:00
|
|
|
row1(show_profile_heading1());
|
2005-01-30 20:15:18 +00:00
|
|
|
rowify(show_profile_question1().html_info());
|
2004-02-02 23:34:39 +00:00
|
|
|
rowify("<br>");
|
2006-08-13 04:27:24 +00:00
|
|
|
show_textarea("response1", stripslashes($profile->response1));
|
2004-02-02 23:34:39 +00:00
|
|
|
rowify("<br>");
|
2005-01-09 09:07:22 +00:00
|
|
|
row1( show_profile_heading2());
|
2005-01-30 20:15:18 +00:00
|
|
|
rowify( show_profile_question2().html_info());
|
2004-02-02 23:34:39 +00:00
|
|
|
rowify("<br>");
|
2006-08-13 04:27:24 +00:00
|
|
|
show_textarea("response2", stripslashes($profile->response2));
|
2004-02-02 23:34:39 +00:00
|
|
|
rowify("<br>");
|
2004-05-30 21:47:11 +00:00
|
|
|
show_language_selection($profile);
|
2004-02-02 23:34:39 +00:00
|
|
|
rowify("<br>");
|
|
|
|
}
|
|
|
|
|
2004-05-30 21:47:11 +00:00
|
|
|
function show_textarea($name, $text) {
|
|
|
|
rowify("<textarea name=\"$name\" cols=80 rows=20>" . $text . "</textarea>");
|
2004-02-02 23:34:39 +00:00
|
|
|
}
|
|
|
|
|
2005-09-11 07:31:42 +00:00
|
|
|
// When passed profile->verification, this function is used to tell the
|
|
|
|
// user the verification status of their profile.
|
|
|
|
//
|
|
|
|
function offensive_profile_warning($verify_flag) {
|
|
|
|
if ($verify_flag == 0) {
|
|
|
|
return "
|
|
|
|
<font size='+2' color='33cc33'>
|
|
|
|
Your profile will be made visible to other people<br>
|
|
|
|
as soon as it has been approved by the project.<br>
|
|
|
|
This may take up to a few days.<br>
|
2005-09-26 20:01:01 +00:00
|
|
|
</font>
|
|
|
|
";
|
2005-09-11 07:31:42 +00:00
|
|
|
} else if ($verify_flag == -1) {
|
|
|
|
return "
|
|
|
|
<font size='+2' color='ff3333'>
|
|
|
|
Your profile has been marked as unacceptable.<br>
|
|
|
|
It is not visible to other people. Please change it.<br>
|
2005-09-26 20:01:01 +00:00
|
|
|
</font>
|
|
|
|
";
|
2005-09-11 07:31:42 +00:00
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2004-05-30 21:47:11 +00:00
|
|
|
function show_picture_option($profile) {
|
2005-01-30 20:15:18 +00:00
|
|
|
row1("Picture");
|
2004-02-02 23:34:39 +00:00
|
|
|
|
2005-09-26 20:01:01 +00:00
|
|
|
$warning = "";
|
2005-10-01 16:00:31 +00:00
|
|
|
if (profile_screening() && $profile->has_picture) {
|
2005-09-26 20:01:01 +00:00
|
|
|
$warning = offensive_profile_warning($profile->verification);
|
|
|
|
}
|
|
|
|
|
2004-05-30 21:47:11 +00:00
|
|
|
if ($profile->has_picture) {
|
2004-02-02 23:34:39 +00:00
|
|
|
echo "
|
|
|
|
<tr><td colspan=2>
|
|
|
|
<table border=0 cellpadding=5
|
|
|
|
<tr>
|
2005-01-30 20:15:18 +00:00
|
|
|
<td valign=top><a href=\"" . IMAGE_URL . $profile->userid . '.jpg' . "\"><img src=\"" . IMAGE_URL . $profile->userid . '_sm.jpg' . "\"></a>
|
2004-02-02 23:34:39 +00:00
|
|
|
</td>
|
2005-09-26 20:01:01 +00:00
|
|
|
<td valign=top> $warning Your profile picture is shown at left.
|
2005-01-30 20:15:18 +00:00
|
|
|
<p>
|
|
|
|
To replace it,
|
|
|
|
click the \"Browse\" button and select a JPEG or PNG file (50KB or less).
|
2006-02-17 22:01:22 +00:00
|
|
|
<input name=picture type=file><br>
|
2005-01-30 20:15:18 +00:00
|
|
|
<p>
|
2006-02-17 22:01:22 +00:00
|
|
|
To remove it from your profile, check this box:
|
|
|
|
<input type=checkbox name=delete_pic>
|
2005-01-30 20:15:18 +00:00
|
|
|
<p>
|
|
|
|
</td></tr>";
|
2004-02-02 23:34:39 +00:00
|
|
|
rowify("<br>");
|
|
|
|
end_table();
|
|
|
|
echo "</td></tr>";
|
2005-09-26 20:01:01 +00:00
|
|
|
} else {
|
2004-02-02 23:34:39 +00:00
|
|
|
rowify("
|
2005-01-30 20:15:18 +00:00
|
|
|
If you would like include a picture with your profile,
|
|
|
|
click the \"Browse\" button and select a JPEG or PNG file.
|
|
|
|
Please select images of 50KB or less.
|
|
|
|
<p>
|
2006-02-17 22:01:22 +00:00
|
|
|
<input name=picture type=file>
|
2005-01-30 20:15:18 +00:00
|
|
|
");
|
2004-02-02 23:34:39 +00:00
|
|
|
rowify("<br>");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-05-30 21:47:11 +00:00
|
|
|
function show_language_selection($profile) {
|
2005-01-30 20:15:18 +00:00
|
|
|
row1("Language");
|
|
|
|
echo "<tr><td>
|
|
|
|
<p>
|
|
|
|
Select the language in which your profile is written:
|
|
|
|
<p>
|
|
|
|
";
|
2004-05-30 21:47:11 +00:00
|
|
|
if (strlen($profile->language)) {
|
|
|
|
show_combo_box("language", LANGUAGE_FILE, $profile->language);
|
2004-02-02 23:34:39 +00:00
|
|
|
} else {
|
|
|
|
show_combo_box("language", LANGUAGE_FILE, "English");
|
|
|
|
}
|
|
|
|
echo "</td></tr>\n";
|
|
|
|
}
|
|
|
|
|
2005-01-30 20:15:18 +00:00
|
|
|
function show_submit() {
|
|
|
|
row1("Submit profile");
|
|
|
|
rowify("<p><input type=submit value=OK name=submit>");
|
2004-02-02 23:34:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-02 23:47:25 +00:00
|
|
|
// $profile is null if user doesn't already have a profile.
|
|
|
|
// Don't assign to $profile->x if this is the case.
|
|
|
|
//
|
2006-02-17 22:01:22 +00:00
|
|
|
function process_create_profile($user, $profile) {
|
2004-02-02 23:34:39 +00:00
|
|
|
$response1 = $_POST['response1'];
|
|
|
|
$response2 = $_POST['response2'];
|
|
|
|
$language = $_POST['language'];
|
2005-10-01 17:17:00 +00:00
|
|
|
if (isset($_POST['delete_pic'])) {
|
|
|
|
$delete_pic = $_POST['delete_pic'];
|
|
|
|
} else {
|
|
|
|
$delete_pic = "off";
|
|
|
|
}
|
2004-02-02 23:34:39 +00:00
|
|
|
|
|
|
|
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") {
|
2004-05-30 21:47:11 +00:00
|
|
|
delete_user_pictures($profile->userid);
|
|
|
|
$profile->has_picture = false;
|
2005-09-11 07:31:42 +00:00
|
|
|
$profile->verification = 0;
|
2004-02-02 23:34:39 +00:00
|
|
|
}
|
|
|
|
|
2004-05-30 21:47:11 +00:00
|
|
|
$profile ? $hasPicture = $profile->has_picture: $hasPicture = false;
|
2004-02-02 23:34:39 +00:00
|
|
|
|
|
|
|
if (is_uploaded_file($_FILES['picture']['tmp_name'])) {
|
|
|
|
$hasPicture = true;
|
2005-11-02 23:47:25 +00:00
|
|
|
if ($profile) $profile->verification = 0;
|
2004-02-02 23:34:39 +00:00
|
|
|
|
2005-01-09 09:07:22 +00:00
|
|
|
// 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'];
|
2004-02-02 23:34:39 +00:00
|
|
|
|
2005-01-09 09:07:22 +00:00
|
|
|
$images = getImages($_FILES['picture']['tmp_name']);
|
2004-02-02 23:34:39 +00:00
|
|
|
|
2005-01-09 09:07:22 +00:00
|
|
|
// 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');
|
2004-02-02 23:34:39 +00:00
|
|
|
}
|
|
|
|
$response1 = sanitize_html($response1);
|
|
|
|
$response2 = sanitize_html($response2);
|
2004-05-30 21:47:11 +00:00
|
|
|
if ($profile) {
|
2004-02-02 23:34:39 +00:00
|
|
|
$query = 'UPDATE profile SET '
|
2005-11-29 21:28:12 +00:00
|
|
|
." response1 = '".mysql_escape_string($response1)."',"
|
|
|
|
." response2 = '".mysql_escape_string($response2)."',"
|
|
|
|
." language = '".mysql_escape_string($language)."',"
|
2005-09-25 16:18:01 +00:00
|
|
|
." has_picture = '$hasPicture',"
|
2005-09-11 07:31:42 +00:00
|
|
|
." verification = '$profile->verification'"
|
2004-02-02 23:34:39 +00:00
|
|
|
." WHERE userid = '$user->id'";
|
|
|
|
$result = mysql_query($query);
|
|
|
|
if (!$result) {
|
2005-11-29 21:28:12 +00:00
|
|
|
echo mysql_error();
|
2004-02-02 23:34:39 +00:00
|
|
|
profile_error_page("Couldn't update profile: database error");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$query = 'INSERT INTO profile SET '
|
|
|
|
." userid = '$user->id',"
|
2005-11-29 21:28:12 +00:00
|
|
|
." language = '".mysql_escape_string($language)."',"
|
|
|
|
." response1 = '".mysql_escape_string($response1)."',"
|
|
|
|
." response2 = '".mysql_escape_string($response2)."',"
|
2004-06-09 21:42:23 +00:00
|
|
|
." has_picture = '$hasPicture',"
|
|
|
|
." verification=0";
|
2004-02-02 23:34:39 +00:00
|
|
|
$result = mysql_query($query);
|
|
|
|
if (!$result) {
|
|
|
|
profile_error_page("Couldn't create profile: database error");
|
|
|
|
}
|
2005-01-09 09:07:22 +00:00
|
|
|
mysql_query("update user set has_profile=1 where id=$user->id");
|
2004-02-02 23:34:39 +00:00
|
|
|
}
|
|
|
|
|
2004-05-30 21:47:11 +00:00
|
|
|
show_result_page($user);
|
2004-02-02 23:34:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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.");
|
|
|
|
}
|
|
|
|
|
|
|
|
$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 "<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);
|
|
|
|
}
|
|
|
|
|
2005-09-26 20:01:01 +00:00
|
|
|
function scale_image(
|
|
|
|
$image, $origWidth, $origHeight, $targetWidth, $targetHeight
|
|
|
|
) {
|
2004-02-02 23:34:39 +00:00
|
|
|
|
2005-09-26 20:01:01 +00:00
|
|
|
// If the image is already smaller than the target dimensions,
|
|
|
|
// just return it.
|
|
|
|
//
|
2004-02-02 23:34:39 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2005-09-26 20:01:01 +00:00
|
|
|
$gd_info = gd_info();
|
|
|
|
$newGD = (strstr($gd_info["GD Version"], "2.0")!="");
|
|
|
|
if ($newGD) {
|
|
|
|
// 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
|
|
|
|
);
|
|
|
|
}
|
2004-02-02 23:34:39 +00:00
|
|
|
|
|
|
|
return $newImage;
|
|
|
|
}
|
|
|
|
|
2004-05-30 21:47:11 +00:00
|
|
|
function show_result_page($user) {
|
2004-02-02 23:34:39 +00:00
|
|
|
page_head("Profile Saved");
|
|
|
|
|
|
|
|
echo "
|
2004-05-14 22:57:59 +00:00
|
|
|
<h2>Congratulations!</h2><p>
|
2004-02-02 23:34:39 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2004-06-15 18:50:57 +00:00
|
|
|
// Builds a summary table of user profiles.
|
2004-02-02 23:34:39 +00:00
|
|
|
//
|
|
|
|
// $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.
|
|
|
|
|
2004-06-15 18:50:57 +00:00
|
|
|
function show_user_table($members, $offset, $numToDisplay, $cols) {
|
|
|
|
echo "<table class=bordered border=1 cellpadding=5>\n";
|
2004-02-02 23:34:39 +00:00
|
|
|
|
|
|
|
$rows = ceil($numToDisplay / $cols);
|
|
|
|
$count = $offset;
|
|
|
|
$numMembers = count($members);
|
|
|
|
|
|
|
|
for ($row = 0; $row < $rows; $row++) {
|
|
|
|
if ($count >= $numMembers) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2004-06-15 18:50:57 +00:00
|
|
|
echo "<tr>\n";
|
2004-02-02 23:34:39 +00:00
|
|
|
|
|
|
|
for ($col = 0; $col < $cols; $col++) {
|
|
|
|
if ($count < $numMembers) {
|
2004-06-15 22:55:54 +00:00
|
|
|
$profile = get_profile($members[$count]);
|
|
|
|
if (!$profile) {
|
|
|
|
$numMembers--;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2004-06-15 18:50:57 +00:00
|
|
|
echo "<td class=bordered width=7% height=64><center>";
|
2004-02-02 23:34:39 +00:00
|
|
|
|
2005-09-26 20:01:01 +00:00
|
|
|
$show_picture = $profile->has_picture;
|
|
|
|
if (profile_screening() && $profile->verification != 1) {
|
|
|
|
$show_picture = false;
|
|
|
|
}
|
|
|
|
if ($show_picture) {
|
2004-06-15 18:50:57 +00:00
|
|
|
echo "<a href=\"", URL_BASE, "view_profile.php?userid={$members[$count]}\"><img src=\"", URL_BASE, IMAGE_URL, "{$members[$count]}_sm.jpg\"></a>";
|
2004-02-02 23:34:39 +00:00
|
|
|
|
|
|
|
} else {
|
2004-06-15 18:50:57 +00:00
|
|
|
echo " ";
|
2004-02-02 23:34:39 +00:00
|
|
|
}
|
|
|
|
|
2004-06-15 18:50:57 +00:00
|
|
|
echo "</center></td><td class=bordered width=33% height=64>\n", get_profile_summary($profile), "</td>";
|
2004-02-02 23:34:39 +00:00
|
|
|
$count++;
|
|
|
|
} else {
|
2004-06-15 18:50:57 +00:00
|
|
|
echo "<td width=7% height=64></td><td width=33% height=64></td>";
|
2004-02-02 23:34:39 +00:00
|
|
|
}
|
|
|
|
}
|
2004-06-15 18:50:57 +00:00
|
|
|
echo "</tr>\n";
|
2004-02-02 23:34:39 +00:00
|
|
|
}
|
2004-06-15 18:50:57 +00:00
|
|
|
echo "</table>\n";
|
2004-02-02 23:34:39 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Generates a string containing:
|
2005-09-26 20:01:01 +00:00
|
|
|
// 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.
|
2004-02-02 23:34:39 +00:00
|
|
|
|
|
|
|
function get_profile_summary($profile) {
|
2004-05-30 21:47:11 +00:00
|
|
|
$user = get_user_from_id($profile->userid);
|
2004-02-02 23:34:39 +00:00
|
|
|
|
2004-05-30 21:47:11 +00:00
|
|
|
if (!$user || !$profile) {
|
2004-02-02 23:34:39 +00:00
|
|
|
echo "Database error!"; // Change this to a standard error page.
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
$description = "";
|
|
|
|
|
2004-05-30 21:47:11 +00:00
|
|
|
if (strlen($profile->response1) != 0) {
|
|
|
|
$temp = $profile->response1;
|
2004-02-02 23:34:39 +00:00
|
|
|
$description = "(\"" . sub_sentence(strip_tags($temp), ' ', MAX_DESC_LENGTH, true) . "\")";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2004-05-30 21:47:11 +00:00
|
|
|
$summary = "<a href=\"" . URL_BASE . "view_profile.php?userid=" . $profile->userid . "\">" . $user->name . "</a> " . $description;
|
2004-02-02 23:34:39 +00:00
|
|
|
return $summary;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Displays a user's profile (if they have one);
|
|
|
|
|
2005-01-24 13:17:49 +00:00
|
|
|
function show_profile($userid, $verify_mode = FALSE) {
|
2004-02-02 23:34:39 +00:00
|
|
|
$user = get_user_from_id($userid);
|
|
|
|
|
|
|
|
if (!$user) {
|
|
|
|
profile_error_page("No user exists for that ID, or there was a database error.<p>");
|
|
|
|
}
|
2004-05-30 21:47:11 +00:00
|
|
|
$profile = get_profile($userid);
|
|
|
|
if (!$profile) {
|
2005-08-30 09:41:47 +00:00
|
|
|
profile_error_page("No user profile exists for that user ID.");
|
2004-02-02 23:34:39 +00:00
|
|
|
}
|
2005-01-24 13:17:49 +00:00
|
|
|
if (!$verify_mode) {
|
|
|
|
$logged_in_user = get_logged_in_user(false);
|
|
|
|
if (!$logged_in_user || ($user->id != $logged_in_user->id)) {
|
|
|
|
$caching = true;
|
|
|
|
$cache_args = "userid=$userid";
|
|
|
|
start_cache(USER_PROFILE_TTL,$cache_args);
|
|
|
|
}
|
2004-02-02 23:34:39 +00:00
|
|
|
}
|
|
|
|
|
2005-10-01 18:40:39 +00:00
|
|
|
$can_edit = isset($logged_in_user) && $logged_in_user && $user->id == $logged_in_user->id;
|
2005-01-24 13:17:49 +00:00
|
|
|
if (!$verify_mode) {
|
|
|
|
page_head("Profile: ".$user->name);
|
|
|
|
}
|
2005-01-18 19:56:18 +00:00
|
|
|
|
|
|
|
start_table();
|
2004-02-02 23:34:39 +00:00
|
|
|
|
2005-01-18 19:56:18 +00:00
|
|
|
if ($can_edit) {
|
|
|
|
row1("<a href=create_profile.php>Edit your profile</a>");
|
2004-02-02 23:34:39 +00:00
|
|
|
}
|
2005-01-18 19:56:18 +00:00
|
|
|
|
2004-02-02 23:34:39 +00:00
|
|
|
|
2005-09-26 20:01:01 +00:00
|
|
|
// If doing screening, only show picture in certain situations
|
2005-09-11 07:31:42 +00:00
|
|
|
//
|
2005-09-26 20:01:01 +00:00
|
|
|
$show_picture = $profile->has_picture;
|
|
|
|
if (profile_screening()) {
|
|
|
|
if (!$verify_mode && !$can_edit && $profile->verification!=1) {
|
|
|
|
$show_picture = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($show_picture) {
|
2005-01-18 19:56:18 +00:00
|
|
|
echo "
|
|
|
|
<tr><td colspan=2 align=center>
|
|
|
|
<img vspace=6 hspace=9 src=\"" , URL_BASE, IMAGE_URL , $user->id , '.jpg' . "\">
|
|
|
|
</td></tr>
|
|
|
|
";
|
2004-02-02 23:34:39 +00:00
|
|
|
}
|
|
|
|
|
2005-09-26 20:01:01 +00:00
|
|
|
// If the user is viewing their own picture, display its status if it's not
|
2005-09-11 07:31:42 +00:00
|
|
|
// yet verified. This will tell them if other users can't view it yet, or
|
|
|
|
// if there is a problem with it and they need to replace it.
|
|
|
|
//
|
2005-10-01 16:00:31 +00:00
|
|
|
if (profile_screening() && $profile->has_picture && $can_edit && $profile->verification!=1) {
|
2005-09-26 20:01:01 +00:00
|
|
|
row1(offensive_profile_warning($profile->verification));
|
|
|
|
}
|
2005-09-11 07:31:42 +00:00
|
|
|
|
2005-04-08 00:06:52 +00:00
|
|
|
show_user_summary_public($user);
|
2004-02-02 23:34:39 +00:00
|
|
|
|
2005-08-30 09:41:47 +00:00
|
|
|
//Setup text output options based on logged in user forum settings
|
2006-08-14 22:11:53 +00:00
|
|
|
if (!verify_mode) {
|
|
|
|
$logged_in_user = get_logged_in_user(false);
|
|
|
|
$logged_in_user = getForumPreferences($logged_in_user);
|
|
|
|
$options = get_transform_settings_from_user($logged_in_user);
|
|
|
|
}
|
|
|
|
|
2005-01-18 19:56:18 +00:00
|
|
|
row1(show_profile_heading1());
|
2005-08-30 09:41:47 +00:00
|
|
|
row1(output_transform($profile->response1,$options), 2, "foobar");
|
2005-01-18 19:56:18 +00:00
|
|
|
row1(show_profile_heading2());
|
2005-08-30 09:41:47 +00:00
|
|
|
row1(output_transform($profile->response2,$options), 2, "foobar");
|
|
|
|
|
2005-01-24 13:17:49 +00:00
|
|
|
if (!$can_edit and !$verify_mode) {
|
2005-01-18 19:56:18 +00:00
|
|
|
row1("Your feedback on this profile");
|
|
|
|
row2(
|
|
|
|
"Recommend this profile for User of the Day:",
|
|
|
|
"I <a href=profile_rate.php?userid=$userid&vote=recommend>like</a> this profile"
|
|
|
|
);
|
|
|
|
row2(
|
|
|
|
"Alert administrators to an offensive profile:",
|
|
|
|
"I <a href=profile_rate.php?userid=$userid&vote=reject>don't like</a> this profile"
|
|
|
|
);
|
2004-02-02 23:34:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
end_table();
|
2005-01-24 13:17:49 +00:00
|
|
|
if (!$verify_mode) {
|
|
|
|
page_tail();
|
|
|
|
} else {
|
|
|
|
echo "<hr>";
|
|
|
|
}
|
2005-10-01 18:30:15 +00:00
|
|
|
if (isset($caching) && $caching) end_cache(USER_PROFILE_TTL,$cache_args);
|
2004-02-02 23:34:39 +00:00
|
|
|
}
|
|
|
|
?>
|