filter by contact type

This commit is contained in:
Fabio Comuni 2011-10-25 15:49:53 +02:00
parent bcb672e7ff
commit 155a09cfdf

View file

@ -10,6 +10,8 @@ function acl_init(&$a){
$start = (x($_POST,'start')?$_POST['start']:0); $start = (x($_POST,'start')?$_POST['start']:0);
$count = (x($_POST,'count')?$_POST['count']:100); $count = (x($_POST,'count')?$_POST['count']:100);
$search = (x($_POST,'search')?$_POST['search']:""); $search = (x($_POST,'search')?$_POST['search']:"");
$type = (x($_POST,'type')?$_POST['type']:"");
if ($search!=""){ if ($search!=""){
$sql_extra = "AND `name` LIKE '%%".dbesc($search)."%%'"; $sql_extra = "AND `name` LIKE '%%".dbesc($search)."%%'";
@ -17,70 +19,83 @@ function acl_init(&$a){
} }
// count groups and contacts // count groups and contacts
$r = q("SELECT COUNT(`id`) AS g FROM `group` WHERE `deleted` = 0 AND `uid` = %d $sql_extra", if ($type=='' || $type=='g'){
intval(local_user()) $r = q("SELECT COUNT(`id`) AS g FROM `group` WHERE `deleted` = 0 AND `uid` = %d $sql_extra",
); intval(local_user())
$group_count = (int)$r[0]['g']; );
$r = q("SELECT COUNT(`id`) AS c FROM `contact` $group_count = (int)$r[0]['g'];
WHERE `uid` = %d AND `self` = 0 } else {
AND `blocked` = 0 AND `pending` = 0 $group_count = 0;
AND `notify` != '' $sql_extra" , }
intval(local_user())
); if ($type=='' || $type=='c'){
$contact_count = (int)$r[0]['c']; $r = q("SELECT COUNT(`id`) AS c FROM `contact`
WHERE `uid` = %d AND `self` = 0
AND `blocked` = 0 AND `pending` = 0
AND `notify` != '' $sql_extra" ,
intval(local_user())
);
$contact_count = (int)$r[0]['c'];
} else {
$contact_count = 0;
}
$tot = $group_count+$contact_count; $tot = $group_count+$contact_count;
$groups = array(); $groups = array();
$contacts = array(); $contacts = array();
$r = q("SELECT `group`.`id`, `group`.`name`, GROUP_CONCAT(DISTINCT `group_member`.`contact-id` SEPARATOR ',') as uids if ($type=='' || $type=='g'){
FROM `group`,`group_member`
WHERE `group`.`deleted` = 0 AND `group`.`uid` = %d
AND `group_member`.`gid`=`group`.`id`
$sql_extra
GROUP BY `group`.`id`
ORDER BY `group`.`name`
LIMIT %d,%d",
intval(local_user()),
intval($start),
intval($count)
);
$r = q("SELECT `group`.`id`, `group`.`name`, GROUP_CONCAT(DISTINCT `group_member`.`contact-id` SEPARATOR ',') as uids
foreach($r as $g){ FROM `group`,`group_member`
$groups[] = array( WHERE `group`.`deleted` = 0 AND `group`.`uid` = %d
"type" => "g", AND `group_member`.`gid`=`group`.`id`
"photo" => "images/default-group-mm.png", $sql_extra
"name" => $g['name'], GROUP BY `group`.`id`
"id" => intval($g['id']), ORDER BY `group`.`name`
"uids" => array_map("intval", explode(",",$g['uids'])), LIMIT %d,%d",
"link" => '' intval(local_user()),
intval($start),
intval($count)
); );
foreach($r as $g){
$groups[] = array(
"type" => "g",
"photo" => "images/default-group-mm.png",
"name" => $g['name'],
"id" => intval($g['id']),
"uids" => array_map("intval", explode(",",$g['uids'])),
"link" => ''
);
}
} }
if ($type=='' || $type=='c'){
$r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url` FROM `contact` $r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url` FROM `contact`
WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 AND `pending` = 0 AND `notify` != '' WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 AND `pending` = 0 AND `notify` != ''
$sql_extra2 $sql_extra2
ORDER BY `name` ASC ", ORDER BY `name` ASC ",
intval(local_user()) intval(local_user())
);
foreach($r as $g){
$contacts[] = array(
"type" => "c",
"photo" => $g['micro'],
"name" => $g['name'],
"id" => intval($g['id']),
"network" => $g['network'],
"link" => $g['url'],
"nick" => $g['nick'],
); );
foreach($r as $g){
$contacts[] = array(
"type" => "c",
"photo" => $g['micro'],
"name" => $g['name'],
"id" => intval($g['id']),
"network" => $g['network'],
"link" => $g['url'],
"nick" => $g['nick'],
);
}
} }
$items = array_merge($groups, $contacts); $items = array_merge($groups, $contacts);
$o = array( $o = array(