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