2011-07-19 14:17:58 +00:00
|
|
|
<?php
|
|
|
|
/* ACL selector json backend */
|
|
|
|
require_once("include/acl_selectors.php");
|
|
|
|
|
|
|
|
function acl_init(&$a){
|
|
|
|
if(!local_user())
|
|
|
|
return "";
|
|
|
|
|
|
|
|
|
|
|
|
$start = (x($_POST,'start')?$_POST['start']:0);
|
|
|
|
$count = (x($_POST,'count')?$_POST['count']:100);
|
|
|
|
$search = (x($_POST,'search')?$_POST['search']:"");
|
|
|
|
|
|
|
|
if ($search!=""){
|
|
|
|
$sql_extra = "AND `name` LIKE '%%".dbesc($search)."%%'";
|
2011-10-25 13:01:58 +00:00
|
|
|
$sql_extra2 = "AND (`name` LIKE '%%".dbesc($search)."%%' OR `nick` LIKE '%%".dbesc($search)."%%')";
|
2011-07-19 14:17:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// count groups and contacts
|
|
|
|
$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`
|
|
|
|
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'];
|
|
|
|
|
|
|
|
$tot = $group_count+$contact_count;
|
|
|
|
|
|
|
|
$groups = array();
|
|
|
|
$contacts = array();
|
|
|
|
|
|
|
|
$r = q("SELECT `group`.`id`, `group`.`name`, GROUP_CONCAT(DISTINCT `group_member`.`contact-id` SEPARATOR ',') as uids
|
|
|
|
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)
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
foreach($r as $g){
|
|
|
|
$groups[] = array(
|
|
|
|
"type" => "g",
|
2011-07-19 14:25:40 +00:00
|
|
|
"photo" => "images/default-group-mm.png",
|
2011-07-19 14:17:58 +00:00
|
|
|
"name" => $g['name'],
|
|
|
|
"id" => intval($g['id']),
|
2011-09-27 12:02:25 +00:00
|
|
|
"uids" => array_map("intval", explode(",",$g['uids'])),
|
|
|
|
"link" => ''
|
2011-07-19 14:17:58 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-25 13:01:58 +00:00
|
|
|
$r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url` FROM `contact`
|
2011-07-19 14:17:58 +00:00
|
|
|
WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 AND `pending` = 0 AND `notify` != ''
|
2011-10-25 13:01:58 +00:00
|
|
|
$sql_extra2
|
2011-07-19 14:17:58 +00:00
|
|
|
ORDER BY `name` ASC ",
|
|
|
|
intval(local_user())
|
|
|
|
);
|
|
|
|
foreach($r as $g){
|
|
|
|
$contacts[] = array(
|
|
|
|
"type" => "c",
|
|
|
|
"photo" => $g['micro'],
|
|
|
|
"name" => $g['name'],
|
|
|
|
"id" => intval($g['id']),
|
2011-09-27 12:02:25 +00:00
|
|
|
"network" => $g['network'],
|
|
|
|
"link" => $g['url'],
|
2011-10-25 13:01:58 +00:00
|
|
|
"nick" => $g['nick'],
|
2011-07-19 14:17:58 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$items = array_merge($groups, $contacts);
|
|
|
|
|
|
|
|
$o = array(
|
|
|
|
'tot' => $tot,
|
|
|
|
'start' => $start,
|
|
|
|
'count' => $count,
|
|
|
|
'items' => $items,
|
|
|
|
);
|
|
|
|
|
|
|
|
echo json_encode($o);
|
|
|
|
|
|
|
|
killme();
|
|
|
|
}
|
|
|
|
|
|
|
|
|