]> git.mxchange.org Git - friendica.git/blob - mod/acl.php
Merge branch 'pull'
[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         }
17         
18         // count groups and contacts
19         $r = q("SELECT COUNT(`id`) AS g FROM `group` WHERE `deleted` = 0 AND `uid` = %d $sql_extra",
20                 intval(local_user())
21         );
22         $group_count = (int)$r[0]['g'];
23         $r = q("SELECT COUNT(`id`) AS c FROM `contact` 
24                         WHERE `uid` = %d AND `self` = 0 
25                           AND `blocked` = 0 AND `pending` = 0 
26                           AND `notify` != '' $sql_extra" ,
27                 intval(local_user())
28         );
29         $contact_count = (int)$r[0]['c'];
30         
31         $tot = $group_count+$contact_count;
32         
33         $groups = array();
34         $contacts = array();
35         
36         $r = q("SELECT `group`.`id`, `group`.`name`, GROUP_CONCAT(DISTINCT `group_member`.`contact-id` SEPARATOR ',') as uids
37                         FROM `group`,`group_member` 
38                         WHERE `group`.`deleted` = 0 AND `group`.`uid` = %d 
39                                 AND `group_member`.`gid`=`group`.`id`
40                                 $sql_extra
41                         GROUP BY `group`.`id`
42                         ORDER BY `group`.`name` 
43                         LIMIT %d,%d",
44                 intval(local_user()),
45                 intval($start),
46                 intval($count)
47         );
48
49         
50         foreach($r as $g){
51                 $groups[] = array(
52                         "type"  => "g",
53                         "photo" => "images/default-group-mm.png",
54                         "name"  => $g['name'],
55                         "id"    => intval($g['id']),
56                         "uids"  => array_map("intval", explode(",",$g['uids']))
57                 );
58         }
59         
60         
61         $r = q("SELECT `id`, `name`, `micro`, `network` FROM `contact` 
62                 WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 AND `pending` = 0 AND `notify` != ''
63                 $sql_extra
64                 ORDER BY `name` ASC ",
65                 intval(local_user())
66         );
67         foreach($r as $g){
68                 $contacts[] = array(
69                         "type"  => "c",
70                         "photo" => $g['micro'],
71                         "name"  => $g['name'],
72                         "id"    => intval($g['id']),
73                         "network" => $g['network']
74                 );
75         }
76                 
77         
78         
79         
80         $items = array_merge($groups, $contacts);
81         
82         $o = array(
83                 'tot'   => $tot,
84                 'start' => $start,
85                 'count' => $count,
86                 'items' => $items,
87         );
88         
89         echo json_encode($o);
90
91         killme();
92 }
93
94