4 function group_add($uid,$name) {
7 if(x($uid) && x($name)) {
8 $r = group_byname($uid,$name); // check for dups
11 $r = q("INSERT INTO `group` ( `uid`, `name` )
22 function group_rmv($uid,$name) {
24 if(x($uid) && x($name)) {
25 $r = q("SELECT * FROM `group` WHERE `uid` = %d AND `name` = '%s' LIMIT 1",
30 $group_id = $r[0]['id'];
35 $r = q("DELETE FROM `group_member` WHERE `uid` = %d AND `gid` = %d ",
41 $r = q("UPDATE `group` SET `deleted` = 1 WHERE `uid` = %d AND `name` = '%s' LIMIT 1",
53 function group_byname($uid,$name) {
54 if((! $uid) || (! strlen($name)))
56 $r = q("SELECT * FROM `group` WHERE `uid` = %d AND `name` = '%s' LIMIT 1",
65 function group_rmv_member($uid,$name,$member) {
66 $gid = group_byname($uid,$name);
69 if(! ( $uid && $gid && $member))
71 $r = q("DELETE FROM `group_member` WHERE `uid` = %d AND `gid` = %d AND `contact-id` = %d LIMIT 1 ",
82 function group_add_member($uid,$name,$member) {
83 $gid = group_byname($uid,$name);
84 if((! $gid) || (! $uid) || (! $member))
87 $r = q("SELECT * FROM `group_member` WHERE `uid` = %d AND `id` = %d AND `contact-id` = %d LIMIT 1",
93 return true; // You might question this, but
94 // we indicate success because the group was in fact created
95 // -- It was just created at another time
97 $r = q("INSERT INTO `group_member` (`uid`, `gid`, `contact-id`)
98 VALUES( %d, %d, %d ) ",
106 function group_get_members($gid) {
109 $r = q("SELECT `group_member`.`contact-id`, `contact`.* FROM `group_member`
110 LEFT JOIN `contact` ON `contact`.`id` = `group_member`.`contact-id`
111 WHERE `gid` = %d AND `group_member`.`uid` = %d ORDER BY `contact`.`name` ASC ",
121 function group_public_members($gid) {
124 $r = q("SELECT `contact`.`id` AS `contact-id` FROM `group_member`
125 LEFT JOIN `contact` ON `contact`.`id` = `group_member`.`contact-id`
126 WHERE `gid` = %d AND `group_member`.`uid` = %d
127 AND `contact`.`network` != 'dfrn' AND `contact`.`network` != 'mail' AND `contact`.`network` != 'face' ",
139 function group_side($every="contacts",$each="group",$edit = false, $group_id = 0, $cid = 0) {
146 $createtext = t('Create a new group');
147 $linktext= t('Everybody');
148 $selected = (($group_id == 0) ? ' class="group-selected" ' : '');
151 <div id="group-sidebar">
154 <div id="sidebar-group-list">
155 <ul id="sidebar-group-ul">
156 <li class="sidebar-group-li" ><a href="$every" $selected >$linktext</a></li>
160 $r = q("SELECT * FROM `group` WHERE `deleted` = 0 AND `uid` = %d ORDER BY `name` ASC",
161 intval($_SESSION['uid'])
164 $member_of = groups_containing(local_user(),$cid);
169 $selected = (($group_id == $rr['id']) ? ' class="group-selected" ' : '');
170 $o .= ' <li class="sidebar-group-li">'
171 . (($edit) ? "<a href=\"group/{$rr['id']}\" title=\"" . t('Edit')
172 . "\" ><img src=\"images/spencil.gif\" alt=\"" . t('Edit') . "\"></a> " : "")
173 . (($cid) ? '<input type="checkbox" onclick="contactgroupChangeMember(' . $rr['id'] . ',' . $cid . ');return true;" '
174 . ((in_array($rr['id'],$member_of)) ? ' checked="checked" ' : '') . '/>' : '')
175 . "<a href=\"$each/{$rr['id']}\" $selected >{$rr['name']}</a></li>\r\n";
178 $o .= " </ul>\r\n </div>";
182 <div id="sidebar-new-group">
183 <a href="group/new">$createtext</a>
192 function expand_groups($a) {
193 if(! (is_array($a) && count($a)))
195 $groups = implode(',', $a);
196 $groups = dbesc($groups);
197 $r = q("SELECT `contact-id` FROM `group_member` WHERE `gid` IN ( $groups )");
201 $ret[] = $rr['contact-id'];
206 function member_of($c) {
208 $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 ",
216 function groups_containing($uid,$c) {
218 $r = q("SELECT `gid` FROM `group_member` WHERE `uid` = %d AND `group_member`.`contact-id` = %d ",