]> git.mxchange.org Git - friendica.git/blob - mod/contactgroup.php
rev update
[friendica.git] / mod / contactgroup.php
1 <?php
2
3 require_once('include/group.php');
4
5 function contactgroup_content(&$a) {
6
7
8         if(! local_user()) {
9                 killme();
10         }
11
12         if(($a->argc > 2) && intval($a->argv[1]) && intval($a->argv[2])) {
13                 $r = q("SELECT `id` FROM `contact` WHERE `id` = %d AND `uid` = %d and `self` = 0 and `blocked` = 0 AND `pending` = 0 LIMIT 1",
14                         intval($a->argv[2]),
15                         intval(local_user())
16                 );
17                 if(count($r))
18                         $change = intval($a->argv[2]);
19         }
20
21         if(($a->argc > 1) && (intval($a->argv[1]))) {
22
23                 $r = q("SELECT * FROM `group` WHERE `id` = %d AND `uid` = %d AND `deleted` = 0 LIMIT 1",
24                         intval($a->argv[1]),
25                         intval(local_user())
26                 );
27                 if(! count($r)) {
28                         killme();
29                 }
30
31                 $group = $r[0];
32                 $members = group_get_members($group['id']);
33                 $preselected = array();
34                 if(count($members))     {
35                         foreach($members as $member)
36                                 $preselected[] = $member['id'];
37                 }
38
39                 if($change) {
40                         if(in_array($change,$preselected)) {
41                                 group_rmv_member(local_user(),$group['name'],$change);
42                         }
43                         else {
44                                 group_add_member(local_user(),$group['name'],$change);
45                         }
46                 }
47         }
48
49         killme();
50 }