source: branches/2.2/contactcenter/inc/class.ui_data.inc.php @ 3335

Revision 3335, 133.0 KB checked in by eduardoalex, 14 years ago (diff)

Ticket #1236 - Corrigida a forma de carregar o combo contendo os usuarios para adicao compartilhada

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