Index: controlies/trunk/applications/controlies/views/laptops/index.html
===================================================================
--- controlies/trunk/applications/controlies/views/laptops/index.html	(revision 358)
+++ controlies/trunk/applications/controlies/views/laptops/index.html	(revision 359)
@@ -53,11 +53,13 @@
                     }
                 },
                 
-                colNames:['Marca','Modelo','Número Serie'],
+                colNames:['Marca','Modelo','Número Serie','Login','Estado'],
                 colModel:[ 
                     {name:'trademark',index:'trademark', width:60, align:"center"},
                     {name:'model',index:'model', width:115, align:"center"},
-                    {name:'serial_number',index:'serial_number', width:115, align:"center"}
+                    {name:'serial_number',index:'serial_number', width:115, align:"center"},
+                    {name:'username',index:'username', width:115, align:"center"},
+                    {name:'state',index:'state', width:115, align:"center"}
                 ], 
                 rowNum:25,
                 height:335,
Index: controlies/trunk/applications/controlies/views/laptops/history.html
===================================================================
--- controlies/trunk/applications/controlies/views/laptops/history.html	(revision 358)
+++ controlies/trunk/applications/controlies/views/laptops/history.html	(revision 359)
@@ -71,7 +71,7 @@
                 jQuery("#form_data_history #id_laptop").val(jQuery("#form_history #id_laptop").val());
                 jQuery("#form_data_history #messageForm").html("Todos los campos son obligatorios");                                     
         
-                x = (jQuery(window).width()-350)/2;
+                x = (jQuery(window).width()-400)/2;
                 y = (jQuery(window).height()-300)/2;
         
                 jQuery("#messageLoading").hide();
@@ -80,7 +80,7 @@
                     resizable: false,
                     position: top,
                     modal: true,
-                    width: 350,
+                    width: 400,
                     title: "Añadir histórico"
                 }).dialog('option', 'position', [x, y]);
             });
