2 /* ACL selector json backend */
4 require_once("include/acl_selectors.php");
6 function acl_init(&$a){
11 $start = (x($_REQUEST,'start')?$_REQUEST['start']:0);
12 $count = (x($_REQUEST,'count')?$_REQUEST['count']:100);
13 $search = (x($_REQUEST,'search')?$_REQUEST['search']:"");
14 $type = (x($_REQUEST,'type')?$_REQUEST['type']:"");
17 // For use with jquery.autocomplete for private mail completion
19 if(x($_REQUEST,'query') && strlen($_REQUEST['query'])) {
22 $search = $_REQUEST['query'];
27 $sql_extra = "AND `name` LIKE '%%".dbesc($search)."%%'";
28 $sql_extra2 = "AND (`attag` LIKE '%%".dbesc($search)."%%' OR `name` LIKE '%%".dbesc($search)."%%' OR `nick` LIKE '%%".dbesc($search)."%%')";
30 $sql_extra = $sql_extra2 = "";
33 // count groups and contacts
34 if ($type=='' || $type=='g'){
35 $r = q("SELECT COUNT(`id`) AS g FROM `group` WHERE `deleted` = 0 AND `uid` = %d $sql_extra",
38 $group_count = (int)$r[0]['g'];
43 if ($type=='' || $type=='c'){
44 $r = q("SELECT COUNT(`id`) AS c FROM `contact`
45 WHERE `uid` = %d AND `self` = 0
46 AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0
47 AND `notify` != '' $sql_extra2" ,
50 $contact_count = (int)$r[0]['c'];
52 elseif ($type == 'm') {
54 // autocomplete for Private Messages
56 $r = q("SELECT COUNT(`id`) AS c FROM `contact`
57 WHERE `uid` = %d AND `self` = 0
58 AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0
59 AND `network` IN ('%s','%s','%s') $sql_extra2" ,
63 dbesc(NETWORK_DIASPORA)
65 $contact_count = (int)$r[0]['c'];
68 elseif ($type == 'a') {
70 // autocomplete for Contacts
72 $r = q("SELECT COUNT(`id`) AS c FROM `contact`
73 WHERE `uid` = %d AND `self` = 0
74 AND `pending` = 0 $sql_extra2" ,
77 $contact_count = (int)$r[0]['c'];
83 $tot = $group_count+$contact_count;
88 if ($type=='' || $type=='g'){
90 $r = q("SELECT `group`.`id`, `group`.`name`, GROUP_CONCAT(DISTINCT `group_member`.`contact-id` SEPARATOR ',') as uids
91 FROM `group`,`group_member`
92 WHERE `group`.`deleted` = 0 AND `group`.`uid` = %d
93 AND `group_member`.`gid`=`group`.`id`
96 ORDER BY `group`.`name`
104 // logger('acl: group: ' . $g['name'] . ' members: ' . $g['uids']);
107 "photo" => "images/twopeople.png",
108 "name" => $g['name'],
109 "id" => intval($g['id']),
110 "uids" => array_map("intval", explode(",",$g['uids'])),
116 if ($type=='' || $type=='c'){
118 $r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url`, `attag` FROM `contact`
119 WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0 AND `notify` != ''
121 ORDER BY `name` ASC ",
125 elseif($type == 'm') {
126 $r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url`, `attag` FROM `contact`
127 WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0
128 AND `network` IN ('%s','%s','%s')
130 ORDER BY `name` ASC ",
131 intval(local_user()),
134 dbesc(NETWORK_DIASPORA)
137 elseif($type == 'a') {
138 $r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url`, `attag` FROM `contact`
139 WHERE `uid` = %d AND `pending` = 0
141 ORDER BY `name` ASC ",
149 if($type == 'm' || $type == 'a') {
151 $x['query'] = $search;
152 $x['photos'] = array();
153 $x['links'] = array();
154 $x['suggestions'] = array();
155 $x['data'] = array();
158 $x['photos'][] = $g['micro'];
159 $x['links'][] = $g['url'];
160 $x['suggestions'][] = $g['name'];
161 $x['data'][] = intval($g['id']);
164 echo json_encode($x);
172 "photo" => $g['micro'],
173 "name" => $g['name'],
174 "id" => intval($g['id']),
175 "network" => $g['network'],
177 "nick" => ($g['attag']) ? $g['attag'] : $g['nick'],
182 $items = array_merge($groups, $contacts);
191 echo json_encode($o);