make the visual group editor work again in the new world

This commit is contained in:
friendica 2012-11-14 20:55:05 -08:00
parent 71dc132f42
commit 160258fd5d
3 changed files with 36 additions and 21 deletions

View File

@ -146,7 +146,7 @@ function group_add_member($uid,$name,$member,$gid = 0) {
// -- It was just created at another time // -- It was just created at another time
if(! count($r)) if(! count($r))
$r = q("INSERT INTO `group_member` (`uid`, `gid`, `xchan`) $r = q("INSERT INTO `group_member` (`uid`, `gid`, `xchan`)
VALUES( %d, %d, %d ) ", VALUES( %d, %d, '%s' ) ",
intval($uid), intval($uid),
intval($gid), intval($gid),
dbesc($member) dbesc($member)
@ -157,11 +157,13 @@ function group_add_member($uid,$name,$member,$gid = 0) {
function group_get_members($gid) { function group_get_members($gid) {
$ret = array(); $ret = array();
if(intval($gid)) { if(intval($gid)) {
$r = q("SELECT abook.*,xchan.* FROM `group_member` $r = q("SELECT abook.*,xchan.*,group_member.* FROM `group_member`
LEFT JOIN abook ON abook_xchan = `group_member`.`xchan` left join xchan on xchan_hash = abook_xchan LEFT JOIN abook ON abook_xchan = `group_member`.`xchan` left join xchan on xchan_hash = abook_xchan
WHERE `gid` = %d AND `group_member`.`uid` = %d ORDER BY xchan_name ASC ", WHERE `gid` = %d AND `group_member`.`uid` = %d and not ( abook_flags & %d) and not (abook_flags & %d) ORDER BY xchan_name ASC ",
intval($gid), intval($gid),
intval(local_user()) intval(local_user()),
intval(ABOOK_FLAG_SELF),
intval(ABOOK_FLAG_BLOCKED)
); );
if(count($r)) if(count($r))
$ret = $r; $ret = $r;

View File

@ -549,12 +549,12 @@ function contact_block() {
$micropro = Null; $micropro = Null;
} else { } else {
dbg(1);
$r = q("SELECT abook.*, xchan.* FROM abook left join xchan on abook.abook_xchan = xchan.xchan_hash WHERE abook_channel = %d AND abook_flags = 0 ORDER BY RAND() LIMIT %d", $r = q("SELECT abook.*, xchan.* FROM abook left join xchan on abook.abook_xchan = xchan.xchan_hash WHERE abook_channel = %d AND abook_flags = 0 ORDER BY RAND() LIMIT %d",
intval($a->profile['uid']), intval($a->profile['uid']),
intval($shown) intval($shown)
); );
dbg(0);
if(count($r)) { if(count($r)) {
$contacts = sprintf( tt('%d Contact','%d Contacts', $total),$total); $contacts = sprintf( tt('%d Contact','%d Contacts', $total),$total);
$micropro = Array(); $micropro = Array();

View File

@ -115,15 +115,19 @@ function group_content(&$a) {
// NOTREACHED // NOTREACHED
} }
if(($a->argc > 2) && intval($a->argv[1]) && intval($a->argv[2])) {
if((argc() > 2) && intval(argv(1)) && argv(2)) {
check_form_security_token_ForbiddenOnErr('group_member_change', 't'); check_form_security_token_ForbiddenOnErr('group_member_change', 't');
$r = q("SELECT `id` FROM `contact` WHERE `id` = %d AND `uid` = %d and `self` = 0 and `blocked` = 0 AND `pending` = 0 LIMIT 1", $r = q("SELECT abook_xchan from abook where abook_xchan = '%s' and abook_channel = %d and not (abook_flags & %d) and not (abook_flags & %d) limit 1",
intval($a->argv[2]), dbesc(argv(2)),
intval(local_user()) intval(local_user()),
intval(ABOOK_FLAG_SELF),
intval(ABOOK_FLAG_BLOCKED)
); );
if(count($r)) if(count($r))
$change = intval($a->argv[2]); $change = argv(2);
} }
if(($a->argc > 1) && (intval($a->argv[1]))) { if(($a->argc > 1) && (intval($a->argv[1]))) {
@ -138,14 +142,19 @@ function group_content(&$a) {
goaway($a->get_baseurl() . '/connnections'); goaway($a->get_baseurl() . '/connnections');
} }
$group = $r[0]; $group = $r[0];
$members = group_get_members($group['id']); $members = group_get_members($group['id']);
$preselected = array(); $preselected = array();
if(count($members)) { if(count($members)) {
foreach($members as $member) foreach($members as $member)
$preselected[] = $member['id']; $preselected[] = $member['xchan_hash'];
} }
if($change) { if($change) {
if(in_array($change,$preselected)) { if(in_array($change,$preselected)) {
group_rmv_member(local_user(),$group['name'],$change); group_rmv_member(local_user(),$group['name'],$change);
} }
@ -154,14 +163,16 @@ function group_content(&$a) {
} }
$members = group_get_members($group['id']); $members = group_get_members($group['id']);
$preselected = array(); $preselected = array();
if(count($members)) { if(count($members)) {
foreach($members as $member) foreach($members as $member)
$preselected[] = $member['id']; $preselected[] = $member['xchan_hash'];
} }
} }
$drop_tpl = get_markup_template('group_drop.tpl'); $drop_tpl = get_markup_template('group_drop.tpl');
$drop_txt = replace_macros($drop_tpl, array( $drop_txt = replace_macros($drop_tpl, array(
'$id' => $group['id'], '$id' => $group['id'],
@ -195,23 +206,25 @@ function group_content(&$a) {
$sec_token = addslashes(get_form_security_token('group_member_change')); $sec_token = addslashes(get_form_security_token('group_member_change'));
$textmode = (($switchtotext && (count($members) > $switchtotext)) ? true : false); $textmode = (($switchtotext && (count($members) > $switchtotext)) ? true : false);
foreach($members as $member) { foreach($members as $member) {
if($member['url']) { if($member['xchan_url']) {
$member['click'] = 'groupChangeMember(' . $group['id'] . ',' . $member['id'] . ',\'' . $sec_token . '\'); return true;'; $member['click'] = 'groupChangeMember(' . $group['id'] . ',\'' . $member['xchan_hash'] . '\',\'' . $sec_token . '\'); return true;';
$groupeditor['members'][] = micropro($member,true,'mpgroup', $textmode); $groupeditor['members'][] = micropro($member,true,'mpgroup', $textmode);
} }
else else
group_rmv_member(local_user(),$group['name'],$member['id']); group_rmv_member(local_user(),$group['name'],$member['xchan_hash']);
} }
$r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `blocked` = 0 and `pending` = 0 and `self` = 0 ORDER BY `name` ASC", $r = q("SELECT abook.*, xchan.* FROM `abook` left join xchan on abook_xchan = xchan_hash WHERE `abook_channel` = %d AND not (abook_flags & %d) and not (abook_flags & %d) order by xchan_name asc",
intval(local_user()) intval(local_user()),
intval(ABOOK_FLAG_BLOCKED),
intval(ABOOK_FLAG_SELF)
); );
if(count($r)) { if(count($r)) {
$textmode = (($switchtotext && (count($r) > $switchtotext)) ? true : false); $textmode = (($switchtotext && (count($r) > $switchtotext)) ? true : false);
foreach($r as $member) { foreach($r as $member) {
if(! in_array($member['id'],$preselected)) { if(! in_array($member['xchan_hash'],$preselected)) {
$member['click'] = 'groupChangeMember(' . $group['id'] . ',' . $member['id'] . ',\'' . $sec_token . '\'); return true;'; $member['click'] = 'groupChangeMember(' . $group['id'] . ',\'' . $member['xchan_hash'] . '\',\'' . $sec_token . '\'); return true;';
$groupeditor['contacts'][] = micropro($member,true,'mpall', $textmode); $groupeditor['contacts'][] = micropro($member,true,'mpall', $textmode);
} }
} }