Index: controlies/Plugins/Groups.py
===================================================================
--- controlies/Plugins/Groups.py	(revision 68)
+++ controlies/Plugins/Groups.py	(revision 69)
@@ -34,23 +34,25 @@
     def __init__(self):
 		pass
 	
-    def __init__(self,ldap,name,gidNumber):
+    def __init__(self,ldap,type,name):
 		self.ldap = ldap
+		self.type = type
 		self.name = name
-		self.gidNumber = gidNumber
 				
-    def validation(self):
+    def validation(self,action):
+
+		if action == "add":
+			if self.type == "none":
+				return "type"
+				
 		if self.name == "":
 			return "name"
-
-		if self.gidNumber == "":
-			return "gidNumber"
 		
 		return "OK"
 
     def process(self,action):
 		if action == "add":
-			val = self.validation()
+			val = self.validation(action)
 			
 			if val != "OK":
 				return val
@@ -59,21 +61,13 @@
 				return response
 
 		if action == "modify":
-			val = self.validation()
+			val = self.validation(action)
 			
 			if val != "OK":
 				return val
 			else:
 				response = self.modify()
-				return response
-				
-		if action == "delete":
-			response = self.delete()
-			return response
-		
-		if action == "list":
-			response = self.list();
-			return response	
+				return response		
 			
     def list(self,args):
 
