aboutsummaryrefslogtreecommitdiffstats
path: root/mod/acl.php
blob: cb5959a95b4b6393158097ef263b9d264ca8ee42 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
/* ACL selector json backend */
require_once("include/acl_selectors.php");

function acl_init(&$a){
	if(!local_user())
		return "";


	$start = (x($_POST,'start')?$_POST['start']:0);
	$count = (x($_POST,'count')?$_POST['count']:100);
	$search = (x($_POST,'search')?$_POST['search']:"");

	if ($search!=""){
		$sql_extra = "AND `name` LIKE '%%".dbesc($search)."%%'";
	}
	
	// count groups and contacts
	$r = q("SELECT COUNT(`id`) AS g FROM `group` WHERE `deleted` = 0 AND `uid` = %d $sql_extra",
		intval(local_user())
	);
	$group_count = (int)$r[0]['g'];
	$r = q("SELECT COUNT(`id`) AS c FROM `contact` 
			WHERE `uid` = %d AND `self` = 0 
			  AND `blocked` = 0 AND `pending` = 0 
			  AND `notify` != '' $sql_extra" ,
		intval(local_user())
	);
	$contact_count = (int)$r[0]['c'];
	
	$tot = $group_count+$contact_count;
	
	$groups = array();
	$contacts = array();
	
	$r = q("SELECT `group`.`id`, `group`.`name`, GROUP_CONCAT(DISTINCT `group_member`.`contact-id` SEPARATOR ',') as uids
			FROM `group`,`group_member` 
			WHERE `group`.`deleted` = 0 AND `group`.`uid` = %d 
				AND `group_member`.`gid`=`group`.`id`
				$sql_extra
			GROUP BY `group`.`id`
			ORDER BY `group`.`name` 
			LIMIT %d,%d",
		intval(local_user()),
		intval($start),
		intval($count)
	);

	
	foreach($r as $g){
		$groups[] = array(
			"type"  => "g",
			"photo" => "images/default-group-mm.png",
			"name"  => $g['name'],
			"id"	=> intval($g['id']),
			"uids"  => array_map("intval", explode(",",$g['uids']))
		);
	}
	
	
	$r = q("SELECT `id`, `name`, `micro`, `network` FROM `contact` 
		WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 AND `pending` = 0 AND `notify` != ''
		$sql_extra
		ORDER BY `name` ASC ",
		intval(local_user())
	);
	foreach($r as $g){
		$contacts[] = array(
			"type"  => "c",
			"photo" => $g['micro'],
			"name"  => $g['name'],
			"id"	=> intval($g['id']),
			"network" => $g['network']
		);
	}
		
	
	
	
	$items = array_merge($groups, $contacts);
	
	$o = array(
		'tot'	=> $tot,
		'start' => $start,
		'count'	=> $count,
		'items'	=> $items,
	);
	
	echo json_encode($o);

	killme();
}