Index: controlies/trunk/applications/controlies/views/laptops/form_history.html
===================================================================
--- controlies/trunk/applications/controlies/views/laptops/form_history.html	(revision 358)
+++ controlies/trunk/applications/controlies/views/laptops/form_history.html	(revision 359)
@@ -1,7 +1,8 @@
 <script language="javascript">
 
     $(function() {
-        $("#name").focus();
+		hideAllFields();
+        $("#id_state").focus();
         $("#saveButtonFormHistory").button({ icons: { primary: "ui-icon-disk"}});
         $("#cancelButtonFormHistory")
             .button({ icons: { primary: "ui-icon-close"}})
@@ -20,7 +21,8 @@
             switch(result.response){
                 case "OK":{
                     jQuery('#messageHistory').html("Operación realizada correctamente").css("color","green").effect("highlight", {"color":"yellow"}, 1000);
-					jQuery("#list_history").trigger("reloadGrid");					
+					jQuery("#list_history").trigger("reloadGrid");
+					jQuery("#list").trigger("reloadGrid");				
 					setTimeout("$('#dialog-form-history').dialog('close')",1000);
                     break;
                 }
@@ -39,7 +41,52 @@
 
         return false;
     }
-
+    
+	function getDataLDAP(){
+		jQuery.post('call/json/getDataLDAP', jQuery("#form_data_history").serialize(), function(result) {
+			jQuery("#form_data_history #name").val(result.response['name']);
+			jQuery("#form_data_history #nif").val(result.response['nif']);
+			switch(result.response['type']){
+				case 'teacher': jQuery("#form_data_history #id_user_type").val(1); break;
+				case 'student': jQuery("#form_data_history #id_user_type").val(2); break;
+			}	
+		});
+	}
+	
+	function hideAllFields(){
+		jQuery("#form_data_history #usernameP").hide();
+		jQuery("#form_data_history #id_user_typeP").hide();
+		jQuery("#form_data_history #nifP").hide();
+		jQuery("#form_data_history #nameP").hide();
+		jQuery("#form_data_history #commentP").hide();
+	}
+	
+	function showFields(){
+		hideAllFields();
+		switch(jQuery("#form_data_history #id_state").val()){
+			case '2':
+			case '3':
+				jQuery("#form_data_history #usernameP").show();
+				jQuery("#form_data_history #id_user_typeP").show();
+				jQuery("#form_data_history #nifP").show();
+				jQuery("#form_data_history #nameP").show();
+				jQuery("#form_data_history #commentP").show();
+				break;
+			case '1':
+				jQuery("#form_data_history #commentP").show();
+				break;
+		} 
+		if(jQuery("#form_data_history #id_state").val()=="3"){
+			jQuery.post('call/json/getDataLastHistory', jQuery("#form_data_history").serialize(), function(result) {
+				jQuery("#form_data_history #name").val(result.response['name']);
+				jQuery("#form_data_history #nif").val(result.response['nif']);
+				switch(result.response['type']){
+					case 'teacher': jQuery("#form_data_history #id_user_type").val(1); break;
+					case 'student': jQuery("#form_data_history #id_user_type").val(2); break;
+				}	
+			});
+		}
+	}
 </script>
  
 <form id="form_data_history" onsubmit="return sendHistory();">
@@ -48,18 +95,19 @@
     <input type="hidden" id="id_history" name="id_history"/>    
     <div>
 		<p><span id="id_stateTag">Estado (*)</span><br>
-			<select type="text" id="id_state" name="id_state">
+			<select type="text" id="id_state" name="id_state" onchange="javascript:showFields();">
 				<option value="none">Seleccione...</option>
 			</select>
 		</p>
-		<p><span id="id_user_typeTag">Tipo usuario (*)</span><br>
+		<p id="usernameP"><span id="usernameTag">Login (*)</span><br><input type="text" id="username" name="username" size="15" maxlength="200" onblur="javascript:getDataLDAP();"/></p>
+		<p id="id_user_typeP"><span id="id_user_typeTag">Tipo usuario (*)</span><br>
 			<select type="text" id="id_user_type" name="id_user_type">
 				<option value="none">Seleccione...</option>
 			</select>
 		</p>    
-		<p><span id="usernameTag">Login (*)</span><br><input type="text" id="username" name="username" size="20" maxlength="200"/></p>
-		<p><span id="nameTag">Nombre y Apellidos</span><br><input type="text" id="name" name="name" size="35" maxlength="200"/></p>
-		<p><span id="commentTag">Comentario</span><br><input type="text" id="comment" name="comment" size="35" maxlength="200"/></p>
+		<p id="nifP"><span id="nifTag">NIF / NIE</span><br><input type="text" id="nif" name="nif" size="20" maxlength="200"/></p>
+		<p id="nameP"><span id="nameTag">Nombre y Apellidos</span><br><input type="text" id="name" name="name" size="35" maxlength="200"/></p>
+		<p id="commentP"><span id="commentTag">Comentario</span><br><input type="text" id="comment" name="comment" size="35" maxlength="200"/></p>
     </div>
     <div id="messageHistory" style="text-align:center; font-weight:bold; color:red; padding:3px; "></div>
     <div style="text-align:center;"><button id="saveButtonFormHistory" type="submit" style="width:100px;">Guardar</button>&nbsp;&nbsp;<button type="button" id="cancelButtonFormHistory" style="width:100px;">Cancelar</button></div>
Index: controlies/trunk/applications/controlies/controllers/laptops.py
===================================================================
--- controlies/trunk/applications/controlies/controllers/laptops.py	(revision 358)
+++ controlies/trunk/applications/controlies/controllers/laptops.py	(revision 359)
@@ -3,6 +3,7 @@
 from applications.controlies.modules.LaptopsHistory import LaptopsHistory
 from applications.controlies.modules.SQLiteConnection import SQLiteConnection
 from applications.controlies.modules.Utils import Utils
+from applications.controlies.modules.Users import Users
 
 def index():    
     return dict()
@@ -53,7 +54,7 @@
 @auth.requires_login()
 def listHistory():    
     my = SQLiteConnection()
-    l = LaptopsHistory(my,"",request.vars["id_laptop"],"","","","","")
+    l = LaptopsHistory(my,"",request.vars["id_laptop"],"","","","","","")
     response = l.list(request.vars)
     return response
 
@@ -61,7 +62,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["username"],request.vars["name"],request.vars["comment"])
+    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"])
     response = l.process(request.vars["action"])
     return dict(response = response)   
 
@@ -68,7 +69,7 @@
 @service.json
 def getAllStates():
     my = SQLiteConnection()
-    l = LaptopsHistory(my,"","","","","","","")
+    l = LaptopsHistory(my,"","","","","","","","")
     response = l.getAllStates()
     return dict(response=response)
 
@@ -75,11 +76,25 @@
 @service.json
 def getAllUserTypes():
     my = SQLiteConnection()
-    l = LaptopsHistory(my,"","","","","","","")
+    l = LaptopsHistory(my,"","","","","","","","")
     response = l.getAllUserTypes()
     return dict(response=response)
 
+@service.json
+def getDataLDAP():
+    l=conecta()
+    u = Users(l,"","","","",request.vars['username'],"","","","","")
+    response = u.getUserData()
+    l.close()
+    return dict(response=response)
 
+@service.json
+def getDataLastHistory():
+    my = SQLiteConnection()
+    l = LaptopsHistory(my,"",request.vars["id_laptop"],"","","","","","")
+    response = l.getLastHistory()
+    return dict(response=response)
+
 def laptops():
     return dict()
 
Index: controlies/trunk/applications/controlies/modules/SQLiteConnection.py
===================================================================
--- controlies/trunk/applications/controlies/modules/SQLiteConnection.py	(revision 358)
+++ controlies/trunk/applications/controlies/modules/SQLiteConnection.py	(revision 359)
@@ -63,6 +63,7 @@
                         Field('username','string'),
                         Field('name','string'),
                         Field('id_user_type','integer'),
+                        Field('nif','string'),
                         Field('comment','string'),
                         Field('id_state','integer'),
                         primarykey=['id_historical'])
