Index: controlies/trunk/applications/controlies/controllers/laptops.py
===================================================================
--- controlies/trunk/applications/controlies/controllers/laptops.py	(revision 365)
+++ controlies/trunk/applications/controlies/controllers/laptops.py	(revision 366)
@@ -64,7 +64,7 @@
 @auth.requires_login()    
 def modifyHistory():
     my = SQLiteConnection()
-    l = LaptopsHistory(my,"",request.vars["id_laptop"],request.vars["id_state"],request.vars["id_user_type"],request.vars["nif"],request.vars["username"],request.vars["name"],request.vars["comment"])
+    l = LaptopsHistory(my,request.vars["id_historical"],request.vars["id_laptop"],request.vars["id_state"],request.vars["id_user_type"],request.vars["nif"],request.vars["username"],request.vars["name"],request.vars["comment"])
     response = l.process(request.vars["action"])
     return dict(response = response)   
 
Index: controlies/trunk/applications/controlies/modules/Users.py
===================================================================
--- controlies/trunk/applications/controlies/modules/Users.py	(revision 365)
+++ controlies/trunk/applications/controlies/modules/Users.py	(revision 366)
@@ -136,30 +136,31 @@
 
         # type of user (Teacher/Student)
         try:
-            searchType = args['type']
+            searchType = str(args['type'])
         except LookupError:
-            searchType = "none"
+            searchType = "None"
 
         rows = []
         for i in search:
-            
             typeRow="Alumno"
             userdata=i[0][1]
             if userdata["homeDirectory"][0][0:14]=="/home/profesor":
                 typeRow="Profesor"
+                
             if not "employeeNumber" in userdata: userdata["employeeNumber"]=["0"]
-            if searchType == typeRow or searchType=="none":
+
+            if searchType == typeRow or searchType=="None":
                 row = {
-                    "id":userdata["uid"][0], 
-                    "cell":[typeRow, userdata["cn"][0], userdata["uid"][0], userdata["uidNumber"][0], userdata["gidNumber"][0], userdata["employeeNumber"][0]], 
+                    "id":str(userdata["uid"][0]), 
+                    "cell":[typeRow, str(userdata["cn"][0]), str(userdata["uid"][0]), str(userdata["uidNumber"][0]), str(userdata["gidNumber"][0]), str(userdata["employeeNumber"][0])], 
                     "type": typeRow,                    
-                    "cn":userdata["cn"][0],
-                    "uidNumber":userdata["uidNumber"][0],
-                    "gidNumber":userdata["gidNumber"][0],                
-                    "employeeNumber":userdata["employeeNumber"][0]
+                    "cn":str(userdata["cn"][0]),
+                    "uidNumber":str(userdata["uidNumber"][0]),
+                    "gidNumber":str(userdata["gidNumber"][0]),                
+                    "employeeNumber":str(userdata["employeeNumber"][0])
                 }
                 rows.append(row)
-                    
+   
         # grid parameters
         if len(rows) > 0:
             totalPages = floor( len(rows) / int(limit) )
@@ -394,7 +395,7 @@
         return searching
 
     def getUserGroups(self):
-        result = self.ldap.search("ou=Group","(&(memberUid="+self.user+")(|(groupType=school_department)(groupType=school_class)))",["cn","groupType"])
+        result = self.ldap.search("ou=Group","(&(memberUid="+str(self.user)+")(|(groupType=school_department)(groupType=school_class)))",["cn","groupType"])
 
         departments = []
         classrooms = []     
@@ -410,7 +411,7 @@
         
     def getUserData(self):
         self.getUserGroups()
-        result = self.ldap.search("ou=People","uid="+self.user,["uid","cn","sn","employeenumber","homedirectory","uidnumber","gidnumber","jpegPhoto"])
+        result = self.ldap.search("ou=People","uid="+str(self.user),["uid","cn","sn","employeenumber","homedirectory","uidnumber","gidnumber","jpegPhoto"])
         
         if len(result) == 0:
             return { "user":"", "name":"", "surname":"", "nif":"", "photo":"", "type":"","uidnumber":"","gidnumber":"", "groups":[] }
Index: controlies/trunk/applications/controlies/modules/LaptopsHistory.py
===================================================================
--- controlies/trunk/applications/controlies/modules/LaptopsHistory.py	(revision 365)
+++ controlies/trunk/applications/controlies/modules/LaptopsHistory.py	(revision 366)
@@ -32,14 +32,14 @@
     
     def __init__(self,SQLite,id_historical,id_laptop,id_state,id_user_type,nif,username,name,comment):
         self.SQLite = SQLite
