Index: trunk/phpgwapi/inc/class.sessions.inc.php
===================================================================
--- trunk/phpgwapi/inc/class.sessions.inc.php	(revision 370)
+++ trunk/phpgwapi/inc/class.sessions.inc.php	(revision 548)
@@ -520,4 +520,31 @@
 			}
 
+			if($this->account_id!=null) {
+				$last_access = $this->get_last_access_on_history($this->account_id);
+				//echo $last_access+($current_config["time_to_account_expires"]*86400);
+				//exit(0);
+				
+				$this->read_repositories(False);
+				if((isset($GLOBALS['phpgw_info']['server']['time_to_account_expires'])) && ($last_access) && ($this->account_lid!="expresso-admin")) {
+					if ($last_access+($GLOBALS['phpgw_info']['server']['time_to_account_expires']*86400) < time())
+					{
+						if(is_object($GLOBALS['phpgw']->log))
+						{
+							$GLOBALS['phpgw']->log->message(array(
+								'text' => 'W-LoginFailure, account loginid %1 is expired for innativity',
+								'p1'   => $this->account_lid,
+								'line' => __LINE__,
+								'file' => __FILE__
+							));
+							$GLOBALS['phpgw']->log->commit();
+						}
+						$this->reason = 'account is expired';
+						$this->cd_reason = 98;
+		
+						return False;
+					}
+				}
+			}
+
 			/* jakjr: Expresso does not use auto-create account.
 			if (!$this->account_id && $GLOBALS['phpgw_info']['server']['auto_create_acct'] == True)
@@ -597,4 +624,14 @@
 
 			return $this->sessionid;
+		}
+
+		/**
+		  * Retorna o UNIX DATE do ultimo acesso dessa conta, baseado na tabela de histórico.
+		  */
+		function get_last_access_on_history($account_id) {
+			$GLOBALS['phpgw']->db->query("select li from phpgw_access_log where account_id='$account_id' order by li desc limit 1",__LINE__,__FILE__);
+			if(!$GLOBALS['phpgw']->db->next_record())
+				return false;
+			return $GLOBALS['phpgw']->db->f('li');
 		}
 
Index: trunk/expressoAdmin1_2/inc/class.db_functions.inc.php
===================================================================
--- trunk/expressoAdmin1_2/inc/class.db_functions.inc.php	(revision 507)
+++ trunk/expressoAdmin1_2/inc/class.db_functions.inc.php	(revision 548)
@@ -37,4 +37,32 @@
 			$result[] = $this->db->row();
 		return $result;
+	}
+/*
+	*	Reativa os usuários desabilitados por tempo inativo modificando o seu ultimo acesso para o dia atual.
+	*/
+	function reativar_usuario_inativo($uidNumber) {
+		
+	/*	$sql = "insert into phpgw_access_log (sessionid,loginid,ip,li,lo,account_id) values ('expirescontrol','teste','10.10.10.10','0','0','1') ";
+			$this->db->query($sql);*/
+		
+		$sql = "select * from phpgw_access_log where account_id=$uidNumber order by li desc limit 1";
+	
+		$this->db->query($sql);
+		$this->db->next_record();
+		$linha = $this->db->row();
+
+		
+		if(count($linha)>0) {
+			$sql = "insert into phpgw_access_log (sessionid,loginid,ip,li,lo,account_id) values ('expirescontrol','".$linha["loginid"]."','0.0.0.0','".time()."','0','".$linha["account_id"]."')";
+			
+			$this->db->query($sql);
+		}
+	}
+
+	
+	function inserir_usuario_log_controle_inativo($uid,$uidNumber) {
+			$sql = "insert into phpgw_access_log (sessionid,loginid,ip,li,lo,account_id) values ('expirescontrol','".$uid."','0.0.0.0','".time()."','0','".$uidNumber."')";
+			
+			$this->db->query($sql);
 	}
 
