Changeset 5130 for trunk


Ignore:
Timestamp:
11/03/11 11:13:40 (12 years ago)
Author:
wmerlotto
Message:

Ticket #2305 - Enviando alteracoes, desenvolvidas internamente na Prognus, do modulo services.

Location:
trunk/services
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/services/class.db.php

    r5072 r5130  
    44* Copyright (C) 2011 Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 
    55* 
    6 * This program is free software; you can redistribute it and/or modify it under 
    7 * the terms of the GNU Affero General Public License version 3 as published by 
    8 * the Free Software Foundation with the addition of the following permission 
    9 * added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED 
    10 * WORK IN WHICH THE COPYRIGHT IS OWNED BY FUNAMBOL, FUNAMBOL DISCLAIMS THE 
    11 * WARRANTY OF NON INFRINGEMENT  OF THIRD PARTY RIGHTS. 
    12 * 
    13 * This program is distributed in the hope that it will be useful, but WITHOUT 
    14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
    15 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more 
    16 * details. 
    17 * 
    18 * You should have received a copy of the GNU Affero General Public License 
    19 * along with this program; if not, see www.gnu.org/licenses or write to 
    20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
    21 * MA 02110-1301 USA. 
    22 * 
    23 * This code is based on the OpenXchange Connector and on the Prognus pSync 
    24 * Connector both developed by the community and licensed under the GPL 
    25 * version 2 or above as published by the Free Software Foundation. 
     6*  This program is free software; you can redistribute it and/or 
     7*  modify it under the terms of the GNU General Public License 
     8*  as published by the Free Software Foundation; either version 2 
     9*  of the License, or (at your option) any later version. 
     10* 
     11*  This program is distributed in the hope that it will be useful, 
     12*  but WITHOUT ANY WARRANTY; without even the implied warranty of 
     13*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     14*  GNU General Public License for more details. 
     15* 
     16*  You should have received a copy of the GNU General Public License 
     17*  along with this program; if not, write to the Free Software 
     18*  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.  
    2619* 
    2720* You can contact Prognus Software Livre headquarters at Av. Tancredo Neves, 
     
    2922* e-mail address prognus@prognus.com.br. 
    3023* 
    31 * Serviço de banco de dados 
    32 * 
    33 * Serviço que faz a busca no banco de dados para retornar os usuários, de acordo com o parâmetro de busca. 
    34 * 
    35 * @package    <services> 
     24* 
     25* @package    DBService 
    3626* @license    http://www.gnu.org/copyleft/gpl.html GPL 
    3727* @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 
     28* @sponsor    Caixa Econômica Federal 
    3829* @version    1.0 
    39 * @sponsor    Caixa Econômica Federal 
     30* @since      2.4.0 
    4031*/ 
    4132 
     
    119110                                $query .= ' where ' 
    120111                                        . 'A.id_owner=' . $_SESSION['phpgw_info']['expressomail']['user']['account_id'] 
    121                                         . ' and names_ordered LIKE \'%' . $search_for . '%\'';                          
     112                                        . ' and lower(to_ascii(names_ordered)) LIKE lower(to_ascii(\'%' . $search_for . '%\'))';                          
    122113                                 
    123114        if (!$this->db->query($query)) 
  • trunk/services/class.ical.php

    r4445 r5130  
    11<?php 
    22/** 
     3* 
     4* Copyright (C) 2011 Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 
     5* 
     6*  This program is free software; you can redistribute it and/or 
     7*  modify it under the terms of the GNU General Public License 
     8*  as published by the Free Software Foundation; either version 2 
     9*  of the License, or (at your option) any later version. 
     10 
     11*  This program is distributed in the hope that it will be useful, 
     12*  but WITHOUT ANY WARRANTY; without even the implied warranty of 
     13*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     14*  GNU General Public License for more details. 
     15 
     16*  You should have received a copy of the GNU General Public License 
     17*  along with this program; if not, write to the Free Software 
     18*  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.  
     19* 
     20*  You can contact Prognus Software Livre headquarters at Av. Tancredo Neves, 
     21*  6731, PTI, Bl. 05, Esp. 02, Sl. 10, Foz do Iguaçu - PR - Brasil or at 
     22*  e-mail address prognus@prognus.com.br. 
     23* 
     24* 
    325* Serviço ical 
    426* 
    527* Classe responsavel por gerar, e interpretar arquivos ical/vcalendar. 
    628* 
    7 * @package    Service 
     29* @package    ICalService 
    830* @license    http://www.gnu.org/copyleft/gpl.html GPL 
    9 * @author     Prognus Software Livre (http://www.prognus.com.br) 
    10 * @author     Cristiano Corr?a Schmidt 
     31* @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 
     32* @sponsor    Caixa Econômica Federal 
    1133* @version    1.0 
    12 * @since      Classe disponibilizada na versão 1.0 
     34* @since      2.4.0 
    1335*/ 
    1436class ICalService 
  • trunk/services/class.ldap.php

    r5068 r5130  
    44* Copyright (C) 2011 Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 
    55* 
    6 * This program is free software; you can redistribute it and/or modify it under 
    7 * the terms of the GNU Affero General Public License version 3 as published by 
    8 * the Free Software Foundation with the addition of the following permission 
    9 * added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED 
    10 * WORK IN WHICH THE COPYRIGHT IS OWNED BY FUNAMBOL, FUNAMBOL DISCLAIMS THE 
    11 * WARRANTY OF NON INFRINGEMENT  OF THIRD PARTY RIGHTS. 
    12 * 
    13 * This program is distributed in the hope that it will be useful, but WITHOUT 
    14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
    15 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more 
    16 * details. 
    17 * 
    18 * You should have received a copy of the GNU Affero General Public License 
    19 * along with this program; if not, see www.gnu.org/licenses or write to 
    20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
    21 * MA 02110-1301 USA. 
    22 * 
    23 * This code is based on the OpenXchange Connector and on the Prognus pSync 
    24 * Connector both developed by the community and licensed under the GPL 
    25 * version 2 or above as published by the Free Software Foundation. 
     6*  This program is free software; you can redistribute it and/or 
     7*  modify it under the terms of the GNU General Public License 
     8*  as published by the Free Software Foundation; either version 2 
     9*  of the License, or (at your option) any later version. 
     10* 
     11*  This program is distributed in the hope that it will be useful, 
     12*  but WITHOUT ANY WARRANTY; without even the implied warranty of 
     13*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     14*  GNU General Public License for more details. 
     15* 
     16*  You should have received a copy of the GNU General Public License 
     17*  along with this program; if not, write to the Free Software 
     18*  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.  
    2619* 
    2720* You can contact Prognus Software Livre headquarters at Av. Tancredo Neves, 
     
    2922* e-mail address prognus@prognus.com.br. 
    3023* 
    31 * Serviço de LDAP 
    32 * 
    33 * @package    Services 
    34 * @license    http://www.gnu.org/copyleft/gpl.html GPL 
    35 * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 
    36 * @version    1.0 
    37 * @sponsor    Caixa Econômica Federal 
    38 */ 
    39  
    40  
    41  
    42  
    43 /** 
    44 * Serviço Ldap 
    45 * 
    46 * Classe responsável pelas operações com o LDAP 
    47 * 
    48 * @package    Service 
     24* 
     25* @package    LdapService 
    4926* @license    http://www.gnu.org/copyleft/gpl.html GPL 
    5027* @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 
    5128* @sponsor    Caixa Econômica Federal 
    5229* @version    1.0 
     30* @since      2.4.0 
    5331*/ 
     32 
    5433class LdapService 
    5534{ 
     
    6241    function LdapService() 
    6342    { 
    64          
    65     } 
    66  
    67          
    68         /** 
    69      * Conecta com o LDAP 
    70      * 
    71      * @license    http://www.gnu.org/copyleft/gpl.html GPL 
    72          * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 
    73          * @sponsor    Caixa Econômica Federal 
    74      * @param   $host 
    75      * @param   $dn 
    76      * @param   $passwd 
    77      * @param   $ldapreferral 
    78      */ 
     43        if(isset($GLOBALS['phpgw_info']['server']['ldap_context']) ) 
     44                        $this->context = $GLOBALS['phpgw_info']['server']['ldap_context']; 
     45    } 
     46 
     47        public function setContext( $pContext )  
     48            {  
     49                $this->context = $pContext;  
     50            }  
     51         
    7952    function connect($host='', $dn='', $passwd='', $ldapreferral=false) 
    8053    { 
     
    11386                        return( $toWrap ); 
    11487         
    115                 //      if( count( $toWrap ) <= 1 ) 
    116                 //          return implode( "", $toWrap ); 
    117          
    11888                return $this->wrap( $toWrap, '|' ); 
    11989    } 
     
    12494                        return( $toWrap ); 
    12595         
    126                 //      if( count( $toWrap ) <= 1 ) 
    127                 //          return implode( "", $toWrap ); 
    128          
    12996                return $this->wrap( $toWrap, '&' ); 
    13097    } 
     
    145112    } 
    146113 
    147         /** 
    148      * Manipula o filtro de busca 
    149      * 
    150      * @license    http://www.gnu.org/copyleft/gpl.html GPL 
    151          * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 
    152          * @sponsor    Caixa Econômica Federal 
    153      * @param   $search 
    154      * @param   $targetTypes 
    155      * @param   $customFilter 
    156      * @param   $exact 
    157      */ 
    158114    function getSearchFilter( $search, $targetTypes = false, $customFilter = '', $exact = false ) 
    159115    { 
     
    186142                                                        'uid', /*'employeeNumber', */'cn', 
    187143                                                        // givenName e SN sao complementares (nome e sobrenome) 
    188                                                         'givenName', 'sn', 'displayName' ) //), 
     144                                                'givenName', 'sn', 'displayName', 'mail', 'mailAlternateAddress' ) //), 
    189145                                                        //parametros que a busca pode ser por aproximacao fonetica 
    190146                                                /*$this->approxFilter( $search, array(  
     
    193149         
    194150                                $searchFilter = $this->stemFilter( $search, array( 'cn', 'givenName', 'uid', 
    195                                                                                 'sn', 'displayName' ) ); 
     151                                                                       'sn', 'displayName', 'mail', 'mailAlternateAddress' ) ); 
    196152                        } 
    197153                        break; 
     
    215171                        )); 
    216172         
    217                 // Verificoes extras para validar o resultado 
    218                 //  (& 
    219                 //     // Somente objetos com e-mail no formato da RFC822 
    220                 //    (mail=*@*) 
    221                 //  ) 
    222173        } 
    223174 
    224          
    225         /** 
    226      * Manipula o filtro de segurança 
    227      * 
    228      * @license    http://www.gnu.org/copyleft/gpl.html GPL 
    229          * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 
    230          * @sponsor    Caixa Econômica Federal 
    231      * @param   $targetTypes 
    232      */ 
    233175        function securityFilter( $targetTypes ) 
    234176    { 
     
    248190                        break; 
    249191                         
    250                         default : $typeFilter[] = "(phpgwAccountStatus=A)"; 
     192                default : $typeFilter[] = "(phpgwAccountStatus=A)(accountStatus=active)"; 
    251193                        break; 
    252194                        } 
     
    256198        } 
    257199 
    258          
    259         /** 
    260      * Manipula o filtro da conta 
    261      * 
    262      * @license    http://www.gnu.org/copyleft/gpl.html GPL 
    263          * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 
    264          * @sponsor    Caixa Econômica Federal 
    265      * @param   $targetTypes 
    266      */ 
    267200    function accountFilter( $targetTypes ) 
    268201    { 
     
    281214    } 
    282215 
    283      
    284          
    285         /** 
    286      * @license    http://www.gnu.org/copyleft/gpl.html GPL 
    287          * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 
    288          * @sponsor    Caixa Econômica Federal 
    289      * @param   $search 
    290      * @param   $params 
    291      */ 
    292216        function stemFilter( $search, $params ) 
    293217    { 
     
    303227    } 
    304228 
    305      
    306         /** 
    307      * Manipula o filtro fonético 
    308      * 
    309      * @license    http://www.gnu.org/copyleft/gpl.html GPL 
    310          * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 
    311          * @sponsor    Caixa Econômica Federal 
    312      * @param   $search 
    313      * @param   $params 
    314      */ 
    315229        function phoneticFilter( $search, $params ) 
    316230    { 
     
    336250    } 
    337251 
    338 //     public function search() 
    339 //     { 
    340 //       
    341 //     } 
    342  
    343      
    344         /** 
    345      * Método que realiza a busca no LDAP 
    346      * 
    347      * @license    http://www.gnu.org/copyleft/gpl.html GPL 
    348          * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 
    349          * @sponsor    Caixa Econômica Federal 
    350      * @param   $search 
    351      * @param   $justthese 
    352      * @param   $context 
    353      * @param   $accountType 
    354      * @param   $sort 
    355      */ 
    356252        public function accountSearch($search, $justthese = "*", $context = false , $accountType = false, $sort = false) 
    357253    { 
     
    362258 
    363259         if( !$context ) 
    364              $context = $GLOBALS['phpgw_info']['server']['ldap_context']; 
    365  
    366          $ls = ldap_search( $this->connection, utf8_encode($context), $filter, $justthese, 0, $this->limit ); 
     260             $context = $this->context; 
     261 
     262         $sr = ldap_search( $this->connection, utf8_encode($context), $filter, $justthese, 0, $this->limit );  
     263 
     264                 if(!$sr) return false;  
    367265 
    368266         if($sort) 
    369              ldap_sort( $this->connection, $ls, $sort ); 
    370  
    371          $entries = ldap_get_entries( $this->connection, $ls ); 
    372  
    373          if( !$entries ) return( null ); 
     267             ldap_sort( $this->connection, $sr, $sort );  
     268 
     269                         return $this->formatEntries( ldap_get_entries( $this->connection, $sr ) );  
     270                    }  
     271                      
     272                    private function formatEntries ( $pEntries )  
     273                    {       
     274 
     275                         if( !$pEntries ) return( false );   
    374276 
    375277         $return = array(); 
    376278 
    377          for ($i=0; $i < $entries["count"]; $i++) 
     279         for ($i=0; $i < $pEntries["count"]; $i++) 
    378280         { 
    379281               $entrieTmp = array(); 
    380                foreach ($entries[$i] as $index => $value) 
     282               foreach ($pEntries[$i] as $index => $value) 
    381283               { 
    382284                   if(!is_numeric($index) && $index != 'count') 
     
    406308    } 
    407309 
     310                        /**  
     311                    * Retorna o endereço de e-mail da conta pelo uidNumber  
     312                    *  
     313                    * @license    http://www.gnu.org/copyleft/gpl.html GPL  
     314                    * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)  
     315                    * @sponsor    Caixa Econômica Federal  
     316                    * @author     Cristiano Corrêa Schmidt  
     317                    * @param      int $pUidNumber uidNumber da conta  
     318                        * @return     string  
     319                    * @access     public  
     320                    */  
     321                    public function getMailByUidNumber( $pUidNumber )  
     322                    {  
     323                        if( !$this->connection ) $this->connect();  
     324                        $sr =  ldap_search( $this->connection, $this->context, '(uidNumber='.$pUidNumber.')', array('mail') );  
     325                        if(!$sr) return false;  
     326                            
     327                        $return = ldap_get_entries( $this->connection, $sr );  
     328                        return   $return[0]['mail'][0];  
     329                    }  
     330                      
     331                    /**  
     332                    * Retorna em um array os endereços de e-mails alternativos da conta pelo uidNumber  
     333                    *  
     334                    * @license    http://www.gnu.org/copyleft/gpl.html GPL  
     335                    * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)  
     336                    * @sponsor    Caixa Econômica Federal  
     337                    * @author     Cristiano Corrêa Schmidt  
     338                    * @param      int $pUidNumber uidNumber da conta  
     339                    * @return     Array  
     340                    * @access     public  
     341                    */  
     342                    public function getMailAlternateByUidNumber( $pUidNumber )  
     343                    {  
     344                         if( !$this->connection ) $this->connect();  
     345                           
     346                         $sr = ldap_search( $this->connection, $this->context, '(uidNumber='.$pUidNumber.')', array('mailAlternateAddress'));  
     347                         if(!$sr) return false;  
     348                           
     349                         $returnL = ldap_get_entries( $this->connection,$sr);  
     350                         $return = array();  
     351                         foreach ($returnL[0]['mailalternateaddress'] as $i => $v)  
     352                         {  
     353                             if($i === 'count') continue;  
     354                             $return[] = $v;  
     355                         }  
     356                         return $return;  
     357                    }  
     358 
    408359} 
    409360 
  • trunk/services/class.mail.php

    r5068 r5130  
    22/** 
    33* 
    4 * Copyright (C) 2011 Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 
    5 * 
    6 * This program is free software; you can redistribute it and/or modify it under 
    7 * the terms of the GNU Affero General Public License version 3 as published by 
    8 * the Free Software Foundation with the addition of the following permission 
    9 * added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED 
    10 * WORK IN WHICH THE COPYRIGHT IS OWNED BY FUNAMBOL, FUNAMBOL DISCLAIMS THE 
    11 * WARRANTY OF NON INFRINGEMENT  OF THIRD PARTY RIGHTS. 
    12 * 
    13 * This program is distributed in the hope that it will be useful, but WITHOUT 
    14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
    15 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more 
    16 * details. 
    17 * 
    18 * You should have received a copy of the GNU Affero General Public License 
    19 * along with this program; if not, see www.gnu.org/licenses or write to 
    20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
    21 * MA 02110-1301 USA. 
    22 * 
    23 * This code is based on the OpenXchange Connector and on the Prognus pSync 
    24 * Connector both developed by the community and licensed under the GPL 
    25 * version 2 or above as published by the Free Software Foundation. 
     4* Copyright (C) 2011 Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 
     5* 
     6*  This program is free software; you can redistribute it and/or 
     7*  modify it under the terms of the GNU General Public License 
     8*  as published by the Free Software Foundation; either version 2 
     9*  of the License, or (at your option) any later version. 
     10 
     11*  This program is distributed in the hope that it will be useful, 
     12*  but WITHOUT ANY WARRANTY; without even the implied warranty of 
     13*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     14*  GNU General Public License for more details. 
     15 
     16*  You should have received a copy of the GNU General Public License 
     17*  along with this program; if not, write to the Free Software 
     18*  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.  
    2619* 
    2720* You can contact Prognus Software Livre headquarters at Av. Tancredo Neves, 
    28 * 6731, PTI, Bl. 05, Esp. 02, Sl. 10, Foz do Iguaçu - PR - Brasil or at 
     21*  6731, PTI, Bl. 05, Esp. 02, Sl. 10, Foz do Iguaçu - PR - Brasil or at 
    2922* e-mail address prognus@prognus.com.br. 
    3023* 
    31 * Serviço de email 
    32 * 
    33 * @package    Services 
     24* 
     25* @package    MailService 
    3426* @license    http://www.gnu.org/copyleft/gpl.html GPL 
    35 * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 
     27* @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 
     28* @sponsor    Caixa EconÃŽmica Federal 
    3629* @version    1.0 
    37 * @sponsor    Caixa Econômica Federal 
     30* @since      2.4.0 
    3831*/ 
    3932 
    40  
    41 if( !function_exists( 'zend_include' ) ) 
     33require_once ( $_SESSION['rootPath'].'/library/mime/mimePart.php' ); 
     34require_once ( $_SESSION['rootPath'].'/library/mime/mime.php' ); 
     35 
     36 
     37class MailService  
    4238{ 
    43     function zend_include( $path ) 
    44     { 
    45         set_include_path( LIBRARY ); 
    46         require_once( $path ); 
    47         restore_include_path(); 
    48     } 
    49 } 
    50  
    51  
    52 zend_include( 'Zend/Mail.php' ); 
    53  
    54  
    55 /** 
    56 * Serviço de email 
    57 * 
    58 * Classe responsável pelas operações de email 
    59 * 
    60 * @package    Service 
    61 * @license    http://www.gnu.org/copyleft/gpl.html GPL 
    62 * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 
    63 * @sponsor    Caixa Econômica Federal 
    64 * @version    1.0 
    65 */ 
    66 class MailService extends Zend_Mail /*implements ConfigurationService, HookableService*/ 
    67 { 
    68     static $configuration = array( 'host' => '', 'port' => '', 'username' => '', 'password' => '' ); 
    69  
    70      
    71         /** 
    72      * Construtor da classe 
    73      * 
    74      * @license    http://www.gnu.org/copyleft/gpl.html GPL 
    75      * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 
    76          * @sponsor   Caixa Econômica Federal 
    77      * @param string $config 
    78      */ 
     39    static $configuration = array( 'host' => '', 'port' => '', 'username' => '', 'password' => '' , 'auth' => ''); 
     40    protected $mail; 
     41    protected $smtpConfig; 
     42    protected $arrayFields = array(); 
     43     
    7944        public function __construct( $config = null) 
    8045    { 
     46       $this->mail = new Mail_mime(); 
     47         
    8148                if( !$config ) 
    8249                { 
     
    8956                        self::$configuration['host'] = $emailadmin['smtpServer']; 
    9057                        self::$configuration['port'] = $emailadmin['smtpPort']; 
    91          
    92                 //          self::$configuration['username'] = $emailadmin['user']; 
    93                 //          self::$configuration['password'] = $emailadmin['pass']; 
    94                 //          self::$configuration['name'] = $emailadmin['name']; 
    95                 //          self::$configuration['type'] = 'SMTP'; 
    96          
    97                 //          array_merge( $configuration, array( 'auth' => 'login' ) ); 
    98                  
    99                         zend_include( 'Zend/Mail/Transport/Smtp.php' ); 
    100                                 zend_include( 'Zend/Mail/Part.php' ); 
    101                         set_include_path(LIBRARY); 
    102                         parent::setDefaultTransport( new Zend_Mail_Transport_Smtp( self::$configuration['host'], self::$configuration ) ); 
    103                         restore_include_path(); 
     58            self::$configuration['auth'] = $emailadmin['smtpAuth'] ? true : false; 
     59            self::$configuration['username'] = $emailadmin['imapAdminUsername']; 
     60            self::$configuration['password'] = $emailadmin['imapAdminPW']; 
    10461                } 
    105          
    10662                else 
    10763                        $this->configure( $config ); 
    108     } 
    109  
    110      
    111         /** 
    112      * Método que envia a mensagem 
    113      * 
    114      * @license    http://www.gnu.org/copyleft/gpl.html GPL 
    115      * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 
    116          * @sponsor    Caixa Econômica Federal 
    117      * @param string $to 
    118      * @param string $from 
    119      * @param string $subject 
    120      * @param string $body 
    121      * @param string $bcc 
    122      * @param string $cc 
    123      * @param string $isHTML 
    124      */ 
    125         public function send( $to, $from, $subject, $body, $bcc = null, $cc = null, $isHTML = true ) 
    126     { 
    127         set_include_path( LIBRARY ); 
     64 
     65    } 
     66     
     67    public function sendMail( $to, $from, $subject, $body, $bcc = false, $cc = false, $isHTML = true ) 
     68    { 
     69         
    12870                if( $body ) 
    12971                { 
    130                         if( $isHTML ) 
    131                         parent::setBodyHtml( $body ); 
    132          
    133                         else 
    134                         parent::setBodyText( $body ); 
     72            if( $isHTML ) $this->mail->setHTMLBody( $body ); 
     73            else $this->mail->setTXTBody( $body ); 
    13574                } 
    13675         
    137                 if( $subject ) 
    138                         parent::setSubject( $subject ); 
    139                  
    140                 if( !$from ) 
    141                         $from = $GLOBALS['phpgw']->preferences->values['email']; 
    142          
    143                 parent::setFrom( $from, self::getNameByMail( $from ) ); 
    144          
    145                 //pra nao ter que fazer os ifs acima... 
    146                 $destTypes = array( 'to', 'bcc', 'cc' ); 
    147          
    148                 foreach( $destTypes as $destination ) 
    149                 { 
    150                         $dest = $$destination; 
    151                  
    152                         if( $dest ) 
    153                         { 
    154                                 if( !is_array( $dest ) ) 
    155                                         $dest = array( $dest ); 
    156          
    157                                 foreach( $dest as $d ) 
    158                                 { 
    159                                         $addDestination = 'add'.ucfirst($destination); 
    160                  
    161                                         parent::$addDestination( $d, self::getNameByMail( $d ) ); 
    162                                 } 
    163                         } 
    164                 } 
    165          
    166                 parent::send(); 
    167                 restore_include_path(); 
    168     } 
    169  
     76        if( $subject ) $this->mail->setSubject ( $subject ); 
     77                 
     78        if( !$from ) $from = $GLOBALS['phpgw']->preferences->values['email']; 
     79         
     80        $this->mail->setFrom( $from ); 
     81         
     82        $this->mail->addTo($to); 
     83         
     84        if( $bcc ) $this->mail->addBcc ($bbc); 
     85                 
     86        if( $cc ) $this->mail->addCc ($cc); 
     87         
     88        $hdrs = $this->mail->headers($this->arrayFields); 
     89                 
     90        require_once ($_SESSION['rootPath'].'/library/Mail/Mail.php'); 
     91        
     92        $mail_object =& Mail::factory("smtp", self::$configuration); 
     93         
     94        $recipients = ''; 
     95                 
     96                if( $hdrs["To"] )  
     97                        $recipients .= $hdrs["To"]; 
     98                if( $hdrs["Cc"] && $recipients)  
     99                        $recipients .= ', '.$hdrs["Cc"]; 
     100                if($hdrs["Cc"] && !$recipients) 
     101                        $recipients = $hdrs["Cc"]; 
     102         
     103        if($hdrs["Bcc"]) 
     104            $arrayBcc = explode(',',$hdrs["Bcc"]); 
     105         
     106        if($recipients) 
     107                $sent = $mail_object->send($recipients, $hdrs , $this->mail->getMessageBody());  
     108                 
     109        if(isset($arrayBcc)){ 
     110                foreach ($arrayBcc as $bcc) 
     111                        if($bcc) 
     112                                $sent = $mail_object->send($bcc, $hdrs , $this->mail->getMessageBody());  
     113    } 
     114        if($sent !== true) 
     115                return $sent->message; 
     116 
     117                return true; 
     118    } 
    170119    
    171         /** 
    172      * Método de configuração 
    173      * 
    174      * @license    http://www.gnu.org/copyleft/gpl.html GPL 
    175      * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 
    176          * @sponsor    Caixa Econômica Federal 
    177      * @param string $config 
    178      */ 
    179120        public function configure( $config ) 
    180121    { 
     
    182123         
    183124                foreach( $config as $key => $value ) 
    184                 { 
    185125                        if( $value && isset( self::$configuration[$key] ) ) 
    186                         { 
    187126                        self::$configuration[$key] = $value; 
    188127                        } 
     128     
     129    public function send() 
     130    { 
     131        require_once ($_SESSION['rootPath'].'/library/Mail/Mail.php'); 
     132        $hdrs = $this->mail->headers($this->arrayFields); 
     133        $mail_object =& Mail::factory("smtp", self::$configuration); 
     134         
     135        $recipients = ''; 
     136                 
     137                if( $hdrs["To"] )  
     138                        $recipients .= $hdrs["To"]; 
     139                if( $hdrs["Cc"] && $recipients)  
     140                        $recipients .= ', '.$hdrs["Cc"]; 
     141                if($hdrs["Cc"] && !$recipients) 
     142                        $recipients = $hdrs["Cc"]; 
     143         
     144        if($hdrs["Bcc"]) 
     145            $arrayBcc = explode(',',$hdrs["Bcc"]); 
     146         
     147        if($recipients) 
     148                $sent = $mail_object->send($recipients, $hdrs , $this->mail->getMessageBody());  
     149                 
     150        if(isset($arrayBcc)){ 
     151                foreach ($arrayBcc as $bcc) 
     152                        if($bcc) 
     153                                $sent = $mail_object->send($bcc, $hdrs , $this->mail->getMessageBody());  
     154        } 
     155        if($sent !== true) 
     156                return $sent->message; 
     157         
     158                return true; 
     159    } 
     160 
     161    public function  addStringAttachment($file, $filename, $type, $encoding = 'base64', $disposition = 'attachment') 
     162    {            
     163                $this->mail->addAttachment($file, $type, $filename, false, $encoding, $disposition , $charset = '' ,  $language = '' ,  $location = '' ,  $n_encoding = 'base64'); 
     164    } 
     165     
     166    public function  addFileAttachment($file, $filename, $type, $encoding = 'base64', $disposition = 'attachment') 
     167    {      
     168        $this->mail->addAttachment($file, $type, $filename, true, $encoding, $disposition, $charset = '' ,  $language = '' ,  $location = '' ,  $n_encoding = 'base64'); 
     169    } 
     170     
     171    public function addFileImage($file, $c_type='application/octet-stream', $name = '',  $content_id = null) 
     172    { 
     173          $this->mail->addHTMLImage($file, $c_type, $name, true, $content_id ); 
    189174                } 
    190     } 
    191  
    192     //hook 
    193     public function getNameByMail( $mail ) 
    194     { 
    195                 return( null ); 
    196     } 
    197  
    198     public function getAttachment( $attachment ) 
    199     { 
    200                 return( null ); 
    201     } 
    202  
    203      /** 
    204      * Adds attachment to the mail message 
    205      * 
    206      * @param string $file  binary file 
    207      * @param string $filename file name 
    208      * @param string $type type example: image/gif 
    209      * @param Zend_Mime $disposition example: Zend_Mime::DISPOSITION_INLINE 
    210      * @param Zend_Mime $encoding example: Zend_Mime::ENCODING_BASE64 
    211      * @return bool 
    212      */ 
    213     public function  addAttachment($file, $filename, $type, $encoding = null, $disposition = 'DISPOSITION_ATTACHMENT') 
    214     { 
    215         $part = new Zend_Mime_Part( $file ); 
    216  
    217         $part->type = $type; 
    218         $part->filename = $filename; 
    219  
    220        switch ($disposition) 
     175     
     176    public function  addStringImage($file, $c_type='application/octet-stream', $name = '',  $content_id = null) 
     177    {        
     178        $this->mail->addHTMLImage($file, $c_type, $name, false, $content_id ); 
     179    } 
     180 
     181    public function  getMessage() 
     182    { 
     183         return $this->mail->getMessage(null,null,$this->arrayFields); 
     184    } 
     185 
     186    public function addTo($email) 
     187    { 
     188        $this->mail->addTo($email); 
     189    } 
     190 
     191    public function addCc($email) 
     192    { 
     193        $this->mail->addCc($email); 
     194    } 
     195 
     196    public function addBcc($email) 
     197    { 
     198       $this->mail->addBcc($email); 
     199    } 
     200 
     201    public function setSubject($subject) 
    221202       { 
    222             case 'DISPOSITION_INLINE': 
    223                 $part->disposition = Zend_Mime::DISPOSITION_INLINE; 
    224                 break; 
    225             case 'DISPOSITION_ATTACHMENT': 
    226                 $part->disposition = Zend_Mime::DISPOSITION_ATTACHMENT; 
    227                 break; 
    228             default:   
    229                 break; 
     203       $this->mail->setSubject($subject); 
    230204        } 
    231205         
    232         switch ($encoding) 
     206    public function setFrom($email) 
    233207        { 
    234             case 'ENCODING_7BIT': 
    235                 $part->encoding = Zend_Mime::ENCODING_7BIT; 
    236                 break; 
    237             case 'ENCODING_8BIT:': 
    238                 $part->encoding = Zend_Mime::ENCODING_8BIT; 
    239                 break; 
    240             case 'ENCODING_QUOTEDPRINTABLE:': 
    241                 $part->encoding = Zend_Mime::ENCODING_QUOTEDPRINTABLE; 
    242                 break; 
    243             default: 
    244                 $part->encoding = Zend_Mime::ENCODING_BASE64; 
    245                 break; 
     208        $this->mail->setFrom($email); 
    246209        } 
    247210 
    248         parent::addAttachment( $part ); 
    249  
    250         return; 
    251     } 
     211    public function setBodyText($data) 
     212    { 
     213        $this->mail->setTXTBody($data); 
     214    } 
     215 
     216    public function setBodyHtml($data) 
     217    { 
     218        $this->mail->setHTMLBody($data); 
     219    } 
     220     
     221    public function getBodyHtml() 
     222    { 
     223        return $this->mail->getHTMLBody(); 
     224    } 
     225          
     226    public function addHeaderField($field,$value) 
     227    { 
     228        $this->arrayFields[$field] = $value; 
     229    } 
     230     
    252231} 
    253232 
Note: See TracChangeset for help on using the changeset viewer.