Index: /trunk/services/class.ldap.php
===================================================================
--- /trunk/services/class.ldap.php	(revision 4828)
+++ /trunk/services/class.ldap.php	(revision 5068)
@@ -1,4 +1,55 @@
 <?php
-
+/**
+*
+* Copyright (C) 2011 Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)
+*
+* This program is free software; you can redistribute it and/or modify it under
+* the terms of the GNU Affero General Public License version 3 as published by
+* the Free Software Foundation with the addition of the following permission
+* added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED
+* WORK IN WHICH THE COPYRIGHT IS OWNED BY FUNAMBOL, FUNAMBOL DISCLAIMS THE
+* WARRANTY OF NON INFRINGEMENT  OF THIRD PARTY RIGHTS.
+*
+* This program is distributed in the hope that it will be useful, but WITHOUT
+* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+* FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+* details.
+*
+* You should have received a copy of the GNU Affero General Public License
+* along with this program; if not, see www.gnu.org/licenses or write to
+* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+* MA 02110-1301 USA.
+*
+* This code is based on the OpenXchange Connector and on the Prognus pSync
+* Connector both developed by the community and licensed under the GPL
+* version 2 or above as published by the Free Software Foundation.
+*
+* You can contact Prognus Software Livre headquarters at Av. Tancredo Neves,
+* 6731, PTI, Bl. 05, Esp. 02, Sl. 10, Foz do Iguaçu - PR - Brasil or at
+* e-mail address prognus@prognus.com.br.
+*
+* Serviço de LDAP
+*
+* @package    Services
+* @license    http://www.gnu.org/copyleft/gpl.html GPL
+* @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)
+* @version    1.0
+* @sponsor    Caixa Econômica Federal
+*/
+
+
+
+
+/**
+* Serviço Ldap
+*
+* Classe responsável pelas operações com o LDAP
+*
+* @package    Service
+* @license    http://www.gnu.org/copyleft/gpl.html GPL
+* @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)
+* @sponsor    Caixa Econômica Federal
+* @version    1.0
+*/
 class LdapService
 {
@@ -14,4 +65,16 @@
     }
 
