~ubuntu-branches/ubuntu/lucid/boinc/lucid

« back to all changes in this revision

Viewing changes to html/user/create_profile.php

  • Committer: Bazaar Package Importer
  • Author(s): Frank S. Thomas, Frank S. Thomas
  • Date: 2008-05-31 08:02:47 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20080531080247-4ce890lp2rc768cr
Tags: 6.2.7-1
[ Frank S. Thomas ]
* New upstream release.
  - BOINC Manager: Redraw disk usage charts immediately after connecting to
    a (different) client. (closes: 463823)
* debian/copyright:
  - Added the instructions from debian/README.Debian-source about how
    repackaged BOINC tarballs can be reproduced because DevRef now
    recommends to put this here instead of in the afore-mentioned file.
  - Updated for the new release.
* Removed the obsolete debian/README.Debian-source.
* For consistency upstream renamed the core client and the command tool
  ("boinc_client" to "boinc" and "boinc_cmd" to "boinccmd"). Done the same
  in all packages and created symlinks with the old names for the binaries
  and man pages. Also added an entry in debian/boinc-client.NEWS explaining
  this change.
* debian/rules: Do not list Makefile.ins in the clean target individually,
  just remove all that can be found.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
<?php
2
2
 
 
3
// TODO: the following is organized in a funky way.  Clean it up
 
4
 
3
5
require_once("../inc/profile.inc");
4
6
 
5
 
db_init();
 
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.
 
11
//
 
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>";
 
15
        exit();
 
16
    }
 
17
    echo "<select name=\"$name\">\n";
 
18
 
 
19
    $file = fopen($filename, "r");
 
20
 
 
21
    while ($line = trim(fgets($file, 1024))) {
 
22
        if ($line == $selection) {
 
23
            echo "<option SELECTED value=\"$line\">$line\n";
 
24
        } else {
 
25
            echo "<option value=\"$line\">$line\n";
 
26
        }
 
27
    }
 
28
 
 
29
    echo "</select>\n";
 
30
    fclose($file);
 
31
}
 
32
 
 
33
 
 
34
function show_picture_option($profile) {
 
35
    row1("Picture");
 
36
 
 
37
    $warning = "";
 
38
    if (profile_screening() && $profile->has_picture) {
 
39
        $warning = offensive_profile_warning($profile->verification);
 
40
    }
 
41
 
 
42
    if (($profile) && ($profile->has_picture)) {
 
43
        echo "
 
44
<tr><td colspan=2>
 
45
<table border=0 cellpadding=5
 
46
<tr>
 
47
<td valign=top><a href=\"" . IMAGE_URL . $profile->userid . '.jpg' . "\"><img src=\"" . IMAGE_URL . $profile->userid . '_sm.jpg' . "\"></a>
 
48
</td>
 
49
<td valign=top> $warning Your profile picture is shown at left.
 
50
<p>
 
51
To replace it,
 
52
click the \"Browse\" button and select a JPEG or PNG file (50KB or less).
 
53
<input name=picture type=file><br>
 
54
<p>
 
55
To remove it from your profile, check this box:
 
56
<input type=checkbox name=delete_pic>
 
57
<p>
 
58
</td></tr>";
 
59
        rowify("<br>");
 
60
        end_table();
 
61
        echo "</td></tr>";
 
62
    } else {
 
63
        rowify("
 
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.
 
67
<p>
 
68
<input name=picture type=file>
 
69
        ");
 
70
        rowify("<br>");
 
71
    }
 
72
}
 
73
 
 
74
function show_language_selection($profile) {
 
75
    row1("Language");
 
76
    echo "<tr><td>
 
77
        <p>
 
78
        Select the language in which your profile is written:
 
79
        <p>
 
80
    ";
 
81
    if (isset($profile->language)) {
 
82
        show_combo_box("language", LANGUAGE_FILE, $profile->language);
 
83
    } else {
 
84
        show_combo_box("language", LANGUAGE_FILE, "English");
 
85
    }
 
86
    echo "</td></tr>\n";
 
87
}
 
88
 
 
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>");
 
94
    if ($publickey) {
 
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));
 
97
    }
 
98
    table_row("<p><input type=\"submit\" value=\"Create/edit profile\" name=\"submit\">");
 
99
}
 
100
 
 
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.
 
106
 
 
107
function getImages($fileName) {
 
108
    $size = getImageSize($fileName);
 
109
 
 
110
    // Determine if the filetype uploaded is supported.
 
111
    // TODO: Change these to constants.
 
112
    switch($size[2]) {
 
113
    case '2':    // JPEG
 
114
        $image = imageCreateFromJPEG($fileName);
 
115
        break;
 
116
    case '3':    // PNG
 
117
        $image = imageCreateFromPNG($fileName);
 
118
        break;
 
119
    default:
 
120
        error_page("The format of your uploaded image is not supported.");
 
121
    }
 
122
 
 
123
    $width = $size[0];
 
124
    $height = $size[1];
 
125
 
 
126
    $smallImage = scale_image($image, $width, $height, SMALL_IMG_WIDTH, SMALL_IMG_HEIGHT);
 
127
 
 
128
    if ($width > MAX_IMG_WIDTH || $height > MAX_IMG_HEIGHT) {
 
129
        $image = scale_image($image, $width, $height, MAX_IMG_WIDTH, MAX_IMG_HEIGHT);
 
130
    }
 
131
 
 
132
    /*
 
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>";
 
142
    */
 
143
 
 
144
    return array($image, $smallImage);
 
145
}
 
