packages/ssoinabox-webui/root/usr/local/share/ssoinabox/htdocs/groups.php
changeset 0 3906ca745819
child 4 2212b2ded8bf
equal deleted inserted replaced
-1:000000000000 0:3906ca745819
       
     1 <?php
       
     2 
       
     3 require('includes/starthere.php');
       
     4 
       
     5 // POSTed actions
       
     6 if ( !empty($_SERVER['PATH_INFO']) )
       
     7 {
       
     8 	$pi = explode('/', trim($_SERVER['PATH_INFO'], '/'));
       
     9 	switch($pi[0])
       
    10 	{
       
    11 		case 'delete':
       
    12 			if ( !isset($pi[1]) )
       
    13 				break;
       
    14 			
       
    15 			$group =& $pi[1];
       
    16 			
       
    17 			if ( !ldap_get_group($group) )
       
    18 			{
       
    19 				break;
       
    20 			}
       
    21 			
       
    22 			if ( delete_group($group) )
       
    23 			{
       
    24 				queue_message(E_NOTICE, "The group \"$group\" was deleted.");
       
    25 			}
       
    26 			else
       
    27 			{
       
    28 				queue_message(E_ERROR, "Failed to delete the group. Ensure that no users have it set as their primary group.");
       
    29 			}
       
    30 			
       
    31 			break;
       
    32 		case 'create':
       
    33 			
       
    34 			if ( empty($_POST) )
       
    35 			{
       
    36 				queue_message(E_ERROR, "Bad request");
       
    37 				break;
       
    38 			}
       
    39 			
       
    40 			if ( ldap_get_group($_POST['cn']) )
       
    41 			{
       
    42 				queue_message(E_ERROR, "This group already exists.");
       
    43 				break;
       
    44 			}
       
    45 			
       
    46 			if ( create_group($_POST['cn'], $_POST['description']) )
       
    47 				queue_message(E_NOTICE, "The group \"{$_POST['cn']}\" was created.");
       
    48 			else
       
    49 				queue_message(E_ERROR, "Failed to create group");
       
    50 			
       
    51 			break;
       
    52 	}
       
    53 }
       
    54 
       
    55 // list groups
       
    56 $groups = ldap_list_groups();
       
    57 
       
    58 // Present the UI
       
    59 display_template('groups', array(
       
    60 		'groups' => $groups
       
    61 		, 'users_json' => json_encode(ldap_list_users())
       
    62 		, 'next_gid' => get_next_available_gid()
       
    63 	));
       
    64