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

« back to all changes in this revision

Viewing changes to html/user/friend.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
<?php
 
2
 
 
3
// stuff related to "buddy lists"
 
4
 
 
5
require_once("../inc/forum_db.inc");
 
6
require_once("../inc/profile.inc");
 
7
 
 
8
// see if there's already a request,
 
9
// and whether the notification record is there
 
10
//
 
11
function check_pending($user, $destuser) {
 
12
    $friend = BoincFriend::lookup($user->id, $destuser->id);
 
13
    if ($friend) {
 
14
        if ($friend->reciprocated) {
 
15
            error_page("Already friends");
 
16
        }
 
17
        $notify = BoincNotify::lookup($destuser->id, NOTIFY_FRIEND_REQ, $user->id);
 
18
        if ($notify) {
 
19
            page_head("Request pending");
 
20
            $t = date_str($friend->create_time);
 
21
            echo "You requested friendship with $destuser->name on $t.
 
22
                <p>
 
23
                This request is still pending confirmation.
 
24
            ";
 
25
            page_tail();
 
26
            exit();
 
27
        }
 
28
        BoincFriend::delete($user->id, $destuser->id);
 
29
    }
 
30
}
 
31
 
 
32
function check_ignoring($srcuser, $destuser) {
 
33
    BoincForumPrefs::lookup($destuser);
 
34
    if (is_ignoring($destuser, $srcuser)) {
 
35
        error_page("$destuser->name is not accepting friendship requests from you");
 
36
    }
 
37
}
 
38
 
 
39
// user has clicked "add to friends".  Ask them if they really mean it.
 
40
//
 
41
function handle_add($user) {
 
42
    $destid = get_int('userid');
 
43
    if ($destid == $user->id) {
 
44
        error_page("You can't be friends with yourself");
 
45
    }
 
46
    $destuser = BoincUser::lookup_id($destid);
 
47
    if (!$destuser) error_page("No such user");
 
48
 
 
49
    check_pending($user, $destuser);
 
50
    check_ignoring($user, $destuser);
 
51
 
 
52
    page_head("Add friend");
 
53
    echo "
 
54
        <form method=post action=friend.php>
 
55
        <input type=hidden name=userid value=$destid>
 
56
        <input type=hidden name=action value=add_confirm>
 
57
        You have asked to add <b>$destuser->name</b> as a friend.
 
58
        We will notify <b>$destuser->name</b> and will ask him/her to
 
59
        confirm that you are friends.
 
60
        <p>
 
61
        Add an optional message here:
 
62
        <br>
 
63
        <textarea name=message cols=64 rows=4></textarea>
 
64
        <p>
 
65
        <input type=submit value=OK>
 
66
        </form>
 
67
    ";
 
68
    page_tail();
 
69
}
 
70
 
 
71
// User really means it.  Make DB entry and send notification
 
72
//
 
73
function handle_add_confirm($user) {
 
74
    $destid = post_int('userid');
 
75
    $destuser = BoincUser::lookup_id($destid);
 
76
    if (!$destuser) error_page("No such user");
 
77
 
 
78
    check_pending($user, $destuser);
 
79
    check_ignoring($user, $destuser);
 
80
 
 
81
    $msg = post_str('message', true);
 
82
    if ($msg) $msg = strip_tags(process_user_text($msg));
 
83
 
 
84
    $now = time();
 
85
    $ret = BoincFriend::replace("user_src=$user->id, user_dest=$destid, message='$msg', create_time=$now, reciprocated=0");
 
86
    if (!$ret) {
 
87
        error_page("database error");
 
88
    }
 
89
    $now = time();
 
90
    $type = NOTIFY_FRIEND_REQ;
 
91
    BoincNotify::replace("userid=$destid, create_time=$now, type=$type, opaque=$user->id");
 
92
 
 
93
    BoincForumPrefs::lookup($destuser);
 
94
    if ($destuser->prefs->pm_notification == 1) {
 
95
        send_friend_request_email($user, $destuser, $msg);
 
96
    }
 
97
    page_head("Friend request sent");
 
98
    echo "
 
99
        We have notified <b>$destuser->name</b> of your request.
 
100
    ";
 
101
    page_tail();
 
102
}
 
103
 
 
104
// Show destination user the details of request, ask if they accept
 
105
//
 
106
function handle_query($user) {
 
107
    $srcid = get_int('userid');
 
108
    $srcuser = BoincUser::lookup_id($srcid);
 
109
    if (!$srcuser) error_page("No such user");
 
110
    $friend = BoincFriend::lookup($srcid, $user->id);
 
111
    if (!$friend) error_page("Request not found");
 
112
    page_head("Friend request");
 
113
    $x = user_links($srcuser, true);
 
114
    echo "
 
115
        $x has added you as a friend.
 
116
    ";
 
117
    if (strlen($friend->message)) {
 
118
        echo "<p>$srcuser->name says: $friend->message<p>";
 
119
    }
 
120
    echo "
 
121
        <p>
 
122
        <a href=friend.php?action=accept&userid=$srcid>Accept</a>
 
123
        (click if $srcuser->name is in fact a friend)
 
124
        <p>
 
125
        <a href=friend.php?action=ignore&userid=$srcid>Decline</a>
 
126
        (click if $srcuser->name is not a friend)
 
127
        <p>
 
128
    ";
 
129
    page_tail();
 
130
}
 
131
 
 
132
// Here if they accepted
 
133
//
 
