} else { if ($group['managedby'][0] != $_SESSION['user_dn']) { unset($groups[$key]); } } } $groups = array_values($groups); // Sort the groups $sortKeys = array(); foreach ($groups as $group) { $sortKeys[] = implode(' / ', dnToLevels($group['dn'])); } array_multisort($sortKeys, $groups); // PRint the groups foreach ($groups as $group) { printGroupHtml($ldap, $group); } ?> </div> <form action="<?php echo getUrl('create_group'); ?> " method="post" id="create_group_form"> <p>Create a new group in <select name="container_dn" id="new_group_container_dn"> <?php foreach ($ldapConfig['WritableGroupContainers'] as $dn) { print "\n\t\t\t<option value=\"" . base64_encode($dn) . "\">" . implode(" / ", dnToLevels($dn)) . "</option>"; }
throw new InvalidArgumentException("No new_group_name passed"); } $newGroupName = $_POST['new_group_name']; if (!preg_match('/^[a-z0-9][a-z0-9\\s.,_\'&-]+$/i', $newGroupName)) { throw new InvalidArgumentException("Invalid new_group_name passed"); } $groupId = "CN=" . $ldap->escapeDnValue($newGroupName) . "," . $containerDn; // Verify that the current user really can manage the group. try { $groups = $ldap->read('(objectclass=group)', $groupId, array('managedby', 'member')); if (count($groups)) { throw new Exception("A group with the name {$newGroupName} already exists."); } } catch (LdapException $e) { } $entry['cn'][0] = $newGroupName; $entry['objectclass'][0] = 'top'; $entry['objectclass'][1] = 'group'; $entry['grouptype'] = "2"; $entry['managedby'][0] = $_SESSION['user_dn']; // $entry["sAMAccountName"] = $newGroupName; // create the new group $ldap->add($groupId, $entry); // Print out its HTML for insertion into the document while (ob_get_level()) { ob_end_clean(); } header('Content-Type: text/html'); $entry['dn'] = $groupId; printGroupHtml($ldap, $entry); exit;