Index: controlies/branches/web2py/applications/controlies/models/db.py
===================================================================
--- controlies/branches/web2py/applications/controlies/models/db.py	(revision 162)
+++ controlies/branches/web2py/applications/controlies/models/db.py	(revision 163)
@@ -88,14 +88,6 @@
 #########################################################################
 import applications.controlies.modules.LdapConnection as LdapConnection
 
-ldapmode='uid'
-if session.username is not None:
-    if session.username=='admin':
-        ldapmode='cn'
+auth.settings.login_methods=[ldap_auth( server='localhost', base_dn='ou=People,dc=instituto,dc=extremadura,dc=es',secure=LdapConnection.ldap_secure,cert_path=LdapConnection.ldap_cert,mode='cn')]
 
-if session.server is None:
-   session.server='localhost'
-
-auth.settings.login_methods=[ldap_auth( server=session.server, base_dn='ou=People,dc=instituto,dc=extremadura,dc=es',secure=LdapConnection.ldap_secure,cert_path=LdapConnection.ldap_cert,mode=ldapmode)]
-
 #auth.settings.login_onaccept=lambda form: session_ldap(form)
Index: controlies/branches/web2py/applications/controlies/controllers/default.py
===================================================================
--- controlies/branches/web2py/applications/controlies/controllers/default.py	(revision 162)
+++ controlies/branches/web2py/applications/controlies/controllers/default.py	(revision 163)
@@ -32,11 +32,19 @@
     to decorate functions that need access control
     """
     if "host" in request.vars:
-        session.server=request.vars[ "host"]
+        session.server=request.vars["host"]
         session.username=request.vars["username"]        
         session.password=request.vars["password"]
+        con_parameters=auth.settings.login_methods[0].func_defaults
+        if con_parameters[0] != request.vars["host"] or request.vars["username"] != 'admin':
+            #tengo que cambiar los parámetros con los que se llama a la función de logueo:
+            new_parameters=list(con_parameters)
+            new_parameters[0]=request.vars["host"]
+            if request.vars["username"] != 'admin' : new_parameters[3]='uid'
+            auth.settings.login_methods[0].func_defaults=tuple(new_parameters)
 
 
+
     return dict(form=auth())
 
 @auth.requires_login()
Index: controlies/branches/web2py/applications/controlies/modules/Hosts.py
===================================================================
--- controlies/branches/web2py/applications/controlies/modules/Hosts.py	(revision 162)
+++ controlies/branches/web2py/applications/controlies/modules/Hosts.py	(revision 163)
@@ -94,7 +94,6 @@
 		return "OK"		
 		
     def process(self,action):
-		import pdb
 		if action == "add":
 			val = self.validation(action)
 			
@@ -190,7 +189,6 @@
 		elif type == "thinclient":
 			search = self.ldap.search("cn=THINCLIENTS,cn=DHCP Config","cn=*",["cn","dhcpHWAddress"])
 			filter="(|(dhcpOption=*subnet*)(dhcpOption=*log*))"
-			import pdb
 			
 			rows = []
 			
@@ -294,7 +292,6 @@
 		NetworkUtils.startup(self.mac)
 		
     def groupOverflow(self,overflow):
-		import pdb
 		if self.type == 'thinclient':
 			search = self.ldap.search("cn=" + self.group +",cn=THINCLIENTS,cn=DHCP Config","cn=*",["cn"])
 			if len(search)-2 >= overflow:
Index: controlies/branches/web2py/applications/controlies/modules/Users.py
===================================================================
--- controlies/branches/web2py/applications/controlies/modules/Users.py	(revision 162)
+++ controlies/branches/web2py/applications/controlies/modules/Users.py	(revision 163)
@@ -1,12 +1,12 @@
 ##############################################################################
 # -*- coding: utf-8 -*-
-# Project:     	ControlIES
-# Module:    	Users.py
-# Purpose:     	Users class
-# Language:    	Python 2.5
-# Date:        	7-Feb-2011.
-# Ver:        	7-Feb-2011.
-# Author:		Manuel Mora Gordillo
+# Project:      ControlIES
+# Module:       Users.py
+# Purpose:      Users class
+# Language:     Python 2.5
+# Date:         7-Feb-2011.
+# Ver:          7-Feb-2011.
+# Author:       Manuel Mora Gordillo
 # Copyright:    2011 - Manuel Mora Gordillo <manuito @no-spam@ gmail.com>
 #
 # ControlIES is free software: you can redistribute it and/or modify
@@ -33,400 +33,401 @@
 class Users(object):
 
     def __init__(self):
-		pass
-	
+        pass
+    
     def __init__(self,ldap,type,name,surname,nif,user,password,password2,departments,classrooms):
-		self.ldap = ldap
-		self.type = type
-		self.name = name
-		self.surname = surname
-		self.nif = nif
-		self.user = user		
-		self.password = password
-		self.password2 = password2
-		self.departments = departments
-		self.classrooms = classrooms
-		
+        self.ldap = ldap
+        self.type = type
+        self.name = name
+        self.surname = surname
+        self.nif = nif
+        self.user = user        
+        self.password = password
+        self.password2 = password2
+        self.departments = departments
+        self.classrooms = classrooms
+        
     def validation(self,action):
-		
-		if action == "add":
-			if self.type == "none":
-				return "type"
-		
-		if self.name == "":
-			return "name"
+        
+        if action == "add":
+            if self.type == "none":
+                return "type"
+        
+        if self.name == "":
+            return "name"
 
-		if self.surname == "":
-			return "surname"
+        if self.surname == "":
+            return "surname"
 
-		if self.nif == "":
-			return "nif"
+        if self.nif == "":
+            return "nif"
 
-		if self.user == "":
-			return "user"
-		
-		if action == "add":
-			if self.existsUsername():
-				return "userAlreadyExists"
-		
-			if self.password == "":
-				return "password"
+        if self.user == "":
+            return "user"
+        
+        if action == "add":
+            if self.existsUsername():
+                return "userAlreadyExists"
+        
+            if self.password == "":
+                return "password"
 
-			if self.password2 == "":
-				return "password2"
+            if self.password2 == "":
+                return "password2"
 
-			if self.password != self.password2:
-				return "distinctPassword"
-				
-		elif action == "modify":			
-			if self.password == "" and self.password2 != "":
-				return "password"
-								
-			if self.password != "" and self.password2 == "":
-				return "password2"
+            if self.password != self.password2:
+                return "distinctPassword"
+                
+        elif action == "modify":            
+            if self.password == "" and self.password2 != "":
+                return "password"
+                                
+            if self.password != "" and self.password2 == "":
+                return "password2"
 
-			if self.password != "" and self.password2 != "" and self.password != self.password2:
-				return "distinctPassword"
+            if self.password != "" and self.password2 != "" and self.password != self.password2:
+                return "distinctPassword"
 
-		return "OK"
+        return "OK"
 
     def process(self,action):
-		if action == "add":
-			val = self.validation(action)
-			
-			if val != "OK":
-				return val
-			else:
-				response = self.add()
-				return response
+        if action == "add":
+            val = self.validation(action)
+            
+            if val != "OK":
+                return val
+            else:
+                response = self.add()
+                return response
 
-		if action == "modify":
-			val = self.validation(action)
-			
-			if val != "OK":
-				return val
-			else:
-				response = self.modify()
-				return response
-		
-			
+        if action == "modify":
+            val = self.validation(action)
+            
+            if val != "OK":
+                return val
+            else:
+                response = self.modify()
+                return response
+        
+            
     def list(self,args):
 
-		filter = self.buildFilter(args)
-		search = self.ldap.search("ou=People",filter,["employeeNumber","uid","cn","uidnumber","gidnumber","homedirectory"])
+        filter = self.buildFilter(args)
+        search = self.ldap.search("ou=People",filter,["employeeNumber","uid","cn","uidnumber","gidnumber","homedirectory"])
 
-		# grid parameters
-		limit = int(args['rows'])
-		page = int(args['page'])
-		start = limit * page - limit
-		finish = start + limit;				
+        # grid parameters
+        limit = int(args['rows'])
+        page = int(args['page'])
+        start = limit * page - limit
+        finish = start + limit;             
 
-		# sort by field
-		sortBy = args['sidx']
-		if sortBy == "uid":
-			sortBy = "id"
+        # sort by field
+        sortBy = args['sidx']
+        if sortBy == "uid":
+            sortBy = "id"
 
-		# reverse Sort
-		reverseSort = False
-		if args['sord'] == "asc":
-			reverseSort = True
+        # reverse Sort
+        reverseSort = False
+        if args['sord'] == "asc":
+            reverseSort = True
 
-		# type of user (Teacher/Student)
-		try:
-			searchType = args['type']
-		except LookupError:
-			searchType = "none"
+        # type of user (Teacher/Student)
+        try:
+            searchType = args['type']
+        except LookupError:
+            searchType = "none"
 
-		rows = []
-		for i in search:
-			
-			typeRow="Alumno"
-			if i[0][1]["homeDirectory"][0][0:14]=="/home/profesor":
-				typeRow="Profesor"
-			
-			if searchType == typeRow or searchType=="none":
-				row = {
-					"id":i[0][1]["uid"][0], 
-					"cell":[typeRow, i[0][1]["cn"][0], i[0][1]["uid"][0], i[0][1]["uidNumber"][0], i[0][1]["gidNumber"][0], i[0][1]["employeeNumber"][0]], 
-					"type": typeRow,					
-					"cn":i[0][1]["cn"][0],
-					"uidNumber":i[0][1]["uidNumber"][0],
-					"gidNumber":i[0][1]["gidNumber"][0],				
-					"employeeNumber":i[0][1]["employeeNumber"][0]
-				}
-				rows.append(row)
+        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":
+                row = {
+                    "id":userdata["uid"][0], 
+                    "cell":[typeRow, userdata["cn"][0], userdata["uid"][0], userdata["uidNumber"][0], userdata["gidNumber"][0], userdata["employeeNumber"][0]], 
+                    "type": typeRow,                    
+                    "cn":userdata["cn"][0],
+                    "uidNumber":userdata["uidNumber"][0],
+                    "gidNumber":userdata["gidNumber"][0],                
+                    "employeeNumber":userdata["employeeNumber"][0]
+                }
+                rows.append(row)
+                    
+        # grid parameters
+        if len(rows) > 0:
+            totalPages = ceil( len(rows) / int(limit) )
+        else:
+            totalPages = 0
 
-		# grid parameters
-		if len(rows) > 0:
-			totalPages = ceil( len(rows) / int(limit) )
-		else:
-			totalPages = 0
+        if page > totalPages:
+            page = totalPages
 
-		if page > totalPages:
-			page = totalPages
+        # sort rows
+        result = sorted(rows, key=itemgetter(sortBy), reverse=reverseSort)
 
-		# sort rows
-		result = sorted(rows, key=itemgetter(sortBy), reverse=reverseSort)
+        return { "page":page, "total":totalPages, "records":len(rows), "rows":result[start:finish] }
 
-		return { "page":page, "total":totalPages, "records":len(rows), "rows":result[start:finish] }
 
-
     def buildFilter(self, args):
-		filter = "(&(uid=*)"
-		
-		try:
-			filter = filter + "(uid=*" + args['uid'] + "*)"
-		except LookupError:
-			pass
+        filter = "(&(uid=*)"
+        
+        try:
+            filter = filter + "(uid=*" + args['uid'] + "*)"
+        except LookupError:
+            pass
 
-		try:
-			filter = filter + "(cn=*" + args['cn'] + "*)"
-		except LookupError:
-			pass
+        try:
+            filter = filter + "(cn=*" + args['cn'] + "*)"
+        except LookupError:
+            pass
 
-		try:
-			filter = filter + "(uidNumber=" + args['uidNumber'] + ")"
-		except LookupError:
-			pass
+        try:
+            filter = filter + "(uidNumber=" + args['uidNumber'] + ")"
+        except LookupError:
+            pass
 
-		try:
-			filter = filter + "(gidNumber=" + args['gidNumber'] + ")"
-		except LookupError:
-			pass
+        try:
+            filter = filter + "(gidNumber=" + args['gidNumber'] + ")"
+        except LookupError:
+            pass
 
-		try:
-			filter = filter + "(employeeNumber=*" + args['employeeNumber'] + "*)"
-		except LookupError:
-			pass
+        try:
+            filter = filter + "(employeeNumber=*" + args['employeeNumber'] + "*)"
+        except LookupError:
+            pass
 
-		filter = filter + ")"
-		return filter
+        filter = filter + ")"
+        return filter
 
 
     def add(self):
 
-		maxID = str(LdapUtils.getMaxID(self.ldap))
-		passwd = '{SSHA}' + Utils.encrypt(self.password)
-		
-		attr = [
-		('objectclass', ['top','posixAccount','shadowAccount','person','inetOrgPerson']),
-		('uid', [self.user]),
-		('cn', [self.name] ),
-		('employeenumber', [self.nif] ),		
-		('sn', [self.surname] ),
-		('uidnumber', [maxID] ),
-		('gidnumber', [maxID] ),	
-		('loginshell', ['/bin/bash'] ),
-		('homeDirectory', [LdapUtils.whatHome(self.type) + self.user] ),
-		#('jpegPhoto', ['jpegPhoto'] ),		
-		('userpassword', [passwd])
-		]
+        maxID = str(LdapUtils.getMaxID(self.ldap))
+        passwd = '{SSHA}' + Utils.encrypt(self.password)
+        
+        attr = [
+        ('objectclass', ['top','posixAccount','shadowAccount','person','inetOrgPerson']),
+        ('uid', [self.user]),
+        ('cn', [self.name] ),
+        ('employeenumber', [self.nif] ),        
+        ('sn', [self.surname] ),
+        ('uidnumber', [maxID] ),
+        ('gidnumber', [maxID] ),    
+        ('loginshell', ['/bin/bash'] ),
+        ('homeDirectory', [LdapUtils.whatHome(self.type) + self.user] ),
+        #('jpegPhoto', ['jpegPhoto'] ),     
+        ('userpassword', [passwd])
+        ]
 
-		self.ldap.add("uid="+self.user+",ou=People", attr)
+        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'] )
-		]
+        # 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] )
-		]
+        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.departments:
+            self.ldap.modify('cn='+ n +',ou=Group', attr)
 
-		for n in self.classrooms:
-			self.ldap.modify('cn='+ n +',ou=Group', attr)
-						
-		return "OK"
-			
-			
+        for n in self.classrooms:
+            self.ldap.modify('cn='+ n +',ou=Group', attr)
+                        
+        return "OK"
+            
+            
     def modify(self):
-		
-		attr = [
-		(ldap.MOD_REPLACE, 'cn', [self.name] ),
-		(ldap.MOD_REPLACE, 'employeenumber', [self.nif] ),		
-		(ldap.MOD_REPLACE, 'sn', [self.surname] )		
-		]
+        attr = [
+        (ldap.MOD_REPLACE, 'cn', [self.name] ),
+        (ldap.MOD_REPLACE, 'employeenumber', [self.nif] ),      
+        (ldap.MOD_REPLACE, 'sn', [self.surname] )       
+        ]
 
-		if self.password!="":
-			passwd = '{SSHA}' + Utils.encrypt(self.password)
-			attr.append((ldap.MOD_REPLACE, 'userpassword', [passwd]))
-		
-		self.ldap.modify("uid="+self.user+",ou=People", attr)
+        if self.password!="":
+            passwd = '{SSHA}' + Utils.encrypt(self.password)
+            attr.append((ldap.MOD_REPLACE, 'userpassword', [passwd]))
+        
+        self.ldap.modify("uid="+self.user+",ou=People", attr)
 
-		# Get current groups
-		currentGroups = self.getUserGroups()
-		
-		groupsDepartments = Utils.cmpLists(currentGroups["departments"], self.departments)
-		groupsClassrooms = Utils.cmpLists(currentGroups["classrooms"], self.classrooms)		
-		
-		# Delete unselected groups		
-		deleteDepartments = groupsDepartments["onlyInList1"]
-		deleteClassrooms = groupsClassrooms["onlyInList1"]
-		
-		attr = [
-		(ldap.MOD_DELETE, 'member', ['uid='+self.user+',ou=People,dc=instituto,dc=extremadura,dc=es'] ),
-		(ldap.MOD_DELETE, 'memberUid', [self.user] )
-		]
+        # Get current groups
+        currentGroups = self.getUserGroups()
+        
+        groupsDepartments = Utils.cmpLists(currentGroups["departments"], self.departments)
+        groupsClassrooms = Utils.cmpLists(currentGroups["classrooms"], self.classrooms)     
+        
+        # Delete unselected groups      
+        deleteDepartments = groupsDepartments["onlyInList1"]
+        deleteClassrooms = groupsClassrooms["onlyInList1"]
+        
+        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 deleteDepartments:
-			self.ldap.modify('cn='+ d +',ou=Group', attr)
+        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 = groupsDepartments["onlyInList2"]
-		newClassrooms = groupsClassrooms["onlyInList2"]
-		
-		attr = [
-		(ldap.MOD_ADD, 'member', ['uid='+self.user+',ou=People,dc=instituto,dc=extremadura,dc=es'] ),
-		(ldap.MOD_ADD, 'memberUid', [self.user] )
-		]
+        for d in deleteClassrooms:
+            self.ldap.modify('cn='+ d +',ou=Group', attr)
+                    
+        # Add selected groups   
+        newDepartments = groupsDepartments["onlyInList2"]
+        newClassrooms = groupsClassrooms["onlyInList2"]
+        
+        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 newDepartments:
+            self.ldap.modify('cn='+ n +',ou=Group', attr)
 
-		for n in newClassrooms:
-			self.ldap.modify('cn='+ n +',ou=Group', attr)
-					
-		return "OK"
+        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()
+        
+        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] )
-		]
+        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 currentGroups["departments"]:
-			self.ldap.modify('cn='+ d +',ou=Group', attr)
+        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"
+        for d in currentGroups["classrooms"]:
+            self.ldap.modify('cn='+ d +',ou=Group', attr)
+            
+        return "OK"
 
 
     def existsUsername(self):
-		
-		result = self.ldap.search("ou=People","uid="+self.user,["uid"])
+        
+        result = self.ldap.search("ou=People","uid="+self.user,["uid"])
 
-		if len(result) > 0:
-			return True
-		
-		return False
+        if len(result) > 0:
+            return True
+        
+        return False
 
 
     def searchNewUsername(self):
 
-		result = self.ldap.search("ou=People","uid=*",["uid"])
-		users = []
-		for i in result:
-			users.append(i[0][1]['uid'][0])
+        result = self.ldap.search("ou=People","uid=*",["uid"])
+        users = []
+        for i in result:
+            users.append(i[0][1]['uid'][0])
 
-		n = self.name.lower().split(" ")
-		
-		username = ""
-		if len(n) > 0:
-			username = n[0][0:1]
+        n = self.name.lower().split(" ")
+        
+        username = ""
+        if len(n) > 0:
+            username = n[0][0:1]
 
-		if len(n) > 1:
-			 username = username + n[1]
-			 
-		if len(n) > 2:
-			username = username + n[2][0:1]
+        if len(n) > 1:
+             username = username + n[1]
+             
+        if len(n) > 2:
+            username = username + n[2][0:1]
 
-		num = 1
-		searching = username + "0" + str(num)
+        num = 1
+        searching = username + "0" + str(num)
 
-		found = True
-		while found:
-			try:
-				users.index(searching)
-				num = num + 1
-				
-				if len(str(num)) == 1:
-					searching = username + "0" + str(num)
-				else:
-					searching = username + str(num)
-			except:
-				found = False
-				
-		return searching
+        found = True
+        while found:
+            try:
+                users.index(searching)
+                num = num + 1
+                
+                if len(str(num)) == 1:
+                    searching = username + "0" + str(num)
+                else:
+                    searching = username + str(num)
+            except:
+                found = False
+                
+        return searching
 
     def getUserGroups(self):
-		result = self.ldap.search("ou=Group","(&(memberUid="+self.user+")(|(groupType=school_department)(groupType=school_class)))",["cn","groupType"])
-		
-		departments = []
-		classrooms = []		
-		for g in result:
-			if g[0][1]["groupType"][0] == "school_department":
-				departments.append(g[0][1]["cn"][0])
-			elif g[0][1]["groupType"][0] == "school_class":
-				classrooms.append(g[0][1]["cn"][0])
-		
-		departments.sort()
-		classrooms.sort()
-		return { "departments":departments, "classrooms":classrooms }
-		
+        result = self.ldap.search("ou=Group","(&(memberUid="+self.user+")(|(groupType=school_department)(groupType=school_class)))",["cn","groupType"])
+        
+        departments = []
+        classrooms = []     
+        for g in result:
+            if g[0][1]["groupType"][0] == "school_department":
+                departments.append(g[0][1]["cn"][0])
+            elif g[0][1]["groupType"][0] == "school_class":
+                classrooms.append(g[0][1]["cn"][0])
+        
+        departments.sort()
+        classrooms.sort()
+        return { "departments":departments, "classrooms":classrooms }
+        
     def getUserData(self):
-		self.getUserGroups()
-		result = self.ldap.search("ou=People","uid="+self.user,["uid","cn","sn","employeenumber","homedirectory","jpegPhoto"])
-		
-		if len(result) == 0:
-			return { "user":"", "name":"", "surname":"", "nif":"", "photo":"", "type":"", "groups":[] }
-		
-		type = "student"
-		if result[0][0][1]["homeDirectory"][0][0:14]=="/home/profesor":
-			type = "teacher"
-		
-		try:
-			photo = base64.b64encode(result[0][0][1]["jpegPhoto"][0])
-		except:
-			photo = ""
-			
-		dataUser = {
-			"user":result[0][0][1]["uid"][0],
-			"name":result[0][0][1]["cn"][0],
-			"surname":result[0][0][1]["sn"][0],
-			"nif":result[0][0][1]["employeeNumber"][0],
-			"photo":photo,
-			"type":type,
-			"groups":self.getUserGroups()
-		 }
-		 
-		return dataUser
+        self.getUserGroups()
+        result = self.ldap.search("ou=People","uid="+self.user,["uid","cn","sn","employeenumber","homedirectory","jpegPhoto"])
+        
+        if len(result) == 0:
+            return { "user":"", "name":"", "surname":"", "nif":"", "photo":"", "type":"", "groups":[] }
+        
+        type = "student"
+        if result[0][0][1]["homeDirectory"][0][0:14]=="/home/profesor":
+            type = "teacher"
+        
+        try:
+            photo = base64.b64encode(result[0][0][1]["jpegPhoto"][0])
+        except:
+            photo = ""
+        userdata=result[0][0][1]  
+        if "employeeNumber" not in userdata: userdata["employeeNumber"]=["0"]
+        dataUser = {
+            "user":userdata["uid"][0],
+            "name":userdata["cn"][0],
+            "surname":userdata["sn"][0],
+            "nif":userdata["employeeNumber"][0],
+            "photo":photo,
+            "type":type,
+            "groups":self.getUserGroups()
+         }
+         
+        return dataUser
 
     def getUserPhoto(self):
-		self.getUserGroups()
-		result = self.ldap.search("ou=People","uid="+self.user,["jpegPhoto"])
-				
-		try:
-			photo = base64.b64encode(result[0][0][1]["jpegPhoto"][0])
-		except:
-			photo = ""
-			
-		dataUser = {
-			"photo":photo
-		 }
-		 
-		return dataUser
+        self.getUserGroups()
+        result = self.ldap.search("ou=People","uid="+self.user,["jpegPhoto"])
+                
+        try:
+            photo = base64.b64encode(result[0][0][1]["jpegPhoto"][0])
+        except:
+            photo = ""
+            
+        dataUser = {
+            "photo":photo
+         }
+         
+        return dataUser
Index: controlies/branches/web2py/applications/controlies/views/usuarios/index.html
===================================================================
--- controlies/branches/web2py/applications/controlies/views/usuarios/index.html	(revision 162)
+++ controlies/branches/web2py/applications/controlies/views/usuarios/index.html	(revision 163)
@@ -195,8 +195,8 @@
                         jQuery("#form_data #nif").val(result.response['nif']);       
                         jQuery("#form_data #user").val(result.response['user']);
                         jQuery("#form_data #surname").val(result.response['surname']);
-                        
-                        jQuery("#form_data #photo").attr("src","data:image/png;base64,"+result.response['photo']);                       
+                        if (result.response['photo']!='')
+                            jQuery("#form_data #photo").attr("src","data:image/png;base64,"+result.response['photo']);                       
 
                         $.each(result.response['groups']['departments'], function(i, l){
                             jQuery('#form_data input:checkbox[value='+l+']').attr('checked', true);                          
