Fixing a small css issue in the user class.
[elgg.git] / units / friends / friends_actions.php
blob484ad6ff3b669e911051551ffab01cd244400228
1 <?php
2 global $USER, $CFG;
4 // Actions to perform on the friends screen
6 $action = optional_param('action');
7 $friend_id = optional_param('friend_id',0,PARAM_INT);
8 $friend = get_record('users','ident',$friend_id);
10 switch ($action) {
12 // Friend someone
13 case "friend":
14 if (!empty($friend) && logged_on) {
15 $friendalready = record_exists('friends','owner',$USER->ident,'friend',$friend_id);
16 $requestedalready = record_exists('friends','owner',$USER->ident,'friend',$friend_id);
17 if (empty($friendalready) && empty($requestedalready)) {
18 $f = new StdClass;
19 $f->owner = $USER->ident;
20 $f->friend = $friend_id;
21 if ($friend->moderation == 'no') {
22 if (insert_record('friends',$f)) {
23 if (user_info("user_type",$friend_id) == "person") {
24 $messages[] = sprintf(__gettext("%s was added to your friends list."),$friend->name);
25 $u = get_record('users','ident',$friend_id);
26 $message_body = sprintf(__gettext("%s has added you as a friend!\n\nTo visit this user's profile, click on the following link:\n\n\t%s\n\nTo view all your friends, click here:\n\n\t%s\n\nRegards,\n\nThe %s team."),$_SESSION['name'], $CFG->wwwroot . user_info("username",$USER->ident) . "/", $CFG->wwwroot . user_info("username",$friend_id) . "/friends/",$CFG->sitename);
27 $title = sprintf(__gettext("New %s friend"), $CFG->sitename);
28 notify_user($u,$title,$message_body);
30 } else {
31 if (user_info("user_type",$friend_id) == "person") {
32 $messages[] = sprintf(__gettext("%s couldn't be added to your friends list."),$friend->name);
35 } else if ($friend->moderation == 'yes') {
36 if (insert_record('friends_requests',$f)) {
37 if (user_info("user_type",$friend_id) == "person") {
38 $messages[] = sprintf(__gettext("%s has elected to moderate friendship requests. Your request has been added to their moderation queue."),$friend->name);
39 $u = get_record('users','ident',$friend_id);
40 $message_body = sprintf(__gettext("%s has requested to add you as a friend!\n\nTo visit this user's profile, click on the following link:\n\n\t%s\n\nTo view all your friends requests and approve or deny this user, click here:\n\n\t%s\n\nRegards,\n\nThe %s team."),$_SESSION['name'], $CFG->wwwroot . user_info("username",$USER->ident) . "/", $CFG->wwwroot . "_friends/requests.php?owner=" . $friend_id,$CFG->sitename);
41 $title = sprintf(__gettext("New %s friend request"), $CFG->sitename);
42 notify_user($u,$title,$message_body);
44 } else {
45 if (user_info("user_type",$friend_id) == "person") {
46 $messages[] = sprintf(__gettext("%s has elected to moderate friendship requests, but your friend request couldn't be added to their moderation queue."),$friend->name);
49 } else if ($friend->moderation == 'priv' && user_info("user_type",$friend_id) == "person") {
50 $messages[] = sprintf(__gettext("%s has decided not to allow any new friendship requests at this time. Your friendship request has been declined."),$friend->name);
54 break;
55 // Unfriend someone
56 case "unfriend":
57 if (!empty($friend) && logged_on) {
58 if (delete_records('friends','owner',$USER->ident,'friend',$friend_id)) {
59 if (user_info("user_type",$friend_id) == "person") {
60 $messages[] = $friend->name . __gettext(" was removed from your friends.");
62 } else {
63 if (user_info("user_type",$friend_id) == "person") {
64 $messages[] = $friend->name . __gettext(" couldn't be removed from your friends.");
68 break;
69 // Approve a friendship request
70 case "friends:approve:request":
71 $request_id = optional_param('request_id',0,PARAM_INT);
72 if (!empty($request_id) && logged_on && user_type($page_owner) == "person") {
73 if ($request = get_record_sql('SELECT u.name, fr.owner, fr.friend FROM '.$CFG->prefix.'friends_requests fr
74 LEFT JOIN '.$CFG->prefix.'users u ON u.ident = fr.owner
75 WHERE fr.ident = ?',array($request_id))) {
76 if (run("permissions:check",array("userdetails:change", $page_owner))) {
77 $f = new StdClass;
78 $f->owner = $request->owner;
79 $f->friend = $request->friend;
80 if (insert_record('friends',$f)) {
81 delete_records('friends_requests','ident',$request_id);
82 $messages[] = sprintf(__gettext("You approved the friendship request. %s now lists you as a friend."),stripslashes($request->name));
83 $message_body = sprintf(__gettext("%s has approved your friendship request!\n\nTo visit this user's profile, click on the following link:\n\n\t%s\n\nTo view all your friends, click here:\n\n\t%s\n\nRegards,\n\nThe %s team."),user_info("name",$request->friend), $CFG->wwwroot . user_info("username",$request->friend) . "/", $CFG->wwwroot . user_info("username",$request->owner) . "/friends/",$CFG->sitename);
84 $title = sprintf(__gettext("%s friend request approved!"), $CFG->sitename);
85 notify_user($request->owner,$title,$message_body);
86 } else {
87 $messages[] = __gettext("An error occurred: couldn't add you as a friend");
89 } else {
90 $messages[] = __gettext("Error: you do not have authority to modify this friendship request.");
92 } else {
93 $messages[] = __gettext("An error occurred: the friendship request could not be found.");
97 break;
98 // Reject a friendship request
99 case "friends:decline:request":
100 $request_id = optional_param('request_id',0,PARAM_INT);
101 if (!empty($request_id) && logged_on && user_type($page_owner) == "person") {
102 if ($request = get_record_sql('SELECT u.name, fr.owner, fr.friend FROM '.$CFG->prefix.'friends_requests fr
103 LEFT JOIN '.$CFG->prefix.'users u ON u.ident = fr.owner
104 WHERE fr.ident = ?',array($request_id))) {
105 if (run("permissions:check",array("userdetails:change", $page_owner))) {
106 delete_records('friends_requests','ident',$request_id);
107 $messages[] = sprintf(__gettext("You declined the friendship request. %s does not list you as a friend."),stripslashes($request->name));
108 $message_body = sprintf(__gettext("%s has denied your friendship request.\n\nTo visit this user's profile, click on the following link:\n\n\t%s\n\nTo view all your existing friends, click here:\n\n\t%s\n\nRegards,\n\nThe %s team."),user_info("name",$request->friend), $CFG->wwwroot . user_info("username",$request->friend) . "/", $CFG->wwwroot . user_info("username",$request->owner) . "/friends/",$CFG->sitename);
109 $title = sprintf(__gettext("%s friend request denied"), $CFG->sitename);
110 notify_user($request->owner,$title,$message_body);
111 } else {
112 $messages[] = __gettext("Error: you do not have authority to modify this friendship request.");
114 } else {
115 $messages[] = __gettext("An error occurred: the friendship request could not be found.");
119 break;