Index: /branches/2.2/setup/ldapmodify.php
===================================================================
--- /branches/2.2/setup/ldapmodify.php	(revision 3607)
+++ /branches/2.2/setup/ldapmodify.php	(revision 3664)
@@ -91,5 +91,7 @@
 	if ( array_key_exists( 'ldap_group_context', $phpgw_info[ 'server' ] ) && count( $phpgw_info['server']['global_denied_groups'] ) )
 	{
-		$sr = ldap_search( $ldap, $config[ 'ldap_group_context' ], '(objectClass=posixGroup)', array( 'gidnumber', 'cn', 'memberuid' ) );
+		$sr = ldap_search( $ldap, $config[ 'ldap_group_context' ], '(objectClass=posixGroup)',
+			array( 'gidnumber', 'cn', 'memberuid', 'objectclass', 'phpgwaccountstatus', 'phpgwaccounttype', 'phpgwaccountexpires' )
+		);
 		$info = ldap_get_entries( $ldap, $sr );
 		$tmp = '';
@@ -121,7 +123,4 @@
 	);
 
-	//error_log( print_r( $config, true ), 3, '/tmp/log' );
-	//error_log( print_r( $group_info, true ), 3, '/tmp/log' );
-
 	if ( array_key_exists( 'submit', $_POST ) )
 	{
@@ -133,6 +132,4 @@
 			$groups = CreateObject( 'phpgwapi.accounts' );
 			copyobj( $GLOBALS[ 'phpgw_setup' ] -> db, $groups -> db );
-
-			//error_log( print_r( $_POST[ 'ldapgroups' ], true ), 3, '/tmp/log' );
 
 			foreach ( $_POST[ 'ldapgroups' ] as $groupid )
@@ -159,29 +156,22 @@
 					$groups->account_id = ( int ) $thisacctid;
 
-					$sr = ldap_search( $ldap, $config[ 'ldap_group_context' ], 'cn=' . $thisacctlid );
-					$entry = ldap_get_entries( $ldap, $sr );
-
-			//		error_log( print_r( $entry, true ), 3, '/tmp/log' );
-
-					reset( $entry[ 0 ][ 'objectclass' ] );
+					reset( $group_info[ $groupid ][ 'objectclass' ] );
 
 					$add = array( );
 
-					if ( ! in_array( 'phpgwAccount', $entry[ 0 ][ 'objectclass' ] ) )
+					if ( ! in_array( 'phpgwAccount', $group_info[ $groupid ][ 'objectclass' ] ) )
 						$add[ 'objectclass'] = array( 'phpgwAccount' );
 
-					if ( ! array_key_exists( 'phpgwaccountstatus', $entry[ 0 ] ) )
+					if ( ! array_key_exists( 'phpgwaccountstatus', $group_info[ $groupid ] ) )
 						$add[ 'phpgwaccountstatus'] = array( 'A' );
 
-					if ( ! array_key_exists( 'phpgwaccounttype', $entry[ 0 ] ) )
+					if ( ! array_key_exists( 'phpgwaccounttype', $group_info[ $groupid ] ) )
 						$add[ 'phpgwaccounttype' ] = array( 'g' );
 
-					if ( ! array_key_exists( 'phpgwaccountexpires', $entry[ 0 ] ) )
+					if ( ! array_key_exists( 'phpgwaccountexpires', $group_info[ $groupid ] ) )
 						$add[ 'phpgwaccountexpires' ] = array( -1 );
 
-			//		error_log( print_r( $add, true ), 3, '/tmp/log' );
-
-					//if ( count( $add ) )
-					//	ldap_mod_add( $ldap, $thisdn, $add );
+					if ( count( $add ) )
+						ldap_mod_add( $ldap, $thisdn, $add );
 
 					// Now make the members a member of this group in phpgw.
@@ -190,7 +180,4 @@
 						if ( array_key_exists( 'count', $thismembers ) )
 							unset( $thismembers[ 'count' ] );
-
-			//			error_log( print_r( $thismembers, true ), 3, '/tmp/log' );
-			//			error_log( print_r( $account_info, true ), 3, '/tmp/log' );
 
 						foreach ( $thismembers as $key => $members )
@@ -215,12 +202,12 @@
 								$acl -> account_id = ( int ) $tmpid;
 								$acl -> read_repository( );
-	
+
 								$acl -> delete( 'phpgw_group', $thisacctid, 1 );
 								$acl -> add( 'phpgw_group', $thisacctid, 1 );
-	
+
 								// Now add the acl to let them change their password
 								$acl -> delete( 'preferences', 'changepassword', 1 );
 								$acl -> add( 'preferences', 'changepassword', 1 );
-	
+
 								$acl -> save_repository( );
 							}
