Index: controlies/Plugins/Users.py
===================================================================
--- controlies/Plugins/Users.py	(revision 63)
+++ controlies/Plugins/Users.py	(revision 64)
@@ -207,7 +207,7 @@
 
     def add(self):
 
-		maxID = str(self.getMaxID(l))
+		maxID = str(self.getMaxID())
 		passwd = hashlib.sha1(self.password).hexdigest()
 		
 		attr = [
@@ -225,7 +225,32 @@
 		]
 
 		self.ldap.add("uid="+self.user+",ou=People", attr)
+
+
+		# Add private group
+		attr = [
+		('objectclass', ['top','posixGroup','lisGroup']),
+		('grouptype', ['private']),	
+		('gidnumber', [maxID] ),	
+		('cn', [self.user] ),
+		('description', [self.name+' personal group'] )
+		]
+
+		self.ldap.add("cn="+self.user+",ou=Group", attr)
 		
+		
+		# Add selected groups	
+		attr = [
+		(ldap.MOD_ADD, 'member', ['uid='+self.user+',ou=People,dc=instituto,dc=extremadura,dc=es'] ),
+		(ldap.MOD_ADD, 'memberUid', [self.user] )
+		]
+
+		for n in self.departments:
+			self.ldap.modify('cn='+ n +',ou=Group', attr)
+
+		for n in self.classrooms:
+			self.ldap.modify('cn='+ n +',ou=Group', attr)
+						
 		return "OK"
 			
 			
@@ -240,34 +265,69 @@
 		(ldap.MOD_REPLACE, 'userpassword', [passwd])
 		]
 
-		#self.ldap.modify("uid="+self.user+",ou=People", attr)
+		self.ldap.modify("uid="+self.user+",ou=People", attr)
 
-		#Modify groups
+		# Get current groups
 		currentGroups = self.getUserGroups()
 		
 		#sameGroups = set(currentGroups["departments"]) & set(self.departments)
-		deleteGroups = set(currentGroups["departments"]).difference(set(self.departments))
-
+		
+		# Delete unselected groups		
+		deleteDepartments = set(currentGroups["departments"]).difference(set(self.departments))
+		deleteClassrooms = set(currentGroups["classrooms"]).difference(set(self.classrooms))
+		
 		attr = [
 		(ldap.MOD_DELETE, 'member', ['uid='+self.user+',ou=People,dc=instituto,dc=extremadura,dc=es'] ),
 		(ldap.MOD_DELETE, 'memberUid', [self.user] )
 		]
 
-		for d in deleteGroups:
-			self.ldap.delete('cn='+ d +',ou=Group')
-			
-		newGroups = set(self.departments).difference(currentGroups["departments"])
+		for d in deleteDepartments:
+			self.ldap.modify('cn='+ d +',ou=Group', attr)
+
+		for d in deleteClassrooms:
+			self.ldap.modify('cn='+ d +',ou=Group', attr)
+					
+		# Add selected groups	
+		newDepartments = set(self.departments).difference(currentGroups["departments"])
+		newClassrooms = set(self.classrooms).difference(currentGroups["classrooms"])
 		
-		#print deleteGroups
-		#print newGroups
+		attr = [
+		(ldap.MOD_ADD, 'member', ['uid='+self.user+',ou=People,dc=instituto,dc=extremadura,dc=es'] ),
+		(ldap.MOD_ADD, 'memberUid', [self.user] )
+		]
+
+		for n in newDepartments:
+			self.ldap.modify('cn='+ n +',ou=Group', attr)
+
+		for n in newClassrooms:
+			self.ldap.modify('cn='+ n +',ou=Group', attr)
+					
 		return "OK"
 
+
     def delete(self):
 		
 		self.ldap.delete('uid='+ self.user +',ou=People')
+		self.ldap.delete("cn="+self.user+",ou=Group")
+		
+		# Delete unselected groups		
+		currentGroups = self.getUserGroups()
 
+		attr = [
+		(ldap.MOD_DELETE, 'member', ['uid='+self.user+',ou=People,dc=instituto,dc=extremadura,dc=es'] ),
+		(ldap.MOD_DELETE, 'memberUid', [self.user] )
+		]
 
-    def getMaxID(self,l): # find the maximum ID
+		for d in currentGroups["departments"]:
+			self.ldap.modify('cn='+ d +',ou=Group', attr)
+
+		for d in currentGroups["classrooms"]:
+			self.ldap.modify('cn='+ d +',ou=Group', attr)
+			
+		return "OK"
+
+
+    def getMaxID(self): # find the maximum ID
 		result = self.ldap.search("ou=Group","cn=*",["gidNumber"])		
 		numbers = []
 		for i in result:
Index: controlies/www/users/index.html
===================================================================
--- controlies/www/users/index.html	(revision 63)
+++ controlies/www/users/index.html	(revision 64)
@@ -85,6 +85,7 @@
 
 				$("#dialog-form").html("");
 				$("#dialog-form").load("users/form.html", function() {
+					getAllGroups();
 					$("#form_data #action").val("add");
 					$("#form_data #messageForm").html("Todos los campos son obligatorios");					
 				});
@@ -110,18 +111,7 @@
 				$("#dialog-form").html("");
 				$("#dialog-form").load("users/form.html", function() {
 					
-					$.post('groups','action=getAllGroups', function(data) {
-						var groups = $.parseJSON(data);					
-						
-						$.each( groups.departments, function(i, l){
-							$("#form_data #departments").append("<option value='"+l+"'>"+l+"</option>");
-						 });
-						$.each( groups.classrooms, function(i, l){
-							$("#form_data #classrooms").append("<option value='"+l+"'>"+l+"</option>");
-						 });						 
-						$("#form_data #departments").multiselect(); 
-						$("#form_data #classrooms").multiselect(); 						 
-					});
+					getAllGroups();
 					
 					$("#form_data #action").val("modify");
 					$("#form_data #user").attr("readonly","true");
@@ -189,6 +179,21 @@
 					}
 				}).dialog('open');
 			}
+			
+			function getAllGroups(){
+				$.post('groups','action=getAllGroups', function(data) {
+					var groups = $.parseJSON(data);					
+					
+					$.each( groups.departments, function(i, l){
+						$("#form_data #departments").append("<option value='"+l+"'>"+l+"</option>");
+					 });
+					$.each( groups.classrooms, function(i, l){
+						$("#form_data #classrooms").append("<option value='"+l+"'>"+l+"</option>");
+					 });						 
+					$("#form_data #departments").multiselect(); 
+					$("#form_data #classrooms").multiselect(); 						 
+				});				
+			}
 		</script>
 
 		<div id="tabla_clientes">