@@ -111,7 +105,7 @@
 			
 			if searchType == typeRow or searchType=="none":
 				row = {
-					"id":i[0][0], 
+					"id":i[0][1]["cn"][0], 
 					"cell":[typeRow, i[0][1]["cn"][0], i[0][1]["gidNumber"][0]],
 					"type": typeRow,
 					"cn": i[0][1]["cn"][0],
@@ -166,18 +160,20 @@
 		
 
     def add(self):
-		record = [
-		('objectclass', ['person','organizationalperson','inetorgperson']),
-		('uid', ['francis']),
+		maxID = str(self.getMaxID())
+
+		attr = [
+		('objectclass', ['top','posixGroup','lisGroup','lisAclGroup']),
+		#('objectclass', ['top','posixGroup','lisGroup']),
+		('grouptype', [self.type] ),		
+		('gidnumber', [maxID] ),		
 		('cn', [self.name] ),
-		('sn', ['Bacon'] ),
-		('userpassword', [self.password]),
-		('ou', ['users'])
+		('description', [self.name+' department group']),
+		('memberuid', ['manuprofe']),
+		('member', ['uid=manuprofe,ou=People,dc=instituto,dc=extremadura,dc=es'])
 		]
-		try:
-			self.ldap.add("cn=Groups", record)
-		except ldap.ALREADY_EXISTS:
-			return "fail"
+
+		self.ldap.add("cn="+self.name+",ou=Group", attr)
 		
 		return "OK"
 			
@@ -186,7 +182,27 @@
 		(ldap.MOD_ADD, 'description', 'Author of New Organon'),
 		(ldap.MOD_ADD, 'description', 'British empiricist') 
 		]
-		self.ldap.modify_s('uid='+ uid +',cn=Groups', mod_attrs)
+		self.ldap.modify_s('uid='+ uid +',ou=Group', mod_attrs)
 
-    def delete(self,uid):
-		self.ldap.delete('uid='+ uid +',cn=Groups')
+    def delete(self):
+		self.ldap.delete('cn='+ self.name +',ou=Group')
+
+
+    def getMaxID(self): # find the maximum ID
+		result = self.ldap.search("ou=Group","cn=*",["gidNumber"])		
+		numbers = []
+		for i in result:
+			numbers.append(int(i[0][1]['gidNumber'][0]))
+
+		result = self.ldap.search("ou=People","uid=*",["gidNumber","uidNumber"])		
+		for i in result:
+			numbers.append(int(i[0][1]['gidNumber'][0]))
+			numbers.append(int(i[0][1]['uidNumber'][0]))
+
+		numbers.sort()		
+		
+		maxID = 1		
+		if len(numbers) > 0:
+			maxID = numbers[len(numbers)-1] + 1
+
+		return maxID
Index: controlies/Plugins/Users.py
===================================================================
--- controlies/Plugins/Users.py	(revision 68)
+++ controlies/Plugins/Users.py	(revision 69)
@@ -106,10 +106,6 @@
 			else:
 				response = self.modify()
 				return response
-				
-		if action == "delete":
-			response = self.delete()
-			return response
 		
 			
     def list(self,args):
@@ -226,7 +222,6 @@
 
 		self.ldap.add("uid="+self.user+",ou=People", attr)
 
-
 		# Add private group
 		attr = [
 		('objectclass', ['top','posixGroup','lisGroup']),
Index: controlies/www/index.html
===================================================================
--- controlies/www/index.html	(revision 68)
+++ controlies/www/index.html	(revision 69)
@@ -59,7 +59,7 @@
 		<div id="tabs-1">
 			<img src="img/unlock.png" style="float:right;"/>
 			<form id="form_authentication" onSubmit="return authentication();">
-				<p><span id="hostTag">LDAP</span><br><input type="text" id="host" name="host" value="172.23.36.5"></p>
+				<p><span id="hostTag">LDAP</span><br><input type="text" id="host" name="host" value="172.23.36.8"></p>
 				<p><span id="userTag">Nombre</span><br><input type="text" id="user" name="user" value="admin"></p>
 				<p><span id="passwordTag">Contrase&ntilde;a</span><br><input type="password" id="password" name="password"></p><br>
 				<div id="message" style="text-align:center; font-weight:bold; color:red; "></div>
Index: controlies/www/groups/form.html
===================================================================
--- controlies/www/groups/form.html	(revision 68)
+++ controlies/www/groups/form.html	(revision 69)
@@ -17,7 +17,7 @@
 
 		restartStyle();
 
-		$.post('users', $("#form_data").serialize(), function(data) {
+		$.post('groups', $("#form_data").serialize(), function(data) {
 			var result = $.parseJSON(data);
 
 			switch(result.response){
@@ -24,6 +24,7 @@
 				case "OK":{
 					$('#message').html("Operación realizada correctamente").css("color","green").effect("highlight", {"color":"yellow"}, 1000);
 					setTimeout("$('#dialog-form').dialog('close')",1000);
+					$("#list").trigger("reloadGrid");
 					break;
 				}
 				case "fail":{
@@ -30,12 +31,6 @@
 					$('#message').html("Se produjo un error").effect("highlight", {"color":"yellow"}, 1000);
 					break;
 				}
-				case "distinctPassword":{
-					$('#password2Tag').css("color","red");
-					$('#password2').effect("highlight", {"color":"yellow"}, 1000).focus();
-					$('#message').html("La repetición no coincide").effect("highlight", {"color":"yellow"}, 1000);
-					break;
-				}
 				default:{
 					$('#'+result.response+"Tag").css("color","red");
 					$('#'+result.response).effect("highlight", {"color":"yellow"}, 1000).focus();
@@ -51,11 +46,14 @@
 
 <form id="form_data" onSubmit="return send();">
 	<input type="hidden" id="action" name="action"/>
-	<input type="hidden" id="id" name="id"/>
-	<p><span id="nameTag">Nombre y Apellidos</span><br><input type="text" id="name" name="name"/></p>
-	<p><span id="nifTag">NIF</span><br><input type="text" id="nif" name="nif"/></p>
-	<p><span id="passwordTag">Contraseña</span><br><input type="text" id="password" name="password"/></p>
-	<p><span id="password2Tag">Repita Contraseña</span><br><input type="text" id="password2" name="password2"/></p>
+	<p><span id="typeTag">Tipo Grupo</span><br>
+		<select type="text" id="type" name="type">
+			<option value="none">Seleccione...</option>
+			<option value="school_department">Departamento</option>
+			<option value="school_classroom">Curso</option>
+		</select>
+	</p>	
+	<p><span id="nameTag">Nombre </span><br><input type="text" id="name" name="name"/></p>
 	<div id="message" style="text-align:center; font-weight:bold; color:red; padding:3px; "></div>
 	<div style="text-align:center;"><button id="saveButton" type="submit" style="width:100px;">Guardar</button>&nbsp;&nbsp;<button type="button" id="cancelButton" style="width:100px;">Cancelar</button></div>
 </form>
Index: controlies/www/groups/index.html
===================================================================
--- controlies/www/groups/index.html	(revision 68)
+++ controlies/www/groups/index.html	(revision 69)
@@ -20,7 +20,7 @@
 					datatype: "json", 
 					colNames:['Tipo Grupo','Nombre','ID Grupo'],
 					colModel:[
-						{name:'type',index:'type', width:60, align:"center",  stype:'select', editoptions:{value:":Todo;Departamento:Departamentos;Aula:Aulas"}},										 
+						{name:'type',index:'type', width:60, align:"center",  stype:'select', editoptions:{value:":Todo;Departamento:Departamentos;Curso:Cursos"}},										 
 						{name:'cn',index:'cn', width:80, align:"center"},
 						{name:'gidNumber',index:'gidNumber', width:60, align:"center"}
 					], 
@@ -41,7 +41,7 @@
 					caption: "Insertar",
 					buttonicon :'ui-icon-plus',
 					onClickButton : function (){ 
-						handleRecord('add','Añadir Usuario');
+						addRecord();
 					} 
 				}); 
 				$("#list").jqGrid('navButtonAdd','#pager',{
@@ -48,7 +48,7 @@
 					caption: "Modificar", 
 					buttonicon :'ui-icon-pencil',
 					onClickButton : function (){ 
-						handleRecord('modify','Modificar Usuario');
+						modifyRecord();
 					} 
 				}); 
 				$("#list").jqGrid('navButtonAdd','#pager',{
@@ -78,35 +78,85 @@
 				return id;
 			}
 			
-			function handleRecord(action,title){
-				var id;
+			function addRecord(){
+
+				$("#dialog-form").html("");
+				$("#dialog-form").load("groups/form.html", function() {
+					$("#form_data #action").val("add");
+					$("#form_data #messageForm").html("Todos los campos son obligatorios");					
+				});
+
+				x = ($(window).width()-250)/2;
+				y = ($(window).height()-400)/2;
+
+				$("#dialog-form").dialog({
+					resizable: false,
+					position: top,
+					modal: true,
+					title: "Añadir Grupo"
+				}).dialog('option', 'position', [x, y]);
+			}
+
+			function modifyRecord(){
+				var uid;
 				
-				if(action=="modify"){
-					var id = rowSelected();
-					if(id==false)
-						return false;
-				}
+				var uid = rowSelected();
+				if(uid==false)
+					return false;
 
+				$("#dialog-form").html("");
+				$("#dialog-form").load("groups/form.html", function() {
+					
+					getAllGroups();
+					
+					$("#form_data #action").val("modify");
+					$("#form_data #user").attr("readonly","true");
+					$("#form_data #user").css("background-color","#DDD");
+					$("#form_data #messageForm").html("Todos los campos son obligatorios");					
+					
+					$.post('users', 'action=getUserData&user='+uid, function(data) {
+						var result = $.parseJSON(data);
+
+						if(result.response['type']=="teacher")
+							var textType = "Profesor";
+						else
+							var textType = "Alumno";
+							
+						var dep = Array(result.response['groups']['departments']);
+
+						$("#form_data #type").replaceWith(textType+"<input type='hidden' id='type' name='type' value='"+result.response['type']+"'/>");
+						$("#form_data #name").val(result.response['name']);
+						$("#form_data #nif").val(result.response['nif']);		
+						$("#form_data #user").val(result.response['user']);
+						$("#form_data #surname").val(result.response['surname']);
+
+						$.each(result.response['groups']['departments'], function(i, l){
+							$('#form_data input:checkbox[value='+l+']').attr('checked', true);							
+						});
+
+						$.each(result.response['groups']['classrooms'], function(i, l){
+							$('#form_data input:checkbox[value='+l+']').attr('checked', true);							
+						});						
+					});				  
+				});
+
+				x = ($(window).width()-300)/2;
+				y = ($(window).height()-500)/2;
 				
 				$("#dialog-form").dialog({
 					resizable: false,
 					modal: true,
-					title: title,
-					open: function(event, ui) {
-						$("#dialog-form").html("");
-						$("#dialog-form").load("users/form.html", function() {
-						  $("#form_data #action").val(action);
-						  $("#form_data #id").val(id);
-						});
-					}
-				});
+					width: 300,
+					title: "Modificar Grupo"
+				}).dialog('option', 'position', [x, y]);
 			}
+
 			function deleteRecord(){
 				
 				var id = rowSelected();
 				if(id==false)
 					return false;
-			
+
 				$( "#dialog-confirm" ).dialog({
 					resizable: false,
 					height:160,
@@ -114,13 +164,13 @@
 					modal: true,
 					buttons: {
 						"Borrar": function() {
-							$.post("users","idUser="+id+"&action=delete", function(data){
-								$( this ).dialog( "close" );
+							$.post("groups","name="+id+"&action=delete", function(data){
+								$("#dialog-confirm").dialog( "close" );
 								$("#list").trigger("reloadGrid");
 							});
 						},
 						"Cancelar": function() {
-							$( this ).dialog( "close" );
+							$(this).dialog( "close" );
 						}
 					}
 				}).dialog('open');
Index: controlies/MainLoop.py
===================================================================
--- controlies/MainLoop.py	(revision 68)
+++ controlies/MainLoop.py	(revision 69)
@@ -151,12 +151,19 @@
 				g = Groups(l,"","")
 				response = g.list(request.args)
 				return json.dumps(response)
+				
         	elif request.args['action'][0] == "getAllGroups":
 				g = Groups(l,"","")
 				response = g.getAllGroups()
 				return json.dumps(response)				
+
+        	elif request.args['action'][0] == "delete":
+				g = Groups(l,"",request.args['name'][0])
+				response = g.delete()
+				return json.dumps({"response" : response})
+				
         	else:
-				g = Groups(l,request.args['name'][0],request.args['gid'][0])
+				g = Groups(l,request.args['type'][0],request.args['name'][0])
 				response = g.process(request.args['action'][0])
 				return json.dumps({"response" : response})
 				
