]> git.mxchange.org Git - friendica.git/blob - include/group.php
new todo list
[friendica.git] / include / group.php
1 <?php
2
3
4 function group_add($uid,$name) {
5
6         $ret = false;
7         if(x($uid) && x($name)) {
8                 $r = group_byname($uid,$name); // check for dups
9                 if($r !== false) 
10                         return true;
11                 $r = q("INSERT INTO `group` ( `uid`', `name` )
12                         VALUES( %d, '%s' ) ",
13                         intval($uid),
14                         dbesc($name)
15                 );
16                 $ret = $r;
17         }       
18         return $ret;
19 }
20
21
22 function group_rmv($uid,$name) {
23         $ret = false;
24         if(x($uid) && x($name)) {
25                 $r = q("SELECT * FROM `group` WHERE `uid` = %d AND `name` = '%s' LIMIT 1",
26                         intval($uid),
27                         dbesc($name)
28                 }
29                 if(count($r))
30                         $group_id = $r[0]['id'];
31                 if(! $group_id)
32                         return false;
33
34                 // remove all members
35                 $r = q("DELETE FROM `group_member` WHERE `uid` = %d AND `gid` = %d ",
36                         intval($uid),
37                         intval($group_id)
38                 );
39
40                 // remove group
41                 $r = q("DELETE FROM `group` WHERE `uid` = %d AND `id` = %d LIMIT 1",
42                         intval($uid),
43                         dbesc($name)
44                 );
45
46                 $ret = $r;
47
48         }
49         // TODO!! remove this group from all content ACL's !!
50
51         return $ret;
52 }
53
54 function group_byname($uid,$name) {
55         if((! $uid) || (! strlen($name)))
56                 return false;
57         $r = q("SELECT * FROM `group` WHERE `uid` = %d AND `name` = '%s' LIMIT 1",
58                 intval($uid),
59                 dbesc($name)
60         );
61         if(count($r))
62                 return $r[0]['id'];
63         return false;
64 }
65
66 function group_rmv_member($uid,$name,$member) {
67         $gid = group_byname($uid,$name);
68         if(! $gid)
69                 return false;
70         if(! ( $uid && $gid && $member))
71                 return false;
72         $r = q("DELETE FROM `group_member` WHERE `uid` = %d AND `gid` = %d AND `contact-id` = %d LIMIT 1 ",
73                 intval($uid),
74                 intval($gid),
75                 intval($member)
76         );
77         return $r;
78         
79
80 }
81
82
83 function group_add_member($uid,$name,$member) {
84         $gid = group_byname($uid,$name);
85         if((! $gid) || (! $uid) || (! $member))
86                 return false;
87
88         $r = q("SELECT * FROM `group_member` WHERE `uid` = %d AND `id` = %d AND `contact-id` = %d LIMIT 1",     
89                 intval($uid),
90                 intval($gid),
91                 intval($member)
92         );
93         if(count($r))
94                 return true;    // You might question this, but 
95                                 // we indicate success because the group was in fact created
96                                 // -- It was just created at another time
97         if(! count($r))
98                 $r = q("INSERT INTO `group_member` (`uid`, `gid`, `contact-id`)
99                         VALUES( %d, %d, %d ) ",
100                         intval($uid),
101                         intval($gid),
102                         intval($member)
103         );
104         return $r;
105 }