Changeset 400 for trunk/contactcenter


Ignore:
Timestamp:
08/14/08 12:17:32 (16 years ago)
Author:
niltonneto
Message:

Corrigido comentários com problema de charset.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/contactcenter/inc/class.bo_global_ldap_catalog.inc.php

    r388 r400  
    1616        */ 
    1717        include_once('class.abo_catalog.inc.php'); 
    18  
     18         
    1919        class bo_global_ldap_catalog extends abo_catalog 
    2020        { 
    2121                var $ldap; 
    22  
     22         
    2323                var $src_info; 
    24  
     24                 
    2525                var $trans_table; 
    2626                // used to determine if a catalog is external 
     
    4141                        'pgp_key'       => true, 
    4242                        'notes'         => true, 
    43  
     43                         
    4444                        /* Array fields */ 
    4545                        'companies'     => true, 
     
    4848                        'connections'   => true 
    4949                ); 
    50  
     50                 
    5151                /* 
    52  
     52                 
    5353                        @function global_ldap_catalog 
    5454                        @abstract Constructor 
    5555                        @author Raphael Derosso Pereira 
    56                         @author Mï¿œrio Cï¿œsar Kolling (external catalogs) 
     56                        @author Mário César Kolling (external catalogs) 
    5757 
    5858                        @param integer $id_source The ID of the LDAP source 
     
    6767                                exit('PHP LDAP support Unavailable!'); 
    6868                        } 
    69  
     69                         
    7070                        $this->ldap = CreateObject('contactcenter.bo_ldap_manager'); 
    71  
     71                         
    7272                        if ($this->external) 
    7373                        { 
     
    9292                        } 
    9393                        else 
    94                         { 
     94                        {        
    9595                                $this->trans_table = $this->ldap->get_ldap_fields_association($id_source); 
    9696                        } 
    9797                } 
    98  
     98                 
    9999                /* 
    100  
     100                 
    101101                        @function find 
    102102                        @abstract Searches the LDAP directory for the specified fields with 
     
    104104                                that matches the rules. 
    105105                        @author Raphael Derosso Pereira 
    106  
     106                         
    107107                        @param array $what The fields to be taken 
    108108                        @param array $rules The rules to be match. See class.abo_catalog.inc.php 
     
    113113                                        'offset' => (integer) [NOT IMPLEMENTED] 
    114114                                ) 
    115  
     115                 
    116116                */ 
    117117                function find($what, $rules=false, $other=false) 
    118118                { 
    119119                        $restric_fields = $this->get_restrictions_without_branch($rules); 
    120  
     120                         
    121121                        $trans_f = $this->translate_fields($what, $restric_fields); 
    122  
     122                         
    123123                        foreach($trans_f as $orig => $field_a) 
    124124                        { 
     
    128128                                } 
    129129                        } 
    130  
     130                         
    131131                        $fields = array_unique($fields); 
    132  
     132                         
    133133                        $filter = $this->process_restrictions($rules, $trans_f); 
    134134 
    135135                        if("ou" === strtolower(substr($this->src_info['context'], 0, 2)) || 
    136                                 (trim($rules[4]['value']) != "inetOrgPerson")) 
    137                         { 
     136                                (trim($rules[4]['value']) != "inetOrgPerson"))   
     137                        {                        
    138138                                $ldap = $GLOBALS['phpgw']->common->ldapConnect($this->src_info['host'], $this->src_info['acc'], $this->src_info['pw'], true); 
    139139                                $result_r = ldap_search($ldap , $this->src_info['context'], $filter, $fields, 0, $this->src_info['max_results']); 
    140140                        } 
    141141                        else 
    142                         { 
     142                        {                                
    143143                                return false; 
    144144                        } 
    145  
     145                         
    146146 
    147147                        if (!$result_r) 
     
    149149                                return false; 
    150150                        } 
    151  
     151                         
    152152                        if ($other['order']) 
    153153                        { 
     
    163163                                } 
    164164                        } 
    165  
     165                         
    166166                        $result_u = ldap_get_entries($ldap, $result_r); 
    167  
     167                         
    168168                        $i = 0; 
    169169                        foreach ($result_u as $index => $result_p) 
     
    173173                                        continue; 
    174174                                } 
    175  
     175                                 
    176176                                foreach ($trans_f as $orig => $trans) 
    177177                                { 
     
    191191                                $i++; 
    192192                        } 
    193  
     193                         
    194194                        return $return; 
    195195                } 
    196  
     196                 
    197197                /* 
    198  
     198                 
    199199                        @function translate_fields 
    200200                        @abstract Return the LDAP objectClass fields that corresponds to the 
    201201                                specified parameter fields 
    202202                        @author Raphael Derosso Pereira 
    203  
     203                         
    204204                        @param array $fields The fields in the standard ContactCenter format 
    205205                        @param array $rules The rules 
    206  
     206                 
    207207                */ 
    208208                function translate_fields ( $fields, &$restric_fields ) 
    209209                { 
    210210                        $return = array(); 
    211  
     211                         
    212212                        $i = 0; 
    213213                        foreach ($fields as $field) 
     
    217217                                        continue; 
    218218                                } 
    219  
     219                                 
    220220                                if (!is_array($this->trans_table[$field])) 
    221221                                { 
    222222                                        $reference = $this->trans_table[$field]; 
    223  
     223                                         
    224224                                        reset($restric_fields); 
    225225                                        while(list(,$field_r) = each($restric_fields)) 
     
    243243                                } 
    244244                        } 
    245  
     245                         
    246246                        if (count($return)) 
    247247                        { 
    248248                                return $return; 
    249249                        } 
    250  
     250                         
    251251                        return false; 
    252252                } 
    253  
     253                 
    254254                /* 
    255  
     255                 
    256256                        @function process_restrictions 
    257257                        @abstract Returns a LDAP filter string that corresponds to the 
    258258                                specified restriction rules 
    259259                        @author Raphael Derosso Pereira 
    260  
     260                         
    261261                        @param string $rules The restriction rules 
    262  
     262                 
    263263                */ 
    264264                function process_restrictions( $rules, &$trans_table, $join_type='&' ) 
     
    268268                                return null; 
    269269                        } 
    270  
     270                         
    271271                        foreach($rules as $rule_i => $rule) 
    272272                        { 
     
    280280                                                                $join = '|'; 
    281281                                                                break; 
    282  
     282                                                                 
    283283                                                        case 'AND': 
    284284                                                                $join = '&'; 
    285285                                                                break; 
    286  
     286                                                                 
    287287                                                        case 'NOT': 
    288288                                                                $join = '!'; 
    289289                                                                break; 
    290  
     290                                                                 
    291291                                                        default: 
    292292                                                                $join = $join_type; 
     
    294294                                                $return_t[] = $this->process_restrictions($rule['sub_branch'], $trans_table, $join); 
    295295                                                break; 
    296  
     296                                                 
    297297                                        case '=': 
    298298                                                if (array_key_exists($rule['field'], $trans_table)) 
     
    305305                                                } 
    306306                                                break; 
    307  
    308                                         case '!=': 
     307                                         
     308                                        case '!=':       
    309309                                                if (array_key_exists($rule['field'], $trans_table)) 
    310310                                                { 
     
    316316                                                } 
    317317                                                break; 
    318  
     318                                         
    319319                                        case '<=': 
    320320                                        case '<': 
     
    328328                                                } 
    329329                                                break; 
    330  
     330                                         
    331331                                        case '>': 
    332332                                        case '>=': 
     
    340340                                                } 
    341341                                                break; 
    342  
     342                                                 
    343343                                        case 'NULL': 
    344344                                                if (array_key_exists($rule['field'], $trans_table)) 
     
    351351                                                } 
    352352                                                break; 
    353  
     353                                         
    354354                                        case 'IN': 
    355355                                                if (array_key_exists($rule['field'], $trans_table)) 
     
    371371                                                        $value_1 = strtoupper(str_replace('%', '*', $rule['value'])); 
    372372                                                        $value_2 = strtolower($value_1); 
    373  
     373                                                         
    374374                                                        foreach($trans_table[$rule['field']] as $field) 
    375375                                                        { 
     
    380380                                                } 
    381381                                                break; 
    382  
     382                                                 
    383383*/                                      case 'LIKE': 
    384384                                                if (array_key_exists($rule['field'], $trans_table)) 
    385385                                                { 
    386386                                                        $value = str_replace('%', '*', $rule['value']); 
    387  
     387                                                         
    388388                                                        foreach($trans_table[$rule['field']] as $field) 
    389389                                                        { 
     
    393393                                                } 
    394394                                                break; 
    395  
     395                                                 
    396396                                        case 'NOT NULL': 
    397397                                                if (array_key_exists($rule['field'], $trans_table)) 
     
    404404                                                } 
    405405                                                break; 
    406  
     406                                         
    407407                                        case 'NOT IN': 
    408408                                                if (array_key_exists($rule['field'], $trans_table)) 
     
    424424                                                        $value_1 = strtoupper(str_replace('%', '*', $rule['value'])); 
    425425                                                        $value_2 = strtolower($value_1); 
    426  
     426                                                         
    427427                                                        foreach($trans_table[$rule['field']] as $field) 
    428428                                                        { 
     
    438438                                                { 
    439439                                                        $value = str_replace('%', '*', $rule['value']); 
    440  
     440                                                         
    441441                                                        foreach($trans_table[$rule['field']] as $field) 
    442442                                                        { 
     
    448448                                } 
    449449                        } 
    450  
     450                         
    451451                        if (count($return_t)) 
    452452                        { 
     
    466466 
    467467                /*! 
    468  
     468                 
    469469                        @function get_restrictions_without_branch 
    470470                        @abstract Returns an array containing the restrictions ignoring the 
    471471                                branches 
    472472                        @author Raphael Derosso Pereira 
    473  
     473                         
    474474                        @param array $restrictions The restrictions 
    475  
     475                 
    476476                */ 
    477477                function get_restrictions_without_branch(&$restrictions) 
     
    481481                                return null; 
    482482                        } 
    483  
     483                         
    484484                        $fields = array(); 
    485  
     485                         
    486486                        foreach ($restrictions as $restrict_data) 
    487487                        { 
     
    491491                                                $fields = array_merge($fields, $this->get_restrictions_without_branch($restrict_data['sub_branch'])); 
    492492                                                break; 
    493  
     493                                                 
    494494                                        case '=': 
    495                                         case '!=': 
     495                                        case '!=':       
    496496                                        case '<=': 
    497497                                        case '<': 
     
    508508                                                array_push($fields, $restrict_data); 
    509509                                                break; 
    510  
     510                                                 
    511511                                        default: 
    512                                                 exit('Error in '.__FILE__.' on '.__LINE__.'<br>The restriction type passed was: '.$restrict_data['type']); 
    513                                 } 
    514                         } 
    515  
     512                                                exit('Error in '.__FILE__.' on '.__LINE__.'<br>The restriction type passed was: '.$restrict_data['type']);                                       
     513                                } 
     514                        } 
     515                         
    516516                        return $fields; 
    517517                } 
    518  
    519  
     518                 
     519                 
    520520                /*********************************************************************\ 
    521521                 *                        Methods to Get Data                        * 
    522522                \*********************************************************************/ 
    523  
    524  
     523                 
     524         
    525525                /*! 
    526  
     526                 
    527527                 @function get_single_entry 
    528528                 @abstract Returns all information requested about one contact 
    529529                 @author Raphael Derosso Pereira 
    530  
     530                      
    531531                 @param integer $id_contact The contact ID 
    532532                 @param array $fields The array returned by get_fields with true 
    533533                        on the fields to be taken. 
    534  
     534                         
    535535                */ 
    536536                function get_single_entry ( $id_contact, $fields ) 
    537537                { 
    538                         if (!is_array($fields)) 
    539                         { 
    540                                 if (is_object($GLOBALS['phpgw']->log)) 
     538                        if (!is_array($fields))  
     539                        { 
     540                                if (is_object($GLOBALS['phpgw']->log))  
    541541                                { 
    542542                                        $GLOBALS['phpgw']->log->message(array( 
     
    544544                                                'line' => __LINE__, 
    545545                                                'file' => __FILE__)); 
    546  
     546                                         
    547547                                        $GLOBALS['phpgw']->log->commit(); 
    548548                                } 
    549                                 else 
     549                                else  
    550550                                { 
    551551                                        exit('Argument Error on: <br>File:'.__FILE__.'<br>Line:'.__LINE__.'<br>'); 
    552552                                } 
    553553                        } 
    554  
     554                         
    555555                        $ldap = $GLOBALS['phpgw']->common->ldapConnect($this->src_info['host'],$this->src_info['acc'],$this->src_info['pw'],true); 
    556  
     556                         
    557557                        if (!$ldap) 
    558558                        { 
     
    566566                                return false; 
    567567                        } 
    568  
     568                         
    569569                        $first_entry = ldap_first_entry($ldap, $resource); 
    570570                        $contact = ldap_get_attributes($ldap,$first_entry); 
    571                         if($contact['jpegPhoto']){ 
    572                                 $contact['jpegPhoto'] = ldap_get_values_len ($ldap, $first_entry, "jpegPhoto"); 
     571                        if($contact['jpegPhoto']){       
     572                                $contact['jpegPhoto'] = ldap_get_values_len ($ldap, $first_entry, "jpegPhoto");  
    573573                        } 
    574574 
    575575//                      print_r($contact); 
    576  
     576                         
    577577                //      $contact_data = $this->fields; 
    578  
     578                         
    579579                        foreach($fields as $field => $trueness) 
    580580                        { 
     
    584584                                        continue; 
    585585                                } 
    586  
     586                                 
    587587                                switch ($field) 
    588588                                { 
     
    593593                                                $l_fields['department']    = $this->trans_table['contact.business_info.department']; 
    594594                                                $l_fields['company_notes'] = $this->trans_table['contact.company.company_notes']; 
    595  
     595                                                 
    596596                                                $contact_data['companies'] = array(); 
    597597                                                foreach($l_fields as $l_field => $l_value) 
     
    601601                                                                continue; 
    602602                                                        } 
    603  
     603                                                         
    604604                                                        $contact_data['companies']['company1'][$l_field] = utf8_decode($contact[$l_value[0]][0]); 
    605605                                                } 
    606  
     606                                                 
    607607                                                if (!(count($contact_data['companies']))) 
    608608                                                { 
     
    610610                                                } 
    611611                                                break; 
    612  
     612                                         
    613613                                        case 'relations': 
    614614                                                unset($l_fields); 
     
    617617                                                        unset($contact_data['relations']); 
    618618                                                } 
    619  
     619                                                 
    620620                                                $contact_data['relations'] = array(); 
    621621                                                if (!is_array($this->trans_table['contact.contact_related.names_ordered'])) 
     
    625625                                                                continue; 
    626626                                                        } 
    627  
     627                                                         
    628628                                                        $i = 1; 
    629629                                                        foreach($trans as $l_type => $l_type_fields) 
     
    633633                                                                        continue; 
    634634                                                                } 
    635  
     635                                                                 
    636636                                                                $contact_data['relations']['relation'.$i]['type'] = $l_type; 
    637637                                                                $contact_data['relations']['relation'.$i]['names_ordered'] = utf8_decode($contact[$l_type_fields[0]][0]); 
     
    639639                                                        } 
    640640                                                } 
    641  
     641                                                 
    642642                                                if (!(count($contact_data['relations']))) 
    643643                                                { 
     
    645645                                                } 
    646646                                                break; 
    647  
     647                                         
    648648                                        case 'addresses': 
    649649                                                unset($l_fields); 
     
    674674                                                                        continue; 
    675675                                                                } 
    676  
     676                                                                 
    677677                                                                $i = 1; 
    678678                                                                foreach($trans as $l_type => $l_type_fields) 
     
    682682                                                                                continue; 
    683683                                                                        } 
    684  
     684                                                                         
    685685                                                                        $contact_data['addresses']['address'.$i]['type'] = $l_type; 
    686686                                                                        $contact_data['addresses']['address'.$i][$l_field] = utf8_decode($contact[$l_type_fields[0]][0]); 
     
    693693                                                        } 
    694694                                                } 
    695  
     695                                                 
    696696                                                if (!(count($contact_data['addresses']))) 
    697697                                                { 
     
    699699                                                } 
    700700                                                break; 
    701  
     701                                         
    702702                                        case 'connections': 
    703703                            $preferences = ExecMethod('contactcenter.ui_preferences.get_preferences'); 
     
    720720                                                                        continue; 
    721721                                                                } 
    722  
     722                                                                 
    723723                                                                $i = 1; 
    724724                                                                foreach($trans as $l_type => $l_type_fields) 
     
    728728                                                                                continue; 
    729729                                                                        } 
    730  
     730                                                                         
    731731                                                                        switch ($l_type) 
    732732                                                                        { 
     
    748748                                                        } 
    749749                                                } 
    750  
     750                                                 
    751751                                                if (!(count($contact_data['connections']))) 
    752752                                                { 
     
    754754                                                } 
    755755                                                break; 
    756  
     756                                         
    757757                                        case 'prefix': 
    758758                                                unset($l_fields); 
     
    763763                                                        continue; 
    764764                                                } 
    765  
     765                                                 
    766766                                                $contact_data['prefix'] = utf8_decode($contact[$l_fields[0]][0]); 
    767767                                                break; 
    768  
     768                                                 
    769769                                        case 'suffix': 
    770770                                                unset($l_fields); 
     
    775775                                                        continue; 
    776776                                                } 
    777  
     777                                                 
    778778                                                $contact_data['suffix'] = utf8_decode($contact[$l_fields[0]][0]); 
    779779                                                break; 
    780  
     780                                                 
    781781                                        case 'status': 
    782782                                                unset($l_fields); 
     
    787787                                                        continue; 
    788788                                                } 
    789  
     789                                                 
    790790                                                $contact_data['status'] = utf8_decode($contact[$l_fields[0]][0]); 
    791791                                                break; 
    792  
     792                                                 
    793793                                                case 'photo': 
    794794                                                unset($l_fields); 
     
    799799                                                        continue; 
    800800                                                } 
    801  
     801                                                 
    802802                                                $contact_data['photo'] = $contact[$l_fields[0]][0]; 
    803                                                 break; 
     803                                                break;                                                                                   
    804804 
    805805                                        default: 
     
    811811                                                        continue; 
    812812                                                } 
    813  
     813                                                 
    814814                                                if(count($contact[$l_fields[0]]) > 1) 
    815815                                                { 
     
    828828                                } 
    829829                        } 
    830  
     830                         
    831831                        if (!is_array($contact_data)) 
    832832                        { 
    833833                                return false; 
    834834                        } 
    835  
     835                         
    836836                        return $contact_data; 
    837837                } 
     
    842842                 @abstract Returns all information requested about a bunch of contacts, usually a page 
    843843                 @author Raphael Derosso Pereira 
    844                  @author Mï¿œrio Cï¿œsar Kolling 
     844                 @author Mário César Kolling 
    845845 
    846846                 @param string $filter Filter (returned by generate_filter). 
     
    11581158                        return $contacts; 
    11591159                } 
    1160  
     1160                 
    11611161                function get_multiple_entries ( $id_contacts, $fields, $other_data = false ) 
    11621162                { 
    11631163                        if (!is_array($id_contacts) or !is_array($fields) or ($other_data != false and !is_array($other_data))) 
    11641164                        { 
    1165                                 if (is_object($GLOBALS['phpgw']->log)) 
     1165                                if (is_object($GLOBALS['phpgw']->log))  
    11661166                                { 
    11671167                                        $GLOBALS['phpgw']->log->message(array( 
     
    11691169                                                'line' => __LINE__, 
    11701170                                                'file' => __FILE__)); 
    1171  
     1171                                         
    11721172                                        $GLOBALS['phpgw']->log->commit(); 
    11731173                                } 
     
    11761176                                } 
    11771177                        } 
    1178  
     1178                          
    11791179                        foreach ($id_contacts as $id) 
    11801180                        { 
    11811181                                $contacts[$id] = $this->get_single_entry($id,$fields); 
    11821182                        } 
    1183  
     1183                         
    11841184                        return $contacts; 
    11851185 
    11861186                        // SERPRO 
    1187  
     1187                                                 
    11881188                        /*$contacts = array(); 
    1189  
     1189         
    11901190                        if ($other_data) 
    11911191                        { 
     
    11981198 
    11991199                        return $this->get_all_entries($filter, $fields);*/ 
    1200  
     1200                         
    12011201                } 
    12021202 
     
    12081208                                $contacts[$id] = $this->get_single_entry($id,$fields); 
    12091209                        } 
    1210  
     1210                         
    12111211                        return $contacts; 
    12121212                } 
    1213  
     1213                 
    12141214                // SERPRO 
    12151215                /* 
     
    12221222                                { 
    12231223 
    1224                                         // 
    1225                                         //  Nï¿œo utiliza mais a funᅵᅵo ldap_explode, usa a expressï¿œo regular a seguir para pegar o primeiro 
     1224                                        //  
     1225                                        //  Não utiliza mais a função ldap_explode, usa a expressão regular a seguir para pegar o primeiro 
    12261226                                        //  componente da dn 
    1227                                         // 
     1227                                        //  
    12281228                                        preg_match('/^(\w*=[^,]*),.*$/', $id_contacts[$i], $cn); 
    12291229 
    12301230                                // 
    12311231                                // Adicionados os str_replace para adicionar caracteres de escape em frente aos caracteres '(' e ')', 
    1232                                 // posteriormente poderï¿œ ser necessï¿œrio substituir por uma expressï¿œo regular mais genï¿œrica. 
     1232                                // posteriormente poderá ser necessário substituir por uma expressão regular mais genérica. 
    12331233                                // 
    12341234 
     
    12361236                                        { 
    12371237                                                // 
    1238                                                 // Esta operaᅵᅵo resolve o problema causado pela conversï¿œo de caracteres acentuados realizada 
    1239                                                 // pela funᅵᅵo ldap_explode_dn(). Talvez seja necessï¿œrio utilizar esta traduᅵᅵo em outros lugares, 
    1240                                                 // neste caso ï¿œ mais apropriado colocar dentro de uma funᅵᅵo. 
     1238                                                // Esta operação resolve o problema causado pela conversão de caracteres acentuados realizada 
     1239                                                // pela função ldap_explode_dn(). Talvez seja necessário utilizar esta tradução em outros lugares, 
     1240                                                // neste caso é mais apropriado colocar dentro de uma função. 
    12411241                                                // 
    12421242                                                //foreach($cn as $key=>$value){ 
     
    12821282                        return null; 
    12831283                } 
    1284  
     1284                 
    12851285                function get_relations ($id_contact,$extra=false) 
    12861286                { 
    12871287                } 
    1288  
     1288                 
    12891289                function get_addresses ( $id_contact,$extra=false ) 
    12901290                { 
    12911291                } 
    1292  
     1292                 
    12931293                function get_connections ( $id_contact,$extra=false ) 
    12941294                { 
    12951295                } 
    1296  
     1296                 
    12971297                function get_companies ( $id_contact, $extra=false ) 
    12981298                { 
    12991299                } 
    1300  
     1300                 
    13011301                function get_all_prefixes (  ) 
    13021302                { 
    13031303                } 
    1304  
     1304                 
    13051305                function get_all_suffixes (  ) 
    13061306                { 
    13071307                } 
    1308  
     1308                 
    13091309                function get_all_status (  ) 
    13101310                { 
    13111311                } 
    1312  
     1312                 
    13131313                function get_all_relations_types (  ) 
    13141314                { 
    13151315                } 
    1316  
     1316                 
    13171317                function get_all_addresses_types (  ) 
    13181318                { 
    13191319                } 
    1320  
     1320                 
    13211321                function get_all_connections_types (  ) 
    13221322                { 
    13231323                } 
    1324  
     1324                 
    13251325                function get_vcard ( $id_contact ) 
    13261326                { 
    13271327                } 
    1328  
    1329  
    1330  
    1331  
     1328                 
     1329                 
     1330                 
     1331                 
    13321332                function get_global_tree ( $root ) 
    13331333                { 
    13341334                } 
    1335  
     1335         
    13361336                function get_actual_brach (  ) 
    13371337                { 
    13381338                } 
    1339  
     1339         
    13401340                function set_actual_branch ( $branch ) 
    13411341                { 
Note: See TracChangeset for help on using the changeset viewer.