$r = group_byname($uid,$name); // check for dups
if($r !== false)
return true;
- $r = q("INSERT INTO `group` ( `uid`', `name` )
+ $r = q("INSERT INTO `group` ( `uid`, `name` )
VALUES( %d, '%s' ) ",
intval($uid),
dbesc($name)
$r = q("SELECT * FROM `group` WHERE `uid` = %d AND `name` = '%s' LIMIT 1",
intval($uid),
dbesc($name)
- }
+ );
if(count($r))
$group_id = $r[0]['id'];
if(! $group_id)
);
// remove group
- $r = q("DELETE FROM `group` WHERE `uid` = %d AND `id` = %d LIMIT 1",
+ $r = q("UPDATE `group` SET `deleted` = 1 WHERE `uid` = %d AND `name` = '%s' LIMIT 1",
intval($uid),
dbesc($name)
);
$ret = $r;
}
- // TODO!! remove this group from all content ACL's !!
return $ret;
}
intval($member)
);
return $r;
-}
\ No newline at end of file
+}
+
+function group_get_members($gid) {
+ $ret = array();
+ if(intval($gid)) {
+ $r = q("SELECT `group_member`.`contact-id`, `contact`.* FROM `group_member`
+ LEFT JOIN `contact` ON `contact`.`id` = `group_member`.`contact-id`
+ WHERE `gid` = %d AND `group_member`.`uid` = %d ORDER BY `contact`.`name` ASC ",
+ intval($gid),
+ intval(local_user())
+ );
+ if(count($r))
+ $ret = $r;
+ }
+ return $ret;
+}
+
+function group_public_members($gid) {
+ $ret = 0;
+ if(intval($gid)) {
+ $r = q("SELECT `contact`.`id` AS `contact-id` FROM `group_member`
+ LEFT JOIN `contact` ON `contact`.`id` = `group_member`.`contact-id`
+ WHERE `gid` = %d AND `group_member`.`uid` = %d
+ AND `contact`.`network` != 'dfrn' AND `contact`.`network` != 'mail' AND `contact`.`network` != 'face' ",
+ intval($gid),
+ intval(local_user())
+ );
+ if(count($r))
+ $ret = count($r);
+ }
+ return $ret;
+}
+
+
+
+function group_side($every="contacts",$each="group",$edit = false) {
+
+ $o = '';
+
+ if(! local_user())
+ return '';
+
+ $createtext = t('Create a new group');
+ $linktext= t('Everybody');
+
+$o .= <<< EOT
+
+<div id="group-sidebar">
+<h3>Groups</h3>
+
+<div id="sidebar-new-group">
+<a href="group/new">$createtext</a>
+</div>
+
+<div id="sidebar-group-list">
+ <ul id="sidebar-group-ul">
+ <li class="sidebar-group-li" ><a href="$every" >$linktext</a></li>
+
+EOT;
+
+ $r = q("SELECT * FROM `group` WHERE `deleted` = 0 AND `uid` = %d",
+ intval($_SESSION['uid'])
+ );
+ if(count($r)) {
+ foreach($r as $rr)
+ $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";
+ }
+ $o .= " </ul>\r\n </div>\r\n</div>";
+
+ return $o;
+}
+
+function expand_groups($a) {
+ if(! (is_array($a) && count($a)))
+ return array();
+ $groups = implode(',', $a);
+ $groups = dbesc($groups);
+ $r = q("SELECT `contact-id` FROM `group_member` WHERE `gid` IN ( $groups )");
+ $ret = array();
+ if(count($r))
+ foreach($r as $rr)
+ $ret[] = $rr['contact-id'];
+ return $ret;
+}