friendica/mod/acl.php

116 lines
2.7 KiB
PHP
Raw Normal View History

2011-07-19 16:17:58 +02:00
<?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']:"");
2011-10-25 15:49:53 +02:00
$type = (x($_POST,'type')?$_POST['type']:"");
2011-07-19 16:17:58 +02:00
if ($search!=""){
$sql_extra = "AND `name` LIKE '%%".dbesc($search)."%%'";
$sql_extra2 = "AND (`attag` LIKE '%%".dbesc($search)."%%' OR `name` LIKE '%%".dbesc($search)."%%' OR `nick` LIKE '%%".dbesc($search)."%%')";
2012-02-26 21:40:41 +01:00
} else {
$sql_extra = $sql_extra2 = "";
2011-07-19 16:17:58 +02:00
}
// count groups and contacts
2011-10-25 15:49:53 +02:00
if ($type=='' || $type=='g'){
$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'];
} else {
$group_count = 0;
}
if ($type=='' || $type=='c'){
$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'];
} else {
$contact_count = 0;
}
2011-07-19 16:17:58 +02:00
$tot = $group_count+$contact_count;
$groups = array();
$contacts = array();
2011-10-25 15:49:53 +02:00
if ($type=='' || $type=='g'){
$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)
2011-07-19 16:17:58 +02:00
);
2011-10-25 15:49:53 +02:00
foreach($r as $g){
// logger('acl: group: ' . $g['name'] . ' members: ' . $g['uids']);
2011-10-25 15:49:53 +02:00
$groups[] = array(
"type" => "g",
2012-01-11 06:09:38 +01:00
"photo" => "images/twopeople.png",
2011-10-25 15:49:53 +02:00
"name" => $g['name'],
"id" => intval($g['id']),
"uids" => array_map("intval", explode(",",$g['uids'])),
"link" => ''
);
}
2011-07-19 16:17:58 +02:00
}
2011-10-25 15:49:53 +02:00
if ($type=='' || $type=='c'){
2011-07-19 16:17:58 +02:00
2012-02-26 21:40:41 +01:00
$r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url`, `attag` FROM `contact`
2011-10-25 15:49:53 +02:00
WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 AND `pending` = 0 AND `notify` != ''
$sql_extra2
ORDER BY `name` ASC ",
intval(local_user())
2011-07-19 16:17:58 +02:00
);
2011-10-25 15:49:53 +02:00
foreach($r as $g){
$contacts[] = array(
"type" => "c",
"photo" => $g['micro'],
"name" => $g['name'],
"id" => intval($g['id']),
"network" => $g['network'],
"link" => $g['url'],
"nick" => ($g['attag']) ? $g['attag'] : $g['nick'],
2011-10-25 15:49:53 +02:00
);
}
2011-07-19 16:17:58 +02:00
}
$items = array_merge($groups, $contacts);
$o = array(
'tot' => $tot,
'start' => $start,
'count' => $count,
'items' => $items,
);
echo json_encode($o);
killme();
}