2007-08-28 10:18:04 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* AJAX autocompletion code for group names.
|
|
|
|
*
|
|
|
|
* @author Jan Dittberner <jan@dittberner.info>
|
|
|
|
* @version $Id$
|
|
|
|
* @license GPL
|
2007-11-26 09:49:33 +01:00
|
|
|
* @package DAVAdmin
|
2007-08-28 10:18:04 +02:00
|
|
|
*
|
2008-11-16 19:54:41 +01:00
|
|
|
* Copyright (c) 2007, 2008 Jan Dittberner
|
2007-08-28 10:18:04 +02:00
|
|
|
*
|
2007-11-26 09:49:33 +01:00
|
|
|
* This file is part of DAVAdmin.
|
2007-08-28 10:18:04 +02:00
|
|
|
*
|
2008-11-16 19:54:41 +01:00
|
|
|
* DAVAdmin is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
2007-08-28 10:18:04 +02:00
|
|
|
*
|
2008-11-16 19:54:41 +01:00
|
|
|
* DAVAdmin is distributed in the hope that it will be useful, but
|
2007-08-28 10:18:04 +02:00
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2008-11-16 19:54:41 +01:00
|
|
|
* along with DAVAdmin; if not, see <http://www.gnu.org/licenses/>.
|
2007-08-28 10:18:04 +02:00
|
|
|
*/
|
|
|
|
|
2007-12-01 21:30:41 +01:00
|
|
|
/** Include the code shared between normal pages and AJAX. */
|
|
|
|
require_once("shared.inc.php");
|
2007-08-28 10:18:04 +02:00
|
|
|
|
|
|
|
// output is plain text (JSON or an error message)
|
|
|
|
header("Content-Type: text/plain; charset=UTF-8");
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets group names for autocompletion.
|
|
|
|
*
|
|
|
|
* @param string $part Comma separated list of groups and beginning of
|
|
|
|
* a new group entry
|
|
|
|
* @return list of Comma separated lists of groups
|
|
|
|
*/
|
|
|
|
function getGroups($part) {
|
|
|
|
$regexp = '%(?:^|,\ *)("(?>[^"]*)(?>""[^"]* )*"|(?: [^",]*))%x';
|
|
|
|
preg_match_all($regexp, $part, $matches);
|
|
|
|
$array = $matches[1];
|
|
|
|
$last_string = trim(array_pop($array));
|
2007-11-22 08:41:30 +01:00
|
|
|
$retval = array();
|
2007-08-28 10:18:04 +02:00
|
|
|
if ($last_string != '') {
|
2007-11-23 19:48:56 +01:00
|
|
|
$prefix = count($array) ? implode(",", $array) . ", ": '';
|
2007-11-22 08:41:30 +01:00
|
|
|
$groups = file($GLOBALS['davconfig']['group.file']);
|
|
|
|
foreach ($groups as $line) {
|
|
|
|
list($group, $users) = explode(":", $line);
|
|
|
|
$group = trim($group);
|
2007-12-03 16:01:45 +01:00
|
|
|
if (!in_array($group, $array) &&
|
|
|
|
(stripos($group, $last_string) === 0)) {
|
2007-11-23 19:48:56 +01:00
|
|
|
$retval[$prefix . $group] = $group;
|
2007-08-28 10:18:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return json_encode($retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
// split group list part from requested URL.
|
|
|
|
$parts = substr($_SERVER['PHP_SELF'], strrpos($_SERVER['PHP_SELF'], "/") + 1);
|
|
|
|
print getGroups($parts);
|
|
|
|
?>
|