+	
+	/**
+     * Conecta com o LDAP
+     *
+     * @license    http://www.gnu.org/copyleft/gpl.html GPL
+	 * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)
+	 * @sponsor    Caixa Econômica Federal
+     * @param 	$host
+     * @param 	$dn
+     * @param 	$passwd
+     * @param 	$ldapreferral
+     */
     function connect($host='', $dn='', $passwd='', $ldapreferral=false)
     {
@@ -47,130 +110,159 @@
     function _or( $toWrap )
     {
-	if( !is_array( $toWrap ) )
-	    return( $toWrap );
-
-// 	if( count( $toWrap ) <= 1 )
-// 	    return implode( "", $toWrap );
-
-	return $this->wrap( $toWrap, '|' );
+		if( !is_array( $toWrap ) )
+			return( $toWrap );
+	
+		// 	if( count( $toWrap ) <= 1 )
+		// 	    return implode( "", $toWrap );
+	
+		return $this->wrap( $toWrap, '|' );
     }
 
     function _and( $toWrap )
     {
-	if( !is_array( $toWrap ) )
-	    return( $toWrap );
-
-// 	if( count( $toWrap ) <= 1 )
-// 	    return implode( "", $toWrap );
-
-	return $this->wrap( $toWrap, '&' );
+		if( !is_array( $toWrap ) )
+			return( $toWrap );
+	
+		// 	if( count( $toWrap ) <= 1 )
+		// 	    return implode( "", $toWrap );
+	
+		return $this->wrap( $toWrap, '&' );
     }
 
     function _not( $toWrap )
     {
-	return $this->wrap( $toWrap, '!' );
+		return $this->wrap( $toWrap, '!' );
     }
 
     function wrap( $toWrap, $conditional = "" )
     {
-	if( !is_array( $toWrap ) )
-	    $toWrap = array( $toWrap );
-
-	$toWrap = array_unique( $toWrap );
-
-	return "(".$conditional.implode( "", $toWrap ).")";
-    }
-
+		if( !is_array( $toWrap ) )
+			$toWrap = array( $toWrap );
+	
+		$toWrap = array_unique( $toWrap );
+
+		return "(".$conditional.implode( "", $toWrap ).")";
+    }
+
+	/**
+     * Manipula o filtro de busca
+     *
+     * @license    http://www.gnu.org/copyleft/gpl.html GPL
+	 * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)
+	 * @sponsor    Caixa Econômica Federal
+     * @param 	$search
+     * @param 	$targetTypes
+     * @param 	$customFilter
+     * @param 	$exact
+     */
     function getSearchFilter( $search, $targetTypes = false, $customFilter = '', $exact = false )
     {
         $search = utf8_encode( $search );
 
-	if( !$targetTypes )
-            $targetTypes = $this->allTargetTypes;
-
-	if( !is_array( $targetTypes ) )
-	    $targetTypes = array( $targetTypes );
-
-	$searchFilter = '';
-
-	foreach( $targetTypes as $targetType )
-	{
-	    switch( $targetType )
-	    {
-		case 'g':
+		if( !$targetTypes )
+				$targetTypes = $this->allTargetTypes;
+	
+		if( !is_array( $targetTypes ) )
+			$targetTypes = array( $targetTypes );
+	
+		$searchFilter = '';
+	
+		foreach( $targetTypes as $targetType )
 		{
-		    //no caso de grupos, a busca so precisa ser feita em cima do CN
-		    $searchFilter = $this->stemFilter( $search, 'cn' );
+			switch( $targetType )
+			{
+			case 'g':
+			{
+				//no caso de grupos, a busca so precisa ser feita em cima do CN
+				$searchFilter = $this->stemFilter( $search, 'cn' );
+			}
+			break;
+	
+			default :
+			{
+			//parametros que a busca tem que ser sintaticas
+				$searchFilter = /*array( */$this->stemFilter( $search, array(
+							// UID e employeeNumber podem ser iguais ou muito similares, dependendo da organizacao
+							'uid', /*'employeeNumber', */'cn',
+							// givenName e SN sao complementares (nome e sobrenome)
+							'givenName', 'sn', 'displayName' ) //),
+							//parametros que a busca pode ser por aproximacao fonetica
+						/*$this->approxFilter( $search, array( 
+							// O CN e displayName geralmente sao a mesma coisa
+							'cn', 'displayName' ))*/  );
+	
+				$searchFilter = $this->stemFilter( $search, array( 'cn', 'givenName', 'uid',
+										'sn', 'displayName' ) );
+			}
+			break;
+			}
 		}
-		break;
-
-		default :
+
+		$filter = array();
+	
+		if( $customFilter )
+			$filter[] = $customFilter;
+		if( $search )
+			$filter[] = $searchFilter;
+	
+		return $this->_and( array(
+			// Somente objetos relacionados com o Expresso
+			$this->accountFilter( $targetTypes ),
+			// Objetos ocultados e/ou desativados pelo Administrador nao podem ser exibidos nas consultas do Expresso
+			$this->securityFilter( $targetTypes ),
+			//foco da busca
+			( $exact ? $this->_and( $filter ) : $this->_or( $filter ) )
+			));
+	
+		// Verificoes extras para validar o resultado
+		//  (&
+		//     // Somente objetos com e-mail no formato da RFC822
+		//    (mail=*@*)
+		//  )
+	}
+
+	
+	/**
+     * Manipula o filtro de segurança
+     *
+     * @license    http://www.gnu.org/copyleft/gpl.html GPL
+	 * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)
+	 * @sponsor    Caixa Econômica Federal
+     * @param 	$targetTypes
+     */
+	function securityFilter( $targetTypes )
+    {
+		if( !$targetTypes )
+				$targetTypes = $this->allTargetTypes;
+
+		if( !is_array( $targetTypes ) )
+			$targetTypes = array( $targetTypes );
+	
+		$typeFilter = array();
+	
+		foreach( $targetTypes as $targetType )
 		{
-		   //parametros que a busca tem que ser sintaticas
-		    $searchFilter = /*array( */$this->stemFilter( $search, array(
-						// UID e employeeNumber podem ser iguais ou muito similares, dependendo da organizacao
-						'uid', /*'employeeNumber', */'cn',
-						// givenName e SN sao complementares (nome e sobrenome)
-						'givenName', 'sn', 'displayName' ) //),
-					    //parametros que a busca pode ser por aproximacao fonetica
-					   /*$this->approxFilter( $search, array( 
-						// O CN e displayName geralmente sao a mesma coisa
-						'cn', 'displayName' ))*/  );
-
-		    $searchFilter = $this->stemFilter( $search, array( 'cn', 'givenName', 'uid',
-								       'sn', 'displayName' ) );
+			switch( $targetType )
+			{
+			case 'g': $typeFilter[] = "(objectClass=posixGroup)";
+			break;
+			
+			default : $typeFilter[] = "(phpgwAccountStatus=A)";
+			break;
+			}
 		}
-		break;
-	    }
+
+		return $this->_and( array( '(!(phpgwAccountVisible=-1))', $this->_or( $typeFilter ) ) );
 	}
 
-	$filter = array();
-
-	if( $customFilter )
-	    $filter[] = $customFilter;
-	if( $search )
-	    $filter[] = $searchFilter;
-
-	return $this->_and( array(
-	    // Somente objetos relacionados com o Expresso
-	    $this->accountFilter( $targetTypes ),
-	    // Objetos ocultados e/ou desativados pelo Administrador nao podem ser exibidos nas consultas do Expresso
-	    $this->securityFilter( $targetTypes ),
-	    //foco da busca
-	    ( $exact ? $this->_and( $filter ) : $this->_or( $filter ) )
-	    ));
-
-	// Verificoes extras para validar o resultado
-	//  (&
-	//     // Somente objetos com e-mail no formato da RFC822
-	//    (mail=*@*)
-	//  )
-    }
-
-    function securityFilter( $targetTypes )
-    {
-	if( !$targetTypes )
-            $targetTypes = $this->allTargetTypes;
-
-	if( !is_array( $targetTypes ) )
-	    $targetTypes = array( $targetTypes );
-
-	$typeFilter = array();
-
-	foreach( $targetTypes as $targetType )
-	{
-	    switch( $targetType )
-	    {
-		case 'g': $typeFilter[] = "(objectClass=posixGroup)";
-		break;
-		
-		default : $typeFilter[] = "(phpgwAccountStatus=A)";
-		break;
-	    }
-	}
-
-	return $this->_and( array( '(!(phpgwAccountVisible=-1))', $this->_or( $typeFilter ) ) );
-    }
-
+	
+	/**
+     * Manipula o filtro da conta
+     *
+     * @license    http://www.gnu.org/copyleft/gpl.html GPL
+	 * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)
+	 * @sponsor    Caixa Econômica Federal
+     * @param 	$targetTypes
+     */
     function accountFilter( $targetTypes )
     {
@@ -189,34 +281,56 @@
     }
 