-        self.id_historical = id_historical        
-        self.id_laptop = id_laptop
-        self.id_state = id_state
-        self.id_user_type = id_user_type
-        self.nif = nif
-        self.username = username
-        self.name = name
-        self.comment = comment
+        self.id_historical = str(id_historical)        
+        self.id_laptop = str(id_laptop)
+        self.id_state = str(id_state)
+        self.id_user_type = str(id_user_type)
+        self.nif = str(nif)
+        self.username = str(username)
+        self.name = str(name)
+        self.comment = str(comment)
         
     def validation(self,action):
 
@@ -131,9 +131,8 @@
             
             
     def modify(self):
-        sql = "UPDATE laptops SET serial_number='"+self.serial_number+"', id_trademark='"+self.id_trademark+"' "
-        sql = sql + "WHERE id_laptop='"+str(self.id_laptop)+"'"
-
+        sql = "UPDATE laptops_historical SET username='"+self.username+"', name='"+self.name+"', id_user_type='"+self.id_user_type+"', nif='"+self.nif+"', comment='"+self.comment+"', id_state='"+self.id_state+"' "
+        sql = sql + "WHERE id_historical='"+str(self.id_historical)+"'"
         db = self.SQLite.getDB()
         result = db.executesql(sql)
                     
@@ -208,4 +207,17 @@
                 "id_state":str(result[0][1])
             }
 
-        return data
\ No newline at end of file
+        return data
+    
+    def userAssignment(self):
+        sql="SELECT lh.id_laptop, lh.username FROM laptops l, laptops_historical lh"
+        sql=sql+" WHERE l.id_laptop=lh.id_laptop"
+        sql=sql+" GROUP BY l.id_laptop ORDER BY lh.datetime desc"
+        db = self.SQLite.getDB()
+        result = db.executesql(sql)
+
+        for r in result:
+            if str(r[1])==self.username:
+                return str(r[0])
+                    
+        return False
\ No newline at end of file
Index: controlies/trunk/applications/controlies/modules/Utils/LdapUtils.py
===================================================================
--- controlies/trunk/applications/controlies/modules/Utils/LdapUtils.py	(revision 365)
+++ controlies/trunk/applications/controlies/modules/Utils/LdapUtils.py	(revision 366)
@@ -53,6 +53,17 @@
 	
 	return { "departments":departments, "classrooms":classrooms }
 
+def getClassroomGroups(ldap):
+	result = ldap.search("ou=Group","(|(groupType=school_class))",["cn","groupType"])
+	
+	classrooms = []		
+	for g in result:
+		classrooms.append(g[0][1]["cn"][0])
+	
+	classrooms.sort()
+	
+	return { "classrooms":classrooms }
+
 def getAllRanges(ldap):
 	myRange = []
 	mySubRange = []	
Index: controlies/trunk/applications/controlies/modules/Groups.py
===================================================================
--- controlies/trunk/applications/controlies/modules/Groups.py	(revision 365)
+++ controlies/trunk/applications/controlies/modules/Groups.py	(revision 366)
@@ -83,7 +83,6 @@
 				return response		
 			
     def list(self,args):
-
 		filter = self.buildFilter(args)		
 		search = self.ldap.search("ou=Group",filter,["cn","gidNumber","groupType","memberUid"])
 
@@ -105,19 +104,18 @@
 
 		# type of group (Classroom/Department)
 		try:
-			searchType = args['type']
+			searchType = str(args['type'])
 		except LookupError:
-			searchType = "none"
+			searchType = "None"
 
 		rows = []
 		for i in search:
 			
 			typeRow="Aula"
-			if i[0][1]["groupType"][0]=="school_department":
+			if str(i[0][1]["groupType"][0])=="school_department":
 				typeRow="Departamento"
-			
-			if searchType == typeRow or searchType=="none":
-				
+
+			if searchType == typeRow or searchType=="None":
 				try:
 					usersNumber = len(i[0][1]["memberUid"])
 				except:
@@ -154,7 +152,6 @@
 
     def listUsers(self,args):
 		from applications.controlies.modules.Users import Users
-		
 		# grid parameters
 		limit = int(args['rows'])
 		page = int(args['page'])
@@ -175,9 +172,9 @@
 
 		rows = []
 		for i in groupData["memberuid"]:
+
 			u = Users(self.ldap,"","","","",i,"","","","")
 			userData = u.getUserData()
-
 			row = {
 				"id":userData["user"], 
 				"cell":[userData["name"],userData["user"],userData["nif"]],
@@ -186,7 +183,6 @@
 				"employeeNumber": userData["nif"]
 			}
 			rows.append(row)			
