3
// TODO: the following is organized in a funky way. Clean it up
3
5
require_once("../inc/profile.inc");
7
// output a select form item with the given name,
8
// from a list of newline-delineated items from the text file.
9
// If $selection is provided, and if it matches one of the entries in the file,
10
// it will be selected by default.
12
function show_combo_box($name, $filename, $selection=null) {
13
if (!file_exists($filename)) {
14
echo "ERROR: $filename does not exist! Cannot create combo box.<br>";
17
echo "<select name=\"$name\">\n";
19
$file = fopen($filename, "r");
21
while ($line = trim(fgets($file, 1024))) {
22
if ($line == $selection) {
23
echo "<option SELECTED value=\"$line\">$line\n";
25
echo "<option value=\"$line\">$line\n";
34
function show_picture_option($profile) {
38
if (profile_screening() && $profile->has_picture) {
39
$warning = offensive_profile_warning($profile->verification);
42
if (($profile) && ($profile->has_picture)) {
45
<table border=0 cellpadding=5
47
<td valign=top><a href=\"" . IMAGE_URL . $profile->userid . '.jpg' . "\"><img src=\"" . IMAGE_URL . $profile->userid . '_sm.jpg' . "\"></a>
49
<td valign=top> $warning Your profile picture is shown at left.
52
click the \"Browse\" button and select a JPEG or PNG file (50KB or less).
53
<input name=picture type=file><br>
55
To remove it from your profile, check this box:
56
<input type=checkbox name=delete_pic>
64
If you would like include a picture with your profile,
65
click the \"Browse\" button and select a JPEG or PNG file.
66
Please select images of 50KB or less.
68
<input name=picture type=file>
74
function show_language_selection($profile) {
78
Select the language in which your profile is written:
81
if (isset($profile->language)) {
82
show_combo_box("language", LANGUAGE_FILE, $profile->language);
84
show_combo_box("language", LANGUAGE_FILE, "English");
89
function show_submit() {
90
row1("Submit profile");
91
echo "<script>var RecaptchaOptions = { theme : 'white' };</script>";
92
$config = get_config();
93
$publickey = parse_config($config, "<recaptcha_public_key>");
95
table_row("To protect project's webpages from spam, we ask you to type in two words shown in the image:<br>\n".
96
recaptcha_get_html($publickey));
98
table_row("<p><input type=\"submit\" value=\"Create/edit profile\" name=\"submit\">");
101
// Returns an array containing:
102
// [0]: The original image refered to by $fileName if its dimensions are
103
// less than MAX_IMG_WIDTH x MAX_IMG_HEIGHT, or a version scaled to
104
// those dimensions if it was too large.
105
// [1]: A scaled version of the above.
107
function getImages($fileName) {
108
$size = getImageSize($fileName);
110
// Determine if the filetype uploaded is supported.
111
// TODO: Change these to constants.
114
$image = imageCreateFromJPEG($fileName);
117
$image = imageCreateFromPNG($fileName);
120
error_page("The format of your uploaded image is not supported.");
126
$smallImage = scale_image($image, $width, $height, SMALL_IMG_WIDTH, SMALL_IMG_HEIGHT);
128
if ($width > MAX_IMG_WIDTH || $height > MAX_IMG_HEIGHT) {
129
$image = scale_image($image, $width, $height, MAX_IMG_WIDTH, MAX_IMG_HEIGHT);
133
echo "<br><br>Image type: $size[2]";
134
echo "<br>Original width: $width";
135
echo "<br>Original height: $height";
136
echo "<br>Scalar: $scalar";
137
echo "<br>Dest width: " . ($width / $scalar);
138
echo "<br>Dest height: " . ($height / $scalar);
139
echo "<br>Horizontal offset: $horiz_offset";
140
echo "<br>Vertical offset: $vert_offset";
141
echo "<br><br><a href=\"images/user_profile/test.jpg\">View result</a>";
144
return array($image, $smallImage);
147
function show_description() {
150
Your <b>profile</b> lets you share your opinions and background
151
with the ".PROJECT." community.
156
function show_questions($profile) {
159
if (isset($profile->response1)) {
160
$response1 = stripslashes($profile->response1);
162
if (isset($profile->response2)) {
163
$response2 = stripslashes($profile->response2);
166
row1(show_profile_heading1());
167
rowify(show_profile_question1().html_info());
169
show_textarea("response1", $response1);
171
row1( show_profile_heading2());
172
rowify( show_profile_question2().html_info());
174
show_textarea("response2", $response2);
176
show_language_selection($profile);
180
function show_textarea($name, $text) {
181
rowify("<textarea name=\"$name\" cols=80 rows=20>" . $text . "</textarea>");
184
// $profile is null if user doesn't already have a profile.
185
// Don't assign to $profile->x if this is the case.
187
function process_create_profile($user, $profile) {
188
$response1 = $_POST['response1'];
189
$response2 = $_POST['response2'];
190
$language = $_POST['language'];
191
if (isset($_POST['delete_pic'])) {
192
$delete_pic = $_POST['delete_pic'];
197
if (strlen($response1)==0 &&
198
strlen($response2)==0 &&
199
$delete_pic != "on" &&
200
!is_uploaded_file($_FILES['picture']['tmp_name'])
202
error_page("Your profile submission was empty.");
206
if ($delete_pic == "on") {
207
delete_user_pictures($profile->userid);
208
$profile->has_picture = false;
209
$profile->verification = 0;
212
$profile ? $hasPicture = $profile->has_picture: $hasPicture = false;
214
if (is_uploaded_file($_FILES['picture']['tmp_name'])) {
216
if ($profile) $profile->verification = 0;
218
// echo "<br>Name: " . $_FILES['picture']['name'];
219
// echo "<br>Type: " . $_FILES['picture']['type'];
220
// echo "<br>Size: " . $_FILES['picture']['size'];
221
// echo "<br>Temp name: " . $_FILES['picture']['tmp_name'];
223
$images = getImages($_FILES['picture']['tmp_name']);
225
// Write the original image file to disk.
226
// TODO: define a constant for image quality.
227
ImageJPEG($images[0], IMAGE_PATH . $user->id . '.jpg');
228
ImageJPEG($images[1], IMAGE_PATH . $user->id . '_sm.jpg');
230
$response1 = sanitize_html($response1);
231
$response2 = sanitize_html($response2);
233
$query = " response1 = '".boinc_real_escape_string($response1)."',"
234
." response2 = '".boinc_real_escape_string($response2)."',"
235
." language = '".boinc_real_escape_string($language)."',"
236
." has_picture = '$hasPicture',"
237
." verification = '$profile->verification'"
238
." WHERE userid = '$user->id'";
239
$result = BoincProfile::update_aux($query);
241
error_page("Couldn't update profile: database error");
245
." userid = '$user->id',"
246
." language = '".boinc_real_escape_string($language)."',"
247
." response1 = '".boinc_real_escape_string($response1)."',"
248
." response2 = '".boinc_real_escape_string($response2)."',"
249
." has_picture = '$hasPicture',"
251
$result = BoincProfile::insert($query);
253
error_page("Couldn't create profile: database error");
255
$user->update("has_profile=1");
258
page_head("Profile saved");
262
Your profile was successfully entered into our database.<br><br>
263
<a href=view_profile.php?userid=$user->id>View your profile</a><br>
269
function show_profile_creation_page($user) {
270
$config = get_config();
271
$min_credit = parse_config($config, "<profile_min_credit>");
272
if ($min_credit && $user->expavg_credit < $min_credit) {
274
"To prevent spam, an average credit of $min_credit or greater is required to create or edit a profile. We apologize for this inconvenience."
278
// If the user already has a profile,
279
// fill in the fields with their current values.
281
$profile = get_profile($user->id);
282
if (post_str("submit", true)) {
283
$privatekey = parse_config($config, "<recaptcha_private_key>");
285
$resp = recaptcha_check_answer($privatekey, $_SERVER["REMOTE_ADDR"],
286
$_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]
288
if (!$resp->is_valid) {
289
error_page("The reCAPTCHA wasn't entered correctly. Go back and try it again.<br>".
290
"(reCAPTCHA said: " . $resp->error . ")"
295
process_create_profile($user, $profile);
300
page_head("Edit your profile");
302
page_head("Create a profile");
306
<form action=", $_SERVER['PHP_SELF'], " method=\"POST\", ENCTYPE=\"multipart/form-data\">
308
start_table_noborder();
310
show_questions($profile);
311
show_picture_option($profile);
7
318
$user = get_logged_in_user(true);
8
319
show_profile_creation_page($user);