Ignore:
Timestamp:
04/22/09 13:59:35 (15 years ago)
Author:
niltonneto
Message:

Resolve #453

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/expressoMail1_2/inc/class.db_functions.inc.php

    r673 r757  
    1010        var $db; 
    1111        var $user_id; 
     12        var $related_ids;  
    1213         
    1314        function db_functions(){ 
     
    3031                $result = array(); 
    3132                $stringDropDownContacts = '';            
    32                 // Traz primeiro os usuarios que compartilharam com o usuario logado: 
    33                 $query = 'select id_related from phpgw_cc_contact_rels where id_contact='.$this -> user_id.' and id_typeof_contact_relation=1'; 
    34                 // Somente do usuario logado 
    35                 $query_related = 'A.id_owner ='.$this -> user_id; 
    36                 if (!$this->db->query($query)) 
    37                 return null;                     
    38                 while($this->db->next_record()){ 
    39                         $row = $this->db->row(); 
    40                         $result[] = $row['id_related']; 
    41                 } 
    42                 $ids_related = implode(",",$result); 
    43  
    44                 // Se houver contatos compartilhados então altera a query. 
    45                 if($ids_related)                 
    46                         $query_related = '(A.id_owner ='.$this -> user_id.' or A.id_owner in ('.$ids_related.'))'; 
     33                 
     34                $query_related = $this->get_query_related('A.id_owner'); // field name for owner 
    4735                         
    4836                // Traz os contatos pessoais e compartilhados 
     
    5038                        'phpgw_cc_contact_conns B, phpgw_cc_connections C where '. 
    5139                        'A.id_contact = B.id_contact and B.id_connection = C.id_connection '. 
    52                         'and B.id_typeof_contact_connection = 1 and '.$query_related.' group by '.  
    53                         'A.names_ordered,C.connection_value     order by A.names_ordered'; 
    54  
     40                        'and B.id_typeof_contact_connection = 1 and ('.$query_related.') group by '.  
     41                        'A.names_ordered,C.connection_value     order by lower(A.names_ordered)'; 
     42                 
    5543        if (!$this->db->query($query)) 
    5644                return null; 
     
    7159                return $stringDropDownContacts; 
    7260        } 
    73          
     61        // Get Related Ids for sharing contacts or groups. 
     62        function get_query_related($field_name){                 
     63                $query_related = $field_name .'='.$this -> user_id; 
     64                // Only at first time, it gets all related ids... 
     65                if(!$this->related_ids) { 
     66                        $query = 'select id_related from phpgw_cc_contact_rels where id_contact='.$this -> user_id.' and id_typeof_contact_relation=1';          
     67                        if (!$this->db->query($query)){ 
     68                return $query_related; 
     69                        } 
     70                         
     71                        while($this->db->next_record()){ 
     72                                $row = $this->db->row(); 
     73                                $result[] = $row['id_related']; 
     74                        } 
     75                        if($result) 
     76                                $this->related_ids = implode(",",$result); 
     77                } 
     78                if($this->related_ids) 
     79                        $query_related .= ' or '.$field_name.' in ('.$this->related_ids.')'; 
     80                 
     81                return $query_related; 
     82        } 
    7483        function get_cc_groups()  
    7584        { 
     
    7786                $stringDropDownContacts = '';                    
    7887                $result = array(); 
    79                 $query = 'select title, short_name from phpgw_cc_groups where owner ='.$this -> user_id.' order by title'; 
     88                $query_related = $this->get_query_related('owner'); // field name for 'owner'            
     89                $query = 'select title, short_name, owner from phpgw_cc_groups where '.$query_related.' order by lower(title)'; 
     90 
    8091                // Executa a query  
    8192                if (!$this->db->query($query)) 
     
    8495                while($this->db->next_record()) 
    8596                        $result[] = $this->db->row(); 
    86                 // Se houver grupos .... 
     97 
     98                // Se houver grupos ....                                 
    8799                if (count($result) != 0)  
    88                 {        
    89                         foreach($result as $group) 
    90                                 $stringDropDownContacts .=  $group['title']. ';' . $group['short_name'] . ','; 
     100                { 
     101                        // Create Ldap Object, if exists related Ids for sharing groups. 
     102                        if($this->related_ids){ 
     103                                $_SESSION['phpgw_info']['expressomail']['user']['cc_related_ids']= array(); 
     104                                include_once("class.ldap_functions.inc.php"); 
     105                                $ldap = new ldap_functions(); 
     106                        } 
     107                        foreach($result as $group){ 
     108                                // Searching uid (LDAP), if exists related Ids for sharing groups. 
     109                                // Save into user session. It will used before send mail (verify permission). 
     110                                if(!$_SESSION['phpgw_info']['expressomail']['user']['cc_related_ids'][$group['owner']] && $ldap){                                        
     111                                        $_SESSION['phpgw_info']['expressomail']['user']['cc_related_ids'][$group['owner']] = $ldap -> uidnumber2uid($group['owner']); 
     112                                } 
     113                                if($this->user_id != $group['owner']) 
     114                                        $owneruid = "::".$_SESSION['phpgw_info']['expressomail']['user']['cc_related_ids'][$group['owner']]; 
     115 
     116                                $stringDropDownContacts .=  $group['title']. ';' . ($group['short_name'].$owneruid) . ','; 
     117                        } 
    91118                        //Retira ultima virgula. 
    92119                        $stringDropDownContacts = substr($stringDropDownContacts,0,(strlen($stringDropDownContacts) - 1)); 
    93120                } 
    94121                else 
    95                         return null; 
    96                          
     122                        return null;             
    97123                return $stringDropDownContacts; 
    98124        } 
     
    100126        function getContactsByGroupAlias($alias) 
    101127        { 
     128                list($alias,$uid) = explode("::",$alias);                
     129                $cc_related_ids = $_SESSION['phpgw_info']['expressomail']['user']['cc_related_ids'];             
     130                // Explode personal group, If exists related ids (the user has permission to send email). 
     131                if(is_array($cc_related_ids) && $uid){ 
     132                        $owner =  array_search($uid,$cc_related_ids);                    
     133                } 
    102134                 
    103135                $query = "select C.id_connection, A.names_ordered, C.connection_value from phpgw_cc_contact A, ". 
     
    105137                "A.id_contact = B.id_contact and B.id_connection = C.id_connection ". 
    106138                "and B.id_typeof_contact_connection = 1 and ". 
    107                 "A.id_owner =".$this -> user_id." and ".                         
     139                "A.id_owner =".($owner ? $owner : $this->user_id)." and ".                       
    108140                "D.id_group = E.id_group and ". 
    109                 "D.id_connection = C.id_connection and E.short_name = '".$alias. 
    110                 "' order by A.names_ordered"; 
     141                "D.id_connection = C.id_connection and E.short_name = '".$alias."'"; 
    111142 
    112143                if (!$this->db->query($query)) 
     
    136167 
    137168                                $alias = substr($array_addrs[$i], strpos($array_addrs[$i],'<'), strpos($array_addrs[$i],'>'));                           
    138                                 $alias = str_replace('<','', str_replace('>','',$alias));                                                                        
     169                                $alias = str_replace('<','', str_replace('>','',$alias)); 
     170                                                                                         
    139171                                $arrayContacts = $this -> getContactsByGroupAlias($alias); 
    140172 
Note: See TracChangeset for help on using the changeset viewer.