-								
 			
 		if len(rows) > 0:
 			totalPages = floor( len(rows) / int(limit) )
@@ -202,26 +198,31 @@
 
 		# sort rows
 		result = sorted(rows, key=itemgetter(sortBy), reverse=reverseSort)
-
 		return { "page":page, "total":totalPages, "records":len(groupData["memberuid"]), "rows":result[start:finish] }
 
 
 
     def buildFilter(self, args):
-		filter = "(&(cn=*)(|(groupType=school_class)(groupType=school_department))"
-		
-		try:
-			filter = filter + "(cn=*" + args['cn'] + "*)"
-		except LookupError:
-			pass
+        
+        if self.type=="":
+            filter = "(&(cn=*)(|(groupType=school_class)(groupType=school_department))"
+        else:
+            filter = "(&(cn=*)(|(groupType="+str(self.type)+"))"
 
-		try:
-			filter = filter + "(gidNumber=" + args['gidNumber'] + ")"
-		except LookupError:
-			pass
+        try:
+            if str(args['cn'])!="None":
+			filter = filter + "(cn=*" + str(args['cn']) + "*)"
+        except LookupError:
+            pass
 
-		filter = filter + ")"
-		return filter
+        try:
+            if str(args['gidNumber'])!="None":
+			filter = filter + "(gidNumber=" + str(args['gidNumber']) + ")"
+        except LookupError:
+            pass
+
+        filter = filter + ")"
+        return filter
 		
 
     def add(self):
Index: controlies/trunk/applications/controlies/modules/Laptops.py
===================================================================
--- controlies/trunk/applications/controlies/modules/Laptops.py	(revision 365)
+++ controlies/trunk/applications/controlies/modules/Laptops.py	(revision 366)
@@ -157,7 +157,6 @@
     def add(self):
         sql = "INSERT INTO laptops (id_laptop, serial_number, id_trademark) "
         sql = sql + "VALUES(null,'"+self.serial_number+"','"+self.id_trademark+"')"
-
         db = self.SQLite.getDB()
         result = db.executesql(sql)
         
@@ -224,3 +223,10 @@
             }
             data.append(dataType)
         return data
+
+    def getMaxId(self):
+        sql="SELECT max(id_laptop) AS max FROM laptops"
+        db = self.SQLite.getDB()
+        result = db.executesql(sql)
+
+        return str(result[0][0])
\ No newline at end of file
Index: controlies/trunk/applications/controlies/models/menu.py
===================================================================
--- controlies/trunk/applications/controlies/models/menu.py	(revision 365)
+++ controlies/trunk/applications/controlies/models/menu.py	(revision 366)
@@ -49,6 +49,7 @@
 
 response.menu+=[('BD Portátiles', False, None,[            
             ('Portátiles', False,URL( 'laptops', 'index')),
+            ('Grupos', False,URL( 'laptops_groups', 'index')),
             ('Marcas', False,URL( 'laptops_trademarks', 'index')),   
             ]
    )]
Index: controlies/trunk/applications/controlies/views/laptops/history.html
===================================================================
--- controlies/trunk/applications/controlies/views/laptops/history.html	(revision 365)
+++ controlies/trunk/applications/controlies/views/laptops/history.html	(revision 366)
@@ -127,8 +127,8 @@
 			
 			jQuery.post('call/json/getDataHistory',{ id_historical: id }, function(result) {
 
+				jQuery("#form_data_history #id_historical").val(id);
 				jQuery("#form_data_history #id_state").val(result.response['id_state']);				
-				jQuery("#form_data_history #id_historical").val(result.response['id_historical']);
 				jQuery("#form_data_history #id_laptop").val(result.response['id_laptop']);
 				jQuery("#form_data_history #username").val(result.response['username']);
 				jQuery("#form_data_history #id_user_type").val(result.response['id_user_type']);	
Index: controlies/trunk/applications/controlies/views/laptops/form_history.html
===================================================================
--- controlies/trunk/applications/controlies/views/laptops/form_history.html	(revision 365)
+++ controlies/trunk/applications/controlies/views/laptops/form_history.html	(revision 366)
@@ -98,7 +98,7 @@
 <form id="form_data_history" onsubmit="return sendHistory();">
     <input type="hidden" id="action" name="action"/>
     <input type="hidden" id="id_laptop" name="id_laptop"/>
-    <input type="hidden" id="id_history" name="id_history"/>    
+    <input type="hidden" id="id_historical" name="id_historical"/>    
     <div>
 		<p><span id="id_stateTag">Estado (*)</span><br>
 			<select type="text" id="id_state" name="id_state" onchange="javascript:showFields();">
