source: trunk/contactcenter/inc/class.ui_data.inc.php @ 5131

Revision 5131, 162.3 KB checked in by wmerlotto, 12 years ago (diff)

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

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1<?php
2  /***************************************************************************\
3  * eGroupWare - Contacts Center                                              *
4  * http://www.egroupware.org                                                 *
5  * Written by:                                                               *
6  *  - Raphael Derosso Pereira <raphaelpereira@users.sourceforge.net>         *
7  *  - Jonas Goes <jqhcb@users.sourceforge.net>                               *
8  *  sponsored by Thyamad - http://www.thyamad.com                            *
9  * ------------------------------------------------------------------------- *
10  *  This program is free software; you can redistribute it and/or modify it  *
11  *  under the terms of the GNU General Public License as published by the    *
12  *  Free Software Foundation; either version 2 of the License, or (at your   *
13  *  option) any later version.                                               *
14  \***************************************************************************/
15
16
17        class ui_data
18        {
19                var $public_functions = array(
20                        'data_manager' => true,
21                        'advanced_searh_fields' => true
22                );
23
24                var $bo;
25                var $so_group;
26                var $typeContact;
27                var $preferences;
28
29                var $page_info = array(
30                        'n_cards'          => 20,
31                        'n_pages'          => false,
32                        'actual_letter'    => 'A',
33                        'actual_page'      => 1,
34                        'actual_entries'   => false,
35                        'changed'          => false,
36                        'catalogs'         => false,
37                        'actual_catalog'   => false
38                );
39
40                /*!
41
42                        @function ui_data
43                        @abstract The constructor. Sets the initial parameters and loads
44                                the data saved in the session
45                        @author Raphael Derosso Pereira
46
47                */
48                function ui_data()
49                {
50                        $temp = $GLOBALS['phpgw']->session->appsession('ui_data.page_info','contactcenter');
51                        $temp2 = $GLOBALS['phpgw']->session->appsession('ui_data.all_entries','contactcenter');
52
53                        $this->bo = CreateObject('contactcenter.bo_contactcenter');
54
55                        if ($temp)
56                        {
57                                $this->page_info = $temp;
58                        }
59
60                        if ($temp2)
61                        {
62                                $this->all_entries = $temp2;
63                        }
64
65                        if (!$this->page_info['actual_catalog'])
66                        {
67                                $catalogs = $this->bo->get_catalog_tree();
68                                $this->page_info['actual_catalog'] = $catalogs[0];
69                        }
70
71                        $this->page_info['actual_catalog'] = $this->bo->set_catalog($this->page_info['actual_catalog']);
72
73
74                        if($this->page_info['actual_catalog']['class'] == 'bo_group_manager')
75                                $this -> typeContact = 'groups';
76/**rev 104**/
77                        else if($this->page_info['actual_catalog']['class'] == 'bo_shared_group_manager')
78                                $this -> typeContact = 'shared_groups';
79                        else if($this->page_info['actual_catalog']['class'] == 'bo_shared_people_manager')
80                                $this -> typeContact = 'shared_contacts';
81/******/
82                        else
83                                $this -> typeContact = 'contacts';
84                        $this->preferences = $_SESSION['phpgw_info']['user']['preferences']['contactcenter'];
85                }
86
87                /*!
88
89                        @function index
90                        @abstract Builds the Main Page
91                        @author Raphael Derosso Pereira
92                        @author Jonas Goes
93
94                */
95                function index()
96                {
97                        if(!@is_object($GLOBALS['phpgw']->js))
98                        {
99                                $GLOBALS['phpgw']->js = CreateObject('phpgwapi.javascript');
100                        }
101                        $GLOBALS['phpgw']->js->validate_file('venus','table');
102                        $GLOBALS['phpgw']->js->validate_file('venus','shapes');
103                        $GLOBALS['phpgw']->js->validate_file('venus','jsStructUtil');
104                        $GLOBALS['phpgw']->js->validate_file('venus','cssUtil');
105
106//                      $GLOBALS['phpgw']->js->set_onload('setTimeout(\'updateCards()\',1000)');
107                        $GLOBALS['phpgw']->common->phpgw_header();
108
109                        $GLOBALS['phpgw']->template->set_file(array('index' => 'index.tpl'));
110                        $GLOBALS['phpgw']->template->set_var('cc_root_dir', $GLOBALS['phpgw_info']['server']['webserver_url'].'/contactcenter/');
111
112                        /* Quick Add */
113                        $GLOBALS['phpgw']->template->set_var('cc_qa_alias',lang('Alias').':');
114                        $GLOBALS['phpgw']->template->set_var('cc_qa_given_names',lang('Given Names').':');
115                        $GLOBALS['phpgw']->template->set_var('cc_qa_family_names',lang('Family Names').':');
116                        $GLOBALS['phpgw']->template->set_var('cc_qa_phone',lang('Phone').':');
117                        $GLOBALS['phpgw']->template->set_var('cc_qa_email',lang('Email').':');
118                        $GLOBALS['phpgw']->template->set_var('cc_qa_save',lang('Save'));
119                        $GLOBALS['phpgw']->template->set_var('cc_qa_clear',lang('Clear'));
120                        $GLOBALS['phpgw']->template->set_var('cc_qa_close',lang('Close'));
121                        /* End Quick Add */
122
123                        /* Advanced Search */
124                       
125                        $GLOBALS['phpgw']->template->set_var('cc_corporate',lang('Corporate'));
126                        $GLOBALS['phpgw']->template->set_var('cc_cs_title',lang('Advanced Search'));
127                        $GLOBALS['phpgw']->template->set_var('cc_catalogues',lang('Catalogues'));
128                       
129                       
130                       
131                        /* End of Advanced Search*/
132
133                        $cc_css_file = $GLOBALS['phpgw_info']['server']['webserver_url'].'/contactcenter/styles/cc.css';
134                        $cc_card_image_file = $GLOBALS['phpgw_info']['server']['webserver_url'].'/contactcenter/templates/default/images/card.png';
135                        $GLOBALS['phpgw']->template->set_var('cc_css',$cc_css_file);
136                        $GLOBALS['phpgw']->template->set_var('cc_dtree_css', $cc_dtree_file);
137                        $GLOBALS['phpgw']->template->set_var('cc_card_image',$cc_card_image_file);
138
139                        $GLOBALS['phpgw']->template->set_var('cc_personal',lang('Personal'));
140
141/***rev 104***/
142                        //$GLOBALS['phpgw']->template->set_var('cc_full_add',lang('Full Add'));
143                        $GLOBALS['phpgw']->template->set_var('cc_full_add_button',lang('Full Add'));
144/******/
145                        $GLOBALS['phpgw']->template->set_var('cc_full_add_button_sh',lang('Full Add Shared'));
146                        $GLOBALS['phpgw']->template->set_var('cc_reset',lang('Reset'));
147
148                        $GLOBALS['phpgw']->template->set_var('cc_personal_data',lang('Personal Data'));
149                        $GLOBALS['phpgw']->template->set_var('cc_addresses',lang('Addresses'));
150                        $GLOBALS['phpgw']->template->set_var('cc_connections',lang('Connections'));
151                        $GLOBALS['phpgw']->template->set_var('cc_relations',lang('Relations'));
152
153                        $GLOBALS['phpgw']->template->set_var('cc_quick_add',lang('Quick Add'));
154                        $GLOBALS['phpgw']->template->set_var('cc_catalogs',lang('Catalogues'));
155                        $GLOBALS['phpgw']->template->set_var('cc_group_add',lang('Group Add'));
156
157                        /* Panel */
158                        $GLOBALS['phpgw']->template->set_var('cc_panel_new',lang('New').'...');
159                        $GLOBALS['phpgw']->template->set_var('cc_panel_search',lang('Search').'...');
160                        $GLOBALS['phpgw']->template->set_var('cc_panel_table',lang('Table View'));
161                        $GLOBALS['phpgw']->template->set_var('cc_panel_cards',lang('Cards View'));
162                        $GLOBALS['phpgw']->template->set_var('cc_btn_import_export', lang('Import/Export'));
163                        $GLOBALS['phpgw']->template->set_var('cc_btn_new', lang("New..."));
164
165                        $GLOBALS['phpgw']->template->set_var('cc_panel_search_found',lang('Showing found entries'));
166                        $GLOBALS['phpgw']->template->set_var('cc_panel_first_page',lang('First Page'));
167                        $GLOBALS['phpgw']->template->set_var('cc_panel_previous_page',lang('Previous Page'));
168                        $GLOBALS['phpgw']->template->set_var('cc_panel_next_page',lang('Next Page'));
169                        $GLOBALS['phpgw']->template->set_var('cc_panel_last_page',lang('Last Page'));
170                        $GLOBALS['phpgw']->template->set_var('cc_all',lang('all'));
171                        /* End Panel */
172
173                        /* Messages */
174/**rev 104**/
175                        $GLOBALS['phpgw']->template->set_var('cc_msg_not_allowed',lang('Not Allowed'));
176                        $GLOBALS['phpgw']->template->set_var('cc_msg_unavailable',lang('Unavailable function'));
177/*****/
178
179
180                        $GLOBALS['phpgw']->template->set_var('cc_msg_name_mandatory',lang('Name is mandatory'));
181                        $GLOBALS['phpgw']->template->set_var('cc_msg_err_invalid_serch',lang('The query should not have the characters {%,?}'));
182                        $GLOBALS['phpgw']->template->set_var('cc_msg_tel_or_mail_required',lang('Tel or email is required'));
183
184                        $GLOBALS['phpgw']->template->set_var('cc_msg_no_cards',lang('No Cards'));
185                        $GLOBALS['phpgw']->template->set_var('cc_msg_err_no_room',lang('No Room for Cards! Increase your browser area.'));
186                        $GLOBALS['phpgw']->template->set_var('cc_msg_card_new',lang('New from same Company'));
187                        $GLOBALS['phpgw']->template->set_var('cc_msg_card_edit',lang('Edit Contact'));
188                        $GLOBALS['phpgw']->template->set_var('cc_msg_card_remove',lang('Remove Contact'));
189                        $GLOBALS['phpgw']->template->set_var('cc_send_mail',lang('Send Mail'));
190                        $GLOBALS['phpgw']->template->set_var('cc_msg_group_edit',lang('Edit Group'));
191                        $GLOBALS['phpgw']->template->set_var('cc_msg_group_remove',lang('Remove Group'));
192                        $GLOBALS['phpgw']->template->set_var('cc_msg_group_remove_confirm',lang('Confirm Removal of this Group?'));
193                        $GLOBALS['phpgw']->template->set_var('cc_msg_card_remove_confirm',lang('Confirm Removal of this Contact?'));
194                        $GLOBALS['phpgw']->template->set_var('cc_participants',lang('Participants'));
195                        $GLOBALS['phpgw']->template->set_var('cc_empty',lang('Empty'));
196                        /* End Messages */
197
198                        $GLOBALS['phpgw']->template->set_var('cc_results',lang('Results'));
199                        $GLOBALS['phpgw']->template->set_var('cc_is_my',lang('Is My'));
200                        $GLOBALS['phpgw']->template->set_var('cc_ie_personal',lang('Import/Export pesonal contacts'));
201                        $GLOBALS['phpgw']->template->set_var('cc_btn_search',lang('Search'));
202                        $GLOBALS['phpgw']->template->set_var('cc_add_relation',lang('Add Relation'));
203                        $GLOBALS['phpgw']->template->set_var('cc_del_relation',lang('Remove Selected Relations'));
204                        $GLOBALS['phpgw']->template->set_var('cc_msg_group',lang('Group'));
205                        $GLOBALS['phpgw']->template->set_var('cc_msg_contact_full',lang('Contact [Full]'));
206                        $GLOBALS['phpgw']->template->set_var('cc_msg_contact_sh',lang('Contact [Shared]'));
207                        $GLOBALS['phpgw']->template->set_var('cc_msg_contact_qa',lang('Contact [Quick Add]'));
208                        $GLOBALS['phpgw']->template->set_var('cc_contact_title',lang('Contact Center').' - '.lang('Contacts'));
209                        $GLOBALS['phpgw']->template->set_var('cc_window_views_title',lang('Contact Center').' - '.lang('Views'));
210                        $GLOBALS['phpgw']->template->set_var('phpgw_img_dir', $GLOBALS['phpgw_info']['server']['webserver_url'] . '/phpgwapi/images');
211
212                        $GLOBALS['phpgw']->template->set_var('cc_msg_import_contacts', lang('Import Contacts'));
213                        $GLOBALS['phpgw']->template->set_var('cc_msg_export_contacts', lang('Export Contacts'));
214                        $GLOBALS['phpgw']->template->set_var('cc_msg_expresso_info_csv', lang('The Expresso supports the contacts importation in the CSV file format.'));
215                        $GLOBALS['phpgw']->template->set_var('cc_msg_choose_file_type', lang('Select the file type'));
216                        $GLOBALS['phpgw']->template->set_var('cc_msg_outlook_express', lang('Outlook Express'));
217                        $GLOBALS['phpgw']->template->set_var('cc_msg_outlook2k', lang('Outlook 2000'));
218                        $GLOBALS['phpgw']->template->set_var('cc_msg_expresso_default', lang('Expresso (default)'));
219                        $GLOBALS['phpgw']->template->set_var('cc_msg_choose_contacts_file', lang('Select the file that contains the contacts to be imported:'));
220                        $GLOBALS['phpgw']->template->set_var('cc_msg_close_win', lang('Close'));
221                        $GLOBALS['phpgw']->template->set_var('cc_msg_close', lang('Close'));
222                        $GLOBALS['phpgw']->template->set_var('cc_msg_ie_personal', lang('Import / Export personal Contacts'));
223                        $GLOBALS['phpgw']->template->set_var('cc_msg_import_fail', lang('The importation has failed. Verify the file format.'));
224                        $GLOBALS['phpgw']->template->set_var('cc_msg_importing_contacts', lang('Importing Contacts...'));
225                        $GLOBALS['phpgw']->template->set_var('cc_msg_import_finished', lang('The importation has finished.'));
226                        $GLOBALS['phpgw']->template->set_var('cc_msg_new', lang(' new'));
227                        $GLOBALS['phpgw']->template->set_var('cc_msg_failure', lang(' failed'));
228                        $GLOBALS['phpgw']->template->set_var('cc_msg_exists', lang(' were existent'));
229                        $GLOBALS['phpgw']->template->set_var('cc_msg_show_more_info', lang('show more info'));
230                        $GLOBALS['phpgw']->template->set_var('cc_msg_clean', lang('Clean'));
231                        $GLOBALS['phpgw']->template->set_var('cc_msg_invalid_csv', lang('Select a valid CSV file to import your contacts'));
232                        $GLOBALS['phpgw']->template->set_var('cc_msg_export_csv', lang('Select the format type that you want to export your contacts'));
233                        $GLOBALS['phpgw']->template->set_var('cc_msg_automatic', lang('Automatic'));
234                        $GLOBALS['phpgw']->template->set_var('cc_msg_export_error', lang('An error has occurred while the exportation.'));
235                        $GLOBALS['phpgw']->template->set_var('cc_msg_new_email', lang('New Email'));
236                        $GLOBALS['phpgw']->template->set_var('cc_msg_main', lang('Main'));
237                        $GLOBALS['phpgw']->template->set_var('cc_msg_alternative', lang('Alternative'));
238                        $GLOBALS['phpgw']->template->set_var('cc_msg_select_email', lang('Select E-Mail'));
239                        $GLOBALS['phpgw']->template->set_var('cc_msg_new_phone', lang('New Telephone'));
240                        $GLOBALS['phpgw']->template->set_var('cc_msg_home', lang('Home Phone'));
241                        $GLOBALS['phpgw']->template->set_var('cc_msg_cellphone', lang('Cellphone'));
242                        $GLOBALS['phpgw']->template->set_var('cc_msg_corporative_cellphone', lang('Corporative Cellphone'));
243                        $GLOBALS['phpgw']->template->set_var('cc_msg_corporative_fax', lang('Corporative Fax'));
244                        $GLOBALS['phpgw']->template->set_var('cc_msg_corporative_pager', lang('Corporative Pager'));
245                        $GLOBALS['phpgw']->template->set_var('cc_msg_work', lang('Work'));
246                        $GLOBALS['phpgw']->template->set_var('cc_msg_fax', lang('Fax'));
247                        $GLOBALS['phpgw']->template->set_var('cc_msg_pager', lang('Pager'));
248                        $GLOBALS['phpgw']->template->set_var('cc_msg_choose_phone', lang('Select the telephone'));
249                        $GLOBALS['phpgw']->template->set_var('cc_msg_warn_firefox', lang('Warning: Too old version of Firefox'));
250                        $GLOBALS['phpgw']->template->set_var('cc_msg_firefox_half1', lang('For this application work correctly</u>'));
251                        $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'));
252                        $GLOBALS['phpgw']->template->set_var('cc_msg_click_close', lang('click Close'));
253                        $GLOBALS['phpgw']->template->set_var('cc_msg_install_now', lang('Install Now'));
254                        $GLOBALS['phpgw']->template->set_var('cc_msg_install_new_firefox', lang('Install a new Firefox version'));
255                        $GLOBALS['phpgw']->template->set_var('cc_msg_moz_thunderbird', lang('Export as Mozilla Thunderbird CSV.'));
256                        $GLOBALS['phpgw']->template->set_var('cc_msg_outlook_express_pt', lang('Export as Outlook Express (Portuguese) CSV.'));
257                        $GLOBALS['phpgw']->template->set_var('cc_msg_outlook_express_en', lang('Export as Outlook Express (English) CSV.'));
258                        $GLOBALS['phpgw']->template->set_var('cc_msg_outlook_2k_pt', lang('Export as Outlook 2000 (Portuguese) CSV.'));
259                        $GLOBALS['phpgw']->template->set_var('cc_msg_outlook_2k_en', lang('Export as Outlook 2000 (English) CSV.'));
260                        $GLOBALS['phpgw']->template->set_var('cc_msg_outlook_2003', lang('Export as Outlook 2003 CSV.'));
261                        $GLOBALS['phpgw']->template->set_var('cc_msg_expresso_default_csv', lang('Export as Expresso (Default) CSV.'));
262                        $GLOBALS['phpgw']->template->set_var('cc_msg_copy_to_catalog', lang('Copy to personal catalog.'));
263                        $GLOBALS['phpgw']->template->set_var('cc_msg_add_contact_to_group', lang('You did not add any contact for this group.'));
264                        $GLOBALS['phpgw']->template->set_var('cc_msg_fill_field_name', lang('Fill the field Full Name'));
265                        $GLOBALS['phpgw']->template->set_var('cc_msg_show_extra_detail', lang("Show extra contact's details."));
266
267                        $select_groups = '';
268                       
269                        $this->so_group = CreateObject('contactcenter.so_group');
270                       
271                        $array_groups = $this->so_group->selectGroupsOwnerCanImportContacts($GLOBALS['phpgw_info']['user']['account_id']);
272                       
273                        $select_groups = "<select id='id_group'>";//<option value=0>Selecione um grupo...</option></select>";
274                        $select_groups .= "<option value=0 selected>Nenhum...</option>";
275                        foreach ($array_groups as $group){
276                                $select_groups .= "<option value='".$group['id_group']."'>".$group['title']."</option>";                                               
277                        }                                       
278                        $select_groups .= "</select>";
279                       
280                        $GLOBALS['phpgw']->template->set_var('cc_select_groups',$select_groups);
281                       
282                        if($GLOBALS['phpgw_info']['server']['personal_contact_type']=='True'){
283                                $GLOBALS['phpgw']->template->set_var('cc_contact_type', 'advanced');
284                        }else{
285                                $GLOBALS['phpgw']->template->set_var('cc_contact_type', 'default');
286                        }
287                       
288                        /*
289                         * Monta Contactcenter Busca Avancada
290                         */
291                        $c = CreateObject('phpgwapi.config','contactcenter');
292                        $c->read_repository();
293                        $current_config = $c->config_data;
294
295                        $arraySearch = array();
296                        foreach ($current_config as $index => $value)
297                        {
298
299                            if(substr($index, 0, 24) == 'cc_attribute_searchable_')
300                            {
301                                if($value == 'true')
302                                {
303                                    $v = substr($index, 24, strlen($index));
304                                    $arraySearch[] = $v;
305                                }
306                            }
307                        }
308                        $advanceSearchArray = array();
309                        foreach ($arraySearch as $value)
310                        {
311                            foreach ($current_config as $index => $value2)
312                            {
313                                if($value == substr($index, 22, strlen($index)) && substr($index, 0, 22) == 'cc_attribute_ldapname_')
314                                {
315                                    foreach ($current_config as $index2 => $value3)
316                                    {
317                                        if($value == substr($index2, 18, strlen($index2)) && substr($index2, 0, 18) == 'cc_attribute_name_')
318                                             $advanceSearchArray[$value2] =  $value3;
319                                    }
320                                }
321
322                            }
323                        }
324
325                        $advanceSearch = array();
326                        foreach ($advanceSearchArray as $index => $value)
327                            $advanceSearch[] ='"'.$index.'":"'.$value.'"';
328
329                        $advancedFields =  "{".implode(',',$advanceSearch)."}";
330
331
332                        $GLOBALS['phpgw']->template->set_var('cc_config_advanced_search', $advancedFields);
333
334                       
335                       
336                        $GLOBALS['phpgw']->template->parse('out','index');
337
338                        $api = CreateObject('contactcenter.ui_api');
339                        $main = $api->get_full_add();
340                        $main .= $api->get_search_obj();
341                        $main .= $api->get_quick_add_plugin();
342                        $main .= $api->get_add_group();
343                        $main .= $api->get_contact_details();
344                        $main .= $GLOBALS['phpgw']->template->get_var('out');
345
346                        echo $main;
347                }
348
349
350                /*!
351
352                        @function data_manager
353                        @abstract Calls the right method and passes to it the right
354                                parameters
355                        @author Raphael Derosso Pereira
356
357                */
358                function data_manager()
359                {
360                        switch($_GET['method'])
361                        {
362                                /* Cards Methods */
363                                case 'set_n_cards':
364                                        return $this->set_n_cards((int)$_GET['ncards']);
365
366                                case 'get_cards_data':
367
368                                        $ids = false;
369                                        // To support ldap catalogs using accentuation
370                                        if ($_POST['letter'] == 'search' && isset($_POST['data']))
371                                        {
372                                                $ids = utf8_decode($this->search($_POST['data']));
373                                        }
374
375                                        if(isset($_SESSION['ids']))
376                                                $ids = $_SESSION['ids'];
377
378                                        return $this->get_cards_data($_POST['letter'], $_POST['page'], $ids);
379
380                                case 'get_cards_data_get':
381                                        return $this->get_cards_data($_GET['letter'], $_GET['page'], unserialize(str_replace('\\"','"',$_GET['ids'])));
382
383
384                                case 'get_photo':
385                                        return $this->get_photo($_GET['id']);
386
387                                case 'get_init_values':
388                                        echo serialize(array("visible_all_ldap" => $this->get_visible_all_ldap(), "preferences" => $this->preferences));
389                                        return;
390
391                                /* Catalog Methods */
392                                case 'set_catalog':
393                                        return $this->set_catalog($_GET['catalog']);
394
395                                case 'get_catalog_tree':
396                                        echo serialize($this->get_catalog_tree($_GET['level']));
397                                        return;
398
399                                case 'get_actual_catalog':
400                                        echo serialize($this->get_actual_catalog());
401                                        return;
402
403                                case 'get_catalog_participants_list':
404                                        echo serialize($this->get_catalog_participants_list($_POST['id']));
405                                        return;
406/**rev 104**/
407                                case 'get_catalog_participants_group':
408                                        echo serialize($this->get_catalog_participants_group($_POST['id']));
409                                        return;
410/***/
411                                case 'get_catalog_add_contact':
412                                        // To support ldap catalogs with accentuation
413                                        echo serialize($this->get_catalog_add_contact($_POST['id']));
414                                        return;
415
416                                /* Full Add Methods */
417                                case 'get_full_data':
418                                        //return $this->get_full_data($_GET['id']);
419/**rev 104**/
420                                        return $this->get_full_data($_GET['id'],$_GET['catalog']);
421/****/
422
423                                case 'get_group':
424                                        return $this->get_group_data($_GET['id'],isset($_GET['shared_from'])?$_GET['shared_from']:null);
425
426                                case 'get_contact_full_add_const':
427                                        return $this->get_contact_full_add_const();
428
429                                case 'post_full_add':
430                                        return $this->post_full_add();
431
432                                case 'post_full_add_shared' :
433                                        return $this->post_full_add_shared();
434
435                                case 'post_photo':
436                                        return $this->post_photo((int) $_GET['id'] ? (int) $_GET['id'] : '_new_');
437
438                                case 'get_states':
439                                        return $this->get_states($_GET['country']);
440
441                                case 'get_cities':
442                                        return $this->get_cities($_GET['country'], $_GET['state'] ? $_GET['state'] : null);
443
444
445                                /* Other Methods */
446                                case 'quick_add':
447                                        return $this->quick_add($_POST['add']);
448
449                                case 'add_group':
450                                        return $this->add_group($_POST['add']);
451
452                                case 'remove_entry':
453                                        return $this->remove_entry((int)$_GET['remove']);
454
455                                case 'remove_all_entries':
456                                        return $this->remove_all_entries();
457
458                                case 'remove_group':
459
460                                        return $this->remove_group((int)$_GET['remove']);
461
462                                case 'search':
463                                        $ids = false;
464                                        $ids = $this->search($_GET['data']);
465                                        $data = unserialize($_GET['data']);
466                                        $dontPaginate = false;
467                                        if (isset($data['ccAddGroup'])){
468                                            $dontPaginate = true;
469                                        }
470                                        return $this->get_cards_data('search', '1', $ids, $dontPaginate);
471
472                                case 'email_win':
473                                        $GLOBALS['phpgw']->common->phpgw_header();
474                                        $api = CreateObject('contactcenter.ui_api');
475                                        $win = $api->get_email_win();
476                                        $win .= $api->get_quick_add_plugin();
477                                        $win .= '<input id="QAbutton" type="button" value="QuickAdd" />'
478                                                .'<br><input type="button" value="EmailWin" onclick="ccEmailWin.open()" />'
479                                                .'<script type="text/javascript">'
480                                                .'      ccQuickAdd.associateAsButton(Element("QAbutton"));'
481                                                .'</script>';
482                                        echo $win;
483                                        return;
484
485                                /* Information Gathering */
486                                case 'get_multiple_entries':
487                                        echo serialize($this->get_multiple_entries(str_replace('\\"','"',$_POST['data'])));
488                                        return;
489
490                                case 'get_all_entries':
491                                        echo serialize($this->get_all_entries(str_replace('\\"','"',$_POST['data'])));
492                                        return;
493
494                                case 'import_contacts':
495                                        return $this->import_contacts($_GET['typeImport'],$_GET['id_group']);
496
497                                case 'export_contacts':
498                                        return $this->export_contacts($_POST['typeExport']);
499                               
500                                case 'get_qtds_compartilhado':
501                                        return $this->get_qtds_compartilhado();
502                                case 'get_list_owners_perms_add':
503                                        echo $this->get_list_owners_perms_add();
504                                        return;
505                                case 'get_contact_details':
506                                        return $this->get_contact_details($_GET['id']);
507                        }
508                }
509
510                /*!
511
512                        @function set_n_cards
513                        @abstract Informs the class the number of cards the page can show
514                        @author Raphael Derosso Pereira
515
516                        @param integer $n_cards The number of cards
517
518                */
519                function set_n_cards($n_cards)
520                {
521                        if (is_int($n_cards))
522                        {
523                                $this->page_info['n_cards'] = $n_cards;
524                                echo 1;
525                        }
526
527                        $this->save_session();
528                }
529
530                /*!
531
532                        @function set_catalog
533                        @abstract Sets the current catalog selected by the user
534                        @author Raphael Derosso Pereira
535
536                        @param string $id_catalog The sequence of IDs to reach the catalog
537                                separated by commas
538
539                */
540                function set_catalog($id_catalog, $echo=true)
541                {
542                        $id_catalog = str_replace('\\"', '"', $id_catalog);
543                        $temp = $this->bo->set_catalog($id_catalog);
544
545                        if(!$this->bo->catalog->src_info) {
546                            $ldap = CreateObject('contactcenter.bo_ldap_manager');
547                            $this->bo->catalog->src_info = $ldap->srcs[1];
548                        }
549
550                        $resetCC_actual_letter = 0;
551                        if($this->bo->catalog->src_info['visible'] == "false")
552                        {
553                            $resetCC_actual_letter = 1;
554                        }
555
556                        if ($temp)
557                        {
558                                unset($this->page_info['actual_letter']);
559                                $this->page_info['changed'] = true;
560                                $this->page_info['actual_entries'] = false;
561                                $this->page_info['actual_catalog'] = $temp;
562                                $this->save_session();
563
564                                $catalog_info = $this->bo->get_branch_by_level($this->bo->catalog_level[0]);
565
566                                if ($catalog_info['class'] === 'bo_global_ldap_catalog' ||
567                                    $catalog_info['class'] === 'bo_catalog_group_catalog')
568                                {
569                                        $perms = 1;
570                                }
571                                else
572                                {
573                                        $perms = 15;
574                                }
575
576                                if ($echo)
577                                {
578                                    echo serialize(array(
579                                            'status' => 'ok',
580                                            'catalog' => $catalog_info['class'],
581                                            'external' => $catalog_info['external']?true:false,
582                                            'resetCC_actual_letter' => $resetCC_actual_letter,
583                                            'perms'  => $perms
584                                    ));
585                                }
586                                else
587                                    {
588                                        return serialize(array(
589                                            'status' => 'ok',
590                                            'catalog' => $catalog_info['class'],
591                                            'external' => $catalog_info['external']?true:false,
592                                            'resetCC_actual_letter' => $resetCC_actual_letter,
593                                            'perms'  => $perms
594                                        ));
595                                    }
596
597                                return;
598                        }
599
600                        echo serialize(array(
601                                'status' => 'ok',
602                                'resetCC_actual_letter' => $resetCC_actual_letter,
603                                'perms'  => 0
604                        ));
605                }
606
607
608                /*!
609
610                        @function get_catalog_tree
611                        @abstract Returns the JS serialized array to used as the tree
612                                level
613                        @author Raphael Derosso Pereira
614            @author Mário César Kolling (error messages and timeout)
615
616                        @param (string) $level The level to be taken
617
618                */
619                function get_catalog_tree($level)
620                {
621                        if ($level === '0')
622                        {
623                                $folderImageDir = $GLOBALS['phpgw_info']['server']['webserver_url'] . '/phpgwapi/dftree/images/';
624
625                                $parent = '0';
626
627                                if (!($tree = $this->bo->get_catalog_tree($level)))
628                                {
629                                        return array(
630                                                'msg'    => lang('Couldn\'t get the Catalogue Tree. Please contact the Administrator.'),
631                                                'status' => 'fatal'
632                                        );
633                                }
634                        }
635                        else
636                        {
637                                $last_dot = strrpos($level,'.');
638                                $parent = substr($level, 0, $last_dot);
639                                $child = substr($level, $last_dot+1, strlen($level));
640                                if (!($tree[$child] = $this->bo->get_catalog_tree($level)))
641                                {
642                                        return array(
643                                                'msg'    => lang('Couldn\'t get the Catalogue Tree. Please contact the Administrator.'),
644                                                'status' => 'fatal'
645                                        );
646                                }
647                                // Deals with timeout and returns the generated message to the browser
648                                else if (!empty($tree[$child]['timeout']) && !empty($tree[$child]['msg']))
649                                {
650                                        $tmp = array(
651                                                'msg'    => $tree[$child]['msg'],
652                                                'status' => 'fatal'
653                                        );
654                                        unset($tree[$child]);
655                                        return $tmp;
656                                }
657                        }
658
659                        $folderImageDir = $GLOBALS['phpgw']->common->image('contactcenter','globalcatalog-mini.png');
660                        $folderImageDir = substr($folderImageDir, 0, strpos($folderImageDir, 'globalcatalog-mini.png'));
661
662                        // Deals with error messages from the server and returns them to the browser
663                        if ($tree['msg'])
664                        {
665                                $msg = $tree['msg'];
666                                unset($tree['msg']);
667                        }
668
669                        $tree_js = $this->convert_tree($tree, $folderImageDir, $parent);
670
671                        // Return status = ok, or else return generated message to the browser
672                        if (!$msg)
673                        {
674                                return array(
675                                        'data' => $tree_js,
676                                        'msg'  => lang('Catalog Tree Successfully taken!'),
677                                        'status' => 'ok'
678                                );
679                        }
680                        else
681                        {
682                                return array(
683                                        'data' => $tree_js,
684                                        'msg'  => $msg,
685                                        'status' => 'error'
686                                );
687                        }
688                }
689
690                /*!
691
692                        @function get_actual_catalog
693                        @abstract Returns the actual selected Catalog
694                        @author Raphael Derosso Pereira
695
696                */
697                function get_actual_catalog()
698                {
699                        $level = $this->bo->get_level_by_branch($this->bo->get_actual_catalog(), $this->bo->tree['branches'], '0');
700
701                        if ($level)
702                        {
703                                return array(
704                                        'status' => 'ok',
705                                        'data'   => $level
706                                );
707                        }
708
709                        return array(
710                                'status' => 'fatal',
711                                'msg'    => lang('Couldn\'t get the actual catalog.'),
712                        );
713                }
714
715                function get_qtds_compartilhado() {
716                        $so_contact = CreateObject('contactcenter.so_contact',  $GLOBALS['phpgw_info']['user']['account_id']);
717            $relacionados = $so_contact->get_relations();
718
719                        $perms_relacao = array();
720
721                foreach($relacionados as $uid_relacionado => $tipo_relacionamento) {
722                                $aclTemp = CreateObject("phpgwapi.acl",$uid_relacionado);
723                $aclTemp->read();
724                $perms_relacao[$uid_relacionado] = $aclTemp->get_specific_rights($GLOBALS['phpgw_info']['user']['account_id'],'contactcenter'); //Preciso verificar as permissões que o contato relacionado deu para o atual
725                        }
726
727                        $validos = array();
728                        $count = 0;
729                        foreach($perms_relacao as $uid_relacionado => $val){
730                                if ($perms_relacao[$uid_relacionado]&2)
731                                {
732                                        $validos[$uid_relacionado] = $perms_relacao[$uid_relacionado];
733                                        $count++;
734                                }
735                        }
736                        echo serialize(array(0=>$count));
737                }
738
739                /*!
740
741                        @function get_cards_data
742                        @abstract Returns the information that is placed on the cards
743                        @author Raphael Derosso Pereira
744
745                        @param string $letter The first letter to be searched
746                        @param (int)  $page The page to be taken
747                        @param (str)  $ids The ids to be taken in case of search
748
749                        TODO: This function is not well done. It must be rewritten
750                                using the new array 'msg','status','data' schema.
751                */
752                function get_cards_data($letter, $page, $ids, $dontPaginate = false)
753                {
754                        if( $ids )
755                                $_SESSION['ids'] = $ids;
756
757                        // It's an external catalog?
758                        $external = $this->bo->is_external($this->page_info['actual_catalog']);
759                        //echo $page."\n";
760                        if ($letter !== 'search' and ($letter != $this->page_info['actual_letter'] or
761                            ($letter == $this->page_info['actual_letter'] and $page == $this->page_info['actual_page']) or
762                            $this->page_info['changed']))
763                        {
764                                unset($ids);
765                                $this->page_info['changed'] = false;
766
767                                switch ($this->page_info['actual_catalog']['class'])
768                                {
769/**rev 104**/
770                                        case 'bo_shared_people_manager':
771/****/
772                                        case 'bo_people_catalog':
773                                                $field_name = 'id_contact';
774
775                                                if ($letter !== 'number')
776                                                {
777                                                        $find_restric[0] = array(
778                                                                0 => array(
779                                                                        'field' => 'contact.names_ordered',
780                                                                        'type'  => 'iLIKE',
781                                                                        'value' => $letter !== 'all' ? $letter.'%' : '%'
782/**rev 104**/
783        /*                                                      ),
784                                                                1 => array(
785                                                                        'field' => 'contact.id_owner',
786                                                                        'type'  => '=',
787                                                                        'value' => $GLOBALS['phpgw_info']['user']['account_id']
788        */
789                                                                )
790                                                        );
791
792                                                        //Tratamento de permissão de escrita no compartilhamento de catalogo
793                                                        $so_contact = CreateObject('contactcenter.so_contact',  $GLOBALS['phpgw_info']['user']['account_id']);
794                                                        $relacionados = $so_contact->get_relations();
795
796                                                        $perms_relacao = array();
797
798                                                        foreach($relacionados as $uid_relacionado => $tipo_relacionamento) {
799                                                                $aclTemp = CreateObject("phpgwapi.acl",$uid_relacionado);
800                                                                $aclTemp->read();
801                                                                $perms_relacao[$uid_relacionado] = $aclTemp->get_specific_rights($GLOBALS['phpgw_info']['user']['account_id'],'contactcenter'); //Preciso verificar as permissões que o contato relacionado deu para o atual
802                                                        }
803
804                                                        $validos = array();
805                                                        $count = 0;
806                                                        foreach($perms_relacao as $uid_relacionado => $val){
807                                                                if ($perms_relacao[$uid_relacionado]&2)
808                                                                {
809                                                                        $validos[$uid_relacionado] = $perms_relacao[$uid_relacionado];
810                                                                        $count++;
811                                                                }
812                                                        }
813                                                        $prop_names = array();
814                                                        if($validos) {
815                                                                $filtro = "(|";
816                                                                foreach($validos as $i => $prop) {
817                                                                        $filtro .= "(uidNumber=".$i.")";
818                                                                }
819                                                                $filtro .= ")";
820
821                                                                if(!$this->bo->catalog->src_info) {
822                                                                        $ldaps = CreateObject('contactcenter.bo_ldap_manager');
823                                                                        $this->bo->catalog->src_info = $ldaps->srcs[1];
824                                                                }
825                                                                $s = $GLOBALS['phpgw']->common->ldapConnect($this->bo->catalog->src_info['host'], $this->bo->catalog->src_info['acc'], $this->bo->catalog->src_info['pw'], false);
826                                                                $n=$this->bo->catalog->src_info['dn'];
827                                                                $apenasThese = array("cn","uidnumber","uid");
828                                                                $r = ldap_search($s,$n, $filtro,$apenasThese);
829                                                                $infos = ldap_get_entries($s, $r);
830                                                                ldap_close($s);
831                                                                for($z = 0; $z < $infos['count']; $z++) {
832                                                                        $prop_names[$infos[$z]['uidnumber'][0]] = array("cn" => $infos[$z]['cn'][0], "uid" => $infos[$z]['uid'][0]);
833                                                                }
834                                                        }
835                                                        //--------------------------------------------------------------------------------
836                                                        if($this->page_info['actual_catalog']['class'] == 'bo_people_catalog')
837                                                        {
838                                                                $find_restric[0][1] = array(
839                                                                                'field' => 'contact.id_owner',
840                                                                                'type'  => '=',
841                                                                                'value' => $GLOBALS['phpgw_info']['user']['account_id']
842                                                                );
843                                                        }
844/****/
845
846                                                }
847                                                else
848                                                {
849                                                        $find_restric[0] = array(
850                                                                0 => array(
851                                                                        'type'  => 'branch',
852                                                                        'value' => 'OR',
853                                                                        'sub_branch' => array(
854                                                                                0 => array(
855                                                                                        'field' => 'contact.names_ordered',
856                                                                                        'type'  => 'LIKE',
857                                                                                        'value' => '0%'
858                                                                                ),
859                                                                                1 => array(
860                                                                                        'field' => 'contact.names_ordered',
861                                                                                        'type'  => 'LIKE',
862                                                                                        'value' => '1%'
863                                                                                ),
864                                                                                2 => array(
865                                                                                        'field' => 'contact.names_ordered',
866                                                                                        'type'  => 'LIKE',
867                                                                                        'value' => '2%'
868                                                                                ),
869                                                                                3 => array(
870                                                                                        'field' => 'contact.names_ordered',
871                                                                                        'type'  => 'LIKE',
872                                                                                        'value' => '3%'
873                                                                                ),
874                                                                                4 => array(
875                                                                                        'field' => 'contact.names_ordered',
876                                                                                        'type'  => 'LIKE',
877                                                                                        'value' => '4%'
878                                                                                ),
879                                                                                5 => array(
880                                                                                        'field' => 'contact.names_ordered',
881                                                                                        'type'  => 'LIKE',
882                                                                                        'value' => '5%'
883                                                                                ),
884                                                                                6 => array(
885                                                                                        'field' => 'contact.names_ordered',
886                                                                                        'type'  => 'LIKE',
887                                                                                        'value' => '6%'
888                                                                                ),
889                                                                                7 => array(
890                                                                                        'field' => 'contact.names_ordered',
891                                                                                        'type'  => 'LIKE',
892                                                                                        'value' => '7%'
893                                                                                ),
894                                                                                8 => array(
895                                                                                        'field' => 'contact.names_ordered',
896                                                                                        'type'  => 'LIKE',
897                                                                                        'value' => '8%'
898                                                                                ),
899                                                                                9 => array(
900                                                                                        'field' => 'contact.names_ordered',
901                                                                                        'type'  => 'LIKE',
902                                                                                        'value' => '9%'
903                                                                                ),
904                                                                        ),
905/**rev 104**/
906/*                                                              ),
907                                                                1 => array(
908                                                                        'field' => 'contact.id_owner',
909                                                                        'type'  => '=',
910                                                                        'value' => $GLOBALS['phpgw_info']['user']['account_id']
911                                                                ),
912*/
913                                                                )
914                                                        );
915                                                }
916
917                                                if($this->page_info['actual_catalog']['class'] == 'bo_people_catalog'){                                                         
918                                                        $find_restric[0][1]     = array(
919                                                                'field' => 'contact.id_owner',
920                                                                'type'  => '=',
921                                                                'value' => $GLOBALS['phpgw_info']['user']['account_id']
922                                                        );
923                                                }
924/*****/
925
926                                                $find_field[0] = array('contact.id_contact','contact.names_ordered');
927
928                                                $find_other[0] = array(
929/**rev 104**/
930                                                        //'offset' => (($page-1)*$this->page_info['n_cards']),
931                                                        //'limit'  => $this->page_info['n_cards'],
932/*****/
933                                                        'order'  => 'contact.names_ordered'
934                                                );
935
936                                                break;
937
938                                        case 'bo_catalog_group_catalog':
939                                        case 'bo_global_ldap_catalog':
940
941                                                $field_name = 'id_contact';
942
943                                                if ($letter !== 'number')
944                                                {
945                                                        $find_restric[0] = array(
946                                                                0 => array(
947                                                                        'field' => 'contact.names_ordered',
948                                                                        'type'  => 'iLIKE',
949                                                                        'value' => $letter !== 'all' ? $letter.'%' : '%'
950                                                                ),
951                                                                /*
952                                                                 * Restrict the returned contacts in a "first letter" search
953/**rev 104
954                                                                 * to objectClass = phpgwAccount, must have attibute phpgwAccountStatus,
955                                                                 * phpgwAccountVisible != -1
956                                                                 */
957                                                                1 => array(
958                                                                        'field' => 'contact.object_class',
959                                                                        'type'  => '=',
960                                                                        'value' => 'phpgwAccount'
961/**rev 104**/
962                                                                //),/*
963                                                                ),
964/****/
965                                                                2 => array(
966                                                                        'field' => 'contact.account_status',
967                                                                        'type'  => 'iLIKE',
968                                                                        'value' => '%'
969/**rev 104**/
970                                                                //),*/
971                                                                //2 => array(
972                                                                ),
973                                                                3 => array(
974/*****/
975                                                                        'field' => 'contact.account_visible',
976                                                                        'type'  => '!=',
977                                                                        'value' => '-1'
978/**rev 104**/
979        /*                                                      ),
980                                                                3 => array(
981                                                                        'field' => 'contact.object_class',
982                                                                        'type'  => '=',
983                                                                        'value' => 'inetOrgPerson'
984                                                                ),
985        */
986                                                                )
987/*****/
988
989                                                        );
990                                                        // If not external catalog get only phpgwAccountType = u ou l
991                                                        if (!$external)
992                                                        {
993                                                                $find_restric[0][5] =  array(
994                                                                                'type'  => 'branch',
995                                                                                'value' => 'OR',
996                                                                                'sub_branch' => array(
997                                                                                        0 => array(
998                                                                                        'field' => 'contact.account_type',
999                                                                                        'type'  => '=',
1000                                                                                        'value' => 'u'
1001                                                                                        ),
1002                                                                                        1 => array(
1003                                                                                        'field' => 'contact.account_type',
1004                                                                                        'type'  => '=',
1005                                                                                        'value' => 'i'
1006/**rev 104**/
1007                                                                                        ),
1008                                                                                        2 => array(
1009                                                                                        'field' => 'contact.account_type',
1010                                                                                        'type'  => '=',
1011/****/
1012                                                                                        'value' => 'l'
1013/**rev 104**/
1014                                                                                        ),
1015                                                                                        3 => array(
1016                                                                                        'field' => 'contact.account_type',
1017                                                                                        'type'  => '=',
1018                                                                                        'value' => 'g'
1019/***/
1020                                                                                        ),
1021                                                                                        4 => array(
1022                                                                                        'field' => 'contact.account_type',
1023                                                                                        'type'  => '=',
1024                                                                                        'value' => 's'
1025                                                                                        )
1026                                                                                )
1027                                                                        );
1028                                                        }
1029                                                }
1030                                                else
1031                                                {
1032                                                        $find_restric[0] = array(
1033                                                                /*
1034                                                                 * Restrict the returned contacts in a "first number" search
1035/**rev 104
1036                                                                 * to objectClass = phpgwAccount, must have attibute phpgwAccountStatus,
1037                                                                 * phpgwAccountVisible != -1
1038                                                                 */
1039                                                                0 => array(
1040                                                                        'field' => 'contact.object_class',
1041                                                                        'type'  => '=',
1042                                                                        'value' => 'phpgwAccount'
1043/**rev 104**/
1044                                                                //),/*
1045                                                                ),
1046/****/
1047                                                                1 => array(
1048                                                                        'field' => 'contact.account_status',
1049                                                                        'type'  => 'iLIKE',
1050                                                                        'value' => '%'
1051/**rev 104**/
1052                                                                //),*/
1053                                                                //1 => array(
1054                                                                ),
1055                                                                2 => array(
1056/*****/
1057                                                                        'field' => 'contact.account_visible',
1058                                                                        'type'  => '!=',
1059                                                                        'value' => '-1'
1060                                                                ),
1061/**rev 104**/
1062        /*                                                      2 => array(
1063                                                                        'field' => 'contact.object_class',
1064                                                                        'type'  => '=',
1065                                                                        'value' => 'inetOrgPerson'
1066                                                                ),
1067        */
1068/****/
1069                                                                3 => array(
1070                                                                        'type'  => 'branch',
1071                                                                        'value' => 'OR',
1072                                                                        'sub_branch' => array(
1073                                                                                0 => array(
1074                                                                                        'field' => 'contact.names_ordered',
1075                                                                                        'type'  => 'LIKE',
1076                                                                                        'value' => '0%'
1077                                                                                ),
1078                                                                                1 => array(
1079                                                                                        'field' => 'contact.names_ordered',
1080                                                                                        'type'  => 'LIKE',
1081                                                                                        'value' => '1%'
1082                                                                                ),
1083                                                                                2 => array(
1084                                                                                        'field' => 'contact.names_ordered',
1085                                                                                        'type'  => 'LIKE',
1086                                                                                        'value' => '2%'
1087                                                                                ),
1088                                                                                3 => array(
1089                                                                                        'field' => 'contact.names_ordered',
1090                                                                                        'type'  => 'LIKE',
1091                                                                                        'value' => '3%'
1092                                                                                ),
1093                                                                                4 => array(
1094                                                                                        'field' => 'contact.names_ordered',
1095                                                                                        'type'  => 'LIKE',
1096                                                                                        'value' => '4%'
1097                                                                                ),
1098                                                                                5 => array(
1099                                                                                        'field' => 'contact.names_ordered',
1100                                                                                        'type'  => 'LIKE',
1101                                                                                        'value' => '5%'
1102                                                                                ),
1103                                                                                6 => array(
1104                                                                                        'field' => 'contact.names_ordered',
1105                                                                                        'type'  => 'LIKE',
1106                                                                                        'value' => '6%'
1107                                                                                ),
1108                                                                                7 => array(
1109                                                                                        'field' => 'contact.names_ordered',
1110                                                                                        'type'  => 'LIKE',
1111                                                                                        'value' => '7%'
1112                                                                                ),
1113                                                                                8 => array(
1114                                                                                        'field' => 'contact.names_ordered',
1115                                                                                        'type'  => 'LIKE',
1116                                                                                        'value' => '8%'
1117                                                                                ),
1118                                                                                9 => array(
1119                                                                                        'field' => 'contact.names_ordered',
1120                                                                                        'type'  => 'LIKE',
1121                                                                                        'value' => '9%'
1122                                                                                ),
1123                                                                        ),
1124                                                                ),
1125                                                        );
1126                                                        // If not external catalog get only phpgwAccountType = u ou l
1127                                                        if (!$external)
1128                                                        {
1129                                                                $find_restric[0][5] =  array(
1130                                                                        'type'  => 'branch',
1131                                                                        'value' => 'OR',
1132                                                                        'sub_branch' => array(
1133                                                                                0 => array(
1134                                                                                'field' => 'contact.account_type',
1135                                                                                'type'  => '=',
1136                                                                                'value' => 'u'
1137                                                                                ),
1138                                                                                1 => array(
1139                                                                                'field' => 'contact.account_type',
1140                                                                                'type'  => '=',
1141/**rev 104**/
1142                                                                                //'value' => 'g'
1143                                                                                //);
1144                                                                                //1 => array(
1145                                                                                'value' => 'i'
1146                                                                                ),
1147                                                                                2 => array(
1148/****/
1149                                                                                'field' => 'contact.account_type',
1150                                                                                'type'  => '=',
1151                                                                                'value' => 'l'
1152/**rev 104**/
1153                                                                                ),
1154                                                                                3 => array(
1155                                                                                'field' => 'contact.account_type',
1156                                                                                'type'  => '=',
1157                                                                                'value' => 'g'
1158                                                                                ),
1159/****/
1160                                                                                4 => array(
1161                                                                                'field' => 'contact.account_type',
1162                                                                                'type'  => '=',
1163                                                                                'value' => 's'
1164                                                                                )
1165                                                                        )
1166                                                                );
1167                                                        }
1168                                                }
1169
1170                                                if (!$external)
1171                                                {
1172                                                        // Get only this attributes: dn, cn, phpgwAccountType, objectClass, phpgwAccountStatus, phpghAccountVisible
1173                                                        // for non-external catalogs, used to restrict the attributes used in filters
1174                                                        $find_field[0] = array('contact.id_contact','contact.names_ordered','contact.account_type',
1175                                                                'contact.object_class','contact.account_visible');
1176                                                }
1177                                                else
1178                                                {
1179                                                        // Get only this attributes: dn, cn for external catalogs,
1180                                                        // used to restrict the attributes used in filters
1181                                                        $find_field[0] = array('contact.id_contact','contact.names_ordered');
1182                                                }
1183
1184                                                $find_other[0] = array(
1185                                                        //'offset' => (($page-1)*$this->page_info['n_cards']),
1186                                                        //'limit'  => $this->page_info['n_cards'],
1187                                                        'order'  => 'contact.names_ordered'
1188                                                );
1189
1190                                                break;
1191
1192                                        case 'bo_company_manager':
1193                                                $field_name = 'id_company';
1194
1195                                                $find_field[0] = array('company.id_company','company.company_name');
1196
1197                                                $find_other[0] = array(
1198                                                        //'offset' => (($page-1)*$this->page_info['n_cards']),
1199                                                        //'limit'  => $this->page_info['n_cards'],
1200                                                        'order'  => 'company.company_name'
1201                                                );
1202
1203                                                $find_restric[0] = array(
1204                                                        0 => array(
1205                                                                'field' => 'company.company_name',
1206                                                                'type'  => 'iLIKE',
1207                                                                'value' => $letter !== 'all' ? $letter.'%' : '%'
1208                                                        )
1209                                                );
1210
1211                                                break;
1212
1213                                        case 'bo_group_manager':
1214/**rev 104**/
1215                                        case 'bo_shared_group_manager':
1216/****/
1217
1218                                                $field_name = 'id_group';
1219
1220                                                if ($letter !== 'number')       {
1221
1222                                                        $find_restric[0] = array(
1223                                                                0 => array(
1224                                                                        'field' => 'group.title',
1225                                                                        'type'  => 'iLIKE',
1226                                                                        'value' => $letter !== 'all' ? $letter.'%' : '%'
1227                                                                )
1228                                                        );
1229                                                }
1230                                                 else {
1231
1232                                                        $find_restric[0] = array(
1233                                                                0 => array(
1234                                                                                        'field' => 'group.title',
1235                                                                                        'type'  => 'LIKE',
1236                                                                                        'value' => '0%'
1237                                                                )
1238                                                        );
1239                                                }
1240/**rev 104**/
1241                                                if($this->page_info['actual_catalog']['class'] == 'bo_group_manager'){
1242/****/
1243                                                        array_push($find_restric[0],  array(
1244                                                                                        'field' => 'group.owner',
1245                                                                                        'type'  => '=',
1246                                                                                        'value' => $GLOBALS['phpgw_info']['user']['account_id']
1247                                                                        )
1248                                                        );
1249                                                }
1250
1251                                                $find_field[0] = array('group.id_group','group.title','group.short_name');
1252                                                $find_other[0] = array(
1253                                                        'order'  => 'group.title'
1254                                                );
1255                                                break;
1256
1257                                        /*case 'bo_catalog_group_catalog':
1258                                                $this->page_info['actual_entries'] = false;
1259
1260                                                $this->page_info['actual_letter'] = $letter;
1261                                                $this->page_info['actual_page'] = 0;
1262
1263                                                $this->save_session();
1264                                                $final[0] = 0;
1265                                                $final[1] = $this->typeContact;
1266                                                echo serialize($final);
1267                                                return;*/
1268
1269                                }
1270
1271                                if(!$this->bo->catalog->src_info) {
1272                                    $ldaps = CreateObject('contactcenter.bo_ldap_manager');
1273                                    $this->bo->catalog->src_info = $ldaps->srcs[1];
1274                                }
1275                                $recursive = $this->bo->catalog->src_info['recursive'];
1276
1277                                $result = $this->bo->find($find_field[0],$find_restric[0],$find_other[0],false,($recursive == "true") ? true : '');
1278                                $n_entries = count($result);
1279
1280                                if ($n_entries)
1281                                {
1282                                        //echo 'N_entries: '.$n_entries.'<br>';
1283                                        $this->page_info['n_pages'] = $dontPaginate ? 1 : ceil($n_entries/$this->page_info['n_cards']);
1284                                }
1285                                else
1286                                {
1287                                        $this->page_info['n_pages'] = 0;
1288                                }
1289
1290                                if (!$result)
1291                                {
1292                                        $this->page_info['actual_entries'] = false;
1293
1294                                        $this->page_info['actual_letter'] = $letter;
1295                                        $this->page_info['actual_page'] = 0;
1296
1297                                        $this->save_session();
1298                                        $final[0] = 0;
1299                                        $final[1] = $this->typeContact;
1300                                        echo serialize($final);
1301                                        return;
1302                                }
1303                                else
1304                                {
1305                                        unset($this->page_info['actual_entries']);
1306                                        if(is_array($result)) {
1307                                                foreach ($result as $id => $value)
1308                                                {
1309                                                        if($this->page_info['actual_catalog']['class'] != 'bo_shared_people_manager' && $this->page_info['actual_catalog']['class'] != 'bo_shared_group_manager')
1310                                                                $this->page_info['actual_entries'][] = $value[$field_name];
1311                                                        else
1312                                                                $this->page_info['actual_entries'][] = array(0=>$value[$field_name],1=>$value['perms'],2=>$value['owner']);
1313                                                }
1314                                        }
1315                                }
1316                        }
1317                        else if ($letter === 'search')
1318                        {
1319                                //if (!$ids and $this->page_info['actual_letter'] !== 'search')
1320                                if (!$ids)
1321                                {
1322/**rev 104**/
1323                                        //error_log('!$ids e $this->page_info[\'actual_letter\'] != search');
1324/*****/
1325                                        $this->page_info['actual_entries'] = false;
1326
1327                                        $this->page_info['actual_letter'] = $letter;
1328                                        $this->page_info['actual_page'] = 0;
1329
1330                                        $this->save_session();
1331                                        $final[0] = 0;
1332                                        $final[1] = $this -> typeContact;
1333                                        echo serialize($final);
1334                                        return;
1335                                }
1336                                else if ($ids['error'])
1337                                {
1338                                        $this->page_info['actual_entries'] = false;
1339                                        $this->page_info['actual_letter'] = $letter;
1340                                        $this->page_info['actual_page'] = 0;
1341
1342                                        $this->save_session();
1343                                        $final[0] = 0;
1344                                        $final[1] = $this -> typeContact;
1345                                        $final['error'] = $ids['error'];
1346                                        echo serialize($final);
1347                                        return;
1348                                }
1349                                else if ($ids)
1350                                {
1351                                        $this->page_info['actual_letter']  = $letter;
1352                                        $this->page_info['actual_entries'] = $ids;
1353                                        $this->page_info['n_pages'] = $dontPaginate ? 1 : ceil(count($this->page_info['actual_entries'])/$this->page_info['n_cards']);
1354                                }
1355                        }
1356                        else
1357                        {
1358                                unset($ids);
1359                        }
1360
1361                        if ($this->page_info['actual_entries'])
1362                        {
1363                                if ($page >= $this->page_info['n_pages'])
1364                                {
1365                                        $page = $this->page_info['n_pages'];
1366                                }
1367
1368                                $final = array(
1369                                        0 => (int)$this->page_info['n_pages'],
1370                                        1 => (int)$page,
1371                                        2 => array(
1372                                                0 => 'cc_company',
1373                                                1 => 'cc_name',
1374                                                2 => 'cc_title',
1375                                                3 => 'cc_phone',
1376                                                4 => 'cc_mail',
1377                                                5 => 'cc_alias',
1378                                                6 => 'cc_id',
1379                                                7 => 'cc_forwarding_address',
1380                                                8 => 'cc_empNumber',
1381                                                9 => 'cc_department',
1382                                                10 => 'cc_mobile'
1383                                        )
1384                                );
1385
1386                                //verifica se esta habilitado a opcao de exibir os detalhes extras
1387                                $objconfig = CreateObject('phpgwapi.config', 'contactcenter');
1388                                $config = $objconfig->read_repository();
1389                               
1390                                //echo 'Page: '.$page.'<br>';
1391                                $n_entries = count($this->page_info['actual_entries']);
1392                                $n_cards = $dontPaginate? $n_entries : $this->page_info['n_cards'];
1393                                $id_i = (($page-1)*$n_cards);
1394                                $id_f = $id_i + $n_cards;
1395
1396                                //echo 'ID_I: '.$id_i.'<br>';
1397                                //echo 'ID_F: '.$id_f.'<br>';
1398                                ///---------------- Correção Temporária PHP5 -----------------------///
1399                                $ids = array();
1400/**rev 104**/
1401                                $perms = array();
1402                                $owners = array();
1403/****/
1404                                $array_temp = array();
1405
1406                                foreach($this->page_info['actual_entries'] as $key=>$tmp){
1407                                        $array_temp[] = $tmp;
1408                                }
1409
1410                                for($i = $id_i; $i < $id_f and $i < $n_entries; $i++)
1411                                {
1412/**rev 104**/
1413                                        if($this->page_info['actual_catalog']['class'] != 'bo_shared_people_manager' && $this->page_info['actual_catalog']['class'] != 'bo_shared_group_manager')
1414                                        {
1415/****/
1416                                                $ids[] = $array_temp[$i];
1417/**rev 104**/
1418                                        }else {
1419                                                $ids[] = $array_temp[$i][0];
1420                                                $perms[] = $array_temp[$i][1];
1421                                                $owners[] = $array_temp[$i][2];
1422/****/
1423                                        }
1424                                }
1425
1426/**rev 104**/
1427                                // Carrega o nome completo dos donos dos objetos (contatos e grupos);
1428                                $owner_names = array();
1429
1430                                if($owners) {
1431                                        $filter = "(|";
1432                                        foreach($owners as $i => $owner) {
1433                                                $filter .= "(uidNumber=".$owner.")";
1434                                        }
1435                                        $filter .= ")";
1436
1437                                        if(!$this->bo->catalog->src_info) {
1438                                                $ldap = CreateObject('contactcenter.bo_ldap_manager');
1439                                                $this->bo->catalog->src_info = $ldap->srcs[1];
1440                                        }
1441                                        $ds = $GLOBALS['phpgw']->common->ldapConnect($this->bo->catalog->src_info['host'], $this->bo->catalog->src_info['acc'], $this->bo->catalog->src_info['pw'], false);
1442                                        $dn=$this->bo->catalog->src_info['dn'];
1443                                        $justThese = array("cn","uidnumber","uid");
1444                                        $sr = ldap_search($ds,$dn, $filter,$justThese);
1445                                        $info = ldap_get_entries($ds, $sr);
1446                                        ldap_close($ds);
1447                                        for($z = 0; $z < $info['count']; $z++) {
1448                                                $owner_names[$info[$z]['uidnumber'][0]] = array("cn" => $info[$z]['cn'][0], "uid" => $info[$z]['uid'][0]);
1449                                        }
1450
1451                                        //SAMPLE : dc=teste, dc=diretorio, dc=empresa
1452                                        if(!count($owner_names)){
1453                                                $dns = explode(',', $dn);
1454                                                for($i = count($dns); $i > 0; $i--){
1455                                                        $ds = $GLOBALS['phpgw']->common->ldapConnect($this->bo->catalog->src_info['host'], $this->bo->catalog->src_info['acc'], $this->bo->catalog->src_info['pw'], false);
1456                                                        //verifica se veio a base como parametro, remoção de erros gerados por paramentro null
1457                                                        //if(isset($dns[$i])){
1458                                                                $sr = ldap_search($ds,$dns[$i], $filter,$justThese);
1459                                                                $info = ldap_get_entries($ds, $sr);
1460                                                                ldap_close($ds);
1461                                                                for($z = 0; $z < $info['count']; $z++) {
1462                                                                        $owner_names[$info[$z]['uidnumber'][0]] = array("cn" => $info[$z]['cn'][0], "uid" => $info[$z]['uid'][0]);
1463                                                                }       
1464                                                                if(count($owner_names)){
1465                                                                        $i = 0;
1466                                                                }
1467                                                //      }
1468                                                }
1469                                        }
1470                                }
1471
1472/*****/
1473
1474
1475                                /// Original
1476                                //for($i = $id_i; $i < $id_f and $i < $n_entries; $i++)
1477                                //{
1478                                //      $ids[] = $this->page_info['actual_entries'][$i];
1479                                //}
1480                                ///
1481
1482                                $fields = $this->bo->catalog->get_fields(false);
1483/**rev 104**/
1484                                //if( $this->typeContact == 'groups') {
1485                                if( $this->typeContact == 'groups' || $this->typeContact == 'shared_groups') {
1486/****/
1487                                        $final = array(
1488                                                0 => (int)$this->page_info['n_pages'],
1489                                                1 => (int)$page,
1490                                                2 => array(
1491                                                        0 => 'cc_title',
1492                                                        1 => 'cc_short_name',
1493                                                        2 => 'cc_id',
1494                                                        3 => 'cc_contacts'
1495                                                )
1496                                        );
1497
1498                                        $groups = $this->bo->catalog->get_multiple_entries($ids,$fields);
1499
1500                                        $i = 0;
1501                                        // contatos do grupo
1502                                        $boGroups = CreateObject('contactcenter.bo_group');
1503                                        $contacts = array();
1504                                        foreach($groups as $group)              {
1505
1506                                                $final[3][$i][0] = $group['title'] ? $group['title'] : 'none';
1507                                                $final[3][$i][1] = $group['short_name'] ? $group['short_name'] : 'none';
1508                                                $final[3][$i][2] = $group['id_group'] ? $group['id_group'] : 'none';
1509                                                $contacts = $boGroups -> get_contacts_by_group($group['id_group']);
1510                                                $final[3][$i][3] = $contacts;
1511                                                $final[3][$i][4] = $perms[$i];
1512                                                if($this->typeContact == 'shared_groups'){
1513                                                        $final[3][$i][5] = lang('Shared').": ".$owner_names[$owners[$i]]['cn'];
1514                                                        $final[3][$i][6] = $owner_names[$owners[$i]]['uid'];
1515                                                        $final[3][$i][7] = $owners[$i]; //uidNumber
1516                                                }                                               
1517                                                $i++;                                                   
1518                                        }
1519
1520                                        $this->page_info['actual_letter'] = $letter;
1521                                        $this->page_info['actual_page'] = $page;
1522
1523
1524                                        $lnk_compose = "location.href=('../expressoMail1_2/index.php?to=";
1525
1526                                        $final[5] = '<span class="link"  onclick="'.$lnk_compose;
1527/**rev 104**/
1528                                        //$final[10] = 'groups';
1529                                        $final[10] = $this->typeContact;
1530/******/
1531                                        $this->save_session();
1532                                        echo serialize($final);
1533                                        return;
1534                                }
1535/**rev 104**/
1536                                $final[10] = $this -> typeContact;
1537/*****/
1538
1539                                $fields['photo'] = true;
1540                                $fields['names_ordered'] = true;
1541                                $fields['alias'] = true;
1542                                $fields['account_type'] = true;
1543                                $fields['companies'] = 'default';
1544                                $fields['connections'] = 'default';
1545
1546/**rev 104**/
1547                                // ?aqui alterar a chamada desse método para receber o base dn?
1548                                //$contacts = &$this->bo->catalog->get_multiple_entries($ids,$fields);
1549
1550                                // ?aqui alterar a chamada desse método para receber o base dn?
1551                                if($external)
1552                                {
1553                                        $contacts = $this->bo->catalog->get_multiple_entries($ids,$fields,false,true);
1554                                } else{
1555                                        $contacts = $this->bo->catalog->get_multiple_entries($ids,$fields);
1556                                }
1557/*******/
1558                                if (!is_array($contacts) or !count($contacts))
1559                                {
1560                                        $final[0] = 0;
1561                                        $final[1] = $this -> typeContact;
1562                                        echo serialize($final);
1563                                        return;
1564                                }
1565
1566                                $i = 0;
1567                                if (!is_array($this->preferences))
1568                                {
1569                                        $this->preferences['personCardEmail'] = 1;
1570                                        $this->preferences['personCardPhone'] = 2;
1571                                }
1572                                foreach($contacts as $index => $contact)
1573                                {
1574                                        /*
1575                                         * TODO: Os timeouts de conexão foram retirados, ver se será necessário retornar essa funcionalidade, e,
1576                                         * neste caso, terminar a implementação das mensagens de retorno.
1577                                         */
1578                                        if ($index !== 'error'){
1579                                                $final[3][$i][0] = $contact['companies']['company1']['company_name']?$contact['companies']['company1']['company_name']:'none';
1580
1581/**rev 104**/
1582                                                //$final[3][$i][1] = $contact['names_ordered'] ? $contact['names_ordered'] : 'none';
1583
1584                                                if($this->page_info['actual_catalog']['class']!='bo_global_ldap_catalog'){
1585                                                        $final[3][$i][1] = $contact['names_ordered'] ? urldecode(is_array($contact['names_ordered']) ? $contact['names_ordered'][0] : $contact['names_ordered'])  : 'none';
1586                                                }
1587                                                else {
1588                                                        $contact['names_ordered'][0] = urldecode($contact['names_ordered'][0]);
1589                                                        $final[3][$i][1] = $contact['names_ordered'] ? $contact['names_ordered']  : 'none';
1590                                                }
1591
1592/********/
1593
1594                                                $final[3][$i][2] = $contact['companies']['company1']['title']? $contact['companies']['company1']['title']:'none';
1595
1596                                                //Para exibir a matricula do empregado
1597                                                $final[3][$i][8] = $contact['companies']['company1']['empNumber']?$contact['companies']['company1']['empNumber']:'none';
1598                                                //Para exibir o setor/lotacao do empregado
1599                                                $final[3][$i][9] = $contact['companies']['company1']['department']?$contact['companies']['company1']['department']:'none';
1600                                                //Para exibir o celular empresarial do empregado
1601                                                $final[3][$i][10] = $contact['companies']['company1']['celPhone']?$contact['companies']['company1']['celPhone']:'none';
1602
1603                                                //Para exibir o celular empresarial do empregado
1604                                                if ($this->preferences['voip_enabled'] && !$external && $final[3][$i][10] != 'none')
1605                                                            $final[3][$i][10] = "<a title=\"".lang("Call Mobile")."\" href=\"#\" onclick=\"connectVoip('".$final[3][$i][10]."', 'mob')\">".$final[3][$i][10]."</a>";
1606
1607                                                if ($contact['connections'])
1608                                                {
1609                                                        $default_email_found = false;
1610                                                        $default_phone_found = false;
1611                                                        foreach($contact['connections'] as $conn_info)
1612                                                        {
1613                                                                if ($conn_info['id_type'] == $this->preferences['personCardEmail'] and !$default_email_found)
1614                                                                {
1615                                                                        if ($conn_info['connection_is_default'])
1616                                                                        {
1617                                                                                $default_email_found = true;
1618                                                                        }
1619                                                                        $final[3][$i][4] = $conn_info['connection_value'] ? $conn_info['connection_value'] : 'none';
1620                                                                        $final[3][$i][13] = $conn_info['id_connection'];
1621                                                                }
1622                                                                else if ($conn_info['id_type'] == $this->preferences['personCardPhone'] and !$default_phone_found)
1623                                                                {
1624                                                                        if ($conn_info['connection_is_default'])
1625                                                                        {
1626                                                                                $default_phone_found = true;
1627                                                                        }
1628                                                                        if($final[3][$i][4] == 'none' or !$final[3][$i][4]){
1629                                                                                $final[3][$i][4] = "Não informado.";
1630                                                                                $final[3][$i][13] = $conn_info['id_connection'];
1631                                                                        }
1632/**rev 104**/
1633                                                                        //if ($_SESSION['phpgw_info']['user']['preferences']['contactcenter']['voip_enabled'] && !$external){
1634                                                                        //      $conn_info['connection_value'] = "<a title=\"".lang("Call Extension")."\" href=\"#\" onclick=\"connectVoip('".$conn_info['connection_value']."', 'ramal')\">".$conn_info['connection_value']."</a>";
1635
1636                                                                        if (!($this->preferences['telephone_number'] == $conn_info['connection_value']) && $this->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){
1637                                                                                $conn_info['connection_value'] = "<a title=\"".lang("Call Extension")."\" href=\"#\" onclick=\"connectVoip('".$conn_info['connection_value']."', 'com')\">".$conn_info['connection_value']."</a>";
1638                                                                       
1639/*****/
1640                                                                        }
1641                                                                        $final[3][$i][3] = $conn_info['connection_value'] ? $conn_info['connection_value'] : 'none';
1642                                                                }
1643                                                                if($final[3][$i][4] == 'none' or !$final[3][$i][4]){
1644                                                                        $final[3][$i][4] = 'Não informado';
1645                                                                        $final[3][$i][13] = $conn_info['id_connection'];
1646                                                               
1647                                                                }
1648                                                        }
1649                                                }
1650
1651                                                if (!$final[3][$i][3])
1652                                                {
1653                                                        $final[3][$i][3] = 'none';
1654                                                }
1655
1656                                                if($final[3][$i][4] == 'none' or !$final[3][$i][4]){
1657                                                                        $final[3][$i][4] = 'Não informado.';
1658                                                                        $final[3][$i][13] = $conn_info['id_connection'];
1659                                                               
1660                                                }
1661
1662                                                $final[3][$i][5] = $contact['alias']? urldecode( $contact['alias'] ):'none';
1663                                                $final[3][$i][6] = utf8_decode($ids[$i]);
1664
1665/**rev 104**/
1666        /*                              //      If contact is a public list, then load the forwarding addresses.
1667                                                if($contact['account_type'][0] == 'l')
1668                                                        $final[3][$i][7] = array();
1669        */
1670
1671                                                //If contact is a public list or a group, then load the forwarding addresses.
1672                                                if($contact['account_type'][0] == 'l' || $contact['account_type'][0] == 'g')
1673                                                        $final[3][$i][7] = ($contact['account_type'][0] == 'l' ? 'list' : 'group');
1674                                                       
1675                                                if($this->page_info['actual_catalog']['class']=='bo_shared_people_manager') {
1676                                                        $final[3][$i][11] = $perms[$i];
1677                                                        $final[3][$i][12] = lang('Shared').": ".$owner_names[$owners[$i]]['cn'];
1678                                                }
1679
1680                                                $final[4][$i] = $contact['photo'] ? 1  : 0;
1681                                               
1682
1683
1684                                                $i++;
1685                                        }
1686                                        else
1687                                        {
1688                                                // coloca mensagem de erro no vetor que retorna para o browser
1689                                        }
1690                                }
1691                                $lnk_compose = "location.href=('../expressoMail1_2/index.php?to=";
1692                                $final[5] = '<span class="link" onclick="'.$lnk_compose;
1693                                $final[6] = $prop_names;
1694                                $final[7] = $validos;
1695                                $final[8] = $this->page_info['actual_catalog']['class'];
1696                                $final[9] = $count;
1697                                $final[11] = $this->bo->catalog_level;
1698                                $final[12] = isset($config['cc_allow_details'])? $config['cc_allow_details'] : false;
1699                                $final[13] = '<span class="" ';
1700                                $this->page_info['actual_letter'] = $letter;
1701                                $this->page_info['actual_page'] = $page;
1702
1703                                $this->save_session();
1704                                echo serialize($final);
1705                                return;
1706                        }
1707
1708                        $this->page_info['actual_letter'] = $letter;
1709                        $this->page_info['actual_page'] = $page;
1710
1711                        $this->save_session();
1712
1713                        $final[0] = 0;
1714                        $final[1] = $this -> typeContact;
1715                        echo serialize($final);
1716                }
1717               
1718               
1719                function get_list_owners_perms_add(){
1720                        $acl = CreateObject('phpgwapi.acl');
1721                        $find_result = $acl->get_rights_and_owners($GLOBALS['phpgw_info']['user']['account_id'],'contactcenter');
1722                        if($find_result){
1723                                $owner_names = array();
1724                                $filter = "(|";
1725                                foreach($find_result as $owner) {
1726                                        if(($owner['acl_rights'] & PHPGW_ACL_ADD) == PHPGW_ACL_ADD){
1727                                                $filter .= "(uidNumber=".$owner['acl_account'].")";
1728                                        }
1729                                }
1730                                if(!$this->bo->catalog->src_info) {
1731                                        $ldap = CreateObject('contactcenter.bo_ldap_manager');
1732                                        $this->bo->catalog->src_info = $ldap->srcs[1];
1733                                }
1734                                $ds = $GLOBALS['phpgw']->common->ldapConnect($this->bo->catalog->src_info['host'], $this->bo->catalog->src_info['acc'], $this->bo->catalog->src_info['pw'], false);
1735                                $filter .= ")";
1736                                $dn=$this->bo->catalog->src_info['dn'];
1737                                $justThese = array("cn","uidnumber","uid");
1738                                $sr = ldap_search($ds,$dn, $filter,$justThese);
1739                                $info = ldap_get_entries($ds, $sr);
1740                                for($z = 0; $z < $info['count']; $z++) {
1741                                        $owner_names[$info[$z]['uidnumber'][0]] = array("cn" => $info[$z]['cn'][0], "uid" => $info[$z]['uid'][0]);
1742                                }
1743                                ldap_close($ds);
1744                                if(!count($owner_names)){
1745                                                $dns = explode(',', $dn);
1746                                                for($i = count($dns); $i > 0; $i--){
1747                                                        $ds = $GLOBALS['phpgw']->common->ldapConnect($this->bo->catalog->src_info['host'], $this->bo->catalog->src_info['acc'], $this->bo->catalog->src_info['pw'], false);
1748                                                        $sr = ldap_search($ds,$dns[$i], $filter,$justThese);
1749                                                        $info = ldap_get_entries($ds, $sr);
1750                                                        ldap_close($ds);
1751                                                        for($z = 0; $z < $info['count']; $z++) {
1752                                                                $owner_names[$info[$z]['uidnumber'][0]] = array("cn" => $info[$z]['cn'][0], "uid" => $info[$z]['uid'][0]);
1753                                                        }
1754                                                        if(count($owner_names)){
1755                                                                $i = 0;
1756                                                        }
1757                                                }
1758                                        }
1759                        }
1760                        echo serialize ($owner_names); 
1761                }
1762
1763                function get_visible_all_ldap()
1764                {
1765                        $bo = CreateObject('contactcenter.bo_ldap_manager');
1766                        $ldap_query = $bo->srcs;
1767                        return $ldap_query[1]['visible'];
1768                }
1769
1770
1771                /*!
1772
1773                        @function get_group_data
1774                        @abstract Returns all the information of a given Group
1775                        @author Nilton Emilio Buhrer Neto
1776
1777                        @param (integer) $id The id to get information
1778
1779                */
1780                function get_group_data($id,$shared_from=null)
1781                {
1782                        $this->bo->catalog = CreateObject('contactcenter.bo_group_manager');
1783                        $fields = $this->bo->catalog->get_fields(true);
1784                        $data = $this->bo->catalog->get_single_entry($id,$fields);
1785                       
1786                        if($id) {                       
1787                                // get All Contacts by group.
1788                                $data['contact_in_list'] = $this->bo->catalog->get_contacts_by_group($id);                                                             
1789                        }
1790                       
1791                        $boGroup = CreateObject('contactcenter.bo_group');
1792
1793                        $all_contacts = $boGroup->get_all_contacts(false,$shared_from);
1794                       
1795                        $contact_options = "";
1796                        if(count($all_contacts)) {                                     
1797                                foreach($all_contacts as $idx => $contact) {                           
1798                                        $contact_options .= "<OPTION value='".$contact['id_connection']."'>".$contact['names_ordered'];
1799                                        if (isset($contact['connection_value']))
1800                                                $contact_options .= " (".$contact['connection_value'].")</OPTION>";
1801                                        else
1802                                                $contact_options .= " (". $contact['phone'].")</OPTION>";
1803                                }
1804                        }
1805                        $data['contact_list'] = $contact_options;
1806                        $data['result'] = 'ok';                                                         
1807                        echo serialize($data);                 
1808                }               
1809               
1810                /*!
1811
1812                        @function get_full_data
1813                        @abstract Returns all the information of a given Entry
1814                        @author Raphael Derosso Pereira
1815
1816                        @param (integer) $id The id to get information
1817
1818                */
1819/**rev 104**/
1820                //function get_full_data($id)
1821                function get_full_data($id,$catalog='bo_people_catalog')
1822                {
1823                        $dateformat = $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
1824/**rev 104**/
1825                        //$this->bo->catalog = CreateObject('contactcenter.bo_people_catalog');
1826                        $this->bo->catalog = CreateObject('contactcenter.'.$catalog);
1827/****/
1828                        $fields = $this->bo->catalog->get_fields(true);
1829                        $fields['photo'] = false;
1830                        $entry = $this->bo->catalog->get_single_entry($id,$fields);
1831
1832                        if (is_bool($entry['given_names']))
1833                        {
1834                                $data['result'] = 'false';
1835                                echo serialize($data);
1836                                return;
1837                        }
1838
1839                        $date = explode('-', $entry['birthdate']);
1840                        $j = 0;
1841                        for ($i = 0; $i < 5; $i+=2)
1842                        {
1843                                switch($dateformat{$i})
1844                                {
1845                                        case 'Y':
1846                                                $birthdate[$j] = $date[0];
1847                                                break;
1848
1849                                        case 'm':
1850                                        case 'M':
1851                                                $birthdate[$j] = $date[1];
1852                                                break;
1853
1854                                        case 'd':
1855                                                $birthdate[$j] = $date[2];
1856                                }
1857                                $j++;
1858                        }
1859                        $datecount = 0;
1860
1861                        $data['result'] = 'ok';
1862                        $data['cc_full_add_contact_id'] = $id;
1863
1864                        /* Personal Data */
1865                        $data['personal']['cc_pd_photo'] = '../index.php?menuaction=contactcenter.ui_data.data_manager&method=get_photo&id='.$id;
1866                        $data['personal']['cc_pd_alias'] = $entry['alias'];
1867                        $data['personal']['cc_pd_given_names'] = $entry['given_names'];
1868                        $data['personal']['cc_pd_family_names'] = $entry['family_names'];
1869                        $data['personal']['cc_pd_full_name'] = $entry['names_ordered'];
1870                        $data['personal']['cc_pd_suffix'] = $entry['id_suffix'];
1871                        $data['personal']['cc_pd_birthdate_0'] = $birthdate[0];
1872                        $data['personal']['cc_pd_birthdate_1'] = $birthdate[1];
1873                        $data['personal']['cc_pd_birthdate_2'] = $birthdate[2];
1874                        //$data['personal']['cc_pd_sex'] = $entry['sex'] === 'M' ? 1 : ($entry['sex'] === 'F' ? 2 : 0);
1875                        $data['personal']['cc_pd_prefix'] = $entry['id_prefix'];
1876                        $data['personal']['cc_pd_gpg_finger_print'] = $entry['pgp_key'];
1877                        $data['personal']['cc_pd_notes'] = $entry['notes'];
1878
1879                        /* Addresses */
1880                        if (is_array($entry['addresses']))
1881                        {
1882                                $data['addresses'] = $entry['addresses'];
1883                        }
1884
1885                        /* Connections */
1886                        if (is_array($entry['connections']))
1887                        {
1888                                $data['connections'] = array();
1889                                foreach ($entry['connections'] as $connection)
1890                                {
1891                                        $type = $connection['id_type'];
1892                                        $i = count($data['connections'][$type]);
1893                                        $data['connections'][$type][$i]['id'] = $connection['id_connection'];
1894                                        $data['connections'][$type][$i]['name'] = $connection['connection_name'];
1895                                        $data['connections'][$type][$i]['value'] = $connection['connection_value'];
1896                                        $data['connections'][$type][$i]['is_default'] = $connection['connection_is_default'];
1897                                }
1898                        }
1899//                      print_r($data);
1900//OBSERVAR cc_department
1901                        /*Corporative*/
1902                        if($GLOBALS['phpgw_info']['server']['personal_contact_type']=='True'){
1903                                $data['personal']['cc_job_title'] = $entry['job_title'];
1904                                $data['personal']['cc_department'] = $entry['department'];
1905                                $data['personal']['cc_name_corporate'] = $entry['corporate_name'];
1906                                $data['personal']['cc_web_page'] = $entry['web_page'];
1907                        }
1908                       
1909
1910
1911                        /* Relations */
1912                        /* Groups */
1913                        /*
1914                         * Criado uma estrutura no data que conterá os grupos do
1915                         * contato. O formato é:
1916                         * data['groups'] = array(
1917                         *                                              'id_group' => array(
1918                         *                                                                              'id_group', 'title', 'short_name'
1919                         *                                                                              )
1920                         *                                              );
1921                         */
1922                        $boGroup = CreateObject('contactcenter.bo_group');
1923                        $groups = $boGroup->get_contact_groups($id);
1924                       
1925                        $i = 0;
1926                        $data['groups'] = array();
1927                        if(is_array($groups))
1928                        foreach($groups as $group)
1929                        {
1930                                $idGroup = $group['id_group'];
1931                                $data['groups'][$idGroup] = array(
1932                                        'title'                 => $group['title'],
1933                                        'id_group'              => $idGroup,
1934                                        'short_name'    => $group['short_name']
1935                                );
1936                                $i++;
1937                        }
1938
1939                        echo serialize($data);
1940                }
1941
1942                /*!
1943
1944                        @function get_contact_full_add_const
1945                        @abstract Returns all the constant fields in Contact Full Add Window to the JS
1946                        @author Raphael Derosso Pereira
1947                */
1948                function get_contact_full_add_const()
1949                {
1950                        $data = array();
1951                        $boPeopleCatalog = CreateObject('contactcenter.bo_people_catalog');
1952                        $predata[] = $boPeopleCatalog -> get_all_prefixes();
1953                        $predata[] = $boPeopleCatalog -> get_all_suffixes();
1954                        $predata[] = $boPeopleCatalog -> get_all_addresses_types();
1955                        $predata[] = $boPeopleCatalog -> get_all_countries();
1956                        $predata[] = $boPeopleCatalog -> get_all_connections_types();
1957                        $boGroup = CreateObject('contactcenter.bo_group');
1958            //$predata[] = $boGroup->get_groups_by_user();
1959                        //$predata[] = $this->bo->catalog->get_all_relations_types();
1960
1961                        if ($this->typeContact == 'shared_contacts') { 
1962                                                $so_contact = CreateObject('contactcenter.so_contact',  $GLOBALS['phpgw_info']['user']['account_id']);
1963                                $relacionados = $so_contact->get_relations();
1964                                         
1965                                foreach($relacionados as $uid_relacionado => $tipo_relacionamento) {     
1966                                                $predata[] = $boGroup->get_groups_by_user($uid_relacionado);                                             
1967                                                }       
1968                                        } else {
1969                                                                $predata[] = $boGroup->get_groups_by_user();
1970                                                        }
1971                       
1972                       
1973                        $i = 0;
1974                        foreach($predata as $data_)
1975                        {
1976                                if ($data_)
1977                                {
1978                                        $data[$i] = $data_;
1979                                }
1980
1981                                $i++;
1982                        }
1983
1984                        if (count($data))
1985                        {
1986                                echo serialize($data);
1987                                return;
1988                        }
1989
1990                        echo 0;
1991                }
1992
1993                /*!
1994
1995                        @function quick_add
1996                        @abstract Adds a new Contact using the Quick Add interface
1997                        @author Raphael Derosso Pereira
1998
1999                        @param string $sdata Serialized data
2000                */
2001                function quick_add($sdata, $echo=true)
2002                {
2003
2004                        $sdata = str_replace('\\"', '"', $sdata);
2005                        $new_array = unserialize($sdata);
2006                        $tdata = array();
2007
2008                        foreach($new_array as $tmp)
2009                                $tdata[] = $tmp;
2010
2011                        if (!$tdata)
2012                        {
2013                            if ($echo)
2014                            {
2015                                echo serialize(array(
2016                                        'msg'    => lang('Problems on adding your Contact. Invalid Data came from client. No Contact added!'),
2017                                        'status' => 'abort'
2018                                ));
2019                           
2020                                return;
2021                            }
2022                            else
2023                                {
2024                                    return serialize(array(
2025                                        'msg'    => lang('Problems on adding your Contact. Invalid Data came from client. No Contact added!'),
2026                                        'status' => 'abort'
2027                                    ));
2028                                }
2029                        }
2030                        $data['alias'] = addslashes($tdata[0]);
2031                        $data['given_names'] = addslashes($tdata[1]);
2032                        $data['family_names'] = addslashes($tdata[2]);
2033                        $data['connections']['default_phone']['connection_name'] = lang('Main');
2034                        $data['connections']['default_phone']['connection_value'] = $tdata[3];
2035                        $data['connections']['default_email']['connection_name'] = lang('Main');
2036                        $data['connections']['default_email']['connection_value'] = $tdata[4];
2037                        $data['is_quick_add'] = true;
2038                        $boPeople = CreateObject('contactcenter.bo_people_catalog');
2039
2040                        $result = $boPeople->quick_add($data);
2041                        if ($result)
2042                        {
2043                            $this->page_info['changed'] = true;
2044
2045                            if ($echo)
2046                            {
2047                                echo serialize(array(
2048                                    'msg'    => lang('Entry added with success!'),
2049                                    'status' => 'ok'
2050                                ));
2051                            }
2052                            else
2053                                {
2054                                    return serialize(array(
2055                                        'msg'    => lang('Entry added with success!'),
2056                                        'status' => 'ok',
2057                                        'conn'   => $boPeople->get_connections($result)
2058                                    ));
2059                                }
2060                        }
2061                        else
2062                        {
2063                            if ($echo)
2064                            {
2065                                echo serialize(array(
2066                                    'msg'    => lang('Problems on adding your Contact. No Contact added!'),
2067                                    'status' => 'error'
2068                                ));
2069                            }
2070                            else
2071                                {
2072                                    echo serialize(array(
2073                                        'msg'    => lang('Problems on adding your Contact. No Contact added!'),
2074                                        'status' => 'error'
2075                                    ));
2076                                }
2077                        }
2078
2079                        $this->save_session();
2080
2081                }
2082
2083                /*!
2084
2085                        @function add_group
2086                        @abstract Adds a new Group using the Add Group interface
2087                        @author Nilton Emilio Buhrer Neto
2088
2089                        @param string $sdata Serialized data
2090                */
2091                function add_group($sdata)
2092                {
2093                        $sdata = str_replace('\\"', '"', $sdata);
2094                        $tdata = unserialize($sdata);
2095                        $new_tdata = array();
2096
2097                        if (!$tdata)
2098                        {
2099                                echo serialize(array(
2100                                        'msg'    => lang('Problems on adding your Contact. Invalid Data came from client. No Contact added!'),
2101                                        'status' => 'abort'
2102                                ));
2103
2104                                return;
2105                        }
2106
2107                        foreach($tdata as $tmp)
2108                                $new_tdata[] = $tmp;
2109
2110                        $data['title'] = $new_tdata[0];
2111                        $data['contact_in_list'] = $new_tdata[1];
2112                        $data['id_group'] = $new_tdata[2];
2113                        $acumulatedErrors = '';
2114
2115                        $actualCatalog = $this->get_actual_catalog();
2116                        for ($i = 0; $i < count($data['contact_in_list']); $i++)
2117                        {
2118                            if (preg_match('/ldap:.*:.*/', $data['contact_in_list'][$i])) // from ldap
2119                            {
2120                                list(, $level, $dn) = explode(':', $data['contact_in_list'][$i]);
2121
2122                                // pesquisa os dados, insere no catálogo e modifica
2123                                // a entrada em $data['contact_in_list'][$i]
2124                                $set_catalog = $this->set_catalog($level, false);
2125                                $contact_data = unserialize($this->get_catalog_add_contact($dn, false));
2126                                $tmp_contact[] = $contact_data[0][0];
2127                                $tmp_contact[] = $contact_data[1][0];
2128                                $tmp_contact[] = $contact_data[2][0];
2129                                $tmp_contact[] = $contact_data[3][0];
2130                                $tmp_contact[] = $contact_data[4][0];
2131
2132                                // Determinar o id_connection
2133                                $id_contact = unserialize($this->quick_add(serialize($tmp_contact), false));
2134
2135                                switch ($id_contact['status'])
2136                                {
2137                                    case 'ok' :
2138                                        foreach ($id_contact['conn'] as $connection)
2139                                        {
2140                                            if ($connection['id_type'] == 1)
2141                                            {
2142                                                $data['contact_in_list'][$i] = $connection['id_connection'];
2143                                            }
2144                                        }
2145                                        break;
2146
2147                                    case 'alreadyExists': // if e-mail exists get their id_connection from people_catalog
2148                                        $data['contact_in_list'][$i] = $id_contact['id_connection'];
2149
2150                                    default:
2151                                        $acumulatedErrors += $id_contact['msg']."\n";
2152                                }
2153                                unset($tmp_contact);
2154
2155                            }
2156                        }
2157                        $set_catalog = $this->set_catalog($actualCatalog['data'], false); // retorna ao catálogo original.
2158                        $boGroup = CreateObject('contactcenter.bo_group_manager');
2159                        $id = $boGroup -> add_group($data);
2160
2161                        if ($id)
2162                        {
2163                                $this->page_info['changed'] = true;
2164
2165                                echo serialize(array(
2166                                        'msg'    => lang('Entry added with success!'),
2167                                        'status' => 'ok'
2168                                ));
2169                        }
2170                        else
2171                        {
2172                                echo serialize(array(
2173                                        'msg'    => lang("Problems on adding your Group. Be sure that a group with this name do not exists").
2174                                            "\n".$acumulatedErrors,
2175                                        'status' => 'error'
2176                                ));
2177                        }
2178
2179                        $this->save_session();
2180                }
2181
2182                /*!
2183
2184                        @function remove_group
2185                        @abstract Removes a group if the user has the right to do it
2186                        @author Nilton Emilio Buhrer Neto
2187                        @param (integer) $id The id to be removed
2188
2189                */
2190                function remove_group($id)
2191                {
2192                                $soGroup = CreateObject('contactcenter.so_group');
2193                                $data = array ('id_group' => $id);
2194                                if($soGroup -> delete($data)) {
2195                                        echo serialize(array(
2196                                                'msg'    => lang('Removed Entry ID '.$id.'!'),
2197                                                'status' => 'ok'
2198                                        ));
2199                                }
2200                                else {
2201                                        echo serialize(array(
2202                                                'msg'    => lang("Could\'nt remove group with id: %1", $id),
2203                                                'status' => 'error'
2204                                        ));
2205                                }
2206
2207                        $this->save_session();
2208                }
2209
2210
2211                function remove_all_entries (){
2212
2213                        $error = false;
2214                        $this->all_entries = $this->bo->catalog->get_all_entries_ids();
2215
2216                        foreach($this->all_entries as $index => $id) {
2217                                $result = $this->bo->catalog->remove_single_entry($id);
2218                                if(!$result) {
2219                                        $error = true;
2220                                        break;
2221                                }
2222                        }
2223
2224                        if(!$error) {
2225                                echo serialize(array(
2226                                        'msg'    => lang('Removed Entry ID '.$id.'!'),
2227                                        'status' => 'ok'
2228                                ));
2229                        }
2230                        else {
2231                                echo serialize(array(
2232                                        'msg'    => lang('Couldn\'t remove this entry. Inform the Site Admin!'),
2233                                        'status' => 'fail'
2234                                ));
2235                        }
2236
2237                        $this->save_session();
2238                }
2239
2240                /*!
2241
2242                        @function remove_entry
2243                        @abstract Removes an entry if the user has the right to do it
2244                        @author Raphael Derosso Pereira
2245
2246                        @param (integer) $id The id to be removed
2247
2248                */
2249                function remove_entry ($id)
2250                {
2251                        if (!is_int($id))
2252                        {
2253                                echo lang('Couldn\'t remove entry! Problem passing data to the server. Please inform admin!');
2254                                return;
2255                        }
2256
2257                        $this->page_info['changed'] = true;
2258                        $result = $this->bo->catalog->remove_single_entry($id);
2259
2260                        if ($result)
2261                        {
2262                                if ($pos = array_search($id, $this->page_info['actual_entries']))
2263                                {
2264                                        unset($this->page_info['actual_entries'][$pos]);
2265                                }
2266
2267                                $temp = false;
2268                                reset($this->page_info['actual_entries']);
2269                                foreach($this->page_info['actual_entries'] as $t)
2270                                {
2271                                        $temp[] = $t;
2272                                }
2273
2274                                $this->page_info['actual_entries'] = $temp;
2275
2276                                echo serialize(array(
2277                                        'msg'    => lang('Removed Entry ID '.$id.'!'),
2278                                        'status' => 'ok'
2279                                ));
2280                        }
2281                        else
2282                        {
2283                                echo serialize(array(
2284                                        'msg'    => lang('Couldn\'t remove this entry. Inform the Site Admin!'),
2285                                        'status' => 'fail'
2286                                ));
2287                        }
2288
2289                        $this->save_session();
2290                }
2291
2292
2293                /*!
2294
2295                        @function post_full_add
2296                        @abstract Saves all the information altered/entered in the Full Add
2297                                window
2298                        @author Raphael Derosso Pereira
2299
2300                */
2301                function post_full_add()
2302                {
2303                        $data =  $_POST['data'];
2304                        // Exceptions!!! utf8 special chars.
2305                        $data = preg_replace("/\%u2(\d+)(\d+)(\d+)/","-",$data);
2306                        $data = unserialize(str_replace('\\"', '"', $data));
2307                        $this -> bo -> catalog = CreateObject('contactcenter.bo_people_catalog');
2308
2309                        if (!is_array($data))
2310                        {
2311                                echo serialize(array(
2312                                        'msg' => lang('<p>Some problem receiving data from browser. This is probably a bug in ContactCenter<br>'.
2313                                                  'Please go to eGroupWare Bug Reporting page and report this bug.<br>'.
2314                                                          'Sorry for the inconvenient!<br><br>'.
2315                                                          '<b><i>ContactCenter Developer Team</i></b></p>'),
2316                                        'status' => 'fatal'
2317                                ));
2318                                return;
2319                        }
2320//                      print_r($data);
2321//                      echo '<br><br>';
2322
2323                        $replacer = $data['commercialAnd'];
2324                        unset($data['commercialAnd']);
2325                        if (!is_string($replacer) or strpos($replacer, "'") or strpos($replacer, '"'))
2326                        {
2327                                echo serialize(array(
2328                                        'msg' => lang('Invalid \'&\' replacer! This may be an attempt to bypass Security! Action aborted!'),
2329                                        'status' => 'fatal'
2330                                ));
2331
2332                                return;
2333                        }
2334
2335                        if ($data['id_contact'])
2336                        {
2337                                $id = $data['id_contact'];
2338                                $id_photo = $id;
2339                                unset($data['id_contact']);
2340                        }
2341                        else
2342                        {
2343                                $id_photo = '_new_';
2344                        }
2345
2346                        /*
2347                         * Process Photo, if available
2348                         */
2349                        $sleep_count = 0;
2350                        $photo_ok = $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter');
2351                        while($photo_ok[0]{0} !== 'o' and $photo_ok[1]{0} === 'y')
2352                        {
2353                                sleep(1);
2354                                $photo_ok = $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter');
2355                                $sleep_count++;
2356
2357                                if ($sleep_count > 35)
2358                                {
2359                                        // TODO
2360                                        return;
2361                                }
2362                        }
2363                        $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('wait', 'n'));
2364
2365                        if (isset($this->page_info['photos'][$id_photo]))
2366                        {
2367                                if (array_search($this->page_info['photos'][$id_photo]['status'], array('changed', 'sync')) === false)
2368                                {
2369                                        echo serialize(array(
2370                                                'msg' => $this->page_info['photos'][$id_photo]['msg'],
2371                                                'status' => $this->page_info['photos'][$id_photo]['status']
2372                                        ));
2373
2374                                        return;
2375                                }
2376
2377                                $data['photo'] = $this->page_info['photos'][$id_photo]['content'];
2378                                unset($this->page_info['photos'][$id_photo]);
2379                                $this->save_session();
2380                        }
2381
2382                        /*
2383                         * Arrange Date so it gets inserted correctly
2384                         */
2385
2386                        $dateformat = $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
2387
2388                        $j = 0;
2389                        for ($i = 0; $i < 5; $i+=2)
2390                        {
2391                                switch($dateformat{$i})
2392                                {
2393                                        case 'Y':
2394                                                $date[$j]['size'] = 4;
2395                                                $date[$j]['digit'] = 'Y';
2396                                                break;
2397
2398                                        case 'm':
2399                                        case 'M':
2400                                                $date[$j]['size'] = 2;
2401                                                $date[$j]['digit'] = 'M';
2402                                                break;
2403
2404                                        case 'd':
2405                                                $date[$j]['size'] = 2;
2406                                                $date[$j]['digit'] = 'D';
2407                                }
2408                                $j++;
2409                        }
2410                        $datecount = 0;
2411
2412                        /* Verify Data and performs insertion/update */
2413                        foreach($data as $field => $value)
2414                        {
2415                                $dataConn = $data['connections'];
2416                                $aa = count($dataConn);
2417
2418                                for($i = 0; $i < $aa; $i++ )
2419                                {
2420                                    if($dataConn['connection'.$i]['connection_is_default'] == "TRUE")
2421                                    {
2422                                        $email = $dataConn['connection'.$i]['connection_value'];
2423                                    }
2424                                }
2425
2426                                switch($field)
2427                                {
2428                                        case 'names_ordered':
2429                                                $data[$field] = addslashes(rawurldecode($value));
2430                                        case 'corporate_name':
2431                                        case 'job_title':
2432                                        case 'department':
2433                                        case 'web_page':
2434                                        case 'alias':
2435                                        case 'given_names':
2436                                        case 'family_names':
2437                                        case 'pgp_key':
2438                                        case 'notes':
2439                                                $data[$field] = addslashes(rawurldecode($data[$field]));
2440                                                break;
2441
2442                                        case 'id_status':
2443                                        case 'id_prefix':
2444                                        case 'id_suffix':
2445                                                if ($data[$field] == 0)
2446                                                {
2447                                                        unset($data[$field]);
2448                                                }
2449                                                break;
2450
2451                                        case 'birthdate_0':
2452                                        case 'birthdate_1':
2453                                        case 'birthdate_2':
2454                                        case 'birthdate':
2455                                       
2456                                                if($field == 'birthdate'){
2457                                                        $array_birth = explode("/",$data[$field]);                                                     
2458                                                        $date['value'][2] = $array_birth[2];
2459                                                        $date['value'][1] = $array_birth[1];
2460                                                        $date['value'][0] = $array_birth[0];                                           
2461                                                }else{                                 
2462                                                        switch($date[$datecount]['digit'])
2463                                                        {
2464                                                                case 'Y':
2465                                                                        $date['value'][2] = (int) $data[$field];
2466                                                                        break;
2467       
2468                                                                case 'M':
2469                                                                        $date['value'][0] = (int) $data[$field];
2470                                                                        break;
2471       
2472                                                                case 'D':
2473                                                                        $date['value'][1] = (int) $data[$field];
2474                                                                        break;
2475                                                        }
2476                                                        unset($data[$field]);
2477                                                }
2478                                               
2479                                                $datecount++;
2480
2481                                                if ($datecount != 3)
2482                                                {
2483                                                        break;
2484                                                }
2485
2486                                                if($date['value'][0] =='' && $date['value'][1] =='' && $date['value'][2] ==''){
2487                                                        $data['birthdate'] = null;
2488                                                        break;
2489                                                }
2490                                                if (!checkdate($date['value'][0], $date['value'][1], $date['value'][2]))
2491                                                {
2492                                                        echo serialize(array(
2493                                                                'msg' => lang('Invalid Date'),
2494                                                                'status' => 'invalid_data'
2495                                                        ));
2496                                                        return;
2497                                                }
2498                                                if( $date['value'][2] != "" && $date['value'][0] != "" && $date['value'][1] != ""){
2499                                                        $data['birthdate'] = $date['value'][2].'-'.$date['value'][0].'-'.$date['value'][1];
2500                                                }
2501                                                break;
2502
2503                                        case 'sex':
2504                                                if ($data[$field] !== 'M' and $data[$field] !== 'F')
2505                                                {
2506                                                        echo serialize(array(
2507                                                                'msg' => lang('Invalid Sex'),
2508                                                                'status' => 'invalid_data'
2509                                                        ));
2510                                                        return;
2511                                                }
2512                                                break;
2513
2514
2515                                        case 'addresses':
2516                                                /* Insert new cities/states */
2517                                                if (isset($value['new_states']))
2518                                                {
2519                                                        foreach($value['new_states'] as $type => $state_info)
2520                                                        {
2521                                                                $index = 'address'.$type;
2522
2523                                                                $id_state = $this->bo->catalog->add_state($state_info);
2524                                                                $data['addresses'][$index]['id_state'] = $id_state;
2525
2526                                                                if ($value['new_cities'][$type])
2527                                                                {
2528                                                                        $data[$field]['new_cities'][$type]['id_state'] = $id_state;
2529                                                                }
2530                                                        }
2531
2532                                                        unset($data['addresses']['new_states']);
2533                                                }
2534
2535                                                if (isset($value['new_cities']))
2536                                                {
2537                                                        foreach($value['new_cities'] as $type => $city_info)
2538                                                        {
2539                                                                $index = 'address'.$type;
2540
2541                                                                $id_city = $this->bo->catalog->add_city($city_info);
2542                                                                $data['addresses'][$index]['id_city'] = $id_city;
2543                                                        }
2544
2545                                                        unset($data['addresses']['new_cities']);
2546                                                }
2547
2548                                        break;
2549
2550                                        case 'birthdate':
2551                                        case 'connections':
2552                                        case 'photo':
2553                                                /* Does nothing... */
2554                                                break;
2555                                        case 'groups':
2556                                                $groups = $data['groups'];
2557                                                unset($data['groups']);
2558                                                break;
2559                                        default:
2560                                                echo serialize(array(
2561                                                        'msg' => lang('Invalid field: ').$field,
2562                                                        'status' => 'invalid_data'
2563                                                ));
2564                                                return;
2565                                }
2566                        }
2567
2568                        if (!is_null($id) and $id !== '')
2569                        {
2570                                $id = $this->bo->catalog->update_single_info($id, $data);
2571                                $result = array(
2572                                        'msg' => lang('Updated Successfully!'),
2573                                        'status' => 'ok'
2574                                );
2575                        }
2576                        else
2577                        {
2578                                $id = $this->bo->catalog->add_single_entry($data);
2579                                $result = array(
2580                                        'msg' => lang('Entry Added Successfully!'),
2581                                        'status' => 'ok'
2582                                );
2583                        }
2584
2585                        if (!($id))
2586                        {
2587                                $result = array(
2588                                        'msg' => lang('Some problem occured when trying to insert/update contact information.<br>'.
2589                                                   'Report the problem to the Administrator.'),
2590                                        'status' => 'fail'
2591                                );
2592                        }
2593                        else
2594                        {
2595                                if (isset($old_connections))
2596                                        $this->bo->catalog->update_contact_groups($id, $groups, $old_connections);
2597                                else
2598                                        $this->bo->catalog->update_contact_groups($id, $groups);
2599                        }
2600
2601                        echo serialize($result);
2602                }
2603
2604
2605                function post_full_add_shared()
2606                {
2607                        $data =  $_POST['data'];
2608                        // Exceptions!!! utf8 special chars.
2609                        $data = preg_replace("/\%u2(\d+)(\d+)(\d+)/","-",$data);
2610                        $data = unserialize(str_replace('\\"', '"', $data));
2611                        $this -> bo -> catalog = CreateObject('contactcenter.bo_shared_people_manager');
2612
2613                        if (!is_array($data))
2614                        {
2615                                echo serialize(array(
2616                                        'msg' => lang('<p>Some problem receiving data from browser. This is probably a bug in ContactCenter<br>'.
2617                                                  'Please go to eGroupWare Bug Reporting page and report this bug.<br>'.
2618                                                          'Sorry for the inconvenient!<br><br>'.
2619                                                          '<b><i>ContactCenter Developer Team</i></b></p>'),
2620                                        'status' => 'fatal'
2621                                ));
2622                                return;
2623                        }
2624//                      print_r($data);
2625//                      echo '<br><br>';
2626
2627                        $replacer = $data['commercialAnd'];
2628                        unset($data['commercialAnd']);
2629                        if (!is_string($replacer) or strpos($replacer, "'") or strpos($replacer, '"'))
2630                        {
2631                                echo serialize(array(
2632                                        'msg' => lang('Invalid \'&\' replacer! This may be an attempt to bypass Security! Action aborted!'),
2633                                        'status' => 'fatal'
2634                                ));
2635
2636                                return;
2637                        }
2638
2639                        if ($data['id_contact'])
2640                        {
2641                                $id = $data['id_contact'];
2642                                $id_photo = $id;
2643                                unset($data['id_contact']);
2644                        }
2645                        else
2646                        {
2647                                $id_photo = '_new_';
2648                        }
2649
2650                        if ($data['owner'])
2651                        {
2652                                $owner = $data['owner'];
2653                                unset($data['owner']);
2654                        }
2655                        /*
2656                         * Process Photo, if available
2657                         */
2658                        $sleep_count = 0;
2659                        $photo_ok = $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter');
2660                        while($photo_ok[0]{0} !== 'o' and $photo_ok[1]{0} === 'y')
2661                        {
2662                                sleep(1);
2663                                $photo_ok = $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter');
2664                                $sleep_count++;
2665
2666                                if ($sleep_count > 35)
2667                                {
2668                                        // TODO
2669                                        return;
2670                                }
2671                        }
2672                        $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('wait', 'n'));
2673
2674                        if (isset($this->page_info['photos'][$id_photo]))
2675                        {
2676                                if (array_search($this->page_info['photos'][$id_photo]['status'], array('changed', 'sync')) === false)
2677                                {
2678                                        echo serialize(array(
2679                                                'msg' => $this->page_info['photos'][$id_photo]['msg'],
2680                                                'status' => $this->page_info['photos'][$id_photo]['status']
2681                                        ));
2682
2683                                        return;
2684                                }
2685
2686                                $data['photo'] = $this->page_info['photos'][$id_photo]['content'];
2687                                unset($this->page_info['photos'][$id_photo]);
2688                                $this->save_session();
2689                        }
2690
2691                        /*
2692                         * Arrange Date so it gets inserted correctly
2693                         */
2694
2695                        $dateformat = $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
2696
2697                        $j = 0;
2698                        for ($i = 0; $i < 5; $i+=2)
2699                        {
2700                                switch($dateformat{$i})
2701                                {
2702                                        case 'Y':
2703                                                $date[$j]['size'] = 4;
2704                                                $date[$j]['digit'] = 'Y';
2705                                                break;
2706
2707                                        case 'm':
2708                                        case 'M':
2709                                                $date[$j]['size'] = 2;
2710                                                $date[$j]['digit'] = 'M';
2711                                                break;
2712
2713                                        case 'd':
2714                                                $date[$j]['size'] = 2;
2715                                                $date[$j]['digit'] = 'D';
2716                                }
2717                                $j++;
2718                        }
2719                        $datecount = 0;
2720
2721                        /* Verify Data and performs insertion/update */
2722                        foreach($data as $field => &$value)
2723                        {
2724
2725                                $dataConn = $data['connections'];
2726                                $aa = count($dataConn);
2727
2728                                for($i = 0; $i < $aa; $i++ )
2729                                {
2730                                    if($dataConn['connection'.$i]['connection_is_default'] == "TRUE")
2731                                    {
2732                                        $email = $dataConn['connection'.$i]['connection_value'];
2733                                    }
2734                                }
2735
2736                                if ($value == '' or is_null($value))
2737                                {
2738                                        unset($data[$field]);
2739                                        continue;
2740                                }
2741
2742                                switch($field)
2743                                {
2744                                        case 'corporate_name':
2745                                        case 'job_title':
2746                                        case 'department':
2747                                        case 'web_page':
2748                                        case 'alias':
2749                                        case 'given_names':
2750                                        case 'family_names':
2751                                        case 'groups':
2752                            $groups = $data['groups'];
2753                            unset($data['groups']);
2754                            break;
2755                                        case 'names_ordered':
2756                                        case 'pgp_key':
2757                                        case 'notes':
2758                                        case 'photo':
2759                                                $data[$field] = urldecode( $value );
2760                                                break;
2761
2762                                        case 'id_status':
2763                                        case 'id_prefix':
2764                                        case 'id_suffix':
2765                                                if ($data[$field] == 0)
2766                                                {
2767                                                        unset($data[$field]);
2768                                                }
2769                                                break;
2770
2771                                        case 'birthdate_0':
2772                                        case 'birthdate_1':
2773                                        case 'birthdate_2':
2774
2775                                                switch($date[$datecount]['digit'])
2776                                                {
2777                                                        case 'Y':
2778                                                                $date['value'][2] = (int) $data[$field];
2779                                                                break;
2780
2781                                                        case 'M':
2782                                                                $date['value'][0] = (int) $data[$field];
2783                                                                break;
2784
2785                                                        case 'D':
2786                                                                $date['value'][1] = (int) $data[$field];
2787                                                                break;
2788                                                }
2789                                                unset($data[$field]);
2790                                                $datecount++;
2791
2792                                                if ($datecount != 3)
2793                                                {
2794                                                        break;
2795                                                }
2796
2797                                                if (!checkdate($date['value'][0], $date['value'][1], $date['value'][2]))
2798                                                {
2799                                                        echo serialize(array(
2800                                                                'msg' => lang('Invalid Date'),
2801                                                                'status' => 'invalid_data'
2802                                                        ));
2803                                                        return;
2804                                                }
2805
2806                                                $data['birthdate'] = $date['value'][2].'-'.$date['value'][0].'-'.$date['value'][1];
2807                                                break;
2808
2809                                        case 'sex':
2810                                                if ($data[$field] !== 'M' and $data[$field] !== 'F')
2811                                                {
2812                                                        echo serialize(array(
2813                                                                'msg' => lang('Invalid Sex'),
2814                                                                'status' => 'invalid_data'
2815                                                        ));
2816                                                        return;
2817                                                }
2818                                                break;
2819
2820
2821                                        case 'addresses':
2822                                                /* Insert new cities/states */
2823                                                if (isset($value['new_states']))
2824                                                {
2825                                                        foreach($value['new_states'] as $type => $state_info)
2826                                                        {
2827                                                                $index = 'address'.$type;
2828
2829                                                                $id_state = $this->bo->catalog->add_state($state_info);
2830                                                                $data['addresses'][$index]['id_state'] = $id_state;
2831
2832                                                                if ($value['new_cities'][$type])
2833                                                                {
2834                                                                        $value['new_cities'][$type]['id_state'] = $id_state;
2835                                                                }
2836                                                        }
2837
2838                                                        unset($data['addresses']['new_states']);
2839                                                }
2840
2841                                                if (isset($value['new_cities']))
2842                                                {
2843                                                        foreach($value['new_cities'] as $type => $city_info)
2844                                                        {
2845                                                                $index = 'address'.$type;
2846
2847                                                                $id_city = $this->bo->catalog->add_city($city_info);
2848                                                                $data['addresses'][$index]['id_city'] = $id_city;
2849                                                        }
2850
2851                                                        unset($data['addresses']['new_cities']);
2852                                                }
2853
2854                                        break;
2855
2856                                        case 'connections':
2857                                                /* Does nothing... */
2858                                                $aaaa = 1111;
2859                                                break;
2860
2861                                        default:
2862                                                echo serialize(array(
2863                                                        'msg' => lang('Invalid field: ').$field,
2864                                                        'status' => 'invalid_data'
2865                                                ));
2866                                                return;
2867                                }
2868                        }
2869
2870                        //$code = '$id = $this->bo->catalog->';
2871
2872                        if (!is_null($id) and $id !== '')
2873                        {
2874                                //$code .= $code.'update_single_info($id, $data);';
2875                                $id = $this->bo->catalog->update_single_info($id, $data);
2876                                if(!$id){
2877                                $result = array(
2878                                                'msg' => lang('Some problem occured when trying to insert/update contact information.<br>'.
2879                                        'Report the problem to the Administrator.'),
2880                                                'status' => 'fail'
2881                                );
2882                        }
2883                                else{
2884                                $result = array(
2885                                                'msg' => lang('Updated Successfully!'),
2886                                        'status' => 'ok'
2887                                );
2888                        }
2889                        }
2890                        else
2891                        {
2892                                //$code .= 'add_single_entry($data,'.$owner.');';
2893                                $id = $this->bo->catalog->add_single_entry($data,$owner);
2894                                if(!$id){
2895                                $result = array(
2896                                        'msg' => lang('Some problem occured when trying to insert/update contact information.<br>'.
2897                                                   'Report the problem to the Administrator.'),
2898                                        'status' => 'fail'
2899                                );
2900                        }
2901                                else{
2902                                        $result = array(
2903                                                'msg' => lang('Entry Added Successfully!'),
2904                                                'status' => 'ok'
2905                                        );
2906                                }
2907                        }
2908                        echo serialize($result);
2909                }
2910                /*!
2911
2912                        @function post_photo
2913                        @abstract Wrapper to post a photo without reload a page.
2914                        @author Raphael Derosso Pereira
2915
2916                */
2917                function post_photo($id)
2918                {
2919                        //print_r($_FILES);
2920                        $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('wait', 'y'));
2921
2922                        if (!is_array($_FILES) and is_array(!$_FILES['cc_pd_photo']))
2923                        {
2924                                $this->page_info['photos'][$id]['status'] = 'no_upload';
2925                                $this->page_info['photos'][$id]['msg'] = lang('No Photos uploaded to Server.');
2926
2927                                $this->save_session();
2928                                $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('ok', 'y'));
2929                                return;
2930                        }
2931
2932                        if (!function_exists('imagecreate'))
2933                        {
2934                                $this->page_info['photos'][$id]['status'] = 'no_GD_lib';
2935                                $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.');
2936
2937                                $this->save_session();
2938                                $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('ok', 'y'));
2939                                return;
2940                        }
2941
2942                        // TODO: Get Max Size from preferences!
2943                        if ($_FILES['cc_pd_photo']['size'] > 1000000)
2944                        {
2945                                $this->page_info['photos'][$id]['status'] = 'too_large';
2946                                $this->page_info['photos'][$id]['msg'] = lang('Image too large! ContactCenter limits the image size to 1 Mb');
2947
2948                                $this->save_session();
2949                                $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('ok', 'y'));
2950                                return;
2951                        }
2952
2953                        if ($_FILES['cc_pd_photo']['error'])
2954                        {
2955                                $this->page_info['photos'][$id]['status'] = 'error';
2956                                $this->page_info['photos'][$id]['msg'] = lang('Some Error occured while processed the Image. Contact the Administrator. The error code was: ').$_FILES['cc_pd_photo']['error'];
2957
2958                                $this->save_session();
2959                                $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('ok', 'y'));
2960                                return;
2961                        }
2962
2963                        switch($_FILES['cc_pd_photo']['type'])
2964                        {
2965                                case 'image/jpeg':
2966                                case 'image/pjpeg':
2967                                        $src_img = imagecreatefromjpeg($_FILES['cc_pd_photo']['tmp_name']);
2968                                        if ($src_img == '')
2969                                        {
2970                                                $bogus = true;
2971                                        }
2972                                        break;
2973
2974                                case 'image/png':
2975                                case 'image/x-png':
2976                                        $src_img = imagecreatefrompng($_FILES['cc_pd_photo']['tmp_name']);
2977                                        if ($src_img == '')
2978                                        {
2979                                                $bogus = true;
2980                                        }
2981                                        break;
2982
2983                                case 'image/gif':
2984                                        $src_img = imagecreatefromgif($_FILES['cc_pd_photo']['tmp_name']);
2985                                        if ($src_img == '')
2986                                        {
2987                                                $bogus = true;
2988                                        }
2989                                        break;
2990
2991                                default:
2992
2993                                        $this->page_info['photos'][$id]['status'] = 'invalid_image';
2994                                        $this->page_info['photos'][$id]['msg'] = lang('The file must be an JPEG, PNG or GIF Image.');
2995
2996                                        $this->save_session();
2997                                        $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('ok', 'y'));
2998                                        return;
2999                        }
3000
3001                        if ($bogus)
3002                        {
3003                                        $this->page_info['photos'][$id]['status'] = 'invalid_file';
3004                                        $this->page_info['photos'][$id]['msg'] = lang('Couldn\'t open Image. It may be corrupted or internal library doesn\'t support this format.');
3005
3006                                        $this->save_session();
3007                                        $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('ok', 'y'));
3008                                        return;
3009                        }
3010
3011                        $img_size = getimagesize($_FILES['cc_pd_photo']['tmp_name']);
3012                        $dst_img = imagecreatetruecolor(60, 80);
3013
3014                        if (!imagecopyresized($dst_img, $src_img, 0, 0, 0, 0, 60, 80, $img_size[0], $img_size[1]))
3015                        {
3016                                $this->page_info['photos'][$id]['status'] = 'invalid_file';
3017                                $this->page_info['photos'][$id]['msg'] = lang('Couldn\'t open Image. It may be corrupted or internal library doesn\'t support this format.');
3018
3019                                $this->save_session();
3020                                $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('ok', 'y'));
3021                                return;
3022                        }
3023
3024                        ob_start();
3025                        imagepng($dst_img);
3026                        $this->page_info['photos'][$id]['content'] = ob_get_contents();
3027                        ob_end_clean();
3028
3029                        $this->page_info['photos'][$id]['status'] = 'changed';
3030                        $this->page_info['photos'][$id]['msg'] = lang('Photo Successfully Updated!');
3031
3032                        $this->save_session();
3033
3034                        $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('ok', 'y'));
3035
3036                        imagedestroy($src_img);
3037                        imagedestroy($dst_img);
3038                        echo 'ok';
3039                        return;
3040                }
3041
3042
3043                /*!
3044
3045                        @function get_photo
3046                        @abstract Returns the photo to the browser
3047                        @author Raphael Derosso Pereira
3048
3049                */
3050                function get_photo($id)
3051                {
3052                        $fields = $this->bo->catalog->get_fields(false);
3053                        $fields['photo'] = true;
3054
3055                        $contact = $this->bo->catalog->get_single_entry($id, $fields);
3056
3057                        if (!$contact['photo'])
3058                        {
3059                                header('Content-type: image/png');
3060                                echo file_get_contents(PHPGW_INCLUDE_ROOT.'/contactcenter/templates/default/images/photo_celepar.png');
3061                                return;
3062                        }
3063
3064                        header('Content-type: image/jpeg');
3065                        $photo = imagecreatefromstring ($contact['photo']);
3066                        $width = imagesx($photo);
3067                        $height = imagesy($photo);
3068                        $twidth = 70;
3069                        $theight = 90;
3070                        $small_photo = imagecreatetruecolor ($twidth, $theight);
3071                        imagecopyresampled($small_photo, $photo, 0, 0, 0, 0,$twidth, $theight, $width, $height);
3072                        imagejpeg($small_photo,"",100);
3073                        return;
3074                }
3075
3076                /*!
3077
3078                        @function get_states
3079                        @abstract Echos a serialized array containing all the states for the given country
3080                        @author Raphael Derosso Pereira
3081
3082                        @params $id_country The ID of the Country that contains the requested states
3083
3084                */
3085                function get_states($id_country)
3086                {
3087                        $states = $this->bo->catalog->get_all_states($id_country);
3088
3089                        if (!$states)
3090                        {
3091                                $result = array(
3092                                        'msg'    => lang('No States found for this Country.'),
3093                                        'status' => 'empty'
3094                                );
3095
3096                                echo serialize($result);
3097                                return;
3098                        }
3099
3100                        $result = array(
3101                                'msg'    => lang('States Successfully retrieved!'),
3102                                'status' => 'ok'
3103                        );
3104
3105                        foreach ($states as $state_info)
3106                        {
3107                                $result['data'][$state_info['id_state']] = $state_info['name'];
3108
3109                                if ($state_info['symbol'])
3110                                {
3111                                        $result['data'][$state_info['id_state']] .= ', '.$state_info['symbol'];
3112                                }
3113                        }
3114
3115                        echo serialize($result);
3116                }
3117
3118                /*!
3119
3120                        @function get_cities
3121                        @abstract Echos a serialized array containing all the cities of a given state
3122                        @author Raphael Derosso Pereira
3123
3124                        @param $id_country The ID of the Country that has the specified Cities (in case the
3125                                Country doesn't have any States)
3126                        @param $id_state The ID of the State that has the Cities requested
3127
3128                */
3129                function get_cities($id_country, $id_state=false)
3130                {
3131                        $cities = $this->bo->catalog->get_all_cities($id_country, $id_state);
3132
3133                        if (!$cities)
3134                        {
3135                                $result = array(
3136                                        'msg'    => lang('No Cities found for this State.'),
3137                                        'status' => 'empty'
3138                                );
3139
3140                                echo serialize($result);
3141                                return;
3142                        }
3143
3144                        $result = array(
3145                                'msg'    => lang('Cities Successfully retrieved!'),
3146                                'status' => 'ok'
3147                        );
3148
3149                        foreach ($cities as $city_info)
3150                        {
3151                                $result['data'][$city_info['id_city']] = $city_info['name'];
3152                        }
3153
3154                        echo serialize($result);
3155                }
3156
3157                //Traduz o campo na busca completa por entradas no catálogo do usuário.
3158                function aux_full_search ($field,$isldap) {
3159                        $retorno = '';
3160                        if($isldap) {
3161                                switch($field) {
3162                                        case 'mail':
3163                                                $retorno = 'contact.connection.mail';
3164                                                break;
3165                                        case 'phone':
3166                                                $retorno = 'contact.connection.phone';
3167                                                break;
3168                                }
3169                        }
3170                        else {
3171                                switch($field) {
3172                                        case 'corporate':
3173                                                $retorno = 'contact.corporate_name';
3174                                                break;
3175                                        case 'mail':
3176                                        case 'phone':
3177                                                $retorno = 'contact.contact_connection.connection.connection_value';
3178                                                break;
3179                                }
3180                        }
3181                        return $retorno;
3182                }
3183
3184                /*!
3185
3186                        @function search
3187                        @abstract Echos a serialized array containing the IDs
3188                                of the entries that matches the search argument
3189                        @author Raphael Derosso Pereira
3190                        @author Mário César Kolling (external catalogs)
3191
3192                        @param string $str_data A serialized array with two informations:
3193                                $data = array(
3194                                        'search_for' => (string),
3195                                        'recursive'  => (boolean),
3196                                );
3197
3198                */
3199                // SERPRO
3200                function search($str_data)
3201                {
3202                        $data = unserialize($str_data);
3203                        // It's an external catalog?
3204                        $external = $this->bo->is_external($this->page_info['actual_catalog']);
3205                        $full_search = isset($data['full_search'])?$data['full_search']:false;
3206                       
3207                        if (!is_array($data) || (!$data['search_for'] && !$full_search) || !is_array($data['fields']))
3208                        {
3209                        //      echo serialize(array(
3210                        //              'msg'    => lang('Invalid parameters'),
3211                        //              'status' => 'abort'
3212                        //      ));
3213
3214                        //      return array('error' => lang('Invalid parameters'));
3215                                $rules = array(
3216                                        0 => array(
3217                                                'field' => $data['fields']['search'],
3218                                                'type'  => 'LIKE',
3219                                                'value' => '%'
3220                                        )
3221                                );
3222                        }
3223
3224
3225                        /*
3226                         * TODO: look into the database to discover the database's encoding and convert the search_for field accordingly
3227                         */
3228                        // Support search parameters with accentuation
3229                        if ($this->page_info['actual_catalog']['class'] != 'bo_people_catalog' &&
3230/**rev 104**/
3231                                //$this->page_info['actual_catalog']['class'] != 'bo_group_manager')
3232                                $this->page_info['actual_catalog']['class'] != 'bo_group_manager' &&
3233                                $this->page_info['actual_catalog']['class'] != 'bo_shared_people_manager' &&
3234                                $this->page_info['actual_catalog']['class'] != 'bo_shared_group_manager')
3235/****/
3236                        {
3237
3238                                $data['search_for'] = $data['search_for'];
3239                        }
3240
3241                        $rules  = array();
3242
3243                        if ($data['search_for'] === '*')
3244                        {
3245                                $rules = array(
3246                                        0 => array(
3247                                                'field' => $data['fields']['search'],
3248                                                'type'  => 'LIKE',
3249                                                'value' => '%'
3250                                        )
3251                                );
3252                        }
3253                        else
3254                        {
3255                                $names = explode(' ', $data['search_for']);
3256
3257                                if (!is_array($names))
3258                                {
3259                                        if(!$full_search) {
3260                                                echo serialize(array(
3261                                                        'msg'    => lang('Invalid Search Parameter'),
3262                                                        'status' => 'abort'
3263                                                ));
3264                                                exit;
3265                                        }
3266                                        else
3267                                                $names = array();
3268
3269                                }
3270
3271                                if (!$external && $this->page_info['actual_catalog']['class'] != 'bo_people_catalog' &&
3272/**rev 104**/
3273                                        //$this->page_info['actual_catalog']['class'] != 'bo_group_manager')
3274                                        $this->page_info['actual_catalog']['class'] != 'bo_group_manager' &&
3275                                        $this->page_info['actual_catalog']['class'] != 'bo_shared_people_manager' &&
3276                                        $this->page_info['actual_catalog']['class'] != 'bo_shared_group_manager' )
3277/*****/
3278                                {
3279                                        /*
3280                                         * Restrict the returned contacts search to objectClass = phpgwAccount,
3281                                         * must have attibute phpgwAccountStatus, phpgwAccountVisible != -1
3282                                         */
3283                                       
3284                                        $rules = array(
3285                                                0 => array(
3286                                                        'field' => 'contact.object_class',
3287                                                        'type'  => '=',
3288                                                        'value' => 'phpgwAccount'
3289                                                ),
3290                                                1 => array(
3291                                                        'field' => 'contact.account_status',
3292                                                        'type'  => 'iLIKE',
3293                                                        'value' => '%'
3294                                                ),
3295/**rev 104**/
3296                                                ///
3297                                                //1 => array(
3298                                                2 => array(
3299/*****/
3300                                                        'field' => 'contact.account_visible',
3301                                                        'type'  => '!=',
3302                                                        'value' => '-1'
3303/**rev 104**/
3304        /*                                      ),
3305                                                2 => array(
3306                                                        'field' => 'contact.object_class',
3307                                                        'type'  => '=',
3308                                                        'value' => 'inetOrgPerson'
3309/****/
3310                                                ),
3311                                        );
3312
3313                                        if($full_search) {
3314                                            foreach($full_search as $field => $value) {
3315                                                    if(trim($value)!='')
3316                                                            array_push($rules,array(
3317                                                                                            'field' => $this->aux_full_search($field,true),
3318                                                                                            'type' => 'LIKE',
3319                                                                                            'value' => '*'.$value.'*'
3320                                                                                            ));
3321                                            }
3322                                        }
3323
3324                                }
3325                                else if(!$external && $full_search) {
3326                                       
3327                                        foreach($full_search as $field => $value) {
3328                                                if(trim($value)!='')
3329                                                        array_push($rules,array(
3330                                                                                        'field' => $this->aux_full_search($field,false),
3331                                                                                        'type' => 'iLIKE',
3332                                                                                        'value' => '%'.$value.'%'
3333                                                                                        ));
3334                                        }
3335                               
3336                                }
3337
3338                                foreach ($names as $name)
3339                                {
3340                                        if ($name != '')
3341                                        {
3342                                                array_push($rules, array(
3343                                                        'field' => $data['fields']['search'],
3344                                                        //'type'  => 'iLIKE',
3345                                                        //'value' => '%'.$name.'%'
3346                                                        'type'  => 'LIKE and ~=',
3347                                'value' => $name
3348                                                ));
3349                                        }
3350                                }
3351                        }
3352
3353                        if ($external || $this->page_info['actual_catalog']['class'] == 'bo_people_catalog' ||
3354/**rev 104**/
3355                                //$this->page_info['actual_catalog']['class'] == 'bo_group_manager')
3356                                $this->page_info['actual_catalog']['class'] == 'bo_group_manager' ||
3357                                $this->page_info['actual_catalog']['class'] == 'bo_shared_people_manager' ||
3358                                $this->page_info['actual_catalog']['class'] == 'bo_shared_group_manager')
3359
3360
3361/***/
3362                        {
3363                                // Get only this attributes: dn, cn for external catalogs,
3364                                // used to restrict the attributes used in filters
3365                                $ids = $this->bo->find(array($data['fields']['id'], $data['fields']['search']), $rules, array('order' => $data['fields']['search'], 'sort' => 'ASC', 'customFilter' => $data['custom_filter'], 'CN' => $data['CN'], 'exact' => $data['exact']), $data['search_for'] != null);   }
3366                        else
3367                        {
3368                                // Get only this attributes: dn, cn, phpgwAccountType, objectClass, phpgwAccountStatus, phpghAccountVisible
3369                                // for non-external catalogs, used to restrict the attributes used in filters
3370                                $ids = $this->bo->find(array(
3371                                        $data['fields']['id'],
3372                                        $data['fields']['search'],
3373                                        'contact.object_class',
3374                                        //'contact.account_status',
3375                                        'contact.account_visible',
3376                                        'contact.connection.mail',
3377                                        'contact.connection.phone'
3378                                        ), $rules, array('order' => $data['fields']['search'], 'sort' => 'ASC', 'customFilter' => $data['custom_filter'], 'CN' => $data['CN'], 'exact' => $data['exact']), $data['search_for_area'], $data['search_for'] != null ); }
3379
3380                        if (!is_array($ids) || !count($ids))
3381                        {
3382                                $this->last_search_ids = null;
3383                                $this->save_session();
3384                                return null;
3385                        }
3386
3387                        $id_field = substr($data['fields']['id'], strrpos($data['fields']['id'], '.')+1);
3388
3389                        $ids_f = array();
3390
3391                        foreach ($ids as $e_info)
3392                        {
3393/**rev 104**/
3394                                //$ids_f[] = $e_info[$id_field];
3395                                if($this->page_info['actual_catalog']['class'] != 'bo_shared_people_manager' && $this->page_info['actual_catalog']['class'] != 'bo_shared_group_manager')
3396                                {
3397                                        $ids_f[] = $e_info[$id_field];
3398                                } else{
3399                                        $ids_f[] = array(0=>$e_info[$id_field],1=>$e_info['perms'],2=>$e_info['owner']);
3400                                }
3401/****/
3402                        }
3403
3404                        return $ids_f;
3405                }
3406
3407                // CELEPAR
3408                /*
3409        function search($str_data)
3410        {
3411            $data = unserialize($str_data);
3412
3413            if (!is_array($data) || !$data['search_for'] || !is_array($data['fields']))
3414            {
3415                echo serialize(array(
3416                    'msg'    => lang('Invalid parameters'),
3417                    'status' => 'abort'
3418                ));
3419
3420                return;
3421            }
3422
3423            $rules  = array();
3424
3425            if ($data['search_for'] === '*')
3426            {
3427                $rules = array(
3428                    0 => array(
3429                        'field' => $data['fields']['search'],
3430                        'type'  => 'LIKE',
3431                        'value' => '%'
3432                    )
3433                );
3434            }
3435            else
3436            {
3437                $names = explode(' ', $data['search_for']);
3438
3439                if (!is_array($names))
3440                {
3441                    echo serialize(array(
3442                        'msg'    => lang('Invalid Search Parameter'),
3443                        'status' => 'abort'
3444                    ));
3445
3446                    return;
3447                }
3448
3449                foreach ($names as $name)
3450                {
3451                    if ($name != '')
3452                    {
3453                        array_push($rules, array(
3454                            'field' => $data['fields']['search'],
3455                            'type'  => 'iLIKE',
3456                            'value' => '%'.$name.'%'
3457                        ));
3458                    }
3459                }
3460            }
3461
3462
3463
3464            //$catalog = $this->bo->get_branch_by_level($this->bo->catalog_level[0]);
3465
3466            //if ($catalog['class'] === 'bo_people_catalog')
3467            //{
3468            //    array_push($rules, array(
3469            //        'field' => 'contact.id_owner',
3470            //        'type'  => '=',
3471            //        'value' => $GLOBALS['phpgw_info']['user']['account_id']
3472            //    ));
3473            //}
3474
3475
3476            $ids = $this->bo->find(array($data['fields']['id'], $data['fields']['search']), $rules, array('order' => $data['fields']['search'], 'sort' => 'ASC'));
3477
3478            if (!is_array($ids) || !count($ids))
3479            {
3480                echo serialize(array(
3481                    'msg'    => lang('No Entries Found!'),
3482                    'status' => 'empty'
3483                ));
3484
3485                return;
3486            }
3487            $id_field = substr($data['fields']['id'], strrpos($data['fields']['id'], '.')+1);
3488
3489            $ids_f = array();
3490            foreach ($ids as $e_info)
3491            {
3492                $ids_f[] = $e_info[$id_field];
3493            }
3494
3495            echo serialize(array(
3496                'data'   => $ids_f,
3497                'msg'    => lang('Found %1 Entries', count($ids)),
3498                'status' => 'ok'
3499            ));
3500
3501                        return;
3502        }*/
3503                /*!
3504
3505                        @function get_multiple_entries
3506                        @abstract Returns an array containing the specifiend data in the default
3507                                CC UI format
3508                        @author Raphael Derosso Pereira
3509
3510                        @param array str_data A serialized array containing the ID's of the entries
3511                                to be taken, the fields to be taken and the rules to be used on the
3512                                retrieval:
3513                                $data = array(
3514                                        'ids'    => array(...),
3515                                        'fields' => array(...),
3516                                        'rules'  => array(...)
3517                                );
3518
3519                */
3520                function get_multiple_entries($str_data)
3521                {
3522                        $data = unserialize($str_data);
3523
3524                        if (!is_array($data) or !count($data) or !count($data['fields']) or !count($data['ids']))
3525                        {
3526                                return array(
3527                                        'msg'    => lang('Invalid Parameters'),
3528                                        'status' => 'abort'
3529                                );
3530                        }
3531
3532                        $entries = $this->bo->catalog->get_multiple_entries($data['ids'], $data['fields']);
3533
3534                        if (!is_array($entries) or !count($entries))
3535                        {
3536                                return array(
3537                                        'msg'    => lang('No Entries Found!'),
3538                                        'status' => 'empty'
3539                                );
3540                        }
3541
3542                        return array(
3543                                'msg'    => lang('Found %1 Entries!', count($entries)),
3544                                'status' => 'ok',
3545                                'data'   => $entries
3546                        );
3547                }
3548
3549                /*
3550
3551                        @function get_all_entries
3552                        @abstract Returns the specified fields for all catalog's entries
3553                                in the default CC UI format
3554                        @author Raphael Derosso Pereira
3555
3556                        @params array str_data A serialized array containing the fields to
3557                                be grabbed, the maximum number of entries to be returned and a
3558                                boolean specifying if the calls refers to a new grab or to an
3559                                unfinished one.
3560
3561                */
3562                function get_all_entries($str_data)
3563                {
3564                        $data = unserialize($str_data);
3565
3566                        if (!is_array($data) or
3567                            !count($data) or
3568                                !count($data['fields']) or
3569                                !$data['maxlength'] or
3570                                (!$data['new'] and !$data['offset']))
3571                        {
3572                                return array(
3573                                        'msg'    => lang('Invalid Parameters'),
3574                                        'status' => 'abort'
3575                                );
3576                        }
3577
3578                        if ($data['new'])
3579                        {
3580                                $this->all_entries = $this->bo->catalog->get_all_entries_ids();
3581
3582                                $this->save_session();
3583
3584                                if (!is_array($this->all_entries) or !count($this->all_entries))
3585                                {
3586                                        return array(
3587                                                'msg'    => lang('No Entries Found!'),
3588                                                'status' => 'empty'
3589                                        );
3590                                }
3591
3592                                $data['offset'] = 0;
3593                        }
3594
3595                        if ($data['maxlength'] != -1)
3596                        {
3597                                $result = $this->bo->catalog->get_multiple_entries(array_slice($this->all_entries, $data['offset'], $data['maxlength']), $data['fields']);
3598                        }
3599                        else
3600                        {
3601                                $result = $this->bo->catalog->get_multiple_entries($this->all_entries, $data['fields']);
3602                        }
3603
3604                        $jsCode = array();
3605                        $count = 0;
3606                        foreach ($result as $each)
3607                        {
3608                                if (!is_array($each))
3609                                {
3610                                        continue;
3611                                }
3612
3613                                if($this-> typeContact == 'groups') {
3614
3615                                        foreach ($each as $field => $value)     {
3616
3617                                                if ($field === 'title') {
3618                                                        $optionName = '\\"'.$value.'\\"';
3619
3620                                                }
3621                                                else if ($field === 'short_name')       {
3622
3623                                                        $jsCode[] = '_this.entries.options[_this.entries.options.length] = new Option("'.$optionName.' ('.$value.')", "'.$count.'");';
3624                                                        $count++;
3625                                                }
3626                                        }
3627                                }
3628
3629                                else  {
3630                                        foreach ($each as $field => $value)     {
3631                                                if ($field === 'names_ordered') {
3632                                                         if(is_array($value))
3633                                $value = $value[0];
3634                                                        $name = '\\"'.$value.'\\"';
3635                                                }
3636                                                else if ($field === 'connections')      {
3637
3638                                                        foreach ($value as $connection)         {
3639                                                                if ($connection['id_type'] == $this->preferences['personCardEmail'])    {
3640                                                                        $jsCode[] = '_this.entries.options[_this.entries.options.length] = new Option("'.$name.' <'.$connection['connection_value'].'>", "'.$count.'");';
3641                                                                        $count++;
3642                                                                }
3643                                                        }
3644                                                }
3645                                        }
3646                                }
3647                        }
3648
3649                        $jsCodeFinal = implode("\n", $jsCode);
3650
3651                        $nEntries = count($result);
3652
3653                        if (!$nEntries)
3654                        {
3655                                return array(
3656                                        'msg'    => lang('Error while getting user information...'),
3657                                        'status' => 'abort'
3658                                );
3659                        }
3660
3661                        return array(
3662                                'msg'      => lang('Found %1 Entries!', $nEntries),
3663                                'status'   => 'ok',
3664                                'typeContact'   => $this -> typeContact,
3665                                'final'    => $nEntries + $data['offset'] < count($this->all_entries) ? false : true,
3666                                'offset'   => $data['offset'] + $nEntries,
3667                                'data'     => $jsCodeFinal
3668                        );
3669                }
3670
3671                /*********************************************************************\
3672                 *                      Auxiliar Methods                             *
3673                \*********************************************************************/
3674
3675                /*!
3676
3677                        @function save_session
3678                        @abstract Saves the data on the session
3679                        @author Raphael Derosso Pereira
3680
3681                */
3682                function save_session()
3683                {
3684                        $GLOBALS['phpgw']->session->appsession('ui_data.page_info','contactcenter',$this->page_info);
3685                        $GLOBALS['phpgw']->session->appsession('ui_data.all_entries','contactcenter',$this->all_entries);
3686                }
3687
3688                /*!
3689
3690                        @function convert_tree
3691                        @abstract Converts the tree array in the BO format to a JS tree array compatible
3692                                with the one available in eGW
3693                        @author Raphael Derosso Pereira
3694
3695                        @param (array)  $tree    The tree in the BO format
3696                        @param (string) $name    The tree name
3697                        @param (string) $iconDir The dir where the icons are
3698                        @param (string) $parent  The parent
3699                */
3700
3701                function convert_tree($tree, &$iconDir, $parent='0')
3702                {
3703//                      echo "Entrou<br>\tPai: $parent <br>";
3704                        $rtree = array();
3705
3706                        if ($parent === '0')
3707                        {
3708//                              echo 'Root!<br>';
3709                                $rtree['0'] = array(
3710                                        'type'       => 'catalog_group',
3711                                        'id'         => '0',
3712                                        'pid'        => 'none',
3713                                        'caption'    => lang('Catalogues'),
3714                                        'class'      => 'bo_catalog_group_catalog',
3715                                        'class_args' => array('_ROOT_', '$this', '$this->get_branch_by_level($this->catalog_level[0])')
3716                                );
3717                        }
3718
3719                        foreach($tree as $id => $value)
3720                        {
3721//                              echo 'ID: '.$id.'<br>';
3722                                $rtree[$parent.'.'.$id] = array(
3723                                        'type'    => $value['type'],
3724                                        'id'      => $parent.'.'.$id,
3725                                        'pid'     => $parent,
3726                                        'caption' => $value['name']
3727                                );
3728
3729                                switch($value['type'])
3730                                {
3731                                        case 'catalog_group':
3732                                        case 'mixed_catalog_group':
3733                                                $rtree = $rtree + $this->convert_tree($value['sub_branch'],$iconDir,$parent.'.'.$id);
3734                                                break;
3735                                }
3736                        }
3737
3738                        if (count($rtree))
3739                        {
3740                                return $rtree;
3741                        }
3742                }
3743
3744                function get_catalog_add_contact($id, $echo=true){
3745
3746                        $array_participants = array();
3747                        if(!$this->bo->catalog->src_info) {
3748                                $ldap = CreateObject('contactcenter.bo_ldap_manager');
3749                                $this->bo->catalog->src_info = $ldap->srcs[1];
3750                        }
3751
3752                        $ds = $GLOBALS['phpgw']->common->ldapConnect($this->bo->catalog->src_info['host'], $this->bo->catalog->src_info['acc'], $this->bo->catalog->src_info['pw'], true);
3753                        $dn=$this->bo->catalog->src_info['dn'];
3754                        $justThese = array("givenname","givenname","sn","telephonenumber","mail");
3755                        $sr = ldap_read($ds,$id, "objectClass=*",$justThese);
3756                        $info = ldap_get_entries($ds, $sr);
3757                        for($z = 0; $z < 5; $z++) {
3758                                $participant = $info[0][$justThese[$z]];
3759                                $participant[0] = utf8_decode($participant[0]);
3760                                array_push($array_participants, $participant);
3761                        }
3762
3763                        ldap_close($ds);
3764                        if ($echo)
3765                        {
3766                            echo serialize($array_participants);
3767                        }
3768                        else
3769                            {
3770                                return serialize($array_participants);
3771                            }
3772                }
3773
3774                function get_catalog_participants_group($id)
3775                {
3776                        if(!$this->bo->catalog->src_info) {
3777                                $ldap = CreateObject('contactcenter.bo_ldap_manager');
3778                                $this->bo->catalog->src_info = $ldap->srcs[1];
3779                        }
3780                        $ds = $GLOBALS['phpgw']->common->ldapConnect($this->bo->catalog->src_info['host'], $this->bo->catalog->src_info['acc'], $this->bo->catalog->src_info['pw'], true);
3781                        $justThese = array("description","memberuid");
3782                        $sr = ldap_read($ds,$id, "objectClass=*",$justThese);
3783                        $info = ldap_get_entries($ds, $sr);
3784                        $member_uids = $info[0]['memberuid'];
3785                        $contact['names_ordered'] = $info[0]['description'];
3786                        $filter = "";
3787                        for($z = 0; $z < count($member_uids); $z++) {
3788                                if($member_uids[$z])
3789                                        $filter.="(uid=".$member_uids[$z].")";
3790                        }
3791                        $array_participants = array();
3792                        if($filter) {
3793                                $filter = "(|".$filter.")";
3794                                $valarray = explode(',',$id);
3795                                array_shift($valarray);
3796                                $dn = implode(',',$valarray);
3797                                $justThese = array("cn","mail");
3798                                $sr = ldap_search($ds,$dn, $filter,$justThese);
3799                                $info = ldap_get_entries($ds, $sr);
3800                                for($z = 0; $z < $info['count']; $z++) {
3801                                        $participant =  '<font color=\'DARKBLUE\'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;'.$info[$z]['cn'][0].'&quot; &lt;'.$info[$z]['mail'][0].'&gt;</font><br>';
3802                                    $array_emails[$info[$z]['mail'][0]] = null;
3803                                        array_push($array_participants, $participant);
3804                                }
3805                                ldap_close($ds);
3806                        }
3807                        sort($array_participants);
3808                        $innerHTML = '';
3809                        foreach($array_participants as $index => $participant){
3810                                $innerHTML .= $participant;
3811                        }
3812                        $return = array('size' => count($array_participants), 'names_ordered'=> $contact['names_ordered'], 'inner_html' => $innerHTML);
3813                        echo serialize($return);
3814                }
3815
3816                function get_catalog_participants_list($id)
3817                {
3818
3819                        $fields = $this->bo->catalog->get_fields(false);
3820                        $fields['names_ordered'] = true;
3821                        $fields['mail_forwarding_address'] = true;
3822                        $contact = $this->bo->catalog->get_single_entry($id,$fields);
3823
3824                        $array_participants = array();
3825                        $array_emails = array();
3826
3827                        $filter = null;
3828                        for($z = 0; $z < $contact['mail_forwarding_address']['count']; $z++) {
3829                                        if(strstr($contact['mail_forwarding_address'][$z],'@')) {
3830                                                $filter.="(mail=".$contact['mail_forwarding_address'][$z].")";
3831                                                $array_emails[$contact['mail_forwarding_address'][$z]] = "<font color=black>".$contact['mail_forwarding_address'][$z]."</font>";
3832                                        }
3833                                        else
3834                                                $array_participants[$z] = "<font color=red>".$contact['mail_forwarding_address'][$z]."</font>";
3835                        }
3836
3837                        if($filter) {
3838                                $filter = "(|".$filter.")";
3839                                if(!$this->bo->catalog->src_info) {
3840                                        $ldap = CreateObject('contactcenter.bo_ldap_manager');
3841                                        $this->bo->catalog->src_info = $ldap->srcs[1];
3842                                }
3843                                $ds = $GLOBALS['phpgw']->common->ldapConnect($this->bo->catalog->src_info['host'], $this->bo->catalog->src_info['acc'], $this->bo->catalog->src_info['pw'], true);
3844                                $dn=$this->bo->catalog->src_info['dn'];
3845                                $justThese = array("cn","mail");
3846                                $sr = ldap_search($ds,$dn, $filter,$justThese);
3847                                $info = ldap_get_entries($ds, $sr);
3848                                for($z = 0; $z < $info['count']; $z++) {
3849                                        $participant =  '<font color=\'DARKBLUE\'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;'.$info[$z]['cn'][0].'&quot; &lt;'.$info[$z]['mail'][0].'&gt;</font><br>';
3850                                        $array_emails[$info[$z]['mail'][0]] = null;
3851                                        array_push($array_participants, $participant);
3852                                }
3853
3854                                foreach($array_emails as $index => $email)
3855                                        if($email)
3856                                                array_push($array_participants, "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".$email."<br>");
3857
3858                                ldap_close($ds);
3859                        }
3860                        sort($array_participants);
3861                        $innerHTML = '';
3862                        foreach($array_participants as $index => $participant){
3863                                $innerHTML .= $participant;
3864                        }
3865                        $return = array('size' => count($array_participants), 'names_ordered'=> $contact['names_ordered'], 'inner_html' => $innerHTML);
3866                        echo serialize($return);
3867                }
3868
3869                function export_contacts($typeExport){
3870
3871                        $boGroup = CreateObject('contactcenter.bo_group');
3872                        $contacts = $boGroup->get_all_contacts();
3873                        $streamBuffer = '';
3874                        $stramArray = Array();
3875
3876                        if(!count($contacts))
3877                                echo null;
3878
3879                        switch($typeExport) {
3880
3881                                case 'outlook_en':
3882                                        $streamBuffer = "Name;E-mail Address;Notes;Mobile Phone;Pager;Company;".
3883                                                        "Job Title;Home Phone;Home Fax;Business Phone;Business Fax\r\n";                                                       
3884                                        foreach($contacts as $index => $object){
3885                                                $streamBuffer.= "\"".$object[ 'names_ordered'] . "\";"
3886                                                        . "\"".$object[ 'main-mail' ] . "\";"
3887                                                        . "\"".str_replace("\r\n\x0a","\t",$object[ 'notes' ]) . "\";"
3888                                                        . "\"".$object[ 'mobile' ] . "\";"
3889                                                        . "\"".$object[ 'business-pager' ] . "\";"
3890                                                        . "\"".$object[ 'corporate_name' ] . "\";"
3891                                                        . "\"".$object[ 'job_title' ] . "\";"
3892                                                        . "\"".$object[ 'home-phone' ] . "\";"
3893                                                        . "\"".$object[ 'home-fax' ] . "\";"
3894                                                        . "\"".$object[ 'business-phone' ] . "\";"
3895                                                        . "\"".$object[ 'business-fax' ] . "\"\r\n";
3896                                        }
3897                                        break;
3898
3899                                case 'outlook_pt-BR':
3900                                        $streamBuffer = "Nome;Apelido;End. de email;Endereço residencial;"
3901                                                                        ."Cidade do endereço residencial;CEP do endereço residencial;Estado;País/região do endereço residencial;"
3902                                                                        ."Telefone residencial;Fax residencial;Telefone celular;Página pessoal da Web;Rua do endereço comercial;"
3903                                                                        ."Cidade do endereço comercial;CEP do endereço comercial;Estado do endereço comercial;"
3904                                                                        ."País/região do endereço comercial;Página comercial da Web;Telefone comercial;Fax comercial;Pager;Empresa;"
3905                                                                        ."Cargo;Departamento;End. comercial;Observações\r\n";
3906
3907                                        foreach($contacts as $index => $object){
3908                                                $streamBuffer.= "\"".$object[ 'names_ordered'] . "\";"
3909                                                        . "\"".$object[ 'alias' ] . "\";"
3910                                                        . "\"".$object[ 'main-mail' ] . "\";"
3911                                                        . "\"".$object[ 'home-address' ] . "\";"
3912                                                        . "\"".$object[ 'home-city_name' ] . "\";"
3913                                                        . "\"".$object[ 'home-postal_code' ] . "\";"
3914                                                        . "\"".$object[ 'home-state_name' ] . "\";"
3915                                                        . "\"".$object[ 'home-id_country' ] . "\";"
3916                                                        . "\"".$object[ 'home-phone' ] . "\";"
3917                                                        . "\"".$object[ 'home-fax' ] . "\";"
3918                                                        . "\"".$object[ 'mobile' ] . "\";"
3919                                                        . "\"".$object[ 'web_page' ] . "\";"
3920                                                        . "\"".$object[ 'business-address' ] . "\";"
3921                                                        . "\"".$object[ 'business-city_name' ] . "\";"
3922                                                        . "\"".$object[ 'business-postal_code' ] . "\";"
3923                                                        . "\"".$object[ 'business-state_name' ] . "\";"
3924                                                        . "\"".$object[ 'business-id_country' ] . "\";"
3925                                                        . "\"".$object[ 'web_page' ] . "\";"
3926                                                        . "\"".$object[ 'business-phone' ] . "\";"
3927                                                        . "\"".$object[ 'business-fax' ] . "\";"
3928                                                        . "\"".$object[ 'business-pager' ] . "\";"
3929                                                        . "\"".$object[ 'corporate_name' ] . "\";"
3930                                                        . "\"".$object[ 'job_title' ] . "\";"
3931                                                        . "\"".$object[ 'department' ] . "\";"
3932                                                        ."\"\";"
3933                                                        . "\"".str_replace("\r\n\x0a","\t",$object[ 'notes' ]) . "\"\r\n";
3934                                        }
3935
3936                                break;
3937
3938                                case 'outlook2000_pt-BR':
3939                                        $streamBuffer = "\"Tratamento\",\"Nome\",\"Segundo Nome\",\"Sobrenome\",\"Sufixo\",".
3940                                        "\"Empresa\",\"Departamento\",\"Cargo\",\"Rua do endereço comercial\",\"Rua do endereço comercial 2\",".
3941                                        "\"Rua do endereço comercial 3\",\"Cidade do endereço comercial\",\"Estado do endereço comercial\",".
3942                                        "\"CEP do endereço comercial\",\"País do endereço comercial\",\"Endereço residencial\",\"Rua residencial 2\",".
3943                                        "\"Rua residencial 3\",\"Cidade do endereço residencial\",\"Estado\",\"CEP do endereço residencial\",\"País do endereço residencial\",".
3944                                        "\"Outro endereço\",\"Outro endereço 2\",\"Outro endereço 3\",\"Cidade\",\"Estado\",\"CEP\",\"País\",".
3945                                        "\"Telefone do assistente\",\"Fax comercial\",\"Telefone comercial\",\"Telefone comercial 2\",\"Retorno de chamada\",".
3946                                        "\"Telefone do carro\",\"Telefone principal da empresa\",\"Fax residencial\",\"Telefone residencial\",".
3947                                        "\"Telefone residencial 2\",\"ISDN\",\"Telefone celular\",\"Outro fax\",\"Outro telefone\",\"Pager\",\"Telefone principal\",".
3948                                        "\"Radiofone\",\"Telefone TTY/TDD\",\"Telex\",\"Aniversário\",\"Anotações\",\"Caixa postal\",\"Categorias\",".
3949                                        "\"Código da empresa\",\"Código do governo\",\"Cônjuge\",\"Conta\",\"Endereço de correio eletrônico\",".
3950                                        "\"Nome de exibição do correio eletr.\",\"Endereço de correio eletrônico 2\",".
3951                                        "\"Nome de exibição do correio eletr.2\",\"Endereço de correio eletrônico 3\",".
3952                                        "\"Nome de exibição do correio eletr.3\",\"Datas especiais\",\"Disponibilidade da Internet\",".
3953                                        "\"Filhos\",\"Hobby\",\"Idioma\",\"Indicação\",\"Informações para cobrança\",\"Iniciais\",\"Local\",".
3954                                        "\"Nome do assistente\",\"Nome do gerenciador\",\"Página da Web\",\"Palavras-chave\",\"Particular\",\"Personalizado 1\",\"Personalizado 2\",".
3955                                        "\"Personalizado 3\",\"Personalizado 4\",\"Prioridade\",\"Profissão\",\"Quilometragem\",\"Sala\",\"Sensibilidade\",\"Servidor de diretório\",".
3956                                        "\"Sexo\"\r\n";
3957
3958
3959
3960                                        foreach($contacts as $index => $object){
3961                                $streamBuffer .= "\"".$object[ 'alias' ] . "\","                                   
3962                                                                . "\"".$object[ 'names_ordered' ] . "\","
3963                                                                .",,,"
3964                                                                . "\"".$object[ 'corporate_name' ] . "\","
3965                                                                . "\"".$object[ 'department' ] . "\","
3966                                                                . "\"".$object[ 'job_title' ] . "\","
3967                                                                . "\"".$object[ 'business-address' ] . "\","
3968                                                                . "\"".$object[ 'business-address-2' ] . "\","
3969                                                                .","
3970                                                                . "\"".$object[ 'business-city_name' ] . "\","
3971                                                                . "\"".$object[ 'business-state' ] . "\","
3972                                                                . "\"".$object[ 'business-postal_code' ] . "\","
3973                                                                . "\"".$object[ 'business-id_country' ] . "\","
3974                                                                . "\"".$object[ 'home-address' ] . "\","
3975                                                                . "\"".$object[ 'home-address-2' ] . "\","
3976                                                                .","
3977                                                                . "\"".$object[ 'home-city_name' ] . "\","
3978                                                                . "\"".$object[ 'home-state_name' ] . "\","
3979                                                                . "\"".$object[ 'home-postal_code' ] . "\","
3980                                                                . "\"".$object[ 'home-id_country' ] . "\","
3981                                                                .",,,,,,,,"
3982                                                                . "\"".$object[ 'business-fax' ] . "\","
3983                                                                . "\"".$object[ 'business-phone' ] . "\","
3984                                                                . "\"".$object[ 'business-mobile' ] . "\","
3985                                                                .",,,"
3986                                                                . "\"".$object[ 'home-fax' ] . "\","
3987                                                                . "\"".$object[ 'home-phone' ] . "\","
3988                                                                .",,"
3989                                                                . "\"".$object[ 'mobile' ] . "\","
3990                                                                .",,"
3991                                                                . "\"".$object[ 'home-pager' ] . "\","
3992                                                                . "\"".$object[ 'business-phone' ] . "\","
3993                                                                .",,,"
3994                                                                . "\"".$object[ 'birthdate' ] . "\","
3995                                                                . "\"".str_replace("\r\n\x0a","\t",$object[ 'notes' ]) . "\","
3996                                                                .",,,,,,"
3997                                                                . "\"".$object[ 'main-mail' ] . "\","
3998                                                                .","
3999                                                                . "\"".$object[ 'alternative-mail' ] . "\","
4000                                                                .",,,,,,,,,,,,,,"
4001                                                                . "\"".$object[ 'web_page' ] . "\","
4002                                                                .",,,,,,,,,,,,"
4003                                                                . "\"".$object[ 'sex' ] . "\"\r\n";                                                             
4004                            }
4005                                break;
4006
4007                                case 'outlook2000_en':
4008                                        $streamBuffer = "Title,First Name,Middle Name,Last Name,Suffix,Company,Department,Job Title,".
4009                                        "Business Street,Business Street 2,Business Street 3,Business City,Business State,Business Postal Code,".
4010                                        "Business Country,Home Street,Home Street 2,Home Street 3,Home City,Home State,Home Postal Code,Home Country,".
4011                                        "Other Street,Other Street 2,Other Street 3,Other City,Other State,Other Postal Code,Other Country,".
4012                                        "Assistant's Phone,Business Fax,Business Phone,Business Phone 2,Callback,Car Phone,Company Main Phone,Home Fax,".
4013                                        "Home Phone,Home Phone 2,ISDN,Mobile Phone,Other Fax,Other Phone,Pager,Primary Phone,Radio Phone,TTY/TDD Phone,Telex,".
4014                                        "Account,Anniversary,Assistant's Name,Billing Information,Birthday,Categories,Children,Directory Server,E-mail Address,".
4015                                        "E-mail Type,E-mail Display Name,E-mail 2 Address,E-mail 2 Type,E-mail 2 Display Name,E-mail 3 Address,E-mail 3 Type,E-mail 3 Display Name,".
4016                                        "Gender,Government ID Number,Hobby,Initials,Internet Free Busy,Keywords,Language,Location,Manager's Name,Mileage,Notes,".
4017                                        "Office Location,Organizational ID Number,PO Box,Priority,Private,Profession,Referred By,Sensitivity,Spouse,User 1,User 2,User 3,User 4,Web Page\r\n";
4018
4019                                foreach($contacts as $index => $object)
4020                                {
4021                                        if( array_key_exists("phone", $object) )
4022                                           $phone = $object['phone'];
4023                                        else
4024                                           $phone = $object['business-phone'];
4025
4026                                                $streamBuffer.= "\"".$object[ 'alias' ] . "\","
4027                                                        . "\"".$object[ 'names_ordered'] . "\","
4028                                                        .",,,"
4029                                                        . "\"".$object[ 'corporate_name' ] . "\","
4030                                                        . "\"".$object[ 'department' ] . "\","
4031                                                        . "\"".$object[ 'job_title' ] . "\","
4032                                                        . "\"".$object[ 'business-address' ] . "\","
4033                                                        . "\"".$object[ 'business-address-2' ] . "\","
4034                                                        .","
4035                                                        . "\"".$object[ 'business-city_name' ] . "\","
4036                                                        . "\"".$object[ 'business-state' ] . "\","
4037                                                        . "\"".$object[ 'business-postal_code' ] . "\","
4038                                                        . "\"".$object[ 'business-id_country' ] . "\","
4039                                                        . "\"".$object[ 'home-address' ] . "\","
4040                                                        . "\"".$object[ 'home-address-2' ] . "\","
4041                                                        .","
4042                                                        . "\"".$object[ 'home-city_name' ] . "\","
4043                                                        . "\"".$object[ 'home-state_name' ] . "\","
4044                                                        . "\"".$object[ 'home-postal_code' ] . "\","
4045                                                        . "\"".$object[ 'home-id_country' ] . "\","
4046                                                        .",,,,,,,,"
4047                                                        . "\"".$object[ 'business-fax' ] . "\","
4048                                                        . "\"".$phone . "\","
4049                                                        . "\"".$object[ 'business-mobile' ] . "\","
4050                                                        .",,,"
4051                                                        . "\"".$object[ 'home-fax' ] . "\","
4052                                                        . "\"".$object[ 'home-phone' ] . "\","
4053                                                        .",,"
4054                                                        . "\"".$object[ 'mobile' ] . "\","
4055                                                        .",,"
4056                                                        . "\"".$object[ 'business-pager' ] . "\","
4057                                                        . "\"".$object[ 'home-pager' ] . "\","
4058                                                        .",,,,,,,,"
4059                                                        . "\"".$object[ 'birthdate' ] . "\","
4060                                                        .",,,"
4061                                                        . "\"".$object[ 'main-mail' ] . "\","
4062                                                        .",,"
4063                                                        . "\"".$object[ 'alternative-mail' ] . "\","
4064                                                        .",,,,,,,,,,,,,,,"
4065                                                        . "\"".str_replace("\r\n\x0a","\t",$object[ 'notes' ]) . "\","
4066                                                        .",,,,,,,,,,,,,"
4067                                                        . "\"".$object[ 'web_page' ] . "\"\r\n";
4068
4069                                        }
4070                                break;
4071
4072                                case 'thunderbird':
4073                                        $streamBuffer = "First Name,Last Name,Display Name,Nickname,Primary Email,Secondary Email,"
4074                                                ."Screen Name,Work Phone,Home Phone,Fax Number,Pager Number,Mobile Number,Home Address,"
4075                                                ."Home Address 2,Home City,Home State,Home ZipCode,Home Country,Work Address,Work Address 2,"
4076                                                ."Work City,Work State,Work ZipCode,Work Country,Job Title,Department,Organization,Web Page 1,"
4077                                                ."Web Page 2,Birth Year,Birth Month,Birth Day,Custom 1,Custom 2,Custom 3,Custom 4,Notes,\r\n";
4078
4079                                        foreach($contacts as $index => $object){
4080                                                $array_birth = explode("-",$object[ 'birthdate' ]);
4081
4082                                                $stramArray[0] = "\"".$object[ 'names_ordered'] . "\"";
4083                                                $stramArray[1] = "";
4084                                                $stramArray[2] = "\"".$object[ 'names_ordered'] . "\"";
4085                                                $stramArray[3] = "\"".$object[ 'alias' ] . "\"";
4086                                                $stramArray[4] = "\"".$object[ 'main-mail' ] . "\"";
4087                                                $stramArray[5] = "\"".$object[ 'alternative-mail' ] . "\"";
4088                                                $stramArray[6] = "";
4089                                                $stramArray[7] = "\"".$object[ 'business-phone' ] . "\"";
4090                                                $stramArray[8] = "\"".$object[ 'home-phone' ] . "\"";
4091                                                $stramArray[9] = "\"".$object[ 'business-fax' ] . "\"";
4092                                                $stramArray[10] = "\"".$object[ 'business-pager' ] . "\"";
4093                                                $stramArray[11] = "\"".$object[ 'mobile' ] . "\"";
4094                                                $stramArray[12] = "\"".$object[ 'home-address' ] . "\"";
4095                                                $stramArray[13] = "\"".$object[ 'home-address-2' ] . "\"";
4096                                                $stramArray[14] = "\"".$object[ 'home-city_name' ] . "\"";
4097                                                $stramArray[15] = "\"".$object[ 'home-state_name' ] . "\"";
4098                                                $stramArray[16] = "\"".$object[ 'home-postal_code' ] . "\"";
4099                                                $stramArray[17] = "\"".$object[ 'home-id_country' ] . "\"";
4100                                                $stramArray[18] = "\"".$object[ 'business-address' ] . "\"";
4101                                                $stramArray[19] = "\"".$object[ 'business-address-2' ] . "\"";
4102                                                $stramArray[20] = "\"".$object[ 'business-city_name' ] . "\"";
4103                                                $stramArray[21] = "\"".$object[ 'business-state_name' ] . "\"";
4104                                                $stramArray[22] = "\"".$object[ 'business-postal_code' ] . "\"";
4105                                                $stramArray[23] = "\"".$object[ 'business-id_country' ] . "\"";
4106                                                $stramArray[24] = "\"".$object[ 'job_title' ] . "\"";
4107                                                $stramArray[25] = "\"".$object[ 'department' ] . "\"";
4108                                                $stramArray[26] = "\"".$object[ 'corporate_name' ] . "\"";
4109                                                $stramArray[27] = "";
4110                                                $stramArray[28] = "";
4111                                                $stramArray[29] = "\"".$array_birth[0] . "\"";
4112                                                $stramArray[30] = "\"".$array_birth[1] . "\"";
4113                                                $stramArray[31] = "\"".$array_birth[2] . "\"";
4114                                                $stramArray[32] = "";
4115                                                $stramArray[33] = "";
4116                                                $stramArray[34] = "";
4117                                                $stramArray[35] = "";
4118                                                $stramArray[36] = "";
4119                                                $stramArray[37] = "\"".str_replace("\r\n\x0a","\t",$object[ 'notes' ]) . "\"\r\n";
4120                                               
4121                                                if($object[ 'phone' ]){
4122                                                        if(!$object[ 'home-phone' ])
4123                                                                $stramArray[8] = "\"".$object[ 'phone' ]. "\"";
4124                                                        else if(!$object[ 'mobile' ])
4125                                                                $stramArray[11] = "\"".$object[ 'phone' ]. "\"";
4126                                                        else if(!$object[ 'business-phone' ])
4127                                                                $stramArray[7] = "\"".$object[ 'phone' ]. "\"";
4128                                                }
4129                                               
4130                                                $streamBuffer .= implode("," , $stramArray);
4131                                        }
4132                                break;
4133
4134                                case 'expresso':
4135                            $streamBuffer = 'Nome,Apelido,E-mail Principal,E-mail Alternativo,Celular,'
4136                                . 'Telefone Comercial,Endereço Comercial,Complemento End. Comercial,CEP Comercial,Cidade End. Comercial,Estado End. Comercial,País End. Comercial,'
4137                                . 'Telefone Residencial,Endereço Residencial,Complemento End. Residencial,CEP Residencial,Cidade End. Residencial,Estado End. Residencial,País End. Residencial,'
4138                                . 'Aniversário,Sexo,Assinatura GPG,Notas,Página Web,Empresa,Cargo,Departamento,Fax Comercial,Pager Comercial,Celular Comercial,Fax,Pager,Endereço Comercial 2,Endereço Residencial 2'
4139                                                        . "\r\n";
4140
4141                            foreach($contacts as $index => $object){
4142                                                                $stramArray[0] = "\"".$object[ 'names_ordered'] . "\"";
4143                                                                $stramArray[1] = "\"".$object[ 'alias' ] . "\"";
4144                                                                $stramArray[2] = "\"".$object[ 'main-mail' ] . "\"";
4145                                                                $stramArray[3] = "\"".$object[ 'alternative-mail' ] . "\"";
4146                                                                $stramArray[4] = "\"".$object[ 'mobile' ] . "\"";
4147                                                                $stramArray[5] = "\"".$object[ 'business-phone' ] . "\"";
4148                                                                $stramArray[6] = "\"".$object[ 'business-address' ] . "\"";
4149                                                                $stramArray[7] = "\"".$object[ 'business-complement' ] . "\"";
4150                                                                $stramArray[8] = "\"".$object[ 'business-postal_code' ] . "\"";
4151                                                                $stramArray[9] = "\"".$object[ 'business-city_name' ] . "\"";
4152                                                                $stramArray[10] = "\"".$object[ 'business-state_name' ] . "\"";
4153                                                                $stramArray[11] = "\"".$object[ 'business-id_country' ] . "\"";
4154                                                                $stramArray[12] = "\"".$object[ 'home-phone' ] . "\"";
4155                                                                $stramArray[13] = "\"".$object[ 'home-address' ] . "\"";
4156                                                                $stramArray[14] = "\"".$object[ 'home-complement' ] . "\"";
4157                                                                $stramArray[15] = "\"".$object[ 'home-postal_code' ] . "\"";
4158                                                                $stramArray[16] = "\"".$object[ 'home-city_name' ] . "\"";
4159                                                                $stramArray[17] = "\"".$object[ 'home-state_name' ] . "\"";
4160                                                                $stramArray[18] = "\"".$object[ 'home-id_country' ] . "\"";
4161                                                                $stramArray[19] = "\"".$object[ 'birthdate' ] . "\"";
4162                                                                $stramArray[20] = "\"".$object[ 'sex' ] . "\"";
4163                                                                $stramArray[21] = "\"".$object[ 'pgp_key' ] . "\"";
4164                                                                $stramArray[22] = "\"".str_replace("\r\n\x0a","\t",$object[ 'notes' ]) . "\"";
4165                                                                $stramArray[23] = "\"".$object[ 'web_page' ] . "\"";
4166                                                                $stramArray[24] = "\"".$object[ 'corporate_name' ] . "\"";
4167                                                                $stramArray[25] = "\"".$object[ 'job_title' ] . "\"";
4168                                                                $stramArray[26] = "\"".$object[ 'department' ] . "\"";
4169                                                                $stramArray[27] = "\"".$object[ 'business-fax' ] . "\"";
4170                                                                $stramArray[28] = "\"".$object[ 'business-pager' ] . "\"";
4171                                                                $stramArray[29] = "\"".$object[ 'business-mobile' ] . "\"";
4172                                                                $stramArray[30] = "\"".$object[ 'home-fax' ] . "\"";
4173                                                                $stramArray[31] = "\"".$object[ 'home-pager' ] . "\"";
4174                                                                $stramArray[32] = "\"".$object[ 'business-address-2' ] . "\"";
4175                                                                $stramArray[33] = "\"".$object[ 'home-address-2' ] . "\"\r\n";
4176                                                               
4177                                                                if($object[ 'phone' ]){
4178                                                                        if(!$object[ 'home-phone' ])
4179                                                                                $stramArray[12] = "\"".$object[ 'phone' ]. "\"";
4180                                                                        else if(!$object[ 'mobile' ])
4181                                                                                $stramArray[4] = "\"".$object[ 'phone' ]. "\"";
4182                                                                        else if(!$object[ 'business-phone' ])
4183                                                                                $stramArray[5] = "\"".$object[ 'phone' ]. "\"";
4184                                                                }
4185                                               
4186                                                                $streamBuffer .= implode("," , $stramArray);
4187                            }
4188                        break;
4189                                       
4190                                        case 'outlook2003':
4191                                        $streamBuffer = "\"Tratamento\",\"Primeiro nome\",\"Segundo Nome\",\"Sobrenome\",\"Sufixo\",".
4192                                        "\"Empresa\",\"Departamento\",\"Cargo\",\"Business Street\",\"Rua do endereço comercial 2\",".
4193                                        "\"Rua do endereço comercial 3\",\"Business City\",\"Business State\",".
4194                                        "\"Business Postal Code\",\"Business Country\",\"Endereço residencial\",\"Endereço residencial 2\",".
4195                                        "\"Endereço residencial 3\",\"Cidade do endereço residencial\",\"Estado\",\"CEP do endereço residencial\",\"País do endereço residencial\",".
4196                                        "\"Outro endereço\",\"Outro endereço 2\",\"Outro endereço 3\",\"Cidade\",\"Estado\",\"CEP\",\"País\",".
4197                                        "\"Telefone do assistente\",\"Fax comercial\",\"Telefone comercial\",\"Telefone comercial 2\",\"Retorno de chamada\",".
4198                                        "\"Telefone do carro\",\"Telefone principal da empresa\",\"Fax residencial\",\"Telefone residencial\",".
4199                                        "\"Telefone residencial 2\",\"ISDN\",\"Telefone celular\",\"Outro fax\",\"Outro telefone\",\"Pager\",\"Telefone principal\",".
4200                                        "\"Radiofone\",\"Telefone TTY/TDD\",\"Telex\",\"Anotações\",\"Birthday\",\"Caixa postal de outro endereço\",\"Caixa postal do endereço comercial\",".
4201                                        "\"Caixa postal do endereço residencial\",\"Categorias\",\"Código da empresa\",\"Código do governo\",\"Conta\",\"Datas especiais\",\"Disponibilidade da internet\",\"E-mail Address\",".
4202                                        "\"Tipo de email\",\"Nome para exibição do email\",\"Endereço de email 2\",".
4203                                        "\"Tipo de email 2\",\"Nome para exibição do email 2\",".
4204                                        "\"Endereço de email 3\",\"Tipo de email 3\",\"Nome para exibição de email 3\",".
4205                                        "\"Filhos\",\"Hobby\",\"Idioma\",\"Indicação\",\"Informações para cobrança\",\"Iniciais\",\"Local\",".
4206                                        "\"Nome do assistente\",\"Nome do gerenciador\",\"Página da Web\",\"Palavras-chave\",\"Particular\",\"Personalizado 1\",\"Personalizado 2\",".
4207                                        "\"Personalizado 3\",\"Personalizado 4\",\"Prioridade\",\"Profissão\",\"Quilometragem\",\"Sala\",\"Sensibilidade\",\"Servidor de diretório\",".
4208                                        "\"Sexo\",\"Spouse\"\r\n";
4209                                        foreach($contacts as $index => $object){
4210                                                $stramArray[0] = "\"".$object[ 'alias' ] . "\"";
4211                                                $stramArray[1] = "\"".$object[ 'names_ordered'] . "\"";
4212                                                $stramArray[2] = "";
4213                                                $stramArray[3] = "";
4214                                                $stramArray[4] = "";                                                                                           
4215                                                $stramArray[5] = "\"".$object[ 'corporate_name' ] . "\"";                       
4216                                                $stramArray[6] = "\"".$object[ 'department' ] . "\"";
4217                                                $stramArray[7] = "\"".$object[ 'job_title' ] . "\"";                           
4218                                                $stramArray[8] = "\"".$object[ 'business-address' ] . "\"";
4219                                                $stramArray[9] = "\"".$object[ 'business-address-2' ] . "\"";
4220                                                $stramArray[10] = "";
4221                                                $stramArray[11] = "\"".$object[ 'business-city_name' ] . "\"";         
4222                                                $stramArray[12] = "\"".$object[ 'business-state_name' ] . "\"";         
4223                                                $stramArray[13] = "\"".$object[ 'business-postal_code' ] . "\"";       
4224                                                $stramArray[14] = "\"".$object[ 'business-id_country' ] . "\"";         
4225                                                $stramArray[15] = "\"".$object[ 'home-address' ] . "\"";                       
4226                                                $stramArray[16] = "\"".$object[ 'business-address-2' ] . "\"";         
4227                                                $stramArray[17] = "";                                                                                           
4228                                                $stramArray[18] = "\"".$object[ 'home-city_name' ] . "\"";
4229                                                $stramArray[19] = "\"".$object[ 'home-state_name' ] . "\"";
4230                                                $stramArray[20] = "\"".$object[ 'home-postal_code' ] . "\"";
4231                                                $stramArray[21] = "\"".$object[ 'home-id_country' ] . "\"";
4232                                                $stramArray[22] = "";
4233                                                $stramArray[23] = "";
4234                                                $stramArray[24] = "";
4235                                                $stramArray[25] = "\"".$object[ 'home-city_name' ] . "\"";
4236                                                $stramArray[26] = "\"".$object[ 'home-state_name' ] . "\"";
4237                                                $stramArray[27] = "\"".$object[ 'home-postal_code' ] . "\"";
4238                                                $stramArray[28] = "\"".$object[ 'home-id_country' ] . "\"";
4239                                                $stramArray[29] = "";
4240                                                $stramArray[30] = "\"".$object[ 'business-fax' ] . "\"";
4241                                                $stramArray[31] = "\"".$object[ 'business-phone' ] . "\"";
4242                                                $stramArray[32] = "\"".$object[ 'mobile' ] . "\"";
4243                                                $stramArray[33] = "";
4244                                                $stramArray[34] = "";
4245                                                $stramArray[35] = "";
4246                                                $stramArray[36] = "\"".$object[ 'home-fax' ] . "\"";
4247                                                $stramArray[37] = "\"".$object[ 'home-phone' ] . "\"";
4248                                                $stramArray[38] = "";
4249                                                $stramArray[39] = "";
4250                                                $stramArray[40] = "\"".$object[ 'mobile' ] . "\"";
4251                                                $stramArray[41] = "";
4252                                                $stramArray[42] = "";
4253                                                $stramArray[43] = "\"".$object[ 'home-pager' ] . "\"";
4254                                                $stramArray[44] = "\"".$object[ 'phone' ] . "\"";
4255                                                $stramArray[45] = "";
4256                                                $stramArray[46] = "";
4257                                                $stramArray[47] = "";
4258                                                $stramArray[48] = "\"".str_replace("\r\n\x0a","\t",$object[ 'notes' ]) . "\"";
4259                                                $stramArray[49] = "\"".$object[ 'birthdate' ] . "\"";
4260                                                $stramArray[50] = "";
4261                                                $stramArray[51] = "";
4262                                                $stramArray[52] = "";
4263                                                $stramArray[53] = "";
4264                                                $stramArray[54] = "";
4265                                                $stramArray[55] = "";
4266                                                $stramArray[56] = "";
4267                                                $stramArray[57] = "";
4268                                                $stramArray[58] = "";
4269                                                $stramArray[59] = "\"".$object[ 'main-mail' ] . "\"";
4270                                                $stramArray[60] = "";
4271                                                $stramArray[61] = "";
4272                                                $stramArray[62] = "\"".$object[ 'alternative-mail' ] . "\"";
4273                                                $stramArray[63] = "";
4274                                                $stramArray[64] = "";
4275                                                $stramArray[65] = "";
4276                                                $stramArray[66] = "";
4277                                                $stramArray[67] = "";
4278                                                $stramArray[68] = "";
4279                                                $stramArray[69] = "";
4280                                                $stramArray[70] = "";
4281                                                $stramArray[71] = "";
4282                                                $stramArray[72] = "";
4283                                                $stramArray[73] = "";
4284                                                $stramArray[74] = "";
4285                                                $stramArray[75] = "";
4286                                                $stramArray[76] = "";
4287                                                $stramArray[77] = "\"".$object[ 'web_page' ] . "\"";
4288                                                $stramArray[78] = "";
4289                                                $stramArray[79] = "";
4290                                                $stramArray[80] = "";
4291                                                $stramArray[81] = "";
4292                                                $stramArray[82] = "";
4293                                                $stramArray[83] = "";
4294                                                $stramArray[84] = "";
4295                                                $stramArray[85] = "";
4296                                                $stramArray[86] = "";
4297                                                $stramArray[87] = "";
4298                                                $stramArray[88] = "";
4299                                                $stramArray[89] = "";
4300                                                $stramArray[90] = "\"".$object[ 'sex' ] . "\"";
4301                                                $stramArray[91] = "\r\n";
4302                                               
4303                                                $streamBuffer .= implode("," , $stramArray);
4304                            }
4305                        break;
4306
4307                        }
4308
4309                        $file = "contacts_".md5(microtime()).".swp";
4310                        $tempDir = $GLOBALS['phpgw_info']['server']['temp_dir'];
4311                        $f = fopen($tempDir.'/'.$file,"w");
4312                        if(!$f)
4313                                echo null;
4314
4315                        fputs($f,$streamBuffer);
4316                        fclose($f);
4317
4318                        echo $tempDir.'/'.$file;
4319                }
4320
4321                // Get the csv field and put into array, from php.net
4322                function parse_line($input_text, $delimiter = ',', $text_qualifier = '"') {
4323                        $text = trim($input_text);
4324                          if(is_string($delimiter) && is_string($text_qualifier)) {
4325                         $re_d = '\x' . dechex(ord($delimiter));            //format for regexp
4326                        $re_tq = '\x' . dechex(ord($text_qualifier));    //format for regexp
4327
4328                        $fields = array();
4329                        $field_num = 0;
4330                        while(strlen($text) > 0) {
4331                        if($text{0} == $text_qualifier) {
4332                                preg_match('/^' . $re_tq . '((?:[^' . $re_tq . ']|(?<=\x5c)' . $re_tq . ')*)' . $re_tq . $re_d . '?(.*)$/', $text, $matches);
4333
4334                                $value = str_replace('\\' . $text_qualifier, $text_qualifier, $matches[1]);
4335                                $text = trim($matches[2]);
4336
4337                                $fields[$field_num++] = $value;
4338                        } else {
4339                                preg_match('/^([^' . $re_d . ']*)' . $re_d . '?(.*)$/', $text, $matches);
4340
4341                                $value = $matches[1];
4342                                $text = trim($matches[2]);
4343
4344                                $fields[$field_num++] = $value;
4345                }
4346                }
4347                        return $fields;
4348                    } else
4349                        return false;
4350                }
4351
4352                //funcao alterada para importar outros campos alem de nome, telefone e email, de arquivo csv (Outlook 2000)
4353                //em 08/04/2009 - Rommel Cysne (rommel.cysne@serpro.gov.br);
4354                //Foi adicionada uma funcao (escapesheelcmd()) nas variaveis para que caracteres especiais sejam ignorados
4355                //durante a importacao dos contatos; o processo estava travando por causa de caracteres em campos como nome,
4356                //sobrenome, notas e e-mail;
4357                //em 19/06/2009 - Rommel Cysne (rommel.cysne@serpro.gov.br);
4358                function import_contacts($typeImport, $id_group=false)
4359                {
4360                        $this->so_group = CreateObject('contactcenter.so_group');
4361                        if($file = $_SESSION['contactcenter']['importCSV'])
4362                        {
4363                                unset($_SESSION['contactcenter']['importCSV']);
4364                                $len = filesize($file);
4365                                $count = 0;
4366                                $return = array('error' => false, '_new' => 0, '_existing' => 0, '_failure' => 0);
4367                                $handle = @fopen($file, "r") or die(serialize($return['error'] = true));
4368
4369                                $input_header = fgets($handle);
4370                                if ($typeImport == 'outlook')
4371                                        $delim = ';';
4372                                else if ($typeImport == 'auto' || $typeImport== 'thunderbird')
4373                                $delim = strstr($input_header,',') ? ',' : ';';
4374                                else
4375                                        $delim = ',';
4376                                $csv_header = $this->parse_line($input_header,$delim);
4377                                $firstContact = fgets($handle);
4378                                preg_match("/\"(.+)\"[,;]/sU",$firstContact,$matches); // yahoo csv
4379                                rewind($handle);
4380
4381                                $header = @fgetcsv($handle, $len, $delim) or die(serialize($return['error'] = true));
4382                                if(count($header)  < 2 || count($header) > 100) {
4383                                        $return['error'] = true;
4384                                        $return['sizeheader'] = count($header);
4385                                        echo serialize($return);
4386                                        return;
4387                                }
4388
4389                                if ($matches[0][strlen($matches[0])-1] == ';')
4390                                        $delim = ';';
4391
4392                                $boGroup = CreateObject('contactcenter.bo_group');
4393                                $boPeople = CreateObject('contactcenter.bo_people_catalog');
4394                                        switch($typeImport){
4395                                                case 'outlook2000':
4396                                                        $name_pos=1;
4397                                                        $name2_pos=2;
4398                                                        $name3_pos=3;
4399                                                        $corporate_street_pos=8;
4400                                                        $cep_pos=13;
4401                                                        $corporate_street_2_pos=22;
4402                                                        $fax_pos=30;
4403                                                        $phone_pos=31;
4404                                                        $home_phone_pos=37;
4405                                                        $personal_cell_pos=40;
4406                                                        $pager_pos=43;
4407                                                        $birth_pos=48;
4408                                                        $notes_pos=49;
4409                                                        $email_pos=56;
4410                                                        $aditionalEmail_pos=59;
4411
4412                                                        break;
4413                                                case 'outlook':
4414                                                        $name_pos=0;
4415                                                        $email_pos=2;
4416                                                        $phone_pos=8;
4417                                                        $home_phone_pos=9;
4418                                                        $personal_cell_pos=10;
4419                                                        $corporate_street_pos=12;
4420                                                        $cep_pos=14;
4421                                                        $corporate_phone_pos=18;
4422                                                        $fax_pos=19;
4423                                                        $pager_pos=20;
4424                                                        $notes_pos=25;
4425                                                        break;
4426                                                case 'thunderbird':
4427                                                        $name_pos=2;
4428                                                        $alias_pos=3;
4429                                                        //MAILS
4430                                                        $email_pos=4;
4431                                                        $aditionalEmail_pos=5;
4432                                                       
4433                                                        //PHONES
4434                                                        $corporate_phone_pos=7;
4435                                                        $main_phone_pos=8;
4436                                                        $home_phone_pos=8;
4437                                                        $fax_pos=9;
4438                                                        $pager_pos=10;
4439                                                        $personal_cell_pos=11;
4440                                                       
4441                                                        //ADRESS
4442                                                        $street_pos=12;
4443                                                        $street_2_pos = 13;
4444                                                        $city_pos=14;
4445                                                        $state_pos=15;
4446                                                        $cep_pos=16;
4447                                                        $country_pos=17;
4448                                                       
4449                                                        //CORPORATE ADRESS
4450                                                        $corporate_street_pos=18;
4451                                                        $corporate_city_pos=20;
4452                                                        $corporate_state_pos=21;
4453                                                        $corporate_cep_pos=22;
4454                                                        $corporate_country_pos=23;
4455                                                       
4456                                                        //CORPORATE DETAILS
4457                                                        $job_title_pos=24;
4458                                                        $department_pos=25;
4459                                                        $corporate_name_pos=26;
4460                                                       
4461                                                        $notes_pos=36;
4462                                                        break;
4463                                                case 'outlook2003':
4464                                                        $alias_pos=0;
4465                                                        $name_pos=1;
4466                                                        //CORPORATE DETAILS
4467                                                        $corporate_name_pos=5;
4468                                                        $department_pos=6;
4469                                                        $job_title_pos=7;
4470                                                        //CORPORATE ADRESS
4471                                                        $corporate_comp_pos=7;
4472                                                        $corporate_street_pos=8;
4473                                                        $street_2_pos = 9;     
4474                                                        $corporate_city_pos=11;
4475                                                        $corporate_state_pos=12;
4476                                                        $corporate_cep_pos=13;
4477                                                        $corporate_country_pos=14;
4478                                                        //HOME ADRESS
4479                                                        $street_pos=13;
4480                                                        $comp_pos=14;
4481                                                        $cep_pos=15;
4482                                                        $city_pos=16;
4483                                                        $state_pos=17;
4484                                                        $country_pos=18;
4485                                                        //PHONE's
4486                                                        $corporate_phone_pos=31;
4487                                                        $fax_pos=36;
4488                                                        $home_phone_pos=37;
4489                                                        $pager_pos=43;
4490                                                        $main_phone_pos=44;
4491                                                        //OTHER's
4492                                                        $notes_pos=48;
4493                                                        $birth_pos=49;
4494                                                        //EMAIL's
4495                                                        $email_pos=59;
4496                                                        $aditionalEmail_pos=62;
4497                                                        break;
4498                                                case 'expresso':
4499                                                        $name_pos=0;
4500                                                        $alias_pos=1;
4501                                                        $email_pos=2;
4502                                                        $aditionalEmail_pos=3;
4503                                                        $personal_cell_pos=4;
4504                                                        $corporate_phone_pos=5;
4505                                                        $corporate_street_pos=6;
4506                                                        $corporate_comp_pos=7;
4507                                                        $corporate_cep_pos=8;
4508                                                        $corporate_city_pos=9;
4509                                                        $corporate_state_pos=10;
4510                                                        $corporate_country_pos=11;
4511                                                        $home_phone_pos=12;
4512                                                        $street_pos=13;
4513                                                        $comp_pos=14;
4514                                                        $cep_pos=15;
4515                                                        $city_pos=16;
4516                                                        $state_pos=17;
4517                                                        $country_pos=18;
4518                                                        $birth_pos=19;
4519                                                        $sex_pos = 20;
4520                                                        $pgp_key_pos = 21;
4521                                                        $notes_pos=22;
4522                                                        $web_page_pos=23;
4523                                                        $corporate_name_pos=24;
4524                                                        $job_title_pos=25;
4525                                                        $department_pos=26;
4526                                                        $corporate_fax_pos=27;
4527                                                        $corporate_pager_pos=28;
4528                                                        $corporate_cell_pos=29;
4529                                                        $fax_pos=30;
4530                                                        $pager_pos=31;
4531                                                        $corporate_street_2_pos = 32;
4532                                                        $street_2_pos = 33;                                             
4533                                                        break;
4534                                        default:
4535                                                        foreach($csv_header as $index => $fieldName)
4536                                                        {
4537                                                                switch($fieldName){
4538                                                                case 'Name':
4539                                                                case 'Nome':
4540                                                                case 'First Name':
4541                                                                        $name_pos = $index;
4542                                                                        break;
4543                                                                case 'Second name':
4544                                                                case 'Segundo nome':
4545                                                                        $name2_pos = $index;
4546                                                                        break;
4547                                                                case 'Sobrenome':
4548                                                                case 'Surname':
4549                                                                        $name3_pos = $index;
4550                                                                        break;
4551                                                                case 'Business Street':
4552                                                                case 'Rua do endereço comercial':
4553                                                                        $corporate_street_pos = $index;
4554                                                                        break;
4555                                                                case 'Rua do endereço comercial 2':
4556                                                                case 'Outro endereço':
4557                                                                        $corporate_street_2_pos = $index;
4558                                                                        break;
4559                                                                case 'Business Postal Code':
4560                                                                case 'CEP do endereço comercial':
4561                                                                        $cep_pos = $index;
4562                                                                        break;
4563                                                                case 'Business Fax':
4564                                                                case 'Fax comercial':
4565                                                                case 'Fax':
4566                                                                        $fax_pos = $index;
4567                                                                        break;
4568                                                                case 'Home Phone':
4569                                                                case 'Telefone residencial':
4570                                                                        $home_phone_pos = $index;
4571                                                                        break;
4572                                                                case 'Mobile phone':
4573                                                                case 'Telefone celular':
4574                                                                        $personal_cell_pos = $index;
4575                                                                        break;
4576                                                                case 'Pager':
4577                                                                        $pager_pos = $index;
4578                                                                        break;
4579                                                                case 'Phone':
4580                                                                case 'Business Phone':
4581                                                                case 'Telefone':
4582                                                                case 'Telefone principal':
4583                                                                case 'Telefone comercial':
4584                                                                case 'Telefone Comercial':                                                                   
4585                                                                        $phone_pos = $index;
4586                                                                        break;
4587                                                                case 'Aniversário':
4588                                                                case 'Birthdate':
4589                                                                        $birth_pos = $index;
4590                                                                case 'Anotações':
4591                                                                case 'Notes':
4592                                                                        $notes_pos = $index;
4593                                                                case 'E-mail':
4594                                                                case 'Email':
4595                                                                case 'E-mail Address':
4596                                                                case 'Endereço de correio eletrônico':
4597                                                                case 'End. de email':
4598                                                                        $email_pos = $index;
4599                                                                        break;
4600                                                                case 'Endereço de correio eletrônico 2':
4601                                                                        $aditionalEmail_pos = $index;
4602                                                                        break;
4603                                                                }
4604                                                        }
4605                                                        break;
4606                                }
4607
4608
4609               
4610                                while (($data = fgetcsv($handle, $len, $delim)))
4611                                {
4612                                        foreach ($header as $key=>$heading)
4613                                $row[$heading]=(isset($data[$key])) ? $data[$key] : '';
4614
4615                                                $sdata = array();
4616                                                $full_name               = addslashes(trim($row[$header[$name_pos]]));
4617                                                $email                       = addslashes(trim($row[$header[$email_pos]]));
4618                                                $phone                       = addslashes(trim($row[$header[$main_phone_pos]]));
4619                                                $name2                   = addslashes(trim($row[$header[$name2_pos]]));
4620                                                $name3                       = addslashes(trim($row[$header[$name3_pos]]));
4621                                                $birth                       = addslashes(trim($row[$header[$birth_pos]]));
4622                                                $notes                                   = addslashes(trim($row[$header[$notes_pos]]));
4623                                                $altEmail                                = addslashes(trim($row[$header[$altEmail_pos]]));
4624                                                $sdata['alias']          = addslashes(trim($row[$header[$alias_pos]]));
4625                                                $sdata['corporate_name'] = addslashes(trim($row[$header[$corporate_name_pos]]));
4626                                                $sdata['job_title']      = addslashes(trim($row[$header[$job_title_pos]]));
4627                                                $sdata['department']     = addslashes(trim($row[$header[$department_pos]]));
4628                                                $sdata['web_page']               = addslashes(trim($row[$header[$web_page_pos]]));
4629                                                $sdata['sex']            = addslashes(trim($row[$header[$sex_pos]]));
4630                                                $sdata['pgp_key']        = addslashes(trim($row[$header[$pgp_key_pos]]));
4631                                               
4632                                        $array_name = explode(' ', str_replace('"','',(str_replace('\'','',$full_name))));
4633                                        $sdata['given_names'] = addslashes($array_name[0]);
4634                                        $array_name[0] = null;
4635                                        $sdata['family_names'] = trim(implode(' ',$array_name));
4636                                        if($sdata['family_names'] == '')
4637                                        {
4638                                                $sdata['family_names'] = addslashes($name2) . " " . addslashes($name3);
4639                                        }
4640
4641                                                $sdata['connections']['default_email']['connection_name'] = lang('Main');
4642                                                $sdata['connections']['default_email']['connection_value'] = addslashes($email);
4643                                                $sdata['connections']['aditional_email']['connection_name'] = "Alternativo";
4644                                                $sdata['connections']['aditional_email']['connection_value'] = trim($row[$header[$aditionalEmail_pos]]);
4645
4646                                                $sdata['connections']['default_phone']['connection_name'] = lang('Main');
4647                                                $sdata['connections']['default_phone']['connection_value'] = $phone;
4648
4649                                                if( trim($row[$header[$home_phone_pos]]) != "" )
4650                                                {
4651                                                    $sdata['connections']['aditional_phone']['home_phone']['connection_name'] = 'Casa';
4652                                                    $sdata['connections']['aditional_phone']['home_phone']['connection_value'] = trim($row[$header[$home_phone_pos]]);
4653                                                }
4654
4655                                                if( trim($row[$header[$personal_cell_pos]]) != "" )
4656                                                {
4657                                                    $sdata['connections']['aditional_phone']['cellphone']['connection_name'] = 'Celular';
4658                                                    $sdata['connections']['aditional_phone']['cellphone']['connection_value'] = trim($row[$header[$personal_cell_pos]]);
4659                                                }
4660
4661                                                if( trim($row[$header[$corporate_phone_pos]]) != "")
4662                                                {
4663                                                    $sdata['connections']['aditional_phone']['corporate_phone']['connection_name'] = 'Trabalho';
4664                                                    $sdata['connections']['aditional_phone']['corporate_phone']['connection_value'] = trim($row[$header[$corporate_phone_pos]]);
4665                                                }
4666
4667                                                if( trim($row[$header[$fax_pos]]) != "" )
4668                                                {
4669                                                    $sdata['connections']['aditional_phone']['fax']['connection_name'] = 'Fax';
4670                                                    $sdata['connections']['aditional_phone']['fax']['connection_value'] = trim($row[$header[$fax_pos]]);
4671                                                }
4672
4673                                                if ($GLOBALS['phpgw_info']['server']['personal_contact_type'] == 'True')
4674                                                {
4675                                                    if( trim($row[$header[$pager_pos]]) != "" )
4676                                                    {
4677                                                        $sdata['connections']['aditional_phone']['pager']['connection_name'] = 'Pager';
4678                                                        $sdata['connections']['aditional_phone']['pager']['connection_value'] = trim($row[$header[$pager_pos]]);
4679                                                    }
4680
4681                                                    if( trim($row[$header[$corporate_fax_pos]]) != "" )
4682                                                    {
4683                                                        $sdata['connections']['aditional_phone']['corporate_fax']['connection_name'] = 'Fax Corporativo';
4684                                                        $sdata['connections']['aditional_phone']['corporate_fax']['connection_value'] = trim($row[$header[$corporate_fax_pos]]);
4685                                                    }
4686
4687                                                    if( trim($row[$header[$corporate_cell_pos]]) != "" )
4688                                                    {
4689                                                        $sdata['connections']['aditional_phone']['corporate_cell']['connection_name'] = 'Celular Corporativo';
4690                                                        $sdata['connections']['aditional_phone']['corporate_cell']['connection_value'] = trim($row[$header[$corporate_cell_pos]]);
4691                                                    }
4692
4693                                                    if( trim($row[$header[$corporate_pager_pos]]) != "" )
4694                                                    {
4695                                                        $sdata['connections']['aditional_phone']['corporate_pager']['connection_name'] = 'Pager Corporativo';
4696                                                        $sdata['connections']['aditional_phone']['corporate_pager']['connection_value'] = trim($row[$header[$corporate_pager_pos]]);
4697                                                    }
4698                                                }
4699
4700                                                $sdata['addresses']['address_corporative']['address1'] = trim($row[$header[$corporate_street_pos]]);
4701                                                $sdata['addresses']['address_corporative']['address2'] = trim($row[$header[$corporate_street_2_pos]]);
4702                                                $sdata['addresses']['address_corporative']['complement'] = trim($row[$header[$corporate_comp_pos]]);
4703                                                $sdata['addresses']['address_corporative']['postal_code'] = trim($row[$header[$corporate_cep_pos]]);
4704                                                $sdata['addresses']['address_corporative']['id_country'] = "BR";
4705                                                $sdata['addresses']['address_corporative']['id_state'] = trim($row[$header[$corporate_state_pos]]);
4706                                                $sdata['addresses']['address_corporative']['id_city'] = trim($row[$header[$corporate_city_pos]]);
4707
4708
4709                                                $sdata['addresses']['address_personal']['address1'] = trim($row[$header[$street_pos]]);
4710                                                $sdata['addresses']['address_personal']['address2'] = trim($row[$header[$street_2_pos]]);
4711                                                $sdata['addresses']['address_personal']['complement'] = trim($row[$header[$comp_pos]]);
4712                                                $sdata['addresses']['address_personal']['postal_code'] = trim($row[$header[$cep_pos]]);
4713                                                $sdata['addresses']['address_personal']['id_country'] = "BR";
4714                                                $sdata['addresses']['address_personal']['id_state'] = trim($row[$header[$state_pos]]);
4715                                                $sdata['addresses']['address_personal']['id_city'] =  trim($row[$header[$city_pos]]);
4716
4717                                        if(trim($birth))
4718                                        {
4719                                                $array_birth = explode("/",trim($birth));
4720                                                $sdata['birthdate'] = date('Y-m-d', mktime(0,0,0,$array_birth[1],$array_birth[0],$array_birth[2]));
4721                                        }
4722
4723                                        $sdata['notes'] = addslashes($notes);
4724                                        //$sdata['is_quick_add'] = true;
4725                                        $sdata['connections']['default_phone']['connection_value'] = $phone;
4726                                        if(!$phone){
4727
4728                                        }
4729                                        //      verifica se email já existe!
4730                                        $email = addslashes($email);
4731                                        $contact = false;
4732                                        $contact = $boGroup->verify_contact($email, $full_name, $phone);
4733                                        if(!$sdata['given_names'] && $email)
4734                                        {
4735                                                        $a_email = explode("@",$email);
4736                                                        $sdata['given_names'] = addslashes($a_email[0]);
4737                                        }
4738
4739                                        $line_iteration = $return['_failure'] + $return['_existing'] + $return['_new'];
4740
4741                                        if($contact[0] != null)
4742                                        {
4743                                                $return['_existing']++;
4744                                        }
4745                                        else if((!eregi("^[a-zA-Z0-9][_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]{1,})*$", $email)) && $email) {
4746                                                $return['_failure']++;
4747                                                $return['_failure_status'] .= "Line: " . ($line_iteration + 2) . ", Invalid E-Mail address: " . $email ."<br>";
4748                                        }
4749                                        else if (!$sdata['given_names'] || !$boPeople ->quick_add($sdata)){
4750                                                $return['_failure']++;
4751                                                $return['_failure_status'] .= "Line: " . ($line_iteration + 2) . ", Invalid Name: " . $sdata['given_names'] ."<br>";
4752                                        }
4753                                        else{
4754                                                        if($id_group != 0){
4755                                                                $this->so_group->add_user_by_name($id_group,$full_name);
4756                                                        }
4757                                                        $return['_new']++;
4758                                                }
4759                        }
4760                                fclose($handle);
4761                                unlink($file);
4762                        }
4763                        else
4764                                $return['error'] = true;
4765
4766                        echo serialize($return);
4767                }
4768               
4769                function get_contact_details($id)
4770                {
4771                        $data = array();
4772                       
4773                        if(!$this->bo->catalog->src_info) {
4774                                $ldap = CreateObject('contactcenter.bo_ldap_manager');
4775                                $this->bo->catalog->src_info = $ldap->srcs[1];
4776                        }
4777                        //$id = urlencode($id);
4778                        $ds = $GLOBALS['phpgw']->common->ldapConnect($this->bo->catalog->src_info['host'], $this->bo->catalog->src_info['acc'], $this->bo->catalog->src_info['pw'], true);                             
4779                        $dn=$this->bo->catalog->src_info['dn'];
4780
4781                        //buscar os atributos do ldap
4782                        $configobj = CreateObject('phpgwapi.config', 'contactcenter');
4783                        $prefs = $configobj->read_repository();
4784                        $attr_names = array();
4785                        $attr_types = array();
4786                        $justThese = array();
4787                        foreach ($prefs as $pref_key => $pref_value)
4788                        {
4789                                if (stripos($pref_key, "cc_attribute_name_") !== false)
4790                                {
4791                                        $num = substr($pref_key, strlen("cc_attribute_name_"));
4792                                        $attr_names[] = $prefs["cc_attribute_name_$num"];
4793                                        $attr_types[] = $prefs["cc_attribute_type_$num"];
4794                                        $justThese[] = strtolower($prefs["cc_attribute_ldapname_$num"]);
4795                                }
4796                        }
4797                       
4798
4799
4800                        $sr = ldap_read($ds,utf8_encode($id), "objectClass=*",$justThese);                                                     
4801                        $info = ldap_get_entries($ds, $sr);
4802                        if ($info)
4803                        {
4804                                for ($i = 0; $i < count($justThese); $i++)
4805                                {
4806                                        $attr = array();
4807                                        $attr['name'] = $attr_names[$i];
4808                                        if ($attr_types[$i] == 'multivalues')
4809                                        {
4810                                                $attr['type'] = 'multivalues';
4811                                                $attr['value'] = array();
4812                                                for ($j = 0; $j < $info[0][$justThese[$i]]['count']; $j++)
4813                                                        $attr['value'][] = utf8_decode($info[0][$justThese[$i]][$j]);
4814                                        }
4815                                        else
4816                                        {
4817                                                $attr['type'] = 'text';
4818                                                $attr['value'] = utf8_decode($info[0][$justThese[$i]][0]);
4819                                        }
4820                                        $data[] = $attr;
4821                                }
4822                        }
4823                        else
4824                                $data = 'error';
4825                        ldap_close($ds);
4826                       
4827                        echo serialize($data);
4828                }
4829               
4830        }
4831
4832?>
Note: See TracBrowser for help on using the repository browser.