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.ui_data.inc.php

    r276 r284  
    1414  \***************************************************************************/ 
    1515 
    16          
     16 
    1717        class ui_data 
    1818        { 
     
    2020                        'data_manager' => true, 
    2121                ); 
    22                  
     22 
    2323                var $bo; 
    2424                var $typeContact; 
    25                  
     25 
    2626                var $page_info = array( 
    2727                        'n_cards'          => 20, 
     
    3434                        'actual_catalog'   => false 
    3535                ); 
    36                  
     36 
    3737                /*! 
    38                  
     38 
    3939                        @function ui_data 
    4040                        @abstract The constructor. Sets the initial parameters and loads 
    4141                                the data saved in the session 
    4242                        @author Raphael Derosso Pereira 
    43                          
     43 
    4444                */ 
    4545                function ui_data() 
     
    4747                        $temp = $GLOBALS['phpgw']->session->appsession('ui_data.page_info','contactcenter'); 
    4848                        $temp2 = $GLOBALS['phpgw']->session->appsession('ui_data.all_entries','contactcenter'); 
    49                          
     49 
     50                        //TODO: Achar um modo de descarregar este array da sessï¿œo quando o usuï¿œrio sair da tela do contactcenter. 
     51                        //TODO: Descarregar este array da memï¿œria toda vez que uma nova consulta por letras ou mudanï¿œa de catï¿œlogo for feita. 
     52                        $temp3 = $GLOBALS['phpgw']->session->appsession('ui_data.last_search_ids','contactcenter'); 
     53 
    5054                        $this->bo = CreateObject('contactcenter.bo_contactcenter'); 
    51                          
     55 
    5256                        if ($temp) 
    5357                        { 
     
    5963                                $this->all_entries = $temp2; 
    6064                        } 
    61                          
     65 
     66                        if ($temp3) 
     67                        { 
     68                                $this->last_search_ids = $temp3; 
     69                        } 
     70 
    6271                        if (!$this->page_info['actual_catalog']) 
    6372                        { 
     
    6574                                $this->page_info['actual_catalog'] = $catalogs[0]; 
    6675                        } 
    67                          
    68                         $this->page_info['actual_catalog'] =& $this->bo->set_catalog($this->page_info['actual_catalog']);                        
    69                          
     76 
     77                        $this->page_info['actual_catalog'] =& $this->bo->set_catalog($this->page_info['actual_catalog']); 
     78 
    7079                        if($this->page_info['actual_catalog']['class'] == 'bo_group_manager') 
    7180                                $this -> typeContact = 'groups'; 
     
    7584 
    7685                /*! 
    77                  
     86 
    7887                        @function index 
    7988                        @abstract Builds the Main Page 
    8089                        @author Raphael Derosso Pereira 
    8190                        @author Jonas Goes 
    82                          
    83                 */               
     91 
     92                */ 
    8493                function index() 
    85                 {        
     94                { 
    8695                        if(!@is_object($GLOBALS['phpgw']->js)) 
    8796                        { 
     
    92101                        $GLOBALS['phpgw']->js->validate_file('venus','jsStructUtil'); 
    93102                        $GLOBALS['phpgw']->js->validate_file('venus','cssUtil'); 
    94                          
     103 
    95104//                      $GLOBALS['phpgw']->js->set_onload('setTimeout(\'updateCards()\',1000)'); 
    96105                        $GLOBALS['phpgw']->common->phpgw_header(); 
    97                          
     106 
    98107                        $GLOBALS['phpgw']->template->set_file(array('index' => 'index.tpl')); 
    99108                        $GLOBALS['phpgw']->template->set_var('cc_root_dir', $GLOBALS['phpgw_info']['server']['webserver_url'].'/contactcenter/'); 
    100                          
     109 
    101110                        /* Quick Add */ 
    102111                        $GLOBALS['phpgw']->template->set_var('cc_qa_alias',lang('Alias').':'); 
     
    107116                        $GLOBALS['phpgw']->template->set_var('cc_qa_save',lang('Save')); 
    108117                        $GLOBALS['phpgw']->template->set_var('cc_qa_clear',lang('Clear')); 
    109                         $GLOBALS['phpgw']->template->set_var('cc_qa_close',lang('Close')); 
    110118                        /* End Quick Add */ 
    111                          
     119 
    112120                        $cc_css_file = $GLOBALS['phpgw_info']['server']['webserver_url'].'/contactcenter/styles/cc.css'; 
    113121                        $cc_card_image_file = $GLOBALS['phpgw_info']['server']['webserver_url'].'/contactcenter/templates/default/images/card.png'; 
     
    115123                        $GLOBALS['phpgw']->template->set_var('cc_dtree_css', $cc_dtree_file); 
    116124                        $GLOBALS['phpgw']->template->set_var('cc_card_image',$cc_card_image_file); 
    117                          
     125 
    118126                        $GLOBALS['phpgw']->template->set_var('cc_personal',lang('Personal')); 
    119                          
     127 
    120128                        $GLOBALS['phpgw']->template->set_var('cc_full_add',lang('Full Add')); 
    121129                        $GLOBALS['phpgw']->template->set_var('cc_reset',lang('Reset')); 
    122                          
     130 
    123131                        $GLOBALS['phpgw']->template->set_var('cc_personal_data',lang('Personal Data')); 
    124132                        $GLOBALS['phpgw']->template->set_var('cc_addresses',lang('Addresses')); 
     
    129137                        $GLOBALS['phpgw']->template->set_var('cc_catalogs',lang('Catalogues')); 
    130138                        $GLOBALS['phpgw']->template->set_var('cc_group_add',lang('Group Add')); 
    131                          
     139 
    132140                        /* Panel */ 
    133141                        $GLOBALS['phpgw']->template->set_var('cc_panel_new',lang('New').'...'); 
     
    135143                        $GLOBALS['phpgw']->template->set_var('cc_panel_table',lang('Table View')); 
    136144                        $GLOBALS['phpgw']->template->set_var('cc_panel_cards',lang('Cards View')); 
    137                         $GLOBALS['phpgw']->template->set_var('cc_btn_import_export', lang('Import/Export')); 
    138                         $GLOBALS['phpgw']->template->set_var('cc_btn_new', lang("New...")); 
    139                          
     145 
    140146                        $GLOBALS['phpgw']->template->set_var('cc_panel_search_found',lang('Showing found entries')); 
    141147                        $GLOBALS['phpgw']->template->set_var('cc_panel_first_page',lang('First Page')); 
     
    145151                        $GLOBALS['phpgw']->template->set_var('cc_all',lang('all')); 
    146152                        /* End Panel */ 
    147                          
     153 
    148154                        /* Messages */ 
    149155                        $GLOBALS['phpgw']->template->set_var('cc_msg_no_cards',lang('No Cards')); 
     
    160166                        $GLOBALS['phpgw']->template->set_var('cc_empty',lang('Empty')); 
    161167                        /* End Messages */ 
    162                          
     168 
    163169                        $GLOBALS['phpgw']->template->set_var('cc_results',lang('Results')); 
    164170                        $GLOBALS['phpgw']->template->set_var('cc_is_my',lang('Is My')); 
    165                         $GLOBALS['phpgw']->template->set_var('cc_ie_personal',lang('Import/Export pesonal contacts')); 
    166171                        $GLOBALS['phpgw']->template->set_var('cc_btn_search',lang('Search')); 
    167172                        $GLOBALS['phpgw']->template->set_var('cc_add_relation',lang('Add Relation')); 
    168                         $GLOBALS['phpgw']->template->set_var('cc_del_relation',lang('Remove Selected Relations'));                       
     173                        $GLOBALS['phpgw']->template->set_var('cc_del_relation',lang('Remove Selected Relations')); 
    169174                        $GLOBALS['phpgw']->template->set_var('cc_msg_group',lang('Group')); 
    170175                        $GLOBALS['phpgw']->template->set_var('cc_msg_contact_full',lang('Contact [Full]')); 
     
    174179                        $GLOBALS['phpgw']->template->set_var('phpgw_img_dir', $GLOBALS['phpgw_info']['server']['webserver_url'] . '/phpgwapi/images'); 
    175180 
    176                         $GLOBALS['phpgw']->template->set_var('cc_msg_import_contacts', lang('Import Contacts')); 
    177                         $GLOBALS['phpgw']->template->set_var('cc_msg_export_contacts', lang('Export Contacts')); 
    178                         $GLOBALS['phpgw']->template->set_var('cc_msg_expresso_info_csv', lang('The Expresso supports the contacts importation in the CSV file format.')); 
    179                         $GLOBALS['phpgw']->template->set_var('cc_msg_choose_file_type', lang('Select the file type')); 
    180                         $GLOBALS['phpgw']->template->set_var('cc_msg_outlook_express', lang('Outlook Express')); 
    181                         $GLOBALS['phpgw']->template->set_var('cc_msg_outlook2k', lang('Outlook 2000')); 
    182                         $GLOBALS['phpgw']->template->set_var('cc_msg_expresso_default', lang('Expresso (default)')); 
    183                         $GLOBALS['phpgw']->template->set_var('cc_msg_choose_contacts_file', lang('Select the file that contains the contacts to be imported:')); 
    184                         $GLOBALS['phpgw']->template->set_var('cc_msg_close_win', lang('Close')); 
    185                         $GLOBALS['phpgw']->template->set_var('cc_msg_ie_personal', lang('Import / Export personal Contacts')); 
    186                         $GLOBALS['phpgw']->template->set_var('cc_msg_import_fail', lang('The importation has failed. Verify the file format.')); 
    187                         $GLOBALS['phpgw']->template->set_var('cc_msg_importing_contacts', lang('Importing Contacts...')); 
    188                         $GLOBALS['phpgw']->template->set_var('cc_msg_import_finished', lang('The importation has finished.')); 
    189                         $GLOBALS['phpgw']->template->set_var('cc_msg_new', lang(' new')); 
    190                         $GLOBALS['phpgw']->template->set_var('cc_msg_failure', lang(' failed')); 
    191                         $GLOBALS['phpgw']->template->set_var('cc_msg_exists', lang(' were existent')); 
    192                         $GLOBALS['phpgw']->template->set_var('cc_msg_show_more_info', lang('show more info')); 
    193                         $GLOBALS['phpgw']->template->set_var('cc_msg_clean', lang('Clean')); 
    194                         $GLOBALS['phpgw']->template->set_var('cc_msg_invalid_csv', lang('Select a valid CSV file to import your contacts')); 
    195                         $GLOBALS['phpgw']->template->set_var('cc_msg_export_csv', lang('Select the format type that you want to export your contacts')); 
    196                         $GLOBALS['phpgw']->template->set_var('cc_msg_automatic', lang('Automatic')); 
    197                         $GLOBALS['phpgw']->template->set_var('cc_msg_export_error', lang('An error has occurred while the exportation.')); 
    198                         $GLOBALS['phpgw']->template->set_var('cc_msg_new_email', lang('New Email')); 
    199                         $GLOBALS['phpgw']->template->set_var('cc_msg_main', lang('Main')); 
    200                         $GLOBALS['phpgw']->template->set_var('cc_msg_alternative', lang('Alternative')); 
    201                         $GLOBALS['phpgw']->template->set_var('cc_msg_select_email', lang('Select E-Mail')); 
    202                         $GLOBALS['phpgw']->template->set_var('cc_msg_new_phone', lang('New Telephone')); 
    203                         $GLOBALS['phpgw']->template->set_var('cc_msg_home', lang('Home')); 
    204                         $GLOBALS['phpgw']->template->set_var('cc_msg_cellphone', lang('Cellphone')); 
    205                         $GLOBALS['phpgw']->template->set_var('cc_msg_work', lang('Work')); 
    206                         $GLOBALS['phpgw']->template->set_var('cc_msg_fax', lang('Fax')); 
    207                         $GLOBALS['phpgw']->template->set_var('cc_msg_pager', lang('Pager')); 
    208                         $GLOBALS['phpgw']->template->set_var('cc_msg_choose_phone', lang('Select the telephone')); 
    209                         $GLOBALS['phpgw']->template->set_var('cc_msg_warn_firefox', lang('Warning: Too old version of Firefox')); 
    210                         $GLOBALS['phpgw']->template->set_var('cc_msg_firefox_half1', lang('For this application work correctly</u>')); 
    211                         $GLOBALS['phpgw']->template->set_var('cc_msg_firefox_half2', lang('it\'s necessary to update your Firefox Browser for a new version (version > 1.5) Install now clicking in the link bellow, or if you want to update it later')); 
    212                         $GLOBALS['phpgw']->template->set_var('cc_msg_click_close', lang('click Close')); 
    213                         $GLOBALS['phpgw']->template->set_var('cc_msg_install_now', lang('Install Now')); 
    214                         $GLOBALS['phpgw']->template->set_var('cc_msg_install_new_firefox', lang('Install a new Firefox version')); 
    215                         $GLOBALS['phpgw']->template->set_var('cc_msg_moz_thunderbird', lang('Export as Mozilla Thunderbird CSV.')); 
    216                         $GLOBALS['phpgw']->template->set_var('cc_msg_outlook_express_pt', lang('Export as Outlook Express (Portuguese) CSV.')); 
    217                         $GLOBALS['phpgw']->template->set_var('cc_msg_outlook_express_en', lang('Export as Outlook Express (English) CSV.')); 
    218                         $GLOBALS['phpgw']->template->set_var('cc_msg_outlook_2k_pt', lang('Export as Outlook 2000 (Portuguese) CSV.')); 
    219                         $GLOBALS['phpgw']->template->set_var('cc_msg_outlook_2k_en', lang('Export as Outlook 2000 (English) CSV.')); 
    220                         $GLOBALS['phpgw']->template->set_var('cc_msg_expresso_default_csv', lang('Export as Expresso (Default) CSV.')); 
    221                         $GLOBALS['phpgw']->template->set_var('cc_msg_copy_to_catalog', lang('Copy to personal catalog.')); 
    222                         $GLOBALS['phpgw']->template->set_var('cc_msg_add_contact_to_group', lang('You did not add any contact for this group.')); 
    223                         $GLOBALS['phpgw']->template->set_var('cc_msg_fill_field_name', lang('Fill the field Full Name')); 
    224                          
    225181                        $GLOBALS['phpgw']->template->parse('out','index'); 
    226                          
     182 
    227183                        $api = CreateObject('contactcenter.ui_api'); 
    228184                        $main = $api->get_full_add(); 
     
    235191                } 
    236192 
    237                  
     193 
    238194                /*! 
    239                  
     195 
    240196                        @function data_manager 
    241                         @abstract Calls the right method and passes to it the right  
     197                        @abstract Calls the right method and passes to it the right 
    242198                                parameters 
    243199                        @author Raphael Derosso Pereira 
    244                  
     200 
    245201                */ 
    246202                function data_manager() 
     
    251207                                case 'set_n_cards': 
    252208                                        return $this->set_n_cards((int)$_GET['ncards']); 
    253                                          
     209 
    254210                                case 'get_cards_data': 
    255                                         return $this->get_cards_data($_POST['letter'], $_POST['page'], unserialize(str_replace('\\"','"',$_POST['ids']))); 
     211 
     212                                        $ids = false; 
     213                                        // To support ldap catalogs using accentuation 
     214                                        if ($_POST['letter'] == 'search' && isset($_POST['data'])) 
     215                                        { 
     216                                                //$ids = utf8_decode($this->search($_POST['data'])); 
     217                                                $ids = $this->search($_POST['data']); 
     218                                        } 
     219 
     220                                        //return $this->get_cards_data($_POST['letter'], $_POST['page'], unserialize(str_replace('\\"','"',$ids))); 
     221                                        return $this->get_cards_data($_POST['letter'], $_POST['page'], $ids); 
     222                                        //return $this->get_cards_data($_POST['letter'], $_POST['page'], unserialize(str_replace('\\"','"',$_POST['ids']))); 
     223 
    256224                                case 'get_cards_data_get': 
    257225                                        return $this->get_cards_data($_GET['letter'], $_GET['page'], unserialize(str_replace('\\"','"',$_GET['ids']))); 
     
    261229                                        return $this->get_photo($_GET['id']); 
    262230 
    263                                          
     231 
    264232                                /* Catalog Methods */ 
    265233                                case 'set_catalog': 
    266234                                        return $this->set_catalog($_GET['catalog']); 
    267                                          
     235 
    268236                                case 'get_catalog_tree': 
    269237                                        echo serialize($this->get_catalog_tree($_GET['level'])); 
     
    279247 
    280248                                case 'get_catalog_add_contact': 
    281                                         echo serialize($this->get_catalog_add_contact($_POST['id'])); 
     249                                        // To support ldap catalogs with accentuation 
     250                                        echo serialize($this->get_catalog_add_contact(utf8_decode($_POST['id']))); 
    282251                                        return; 
    283                                          
     252 
    284253                                /* Full Add Methods */ 
    285254                                case 'get_full_data': 
    286255                                        return $this->get_full_data($_GET['id']); 
    287                                  
     256 
    288257                                case 'get_group': 
    289258                                        return $this->get_group_data($_GET['id']); 
    290                                          
     259 
    291260                                case 'get_contact_full_add_const': 
    292261                                        return $this->get_contact_full_add_const(); 
     
    300269                                case 'get_states': 
    301270                                        return $this->get_states($_GET['country']); 
    302                                          
     271 
    303272                                case 'get_cities': 
    304273                                        return $this->get_cities($_GET['country'], $_GET['state'] ? $_GET['state'] : null); 
    305                                          
    306                                          
     274 
     275 
    307276                                /* Other Methods */ 
    308                                 case 'quick_add':                                                                                                                        
     277                                case 'quick_add': 
    309278                                        return $this->quick_add($_POST['add']); 
    310                                  
    311                                 case 'add_group':                                                                                                                        
     279 
     280                                case 'add_group': 
    312281                                        return $this->add_group($_POST['add']); 
    313                                                                          
     282 
    314283                                case 'remove_entry': 
    315284                                        return $this->remove_entry((int)$_GET['remove']); 
    316                                  
     285 
    317286                                case 'remove_all_entries': 
    318287                                        return $this->remove_all_entries(); 
    319288 
    320289                                case 'remove_group': 
    321                                                                                  
    322                                         return $this->remove_group((int)$_GET['remove']);                                        
     290 
     291                                        return $this->remove_group((int)$_GET['remove']); 
    323292 
    324293                                case 'search': 
     
    357326 
    358327                /*! 
    359                  
     328 
    360329                        @function set_n_cards 
    361330                        @abstract Informs the class the number of cards the page can show 
    362331                        @author Raphael Derosso Pereira 
    363                          
     332 
    364333                        @param integer $n_cards The number of cards 
    365                          
     334 
    366335                */ 
    367336                function set_n_cards($n_cards) 
     
    372341                                echo 1; 
    373342                        } 
    374                          
     343 
    375344                        $this->save_session(); 
    376345                } 
    377                                  
     346 
    378347                /*! 
    379                  
     348 
    380349                        @function set_catalog 
    381350                        @abstract Sets the current catalog selected by the user 
    382351                        @author Raphael Derosso Pereira 
    383                          
     352 
    384353                        @param string $id_catalog The sequence of IDs to reach the catalog 
    385354                                separated by commas 
    386                  
     355 
    387356                */ 
    388357                function set_catalog($id_catalog) 
     
    390359                        $id_catalog = str_replace('\\"', '"', $id_catalog); 
    391360                        $temp =& $this->bo->set_catalog($id_catalog); 
    392                          
     361 
    393362                        if ($temp) 
    394363                        { 
     
    397366                                $this->page_info['actual_catalog'] =& $temp; 
    398367                                $this->save_session(); 
    399                                  
     368 
    400369                                $catalog_info = $this->bo->get_branch_by_level($this->bo->catalog_level[0]); 
    401                                  
     370 
    402371                                if ($catalog_info['class'] === 'bo_global_ldap_catalog' || 
    403372                                    $catalog_info['class'] === 'bo_catalog_group_catalog') 
     
    409378                                        $perms = 15; 
    410379                                } 
    411                                  
     380 
    412381                                echo serialize(array( 
    413382                                        'status' => 'ok', 
     
    417386                                return; 
    418387                        } 
    419                          
     388 
    420389                        echo serialize(array( 
    421390                                'status' => 'ok', 
     
    423392                        )); 
    424393                } 
    425                  
    426                  
     394 
     395 
    427396                /*! 
    428                  
     397 
    429398                        @function get_catalog_tree 
    430399                        @abstract Returns the JS serialized array to used as the tree 
    431400                                level 
    432401                        @author Raphael Derosso Pereira 
    433                          
    434                         @param (string) $level The level to be taken  
    435                  
     402                        @author Mï¿œrio Cï¿œsar Kolling (error messages and timeout) 
     403 
     404                        @param (string) $level The level to be taken 
     405 
    436406                */ 
    437407                function get_catalog_tree($level) 
     
    442412 
    443413                                $parent = '0'; 
    444                                  
     414 
    445415                                if (!($tree = $this->bo->get_catalog_tree($level))) 
    446416                                { 
     
    456426                                $parent = substr($level, 0, $last_dot); 
    457427                                $child = substr($level, $last_dot+1, strlen($level)); 
    458                          
     428 
    459429                                if (!($tree[$child] = $this->bo->get_catalog_tree($level))) 
    460430                                { 
     
    464434                                        ); 
    465435                                } 
    466                         } 
    467                          
     436                                // Deals with timeout and returns the generated message to the browser 
     437                                else if (!empty($tree[$child]['timeout']) && !empty($tree[$child]['msg'])) 
     438                                { 
     439                                        $tmp = array( 
     440                                                'msg'    => $tree[$child]['msg'], 
     441                                                'status' => 'fatal' 
     442                                        ); 
     443                                        unset($tree[$child]); 
     444                                        return $tmp; 
     445                                } 
     446                        } 
     447 
    468448                        $folderImageDir = $GLOBALS['phpgw']->common->image('contactcenter','globalcatalog-mini.png'); 
    469449                        $folderImageDir = substr($folderImageDir, 0, strpos($folderImageDir, 'globalcatalog-mini.png')); 
    470                          
     450 
     451                        // Deals with error messages from the server and returns them to the browser 
     452                        if ($tree['msg']) 
     453                        { 
     454                                $msg = $tree['msg']; 
     455                                unset($tree['msg']); 
     456                        } 
     457 
    471458                        $tree_js = $this->convert_tree($tree, $folderImageDir, $parent); 
    472                          
    473                         return array( 
    474                                 'data' => $tree_js, 
    475                                 'msg'  => lang('Catalog Tree Successfully taken!'), 
    476                                 'status' => 'ok' 
    477                         ); 
    478                 } 
    479                  
     459 
     460                        // Return status = ok, or else return generated message to the browser 
     461                        if (!$msg) 
     462                        { 
     463                                return array( 
     464                                        'data' => $tree_js, 
     465                                        'msg'  => lang('Catalog Tree Successfully taken!'), 
     466                                        'status' => 'ok' 
     467                                ); 
     468                        } 
     469                        else 
     470                        { 
     471                                return array( 
     472                                        'data' => $tree_js, 
     473                                        'msg'  => $msg, 
     474                                        'status' => 'error' 
     475                                ); 
     476 
     477                        } 
     478                } 
     479 
    480480/*              function get_catalog_tree($level, $name = 'tree') 
    481481                { 
     
    487487                                $parent = '0'; 
    488488                                $child  = '0'; 
    489                                  
     489 
    490490                                if (!($tree = $this->bo->get_catalog_tree($level))) 
    491491                                { 
     
    498498                                $parent = substr($level, 0, $last_dot); 
    499499                                $child = substr($level, $last_dot+1, strlen($level)); 
    500                          
     500 
    501501                                $tree_js = ''; 
    502                                  
     502 
    503503                                if (!($tree[$child] = $this->bo->get_catalog_tree($level))) 
    504504                                { 
     
    506506                                } 
    507507                        } 
    508                          
     508 
    509509                        $folderImageDir = $GLOBALS['phpgw']->common->image('contactcenter','globalcatalog-mini.png'); 
    510510                        $folderImageDir = substr($folderImageDir, 0, strpos($folderImageDir, 'globalcatalog-mini.png')); 
    511                          
     511 
    512512                        $tree_js .= $this->convert_tree($tree, $name, $folderImageDir, $parent); 
    513                          
     513 
    514514                        return $tree_js; 
    515515                } 
    516 */               
    517                  
     516*/ 
     517 
    518518                /*! 
    519                  
     519 
    520520                        @function get_actual_catalog 
    521521                        @abstract Returns the actual selected Catalog 
     
    524524                */ 
    525525                function get_actual_catalog() 
    526                 {                        
     526                { 
    527527                        $level = $this->bo->get_level_by_branch($this->bo->get_actual_catalog(), $this->bo->tree['branches'], '0'); 
    528                          
     528 
    529529                        if ($level) 
    530530                        { 
     
    540540                        ); 
    541541                } 
    542                  
     542 
    543543                /*! 
    544                  
     544 
    545545                        @function get_cards_data 
    546546                        @abstract Returns the information that is placed on the cards 
    547547                        @author Raphael Derosso Pereira 
    548                          
     548 
    549549                        @param string $letter The first letter to be searched 
    550                         @param (int)  $page The page to be taken  
     550                        @param (int)  $page The page to be taken 
    551551                        @param (str)  $ids The ids to be taken in case of search 
    552552 
     
    556556                function get_cards_data($letter, $page, $ids) 
    557557                { 
     558 
     559                        // It's an external catalog? 
     560                        $external = $this->bo->is_external($this->page_info['actual_catalog']); 
     561 
    558562                        //echo $page."\n"; 
    559563                        if ($letter !== 'search' and ($letter != $this->page_info['actual_letter'] or 
    560                             ($letter == $this->page_info['actual_letter'] and $page == $this->page_info['actual_page']) or  
     564                            ($letter == $this->page_info['actual_letter'] and $page == $this->page_info['actual_page']) or 
    561565                            $this->page_info['changed'])) 
    562566                        { 
    563567                                unset($ids); 
    564568                                $this->page_info['changed'] = false; 
    565                                   
     569 
    566570                                switch ($this->page_info['actual_catalog']['class']) 
    567571                                { 
     
    650654                                                        ); 
    651655                                                } 
    652                                                  
     656 
    653657                                                $find_field[0] = array('contact.id_contact','contact.names_ordered'); 
    654                                                  
     658 
    655659                                                $find_other[0] = array( 
    656660                                                        //'offset' => (($page-1)*$this->page_info['n_cards']), 
     
    658662                                                        'order'  => 'contact.names_ordered' 
    659663                                                ); 
    660                                                  
     664 
    661665                                                break; 
    662                                          
     666 
     667                                        //case 'bo_external_ldap_catalog': 
     668 
     669                                        //      break; 
     670 
    663671                                        case 'bo_global_ldap_catalog': 
    664672                                                $field_name = 'id_contact'; 
     
    671679                                                                        'type'  => 'iLIKE', 
    672680                                                                        'value' => $letter !== 'all' ? $letter.'%' : '%' 
    673                                                                 ) 
     681                                                                ), 
     682                                                                /* 
     683                                                                 * Restrict the returned contacts in a "first letter" search 
     684                                                                 * to objectClass = phpgwAccount, must have attibute phpgwAccountStatus, 
     685                                                                 * phpgwAccountVisible != -1 and objectClass = inetOrgPerson 
     686                                                                 */ 
     687                                                                1 => array( 
     688                                                                        'field' => 'contact.object_class', 
     689                                                                        'type'  => '=', 
     690                                                                        'value' => 'phpgwAccount' 
     691                                                                ), 
     692                                                                2 => array( 
     693                                                                        'field' => 'contact.account_status', 
     694                                                                        'type'  => 'iLIKE', 
     695                                                                        'value' => '%' 
     696                                                                ), 
     697                                                                3 => array( 
     698                                                                        'field' => 'contact.account_visible', 
     699                                                                        'type'  => '!=', 
     700                                                                        'value' => '-1' 
     701                                                                ), 
     702                                                                4 => array( 
     703                                                                        'field' => 'contact.object_class', 
     704                                                                        'type'  => '=', 
     705                                                                        'value' => 'inetOrgPerson' 
     706                                                                ), 
    674707                                                        ); 
    675                                                         $find_restric[0][1] =  array( 
    676                                                                         'type'  => 'branch', 
    677                                                                         'value' => 'OR', 
    678                                                                         'sub_branch' => array( 
    679                                                                                 0 => array( 
    680                                                                                 'field' => 'contact.account_type', 
    681                                                                                 'type'  => '=', 
    682                                                                                 'value' => 'u' 
    683                                                                                 ), 
    684                                                                                 /*1 => array( 
    685                                                                                 'field' => 'contact.account_type', 
    686                                                                                 'type'  => '=', 
    687                                                                                 'value' => 'g' 
    688                                                                                 ),*/ 
    689                                                                                 2 => array( 
    690                                                                                 'field' => 'contact.account_type', 
    691                                                                                 'type'  => '=', 
    692                                                                                 'value' => 'l' 
     708                                                        // If not external catalog get only phpgwAccountType = u ou l 
     709                                                        if (!$external) 
     710                                                        { 
     711                                                                $find_restric[0][5] =  array( 
     712                                                                                'type'  => 'branch', 
     713                                                                                'value' => 'OR', 
     714                                                                                'sub_branch' => array( 
     715                                                                                        0 => array( 
     716                                                                                        'field' => 'contact.account_type', 
     717                                                                                        'type'  => '=', 
     718                                                                                        'value' => 'u' 
     719                                                                                        ), 
     720                                                                                        /*1 => array( 
     721                                                                                        'field' => 'contact.account_type', 
     722                                                                                        'type'  => '=', 
     723                                                                                        'value' => 'g' 
     724                                                                                        ),*/ 
     725                                                                                        2 => array( 
     726                                                                                        'field' => 'contact.account_type', 
     727                                                                                        'type'  => '=', 
     728                                                                                        'value' => 'l' 
     729                                                                                        ) 
    693730                                                                                ) 
    694                                                                         ) 
    695                                                         ); 
     731                                                                ); 
     732                                                        } 
    696733                                                } 
    697734                                                else 
    698735                                                { 
    699736                                                        $find_restric[0] = array( 
     737                                                                /* 
     738                                                                 * Restrict the returned contacts in a "first number" search 
     739                                                                 * to objectClass = phpgwAccount, must have attibute phpgwAccountStatus, 
     740                                                                 * phpgwAccountVisible != -1 and objectClass = inetOrgPerson 
     741                                                                 */ 
    700742                                                                0 => array( 
     743                                                                        'field' => 'contact.object_class', 
     744                                                                        'type'  => '=', 
     745                                                                        'value' => 'phpgwAccount' 
     746                                                                ), 
     747                                                                1 => array( 
     748                                                                        'field' => 'contact.account_status', 
     749                                                                        'type'  => 'iLIKE', 
     750                                                                        'value' => '%' 
     751                                                                ), 
     752                                                                2 => array( 
     753                                                                        'field' => 'contact.account_visible', 
     754                                                                        'type'  => '!=', 
     755                                                                        'value' => '-1' 
     756                                                                ), 
     757                                                                3 => array( 
     758                                                                        'field' => 'contact.object_class', 
     759                                                                        'type'  => '=', 
     760                                                                        'value' => 'inetOrgPerson' 
     761                                                                ), 
     762                                                                4 => array( 
    701763                                                                        'type'  => 'branch', 
    702764                                                                        'value' => 'OR', 
     
    755817                                                                ), 
    756818                                                        ); 
    757                                                         $find_restric[0][1] =  array( 
    758                                                                 'type'  => 'branch', 
    759                                                                 'value' => 'OR', 
    760                                                                 'sub_branch' => array( 
    761                                                                         0 => array( 
    762                                                                         'field' => 'contact.account_type', 
    763                                                                         'type'  => '=', 
    764                                                                         'value' => 'u' 
    765                                                                         ), 
    766                                                                         /*1 => array( 
    767                                                                         'field' => 'contact.account_type', 
    768                                                                         'type'  => '=', 
    769                                                                         'value' => 'g' 
    770                                                                         ),*/ 
    771                                                                         2 => array( 
    772                                                                         'field' => 'contact.account_type', 
    773                                                                         'type'  => '=', 
    774                                                                         'value' => 'l' 
     819                                                        // If not external catalog get only phpgwAccountType = u ou l 
     820                                                        if (!$external) 
     821                                                        { 
     822                                                                $find_restric[0][5] =  array( 
     823                                                                        'type'  => 'branch', 
     824                                                                        'value' => 'OR', 
     825                                                                        'sub_branch' => array( 
     826                                                                                0 => array( 
     827                                                                                'field' => 'contact.account_type', 
     828                                                                                'type'  => '=', 
     829                                                                                'value' => 'u' 
     830                                                                                ), 
     831                                                                                /*1 => array( 
     832                                                                                'field' => 'contact.account_type', 
     833                                                                                'type'  => '=', 
     834                                                                                'value' => 'g' 
     835                                                                                ),*/ 
     836                                                                                2 => array( 
     837                                                                                'field' => 'contact.account_type', 
     838                                                                                'type'  => '=', 
     839                                                                                'value' => 'l' 
     840                                                                                ) 
    775841                                                                        ) 
    776                                                                 ) 
    777                                                         ); 
     842                                                                ); 
     843                                                        } 
     844 
    778845                                                } 
    779                                                  
    780                                                 $find_field[0] = array('contact.id_contact','contact.names_ordered','contact.account_type'); 
    781                                                  
     846 
     847                                                if (!$external) 
     848                                                { 
     849                                                        // Get only this attributes: dn, cn, phpgwAccountType, objectClass, phpgwAccountStatus, phpghAccountVisible 
     850                                                        // for non-external catalogs, used to restrict the attributes used in filters 
     851                                                        $find_field[0] = array('contact.id_contact','contact.names_ordered','contact.account_type', 
     852                                                                'contact.object_class','contact.account_status','contact.account_visible'); 
     853                                                } 
     854                                                else 
     855                                                { 
     856                                                        // Get only this attributes: dn, cn for external catalogs, 
     857                                                        // used to restrict the attributes used in filters 
     858                                                        $find_field[0] = array('contact.id_contact','contact.names_ordered'); 
     859                                                } 
     860 
    782861                                                $find_other[0] = array( 
    783862                                                        //'offset' => (($page-1)*$this->page_info['n_cards']), 
     
    785864                                                        'order'  => 'contact.names_ordered' 
    786865                                                ); 
    787                                                  
     866 
    788867                                                break; 
    789                                          
     868 
    790869                                        case 'bo_company_manager': 
    791870                                                $field_name = 'id_company'; 
    792          
     871 
    793872                                                $find_field[0] = array('company.id_company','company.company_name'); 
    794                                                  
     873 
    795874                                                $find_other[0] = array( 
    796875                                                        //'offset' => (($page-1)*$this->page_info['n_cards']), 
     
    798877                                                        'order'  => 'company.company_name' 
    799878                                                ); 
    800          
     879 
    801880                                                $find_restric[0] = array( 
    802881                                                        0 => array( 
     
    806885                                                        ) 
    807886                                                ); 
    808                                                          
     887 
    809888                                                break; 
    810889 
    811890                                        case 'bo_group_manager': 
    812                                          
     891 
    813892                                                $field_name = 'id_group'; 
    814                                                  
     893 
    815894                                                if ($letter !== 'number')       { 
    816                                                          
     895 
    817896                                                        $find_restric[0] = array( 
    818897                                                                0 => array( 
     
    824903                                                } 
    825904                                                 else { 
    826                                                          
     905 
    827906                                                        $find_restric[0] = array( 
    828907                                                                0 => array( 
    829908                                                                                        'field' => 'group.title', 
    830909                                                                                        'type'  => 'LIKE', 
    831                                                                                         'value' => '0%'                                                                          
     910                                                                                        'value' => '0%' 
    832911                                                                ) 
    833                                                         );                                               
     912                                                        ); 
    834913                                                } 
    835                                                  
     914 
    836915                                                array_push($find_restric[0],  array( 
    837916                                                                                        'field' => 'group.owner', 
    838917                                                                                        'type'  => '=', 
    839                                                                                         'value' => $GLOBALS['phpgw_info']['user']['account_id']                                                                          
     918                                                                                        'value' => $GLOBALS['phpgw_info']['user']['account_id'] 
    840919                                                                ) 
    841920                                                ); 
    842                                                  
    843                                                 $find_field[0] = array('group.id_group','group.title','group.short_name');                                               
     921 
     922                                                $find_field[0] = array('group.id_group','group.title','group.short_name'); 
    844923                                                $find_other[0] = array( 
    845924                                                        'order'  => 'group.title' 
    846925                                                ); 
    847                                                  
     926 
    848927                                                break; 
    849                                                  
     928 
    850929                                        case 'bo_catalog_group_catalog': 
    851930                                                $this->page_info['actual_entries'] = false; 
    852                                                  
     931 
    853932                                                $this->page_info['actual_letter'] = $letter; 
    854933                                                $this->page_info['actual_page'] = 0; 
    855                                                  
     934 
    856935                                                $this->save_session(); 
    857936                                                $final[0] = 0; 
    858937                                                $final[1] = $this -> typeContact; 
    859                                                 echo serialize($final);                                          
     938                                                echo serialize($final); 
    860939                                                return; 
    861940 
    862941                                } 
    863                                  
     942 
    864943                                $result = $this->bo->find($find_field[0],$find_restric[0],$find_other[0]); 
    865944                                $n_entries = count($result); 
    866                                  
     945 
    867946                                if ($n_entries) 
    868947                                { 
     
    878957                                { 
    879958                                        $this->page_info['actual_entries'] = false; 
    880                                          
     959 
    881960                                        $this->page_info['actual_letter'] = $letter; 
    882961                                        $this->page_info['actual_page'] = 0; 
    883                                          
    884                                         $this->save_session();                           
     962 
     963                                        $this->save_session(); 
    885964                                        $final[0] = 0; 
    886965                                        $final[1] = $this -> typeContact; 
    887                                         echo serialize($final);                                                                                  
     966                                        echo serialize($final); 
    888967                                        return; 
    889968                                } 
     
    894973                                        { 
    895974                                                $this->page_info['actual_entries'][] = $value[$field_name]; 
    896                                         }  
    897                                         //print_r($this->page_info['actual_entries']); 
    898                                 } 
    899                         } 
     975                                        } 
     976                                } 
     977                        } 
     978//************************************************************************* 
    900979                        else if ($letter === 'search') 
    901980                        { 
    902                                 if (!$ids and $this->page_info['actual_letter'] !== 'search') 
    903                                 { 
     981                                //if (!$ids and $this->page_info['actual_letter'] !== 'search') 
     982                                if (!$ids && !$this->last_search_ids) 
     983                                { 
     984                                        error_log('!$ids e $this->page_info[\'actual_letter\'] != search'); 
    904985                                        $this->page_info['actual_entries'] = false; 
    905                                          
     986 
    906987                                        $this->page_info['actual_letter'] = $letter; 
    907988                                        $this->page_info['actual_page'] = 0; 
    908                                          
     989 
    909990                                        $this->save_session(); 
    910991                                        $final[0] = 0; 
    911992                                        $final[1] = $this -> typeContact; 
    912                                         echo serialize($final);                                  
     993                                        echo serialize($final); 
    913994                                        return; 
    914995                                } 
    915                                 else if ($ids) 
    916                                 {                                
     996                                else if ($ids['error']) 
     997                                { 
     998                                        $this->page_info['actual_entries'] = false; 
     999                                        $this->page_info['actual_letter'] = $letter; 
     1000                                        $this->page_info['actual_page'] = 0; 
     1001 
     1002                                        $this->save_session(); 
     1003                                        $final[0] = 0; 
     1004                                        $final[1] = $this -> typeContact; 
     1005                                        $final['error'] = $ids['error']; 
     1006                                        echo serialize($final); 
     1007                                        return; 
     1008                                } 
     1009                                else if ($ids || $this->last_search_ids) 
     1010                                { 
     1011 
     1012                                        if ($ids) 
     1013                                        { 
     1014 
     1015                                                $this->last_search_ids = $ids; 
     1016 
     1017                                        } 
     1018                                        else { 
     1019 
     1020                                                $ids = $this->last_search_ids; 
     1021 
     1022                                        } 
     1023 
    9171024                                        $this->page_info['actual_letter']  = $letter; 
    9181025                                        $this->page_info['actual_entries'] = $ids; 
     
    9311038                                        $page = $this->page_info['n_pages']; 
    9321039                                } 
    933                                  
     1040 
    9341041                                $final = array( 
    9351042                                        0 => (int)$this->page_info['n_pages'], 
     
    9431050                                                5 => 'cc_alias', 
    9441051                                                6 => 'cc_id', 
    945                                                 7 => 'cc_forwarding_address' 
     1052                                                7 => 'cc_forwarding_address', 
     1053                                                8 => 'cc_empNumber', 
     1054                                                9 => 'cc_department' 
    9461055                                        ) 
    9471056                                ); 
    948                                  
     1057 
    9491058                                //echo 'Page: '.$page.'<br>'; 
    9501059                                $id_i = (($page-1)*$this->page_info['n_cards']); 
    9511060                                $id_f = $id_i + $this->page_info['n_cards']; 
    9521061                                $n_entries = count($this->page_info['actual_entries']); 
    953                                  
     1062 
    9541063                                //echo 'ID_I: '.$id_i.'<br>'; 
    9551064                                //echo 'ID_F: '.$id_f.'<br>'; 
    956                                 ///---------------- Correção Temporária PHP5 -----------------------/// 
     1065                                ///---------------- Correᅵᅵo Temporï¿œria PHP5 -----------------------/// 
    9571066                                $ids = array(); 
    958                                 $array_temp = array();                   
    959                                                                  
     1067                                $array_temp = array(); 
     1068 
    9601069                                foreach($this->page_info['actual_entries'] as $key=>$tmp){ 
    961                                         $array_temp[] = $tmp;                            
    962                                 }        
    963                                  
     1070                                        $array_temp[] = $tmp; 
     1071                                } 
     1072 
    9641073                                for($i = $id_i; $i < $id_f and $i < $n_entries; $i++) 
    9651074                                { 
    9661075                                        $ids[] = $array_temp[$i]; 
    9671076                                } 
    968                                  
     1077 
    9691078                                /// Original 
    9701079                                //for($i = $id_i; $i < $id_f and $i < $n_entries; $i++) 
     
    9731082                                //} 
    9741083                                /// 
    975                                  
     1084 
    9761085                                $fields = $this->bo->catalog->get_fields(false); 
    9771086 
     
    9851094                                                        2 => 'cc_id', 
    9861095                                                        3 => 'cc_contacts' 
    987                                                 )                                                
    988                                         );                                       
    989                                          
     1096                                                ) 
     1097                                        ); 
     1098 
    9901099                                        $groups =& $this->bo->catalog->get_multiple_entries($ids,$fields); 
    991                                          
     1100 
    9921101                                        $i = 0; 
    9931102                                        // contatos do grupo 
    994                                         $boGroups = CreateObject('contactcenter.bo_group');                                      
     1103                                        $boGroups = CreateObject('contactcenter.bo_group'); 
    9951104                                        $contacts = array(); 
    9961105                                        foreach($groups as $group)              { 
    997                                                                                  
     1106 
    9981107                                                $final[3][$i][0] = $group['title'] ? $group['title'] : 'none'; 
    999                                                 $final[3][$i][1] = $group['short_name'] ? $group['short_name'] : 'none';                                                 
     1108                                                $final[3][$i][1] = $group['short_name'] ? $group['short_name'] : 'none'; 
    10001109                                                $final[3][$i][2] = $group['id_group'] ? $group['id_group'] : 'none'; 
    10011110                                                $contacts = $boGroups -> get_contacts_by_group($group['id_group']); 
    10021111                                                $final[3][$i][3] = $contacts; 
    1003                                                 $i++;                                                    
     1112                                                $i++; 
    10041113                                        } 
    1005                                          
     1114 
    10061115                                        $this->page_info['actual_letter'] = $letter; 
    1007                                         $this->page_info['actual_page'] = $page;                                         
    1008                                          
    1009                                          
     1116                                        $this->page_info['actual_page'] = $page; 
     1117 
     1118 
    10101119                                        $lnk_compose = "location.href=('../expressoMail1_2/index.php?to="; 
    1011                                          
     1120 
    10121121                                        $final[5] = '<span class="link"  onclick="'.$lnk_compose; 
    1013                                         $final[10] = 'groups';                                                                                                                                                                                                                           
    1014                                         $this->save_session();                                   
     1122                                        $final[10] = 'groups'; 
     1123                                        $this->save_session(); 
    10151124                                        echo serialize($final); 
    1016                                         return;                                  
    1017                                 } 
    1018                                  
     1125                                        return; 
     1126                                } 
     1127 
    10191128                                $fields['photo'] = true; 
    10201129                                $fields['names_ordered'] = true; 
     
    10231132                                $fields['companies'] = 'default'; 
    10241133                                $fields['connections'] = 'default'; 
     1134 
     1135                                // ?aqui alterar a chamada desse mï¿œtodo para receber o base dn? 
    10251136                                $contacts =& $this->bo->catalog->get_multiple_entries($ids,$fields); 
    1026                                  
    1027                                  
     1137 
    10281138                                if (!is_array($contacts) or !count($contacts)) 
    10291139                                { 
     
    10331143                                        return; 
    10341144                                } 
    1035                                  
     1145 
    10361146                                $i = 0; 
    1037                                 foreach($contacts as $contact) 
    1038                                 { 
    1039                                         $final[3][$i][0] = $contact['companies']['company1']['company_name']?$contact['companies']['company1']['company_name']:'none'; 
    1040                                         $final[3][$i][1] = $contact['names_ordered'] ? $contact['names_ordered'] : 'none'; 
    1041                                         $final[3][$i][2] = $contact['companies']['company1']['title']?$contact['companies']['company1']['title']:'none'; 
    1042  
    1043                                         /* Select the correct Email and Telephone to be shown */ 
    1044                                         $preferences = ExecMethod('contactcenter.ui_preferences.get_preferences'); 
    1045                                         if (!is_array($preferences)) 
    1046                                         { 
    1047                                                 $preferences['personCardEmail'] = 1; 
    1048                                                 $preferences['personCardPhone'] = 2; 
    1049                                         } 
    1050                                         if ($contact['connections']) 
    1051                                         { 
    1052                                                 $default_email_found = false; 
    1053                                                 $default_phone_found = false; 
    1054                                                 foreach($contact['connections'] as $conn_info) 
     1147                                foreach($contacts as $index => $contact) 
     1148                                { 
     1149                                        /* 
     1150                                         * TODO: Os timeouts de conexï¿œo foram retirados, ver se serï¿œ necessï¿œrio retornar essa funcionalidade, e, 
     1151                                         * neste caso, terminar a implementaᅵᅵo das mensagens de retorno. 
     1152                                         */ 
     1153                                        if ($index !== 'error'){ 
     1154                                                $final[3][$i][0] = $contact['companies']['company1']['company_name']?$contact['companies']['company1']['company_name']:'none'; 
     1155                                                $final[3][$i][1] = $contact['names_ordered'] ? $contact['names_ordered'] : 'none'; 
     1156                                                $final[3][$i][2] = $contact['companies']['company1']['title']?$contact['companies']['company1']['title']:'none'; 
     1157 
     1158                                                //Para exibir a matricula do empregado 
     1159                                                $final[3][$i][8] = $contact['companies']['company1']['empNumber']?$contact['companies']['company1']['empNumber']:'none'; 
     1160                                                //Para exibir o setor/lotaᅵᅵo do empregado 
     1161                                                $final[3][$i][9] = $contact['companies']['company1']['department']?$contact['companies']['company1']['department']:'none'; 
     1162 
     1163                                                /* Select the correct Email and Telephone to be shown */ 
     1164                                                $preferences = ExecMethod('contactcenter.ui_preferences.get_preferences'); 
     1165                                                if (!is_array($preferences)) 
    10551166                                                { 
    1056                                                         if ($conn_info['id_type'] == $preferences['personCardEmail'] and !$default_email_found) 
     1167                                                        $preferences['personCardEmail'] = 1; 
     1168                                                        $preferences['personCardPhone'] = 2; 
     1169                                                } 
     1170                                                if ($contact['connections']) 
     1171                                                { 
     1172                                                        $default_email_found = false; 
     1173                                                        $default_phone_found = false; 
     1174                                                        foreach($contact['connections'] as $conn_info) 
    10571175                                                        { 
    1058                                                                 if ($conn_info['connection_is_default']) 
     1176                                                                if ($conn_info['id_type'] == $preferences['personCardEmail'] and !$default_email_found) 
    10591177                                                                { 
    1060                                                                         $default_email_found = true; 
     1178                                                                        if ($conn_info['connection_is_default']) 
     1179                                                                        { 
     1180                                                                                $default_email_found = true; 
     1181                                                                        } 
     1182                                                                        $final[3][$i][4] = $conn_info['connection_value'] ? $conn_info['connection_value'] : 'none'; 
    10611183                                                                } 
    1062                                                                 $final[3][$i][4] = $conn_info['connection_value'] ? $conn_info['connection_value'] : 'none'; 
    1063                                                         } 
    1064                                                         else if ($conn_info['id_type'] == $preferences['personCardPhone'] and !$default_phone_found) 
    1065                                                         { 
    1066                                                                 if ($conn_info['connection_is_default']) 
     1184                                                                else if ($conn_info['id_type'] == $preferences['personCardPhone'] and !$default_phone_found) 
    10671185                                                                { 
    1068                                                                         $default_phone_found = true; 
     1186                                                                        if ($conn_info['connection_is_default']) 
     1187                                                                        { 
     1188                                                                                $default_phone_found = true; 
     1189                                                                        } 
     1190                                                                         
     1191                                                                        if (!($_SESSION['phpgw_info']['user']['preferences']['contactcenter']['telephone_number'] == $conn_info['connection_value']) && $_SESSION['phpgw_info']['user']['preferences']['contactcenter']['voip_enabled'] && $conn_info['connection_value'] && preg_match('/^\([0-9]{2}\)[0-9]{4}\-[0-9]{4}$/',$conn_info['connection_value'])==1 && !$external) { 
     1192                                                                                $conn_info['connection_value'] = "<a title=\"".lang("Call Extension")."\" href=\"#\" onclick=\"connectVoip('".$conn_info['connection_value']."', 'com')\">".$conn_info['connection_value']."</a>"; 
    10691193                                                                } 
    1070                                                                 $final[3][$i][3] = $conn_info['connection_value'] ? $conn_info['connection_value'] : 'none'; 
     1194                                                                         
     1195                                                                        $final[3][$i][3] = $conn_info['connection_value'] ? $conn_info['connection_value'] : 'none'; 
     1196                                                                } 
    10711197                                                        } 
    10721198                                                } 
     1199 
     1200                                                if (!$final[3][$i][3]) 
     1201                                                { 
     1202                                                        $final[3][$i][3] = 'none'; 
     1203                                                } 
     1204 
     1205                                                if (!$final[3][$i][4]) 
     1206                                                { 
     1207                                                        $final[3][$i][4] = 'none'; 
     1208                                                } 
     1209 
     1210                                                $final[3][$i][5] = $contact['alias']?$contact['alias']:'none'; 
     1211                                                $final[3][$i][6] = $ids[$i]; 
     1212 
     1213                                        //      If contact is a public list, then load the forwarding addresses. 
     1214                                                if($contact['account_type'][0] == 'l') 
     1215                                                        $final[3][$i][7] = array(); 
     1216 
     1217                                                $final[4][$i] = $contact['photo'] ? 1  : 0; 
     1218                                                $i++; 
     1219 
    10731220                                        } 
    1074                                          
    1075                                         if (!$final[3][$i][3]) 
     1221                                        else 
    10761222                                        { 
    1077                                                 $final[3][$i][3] = 'none'; 
     1223                                                // coloca mensagem de erro no vetor que retorna para o browser 
    10781224                                        } 
    1079                                          
    1080                                         if (!$final[3][$i][4]) 
    1081                                         { 
    1082                                                 $final[3][$i][4] = 'none'; 
    1083                                         } 
    1084  
    1085                                         $final[3][$i][5] = $contact['alias']?$contact['alias']:'none'; 
    1086                                         $final[3][$i][6] = $ids[$i]; 
    1087  
    1088                                 //      If contact is a public list, then load the forwarding addresses. 
    1089                                         if($contact['account_type'][0] == 'l') 
    1090                                                 $final[3][$i][7] = array(); 
    1091  
    1092                                         $final[4][$i] = $contact['photo'] ? 1  : 0; 
    1093                                         $i++; 
    1094                                 } 
    1095                                 $lnk_compose = "location.href=('../expressoMail1_2/index.php?to=";                               
     1225                                } 
     1226                                $lnk_compose = "location.href=('../expressoMail1_2/index.php?to="; 
    10961227                                $final[5] = '<span class="link" onclick="'.$lnk_compose; 
    1097                                  
    1098                                  
     1228 
     1229 
    10991230                                $this->page_info['actual_letter'] = $letter; 
    11001231                                $this->page_info['actual_page'] = $page; 
    1101                                  
    1102                                 $this->save_session();                           
     1232 
     1233                                $this->save_session(); 
     1234 
    11031235                                echo serialize($final); 
    11041236                                return; 
    11051237                        } 
    1106                          
     1238 
    11071239                        $this->page_info['actual_letter'] = $letter; 
    11081240                        $this->page_info['actual_page'] = $page; 
    1109                          
     1241 
    11101242                        $this->save_session(); 
    1111                          
     1243 
    11121244                        $final[0] = 0; 
    11131245                        $final[1] = $this -> typeContact; 
    11141246                        echo serialize($final); 
    11151247                } 
    1116                  
     1248 
    11171249                /*! 
    1118                  
     1250 
    11191251                        @function get_group_data 
    11201252                        @abstract Returns all the information of a given Group 
    11211253                        @author Nilton Emilio Buhrer Neto 
    1122                          
     1254 
    11231255                        @param (integer) $id The id to get information 
    1124                  
    1125                 */               
     1256 
     1257                */ 
    11261258                function get_group_data($id) 
    11271259                { 
     
    11291261                        $fields = $this->bo->catalog->get_fields(true); 
    11301262                        $data = $this->bo->catalog->get_single_entry($id,$fields); 
    1131                          
    1132                         if($id) {                        
     1263 
     1264                        if($id) { 
    11331265                                // get All Contacts by group. 
    1134                                 $data['contact_in_list'] = $this->bo->catalog->get_contacts_by_group($id);                                                               
    1135                         } 
    1136                          
     1266                                $data['contact_in_list'] = $this->bo->catalog->get_contacts_by_group($id); 
     1267                        } 
     1268 
    11371269                        $boGroup = CreateObject('contactcenter.bo_group'); 
    1138                                                  
    1139                         $all_contacts = $boGroup->get_all_contacts(); 
    1140                          
    1141                         $contact_options = ""; 
    1142                         if(count($all_contacts)) {                                       
    1143                                 foreach($all_contacts as $idx => $contact) {                             
    1144                                         $contact_options .= "<OPTION value='".$contact['id_connection']."'>".$contact['names_ordered']." (".$contact['connection_value'].")</OPTION>"; 
    1145                                 } 
    1146                         } 
    1147                         $data['contact_list'] = $contact_options; 
    1148                         $data['result'] = 'ok';                                                          
    1149                         echo serialize($data);                   
    1150                 }                
    1151                  
     1270 
     1271                        $data['contact_list'] = $boGroup->get_all_contacts(); 
     1272 
     1273                        $data['result'] = 'ok'; 
     1274                        echo serialize($data); 
     1275                } 
     1276 
    11521277                /*! 
    1153                  
     1278 
    11541279                        @function get_full_data 
    11551280                        @abstract Returns all the information of a given Entry 
    11561281                        @author Raphael Derosso Pereira 
    1157                          
     1282 
    11581283                        @param (integer) $id The id to get information 
    1159                  
     1284 
    11601285                */ 
    11611286                function get_full_data($id) 
    11621287                { 
    11631288                        $dateformat = $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']; 
    1164                         $this->bo->catalog = CreateObject('contactcenter.bo_people_catalog');            
     1289                        $this->bo->catalog = CreateObject('contactcenter.bo_people_catalog'); 
    11651290                        $fields = $this->bo->catalog->get_fields(true); 
    11661291                        $fields['photo'] = false; 
     
    11951320                        } 
    11961321                        $datecount = 0; 
    1197                          
     1322 
    11981323                        $data['result'] = 'ok'; 
    11991324                        $data['cc_full_add_contact_id'] = $id; 
     
    12371362 
    12381363                        /* Relations */ 
    1239                          
     1364 
    12401365                        echo serialize($data); 
    12411366                } 
     
    12741399                                return; 
    12751400                        } 
    1276                          
     1401 
    12771402                        echo 0; 
    12781403                } 
    1279                  
     1404 
    12801405                /*! 
    1281                  
     1406 
    12821407                        @function quick_add 
    12831408                        @abstract Adds a new Contact using the Quick Add interface 
    12841409                        @author Raphael Derosso Pereira 
    1285                          
     1410 
    12861411                        @param string $sdata Serialized data 
    12871412                */ 
    12881413                function quick_add($sdata) 
    12891414                { 
    1290                          
     1415 
    12911416                        $sdata = str_replace('\\"', '"', $sdata); 
    12921417                        $new_array = unserialize($sdata); 
    12931418                        $tdata = array(); 
    1294                          
     1419 
    12951420                        foreach($new_array as $tmp) 
    12961421                                $tdata[] = $tmp; 
    1297                          
     1422 
    12981423                        if (!$tdata) 
    12991424                        { 
     
    13021427                                        'status' => 'abort' 
    13031428                                )); 
    1304                                  
     1429 
    13051430                                return; 
    13061431                        } 
    1307                          
    1308                         // verifica se email já existe! 
     1432 
     1433                        // verifica se email jï¿œ existe! 
    13091434                        $boGroup = CreateObject('contactcenter.bo_group'); 
    13101435                        $contact = $boGroup->verify_contact($tdata[4]); 
    1311                                                                                                  
     1436 
    13121437                        if($contact) 
    1313                         {                                                        
     1438                        { 
    13141439                                $str_contact = "\r\n - ".implode("\r\n - ",$contact); 
    1315                                  
     1440 
    13161441                                echo serialize(array( 
    13171442                                        'msg'    => lang('Problems on adding your Contact. The email "%1" already exists in: %2',$tdata[4], $str_contact), 
    13181443                                        'status' => 'alreadyExists' 
    13191444                                )); 
    1320                                  
    1321                                 return;                  
     1445 
     1446                                return; 
    13221447                        } 
    13231448 
     
    13351460 
    13361461                        if ($boPeople ->quick_add($data)) 
    1337                         {                                
     1462                        { 
    13381463                                $this->page_info['changed'] = true; 
    1339                                  
     1464 
    13401465                                echo serialize(array( 
    13411466                                        'msg'    => lang('Entry added with success!'), 
     
    13511476                        } 
    13521477 
    1353                         $this->save_session();   
    1354                          
     1478                        $this->save_session(); 
     1479 
    13551480                } 
    13561481 
    13571482                /*! 
    1358                  
     1483 
    13591484                        @function add_group 
    13601485                        @abstract Adds a new Group using the Add Group interface 
    13611486                        @author Nilton Emilio Buhrer Neto 
    1362                          
     1487 
    13631488                        @param string $sdata Serialized data 
    13641489                */ 
     
    13681493                        $tdata = unserialize($sdata); 
    13691494                        $new_tdata = array(); 
    1370                          
     1495 
    13711496                        if (!$tdata) 
    13721497                        { 
     
    13751500                                        'status' => 'abort' 
    13761501                                )); 
    1377                                  
     1502 
    13781503                                return; 
    13791504                        } 
    1380                          
     1505 
    13811506                        foreach($tdata as $tmp) 
    13821507                                $new_tdata[] = $tmp; 
    1383                          
    1384                         $data['title'] = $new_tdata[0];                  
     1508 
     1509                        $data['title'] = $new_tdata[0]; 
    13851510                        $data['contact_in_list'] = $new_tdata[1]; 
    13861511                        $data['id_group'] = $new_tdata[2]; 
    1387                                                  
     1512 
    13881513                        $boGroup = CreateObject('contactcenter.bo_group_manager'); 
    13891514                        $id = $boGroup -> add_group($data); 
    1390                          
     1515 
    13911516                        if ($id) 
    13921517                        { 
    13931518                                $this->page_info['changed'] = true; 
    1394                                  
     1519 
    13951520                                echo serialize(array( 
    13961521                                        'msg'    => lang('Entry added with success!'), 
     
    14101535 
    14111536                /*! 
    1412                  
     1537 
    14131538                        @function remove_group 
    14141539                        @abstract Removes a group if the user has the right to do it 
    1415                         @author Nilton Emilio Buhrer Neto                        
     1540                        @author Nilton Emilio Buhrer Neto 
    14161541                        @param (integer) $id The id to be removed 
    1417                                  
     1542 
    14181543                */ 
    14191544                function remove_group($id) 
    1420                 {                                
    1421                                 $soGroup = CreateObject('contactcenter.so_group');                               
     1545                { 
     1546                                $soGroup = CreateObject('contactcenter.so_group'); 
    14221547                                $data = array ('id_group' => $id); 
    14231548                                if($soGroup -> delete($data)) { 
     
    14251550                                                'msg'    => lang('Removed Entry ID '.$id.'!'), 
    14261551                                                'status' => 'ok' 
    1427                                         ));                                                      
     1552                                        )); 
    14281553                                } 
    14291554                                else { 
     
    14341559                                } 
    14351560 
    1436                         $this->save_session();                           
     1561                        $this->save_session(); 
    14371562                } 
    14381563 
    14391564 
    14401565                function remove_all_entries (){ 
    1441                  
     1566 
    14421567                        $error = false; 
    14431568                        $this->all_entries = $this->bo->catalog->get_all_entries_ids(); 
     
    14471572                                if(!$result) { 
    14481573                                        $error = true; 
    1449                                         break;           
     1574                                        break; 
    14501575                                } 
    14511576                        } 
     
    14561581                                        'status' => 'ok' 
    14571582                                )); 
    1458                         }  
     1583                        } 
    14591584                        else { 
    14601585                                echo serialize(array( 
     
    14681593 
    14691594                /*! 
    1470                  
     1595 
    14711596                        @function remove_entry 
    14721597                        @abstract Removes an entry if the user has the right to do it 
    14731598                        @author Raphael Derosso Pereira 
    1474                          
     1599 
    14751600                        @param (integer) $id The id to be removed 
    1476                                  
     1601 
    14771602                */ 
    14781603                function remove_entry ($id) 
     
    14831608                                return; 
    14841609                        } 
    1485                          
     1610 
    14861611                        $this->page_info['changed'] = true; 
    14871612                        $result = $this->bo->catalog->remove_single_entry($id); 
    1488                          
     1613 
    14891614                        if ($result) 
    14901615                        { 
     
    14931618                                        unset($this->page_info['actual_entries'][$pos]); 
    14941619                                } 
    1495                                  
     1620 
    14961621                                $temp = false; 
    14971622                                reset($this->page_info['actual_entries']); 
     
    15001625                                        $temp[] = $t; 
    15011626                                } 
    1502                                  
     1627 
    15031628                                $this->page_info['actual_entries'] = $temp; 
    15041629 
     
    15151640                                )); 
    15161641                        } 
    1517                          
     1642 
    15181643                        $this->save_session(); 
    15191644                } 
    15201645 
    1521                  
     1646 
    15221647                /*! 
    1523                  
     1648 
    15241649                        @function post_full_add 
    15251650                        @abstract Saves all the information altered/entered in the Full Add 
     
    15301655                function post_full_add() 
    15311656                { 
    1532                         $data =  $_POST['data']; 
    1533                         // Exceptions!!! utf8 special chars.  
    1534                         $data = preg_replace("/\%u2(\d+)(\d+)(\d+)/","-",$data); 
    1535                         $data = unserialize(str_replace('\\"', '"', $data)); 
     1657                        $data = unserialize(str_replace('\\"', '"', $_POST['data'])); 
    15361658                        $this -> bo -> catalog = CreateObject('contactcenter.bo_people_catalog'); 
     1659 
     1660//                      echo str_replace('\\"', '"', $_POST['data']); 
    15371661 
    15381662                        if (!is_array($data)) 
     
    15581682                                        'status' => 'fatal' 
    15591683                                )); 
    1560                                  
     1684 
    15611685                                return; 
    15621686                        } 
     
    15721696                                $id_photo = '_new_'; 
    15731697                        } 
    1574                          
    1575                         /*  
    1576                          * Process Photo, if available  
     1698 
     1699                        /* 
     1700                         * Process Photo, if available 
    15771701                         */ 
    15781702                        $sleep_count = 0; 
     
    15911715                        } 
    15921716                        $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('wait', 'n')); 
    1593                          
     1717 
    15941718                        if (isset($this->page_info['photos'][$id_photo])) 
    15951719                        { 
     
    16081732                                $this->save_session(); 
    16091733                        } 
    1610                          
     1734 
    16111735                        /* 
    16121736                         * Arrange Date so it gets inserted correctly 
    16131737                         */ 
    1614                           
     1738 
    16151739                        $dateformat = $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']; 
    1616                  
     1740 
    16171741                        $j = 0; 
    16181742                        for ($i = 0; $i < 5; $i+=2) 
     
    16471771                                        continue; 
    16481772                                } 
    1649                                  
     1773 
    16501774                                switch($field) 
    16511775                                { 
     
    16591783                                                /* Do Nothing. This is just to make sure no invalid field is passed */ 
    16601784                                                break; 
    1661                                          
     1785 
    16621786                                        case 'id_status': 
    16631787                                        case 'id_prefix': 
     
    16681792                                                } 
    16691793                                                break; 
    1670                                          
     1794 
    16711795                                        case 'birthdate_0': 
    16721796                                        case 'birthdate_1': 
    16731797                                        case 'birthdate_2': 
    1674                                          
     1798 
    16751799                                                switch($date[$datecount]['digit']) 
    16761800                                                { 
     
    16941818                                                        break; 
    16951819                                                } 
    1696                                                  
     1820 
    16971821                                                if (!checkdate($date['value'][0], $date['value'][1], $date['value'][2])) 
    16981822                                                { 
     
    17031827                                                        return; 
    17041828                                                } 
    1705                                                  
     1829 
    17061830                                                $data['birthdate'] = $date['value'][2].'-'.$date['value'][0].'-'.$date['value'][1]; 
    17071831                                                break; 
     
    17261850                                                        { 
    17271851                                                                $index = 'address'.$type; 
    1728                                                                  
     1852 
    17291853                                                                $id_state = $this->bo->catalog->add_state($state_info); 
    17301854                                                                $data['addresses'][$index]['id_state'] = $id_state; 
     
    17441868                                                        { 
    17451869                                                                $index = 'address'.$type; 
    1746                                                                  
     1870 
    17471871                                                                $id_city = $this->bo->catalog->add_city($city_info); 
    17481872                                                                $data['addresses'][$index]['id_city'] = $id_city; 
     
    17851909                                ); 
    17861910                        } 
    1787                          
     1911 
    17881912                        eval($code); 
    17891913 
     
    18011925 
    18021926                /*! 
    1803                  
     1927 
    18041928                        @function post_photo 
    18051929                        @abstract Wrapper to post a photo without reload a page. 
     
    18111935                        //print_r($_FILES); 
    18121936                        $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('wait', 'y')); 
    1813                          
     1937 
    18141938                        if (!is_array($_FILES) and is_array(!$_FILES['cc_pd_photo'])) 
    18151939                        { 
    18161940                                $this->page_info['photos'][$id]['status'] = 'no_upload'; 
    18171941                                $this->page_info['photos'][$id]['msg'] = lang('No Photos uploaded to Server.'); 
    1818                                  
     1942 
    18191943                                $this->save_session(); 
    18201944                                $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('ok', 'y')); 
     
    18261950                                $this->page_info['photos'][$id]['status'] = 'no_GD_lib'; 
    18271951                                $this->page_info['photos'][$id]['msg'] = lang('Cannot manipulate Image. No Image added. Please, if you want to use images, ask the Administrator to install GD library.'); 
    1828                                  
     1952 
    18291953                                $this->save_session(); 
    18301954                                $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('ok', 'y')); 
     
    18521976                                return; 
    18531977                        } 
    1854                          
     1978 
    18551979                        switch($_FILES['cc_pd_photo']['type']) 
    18561980                        { 
     
    18822006 
    18832007                                default: 
    1884                                          
     2008 
    18852009                                        $this->page_info['photos'][$id]['status'] = 'invalid_image'; 
    18862010                                        $this->page_info['photos'][$id]['msg'] = lang('The file must be an JPEG, PNG or GIF Image.'); 
     
    18952019                                        $this->page_info['photos'][$id]['status'] = 'invalid_file'; 
    18962020                                        $this->page_info['photos'][$id]['msg'] = lang('Couldn\'t open Image. It may be corrupted or internal library doesn\'t support this format.'); 
    1897                                          
     2021 
    18982022                                        $this->save_session(); 
    18992023                                        $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('ok', 'y')); 
    19002024                                        return; 
    19012025                        } 
    1902                          
     2026 
    19032027                        $img_size = getimagesize($_FILES['cc_pd_photo']['tmp_name']); 
    19042028                        $dst_img = imagecreatetruecolor(60, 80); 
    1905                          
     2029 
    19062030                        if (!imagecopyresized($dst_img, $src_img, 0, 0, 0, 0, 60, 80, $img_size[0], $img_size[1])) 
    19072031                        { 
    19082032                                $this->page_info['photos'][$id]['status'] = 'invalid_file'; 
    19092033                                $this->page_info['photos'][$id]['msg'] = lang('Couldn\'t open Image. It may be corrupted or internal library doesn\'t support this format.'); 
    1910                                  
     2034 
    19112035                                $this->save_session(); 
    19122036                                $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('ok', 'y')); 
    19132037                                return; 
    19142038                        } 
    1915                          
     2039 
    19162040                        ob_start(); 
    19172041                        imagepng($dst_img); 
     
    19232047 
    19242048                        $this->save_session(); 
    1925                  
     2049 
    19262050                        $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('ok', 'y')); 
    19272051 
     
    19442068                        $fields = $this->bo->catalog->get_fields(false); 
    19452069                        $fields['photo'] = true; 
    1946                          
     2070 
    19472071                        $contact = $this->bo->catalog->get_single_entry($id, $fields); 
    19482072 
     
    19532077                                return; 
    19542078                        } 
    1955                          
     2079 
    19562080                        header('Content-type: image/jpeg'); 
    19572081                        $photo = imagecreatefromstring ($contact['photo']); 
     
    19652089                        return; 
    19662090                } 
    1967                  
     2091 
    19682092                /*! 
    1969                  
     2093 
    19702094                        @function get_states 
    19712095                        @abstract Echos a serialized array containing all the states for the given country 
     
    19892113                                return; 
    19902114                        } 
    1991                          
     2115 
    19922116                        $result = array( 
    19932117                                'msg'    => lang('States Successfully retrieved!'), 
    19942118                                'status' => 'ok' 
    19952119                        ); 
    1996                          
     2120 
    19972121                        foreach ($states as $state_info) 
    19982122                        { 
     
    20332157                                return; 
    20342158                        } 
    2035                          
     2159 
    20362160                        $result = array( 
    20372161                                'msg'    => lang('Cities Successfully retrieved!'), 
    20382162                                'status' => 'ok' 
    20392163                        ); 
    2040                          
     2164 
    20412165                        foreach ($cities as $city_info) 
    20422166                        { 
    20432167                                $result['data'][$city_info['id_city']] = $city_info['name']; 
    20442168                        } 
    2045                          
     2169 
    20462170                        echo serialize($result); 
    20472171                } 
     
    20492173 
    20502174                /*! 
    2051                  
     2175 
    20522176                        @function search 
    20532177                        @abstract Echos a serialized array containing the IDs 
    20542178                                of the entries that matches the search argument 
    20552179                        @author Raphael Derosso Pereira 
     2180                        @author Mï¿œrio Cï¿œsar Kolling (external catalogs) 
    20562181 
    20572182                        @param string $str_data A serialized array with two informations: 
     
    20652190                { 
    20662191                        $data = unserialize($str_data); 
     2192                        // It's an external catalog? 
     2193                        $external = $this->bo->is_external($this->page_info['actual_catalog']); 
    20672194 
    20682195                        if (!is_array($data) || !$data['search_for'] || !is_array($data['fields'])) 
    20692196                        { 
    2070                                 echo serialize(array( 
    2071                                         'msg'    => lang('Invalid parameters'), 
    2072                                         'status' => 'abort' 
    2073                                 )); 
    2074  
    2075                                 return; 
     2197                                //echo serialize(array( 
     2198                                //      'msg'    => lang('Invalid parameters'), 
     2199                                //      'status' => 'abort' 
     2200                                //)); 
     2201 
     2202                                return array('error' => lang('Invalid parameters')); 
     2203                        } 
     2204 
     2205                        /* 
     2206                         * TODO: look into the database to discover the database's encoding and convert the search_for field accordingly 
     2207                         */ 
     2208                        // Support search parameters with accentuation 
     2209                        if ($this->page_info['actual_catalog']['class'] != 'bo_people_catalog' && 
     2210                                $this->page_info['actual_catalog']['class'] != 'bo_group_manager') 
     2211                        { 
     2212 
     2213                                $data['search_for'] = utf8_encode($data['search_for']); 
    20762214                        } 
    20772215 
     
    20942232                                if (!is_array($names)) 
    20952233                                { 
    2096                                         echo serialize(array( 
    2097                                                 'msg'    => lang('Invalid Search Parameter'), 
    2098                                                 'status' => 'abort' 
    2099                                         )); 
    2100                                          
    2101                                         return; 
    2102                                 } 
    2103                                  
     2234                                        //echo serialize(array( 
     2235                                        //      'msg'    => lang('Invalid Search Parameter'), 
     2236                                        //      'status' => 'abort' 
     2237                                        //)); 
     2238 
     2239                                        return array('error' => lang('Invalid Search Parameter')); 
     2240                                } 
     2241 
     2242                                if (!$external && $this->page_info['actual_catalog']['class'] != 'bo_people_catalog' && 
     2243                                        $this->page_info['actual_catalog']['class'] != 'bo_group_manager') 
     2244                                { 
     2245                                        /* 
     2246                                         * Restrict the returned contacts search to objectClass = phpgwAccount, 
     2247                                         * must have attibute phpgwAccountStatus, phpgwAccountVisible != -1 and 
     2248                                         * objectClass = inetOrgPerson 
     2249                                         */ 
     2250                                        $rules = array( 
     2251                                                0 => array( 
     2252                                                        'field' => 'contact.object_class', 
     2253                                                        'type'  => '=', 
     2254                                                        'value' => 'phpgwAccount' 
     2255                                                ), 
     2256                                                1 => array( 
     2257                                                        'field' => 'contact.account_status', 
     2258                                                        'type'  => 'iLIKE', 
     2259                                                        'value' => '%' 
     2260                                                ), 
     2261                                                2 => array( 
     2262                                                        'field' => 'contact.account_visible', 
     2263                                                        'type'  => '!=', 
     2264                                                        'value' => '-1' 
     2265                                                ), 
     2266                                                3 => array( 
     2267                                                        'field' => 'contact.object_class', 
     2268                                                        'type'  => '=', 
     2269                                                        'value' => 'inetOrgPerson' 
     2270                                                ) 
     2271                                        ); 
     2272                                } 
     2273 
    21042274                                foreach ($names as $name) 
    21052275                                { 
     
    21142284                                } 
    21152285                        } 
    2116                          
    2117                         /* 
    2118                         $catalog = $this->bo->get_branch_by_level($this->bo->catalog_level[0]); 
    2119                          
    2120                         if ($catalog['class'] === 'bo_people_catalog') 
    2121                         { 
    2122                                 array_push($rules, array( 
    2123                                         'field' => 'contact.id_owner', 
    2124                                         'type'  => '=', 
    2125                                         'value' => $GLOBALS['phpgw_info']['user']['account_id'] 
    2126                                 )); 
    2127                         } 
    2128                         */ 
    2129                          
    2130                         $ids = $this->bo->find(array($data['fields']['id'], $data['fields']['search']), $rules, array('order' => $data['fields']['search'], 'sort' => 'ASC')); 
     2286 
     2287                        if ($external || $this->page_info['actual_catalog']['class'] == 'bo_people_catalog' || 
     2288                                $this->page_info['actual_catalog']['class'] == 'bo_group_manager') 
     2289                        { 
     2290                                // Get only this attributes: dn, cn for external catalogs, 
     2291                                // used to restrict the attributes used in filters 
     2292                                $ids = $this->bo->find(array($data['fields']['id'], $data['fields']['search']), $rules, array('order' => $data['fields']['search'], 'sort' => 'ASC')); 
     2293                        } 
     2294                        else 
     2295                        { 
     2296                                // Get only this attributes: dn, cn, phpgwAccountType, objectClass, phpgwAccountStatus, phpghAccountVisible 
     2297                                // for non-external catalogs, used to restrict the attributes used in filters 
     2298                                $ids = $this->bo->find(array( 
     2299                                        $data['fields']['id'], 
     2300                                        $data['fields']['search'], 
     2301                                        'contact.object_class', 
     2302                                        'contact.account_status', 
     2303                                        'contact.account_visible' 
     2304                                        ), $rules, array('order' => $data['fields']['search'], 'sort' => 'ASC')); 
     2305                        } 
    21312306 
    21322307                        if (!is_array($ids) || !count($ids)) 
    21332308                        { 
    2134                                 echo serialize(array( 
    2135                                         'msg'    => lang('No Entries Found!'), 
    2136                                         'status' => 'empty' 
    2137                                 )); 
    2138  
    2139                                 return; 
     2309                                //echo serialize(array( 
     2310                                //      'msg'    => lang('No Entries Found!'), 
     2311                                //      'status' => 'empty' 
     2312                                //)); 
     2313 
     2314                                $this->last_search_ids = null; 
     2315                                $this->save_session(); 
     2316                                return null; 
    21402317                        } 
    21412318 
     
    21452322                        foreach ($ids as $e_info) 
    21462323                        { 
     2324                                //$ids_f[] = "base64::" . base64_encode($e_info[$id_field]); 
    21472325                                $ids_f[] = $e_info[$id_field]; 
    21482326                        } 
    2149                          
    2150                         echo serialize(array( 
    2151                                 'data'   => $ids_f, 
    2152                                 'msg'    => lang('Found %1 Entries', count($ids)), 
    2153                                 'status' => 'ok' 
    2154                         )); 
     2327 
     2328                        //error_log("ids_f serializados: " . serialize($ids_f) . "\n", 3, '/var/www/teste.log'); 
     2329 
     2330                        //return serialize($ids_f); 
     2331                        return $ids_f; 
     2332 
     2333                        //echo serialize(array( 
     2334                        //      'data'   => $ids_f, 
     2335                        //      'msg'    => lang('Found %1 Entries', count($ids)), 
     2336                        //      'status' => 'ok' 
     2337                        //)); 
    21552338                } 
    21562339 
     
    21622345                        @author Raphael Derosso Pereira 
    21632346 
    2164                         @param array str_data A serialized array containing the ID's of the entries  
     2347                        @param array str_data A serialized array containing the ID's of the entries 
    21652348                                to be taken, the fields to be taken and the rules to be used on the 
    21662349                                retrieval: 
     
    21752358                { 
    21762359                        $data = unserialize($str_data); 
    2177                          
     2360 
    21782361                        if (!is_array($data) or !count($data) or !count($data['fields']) or !count($data['ids'])) 
    21792362                        { 
     
    21852368 
    21862369                        $entries = $this->bo->catalog->get_multiple_entries($data['ids'], $data['fields']); 
    2187                          
     2370 
    21882371                        if (!is_array($entries) or !count($entries)) 
    21892372                        { 
     
    22042387 
    22052388                        @function get_all_entries 
    2206                         @abstract Returns the specified fields for all catalog's entries  
     2389                        @abstract Returns the specified fields for all catalog's entries 
    22072390                                in the default CC UI format 
    22082391                        @author Raphael Derosso Pereira 
    22092392 
    2210                         @params array str_data A serialized array containing the fields to  
     2393                        @params array str_data A serialized array containing the fields to 
    22112394                                be grabbed, the maximum number of entries to be returned and a 
    22122395                                boolean specifying if the calls refers to a new grab or to an 
     
    22172400                { 
    22182401                        $data = unserialize($str_data); 
    2219                          
    2220                         if (!is_array($data) or  
    2221                             !count($data) or  
    2222                                 !count($data['fields']) or  
     2402 
     2403                        if (!is_array($data) or 
     2404                            !count($data) or 
     2405                                !count($data['fields']) or 
    22232406                                !$data['maxlength'] or 
    22242407                                (!$data['new'] and !$data['offset'])) 
     
    22462429                                $data['offset'] = 0; 
    22472430                        } 
    2248                          
     2431 
    22492432                        if ($data['maxlength'] != -1) 
    22502433                        { 
     
    22572440 
    22582441                        $prefs = ExecMethod('contactcenter.ui_preferences.get_preferences'); 
    2259                          
     2442 
    22602443                        $jsCode = array(); 
    22612444                        $count = 0; 
     
    22672450                                } 
    22682451 
    2269                                 if($this-> typeContact == 'groups') {                            
    2270                                          
     2452                                if($this-> typeContact == 'groups') { 
     2453 
    22712454                                        foreach ($each as $field => $value)     { 
    2272                                                                                  
     2455 
    22732456                                                if ($field === 'title') { 
    22742457                                                        $optionName = '\\"'.$value.'\\"'; 
    2275                                                           
     2458 
    22762459                                                } 
    22772460                                                else if ($field === 'short_name')       { 
    2278                                                          
     2461 
    22792462                                                        $jsCode[] = '_this.entries.options[_this.entries.options.length] = new Option("'.$optionName.' ('.$value.')", "'.$count.'");'; 
    2280                                                         $count++;                                                                                                                                                                        
    2281                                                 }                                        
     2463                                                        $count++; 
     2464                                                } 
    22822465                                        } 
    22832466                                } 
    2284                                  
    2285                                 else  {  
     2467 
     2468                                else  { 
    22862469                                        foreach ($each as $field => $value)     { 
    22872470                                                if ($field === 'names_ordered') { 
     
    22912474                                                } 
    22922475                                                else if ($field === 'connections')      { 
    2293                                                          
     2476 
    22942477                                                        foreach ($value as $connection)         { 
    22952478                                                                if ($connection['id_type'] == $prefs['personCardEmail'])        { 
     
    23042487 
    23052488                        $jsCodeFinal = implode("\n", $jsCode); 
    2306                          
     2489 
    23072490                        $nEntries = count($result); 
    2308                          
     2491 
    23092492                        if (!$nEntries) 
    23102493                        { 
     
    23242507                        ); 
    23252508                } 
    2326                  
     2509 
    23272510                /*********************************************************************\ 
    23282511                 *                      Auxiliar Methods                             * 
     
    23302513 
    23312514                /*! 
    2332                  
     2515 
    23332516                        @function save_session 
    23342517                        @abstract Saves the data on the session 
    23352518                        @author Raphael Derosso Pereira 
    2336                  
     2519 
    23372520                */ 
    23382521                function save_session() 
     
    23402523                        $GLOBALS['phpgw']->session->appsession('ui_data.page_info','contactcenter',$this->page_info); 
    23412524                        $GLOBALS['phpgw']->session->appsession('ui_data.all_entries','contactcenter',$this->all_entries); 
     2525                        $GLOBALS['phpgw']->session->appsession('ui_data.last_search_ids','contactcenter',$this->last_search_ids); 
    23422526                } 
    23432527 
    23442528                /*! 
    2345                  
     2529 
    23462530                        @function convert_tree 
    23472531                        @abstract Converts the tree array in the BO format to a JS tree array compatible 
    23482532                                with the one available in eGW 
    23492533                        @author Raphael Derosso Pereira 
    2350                  
     2534 
    23512535                        @param (array)  $tree    The tree in the BO format 
    23522536                        @param (string) $name    The tree name 
     
    23822566                                        'caption' => $value['name'] 
    23832567                                ); 
    2384                                  
     2568 
    23852569                                switch($value['type']) 
    23862570                                { 
     
    24052589                                $this->bo->catalog->src_info = $ldap->srcs[1]; 
    24062590                        } 
    2407                          
    2408                         $ds = $GLOBALS['phpgw']->common->ldapConnect($this->bo->catalog->src_info['host'], $this->bo->catalog->src_info['acc'], $this->bo->catalog->src_info['pw'], true);                               
     2591 
     2592                        $ds = $GLOBALS['phpgw']->common->ldapConnect($this->bo->catalog->src_info['host'], $this->bo->catalog->src_info['acc'], $this->bo->catalog->src_info['pw'], true); 
    24092593                        $dn=$this->bo->catalog->src_info['dn']; 
    24102594                        $justThese = array("givenname","givenname","sn","telephonenumber","mail"); 
    2411                         $sr = ldap_read($ds,$id, "objectClass=*",$justThese);                                                    
    2412                         $info = ldap_get_entries($ds, $sr);                                                      
     2595                        $sr = ldap_read($ds,$id, "objectClass=*",$justThese); 
     2596                        $info = ldap_get_entries($ds, $sr); 
    24132597                        for($z = 0; $z < 5; $z++) { 
    2414                                 $participant = $info[0][$justThese[$z]];                                                                                                         
     2598                                $participant = $info[0][$justThese[$z]]; 
    24152599                                array_push($array_participants, $participant); 
    24162600                        } 
     
    24182602                        ldap_close($ds); 
    24192603                        echo serialize($array_participants); 
    2420                 }        
    2421                  
    2422                 function get_catalog_participants_list($id)  
     2604                } 
     2605 
     2606                function get_catalog_participants_list($id) 
    24232607                { 
    2424                          
    2425                         $fields = $this->bo->catalog->get_fields(false);                         
     2608 
     2609                        $fields = $this->bo->catalog->get_fields(false); 
    24262610                        $fields['names_ordered'] = true; 
    2427                         $fields['mail_forwarding_address'] = true;                       
    2428                         $contact = $this->bo->catalog->get_single_entry($id,$fields);                    
    2429                          
     2611                        $fields['mail_forwarding_address'] = true; 
     2612                        $contact = $this->bo->catalog->get_single_entry($id,$fields); 
     2613 
    24302614                        $array_participants = array(); 
    24312615                        $array_emails = array(); 
    2432                          
     2616 
    24332617                        $filter = null; 
    2434                         for($z = 0; $z < $contact['mail_forwarding_address']['count']; $z++) {                   
     2618                        for($z = 0; $z < $contact['mail_forwarding_address']['count']; $z++) { 
    24352619                                        if(strstr($contact['mail_forwarding_address'][$z],'@')) { 
    24362620                                                $filter.="(mail=".$contact['mail_forwarding_address'][$z].")"; 
    24372621                                                $array_emails[$contact['mail_forwarding_address'][$z]] = "<font color=black>".$contact['mail_forwarding_address'][$z]."</font>"; 
    2438                                         }                                                                                                                                
    2439                                         else  
     2622                                        } 
     2623                                        else 
    24402624                                                $array_participants[$z] = "<font color=red>".$contact['mail_forwarding_address'][$z]."</font>"; 
    2441                         }                                        
    2442                          
     2625                        } 
     2626 
    24432627                        if($filter) { 
    2444                                 $filter = "(|".$filter.")";                                                      
     2628                                $filter = "(|".$filter.")"; 
    24452629                                if(!$this->bo->catalog->src_info) { 
    24462630                                        $ldap = CreateObject('contactcenter.bo_ldap_manager'); 
    24472631                                        $this->bo->catalog->src_info = $ldap->srcs[1]; 
    24482632                                } 
    2449                                 $ds = $GLOBALS['phpgw']->common->ldapConnect($this->bo->catalog->src_info['host'], $this->bo->catalog->src_info['acc'], $this->bo->catalog->src_info['pw'], true);                               
     2633                                $ds = $GLOBALS['phpgw']->common->ldapConnect($this->bo->catalog->src_info['host'], $this->bo->catalog->src_info['acc'], $this->bo->catalog->src_info['pw'], true); 
    24502634                                $dn=$this->bo->catalog->src_info['dn']; 
    24512635                                $justThese = array("cn","mail"); 
    2452                                 $sr = ldap_search($ds,$dn, $filter,$justThese);                                                          
    2453                                 $info = ldap_get_entries($ds, $sr);                                                      
     2636                                $sr = ldap_search($ds,$dn, $filter,$justThese); 
     2637                                $info = ldap_get_entries($ds, $sr); 
    24542638                                for($z = 0; $z < $info['count']; $z++) { 
    24552639                                        $participant =  '<font color=\'DARKBLUE\'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;'.$info[$z]['cn'][0].'&quot; &lt;'.$info[$z]['mail'][0].'&gt;</font><br>'; 
    2456                                         $array_emails[$info[$z]['mail'][0]] = null;                                                              
    2457                                         array_push($array_participants, $participant);                                   
    2458                                 } 
    2459                                  
     2640                                        $array_emails[$info[$z]['mail'][0]] = null; 
     2641                                        array_push($array_participants, $participant); 
     2642                                } 
     2643 
    24602644                                foreach($array_emails as $index => $email) 
    2461                                         if($email)  
    2462                                                 array_push($array_participants, "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".$email."<br>");                           
    2463                                                                                                  
     2645                                        if($email) 
     2646                                                array_push($array_participants, "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".$email."<br>"); 
     2647 
    24642648                                ldap_close($ds); 
    24652649                        } 
    24662650                        sort($array_participants); 
    2467                         $innerHTML = '';                         
     2651                        $innerHTML = ''; 
    24682652                        foreach($array_participants as $index => $participant){ 
    24692653                                $innerHTML .= $participant; 
    24702654                        } 
    2471                         $return = array('size' => count($array_participants), 'names_ordered'=> $contact['names_ordered'], 'inner_html' => $innerHTML);                   
     2655                        $return = array('size' => count($array_participants), 'names_ordered'=> $contact['names_ordered'], 'inner_html' => $innerHTML); 
    24722656                        echo serialize($return); 
    2473                 }        
    2474                  
     2657                } 
     2658 
    24752659                function export_contacts($typeExport){ 
    24762660 
     
    24832667 
    24842668 
    2485                         // Essa iteração transforma uma esturuta com contatos redundantes e separados por email ou tel. 
     2669                        // Essa iteraᅵᅵo transforma uma esturuta com contatos redundantes e separados por email ou tel. 
    24862670                        // em outra com apenas 1 elemento pra cada contato 
    24872671                        $i=0; 
     
    24942678                                        $all_contacts[$i]['phone']=$object['connection_value']; 
    24952679                        } 
    2496                          
     2680 
    24972681                        switch($typeExport) { 
    24982682 
    24992683                                case 'outlook_en': 
    25002684                                        $streamBuffer = "Name;E-mail Address;Notes;Mobile Phone;Pager;Company;". 
    2501                                                         "Job Title;Home Phone;Home Fax;Business Phone;Business Fax\r\n";                                                         
     2685                                                        "Job Title;Home Phone;Home Fax;Business Phone;Business Fax\r\n"; 
    25022686                                        foreach($all_contacts as $index => $object){ 
    25032687                                                $streamBuffer.= $object['name'].";".$object['email'].";;;;;;".$object['phone'].";;;\r\n"; 
    25042688                                        } 
    25052689                                break; 
    2506                                  
     2690 
    25072691                                case 'outlook_pt-BR': 
    2508                                         $streamBuffer = "Nome;End. de email;Endereço residencial;". 
    2509                                         "Cidade do endereço residencial;CEP do endereço residencial;". 
    2510                                         "Estado;País/região do endereço residencial;Telefone residencial;". 
    2511                                         "Rua do endereço comercial;Cidade do endereço comercial;". 
    2512                                         "CEP do endereço comercial;Estado do endereço comercial;". 
    2513                                         "País/região do endereço comercial;Telefone comercial;Empresa;Cargo\r\n";                                                        
     2692                                        $streamBuffer = "Nome;End. de email;Endereï¿œo residencial;". 
     2693                                        "Cidade do endereï¿œo residencial;CEP do endereï¿œo residencial;". 
     2694                                        "Estado;Paï¿œs/regiï¿œo do endereï¿œo residencial;Telefone residencial;". 
     2695                                        "Rua do endereï¿œo comercial;Cidade do endereï¿œo comercial;". 
     2696                                        "CEP do endereï¿œo comercial;Estado do endereï¿œo comercial;". 
     2697                                        "Paï¿œs/regiï¿œo do endereï¿œo comercial;Telefone comercial;Empresa;Cargo\r\n"; 
    25142698                                        foreach($all_contacts as $index => $object){ 
    25152699                                                $streamBuffer.= $object['name'].";".$object['email'].";;;;;;".$object['phone'].";;;;;;;;\r\n"; 
    25162700                                        } 
    25172701                                break; 
    2518                                  
     2702 
    25192703                                case 'outlook2000_pt-BR': 
    25202704                                        $streamBuffer = "\"Tratamento\",\"Nome\",\"Segundo Nome\",\"Sobrenome\",\"Sufixo\",". 
    2521                                         "\"Empresa\",\"Departamento\",\"Cargo\",\"Rua do endereço comercial\",\"Rua do endereço comercial 2\",". 
    2522                                         "\"Rua do endereço comercial 3\",\"Cidade do endereço comercial\",\"Estado do endereço comercial\",". 
    2523                                         "\"CEP do endereço comercial\",\"País do endereço comercial\",\"Endereço residencial\",\"Rua residencial 2\",". 
    2524                                         "\"Rua residencial 3\",\"Cidade do endereço residencial\",\"Estado\",\"CEP do endereço residencial\",\"País do endereço residencial\",". 
    2525                                         "\"Outro endereço\",\"Outro endereço 2\",\"Outro endereço 3\",\"Cidade\",\"Estado\",\"CEP\",\"País\",". 
     2705                                        "\"Empresa\",\"Departamento\",\"Cargo\",\"Rua do endereï¿œo comercial\",\"Rua do endereï¿œo comercial 2\",". 
     2706                                        "\"Rua do endereï¿œo comercial 3\",\"Cidade do endereï¿œo comercial\",\"Estado do endereï¿œo comercial\",". 
     2707                                        "\"CEP do endereï¿œo comercial\",\"Paï¿œs do endereï¿œo comercial\",\"Endereï¿œo residencial\",\"Rua residencial 2\",". 
     2708                                        "\"Rua residencial 3\",\"Cidade do endereï¿œo residencial\",\"Estado\",\"CEP do endereï¿œo residencial\",\"Paï¿œs do endereï¿œo residencial\",". 
     2709                                        "\"Outro endereï¿œo\",\"Outro endereï¿œo 2\",\"Outro endereï¿œo 3\",\"Cidade\",\"Estado\",\"CEP\",\"Paï¿œs\",". 
    25262710                                        "\"Telefone do assistente\",\"Fax comercial\",\"Telefone comercial\",\"Telefone comercial 2\",\"Retorno de chamada\",". 
    25272711                                        "\"Telefone do carro\",\"Telefone principal da empresa\",\"Fax residencial\",\"Telefone residencial\",". 
    25282712                                        "\"Telefone residencial 2\",\"ISDN\",\"Telefone celular\",\"Outro fax\",\"Outro telefone\",\"Pager\",\"Telefone principal\",". 
    2529                                         "\"Radiofone\",\"Telefone TTY/TDD\",\"Telex\",\"Aniversário\",\"Anotações\",\"Caixa postal\",\"Categorias\",". 
    2530                                         "\"Código da empresa\",\"Código do governo\",\"Cônjuge\",\"Conta\",\"Endereço de correio eletrônico\",". 
    2531                                         "\"Nome de exibição do correio eletr.\",\"Endereço de correio eletrônico 2\",". 
    2532                                         "\"Nome de exibição do correio eletr.2\",\"Endereço de correio eletrônico 3\",". 
    2533                                         "\"Nome de exibição do correio eletr.3\",\"Datas especiais\",\"Disponibilidade da Internet\",". 
    2534                                         "\"Filhos\",\"Hobby\",\"Idioma\",\"Indicação\",\"Informações para cobrança\",\"Iniciais\",\"Local\",". 
    2535                                         "\"Nome do assistente\",\"Nome do gerenciador\",\"Página da Web\",\"Palavras-chave\",\"Particular\",\"Personalizado 1\",\"Personalizado 2\",". 
    2536                                         "\"Personalizado 3\",\"Personalizado 4\",\"Prioridade\",\"Profissão\",\"Quilometragem\",\"Sala\",\"Sensibilidade\",\"Servidor de diretório\",". 
     2713                                        "\"Radiofone\",\"Telefone TTY/TDD\",\"Telex\",\"Aniversï¿œrio\",\"Anotaᅵᅵes\",\"Caixa postal\",\"Categorias\",". 
     2714                                        "\"Cï¿œdigo da empresa\",\"Cï¿œdigo do governo\",\"Cï¿œnjuge\",\"Conta\",\"Endereï¿œo de correio eletrï¿œnico\",". 
     2715                                        "\"Nome de exibiᅵᅵo do correio eletr.\",\"Endereï¿œo de correio eletrï¿œnico 2\",". 
     2716                                        "\"Nome de exibiᅵᅵo do correio eletr.2\",\"Endereï¿œo de correio eletrï¿œnico 3\",". 
     2717                                        "\"Nome de exibiᅵᅵo do correio eletr.3\",\"Datas especiais\",\"Disponibilidade da Internet\",". 
     2718                                        "\"Filhos\",\"Hobby\",\"Idioma\",\"Indicaᅵᅵo\",\"Informaᅵᅵes para cobranï¿œa\",\"Iniciais\",\"Local\",". 
     2719                                        "\"Nome do assistente\",\"Nome do gerenciador\",\"Pï¿œgina da Web\",\"Palavras-chave\",\"Particular\",\"Personalizado 1\",\"Personalizado 2\",". 
     2720                                        "\"Personalizado 3\",\"Personalizado 4\",\"Prioridade\",\"Profissï¿œo\",\"Quilometragem\",\"Sala\",\"Sensibilidade\",\"Servidor de diretï¿œrio\",". 
    25372721                                        "\"Sexo\"\r\n"; 
    25382722                                        foreach($all_contacts as $index => $object){ 
     
    25402724                                        } 
    25412725                                break; 
    2542                                  
     2726 
    25432727                                case 'outlook2000_en': 
    25442728                                        $streamBuffer = "Title,First Name,Middle Name,Last Name,Suffix,Company,Department,Job Title,". 
     
    25562740                                        } 
    25572741                                break; 
    2558                                          
     2742 
    25592743                                case 'thunderbird': 
    2560                                         $streamBuffer = "\n";                                                    
     2744                                        $streamBuffer = "\n"; 
    25612745                                        foreach($all_contacts as $index => $object){ 
    25622746                                                $streamBuffer.= ",,".$object['name'].",,".$object['email'].",,".$object['phone'].",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,\r\n"; 
    25632747                                        } 
    25642748                                break; 
    2565                                  
    2566                                 case 'expresso': 
     2749 
     2750                                default: 
    25672751                                        $streamBuffer = "Nome,Email,Telefone\r\n"; 
    25682752                                        foreach($all_contacts as $index => $object){ 
     
    25702754                                        } 
    25712755                                break; 
    2572                                  
     2756 
    25732757                        } 
    25742758 
     
    25782762                        if(!$f) 
    25792763                                echo null; 
    2580                  
     2764 
    25812765                        fputs($f,$streamBuffer); 
    25822766                        fclose($f); 
     
    25852769                } 
    25862770 
    2587                 // Get the csv field and put into array, from php.net 
    2588                 function parse_line($input_text, $delimiter = ',', $text_qualifier = '"') { 
    2589                         $text = trim($input_text); 
    2590                           if(is_string($delimiter) && is_string($text_qualifier)) { 
    2591                          $re_d = '\x' . dechex(ord($delimiter));            //format for regexp 
    2592                         $re_tq = '\x' . dechex(ord($text_qualifier));    //format for regexp 
    2593                          
    2594                         $fields = array(); 
    2595                         $field_num = 0; 
    2596                         while(strlen($text) > 0) { 
    2597                         if($text{0} == $text_qualifier) { 
    2598                                 preg_match('/^' . $re_tq . '((?:[^' . $re_tq . ']|(?<=\x5c)' . $re_tq . ')*)' . $re_tq . $re_d . '?(.*)$/', $text, $matches); 
    2599                                 
    2600                                 $value = str_replace('\\' . $text_qualifier, $text_qualifier, $matches[1]); 
    2601                                 $text = trim($matches[2]); 
    2602                 
    2603                                 $fields[$field_num++] = $value; 
    2604                         } else { 
    2605                                 preg_match('/^([^' . $re_d . ']*)' . $re_d . '?(.*)$/', $text, $matches); 
    2606                                 
    2607                                 $value = $matches[1]; 
    2608                                 $text = trim($matches[2]); 
    2609                 
    2610                                 $fields[$field_num++] = $value; 
    2611                 } 
    2612                 } 
    2613                         return $fields; 
    2614                     } else 
    2615                         return false; 
    2616                 } 
    26172771 
    26182772                function import_contacts($typeImport){ 
    26192773 
    2620                         if($file = $_SESSION['contactcenter']['importCSV']) {                            
    2621                                 unset($_SESSION['contactcenter']['importCSV']);                          
     2774                        $delim          = ($typeImport == 'outlook' ? ';' : ','); 
     2775 
     2776                        if($file = $_SESSION['contactcenter']['importCSV']) { 
     2777                                unset($_SESSION['contactcenter']['importCSV']); 
    26222778                                $len = filesize($file); 
    26232779                                $count = 0; 
    26242780                                $return = array('error' => false, '_new' => 0, '_existing' => 0, '_failure' => 0); 
    26252781                                $handle = @fopen($file, "r") or die(serialize($return['error'] = true)); 
    2626                                  
    2627                                 $input_header = fgets($handle); 
    2628                                 if ($typeImport == 'outlook') 
    2629                                         $delim = ';'; 
    2630                                 else if ($typeImport == 'auto') 
    2631                                 $delim = strstr($input_header,',') ? ',' : ';'; 
    2632                                 else   
    2633                                         $delim = ','; 
    2634                                 $csv_header = $this->parse_line($input_header,$delim); 
    2635                                 $firstContact = fgets($handle); 
    2636                                 preg_match("/\"(.+)\"[,;]/sU",$firstContact,$matches); // yahoo csv 
    2637                                 rewind($handle);                                 
    2638  
    26392782                                $header = @fgetcsv($handle, $len, $delim) or die(serialize($return['error'] = true)); 
    26402783                                if(count($header)  < 2 || count($header) > 100) { 
     
    26442787                                        return; 
    26452788                                } 
    2646                                  
    2647                                 if ($matches[0][strlen($matches[0])-1] == ';') 
    2648                                         $delim = ';'; 
    2649                                  
    2650                         $boGroup = CreateObject('contactcenter.bo_group'); 
    2651                         $boPeople = CreateObject('contactcenter.bo_people_catalog'); 
     2789 
     2790                                $boGroup = CreateObject('contactcenter.bo_group'); 
     2791                                $boPeople = CreateObject('contactcenter.bo_people_catalog'); 
     2792 
    26522793                                switch($typeImport){ 
    26532794                                        case 'outlook2000': 
     
    26662807                                                $phone_pos=7; 
    26672808                                                break; 
    2668                                         case 'expresso': 
     2809                                        default: 
    26692810                                                $name_pos=0; 
    26702811                                                $email_pos=1; 
    26712812                                                $phone_pos=2; 
    2672                                                 break; 
    2673                                         default: 
    2674                                                 foreach($csv_header as $index => $fieldName) 
    2675                                                 { 
    2676                                                         switch($fieldName){ 
    2677                                                         case 'Name': 
    2678                                                         case 'Nome': 
    2679                                                         case 'First Name': 
    2680                                                                 $name_pos = $index; 
    2681                                                                 break; 
    2682                                                         case 'E-mail': 
    2683                                                         case 'Email': 
    2684                                                         case 'E-mail Address': 
    2685                                                         case 'Endereço de correio eletrônico': 
    2686                                                         case 'End. de email': 
    2687                                                                 $email_pos = $index; 
    2688                                                                 break; 
    2689                                                         case 'Home Phone': 
    2690                                                         case 'Phone': 
    2691                                                         case 'Telefone': 
    2692                                                         case 'Telefone principal': 
    2693                                                         case 'Telefone comercial': 
    2694                                                                 $phone_pos = $index; 
    2695                                                                 break; 
    2696                                                         } 
    2697                                                 }        
    2698                                                 break; 
    2699                                 } 
    2700                                  
     2813                                } 
    27012814 
    27022815                                while (($data = fgetcsv($handle, $len, $delim))) { 
     2816 
    27032817                                foreach ($header as $key=>$heading) 
    27042818                                $row[$heading]=(isset($data[$key])) ? $data[$key] : ''; 
    2705                                  
     2819 
    27062820                                        $sdata = array(); 
    27072821                                        $full_name  = trim($row[$header[$name_pos]]); 
     
    27172831                                        $sdata['connections']['default_phone']['connection_name'] = lang('Main'); 
    27182832                                        $sdata['connections']['default_phone']['connection_value'] = $phone; 
    2719                                          
    2720                                         //      verifica se email já existe! 
     2833 
     2834                                        //      verifica se email jï¿œ existe! 
    27212835                                        $contact = $boGroup->verify_contact($email); 
    27222836 
    2723                                         $line_iteration = $return['_failure'] + $return['_existing'] + $return['_new'];  
    27242837                                        if($contact){ 
    27252838                                                $return['_existing']++; 
    2726                                         }                                                                                                                
     2839                                        } 
    27272840                                        else if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) { 
    27282841                                                $return['_failure']++; 
    2729                                                 $return['_failure_status'] .= "Line: " . ($line_iteration + 2) . ", Invalid E-Mail address: " . $email ."<br>"; 
    27302842                                        } 
    2731                                         else if (!$sdata['given_names'] || !$email || !$boPeople ->quick_add($sdata)){                                           
    2732                                                 $return['_failure']++;                                                   
    2733                                                 $return['_failure_status'] .= "Line: " . ($line_iteration + 2) . ", Invalid Name: " . $sdata['given_names'] ."<br>"; 
     2843                                        else if (!$sdata['given_names'] || !$email || !$boPeople ->quick_add($sdata)){ 
     2844                                                $return['_failure']++; 
    27342845                                        } 
    27352846                                        else 
    27362847                                                $return['_new']++; 
    2737                         }                                
     2848                        } 
    27382849                                fclose($handle); 
    27392850                                unlink($file); 
     
    27492860                        $new = null; 
    27502861                        $code = null; 
    2751                          
     2862 
    27522863                        if ($parent === '0') 
    27532864                        { 
     
    27552866                                $code .= $name.".add(new dNode({id:'0', caption: '".lang('Catalogues')."'}),'none');\n"; 
    27562867                        } 
    2757                          
     2868 
    27582869                        foreach ($tree as $id => $value) 
    27592870                        { 
     
    27612872 
    27622873                                switch ($value['type']) 
    2763                                 {                                        
     2874                                { 
    27642875                                        case 'unknown': 
    2765                                                 $code .= $name.".add(new dNode({id: '{$parent}.{$id}', caption:'{$value['name']}', onFirstOpen: 'getCatalogTree(\\'{$parent}.{$id}\\');', onClick: 'getCatalogTree(\\'{$parent}.{$id}\\'); waitForTree(\\'{$parent}.{$id}\\', 0)'}),'$parent');\n";  
     2876                                                $code .= $name.".add(new dNode({id: '{$parent}.{$id}', caption:'{$value['name']}', onFirstOpen: 'getCatalogTree(\\'{$parent}.{$id}\\');', onClick: 'getCatalogTree(\\'{$parent}.{$id}\\'); waitForTree(\\'{$parent}.{$id}\\', 0)'}),'$parent');\n"; 
    27662877                                                break; 
    2767                                          
     2878 
    27682879                                        case 'catalog_group': 
    2769                                                 $code .= $name.".add(new dNode({id: '{$parent}.{$id}', caption: '{$value['name']}'}),'$parent');\n";  
     2880                                                $code .= $name.".add(new dNode({id: '{$parent}.{$id}', caption: '{$value['name']}'}),'$parent');\n"; 
    27702881                                                $code .= $this->convert_tree($value['sub_branch'],$name,$iconDir,$parent.'.'.$id); 
    27712882                                                break; 
     
    27762887                                                $code .= $this->convert_tree($value['sub_branch'],$name,$iconDir,$parent.'.'.$id); 
    27772888                                                break; 
    2778                                          
     2889 
    27792890                                        case 'catalog': 
    27802891                                                $code .= $name.".add(new dNode({id: '{$parent}.{$id}', caption: '{$value['name']}', onClick: 'setCatalog(\\'{$parent}.{$id}\\')'}),'$parent');\n"; 
    2781                                                  
    2782                                 } 
    2783                         } 
    2784                          
     2892 
     2893                                } 
     2894                        } 
     2895 
    27852896                        return $code; 
    27862897                } 
Note: See TracChangeset for help on using the changeset viewer.