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 AND `contact`.`network` != 'dfrn' ",
138 function group_side($every="contacts",$each="group",$edit = false) {
145 $createtext = t('Create a new group');
146 $linktext= t('Everybody');
150 <div id="group-sidebar">
153 <div id="sidebar-new-group">
154 <a href="group/new">$createtext</a>
157 <div id="sidebar-group-list">
158 <ul id="sidebar-group-ul">
159 <li class="sidebar-group-li" ><a href="$every" >$linktext</a></li>
163 $r = q("SELECT * FROM `group` WHERE `deleted` = 0 AND `uid` = %d",
164 intval($_SESSION['uid'])
168 $o .= ' <li class="sidebar-group-li">' . (($edit) ? "<a href=\"group/{$rr['id']}\" title=\"" . t('Edit') . "\" ><img src=\"images/spencil.gif\" alt=\"" . t('Edit') . "\"></a> " : "") . "<a href=\"$each/{$rr['id']}\">{$rr['name']}</a></li>\r\n";
170 $o .= " </ul>\r\n </div>\r\n</div>";
175 function expand_groups($a) {
176 if(! (is_array($a) && count($a)))
178 $groups = implode(',', $a);
179 $groups = dbesc($groups);
180 $r = q("SELECT `contact-id` FROM `group_member` WHERE `gid` IN ( $groups )");
184 $ret[] = $rr['contact-id'];