]> git.mxchange.org Git - friendica.git/blob - mod/acl.php
autocomplete contacts nickname while writting in a comment box.
[friendica.git] / mod / acl.php
1 <?php
2 /* ACL selector json backend */
3 require_once("include/acl_selectors.php");
4
5 function acl_init(&$a){
6         if(!local_user())
7                 return "";
8
9
10         $start = (x($_POST,'start')?$_POST['start']:0);
11         $count = (x($_POST,'count')?$_POST['count']:100);
12         $search = (x($_POST,'search')?$_POST['search']:"");
13
14         if ($search!=""){
15                 $sql_extra = "AND `name` LIKE '%%".dbesc($search)."%%'";
16                 $sql_extra2 = "AND (`name` LIKE '%%".dbesc($search)."%%' OR `nick` LIKE '%%".dbesc($search)."%%')";
17         }
18         
19         // count groups and contacts
20         $r = q("SELECT COUNT(`id`) AS g FROM `group` WHERE `deleted` = 0 AND `uid` = %d $sql_extra",
21                 intval(local_user())
22         );
23         $group_count = (int)$r[0]['g'];
24         $r = q("SELECT COUNT(`id`) AS c FROM `contact` 
25                         WHERE `uid` = %d AND `self` = 0 
26                           AND `blocked` = 0 AND `pending` = 0 
27                           AND `notify` != '' $sql_extra" ,
28                 intval(local_user())
29         );
30         $contact_count = (int)$r[0]['c'];
31         
32         $tot = $group_count+$contact_count;
33         
34         $groups = array();
35         $contacts = array();
36         
37         $r = q("SELECT `group`.`id`, `group`.`name`, GROUP_CONCAT(DISTINCT `group_member`.`contact-id` SEPARATOR ',') as uids
38                         FROM `group`,`group_member` 
39                         WHERE `group`.`deleted` = 0 AND `group`.`uid` = %d 
40                                 AND `group_member`.`gid`=`group`.`id`
41                                 $sql_extra
42                         GROUP BY `group`.`id`
43                         ORDER BY `group`.`name` 
44                         LIMIT %d,%d",
45                 intval(local_user()),
46                 intval($start),
47                 intval($count)
48         );
49
50         
51         foreach($r as $g){
52                 $groups[] = array(
53                         "type"  => "g",
54                         "photo" => "images/default-group-mm.png",
55                         "name"  => $g['name'],
56                         "id"    => intval($g['id']),
57                         "uids"  => array_map("intval", explode(",",$g['uids'])),
58                         "link"  => ''
59                 );
60         }
61         
62         
63         $r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url` FROM `contact` 
64                 WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 AND `pending` = 0 AND `notify` != ''
65                 $sql_extra2
66                 ORDER BY `name` ASC ",
67                 intval(local_user())
68         );
69         foreach($r as $g){
70                 $contacts[] = array(
71                         "type"  => "c",
72                         "photo" => $g['micro'],
73                         "name"  => $g['name'],
74                         "id"    => intval($g['id']),
75                         "network" => $g['network'],
76                         "link" => $g['url'],
77                         "nick" => $g['nick'],
78                 );
79         }
80                 
81         
82         
83         
84         $items = array_merge($groups, $contacts);
85         
86         $o = array(
87                 'tot'   => $tot,
88                 'start' => $start,
89                 'count' => $count,
90                 'items' => $items,
91         );
92         
93         echo json_encode($o);
94
95         killme();
96 }
97
98