Index: trunk/expressoAdmin1_2/inc/class.uiaccounts.inc.php
===================================================================
--- trunk/expressoAdmin1_2/inc/class.uiaccounts.inc.php	(revision 540)
+++ trunk/expressoAdmin1_2/inc/class.uiaccounts.inc.php	(revision 548)
@@ -20,5 +20,6 @@
 			'show_photo'				=> True,
 			'show_access_log'			=> True,
-			'css'						=> True
+			'css'						=> True,
+			'list_inative_users' => True
 		);
 
@@ -50,4 +51,63 @@
 			$GLOBALS['phpgw']->js->validate_file('jscode','tabs','expressoAdmin1_2');
 			$GLOBALS['phpgw']->js->validate_file('jscode','users','expressoAdmin1_2');
+		}
+
+		function list_inative_users() {
+
+			$context = $_GET["context"];
+
+			unset($GLOBALS['phpgw_info']['flags']['noheader']);
+			unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
+			$GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['expressoAdmin1_2']['title'].' - '. lang('list inatives');
+			$GLOBALS['phpgw']->common->phpgw_header();
+
+			$p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
+			$p->set_file(array('inative_users' => 'list_inativos.tpl'));
+			$p->set_block('inative_users','list','list');
+			$p->set_block('inative_users','row','row');
+			$p->set_block('inative_users','row_empty','row_empty');
+			$contexts = array();
+			array_push($contexts,$context);
+						
+			$usuarios = $this->functions->get_inative_users($contexts);
+
+	
+			
+			$var = Array(
+				'th_bg'					=> $GLOBALS['phpgw_info']['theme']['th_bg'],
+				'back_url'				=> $GLOBALS['phpgw']->link('/index.php?menuaction=expressoAdmin1_2.uisectors.list_sectors'),
+				'context_display'		=> $context_display,
+				'lang_idusuario'			=> lang('uidNumber'),
+				'lang_login'			=> lang('user login'),
+				'lang_ultimo_login'	=> lang('last login'),
+				'lang_back'			=> lang('back')
+			);
+			$p->set_var($var);
+
+			if (!count($usuarios))
+			{
+				$p->set_var('message',lang('No matches found'));
+			}
+			else
+			{
+				foreach($usuarios as $usuario)
+				{
+					$tr_color = $this->nextmatchs->alternate_row_color($tr_color);
+					
+					$var = Array(
+						'tr_color'    => $tr_color,
+						'id'  => $usuario["uidNumber"],
+						'login' => $usuario["login"],
+						'data_ultimo_login' => date("d/m/Y",$usuario["li"])
+					);
+					$p->set_var($var);
+
+					$p->fp('rows','row',True);
+				}
+			}		
+			$p->parse('rows','row_empty',True);
+			$p->pfp('out','list');
+
+			
 		}
 
@@ -551,4 +611,15 @@
 			}
 
+			$start_coment = "<!--";
+			$end_coment = "-->";		
+			$time_to_expire = $GLOBALS['phpgw_info']['server']['time_to_account_expires'];
+			if(isset($time_to_expire)) {
+				if ($GLOBALS['phpgw']->session->get_last_access_on_history($user_info["uidnumber"])+($time_to_expire*86400) < time())
+				{
+					$start_coment = "";
+					$end_coment = "";
+				}
+			}
+
 			if ($alert_warning != '')
 				$alert_warning = "alert('". $alert_warning ."')";
@@ -572,4 +643,9 @@
 				'disable_phonenumber'		=> $disabled_phonenumber,
 				'disable_group'				=> $disabled_group,
+				'lang_account_expired' 	=> lang('lang_account_expired'),
+				'lang_yes'						=> lang('yes'),
+				'lang_no'						=> lang('no'),
+				'start_coment_expired'						=> $start_coment,
+				'end_coment_expired'						=> $end_coment,	
 				
 				// Display ABAS
Index: trunk/expressoAdmin1_2/inc/class.user.inc.php
===================================================================
--- trunk/expressoAdmin1_2/inc/class.user.inc.php	(revision 528)
+++ trunk/expressoAdmin1_2/inc/class.user.inc.php	(revision 548)
@@ -580,4 +580,12 @@
 					$this->db_functions->write_log("turn off user account",$dn);
 				}
