<?php
define('NEED_ADMIN', 1);
require('includes/starthere.php');
// POSTed actions
if ( !empty($_SERVER['PATH_INFO']) )
{
$pi = explode('/', trim($_SERVER['PATH_INFO'], '/'));
switch($pi[0])
{
case 'delete':
if ( !isset($pi[1]) )
break;
$group =& $pi[1];
if ( !ldap_get_group($group) )
{
break;
}
if ( delete_group($group) )
{
queue_message(E_NOTICE, "The group \"$group\" was deleted.");
}
else
{
queue_message(E_ERROR, "Failed to delete the group. Ensure that no users have it set as their primary group.");
}
break;
case 'create':
if ( empty($_POST) )
{
queue_message(E_ERROR, "Bad request");
break;
}
if ( ldap_get_group($_POST['cn']) )
{
queue_message(E_ERROR, "This group already exists.");
break;
}
if ( create_group($_POST['cn'], $_POST['description']) )
queue_message(E_NOTICE, "The group \"{$_POST['cn']}\" was created.");
else
queue_message(E_ERROR, "Failed to create group");
break;
}
}
// list groups
$groups = ldap_list_groups();
// Present the UI
display_template('groups', array(
'groups' => $groups
, 'users_json' => json_encode(ldap_list_users())
, 'next_gid' => get_next_available_gid()
));