134
function handle_accept($user) {
 
135
    $srcid = get_int('userid');
 
136
    $srcuser = BoincUser::lookup_id($srcid);
 
137
    if (!$srcuser) error_page("No such user");
 
138
 
 
139
    $friend = BoincFriend::lookup($srcid, $user->id);
 
140
    if (!$friend) {
 
141
        error_page("No request");
 
142
    }
 
143
    $friend->update("reciprocated=1");
 
144
 
 
145
    // "accept message" not implemented in interface yet
 
146
    $msg = post_str('message', true);
 
147
    if ($msg) $msg = strip_tags(process_user_text($msg));
 
148
    $now = time();
 
149
    $ret = BoincFriend::replace("user_src=$user->id, user_dest=$srcid, message='$msg', create_time=$now, reciprocated=1");
 
150
    if (!$ret) {
 
151
        error_page("database error");
 
152
    }
 
153
    $type = NOTIFY_FRIEND_ACCEPT;
 
154
    BoincNotify::replace("userid=$srcid, create_time=$now, type=$type, opaque=$user->id");
 
155
    BoincForumPrefs::lookup($srcuser);
 
156
    if ($srcuser->prefs->pm_notification == 1) {
 
157
        send_friend_accept_email($user, $srcuser, $msg);
 
158
    }
 
159
 
 
160
    $notify = BoincNotify::lookup($user->id, NOTIFY_FRIEND_REQ, $srcid);
 
161
    if ($notify) {
 
162
        $notify->delete();
 
163
    }
 
164
 
 
165
    page_head("Friendship confirmed");
 
166
    echo "
 
167
        Your friendship with <b>$srcuser->name</b> has been confirmed.
 
168
    ";
 
169
    page_tail();
 
170
}
 
171
 
 
172
// Here if they declined
 
173
//
 
174
function handle_ignore($user) {
 
175
    $srcid = get_int('userid');
 
176
    $srcuser = BoincUser::lookup_id($srcid);
 
177
    if (!$srcuser) error_page("No such user");
 
178
    $friend = BoincFriend::lookup($srcid, $user->id);
 
179
    if (!$friend) {
 
180
        error_page("No request");
 
181
    }
 
182
    $notify = BoincNotify::lookup($user->id, NOTIFY_FRIEND_REQ, $srcid);
 
183
    if ($notify) {
 
184
        $notify->delete();
 
185
    }
 
186
    page_head("Friendship declined");
 
187
    echo "
 
188
        You have declined friendship with <b>$srcuser->name</b>
 
189
    ";
 
190
    page_tail();
 
191
}
 
192
 
 
193
// Here if initiator clicked on "confirmed" notification.
 
194
// Delete notification
 
195
//
 
196
function handle_accepted($user) {
 
197
    $destid = get_int('userid');
 
198
    $destuser = BoincUser::lookup_id($destid);
 
199
    if (!$destuser) error_page("No such user");
 
200
    $notify = BoincNotify::lookup($user->id, NOTIFY_FRIEND_ACCEPT, $destid);
 
201
    if ($notify) {
 
202
        $notify->delete();
 
203
    } else {
 
204
        echo "?? notification not found";
 
205
    }
 
206
    page_head("Friend confirmed");
 
207
    echo "
 
208
        You are now friends with $destuser->name.
 
209
    ";
 
210
    page_tail();
 
211
}
 
212
 
 
213
function handle_cancel_confirm($user) {
 
214
    $destid = get_int('userid');
 
215
    $destuser = BoincUser::lookup_id($destid);
 
216
    if (!$destuser) error_page("No such user");
 
217
    page_head("Cancel friendship?");
 
218
    echo "
 
219
        Are you sure you want to cancel your friendship with $destuser->name?
 
220
        <p>
 
221
    ";
 
222
    show_button("friend.php?action=cancel&userid=$destid", "Yes", "Cancel friendship");
 
223
    echo "<p>";
 
224
    show_button("home.php", "No", "Don't cancel friendship");
 
225
    page_tail();
 
226
}
 
227
 
 
228
function handle_cancel($user) {
 
229
    $destid = get_int('userid');
 
230
    $destuser = BoincUser::lookup_id($destid);
 
231
    if (!$destuser) error_page("No such user");
 
232
    BoincFriend::delete($user->id, $destid);
 
233
    page_head("Friendship cancelled");
 
234
    echo "
 
235
        Your friendship with $destuser->name has been cancelled.
 
236
    ";
 
237
    page_tail();
 
238
}
 
239
 
 
240
// "home page" has Requests area
 
241
// (icon) N friend request(s)
 
242
 
 
243
$user = get_logged_in_user();
 
244
 
 
245
$action = get_str('action', true);
 
246
if (!$action) $action = post_str('action');
 
247
 
 
248
switch ($action) {
 
249
case 'add':
 
250
    handle_add($user);
 
251
    break;
 
252
case 'add_confirm':
 
253
    handle_add_confirm($user);
 
254
    break;
 
255
case 'query':
 
256
    handle_query($user);
 
257
    break;
 
258
case 'accept':
 
259
    handle_accept($user);
 
260
    break;
 
261
case 'accepted':
 
262
    handle_accepted($user);
 
263
    break;
 
264
case 'ignore':
 
265
    handle_ignore($user);
 
266
    break;
 
267
case 'cancel_confirm':
 
268
    handle_cancel_confirm($user);
 
269
    break;
 
270
case 'cancel':
 
271
    handle_cancel($user);
 
272
    break;
 
273
default:
 
274
    error_page("unknown action");
 
275
}
 
276
 
 
277
?>