@@ -247,5 +234,5 @@
 		}
 
-		if ( array_key_exists( 'users', $_POST ) && is_array( $_POST[ 'users' ] ) )
+		if ( ( array_key_exists( 'users', $_POST ) && is_array( $_POST[ 'users' ] ) ) || ( array_key_exists( 'admins', $_POST ) && is_array( $_POST[ 'admins' ] ) ) )
 		{
 			$accounts = CreateObject( 'phpgwapi.accounts' );
@@ -258,74 +245,81 @@
 			//error_log( print_r( $config, true ), 3, '/tmp/log' );
 
-			foreach ( $_POST[ 'users' ] as $user_id )
-			{
-				$id_exist = 0;
-				$thisacctid  = $account_info[ $user_id ][ 'uidnumber' ][ 0 ];
-				$thisacctlid = $account_info[ $user_id ][ 'uid' ][ 0 ];
-				$thisdn      = $account_info[ $user_id ][ 'dn'];
-
-				echo "{$thisdn}<br>\nUpdating USERID : {$thisacctlid}<br>\n";
-				
-				// Do some checks before we try to import the data.
-				if ( !empty($thisacctid) && !empty($thisacctlid))
+			foreach ( array( 'admins', 'users' ) as $type )
+				if ( array_key_exists( $type, $_POST ) )
 				{
-					$users_process++;
-
-					//$res = ldap_search( $ldap, $config[ 'ldap_group_context' ], 'uid=' . $thisacctlid, array( 'uid', 'objectClass' ) );
-					//$entry = ldap_get_entries( $ldap, $res );
-
-					//error_log( print_r( $entry, true ), 3, '/tmp/log' );
-
-					//for ( $entry = ldap_first_entry( $ldap, $res ); $entry !== false, $arr = ldap_get_attributes( $ldap, $entry ); $entry = ldap_next_entry( $ldap, $entry ) )
-					//{
-					//	error_log( print_r( $arr, true ), 3, '/tmp/log' );
-					//}
-					//error_log( "---------------------------------------------------\n", 3, '/tmp/log' );
-
-					//error_log( print_r( $account_info[ $user_id ], true ), 3, '/tmp/log' );
-					//error_log( "---------------------------------------------------\n", 3, '/tmp/log' );
-
-					$add = array( );
-					$objectClass = array( );
-
-					if ( ! in_array( 'qmailUser', $account_info[ $user_id ][ 'objectclass' ] ) )
-						$objectclass[ ] = 'qmailUser';
-
-					if ( ! in_array( 'phpgwAccount', $account_info[ $user_id ][ 'objectclass' ] ) )
+					if ( $type == 'admins' )
 					{
-						$objectclass[ ] = 'phpgwAccount';
-						$add[ 'phpgwAccountExpires' ] = array( '-1' );
-						$add[ 'phpgwAccountStatus' ] = array( 'A' );
-						$add[ 'phpgwAccountType' ] = array( 'u' );
-						$add[ 'phpgwLastPasswdChange' ] = array( '1290632486' );
+						// give admin access to all apps, to save us some support requests
+						$all_apps = array();
+						$GLOBALS[ 'phpgw_setup' ] -> db -> query( 'SELECT app_name FROM phpgw_applications ORDER BY app_name' );
+						while ( $GLOBALS[ 'phpgw_setup' ] -> db -> next_record( ) )
+							$all_apps[ ] = $GLOBALS[ 'phpgw_setup' ]  -> db -> f( 'app_name' );
 					}
 
-					if ( count( $objectclass ) )
-						$add[ 'objectclass' ] = $objectclass;
-
-					if ( count( $add ) )
-						ldap_mod_add( $ldap, $thisdn, $add );
-
-					$accounts -> account_id = ( int ) $thisacctid;
-					
-					// Insert default acls for this user.
-					$acl -> account_id = ( int ) $thisacctid;
-					$acl -> read_repository( );
-	
-					// Now add the acl to let them change their password
-					$acl -> delete( 'preferences', 'changepassword', 1 );
-					$acl -> add( 'preferences', 'changepassword', 1 );
-
-					// Add user to a default group, previous created
-					$acl -> add( 'phpgw_group', '12007', 1 );
-
-					echo "Adding in ACL BD: {$thisacctid}<br><br>\n";
-
-					// Save these new acls.
-					$acl -> save_repository( );
-						
-					$new_uidnumber++;
+					foreach ( $_POST[ $type ] as $user_id )
+					{
+						$id_exist = 0;
+						$thisacctid  = $account_info[ $user_id ][ 'uidnumber' ][ 0 ];
+						$thisacctlid = $account_info[ $user_id ][ 'uid' ][ 0 ];
+						$thisdn      = $account_info[ $user_id ][ 'dn'];
+
+						echo "{$thisdn}<br>\nUpdating ({$type}) USERID : {$thisacctlid}<br>\n";
+
+						// Do some checks before we try to import the data.
+						if ( !empty($thisacctid) && !empty($thisacctlid))
+						{
+							$users_process++;
+
+							$add = array( );
+							$objectClass = array( );
+
+							if ( ! in_array( 'qmailUser', $account_info[ $user_id ][ 'objectclass' ] ) )
+								$objectclass[ ] = 'qmailUser';
+
+							if ( ! in_array( 'phpgwAccount', $account_info[ $user_id ][ 'objectclass' ] ) )
+							{
+								$objectclass[ ] = 'phpgwAccount';
+								$add[ 'phpgwAccountExpires' ] = array( '-1' );
+								$add[ 'phpgwAccountStatus' ] = array( 'A' );
+								$add[ 'phpgwAccountType' ] = array( 'u' );
+								$add[ 'phpgwLastPasswdChange' ] = array( '1290632486' );
+							}
+
+							if ( count( $objectclass ) )
+								$add[ 'objectclass' ] = $objectclass;
+
+							if ( count( $add ) )
+								ldap_mod_add( $ldap, $thisdn, $add );
+
+							$accounts -> account_id = ( int ) $thisacctid;
+
+							// Insert default acls for this user.
+							$acl -> account_id = ( int ) $thisacctid;
+							$acl -> read_repository( );
+
+							// Now add the acl to let them change their password
+							$acl -> delete( 'preferences', 'changepassword', 1 );
+							$acl -> add( 'preferences', 'changepassword', 1 );
+
+							// Add user to a default group, previous created
+							//$acl -> add( 'phpgw_group', '12007', 1 );
+
+							echo "Adding in ACL BD: {$thisacctid}<br><br>\n";
+
+							// Save these new acls.
+							$acl -> save_repository( );
+
+							$new_uidnumber++;
+						}
+
+						if ( $type == 'admins' )
+						{
+							$GLOBALS[ 'phpgw_setup' ] -> add_acl(array( 'admin', 'expressoAdmin1_2' ), 'run', ( int ) $thisacctid );
+							$GLOBALS[ 'phpgw_setup' ] -> db -> query( "INSERT INTO phpgw_expressoadmin VALUES ( '{$thisacctlid}', '{$config[ 'ldap_context' ]}', 2199023253495 )" );
+							foreach ( $all_apps as $app )
+								$GLOBALS[ 'phpgw_setup' ] -> db -> query( "INSERT INTO phpgw_expressoadmin_apps VALUES ( '{$thisacctlid}', '{$config[ 'ldap_context' ]}', '{$app}' )" );
+						}
+					}
 				}
-			}
 		}
 