+
+				if ($new_values['phpgwaccountexpired'] == '1') /////////////////////////
+				{
+					$this->db_functions->write_log("Reativado usuário bloqueado por inatividade",'',$dn,'','');
+					$this->db_functions->reativar_usuario_inativo($old_values['uidnumber']);
+				}
+
+
 				////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 				// ACCOUNT VISIBLE
Index: trunk/expressoAdmin1_2/inc/class.uisectors.inc.php
===================================================================
--- trunk/expressoAdmin1_2/inc/class.uisectors.inc.php	(revision 414)
+++ trunk/expressoAdmin1_2/inc/class.uisectors.inc.php	(revision 548)
@@ -68,5 +68,6 @@
 				'th_bg'					=> $GLOBALS['phpgw_info']['theme']['th_bg'],
 				'back_url'				=> $GLOBALS['phpgw']->link('/expressoAdmin1_2/index.php'),
-				'context_display'		=> $context_display
+				'context_display'		=> $context_display,
+				'lang_inatives'			=> lang('list inatives')
 			);
 			$p->set_var($var);
@@ -99,4 +100,10 @@
 						'add_link' => $this->row_action('add','sector',$context)
 					);
+					
+					if(isset($GLOBALS['phpgw_info']['server']['time_to_account_expires']))
+						$var['inatives_link'] = $this->row_action('list_inative','users',$context,'uiaccounts');
+					else
+						$var['inatives_link'] = lang('disabled');
+
 					$p->set_var($var);
 
@@ -321,8 +328,8 @@
 		}
 		
-		function row_action($action,$type,$context)
+		function row_action($action,$type,$context,$class='uisectors')
 		{
 			return '<a href="'.$GLOBALS['phpgw']->link('/index.php',Array(
-				'menuaction'		=> 'expressoAdmin1_2.uisectors.'.$action.'_'.$type,
+				'menuaction'		=> 'expressoAdmin1_2.'.$class.'.'.$action.'_'.$type,
 				'context'		=> $context
 			)).'"> '.lang($action).' </a>';
Index: trunk/expressoAdmin1_2/inc/class.functions.inc.php
===================================================================
--- trunk/expressoAdmin1_2/inc/class.functions.inc.php	(revision 414)
+++ trunk/expressoAdmin1_2/inc/class.functions.inc.php	(revision 548)
@@ -351,4 +351,31 @@
 			return $array_acl;
 		}
+		
+		function get_inative_users($contexts) {
+			$retorno = array();
+			$tempUsers = array();
+			//Pego no LDAP todos os usuários dos contextos em questão.
+			$usuariosLdap = $this->get_list('accounts','',$contexts);
+			foreach($usuariosLdap as $usuarioLdap) {
+				$tempUsers[$usuarioLdap["account_id"]] = $usuarioLdap["account_lid"];
+			}
+			$ids = implode(",",array_keys($tempUsers)); //Consigo a lista de uids daquele contexto para mandar na query para o banco.
+			
+			//Pego nas configurações do expresso o número de dias necessários para inatividade.
+			$timeToExpire = $GLOBALS['phpgw_info']['server']['time_to_account_expires'];
+			
+			
+			$ultimoTsValido = time() - ($timeToExpire * 86400); //O último timestamp válido é dado pelo de agora menos o número de dias para expirar vezes a quantidade de segundos existente em 1 dia.
+			$query = "select account_id,max(li) as last_login from phpgw_access_log where account_id in (".$ids.") group by account_id having max(li) < ".$ultimoTsValido." order by max(li)";
+
+			$GLOBALS['phpgw']->db->query($query);
+			while($GLOBALS['phpgw']->db->next_record())
+			{
+				$result = $GLOBALS['phpgw']->db->row();
+				array_push($retorno,array("uidNumber"=>$result["account_id"],"login"=> $tempUsers[$result["account_id"]],"li"=>$result["last_login"]));
+			}
+			
+			return $retorno;
+		}
 
 		function safeBitCheck($number,$comparison)