@@ -79,19 +80,4 @@
             pass
         
     def getDB(self):
-        return self.db
-
-    def select(self,table,data):
-        self.db.table.insert(data)
-
-    def insert(self,table,data):
-        self.db.table.insert(data)
-
-    def execute(self,sql):
-        """db = MySQLdb.connect(host=self.host,user=self.user, passwd=self.passwd,db=self.database)
-        cursor=db.cursor()
-        cursor.execute(sql)
-        result = cursor.fetchall()
-        cursor.close()
-        db.close()
-        return result"""
\ No newline at end of file
+        return self.db
\ No newline at end of file
Index: controlies/trunk/applications/controlies/modules/Laptops.py
===================================================================
--- controlies/trunk/applications/controlies/modules/Laptops.py	(revision 358)
+++ controlies/trunk/applications/controlies/modules/Laptops.py	(revision 359)
@@ -77,9 +77,11 @@
     def list(self,args):
         db = self.SQLite.getDB()
 
-        sql = "SELECT l.id_laptop, t.trademark, t.model, l.serial_number"
-        sql = sql+" FROM laptops l LEFT JOIN laptops_trademarks t ON l.id_trademark=t.id_trademark "
-        
+        sql = "SELECT l.id_laptop, lt.trademark, lt.model, l.serial_number, lh.username, s.state"
+        sql = sql+" FROM laptops l"
+        sql = sql+" LEFT JOIN laptops_trademarks lt ON l.id_trademark=lt.id_trademark "
+        sql = sql+" LEFT JOIN laptops_historical lh ON l.id_laptop=lh.id_laptop "        
+        sql = sql+" LEFT JOIN states s ON lh.id_state=s.id_state "        
         sql = sql+" WHERE 1=1 "
         
         try:
