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) {
146 $createtext = t('Create a new group');
147 $linktext= t('Everybody');
151 <div id="group-sidebar">
154 <div id="sidebar-new-group">
155 <a href="group/new">$createtext</a>
158 <div id="sidebar-group-list">
159 <ul id="sidebar-group-ul">
160 <li class="sidebar-group-li" ><a href="$every" >$linktext</a></li>
164 $r = q("SELECT * FROM `group` WHERE `deleted` = 0 AND `uid` = %d",
165 intval($_SESSION['uid'])
169 $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";
171 $o .= " </ul>\r\n </div>\r\n</div>";
176 function expand_groups($a) {
177 if(! (is_array($a) && count($a)))
179 $groups = implode(',', $a);
180 $groups = dbesc($groups);
181 $r = q("SELECT `contact-id` FROM `group_member` WHERE `gid` IN ( $groups )");
185 $ret[] = $rr['contact-id'];