packages/ssoinabox-webui/root/usr/local/share/ssoinabox/htdocs/groups.php
changeset 0 3906ca745819
child 4 2212b2ded8bf
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/packages/ssoinabox-webui/root/usr/local/share/ssoinabox/htdocs/groups.php	Tue Jan 08 23:13:29 2013 -0500
@@ -0,0 +1,64 @@
+<?php
+
+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()
+	));
+