fixed user management

addresses #1
This commit is contained in:
Jan Dittberner 2007-11-22 07:41:30 +00:00
parent 7bffc8bf97
commit ef9a212ece
3 changed files with 173 additions and 123 deletions

View file

@ -27,8 +27,17 @@
* 02110-1301 USA.
*/
if (!isset($_SERVER['DavAdminConfDir'])) {
header('HTTP/1.0 500 Internal Server Error');
header('Status: 500 Internal Server Error');
header('Content-Type: text/plain;charset=utf8');
print("The Server is not configured correctly. " .
"Please tell your Administrator to set the " .
"DavAdminConfDir environment variable.");
exit();
}
/** Include configuration information. */
require_once('config.inc.php');
require_once($_SERVER['DavAdminConfDir'] . '/config.inc.php');
// output is plain text (JSON or an error message)
header("Content-Type: text/plain; charset=UTF-8");
@ -45,19 +54,15 @@ function getGroups($part) {
preg_match_all($regexp, $part, $matches);
$array = $matches[1];
$last_string = trim(array_pop($array));
$retval = array();
if ($last_string != '') {
try {
$dbh = new PDO($GLOBALS['dsn'], $GLOBALS['dbuser'], $GLOBALS['dbpass']);
$sth = $dbh->prepare("SELECT DISTINCT groupname FROM dav_group WHERE LOWER(groupname) LIKE LOWER(?) ORDER BY groupname");
$sth->execute(array("%" . $last_string . "%"));
$prefix = count($array) ? implode(",", $array) . ", " : '';
$retval = array();
foreach ($sth->fetchAll(PDO::FETCH_ASSOC) as $row) {
$retval[$prefix . $row['groupname']] = $row['groupname'];
$groups = file($GLOBALS['davconfig']['group.file']);
foreach ($groups as $line) {
list($group, $users) = explode(":", $line);
$group = trim($group);
if (stripos($group, $last_string) === 0) {
array_push($retval, $group);
}
$dbh = null;
} catch (PDOException $e) {
return $e->getMessage();
}
}
return json_encode($retval);