]> git.mxchange.org Git - friendica.git/blob - mod/acl.php
98ca90ded8b27d55ecf7aa9854e428c1d068c203
[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         $type = (x($_POST,'type')?$_POST['type']:"");
14         
15
16         if ($search!=""){
17                 $sql_extra = "AND `name` LIKE '%%".dbesc($search)."%%'";
18                 $sql_extra2 = "AND (`attag` LIKE '%%".dbesc($search)."%%' OR `name` LIKE '%%".dbesc($search)."%%' OR `nick` LIKE '%%".dbesc($search)."%%')";
19         }
20         
21         // count groups and contacts
22         if ($type=='' || $type=='g'){
23                 $r = q("SELECT COUNT(`id`) AS g FROM `group` WHERE `deleted` = 0 AND `uid` = %d $sql_extra",
24                         intval(local_user())
25                 );
26                 $group_count = (int)$r[0]['g'];
27         } else {
28                 $group_count = 0;
29         }
30         
31         if ($type=='' || $type=='c'){
32                 $r = q("SELECT COUNT(`id`) AS c FROM `contact` 
33                                 WHERE `uid` = %d AND `self` = 0 
34                                 AND `blocked` = 0 AND `pending` = 0 
35                                 AND `notify` != '' $sql_extra" ,
36                         intval(local_user())
37                 );
38                 $contact_count = (int)$r[0]['c'];
39         } else {
40                 $contact_count = 0;
41         }
42         
43         $tot = $group_count+$contact_count;
44         
45         $groups = array();
46         $contacts = array();
47         
48         if ($type=='' || $type=='g'){
49                 
50                 $r = q("SELECT `group`.`id`, `group`.`name`, GROUP_CONCAT(DISTINCT `group_member`.`contact-id` SEPARATOR ',') as uids
51                                 FROM `group`,`group_member` 
52                                 WHERE `group`.`deleted` = 0 AND `group`.`uid` = %d 
53                                         AND `group_member`.`gid`=`group`.`id`
54                                         $sql_extra
55                                 GROUP BY `group`.`id`
56                                 ORDER BY `group`.`name` 
57                                 LIMIT %d,%d",
58                         intval(local_user()),
59                         intval($start),
60                         intval($count)
61                 );
62
63                 foreach($r as $g){
64 //              logger('acl: group: ' . $g['name'] . ' members: ' . $g['uids']);                
65                         $groups[] = array(
66                                 "type"  => "g",
67                                 "photo" => "images/twopeople.png",
68                                 "name"  => $g['name'],
69                                 "id"    => intval($g['id']),
70                                 "uids"  => array_map("intval", explode(",",$g['uids'])),
71                                 "link"  => ''
72                         );
73                 }
74         }
75         
76         if ($type=='' || $type=='c'){
77         
78                 $r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url` FROM `contact` 
79                         WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 AND `pending` = 0 AND `notify` != ''
80                         $sql_extra2
81                         ORDER BY `name` ASC ",
82                         intval(local_user())
83                 );
84                 foreach($r as $g){
85                         $contacts[] = array(
86                                 "type"  => "c",
87                                 "photo" => $g['micro'],
88                                 "name"  => $g['name'],
89                                 "id"    => intval($g['id']),
90                                 "network" => $g['network'],
91                                 "link" => $g['url'],
92                                 "nick" => ($g['attag']) ? $g['attag'] : $g['nick'],
93                         );
94                 }
95                         
96         }
97         
98         
99         $items = array_merge($groups, $contacts);
100         
101         $o = array(
102                 'tot'   => $tot,
103                 'start' => $start,
104                 'count' => $count,
105                 'items' => $items,
106         );
107         
108         echo json_encode($o);
109
110         killme();
111 }
112
113