-    function stemFilter( $search, $params )
-    {
-	$search = str_replace( ' ', '*', $search );
-
-	if( !is_array( $params ) )
-	    $params = array( $params );
-
-	foreach( $params as $i => $param )
-	    $params[$i] = "($param=*$search*)";
-	
-	return $this->_or( $params );
-    }
-
-    function phoneticFilter( $search, $params )
-    {
-	if( eregi( "\d", $search ) )
-	    return( "" );
-
-	if( !is_array( $params ) )
-	    $params = array( $params );
-
-	foreach( $params as $i => $param )
-	    $params[$i] = "($param~=$search)";
-	
-	return $this->_or( $params );
-    }
-
+    
+	
+	/**
+     * @license    http://www.gnu.org/copyleft/gpl.html GPL
+	 * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)
+	 * @sponsor    Caixa Econômica Federal
+     * @param 	$search
+     * @param 	$params
+     */
+	function stemFilter( $search, $params )
+    {
+		$search = str_replace( ' ', '*', $search );
+	
+		if( !is_array( $params ) )
+			$params = array( $params );
+	
+		foreach( $params as $i => $param )
+			$params[$i] = "($param=*$search*)";
+		
+		return $this->_or( $params );
+    }
+
+    
+	/**
+     * Manipula o filtro fonético
+     *
+     * @license    http://www.gnu.org/copyleft/gpl.html GPL
+	 * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)
+	 * @sponsor    Caixa Econômica Federal
+     * @param 	$search
+     * @param 	$params
+     */
+	function phoneticFilter( $search, $params )
+    {
+		if( eregi( "\d", $search ) )
+			return( "" );
+	
+		if( !is_array( $params ) )
+			$params = array( $params );
+	
+		foreach( $params as $i => $param )
+			$params[$i] = "($param~=$search)";
+		
+		return $this->_or( $params );
+    }
+
+	
+	
+	
     function approxFilter( $search, $params )
     {
-	return $this->_or( array( $this->stemFilter( $search, $params ),
+		return $this->_or( array( $this->stemFilter( $search, $params ),
 				  $this->phoneticFilter( $search, $params ) ) );
     }
@@ -227,5 +341,18 @@
 //     }
 
-    public function accountSearch($search, $justthese = "*", $context = false , $accountType = false, $sort = false)
+    
+	/**
+     * Método que realiza a busca no LDAP
+     *
+     * @license    http://www.gnu.org/copyleft/gpl.html GPL
+	 * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)
+	 * @sponsor    Caixa Econômica Federal
+     * @param 	$search
+     * @param 	$justthese
+     * @param 	$context
+     * @param 	$accountType
+     * @param 	$sort
+     */
+	public function accountSearch($search, $justthese = "*", $context = false , $accountType = false, $sort = false)
     {
          if( !$this->connection )
Index: /trunk/services/class.mail.php
===================================================================
--- /trunk/services/class.mail.php	(revision 4445)
+++ /trunk/services/class.mail.php	(revision 5068)
@@ -1,3 +1,41 @@
 <?php
+/**
+*
+* Copyright (C) 2011 Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)
+*
+* This program is free software; you can redistribute it and/or modify it under
+* the terms of the GNU Affero General Public License version 3 as published by
+* the Free Software Foundation with the addition of the following permission
+* added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED
+* WORK IN WHICH THE COPYRIGHT IS OWNED BY FUNAMBOL, FUNAMBOL DISCLAIMS THE
+* WARRANTY OF NON INFRINGEMENT  OF THIRD PARTY RIGHTS.
+*
+* This program is distributed in the hope that it will be useful, but WITHOUT
+* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+* FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+* details.
+*
+* You should have received a copy of the GNU Affero General Public License
+* along with this program; if not, see www.gnu.org/licenses or write to
+* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+* MA 02110-1301 USA.
+*
+* This code is based on the OpenXchange Connector and on the Prognus pSync
+* Connector both developed by the community and licensed under the GPL
+* version 2 or above as published by the Free Software Foundation.
+*
+* You can contact Prognus Software Livre headquarters at Av. Tancredo Neves,
+* 6731, PTI, Bl. 05, Esp. 02, Sl. 10, Foz do Iguaçu - PR - Brasil or at
+* e-mail address prognus@prognus.com.br.
+*
+* Serviço de email
+*
+* @package    Services
+* @license    http://www.gnu.org/copyleft/gpl.html GPL
+* @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)
+* @version    1.0
+* @sponsor    Caixa Econômica Federal
+*/
+
 
 if( !function_exists( 'zend_include' ) )
@@ -14,95 +52,140 @@
 zend_include( 'Zend/Mail.php' );
 
+
+/**
+* Serviço de email
+*
+* Classe responsável pelas operações de email
+*
+* @package    Service
+* @license    http://www.gnu.org/copyleft/gpl.html GPL
+* @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)
+* @sponsor    Caixa Econômica Federal
+* @version    1.0
+*/
 class MailService extends Zend_Mail /*implements ConfigurationService, HookableService*/
 {
     static $configuration = array( 'host' => '', 'port' => '', 'username' => '', 'password' => '' );
 
-    public function __construct( $config = null)
-    {
-	if( !$config )
-	{
-	    require_once ( ROOT.'/header.inc.php' );
-
-	    $boemailadmin = CreateObject('emailadmin.bo');
-	    $emailadmin = $boemailadmin->getProfileList();
-	    $emailadmin = $boemailadmin->getProfile($emailadmin[0]['profileID']);
-		
-	    self::$configuration['host'] = $emailadmin['smtpServer'];
-	    self::$configuration['port'] = $emailadmin['smtpPort'];
-
-// 	    self::$configuration['username'] = $emailadmin['user'];
-// 	    self::$configuration['password'] = $emailadmin['pass'];
-// 	    self::$configuration['name'] = $emailadmin['name'];
-// 	    self::$configuration['type'] = 'SMTP';
-
-// 	    array_merge( $configuration, array( 'auth' => 'login' ) );
-
-	    zend_include( 'Zend/Mail/Transport/Smtp.php' );
-            zend_include( 'Zend/Mail/Part.php' );
-	    set_include_path(LIBRARY);
-	    parent::setDefaultTransport( new Zend_Mail_Transport_Smtp( self::$configuration['host'], self::$configuration ) );
-	    restore_include_path();
-	}
-
-	else
-	    $this->configure( $config );
-    }
-
-    public function send( $to, $from, $subject, $body, $bcc = null, $cc = null, $isHTML = true )
+    
+	/**
+     * Construtor da classe
+     *
+     * @license    http://www.gnu.org/copyleft/gpl.html GPL
+     * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)
+	 * @sponsor   Caixa Econômica Federal
+     * @param string $config
+     */
+	public function __construct( $config = null)
+    {
+		if( !$config )
+		{
+			require_once ( ROOT.'/header.inc.php' );
+	
+			$boemailadmin = CreateObject('emailadmin.bo');
+			$emailadmin = $boemailadmin->getProfileList();
+			$emailadmin = $boemailadmin->getProfile($emailadmin[0]['profileID']);
+			
+			self::$configuration['host'] = $emailadmin['smtpServer'];
+			self::$configuration['port'] = $emailadmin['smtpPort'];
+	
+		// 	    self::$configuration['username'] = $emailadmin['user'];
+		// 	    self::$configuration['password'] = $emailadmin['pass'];
+		// 	    self::$configuration['name'] = $emailadmin['name'];
+		// 	    self::$configuration['type'] = 'SMTP';
+	
+		// 	    array_merge( $configuration, array( 'auth' => 'login' ) );
+		
+			zend_include( 'Zend/Mail/Transport/Smtp.php' );
+				zend_include( 'Zend/Mail/Part.php' );
+			set_include_path(LIBRARY);
+			parent::setDefaultTransport( new Zend_Mail_Transport_Smtp( self::$configuration['host'], self::$configuration ) );
+			restore_include_path();
+		}
+	
+		else
+			$this->configure( $config );
+    }
+
+    
+	/**
+     * Método que envia a mensagem
+     *
+     * @license    http://www.gnu.org/copyleft/gpl.html GPL
+     * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)
+	 * @sponsor    Caixa Econômica Federal
+     * @param string $to
+     * @param string $from
+     * @param string $subject
+     * @param string $body
+     * @param string $bcc
+     * @param string $cc
+     * @param string $isHTML
+     */
+	public function send( $to, $from, $subject, $body, $bcc = null, $cc = null, $isHTML = true )
     {
         set_include_path( LIBRARY );
-	if( $body )
-	{
-	    if( $isHTML )
-		parent::setBodyHtml( $body );
-
-	    else
-		parent::setBodyText( $body );
-	}
-
-	if( $subject )
-	    parent::setSubject( $subject );
-
-	if( !$from )
-	    $from = $GLOBALS['phpgw']->preferences->values['email'];
-
-	parent::setFrom( $from, self::getNameByMail( $from ) );
-
-//pra nao ter que fazer os ifs acima...
-	$destTypes = array( 'to', 'bcc', 'cc' );
-
-	foreach( $destTypes as $destination )
-	{
-	    $dest = $$destination;
-	
-	    if( $dest )
-	    {
-		if( !is_array( $dest ) )
-		    $dest = array( $dest );
-
-		foreach( $dest as $d )
-		{
-		    $addDestination = 'add'.ucfirst($destination);
-
-		    parent::$addDestination( $d, self::getNameByMail( $d ) );
-		}
-	    }
-	}
-	
-	parent::send();
-	restore_include_path();
-    }
-
-    public function configure( $config )
-    {
-	if( !$config ) return( false );
-
-	foreach( $config as $key => $value )
-	{
-	    if( $value && isset( self::$configuration[$key] ) )
-	    {
-		self::$configuration[$key] = $value;
-	    }
-	}
+		if( $body )
+		{
+			if( $isHTML )
+			parent::setBodyHtml( $body );
+	
+			else
+			parent::setBodyText( $body );
+		}
+	
+		if( $subject )
+			parent::setSubject( $subject );
+		
+		if( !$from )
+			$from = $GLOBALS['phpgw']->preferences->values['email'];
+	
+		parent::setFrom( $from, self::getNameByMail( $from ) );
+	
+		//pra nao ter que fazer os ifs acima...
+		$destTypes = array( 'to', 'bcc', 'cc' );
+	
+		foreach( $destTypes as $destination )
+		{
+			$dest = $$destination;
+		
+			if( $dest )
+			{
+				if( !is_array( $dest ) )
+					$dest = array( $dest );
+	
+				foreach( $dest as $d )
+				{
+					$addDestination = 'add'.ucfirst($destination);
+		
+					parent::$addDestination( $d, self::getNameByMail( $d ) );
+				}
+			}
+		}
+	
+		parent::send();
+		restore_include_path();
+    }
+
+   
+	/**
+     * Método de configuração
+     *
+     * @license    http://www.gnu.org/copyleft/gpl.html GPL
+     * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)
+	 * @sponsor    Caixa Econômica Federal
+     * @param string $config
+     */
+	public function configure( $config )
+    {
+		if( !$config ) return( false );
+	
+		foreach( $config as $key => $value )
+		{
+			if( $value && isset( self::$configuration[$key] ) )
+			{
+			self::$configuration[$key] = $value;
+			}
+		}
     }
 
@@ -110,10 +193,10 @@
     public function getNameByMail( $mail )
     {
-	return( null );
+		return( null );
     }
 
     public function getAttachment( $attachment )
     {
-	return( null );
+		return( null );
     }
 
