3
// stuff related to "buddy lists"
5
require_once("../inc/forum_db.inc");
6
require_once("../inc/profile.inc");
8
// see if there's already a request,
9
// and whether the notification record is there
11
function check_pending($user, $destuser) {
12
$friend = BoincFriend::lookup($user->id, $destuser->id);
14
if ($friend->reciprocated) {
15
error_page("Already friends");
17
$notify = BoincNotify::lookup($destuser->id, NOTIFY_FRIEND_REQ, $user->id);
19
page_head("Request pending");
20
$t = date_str($friend->create_time);
21
echo "You requested friendship with $destuser->name on $t.
23
This request is still pending confirmation.
28
BoincFriend::delete($user->id, $destuser->id);
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");
39
// user has clicked "add to friends". Ask them if they really mean it.
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");
46
$destuser = BoincUser::lookup_id($destid);
47
if (!$destuser) error_page("No such user");
49
check_pending($user, $destuser);
50
check_ignoring($user, $destuser);
52
page_head("Add friend");
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.
61
Add an optional message here:
63
<textarea name=message cols=64 rows=4></textarea>
65
<input type=submit value=OK>
71
// User really means it. Make DB entry and send notification
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");
78
check_pending($user, $destuser);
79
check_ignoring($user, $destuser);
81
$msg = post_str('message', true);
82
if ($msg) $msg = strip_tags(process_user_text($msg));
85
$ret = BoincFriend::replace("user_src=$user->id, user_dest=$destid, message='$msg', create_time=$now, reciprocated=0");
87
error_page("database error");
90
$type = NOTIFY_FRIEND_REQ;
91
BoincNotify::replace("userid=$destid, create_time=$now, type=$type, opaque=$user->id");
93
BoincForumPrefs::lookup($destuser);
94
if ($destuser->prefs->pm_notification == 1) {
95
send_friend_request_email($user, $destuser, $msg);
97
page_head("Friend request sent");
99
We have notified <b>$destuser->name</b> of your request.
104
// Show destination user the details of request, ask if they accept
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);
115
$x has added you as a friend.
117
if (strlen($friend->message)) {
118
echo "<p>$srcuser->name says: $friend->message<p>";
122
<a href=friend.php?action=accept&userid=$srcid>Accept</a>
123
(click if $srcuser->name is in fact a friend)
125
<a href=friend.php?action=ignore&userid=$srcid>Decline</a>
126
(click if $srcuser->name is not a friend)
132
// Here if they accepted
134
function handle_accept($user) {
135
$srcid = get_int('userid');
136
$srcuser = BoincUser::lookup_id($srcid);
137
if (!$srcuser) error_page("No such user");
139
$friend = BoincFriend::lookup($srcid, $user->id);
141
error_page("No request");
143
$friend->update("reciprocated=1");
145
// "accept message" not implemented in interface yet
146
$msg = post_str('message', true);
147
if ($msg) $msg = strip_tags(process_user_text($msg));
149
$ret = BoincFriend::replace("user_src=$user->id, user_dest=$srcid, message='$msg', create_time=$now, reciprocated=1");
151
error_page("database error");
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);
160
$notify = BoincNotify::lookup($user->id, NOTIFY_FRIEND_REQ, $srcid);
165
page_head("Friendship confirmed");
167
Your friendship with <b>$srcuser->name</b> has been confirmed.
172
// Here if they declined
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);
180
error_page("No request");
182
$notify = BoincNotify::lookup($user->id, NOTIFY_FRIEND_REQ, $srcid);
186
page_head("Friendship declined");
188
You have declined friendship with <b>$srcuser->name</b>
193
// Here if initiator clicked on "confirmed" notification.
194
// Delete notification
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);
204
echo "?? notification not found";
206
page_head("Friend confirmed");
208
You are now friends with $destuser->name.
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?");
219
Are you sure you want to cancel your friendship with $destuser->name?
222
show_button("friend.php?action=cancel&userid=$destid", "Yes", "Cancel friendship");
224
show_button("home.php", "No", "Don't cancel friendship");
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");
235
Your friendship with $destuser->name has been cancelled.
240
// "home page" has Requests area
241
// (icon) N friend request(s)
243
$user = get_logged_in_user();
245
$action = get_str('action', true);
246
if (!$action) $action = post_str('action');
253
handle_add_confirm($user);
259
handle_accept($user);
262
handle_accepted($user);
265
handle_ignore($user);
267
case 'cancel_confirm':
268
handle_cancel_confirm($user);
271
handle_cancel($user);
274
error_page("unknown action");