summaryrefslogtreecommitdiffstats
path: root/apps/files_sharing/ajax/userautocomplete.php
blob: 816e01ba9ee669bb21f9f95d4d7e7abd9ae95c80 (plain)
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
<?php
$RUNTIME_NOAPPS = true;

require_once('../../../lib/base.php');

if (!OC_User::isLoggedIn()) {
	echo json_encode(array("status" => "error", "data" => array("message" => "Authentication error")));
	exit();
}
$query = $_GET['term'];
$length = strlen($query);
$query = strtolower($query);
$users = array();
$ocusers = OC_User::getUsers();
$self = OC_User::getUser();
$groups = OC_GROUP::getUserGroups($self);
foreach ($ocusers as $user) {
	if ($user != $self && substr(strtolower($user), 0, $length) == $query) {
		$users[] = (object)array('id' => $user, 'label' => $user, 'name' => $user);
	}
}
foreach ($groups as $group) {
	if (substr(strtolower($group), 0, $length) == $query) {
		$users[] = (object)array('id' => $group, 'label' => $group, 'name' => $group);
	}
}
echo json_encode($users);

?>