Index: trunk/expressoAdmin1_2/templates/default/sectors.tpl
===================================================================
--- trunk/expressoAdmin1_2/templates/default/sectors.tpl	(revision 414)
+++ trunk/expressoAdmin1_2/templates/default/sectors.tpl	(revision 548)
@@ -17,7 +17,8 @@
  </table>
  
- <table border="0" width="55%" align="center">
+ <table border="0" width="65%" align="center">
   <tr bgcolor="{th_bg}">
    <td>{lang_name}</td>
+   <td>{lang_inatives}</td>
    <td>{lang_add_sub_sectors}</td>
    <td>{lang_edit}</td>
@@ -31,4 +32,5 @@
  <tr bgcolor="{tr_color}">
   <td>{sector_name}</td>
+  <td width="13%">{inatives_link}</td>  
   <td width="25%">{add_link}</td>
   <td width="5%">{edit_link}</td>
Index: trunk/expressoAdmin1_2/templates/default/list_inativos.tpl
===================================================================
--- trunk/expressoAdmin1_2/templates/default/list_inativos.tpl	(revision 548)
+++ trunk/expressoAdmin1_2/templates/default/list_inativos.tpl	(revision 548)
@@ -0,0 +1,27 @@
+<!-- BEGIN list -->
+ <table border="0" width="55%" align="center">
+  <tr bgcolor="{th_bg}">
+   <td>{lang_idusuario}</td>
+   <td>{lang_login}</td>
+   <td>{lang_ultimo_login}</td>
+  </tr>
+  {rows}
+ </table>
+<!-- END list -->
+
+<!-- BEGIN row -->
+ <tr bgcolor="{tr_color}">
+  <td width="10%">{id}</td>
+  <td width="70%">{login}</td>
+  <td width="20%">{data_ultimo_login}</td>
+ </tr>
+<!-- END row -->
+
+<!-- BEGIN row_empty -->
+   <tr>
+    <td colspan="3" align="center">{message}</td>
+   </tr>
+	<tr>
+		<td><input type="button" value="{lang_back}" onClick="document.location.href='{back_url}'"></td>
+	</tr>
+<!-- END row_empty -->
Index: trunk/expressoAdmin1_2/templates/default/accounts_form.tpl
===================================================================
--- trunk/expressoAdmin1_2/templates/default/accounts_form.tpl	(revision 540)
+++ trunk/expressoAdmin1_2/templates/default/accounts_form.tpl	(revision 548)
@@ -114,5 +114,10 @@
 			<td><input type="checkbox" {phpgwaccountvisible_checked} {disabled} name="phpgwaccountvisible" id="phpgwaccountvisible" value="1"</td>
 		</tr>		
-
+		{start_coment_expired}
+		<tr bgcolor={row_on}>
+					<td colspan="2">{lang_account_expired}:</td>
+					<td><input type="radio" {disabled} name="phpgwaccountexpired" id="phpgwaccountexpired" value="1" />{lang_yes}
+					<input type="radio" checked="checked" {disabled} name="phpgwaccountexpired" id="phpgwaccountexpired" value="2" />{lang_no}</td>
+				</tr>		{end_coment_expired}
 		<tr bgcolor={row_on} style="display:{display_access_log_button}">
 			<td><input type='button' {disabled} {disabled_access_button} value='{lang_show_access_logs}' onclick="document.location.href='./index.php?menuaction=expressoAdmin1_2.uiaccounts.show_access_log&account_id={uidnumber}';"></td>
Index: trunk/admin/templates/celepar/config.tpl
===================================================================
--- trunk/admin/templates/celepar/config.tpl	(revision 547)
+++ trunk/admin/templates/celepar/config.tpl	(revision 548)
@@ -7,4 +7,8 @@
 <!-- END header -->
 <!-- BEGIN body -->
+	<tr class="row_on">
+    <td>{lang_Time_for_expire_inatives_accounts(0 for never expires)}:</td>
+    <td><input size="8" name="newsettings[time_to_account_expires]" value="{value_time_to_account_expires}"></td>
+   </tr>
    <tr class="row_off">
     <td>{lang_Timeout_for_sessions_in_seconds_(default_14400_=_4_hours)}:</td>
