4 function group_add($uid,$name) {
7 if(x($uid) && x($name)) {
8 $r = group_byname($uid,$name); // check for dups
11 // This could be a problem.
12 // Let's assume we've just created a group which we once deleted
13 // all the old members are gone, but the group remains so we don't break any security
14 // access lists. What we're doing here is reviving the dead group, but old content which
15 // was restricted to this group may now be seen by the new group members.
17 $z = q("SELECT * FROM `group` WHERE `id` = %d LIMIT 1",
20 if(count($z) && $z[0]['deleted']) {
21 $r = q("UPDATE `group` SET `deleted` = 0 WHERE `uid` = %d AND `name` = '%s' LIMIT 1",
25 notice( t('A deleted group with this name was revived. Existing item permissions <strong>may</strong> apply to this group and any future members. If this is not what you intended, please create another group with a different name.') . EOL);
29 $r = q("INSERT INTO `group` ( `uid`, `name` )
40 function group_rmv($uid,$name) {
42 if(x($uid) && x($name)) {
43 $r = q("SELECT * FROM `group` WHERE `uid` = %d AND `name` = '%s' LIMIT 1",
48 $group_id = $r[0]['id'];
53 $r = q("DELETE FROM `group_member` WHERE `uid` = %d AND `gid` = %d ",
59 $r = q("UPDATE `group` SET `deleted` = 1 WHERE `uid` = %d AND `name` = '%s' LIMIT 1",
71 function group_byname($uid,$name) {
72 if((! $uid) || (! strlen($name)))
74 $r = q("SELECT * FROM `group` WHERE `uid` = %d AND `name` = '%s' LIMIT 1",
83 function group_rmv_member($uid,$name,$member) {
84 $gid = group_byname($uid,$name);
87 if(! ( $uid && $gid && $member))
89 $r = q("DELETE FROM `group_member` WHERE `uid` = %d AND `gid` = %d AND `contact-id` = %d LIMIT 1 ",
100 function group_add_member($uid,$name,$member) {
101 $gid = group_byname($uid,$name);
102 if((! $gid) || (! $uid) || (! $member))
105 $r = q("SELECT * FROM `group_member` WHERE `uid` = %d AND `id` = %d AND `contact-id` = %d LIMIT 1",
111 return true; // You might question this, but
112 // we indicate success because the group was in fact created
113 // -- It was just created at another time
115 $r = q("INSERT INTO `group_member` (`uid`, `gid`, `contact-id`)
116 VALUES( %d, %d, %d ) ",
124 function group_get_members($gid) {
127 $r = q("SELECT `group_member`.`contact-id`, `contact`.* FROM `group_member`
128 LEFT JOIN `contact` ON `contact`.`id` = `group_member`.`contact-id`
129 WHERE `gid` = %d AND `group_member`.`uid` = %d ORDER BY `contact`.`name` ASC ",
139 function group_public_members($gid) {
142 $r = q("SELECT `contact`.`id` AS `contact-id` FROM `group_member`
143 LEFT JOIN `contact` ON `contact`.`id` = `group_member`.`contact-id`
144 WHERE `gid` = %d AND `group_member`.`uid` = %d
145 AND `contact`.`network` = '%s' AND `contact`.`notify` != '' ",
147 intval(local_user()),
148 dbesc(NETWORK_OSTATUS)
158 function group_side($every="contacts",$each="group",$edit = false, $group_id = 0, $cid = 0) {
165 $createtext = t('Create a new group');
166 $linktext= t('Everybody');
167 $selected = (($group_id == 0) ? ' group-selected' : '');
170 <div id="group-sidebar" class="widget">
173 <div id="sidebar-group-list">
174 <ul id="sidebar-group-ul">
175 <li class="sidebar-group-li" ><a href="$every" class="sidebar-group-element$selected" >$linktext</a></li>
179 $r = q("SELECT * FROM `group` WHERE `deleted` = 0 AND `uid` = %d ORDER BY `name` ASC",
180 intval($_SESSION['uid'])
183 $member_of = groups_containing(local_user(),$cid);
188 $selected = (($group_id == $rr['id']) ? ' group-selected' : '');
189 $o .= ' <li class="sidebar-group-li">'
190 . (($edit) ? "<a href=\"group/{$rr['id']}\" title=\"" . t('Edit')
191 . "\" class=\"groupsideedit\" ><img src=\"images/spencil.gif\" alt=\"" . t('Edit') . "\"></a> " : "")
192 . (($cid) ? '<input type="checkbox" class="' . (($selected) ? 'ticked' : 'unticked') . '" onclick="contactgroupChangeMember(' . $rr['id'] . ',' . $cid . ');return true;" '
193 . ((in_array($rr['id'],$member_of)) ? ' checked="checked" ' : '') . '/>' : '')
194 . "<a href=\"$each/{$rr['id']}\" class=\"sidebar-group-element" . $selected ."\" >{$rr['name']}</a></li>\r\n";
197 $o .= " </ul>\r\n </div>";
201 <div id="sidebar-new-group">
202 <a href="group/new">$createtext</a>
211 function expand_groups($a) {
212 if(! (is_array($a) && count($a)))
214 $groups = implode(',', $a);
215 $groups = dbesc($groups);
216 $r = q("SELECT `contact-id` FROM `group_member` WHERE `gid` IN ( $groups )");
220 $ret[] = $rr['contact-id'];
225 function member_of($c) {
227 $r = q("SELECT `group`.`name`, `group`.`id` FROM `group` LEFT JOIN `group_member` ON `group_member`.`gid` = `group`.`id` WHERE `group_member`.`contact-id` = %d AND `group`.`deleted` = 0 ORDER BY `group`.`name` ASC ",
235 function groups_containing($uid,$c) {
237 $r = q("SELECT `gid` FROM `group_member` WHERE `uid` = %d AND `group_member`.`contact-id` = %d ",