@@ -100,8 +102,9 @@
         except LookupError:
             pass
 
-        sql = sql + " ORDER BY "+args['sidx']+" "+args['sord']
-        
+        sql = sql + " GROUP BY l.id_laptop"
+        sql = sql + " ORDER BY "+args['sidx']+" "+args['sord']+", lh.datetime desc"
+
         result = db.executesql(sql)
 
         rows = []
@@ -108,10 +111,12 @@
         for reg in result:
             row = {
 				"id":reg[0],
-				"cell":[reg[1],reg[2],reg[3]],
+				"cell":[reg[1],reg[2],reg[3],reg[4],reg[5]],
 				"trademark":reg[1],
 				"model":reg[2],
-				"serial_number":reg[3]
+				"serial_number":reg[3],
+                "username":reg[4],
+                "state":reg[5]
             }
             rows.append(row)
 
Index: controlies/trunk/applications/controlies/modules/LaptopsHistory.py
===================================================================
--- controlies/trunk/applications/controlies/modules/LaptopsHistory.py	(revision 358)
+++ controlies/trunk/applications/controlies/modules/LaptopsHistory.py	(revision 359)
@@ -30,12 +30,13 @@
     def __init__(self):
         pass
     
-    def __init__(self,SQLite,id_history,id_laptop,id_state,id_user_type,username,name,comment):
+    def __init__(self,SQLite,id_history,id_laptop,id_state,id_user_type,nif,username,name,comment):
         self.SQLite = SQLite
         self.id_history = id_history        
         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
@@ -45,11 +46,12 @@
         if self.id_state == "none":
             return "id_state"
 
-        if self.id_user_type == "none":
-            return "id_user_type"
-
-        if self.username == "":
-            return "username"
+        if self.id_state=="2" or self.id_state=="3":
+            if self.username == "":
+                return "username"
+            
+            if self.id_user_type == "none":
+                return "id_user_type"
                 
         return "OK"
 
@@ -120,10 +122,8 @@
 
     def add(self):
         now = datetime.datetime.now()
-        #date = str(now.year)+"-"+str(now.month)+"-"+str(now.day)+" "+str(now.hour)+"-"+str(now.minute)+"-"+str(now.second)
-        sql = "INSERT INTO laptops_historical (id_historical,id_laptop,datetime,username,name,id_user_type,comment,id_state) "
-        sql = sql + "VALUES(null,'"+self.id_laptop+"','"+now.strftime('%Y-%m-%d %H:%M:%S')+"','"+self.username+"','"+self.name+"','"+self.id_user_type+"','"+self.comment+"','"+self.id_state+"')"
-        print sql
+        sql = "INSERT INTO laptops_historical (id_historical,id_laptop,datetime,username,name,id_user_type,nif,comment,id_state) "
+        sql = sql + "VALUES(null,'"+self.id_laptop+"','"+now.strftime('%Y-%m-%d %H:%M:%S')+"','"+self.username+"','"+self.name+"','"+self.id_user_type+"','"+self.nif+"','"+self.comment+"','"+self.id_state+"')"
         db = self.SQLite.getDB()
         result = db.executesql(sql)
         
@@ -174,4 +174,18 @@
                 "user_type":r[1]
             }
             data.append(dataType)
+        return data
+
+    def getLastHistory(self):
+        sql="SELECT username, id_state FROM laptops_historical WHERE id_laptop='"+str(self.id_laptop)+"' ORDER BY datetime desc LIMIT 0,1"
+        db = self.SQLite.getDB()
+        result = db.executesql(sql)
+
+        data=[]
+        for r in result:
+            dataType = {
+                "username":str(r[0]),
+                "id_state":str(r[1])
+            }
+            data.append(dataType)
         return data
\ No newline at end of file
