// Let's assume we've just created a group which we once deleted
// all the old members are gone, but the group remains so we don't break any security
// access lists. What we're doing here is reviving the dead group, but old content which
// was restricted to this group may now be seen by the new group members.
$z=q("SELECT * FROM `groups` WHERE `id` = %d LIMIT 1",
intval($r)
);
if(count($z)&&$z[0]['deleted']){
/*$r=q("UPDATE `groups` SET `deleted` = 0 WHERE `uid` = %d AND `name` = '%s' LIMIT 1",
intval($uid),
dbesc($name)
);*/
q('UPDATE groups SET deleted = 0 WHERE id = %d',intval($z[0]['id']));
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);
}
returntrue;
}
do{
$dups=false;
$hash=random_string().$name;
$r=q("SELECT id FROM `groups` WHERE hash = '%s' LIMIT 1",dbesc($hash));
if($r)
$dups=true;
}while($dups==true);
$r=q("INSERT INTO `groups` ( hash, uid, visible, name )
VALUES('%s',%d,%d,'%s')",
dbesc($hash),
intval($uid),
intval($public),
dbesc($name)
);
$ret=$r;
}
build_sync_packet($uid,null,true);
return$ret;
}
functiongroup_rmv($uid,$name){
$ret=false;
if(x($uid)&&x($name)){
$r=q("SELECT id, hash FROM `groups` WHERE `uid` = %d AND `name` = '%s' LIMIT 1",
intval($uid),
dbesc($name)
);
if($r){
$group_id=$r[0]['id'];
$group_hash=$r[0]['hash'];
}
if(!$group_id)
returnfalse;
// remove group from default posting lists
$r=q("SELECT channel_default_group, channel_allow_gid, channel_deny_gid FROM channel WHERE channel_id = %d LIMIT 1",
$r=q("SELECT xchan FROM group_member WHERE gid IN ( select id from `groups` where hash in ( $groups ))");
$ret=array();
if($r)
foreach($ras$rr)
$ret[]=$rr['xchan'];
return$ret;
}
functionmember_of($c){
$r=q("SELECT `groups`.`name`, `groups`.`id` FROM `groups` LEFT JOIN `group_member` ON `group_member`.`gid` = `groups`.`id` WHERE `group_member`.`xchan` = '%s' AND `groups`.`deleted` = 0 ORDER BY `groups`.`name` ASC ",
dbesc($c)
);
return$r;
}
functiongroups_containing($uid,$c){
$r=q("SELECT `gid` FROM `group_member` WHERE `uid` = %d AND `group_member`.`xchan` = '%s' ",