Ignore:
Timestamp:
05/21/08 16:56:17 (16 years ago)
Author:
rafaelraymundo
Message:

Vide Trac - #197, #166, #198, #199

  1. Correção de problema na leitura do arquivo configuração.
  2. Permissão do click2dial também no contactcenter.
  3. Visualização de matricula, e nro celular no resultado da pesquisa(se estiverem populados)
  4. Adicionada a leitura a Catálogos Externos
File:
1 edited

Legend:

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

    r2 r284  
    55  * Written by:                                                               * 
    66  *  - Raphael Derosso Pereira <raphaelpereira@users.sourceforge.net>         * 
    7   *  sponsored by Thyamad - http://www.thyamad.com 
     7  *  sponsored by Thyamad - http://www.thyamad.com                            * 
    88  * ------------------------------------------------------------------------- * 
    99  *  This program is free software; you can redistribute it and/or modify it  * 
     
    2525                */ 
    2626                var $catalog; 
    27                  
     27 
    2828                /*! 
    2929                        The Security Manager 
    3030                */ 
    3131                var $security; 
    32                  
     32 
    3333 
    3434                function bo_contactcenter($catalog=false) 
     
    3737                        $this->catalog_level = $GLOBALS['phpgw']->session->appsession('bo_contactcenter.catalog_level','contactcenter'); 
    3838                        $this->security = CreateObject('contactcenter.bo_security_manager'); 
    39                          
     39 
    4040                        if ($catalog) 
    4141                        { 
     
    5656                        } 
    5757                } 
    58                  
    59                 /*! 
    60                  
     58 
     59                /* 
     60                 * 
     61                 * @function is_external 
     62                 * @author Mário César Kolling <mario.kolling@serpro.gov.br> 
     63                 * @abstract Verify if a catalog is external 
     64                 * @param (mixed) an catalog array or a catalog tree level, a string in the form 0.sublevel.subsublevel 
     65                 * @return (boolean) true if it is an external catalog false otherwise 
     66                 * 
     67                 */ 
     68 
     69                function is_external($catalog) 
     70                { 
     71                        if (is_array($catalog)) 
     72                        { 
     73                                $level = $this->get_level_by_branch($catalog, $this->tree['branches']); 
     74                        } 
     75                        else 
     76                        { 
     77                                $level = $catalog; 
     78                        } 
     79 
     80                        $lvl_vector = explode('.', $level); 
     81                        $id = $lvl_vector[1]; 
     82 
     83                        if ($this->tree['branches'][$id]['external']) 
     84                        { 
     85                                return true; 
     86                        } 
     87 
     88                        return false; 
     89 
     90                } 
     91 
     92                /* 
     93                 function get_letters_filter($catalog) 
     94                { 
     95 
     96                } 
     97 
     98                function get_numbers_filter($catalog) 
     99                { 
     100 
     101                } 
     102 
     103                function get_search_filter($catalog) 
     104                { 
     105 
     106                } 
     107                */ 
     108 
     109                /*! 
     110 
    61111                        @function find 
    62112                        @abstract Performs a search in the DB based on the parameters 
    63113                        @author Raphael Derosso Pereira (algorithm and code) 
    64114                        @author Vinicius Cubas Brand (algorithm) 
    65                          
     115 
    66116                        @param array $what The list of fields to be returned. The format is: 
    67117                                $what = array( 
     
    69119                                        'contact.names_ordered' 
    70120                                ); 
    71                          
     121 
    72122                        @param array $rules The restrictions. 
    73                          
     123 
    74124                        The restrictions format is quite complicated, but is very complete. 
    75125                        As defined here, there is the possibility to do almost any type of 
    76126                        search (tell me if you can't do any). For example, imagine the 
    77127                        following search: 
    78                                          
     128 
    79129                                                and(a,or(d,e,and(f,g))) 
    80                          
     130 
    81131                        That is represented by the folloowing tree: 
    82                                  
     132 
    83133                                   and 
    84134                                    | 
     
    98148                        The rules that should be passed to the find function for this tree 
    99149                        is: 
    100                                  
     150 
    101151                                $rules = array( 
    102152                                        0 => array( 
     
    139189                                ); 
    140190 
    141    
    142                         The restriction type can be: =, !=, <=, <, >, >=, NULL, IN, LIKE,  
     191 
     192                        The restriction type can be: =, !=, <=, <, >, >=, NULL, IN, LIKE, 
    143193                        NOT NULL, NOT IN, NOT LIKE 
    144194                        Value of branch can be AND, OR, NOT 
    145                          
    146                         @param array $other Other parameter to the search  
     195 
     196                        @param array $other Other parameter to the search 
    147197                                $other = array( 
    148198                                        'offset'          => (int), 
     
    154204 
    155205                        @return array $array[<field_name>][<row_number>] 
    156                                  
     206 
    157207                */ 
    158208                function find($what, $rules=false, $other=false) 
     
    160210                        return $this->catalog->find($what, $rules, $other); 
    161211                } 
    162                  
    163                 /*! 
    164                  
     212 
     213                /*! 
     214 
    165215                        @function get_catalog_tree 
    166216                        @abstract Returns an array describing the available 
     
    168218                                values and types 
    169219                        @author Raphael Derosso Pereira 
     220                        @author Mário César Kolling (external catalogs and optimizations) 
    170221 
    171222                        @param (string)  $level The level to be taken 
    172223                        @param (boolean) $recursive Retrive the whole tree from 
    173224                                the level specified until the leaves 
    174                          
     225 
    175226                        @return The format of the return is: 
    176227                                $return = array( 
     
    195246                                        1  => array(...),... 
    196247                                ); 
    197                                  
     248 
    198249                                <branch_type> can be 'catalog_group', 'catalog' or 'view'; 
    199                                 <branch_class> is the name of the class that is capable of  
     250                                <branch_class> is the name of the class that is capable of 
    200251                                        handling the information for this catalog/view 
    201252                                <branch_class_args> is an array that holds the arguments to 
     
    203254                                <brach_find_args> is the string that should precede the search 
    204255                                        string 
    205                                                  
    206                                 If the branch is actually a leaf, than 'sub_branch' is false;  
    207                  
    208                  
     256 
     257                                If the branch is actually a leaf, than 'sub_branch' is false; 
     258 
     259 
    209260                        TODO: This method is hard-coded, but it should grab the tree 
    210261                        from the DB using the View Manager... 
     
    218269                                        return $this->tree['branches']; 
    219270                                } 
    220                                  
     271 
     272                                $lvl_vector = explode('.', $level); 
     273                                $id = $lvl_vector[1]; 
     274 
    221275                                $branch =& $this->get_branch_by_level($level); 
    222276                                $info = $this->get_info_by_level($level); 
    223                                  
     277 
    224278                                if ($branch['type'] === 'unknown') 
    225279                                { 
     
    227281                                        { 
    228282                                                $ldap = CreateObject('contactcenter.bo_ldap_manager'); 
    229                                                 $new_branch = $ldap->get_ldap_tree($info['src'], $branch['value'], $recursive); 
    230                                                  
     283 
     284                                                if ($this->tree['branches'][$id]['external']) 
     285                                                { 
     286                                                        // if it's an external catalog 
     287                                                        $new_branch = $ldap->get_external_ldap_tree($info['src'], $branch['value'], $recursive); 
     288                                                } 
     289                                                else 
     290                                                { 
     291                                                        // if it's not an external catalog 
     292                                                        $new_branch = $ldap->get_ldap_tree($info['src'], $branch['value'], $recursive); 
     293                                                } 
     294 
    231295                                                if ($new_branch) 
    232296                                                { 
     297                                                        if (!empty($new_branch['timeout']) && !empty($new_branch['msg'])) 
     298                                                        { 
     299                                                                return $new_branch; 
     300                                                        } 
     301 
     302                                                        // Necessary for the new way the catalog tree is built at initialization 
     303                                                        $new_branch['name'] = $branch['name']; 
     304                                                        $new_branch['external'] = $branch['external']; 
    233305                                                        $branch = $new_branch; 
     306 
    234307                                                } 
    235308                                                else 
     
    239312                                        } 
    240313                                        $GLOBALS['phpgw']->session->appsession('bo_contactcenter.tree','contactcenter',$this->tree); 
    241                                          
    242314                                        return $branch; 
    243315                                } 
     
    246318                                        return $branch; 
    247319                                } 
    248                                  
     320 
    249321                                return false; 
    250322                        } 
    251                          
     323 
    252324                        if ($level !== '0') 
    253325                        { 
    254326                                return false; 
    255327                        } 
    256                          
     328 
    257329                        $this->tree = array( 
    258330                                0 => array( 
     
    275347                                                'sub_branch' => false 
    276348                                        ),*/ 
    277                                          
     349 
    278350                                        1  => array( 
    279351                                                'name'       => lang('Groups'), 
     
    281353                                                'class'      => 'bo_group_manager', 
    282354                                                'icon'       => 'people-mini.png', 
    283                                                 'sub_branch' => False    
     355                                                'sub_branch' => False 
    284356                                        ) 
    285357                                ) 
    286358                        ); 
    287                          
     359 
    288360                        $ldap = CreateObject('contactcenter.bo_ldap_manager'); 
    289361                        $ldap_srcs = $ldap->get_all_ldap_sources(); 
    290                          
     362 
    291363                        if ($ldap_srcs) 
    292364                        { 
     
    297369                                        if (($tree = $ldap->get_ldap_tree($id, $ldap_srcs[$id]['dn'], $recursive))) 
    298370                                        { 
     371                                                // It isn't used anymore, but does no harm! 
     372                                                // It may be usefull later for use with search timeouts, or another ldap error 
     373                                                if (array_key_exists('error_msg', $tree)) 
     374                                                { 
     375                                                        if (isset($this->tree['branches']['msg'])) 
     376                                                        { 
     377                                                                $this->tree['branches']['msg'] .= "\n" . lang('Catalog %1 not showed due to error: ' . 
     378                                                                                                         $tree['error_msg'], $ldap_srcs[$id]['name']); 
     379                                                        } 
     380                                                        else 
     381                                                        { 
     382                                                                $this->tree['branches']['msg'] = lang('Catalog %1 not showed due to error: ' . 
     383                                                                                                         $tree['error_msg'], $ldap_srcs[$id]['name']); 
     384                                                        } 
     385                                                } 
     386                                                else 
     387                                                { 
     388                                                        $tree['name'] = $ldap_srcs[$id]['name']; 
     389                                                        $tree['external'] = false; 
     390                                                        array_push($this->tree['branches'], $tree); 
     391                                                        $this->tree[$i]['type'] = 'ldap'; 
     392                                                        $this->tree[$i]['src'] = $id; 
     393                                                } 
     394 
     395                                        } 
     396                                        $i++; 
     397                                } 
     398                        } 
     399 
     400                        // external LDAP sources 
     401                        $ldap_srcs = $ldap->get_external_ldap_sources(); 
     402 
     403                        if ($ldap_srcs) 
     404                        { 
     405                                $i = count($this->tree); 
     406 
     407                                reset($ldap_srcs); 
     408 
     409                                while (list($id,) = each($ldap_srcs)) 
     410                                { 
     411                                        // External catalogs are now identified as type unknown during initialization. An optimization change. 
     412 
     413                                        /* 
     414                                        if (($tree = $ldap->get_external_ldap_tree($id, $ldap_srcs[$id]['dn'], $recursive))) 
     415                                        { 
     416                                                if (array_key_exists('error_msg', $tree)) 
     417                                                { 
     418                                                        if (isset($this->tree['branches']['msg'])) 
     419                                                        { 
     420                                                                $this->tree['branches']['msg'] .= "\n" . lang('Catalog %1 not showed due to error: ' . 
     421                                                                                                         $tree['error_msg'], $ldap_srcs[$id]['name']); 
     422                                                        } 
     423                                                        else 
     424                                                        { 
     425                                                                $this->tree['branches']['msg'] = lang('Catalog %1 not showed due to error: ' . 
     426                                                                                                         $tree['error_msg'], $ldap_srcs[$id]['name']); 
     427                                                        } 
     428                                                } 
     429 
     430                                                else 
     431                                                { 
     432                                                */ 
    299433                                                $tree['name'] = $ldap_srcs[$id]['name']; 
     434                                                $tree['type'] = 'unknown'; 
     435                                                $tree['value'] = $ldap_srcs[$id]['dn']; 
     436                                                $tree['external'] = true; 
     437                                                //$tree['sub_branch'] = false; 
    300438                                                array_push($this->tree['branches'], $tree); 
    301439                                                $this->tree[$i]['type'] = 'ldap'; 
    302440                                                $this->tree[$i]['src'] = $id; 
    303                                         } 
     441                                        //      } 
     442                                        //} 
    304443                                        $i++; 
    305444                                } 
    306445                        } 
    307                          
     446 
    308447                        $GLOBALS['phpgw']->session->appsession('bo_contactcenter.tree','contactcenter',$this->tree); 
    309448                        return $this->tree['branches']; 
    310                 } 
    311  
    312                 /*! 
    313                          
     449                        //return null; 
     450                } 
     451 
     452                /*! 
     453 
    314454                        @function get_branch_by_level 
    315455                        @abstract Returns the branch and it's informations given the level 
    316456                        @author Raphael Derosso Pereira 
    317                          
     457 
    318458                        @param (string) $level The level to be used 
    319                          
     459 
    320460                */ 
    321461                function & get_branch_by_level($level) 
     
    323463                        $path = @explode('.',$level); 
    324464                        $n_ways = count($path); 
    325                          
     465 
    326466                        if ($n_ways <= 1) 
    327467                        { 
    328468                                return false; 
    329469                        } 
    330                          
     470 
    331471                        $code = '$branch =& $this->tree[\'branches\']'; 
    332472                        for ($i = 1; $i < $n_ways-1; $i++) 
     
    338478                        //echo 'Codigo: '.$code.'<br>'; 
    339479                        eval($code); 
    340                          
     480 
    341481                        return $branch; 
    342482                } 
    343483 
    344484                /*! 
    345                   
     485 
    346486                 @function get_info_by_level 
    347487                 @abstract Returns the information about the catalog, given the level 
     
    355495                        $path = @explode('.',$level); 
    356496                        $n_ways = count($path); 
    357                          
     497 
    358498                        if ($n_ways <= 1) 
    359499                        { 
    360500                                return false; 
    361501                        } 
    362                          
     502 
    363503                        $info = $this->tree[$path[1]]; 
    364                          
     504 
    365505                        return $info; 
    366506                } 
     
    413553 
    414554                                        $search = $this->get_level_by_branch($catalog, $bcatalog['sub_branch'], (string) $level); 
    415                                          
     555 
    416556                                        if ($search !== false) 
    417557                                        { 
     
    427567                        return false; 
    428568                } 
    429                  
    430                 /*! 
    431                  
     569 
     570                /*! 
     571 
    432572                        @function get_actual_catalog 
    433                         @abstract Returns the information about the Catalog that is  
     573                        @abstract Returns the information about the Catalog that is 
    434574                                instantiated 
    435575 
    436576                        @author Raphael Derosso Pereira 
    437                  
     577 
    438578                */ 
    439579                function get_actual_catalog() 
     
    442582                        return $catalog; 
    443583                } 
    444                  
    445                 /*! 
    446                  
     584 
     585                /*! 
     586 
    447587                        @function set_catalog 
    448588                        @abstract Sets the actual catalog 
    449589                        @author Raphael Derosso Pereira 
    450                          
     590 
    451591                        @param array $to_catalog The catalog in the format returned by 
    452592                                get_available_tree or the level 
    453                  
     593 
    454594                */ 
    455595                function set_catalog(& $to_catalog ) 
     
    477617                                $level = $this->get_level_by_branch($to_catalog, $this->tree['branches']); 
    478618                        } 
    479                          
     619 
     620                        $lvl_vector = explode('.', $level); 
     621                        $id = $lvl_vector[1]; 
     622 
    480623                        switch($catalog['type']) 
    481624                        { 
     
    499642                                                $call .= ','.implode(',',$args); 
    500643                                        } 
    501                                          
     644 
    502645                                        $call .= ');'; 
    503                                          
     646 
    504647//                                      print_r($catalog); 
    505648//                                      echo '<br><br><b>Setando Catalogo '.$catalog['name'].': </b>'.$call.'<br>'; 
    506649 
    507650                                        eval($call); 
    508                                                                  
     651 
    509652                                        return $catalog; 
    510                                          
     653 
    511654                                default: return false; 
    512655                        } 
    513656                } 
    514                  
     657 
    515658 
    516659 
     
    518661                 *                Methods to set general fields                      * 
    519662                \*********************************************************************/ 
    520                  
    521                 /*! 
    522                  
     663 
     664                /*! 
     665 
    523666                        @function add_vcard 
    524667                        @abstract Insert a VCard to the squema 
     
    526669                        @param string $uploaded_file The path to the file that were 
    527670                                uploaded. 
    528                  
     671 
    529672                */ 
    530673                function add_vcard ( $uploaded_file ) 
     
    533676 
    534677 
    535                  
     678 
    536679                /*********************************************************************\ 
    537680                 *                Methods to get general data                        * 
    538681                \*********************************************************************/ 
    539                  
     682 
    540683        } 
    541684?> 
Note: See TracChangeset for help on using the changeset viewer.