146
 
 
147
function show_description() {
 
148
    echo "
 
149
        <p>
 
150
        Your <b>profile</b> lets you share your opinions and background
 
151
        with the ".PROJECT." community.
 
152
        <p>
 
153
    ";
 
154
}
 
155
 
 
156
function show_questions($profile) {
 
157
    $response1 = "";
 
158
    $response2 = "";
 
159
    if (isset($profile->response1)) {
 
160
        $response1 = stripslashes($profile->response1);
 
161
    }
 
162
    if (isset($profile->response2)) {
 
163
        $response2 = stripslashes($profile->response2);
 
164
    }
 
165
 
 
166
    row1(show_profile_heading1());
 
167
    rowify(show_profile_question1().html_info());
 
168
    rowify("<br>");
 
169
    show_textarea("response1", $response1);
 
170
    rowify("<br>");
 
171
    row1( show_profile_heading2());
 
172
    rowify( show_profile_question2().html_info());
 
173
    rowify("<br>");
 
174
    show_textarea("response2", $response2);
 
175
    rowify("<br>");
 
176
    show_language_selection($profile);
 
177
    rowify("<br>");
 
178
}
 
179
 
 
180
function show_textarea($name, $text) {
 
181
    rowify("<textarea name=\"$name\" cols=80 rows=20>" . $text . "</textarea>");
 
182
}
 
183
 
 
184
// $profile is null if user doesn't already have a profile.
 
185
// Don't assign to $profile->x if this is the case.
 
186
//
 
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'];
 
193
    } else {
 
194
        $delete_pic = "off";
 
195
    }
 
196
 
 
197
    if (strlen($response1)==0 &&
 
198
        strlen($response2)==0 &&
 
199
        $delete_pic != "on" &&
 
200
        !is_uploaded_file($_FILES['picture']['tmp_name'])
 
201
    ) {
 
202
        error_page("Your profile submission was empty.");
 
203
        exit();
 
204
    }
 
205
 
 
206
    if ($delete_pic == "on") {
 
207
        delete_user_pictures($profile->userid);
 
208
        $profile->has_picture = false;
 
209
        $profile->verification = 0;
 
210
    }
 
211
 
 
212
    $profile ? $hasPicture = $profile->has_picture: $hasPicture = false;
 
213
 
 
214
    if (is_uploaded_file($_FILES['picture']['tmp_name'])) {
 
215
        $hasPicture = true;
 
216
        if ($profile) $profile->verification = 0;
 
217
 
 
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'];
 
222
 
 
223
        $images = getImages($_FILES['picture']['tmp_name']);
 
224
 
 
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');
 
229
    }
 
230
    $response1 = sanitize_html($response1);
 
231
    $response2 = sanitize_html($response2);
 
232
    if ($profile) {
 
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);
 
240
        if (!$result) {
 
241
            error_page("Couldn't update profile: database error");
 
242
        }
 
243
    } else {
 
244
        $query = 'SET '
 
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',"
 
250
            ." verification=0";
 
251
        $result = BoincProfile::insert($query);
 
252
        if (!$result) {
 
253
            error_page("Couldn't create profile: database error");
 
254
        }
 
255
        $user->update("has_profile=1");
 
256
    }
 
257
 
 
258
    page_head("Profile saved");
 
259
 
 
260
    echo "
 
261
        Congratulations!
 
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>
 
264
    ";
 
265
 
 
266
    page_tail();
 
267
}
 
268
 
 
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) {
 
273
        error_page(
 
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."
 
275
        );
 
276
    }
 
277
 
 
278
    // If the user already has a profile,
 
279
    // fill in the fields with their current values.
 
280
    //
 
281
    $profile = get_profile($user->id);
 
282
    if (post_str("submit", true)) {
 
283
        $privatekey = parse_config($config, "<recaptcha_private_key>");
 
284
        if ($privatekey) {
 
285
            $resp = recaptcha_check_answer($privatekey, $_SERVER["REMOTE_ADDR"],
 
286
                $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]
 
287
            );
 
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 . ")"
 
291
                );
 
292
            }
 
293
        }
 
294
 
 
295
        process_create_profile($user, $profile);
 
296
        exit();
 
297
    }
 
298
 
 
299
    if ($profile) {
 
300
        page_head("Edit your profile");
 
301
    } else {
 
302
        page_head("Create a profile");
 
303
    }
 
304
 
 
305
    echo "
 
306
        <form action=", $_SERVER['PHP_SELF'], " method=\"POST\", ENCTYPE=\"multipart/form-data\">
 
307
    ";
 
308
    start_table_noborder();
 
309
    show_description();
 
310
    show_questions($profile);
 
311
    show_picture_option($profile);
 
312
    show_submit();
 
313
    end_table();
 
314
    echo "</form>";
 
315
    page_tail();
 
316
}
6
317
 
7
318
$user = get_logged_in_user(true);
8
319
show_profile_creation_page($user);