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

Revision 3420, 133.2 KB checked in by rafaelraymundo, 14 years ago (diff)

Ticket #1384 - Classificação catálogo ContactCenter?

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1<?php
2  /***************************************************************************\
3  * eGroupWare - Contacts Center                                              *
4  * http://www.egroupware.org                                                 *
5  * Written by:                                                               *
6  *  - Raphael Derosso Pereira <raphaelpereira@users.sourceforge.net>         *
7  *  - Jonas Goes <jqhcb@users.sourceforge.net>                               *
8  *  sponsored by Thyamad - http://www.thyamad.com                            *
9  * ------------------------------------------------------------------------- *
10  *  This program is free software; you can redistribute it and/or modify it  *
11  *  under the terms of the GNU General Public License as published by the    *
12  *  Free Software Foundation; either version 2 of the License, or (at your   *
13  *  option) any later version.                                               *
14  \***************************************************************************/
15
16
17        class ui_data
18        {
19                var $public_functions = array(
20                        'data_manager' => true,
21                );
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_catalog_group_catalog':
865                                        case 'bo_global_ldap_catalog':
866
867                                                $field_name = 'id_contact';
868
869                                                if ($letter !== 'number')
870                                                {
871                                                        $find_restric[0] = array(
872                                                                0 => array(
873                                                                        'field' => 'contact.names_ordered',
874                                                                        'type'  => 'iLIKE',
875                                                                        'value' => $letter !== 'all' ? $letter.'%' : '%'
876                                                                ),
877                                                                /*
878                                                                 * Restrict the returned contacts in a "first letter" search
879/**rev 104
880                                                                 * to objectClass = phpgwAccount, must have attibute phpgwAccountStatus,
881                                                                 * phpgwAccountVisible != -1
882                                                                 */
883                                                                1 => array(
884                                                                        'field' => 'contact.object_class',
885                                                                        'type'  => '=',
886                                                                        'value' => 'phpgwAccount'
887/**rev 104**/
888                                                                //),/*
889                                                                ),
890/****/
891                                                                2 => array(
892                                                                        'field' => 'contact.account_status',
893                                                                        'type'  => 'iLIKE',
894                                                                        'value' => '%'
895/**rev 104**/
896                                                                //),*/
897                                                                //2 => array(
898                                                                ),
899                                                                3 => array(
900/*****/
901                                                                        'field' => 'contact.account_visible',
902                                                                        'type'  => '!=',
903                                                                        'value' => '-1'
904/**rev 104**/
905        /*                                                      ),
906                                                                3 => array(
907                                                                        'field' => 'contact.object_class',
908                                                                        'type'  => '=',
909                                                                        'value' => 'inetOrgPerson'
910                                                                ),
911        */
912                                                                )
913/*****/
914
915                                                        );
916                                                        // If not external catalog get only phpgwAccountType = u ou l
917                                                        if (!$external)
918                                                        {
919                                                                $find_restric[0][5] =  array(
920                                                                                'type'  => 'branch',
921                                                                                'value' => 'OR',
922                                                                                'sub_branch' => array(
923                                                                                        0 => array(
924                                                                                        'field' => 'contact.account_type',
925                                                                                        'type'  => '=',
926                                                                                        'value' => 'u'
927                                                                                        ),
928                                                                                        1 => array(
929                                                                                        'field' => 'contact.account_type',
930                                                                                        'type'  => '=',
931                                                                                        'value' => 'i'
932/**rev 104**/
933                                                                                        ),
934                                                                                        2 => array(
935                                                                                        'field' => 'contact.account_type',
936                                                                                        'type'  => '=',
937/****/
938                                                                                        'value' => 'l'
939/**rev 104**/
940                                                                                        ),
941                                                                                        3 => array(
942                                                                                        'field' => 'contact.account_type',
943                                                                                        'type'  => '=',
944                                                                                        'value' => 'g'
945/***/
946                                                                                        )
947                                                                                )
948                                                                );
949                                                        }
950                                                }
951                                                else
952                                                {
953                                                        $find_restric[0] = array(
954                                                                /*
955                                                                 * Restrict the returned contacts in a "first number" search
956/**rev 104
957                                                                 * to objectClass = phpgwAccount, must have attibute phpgwAccountStatus,
958                                                                 * phpgwAccountVisible != -1
959                                                                 */
960                                                                0 => array(
961                                                                        'field' => 'contact.object_class',
962                                                                        'type'  => '=',
963                                                                        'value' => 'phpgwAccount'
964/**rev 104**/
965                                                                //),/*
966                                                                ),
967/****/
968                                                                1 => array(
969                                                                        'field' => 'contact.account_status',
970                                                                        'type'  => 'iLIKE',
971                                                                        'value' => '%'
972/**rev 104**/
973                                                                //),*/
974                                                                //1 => array(
975                                                                ),
976                                                                2 => array(
977/*****/
978                                                                        'field' => 'contact.account_visible',
979                                                                        'type'  => '!=',
980                                                                        'value' => '-1'
981                                                                ),
982/**rev 104**/
983        /*                                                      2 => array(
984                                                                        'field' => 'contact.object_class',
985                                                                        'type'  => '=',
986                                                                        'value' => 'inetOrgPerson'
987                                                                ),
988        */
989/****/
990                                                                3 => array(
991                                                                        'type'  => 'branch',
992                                                                        'value' => 'OR',
993                                                                        'sub_branch' => array(
994                                                                                0 => array(
995                                                                                        'field' => 'contact.names_ordered',
996                                                                                        'type'  => 'LIKE',
997                                                                                        'value' => '0%'
998                                                                                ),
999                                                                                1 => array(
1000                                                                                        'field' => 'contact.names_ordered',
1001                                                                                        'type'  => 'LIKE',
1002                                                                                        'value' => '1%'
1003                                                                                ),
1004                                                                                2 => array(
1005                                                                                        'field' => 'contact.names_ordered',
1006                                                                                        'type'  => 'LIKE',
1007                                                                                        'value' => '2%'
1008                                                                                ),
1009                                                                                3 => array(
1010                                                                                        'field' => 'contact.names_ordered',
1011                                                                                        'type'  => 'LIKE',
1012                                                                                        'value' => '3%'
1013                                                                                ),
1014                                                                                4 => array(
1015                                                                                        'field' => 'contact.names_ordered',
1016                                                                                        'type'  => 'LIKE',
1017                                                                                        'value' => '4%'
1018                                                                                ),
1019                                                                                5 => array(
1020                                                                                        'field' => 'contact.names_ordered',
1021                                                                                        'type'  => 'LIKE',
1022                                                                                        'value' => '5%'
1023                                                                                ),
1024                                                                                6 => array(
1025                                                                                        'field' => 'contact.names_ordered',
1026                                                                                        'type'  => 'LIKE',
1027                                                                                        'value' => '6%'
1028                                                                                ),
1029                                                                                7 => array(
1030                                                                                        'field' => 'contact.names_ordered',
1031                                                                                        'type'  => 'LIKE',
1032                                                                                        'value' => '7%'
1033                                                                                ),
1034                                                                                8 => array(
1035                                                                                        'field' => 'contact.names_ordered',
1036                                                                                        'type'  => 'LIKE',
1037                                                                                        'value' => '8%'
1038                                                                                ),
1039                                                                                9 => array(
1040                                                                                        'field' => 'contact.names_ordered',
1041                                                                                        'type'  => 'LIKE',
1042                                                                                        'value' => '9%'
1043                                                                                ),
1044                                                                        ),
1045                                                                ),
1046                                                        );
1047                                                        // If not external catalog get only phpgwAccountType = u ou l
1048                                                        if (!$external)
1049                                                        {
1050                                                                $find_restric[0][5] =  array(
1051                                                                        'type'  => 'branch',
1052                                                                        'value' => 'OR',
1053                                                                        'sub_branch' => array(
1054                                                                                0 => array(
1055                                                                                'field' => 'contact.account_type',
1056                                                                                'type'  => '=',
1057                                                                                'value' => 'u'
1058                                                                                ),
1059                                                                                1 => array(
1060                                                                                'field' => 'contact.account_type',
1061                                                                                'type'  => '=',
1062/**rev 104**/
1063                                                                                //'value' => 'g'
1064                                                                                //);
1065                                                                                //1 => array(
1066                                                                                'value' => 'i'
1067                                                                                ),
1068                                                                                2 => array(
1069/****/
1070                                                                                'field' => 'contact.account_type',
1071                                                                                'type'  => '=',
1072                                                                                'value' => 'l'
1073/**rev 104**/
1074                                                                                ),
1075                                                                                3 => array(
1076                                                                                'field' => 'contact.account_type',
1077                                                                                'type'  => '=',
1078                                                                                'value' => 'g'
1079                                                                                )
1080/****/
1081                                                                        )
1082                                                                );
1083                                                        }
1084                                                }
1085
1086                                                if (!$external)
1087                                                {
1088                                                        // Get only this attributes: dn, cn, phpgwAccountType, objectClass, phpgwAccountStatus, phpghAccountVisible
1089                                                        // for non-external catalogs, used to restrict the attributes used in filters
1090                                                        $find_field[0] = array('contact.id_contact','contact.names_ordered','contact.account_type',
1091                                                                'contact.object_class','contact.account_visible');
1092                                                }
1093                                                else
1094                                                {
1095                                                        // Get only this attributes: dn, cn for external catalogs,
1096                                                        // used to restrict the attributes used in filters
1097                                                        $find_field[0] = array('contact.id_contact','contact.names_ordered');
1098                                                }
1099
1100                                                $find_other[0] = array(
1101                                                        //'offset' => (($page-1)*$this->page_info['n_cards']),
1102                                                        //'limit'  => $this->page_info['n_cards'],
1103                                                        'order'  => 'contact.names_ordered'
1104                                                );
1105
1106                                                break;
1107
1108                                        case 'bo_company_manager':
1109                                                $field_name = 'id_company';
1110
1111                                                $find_field[0] = array('company.id_company','company.company_name');
1112
1113                                                $find_other[0] = array(
1114                                                        //'offset' => (($page-1)*$this->page_info['n_cards']),
1115                                                        //'limit'  => $this->page_info['n_cards'],
1116                                                        'order'  => 'company.company_name'
1117                                                );
1118
1119                                                $find_restric[0] = array(
1120                                                        0 => array(
1121                                                                'field' => 'company.company_name',
1122                                                                'type'  => 'iLIKE',
1123                                                                'value' => $letter !== 'all' ? $letter.'%' : '%'
1124                                                        )
1125                                                );
1126
1127                                                break;
1128
1129                                        case 'bo_group_manager':
1130/**rev 104**/
1131                                        case 'bo_shared_group_manager':
1132/****/
1133
1134                                                $field_name = 'id_group';
1135
1136                                                if ($letter !== 'number')       {
1137
1138                                                        $find_restric[0] = array(
1139                                                                0 => array(
1140                                                                        'field' => 'group.title',
1141                                                                        'type'  => 'iLIKE',
1142                                                                        'value' => $letter !== 'all' ? $letter.'%' : '%'
1143                                                                )
1144                                                        );
1145                                                }
1146                                                 else {
1147
1148                                                        $find_restric[0] = array(
1149                                                                0 => array(
1150                                                                                        'field' => 'group.title',
1151                                                                                        'type'  => 'LIKE',
1152                                                                                        'value' => '0%'
1153                                                                )
1154                                                        );
1155                                                }
1156/**rev 104**/
1157                                                if($this->page_info['actual_catalog']['class'] == 'bo_group_manager'){
1158/****/
1159                                                        array_push($find_restric[0],  array(
1160                                                                                        'field' => 'group.owner',
1161                                                                                        'type'  => '=',
1162                                                                                        'value' => $GLOBALS['phpgw_info']['user']['account_id']
1163                                                                        )
1164                                                        );
1165                                                }
1166
1167                                                $find_field[0] = array('group.id_group','group.title','group.short_name');
1168                                                $find_other[0] = array(
1169                                                        'order'  => 'group.title'
1170                                                );
1171                                                break;
1172
1173                                        /*case 'bo_catalog_group_catalog':
1174                                                $this->page_info['actual_entries'] = false;
1175
1176                                                $this->page_info['actual_letter'] = $letter;
1177                                                $this->page_info['actual_page'] = 0;
1178
1179                                                $this->save_session();
1180                                                $final[0] = 0;
1181                                                $final[1] = $this->typeContact;
1182                                                echo serialize($final);
1183                                                return;*/
1184
1185                                }
1186
1187                                $result = $this->bo->find($find_field[0],$find_restric[0],$find_other[0]);
1188                                $n_entries = count($result);
1189
1190                                if ($n_entries)
1191                                {
1192                                        //echo 'N_entries: '.$n_entries.'<br>';
1193                                        $this->page_info['n_pages'] = ceil($n_entries/($this->page_info['n_cards'] ? $this->page_info['n_cards'] : 1));
1194                                }
1195                                else
1196                                {
1197                                        $this->page_info['n_pages'] = 0;
1198                                }
1199
1200                                if (!$result)
1201                                {
1202                                        $this->page_info['actual_entries'] = false;
1203
1204                                        $this->page_info['actual_letter'] = $letter;
1205                                        $this->page_info['actual_page'] = 0;
1206
1207                                        $this->save_session();
1208                                        $final[0] = 0;
1209                                        $final[1] = $this->typeContact;
1210                                        echo serialize($final);
1211                                        return;
1212                                }
1213                                else
1214                                {
1215                                        unset($this->page_info['actual_entries']);
1216                                        if(is_array($result)) {
1217                                                foreach ($result as $id => $value)
1218                                                {
1219                                                        if($this->page_info['actual_catalog']['class'] != 'bo_shared_people_manager' && $this->page_info['actual_catalog']['class'] != 'bo_shared_group_manager')
1220                                                                $this->page_info['actual_entries'][] = $value[$field_name];
1221                                                        else
1222                                                                $this->page_info['actual_entries'][] = array(0=>$value[$field_name],1=>$value['perms'],2=>$value['owner']);
1223                                                }
1224                                        }
1225                                }
1226                        }
1227                        else if ($letter === 'search')
1228                        {
1229                                //if (!$ids and $this->page_info['actual_letter'] !== 'search')
1230                                if (!$ids)
1231                                {
1232/**rev 104**/
1233                                        //error_log('!$ids e $this->page_info[\'actual_letter\'] != search');
1234/*****/
1235                                        $this->page_info['actual_entries'] = false;
1236
1237                                        $this->page_info['actual_letter'] = $letter;
1238                                        $this->page_info['actual_page'] = 0;
1239
1240                                        $this->save_session();
1241                                        $final[0] = 0;
1242                                        $final[1] = $this -> typeContact;
1243                                        echo serialize($final);
1244                                        return;
1245                                }
1246                                else if ($ids['error'])
1247                                {
1248                                        $this->page_info['actual_entries'] = false;
1249                                        $this->page_info['actual_letter'] = $letter;
1250                                        $this->page_info['actual_page'] = 0;
1251
1252                                        $this->save_session();
1253                                        $final[0] = 0;
1254                                        $final[1] = $this -> typeContact;
1255                                        $final['error'] = $ids['error'];
1256                                        echo serialize($final);
1257                                        return;
1258                                }
1259                                else if ($ids)
1260                                {
1261                                        $this->page_info['actual_letter']  = $letter;
1262                                        $this->page_info['actual_entries'] = $ids;
1263                                        $this->page_info['n_pages'] = ceil(count($ids)/($this->page_info['n_cards'] ? $this->page_info['n_cards'] : 1));
1264                                }
1265                        }
1266                        else
1267                        {
1268                                unset($ids);
1269                        }
1270
1271                        if ($this->page_info['actual_entries'])
1272                        {
1273                                if ($page >= $this->page_info['n_pages'])
1274                                {
1275                                        $page = $this->page_info['n_pages'];
1276                                }
1277
1278                                $final = array(
1279                                        0 => (int)$this->page_info['n_pages'],
1280                                        1 => (int)$page,
1281                                        2 => array(
1282                                                0 => 'cc_company',
1283                                                1 => 'cc_name',
1284                                                2 => 'cc_title',
1285                                                3 => 'cc_phone',
1286                                                4 => 'cc_mail',
1287                                                5 => 'cc_alias',
1288                                                6 => 'cc_id',
1289                                                7 => 'cc_forwarding_address',
1290                                                8 => 'cc_empNumber',
1291                                                9 => 'cc_department',
1292                                                10 => 'cc_mobile'
1293                                        )
1294                                );
1295
1296                                //echo 'Page: '.$page.'<br>';
1297                                $id_i = (($page-1)*$this->page_info['n_cards']);
1298                                $id_f = $id_i + $this->page_info['n_cards'];
1299                                $n_entries = count($this->page_info['actual_entries']);
1300
1301                                //echo 'ID_I: '.$id_i.'<br>';
1302                                //echo 'ID_F: '.$id_f.'<br>';
1303                                ///---------------- Correção Temporária PHP5 -----------------------///
1304                                $ids = array();
1305/**rev 104**/
1306                                $perms = array();
1307                                $owners = array();
1308/****/
1309                                $array_temp = array();
1310
1311                                foreach($this->page_info['actual_entries'] as $key=>$tmp){
1312                                        $array_temp[] = $tmp;
1313                                }
1314
1315                                for($i = $id_i; $i < $id_f and $i < $n_entries; $i++)
1316                                {
1317/**rev 104**/
1318                                        if($this->page_info['actual_catalog']['class'] != 'bo_shared_people_manager' && $this->page_info['actual_catalog']['class'] != 'bo_shared_group_manager')
1319                                        {
1320/****/
1321                                                $ids[] = $array_temp[$i];
1322/**rev 104**/
1323                                        }else {
1324                                                $ids[] = $array_temp[$i][0];
1325                                                $perms[] = $array_temp[$i][1];
1326                                                $owners[] = $array_temp[$i][2];
1327/****/
1328                                        }
1329                                }
1330
1331/**rev 104**/
1332                                // Carrega o nome completo dos donos dos objetos (contatos e grupos);
1333                                $owner_names = array();
1334
1335                                if($owners) {
1336                                        $filter = "(|";
1337                                        foreach($owners as $i => $owner) {
1338                                                $filter .= "(uidNumber=".$owner.")";
1339                                        }
1340                                        $filter .= ")";
1341
1342                                        if(!$this->bo->catalog->src_info) {
1343                                                $ldap = CreateObject('contactcenter.bo_ldap_manager');
1344                                                $this->bo->catalog->src_info = $ldap->srcs[1];
1345                                        }
1346                                        $ds = $GLOBALS['phpgw']->common->ldapConnect($this->bo->catalog->src_info['host'], $this->bo->catalog->src_info['acc'], $this->bo->catalog->src_info['pw'], false);
1347                                        $dn=$this->bo->catalog->src_info['dn'];
1348                                        $justThese = array("cn","uidnumber","uid");
1349                                        $sr = ldap_search($ds,$dn, $filter,$justThese);
1350                                        $info = ldap_get_entries($ds, $sr);
1351                                        ldap_close($ds);
1352                                        for($z = 0; $z < $info['count']; $z++) {
1353                                                $owner_names[$info[$z]['uidnumber'][0]] = array("cn" => $info[$z]['cn'][0], "uid" => $info[$z]['uid'][0]);
1354                                        }
1355                                }
1356
1357/*****/
1358
1359
1360                                /// Original
1361                                //for($i = $id_i; $i < $id_f and $i < $n_entries; $i++)
1362                                //{
1363                                //      $ids[] = $this->page_info['actual_entries'][$i];
1364                                //}
1365                                ///
1366
1367                                $fields = $this->bo->catalog->get_fields(false);
1368/**rev 104**/
1369                                //if( $this->typeContact == 'groups') {
1370                                if( $this->typeContact == 'groups' || $this->typeContact == 'shared_groups') {
1371/****/
1372                                        $final = array(
1373                                                0 => (int)$this->page_info['n_pages'],
1374                                                1 => (int)$page,
1375                                                2 => array(
1376                                                        0 => 'cc_title',
1377                                                        1 => 'cc_short_name',
1378                                                        2 => 'cc_id',
1379                                                        3 => 'cc_contacts'
1380                                                )
1381                                        );
1382
1383                                        $groups =& $this->bo->catalog->get_multiple_entries($ids,$fields);
1384
1385                                        $i = 0;
1386                                        // contatos do grupo
1387                                        $boGroups = CreateObject('contactcenter.bo_group');
1388                                        $contacts = array();
1389                                        foreach($groups as $group)              {
1390
1391                                                $final[3][$i][0] = $group['title'] ? $group['title'] : 'none';
1392                                                $final[3][$i][1] = $group['short_name'] ? $group['short_name'] : 'none';
1393                                                $final[3][$i][2] = $group['id_group'] ? $group['id_group'] : 'none';
1394                                                $contacts = $boGroups -> get_contacts_by_group($group['id_group']);
1395                                                $final[3][$i][3] = $contacts;
1396                                                $final[3][$i][4] = $perms[$i];
1397                                                if($this->typeContact == 'shared_groups'){
1398                                                        $final[3][$i][5] = lang('Shared').": ".$owner_names[$owners[$i]]['cn'];
1399                                                        $final[3][$i][6] = $owner_names[$owners[$i]]['uid'];
1400                                                        $final[3][$i][7] = $owners[$i]; //uidNumber
1401                                                }                                               
1402                                                $i++;                                                   
1403                                        }
1404
1405                                        $this->page_info['actual_letter'] = $letter;
1406                                        $this->page_info['actual_page'] = $page;
1407
1408
1409                                        $lnk_compose = "location.href=('../expressoMail1_2/index.php?to=";
1410
1411                                        $final[5] = '<span class="link"  onclick="'.$lnk_compose;
1412/**rev 104**/
1413                                        //$final[10] = 'groups';
1414                                        $final[10] = $this->typeContact;
1415/******/
1416                                        $this->save_session();
1417                                        echo serialize($final);
1418                                        return;
1419                                }
1420/**rev 104**/
1421                                $final[10] = $this -> typeContact;
1422/*****/
1423
1424                                $fields['photo'] = true;
1425                                $fields['names_ordered'] = true;
1426                                $fields['alias'] = true;
1427                                $fields['account_type'] = true;
1428                                $fields['companies'] = 'default';
1429                                $fields['connections'] = 'default';
1430
1431/**rev 104**/
1432                                // ?aqui alterar a chamada desse método para receber o base dn?
1433                                //$contacts = &$this->bo->catalog->get_multiple_entries($ids,$fields);
1434
1435                                // ?aqui alterar a chamada desse método para receber o base dn?
1436                                if($external)
1437                                {
1438                                        $contacts = &$this->bo->catalog->get_multiple_entries($ids,$fields,false,true);
1439                                } else{
1440                                        $contacts = &$this->bo->catalog->get_multiple_entries($ids,$fields);
1441                                }
1442
1443/*******/
1444
1445
1446                                if (!is_array($contacts) or !count($contacts))
1447                                {
1448                                        $final[0] = 0;
1449                                        $final[1] = $this -> typeContact;
1450                                        echo serialize($final);
1451                                        return;
1452                                }
1453
1454                                $i = 0;
1455                                foreach($contacts as $index => $contact)
1456                                {
1457                                        /*
1458                                         * TODO: Os timeouts de conexão foram retirados, ver se será necessário retornar essa funcionalidade, e,
1459                                         * neste caso, terminar a implementação das mensagens de retorno.
1460                                         */
1461                                        if ($index !== 'error'){
1462                                                $final[3][$i][0] = $contact['companies']['company1']['company_name']?$contact['companies']['company1']['company_name']:'none';
1463
1464/**rev 104**/
1465                                                //$final[3][$i][1] = $contact['names_ordered'] ? $contact['names_ordered'] : 'none';
1466
1467                                                if($this->page_info['actual_catalog']['class']!='bo_global_ldap_catalog'){
1468                                                        $final[3][$i][1] = $contact['names_ordered'] ? urldecode(is_array($contact['names_ordered']) ? $contact['names_ordered'][0] : $contact['names_ordered'])  : 'none';
1469                                                }
1470                                                else {
1471                                                        $contact['names_ordered'][0] = urldecode($contact['names_ordered'][0]);
1472                                                        $final[3][$i][1] = $contact['names_ordered'] ? $contact['names_ordered']  : 'none';
1473                                                }
1474
1475/********/
1476
1477                                                $final[3][$i][2] = $contact['companies']['company1']['title']? urldecode( $contact['companies']['company1']['title'] ) :'none';
1478
1479                                                //Para exibir a matricula do empregado
1480                                                $final[3][$i][8] = $contact['companies']['company1']['empNumber']?$contact['companies']['company1']['empNumber']:'none';
1481                                                //Para exibir o setor/lotacao do empregado
1482                                                $final[3][$i][9] = $contact['companies']['company1']['department']?$contact['companies']['company1']['department']:'none';
1483                                                //Para exibir o celular empresarial do empregado
1484                                                $final[3][$i][10] = $contact['companies']['company1']['celPhone']?$contact['companies']['company1']['celPhone']:'none';
1485
1486                                                //Para exibir o celular empresarial do empregado
1487                                                if ($_SESSION['phpgw_info']['user']['preferences']['contactcenter']['voip_enabled'] && !$external && $final[3][$i][10] != 'none')
1488                                                            $final[3][$i][10] = "<a title=\"".lang("Call Mobile")."\" href=\"#\" onclick=\"connectVoip('".$final[3][$i][10]."', 'mob')\">".$final[3][$i][10]."</a>";
1489
1490                                                /* Select the correct Email and Telephone to be shown */
1491                                                $preferences = ExecMethod('contactcenter.ui_preferences.get_preferences');
1492
1493                                                if (!is_array($preferences))
1494                                                {
1495                                                        $preferences['personCardEmail'] = 1;
1496                                                        $preferences['personCardPhone'] = 2;
1497                                                }
1498                                                if ($contact['connections'])
1499                                                {
1500                                                        $default_email_found = false;
1501                                                        $default_phone_found = false;
1502                                                        foreach($contact['connections'] as $conn_info)
1503                                                        {
1504                                                                if ($conn_info['id_type'] == $preferences['personCardEmail'] and !$default_email_found)
1505                                                                {
1506                                                                        if ($conn_info['connection_is_default'])
1507                                                                        {
1508                                                                                $default_email_found = true;
1509                                                                        }
1510                                                                        $final[3][$i][4] = $conn_info['connection_value'] ? $conn_info['connection_value'] : 'none';
1511                                                                }
1512                                                                else if ($conn_info['id_type'] == $preferences['personCardPhone'] and !$default_phone_found)
1513                                                                {
1514                                                                        if ($conn_info['connection_is_default'])
1515                                                                        {
1516                                                                                $default_phone_found = true;
1517                                                                        }
1518
1519/**rev 104**/
1520                                                                        //if ($_SESSION['phpgw_info']['user']['preferences']['contactcenter']['voip_enabled'] && !$external){
1521                                                                        //      $conn_info['connection_value'] = "<a title=\"".lang("Call Extension")."\" href=\"#\" onclick=\"connectVoip('".$conn_info['connection_value']."', 'ramal')\">".$conn_info['connection_value']."</a>";
1522
1523                                                                        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){
1524                                                                                $conn_info['connection_value'] = "<a title=\"".lang("Call Extension")."\" href=\"#\" onclick=\"connectVoip('".$conn_info['connection_value']."', 'com')\">".$conn_info['connection_value']."</a>";
1525                                                                       
1526/*****/
1527                                                                        }
1528                                                                        $final[3][$i][3] = $conn_info['connection_value'] ? $conn_info['connection_value'] : 'none';
1529                                                                }
1530                                                        }
1531                                                }
1532
1533                                                if (!$final[3][$i][3])
1534                                                {
1535                                                        $final[3][$i][3] = 'none';
1536                                                }
1537
1538                                                if (!$final[3][$i][4])
1539                                                {
1540                                                        $final[3][$i][4] = 'none';
1541                                                }
1542
1543                                                $final[3][$i][5] = $contact['alias']? urldecode( $contact['alias'] ):'none';
1544                                                $final[3][$i][6] = $ids[$i];
1545
1546/**rev 104**/
1547        /*                              //      If contact is a public list, then load the forwarding addresses.
1548                                                if($contact['account_type'][0] == 'l')
1549                                                        $final[3][$i][7] = array();
1550        */
1551
1552                                                //If contact is a public list or a group, then load the forwarding addresses.
1553                                                if($contact['account_type'][0] == 'l' || $contact['account_type'][0] == 'g')
1554                                                        $final[3][$i][7] = ($contact['account_type'][0] == 'l' ? 'list' : 'group');
1555                                                       
1556                                                if($this->page_info['actual_catalog']['class']=='bo_shared_people_manager') {
1557                                                        $final[3][$i][11] = $perms[$i];
1558                                                        $final[3][$i][12] = lang('Shared').": ".$owner_names[$owners[$i]]['cn'];
1559                                                }
1560/******/
1561
1562                                                $final[4][$i] = $contact['photo'] ? 1  : 0;
1563                                                $i++;
1564                                        }
1565                                        else
1566                                        {
1567                                                // coloca mensagem de erro no vetor que retorna para o browser
1568                                        }
1569                                }
1570                                $lnk_compose = "location.href=('../expressoMail1_2/index.php?to=";
1571                                $final[5] = '<span class="link" onclick="'.$lnk_compose;
1572                                $final[6] = $prop_names;
1573                                $final[7] = $validos;
1574                                $final[8] = $this->page_info['actual_catalog']['class'];
1575                                $final[9] = $count;
1576
1577
1578                                $this->page_info['actual_letter'] = $letter;
1579                                $this->page_info['actual_page'] = $page;
1580
1581                                $this->save_session();
1582                                echo serialize($final);
1583                                return;
1584                        }
1585
1586                        $this->page_info['actual_letter'] = $letter;
1587                        $this->page_info['actual_page'] = $page;
1588
1589                        $this->save_session();
1590
1591                        $final[0] = 0;
1592                        $final[1] = $this -> typeContact;
1593                        echo serialize($final);
1594                }
1595               
1596               
1597                function get_list_owners_perms_add(){
1598                        $acl = CreateObject('phpgwapi.acl');
1599                        $find_result = $acl->get_rights_and_owners($GLOBALS['phpgw_info']['user']['account_id'],'contactcenter');
1600                        if($find_result){
1601                                $owner_names = array();
1602                                $filter = "(|";
1603                                foreach($find_result as $owner) {
1604                                        if(($owner['acl_rights'] & PHPGW_ACL_ADD) == PHPGW_ACL_ADD){
1605                                                $filter .= "(uidNumber=".$owner['acl_account'].")";
1606                                        }
1607                                }
1608                                if(!$this->bo->catalog->src_info) {
1609                                        $ldap = CreateObject('contactcenter.bo_ldap_manager');
1610                                        $this->bo->catalog->src_info = $ldap->srcs[1];
1611                                }
1612                                $ds = $GLOBALS['phpgw']->common->ldapConnect($this->bo->catalog->src_info['host'], $this->bo->catalog->src_info['acc'], $this->bo->catalog->src_info['pw'], false);
1613                                $filter .= ")";
1614                                $dn=$this->bo->catalog->src_info['dn'];
1615                                $justThese = array("cn","uidnumber","uid");
1616                                $sr = ldap_search($ds,$dn, $filter,$justThese);
1617                                $info = ldap_get_entries($ds, $sr);
1618                                for($z = 0; $z < $info['count']; $z++) {
1619                                        $owner_names[$info[$z]['uidnumber'][0]] = array("cn" => $info[$z]['cn'][0], "uid" => $info[$z]['uid'][0]);
1620                                }
1621                                ldap_close($ds);
1622                        }
1623                        echo serialize ($owner_names); 
1624                }
1625
1626                function get_visible_all_ldap()
1627                {
1628                        $bo = CreateObject('contactcenter.bo_ldap_manager');
1629                        $ldap_query = $bo->srcs;
1630                        return $ldap_query[1]['visible'];
1631                }
1632
1633
1634                /*!
1635
1636                        @function get_group_data
1637                        @abstract Returns all the information of a given Group
1638                        @author Nilton Emilio Buhrer Neto
1639
1640                        @param (integer) $id The id to get information
1641
1642                */
1643                function get_group_data($id,$shared_from=null)
1644                {
1645                        $this->bo->catalog = CreateObject('contactcenter.bo_group_manager');
1646                        $fields = $this->bo->catalog->get_fields(true);
1647                        $data = $this->bo->catalog->get_single_entry($id,$fields);
1648                       
1649                        if($id) {                       
1650                                // get All Contacts by group.
1651                                $data['contact_in_list'] = $this->bo->catalog->get_contacts_by_group($id);                                                             
1652                        }
1653                       
1654                        $boGroup = CreateObject('contactcenter.bo_group');
1655
1656                        $all_contacts = $boGroup->get_all_contacts('only_email',$shared_from);
1657                       
1658                        $contact_options = "";
1659                        if(count($all_contacts)) {                                     
1660                                foreach($all_contacts as $idx => $contact) {                           
1661                                        $contact_options .= "<OPTION value='".$contact['id_connection']."'>".$contact['names_ordered']." (".$contact['connection_value'].")</OPTION>";
1662                                }
1663                        }
1664                        $data['contact_list'] = $contact_options;
1665                        $data['result'] = 'ok';                                                         
1666                        echo serialize($data);                 
1667                }               
1668               
1669                /*!
1670
1671                        @function get_full_data
1672                        @abstract Returns all the information of a given Entry
1673                        @author Raphael Derosso Pereira
1674
1675                        @param (integer) $id The id to get information
1676
1677                */
1678/**rev 104**/
1679                //function get_full_data($id)
1680                function get_full_data($id,$catalog='bo_people_catalog')
1681                {
1682                        $dateformat = $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
1683/**rev 104**/
1684                        //$this->bo->catalog = CreateObject('contactcenter.bo_people_catalog');
1685                        $this->bo->catalog = CreateObject('contactcenter.'.$catalog);
1686/****/
1687                        $fields = $this->bo->catalog->get_fields(true);
1688                        $fields['photo'] = false;
1689                        $entry = $this->bo->catalog->get_single_entry($id,$fields);
1690
1691                        if (is_bool($entry['given_names']))
1692                        {
1693                                $data['result'] = 'false';
1694                                echo serialize($data);
1695                                return;
1696                        }
1697
1698                        $date = explode('-', $entry['birthdate']);
1699                        $j = 0;
1700                        for ($i = 0; $i < 5; $i+=2)
1701                        {
1702                                switch($dateformat{$i})
1703                                {
1704                                        case 'Y':
1705                                                $birthdate[$j] = $date[0];
1706                                                break;
1707
1708                                        case 'm':
1709                                        case 'M':
1710                                                $birthdate[$j] = $date[1];
1711                                                break;
1712
1713                                        case 'd':
1714                                                $birthdate[$j] = $date[2];
1715                                }
1716                                $j++;
1717                        }
1718                        $datecount = 0;
1719
1720                        $data['result'] = 'ok';
1721                        $data['cc_full_add_contact_id'] = $id;
1722
1723                        /* Personal Data */
1724                        $data['personal']['cc_pd_photo'] = '../index.php?menuaction=contactcenter.ui_data.data_manager&method=get_photo&id='.$id;
1725                        $data['personal']['cc_pd_alias'] = $entry['alias'];
1726                        $data['personal']['cc_pd_given_names'] = $entry['given_names'];
1727                        $data['personal']['cc_pd_family_names'] = $entry['family_names'];
1728                        $data['personal']['cc_pd_full_name'] = $entry['names_ordered'];
1729                        $data['personal']['cc_pd_suffix'] = $entry['id_suffix'];
1730                        $data['personal']['cc_pd_birthdate_0'] = $birthdate[0];
1731                        $data['personal']['cc_pd_birthdate_1'] = $birthdate[1];
1732                        $data['personal']['cc_pd_birthdate_2'] = $birthdate[2];
1733                        //$data['personal']['cc_pd_sex'] = $entry['sex'] === 'M' ? 1 : ($entry['sex'] === 'F' ? 2 : 0);
1734                        $data['personal']['cc_pd_prefix'] = $entry['id_prefix'];
1735                        $data['personal']['cc_pd_gpg_finger_print'] = $entry['pgp_key'];
1736                        $data['personal']['cc_pd_notes'] = $entry['notes'];
1737
1738                        /* Addresses */
1739                        if (is_array($entry['addresses']))
1740                        {
1741                                $data['addresses'] = $entry['addresses'];
1742                        }
1743
1744                        /* Connections */
1745                        if (is_array($entry['connections']))
1746                        {
1747                                $data['connections'] = array();
1748                                foreach ($entry['connections'] as $connection)
1749                                {
1750                                        $type = $connection['id_type'];
1751                                        $i = count($data['connections'][$type]);
1752                                        $data['connections'][$type][$i]['id'] = $connection['id_connection'];
1753                                        $data['connections'][$type][$i]['name'] = $connection['connection_name'];
1754                                        $data['connections'][$type][$i]['value'] = $connection['connection_value'];
1755                                        $data['connections'][$type][$i]['is_default'] = $connection['connection_is_default'];
1756                                }
1757                        }
1758//                      print_r($data);
1759//OBSERVAR cc_department
1760                        /*Corporative*/
1761                        if($GLOBALS['phpgw_info']['server']['personal_contact_type']=='True'){
1762                                $data['personal']['cc_job_title'] = $entry['job_title'];
1763                                $data['personal']['cc_department'] = $entry['department'];
1764                                $data['personal']['cc_name_corporate'] = $entry['corporate_name'];
1765                                $data['personal']['cc_web_page'] = $entry['web_page'];
1766                        }
1767                       
1768
1769
1770                        /* Relations */
1771
1772                        echo serialize($data);
1773                }
1774
1775                /*!
1776
1777                        @function get_contact_full_add_const
1778                        @abstract Returns all the constant fields in Contact Full Add Window to the JS
1779                        @author Raphael Derosso Pereira
1780                */
1781                function get_contact_full_add_const()
1782                {
1783                        $data = array();
1784                        $boPeopleCatalog = CreateObject('contactcenter.bo_people_catalog');
1785                        $predata[] = $boPeopleCatalog -> get_all_prefixes();
1786                        $predata[] = $boPeopleCatalog -> get_all_suffixes();
1787                        $predata[] = $boPeopleCatalog -> get_all_addresses_types();
1788                        $predata[] = $boPeopleCatalog -> get_all_countries();
1789                        $predata[] = $boPeopleCatalog -> get_all_connections_types();
1790                        //$predata[] = $this->bo->catalog->get_all_relations_types();
1791
1792                        $i = 0;
1793                        foreach($predata as $data_)
1794                        {
1795                                if ($data_)
1796                                {
1797                                        $data[$i] = $data_;
1798                                }
1799
1800                                $i++;
1801                        }
1802
1803                        if (count($data))
1804                        {
1805                                echo serialize($data);
1806                                return;
1807                        }
1808
1809                        echo 0;
1810                }
1811
1812                /*!
1813
1814                        @function quick_add
1815                        @abstract Adds a new Contact using the Quick Add interface
1816                        @author Raphael Derosso Pereira
1817
1818                        @param string $sdata Serialized data
1819                */
1820                function quick_add($sdata)
1821                {
1822
1823                        $sdata = str_replace('\\"', '"', $sdata);
1824                        $new_array = unserialize($sdata);
1825                        $tdata = array();
1826
1827                        foreach($new_array as $tmp)
1828                                $tdata[] = $tmp;
1829
1830                        if (!$tdata)
1831                        {
1832                                echo serialize(array(
1833                                        'msg'    => lang('Problems on adding your Contact. Invalid Data came from client. No Contact added!'),
1834                                        'status' => 'abort'
1835                                ));
1836
1837                                return;
1838                        }
1839
1840                        // verifica se email já existe!
1841                        $boGroup = CreateObject('contactcenter.bo_group');
1842                        $contact = $boGroup->verify_contact($tdata[4]);
1843
1844                        if($contact)
1845                        {
1846                                $str_contact = "\r\n - ".implode("\r\n - ",$contact);
1847
1848                                echo serialize(array(
1849                                        'msg'    => lang('Problems on adding your Contact. The email "%1" already exists in: %2',$tdata[4], $str_contact),
1850                                        'status' => 'alreadyExists'
1851                                ));
1852
1853                                return;
1854                        }
1855
1856                        $data['alias'] = addslashes($tdata[0]);
1857                        $data['given_names'] = addslashes($tdata[1]);
1858                        $data['family_names'] = addslashes($tdata[2]);
1859                        $data['connections']['default_phone']['connection_name'] = lang('Main');
1860                        $data['connections']['default_phone']['connection_value'] = $tdata[3];
1861                        $data['connections']['default_email']['connection_name'] = lang('Main');
1862                        $data['connections']['default_email']['connection_value'] = $tdata[4];
1863                        $boPeople = CreateObject('contactcenter.bo_people_catalog');
1864
1865                        if ($boPeople ->quick_add($data))
1866                        {
1867                                $this->page_info['changed'] = true;
1868
1869                                echo serialize(array(
1870                                        'msg'    => lang('Entry added with success!'),
1871                                        'status' => 'ok'
1872                                ));
1873                        }
1874                        else
1875                        {
1876                                echo serialize(array(
1877                                        'msg'    => lang('Problems on adding your Contact. No Contact added!'),
1878                                        'status' => 'error'
1879                                ));
1880                        }
1881
1882                        $this->save_session();
1883
1884                }
1885
1886                /*!
1887
1888                        @function add_group
1889                        @abstract Adds a new Group using the Add Group interface
1890                        @author Nilton Emilio Buhrer Neto
1891
1892                        @param string $sdata Serialized data
1893                */
1894                function add_group($sdata)
1895                {
1896                        $sdata = str_replace('\\"', '"', $sdata);
1897                        $tdata = unserialize($sdata);
1898                        $new_tdata = array();
1899
1900                        if (!$tdata)
1901                        {
1902                                echo serialize(array(
1903                                        'msg'    => lang('Problems on adding your Contact. Invalid Data came from client. No Contact added!'),
1904                                        'status' => 'abort'
1905                                ));
1906
1907                                return;
1908                        }
1909
1910                        foreach($tdata as $tmp)
1911                                $new_tdata[] = $tmp;
1912
1913                        $data['title'] = $new_tdata[0];
1914                        $data['contact_in_list'] = $new_tdata[1];
1915                        $data['id_group'] = $new_tdata[2];
1916
1917                        $boGroup = CreateObject('contactcenter.bo_group_manager');
1918                        $id = $boGroup -> add_group($data);
1919
1920                        if ($id)
1921                        {
1922                                $this->page_info['changed'] = true;
1923
1924                                echo serialize(array(
1925                                        'msg'    => lang('Entry added with success!'),
1926                                        'status' => 'ok'
1927                                ));
1928                        }
1929                        else
1930                        {
1931                                echo serialize(array(
1932                                        'msg'    => lang('Problems on adding your Group. Be sure that a group with this name do not exists'),
1933                                        'status' => 'error'
1934                                ));
1935                        }
1936
1937                        $this->save_session();
1938                }
1939
1940                /*!
1941
1942                        @function remove_group
1943                        @abstract Removes a group if the user has the right to do it
1944                        @author Nilton Emilio Buhrer Neto
1945                        @param (integer) $id The id to be removed
1946
1947                */
1948                function remove_group($id)
1949                {
1950                                $soGroup = CreateObject('contactcenter.so_group');
1951                                $data = array ('id_group' => $id);
1952                                if($soGroup -> delete($data)) {
1953                                        echo serialize(array(
1954                                                'msg'    => lang('Removed Entry ID '.$id.'!'),
1955                                                'status' => 'ok'
1956                                        ));
1957                                }
1958                                else {
1959                                        echo serialize(array(
1960                                                'msg'    => lang('Problems on adding your Contact. No Contact added!'),
1961                                                'status' => 'error'
1962                                        ));
1963                                }
1964
1965                        $this->save_session();
1966                }
1967
1968
1969                function remove_all_entries (){
1970
1971                        $error = false;
1972                        $this->all_entries = $this->bo->catalog->get_all_entries_ids();
1973
1974                        foreach($this->all_entries as $index => $id) {
1975                                $result = $this->bo->catalog->remove_single_entry($id);
1976                                if(!$result) {
1977                                        $error = true;
1978                                        break;
1979                                }
1980                        }
1981
1982                        if(!$error) {
1983                                echo serialize(array(
1984                                        'msg'    => lang('Removed Entry ID '.$id.'!'),
1985                                        'status' => 'ok'
1986                                ));
1987                        }
1988                        else {
1989                                echo serialize(array(
1990                                        'msg'    => lang('Couldn\'t remove this entry. Inform the Site Admin!'),
1991                                        'status' => 'fail'
1992                                ));
1993                        }
1994
1995                        $this->save_session();
1996                }
1997
1998                /*!
1999
2000                        @function remove_entry
2001                        @abstract Removes an entry if the user has the right to do it
2002                        @author Raphael Derosso Pereira
2003
2004                        @param (integer) $id The id to be removed
2005
2006                */
2007                function remove_entry ($id)
2008                {
2009                        if (!is_int($id))
2010                        {
2011                                echo lang('Couldn\'t remove entry! Problem passing data to the server. Please inform admin!');
2012                                return;
2013                        }
2014
2015                        $this->page_info['changed'] = true;
2016                        $result = $this->bo->catalog->remove_single_entry($id);
2017
2018                        if ($result)
2019                        {
2020                                if ($pos = array_search($id, $this->page_info['actual_entries']))
2021                                {
2022                                        unset($this->page_info['actual_entries'][$pos]);
2023                                }
2024
2025                                $temp = false;
2026                                reset($this->page_info['actual_entries']);
2027                                foreach($this->page_info['actual_entries'] as $t)
2028                                {
2029                                        $temp[] = $t;
2030                                }
2031
2032                                $this->page_info['actual_entries'] = $temp;
2033
2034                                echo serialize(array(
2035                                        'msg'    => lang('Removed Entry ID '.$id.'!'),
2036                                        'status' => 'ok'
2037                                ));
2038                        }
2039                        else
2040                        {
2041                                echo serialize(array(
2042                                        'msg'    => lang('Couldn\'t remove this entry. Inform the Site Admin!'),
2043                                        'status' => 'fail'
2044                                ));
2045                        }
2046
2047                        $this->save_session();
2048                }
2049
2050
2051                /*!
2052
2053                        @function post_full_add
2054                        @abstract Saves all the information altered/entered in the Full Add
2055                                window
2056                        @author Raphael Derosso Pereira
2057
2058                */
2059                function post_full_add()
2060                {
2061                        $data =  $_POST['data'];
2062                        // Exceptions!!! utf8 special chars.
2063                        $data = preg_replace("/\%u2(\d+)(\d+)(\d+)/","-",$data);
2064                        $data = unserialize(str_replace('\\"', '"', $data));
2065                        $this -> bo -> catalog = CreateObject('contactcenter.bo_people_catalog');
2066
2067                        if (!is_array($data))
2068                        {
2069                                echo serialize(array(
2070                                        'msg' => lang('<p>Some problem receiving data from browser. This is probably a bug in ContactCenter<br>'.
2071                                                  'Please go to eGroupWare Bug Reporting page and report this bug.<br>'.
2072                                                          'Sorry for the inconvenient!<br><br>'.
2073                                                          '<b><i>ContactCenter Developer Team</i></b></p>'),
2074                                        'status' => 'fatal'
2075                                ));
2076                                return;
2077                        }
2078//                      print_r($data);
2079//                      echo '<br><br>';
2080
2081                        $replacer = $data['commercialAnd'];
2082                        unset($data['commercialAnd']);
2083                        if (!is_string($replacer) or strpos($replacer, "'") or strpos($replacer, '"'))
2084                        {
2085                                echo serialize(array(
2086                                        'msg' => lang('Invalid \'&\' replacer! This may be an attempt to bypass Security! Action aborted!'),
2087                                        'status' => 'fatal'
2088                                ));
2089
2090                                return;
2091                        }
2092
2093                        if ($data['id_contact'])
2094                        {
2095                                $id = $data['id_contact'];
2096                                $id_photo = $id;
2097                                unset($data['id_contact']);
2098                        }
2099                        else
2100                        {
2101                                $id_photo = '_new_';
2102                        }
2103
2104                        /*
2105                         * Process Photo, if available
2106                         */
2107                        $sleep_count = 0;
2108                        $photo_ok = $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter');
2109                        while($photo_ok[0]{0} !== 'o' and $photo_ok[1]{0} === 'y')
2110                        {
2111                                sleep(1);
2112                                $photo_ok = $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter');
2113                                $sleep_count++;
2114
2115                                if ($sleep_count > 35)
2116                                {
2117                                        // TODO
2118                                        return;
2119                                }
2120                        }
2121                        $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('wait', 'n'));
2122
2123                        if (isset($this->page_info['photos'][$id_photo]))
2124                        {
2125                                if (array_search($this->page_info['photos'][$id_photo]['status'], array('changed', 'sync')) === false)
2126                                {
2127                                        echo serialize(array(
2128                                                'msg' => $this->page_info['photos'][$id_photo]['msg'],
2129                                                'status' => $this->page_info['photos'][$id_photo]['status']
2130                                        ));
2131
2132                                        return;
2133                                }
2134
2135                                $data['photo'] = $this->page_info['photos'][$id_photo]['content'];
2136                                unset($this->page_info['photos'][$id_photo]);
2137                                $this->save_session();
2138                        }
2139
2140                        /*
2141                         * Arrange Date so it gets inserted correctly
2142                         */
2143
2144                        $dateformat = $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
2145
2146                        $j = 0;
2147                        for ($i = 0; $i < 5; $i+=2)
2148                        {
2149                                switch($dateformat{$i})
2150                                {
2151                                        case 'Y':
2152                                                $date[$j]['size'] = 4;
2153                                                $date[$j]['digit'] = 'Y';
2154                                                break;
2155
2156                                        case 'm':
2157                                        case 'M':
2158                                                $date[$j]['size'] = 2;
2159                                                $date[$j]['digit'] = 'M';
2160                                                break;
2161
2162                                        case 'd':
2163                                                $date[$j]['size'] = 2;
2164                                                $date[$j]['digit'] = 'D';
2165                                }
2166                                $j++;
2167                        }
2168                        $datecount = 0;
2169
2170                        /* Verify Data and performs insertion/update */
2171                        foreach($data as $field => $value)
2172                        {
2173
2174                                switch($field)
2175                                {
2176                                        case 'names_ordered':
2177                                                $data[$field] = addslashes(rawurldecode($value));
2178                                        case 'corporate_name':
2179                                        case 'job_title':
2180                                        case 'department':
2181                                        case 'web_page':
2182                                        case 'alias':
2183                                        case 'given_names':
2184                                        case 'family_names':
2185                                        case 'pgp_key':
2186                                        case 'notes':
2187                                                $data[$field] = addslashes(rawurldecode($data[$field]));
2188                                                break;
2189
2190                                        case 'id_status':
2191                                        case 'id_prefix':
2192                                        case 'id_suffix':
2193                                                if ($data[$field] == 0)
2194                                                {
2195                                                        unset($data[$field]);
2196                                                }
2197                                                break;
2198
2199                                        case 'birthdate_0':
2200                                        case 'birthdate_1':
2201                                        case 'birthdate_2':
2202                                        case 'birthdate':
2203                                       
2204                                                if($field == 'birthdate'){
2205                                                        $array_birth = explode("/",$data[$field]);                                                     
2206                                                        $date['value'][2] = $array_birth[2];
2207                                                        $date['value'][1] = $array_birth[1];
2208                                                        $date['value'][0] = $array_birth[0];                                           
2209                                                }else{                                 
2210                                                        switch($date[$datecount]['digit'])
2211                                                        {
2212                                                                case 'Y':
2213                                                                        $date['value'][2] = (int) $data[$field];
2214                                                                        break;
2215       
2216                                                                case 'M':
2217                                                                        $date['value'][0] = (int) $data[$field];
2218                                                                        break;
2219       
2220                                                                case 'D':
2221                                                                        $date['value'][1] = (int) $data[$field];
2222                                                                        break;
2223                                                        }
2224                                                        unset($data[$field]);
2225                                                }
2226                                               
2227                                                $datecount++;
2228
2229                                                if ($datecount != 3)
2230                                                {
2231                                                        break;
2232                                                }
2233
2234                                                if($date['value'][0] =='' && $date['value'][1] =='' && $date['value'][2] ==''){
2235                                                        $data['birthdate'] = null;
2236                                                        break;
2237                                                }
2238                                                if (!checkdate($date['value'][0], $date['value'][1], $date['value'][2]))
2239                                                {
2240                                                        echo serialize(array(
2241                                                                'msg' => lang('Invalid Date'),
2242                                                                'status' => 'invalid_data'
2243                                                        ));
2244                                                        return;
2245                                                }
2246                                                if( $date['value'][2] != "" && $date['value'][0] != "" && $date['value'][1] != ""){
2247                                                        $data['birthdate'] = $date['value'][2].'-'.$date['value'][0].'-'.$date['value'][1];
2248                                                }
2249                                                break;
2250
2251                                        case 'sex':
2252                                                if ($data[$field] !== 'M' and $data[$field] !== 'F')
2253                                                {
2254                                                        echo serialize(array(
2255                                                                'msg' => lang('Invalid Sex'),
2256                                                                'status' => 'invalid_data'
2257                                                        ));
2258                                                        return;
2259                                                }
2260                                                break;
2261
2262
2263                                        case 'addresses':
2264                                                /* Insert new cities/states */
2265                                                if (isset($value['new_states']))
2266                                                {
2267                                                        foreach($value['new_states'] as $type => $state_info)
2268                                                        {
2269                                                                $index = 'address'.$type;
2270
2271                                                                $id_state = $this->bo->catalog->add_state($state_info);
2272                                                                $data['addresses'][$index]['id_state'] = $id_state;
2273
2274                                                                if ($value['new_cities'][$type])
2275                                                                {
2276                                                                        $data[$field]['new_cities'][$type]['id_state'] = $id_state;
2277                                                                }
2278                                                        }
2279
2280                                                        unset($data['addresses']['new_states']);
2281                                                }
2282
2283                                                if (isset($value['new_cities']))
2284                                                {
2285                                                        foreach($value['new_cities'] as $type => $city_info)
2286                                                        {
2287                                                                $index = 'address'.$type;
2288
2289                                                                $id_city = $this->bo->catalog->add_city($city_info);
2290                                                                $data['addresses'][$index]['id_city'] = $id_city;
2291                                                        }
2292
2293                                                        unset($data['addresses']['new_cities']);
2294                                                }
2295
2296                                        break;
2297
2298                                        case 'birthdate':
2299                                        case 'connections':
2300                                        case 'photo':
2301                                                /* Does nothing... */
2302                                                break;
2303
2304                                        default:
2305                                                echo serialize(array(
2306                                                        'msg' => lang('Invalid field: ').$field,
2307                                                        'status' => 'invalid_data'
2308                                                ));
2309                                                return;
2310                                }
2311                        }
2312
2313                        if (!is_null($id) and $id !== '')
2314                        {
2315                                $id = $this->bo->catalog->update_single_info($id, $data);
2316                                $result = array(
2317                                        'msg' => lang('Updated Successfully!'),
2318                                        'status' => 'ok'
2319                                );
2320                        }
2321                        else
2322                        {
2323                                $id = $this->bo->catalog->add_single_entry($data);
2324                                $result = array(
2325                                        'msg' => lang('Entry Added Successfully!'),
2326                                        'status' => 'ok'
2327                                );
2328                        }
2329
2330                        if (!($id))
2331                        {
2332                                $result = array(
2333                                        'msg' => lang('Some problem occured when trying to insert/update contact information.<br>'.
2334                                                   'Report the problem to the Administrator.'),
2335                                        'status' => 'fail'
2336                                );
2337                        }
2338
2339                        echo serialize($result);
2340                }
2341
2342
2343                function post_full_add_shared()
2344                {
2345                        $data =  $_POST['data'];
2346                        // Exceptions!!! utf8 special chars.
2347                        $data = preg_replace("/\%u2(\d+)(\d+)(\d+)/","-",$data);
2348                        $data = unserialize(str_replace('\\"', '"', $data));
2349                        $this -> bo -> catalog = CreateObject('contactcenter.bo_shared_people_manager');
2350
2351                        if (!is_array($data))
2352                        {
2353                                echo serialize(array(
2354                                        'msg' => lang('<p>Some problem receiving data from browser. This is probably a bug in ContactCenter<br>'.
2355                                                  'Please go to eGroupWare Bug Reporting page and report this bug.<br>'.
2356                                                          'Sorry for the inconvenient!<br><br>'.
2357                                                          '<b><i>ContactCenter Developer Team</i></b></p>'),
2358                                        'status' => 'fatal'
2359                                ));
2360                                return;
2361                        }
2362//                      print_r($data);
2363//                      echo '<br><br>';
2364
2365                        $replacer = $data['commercialAnd'];
2366                        unset($data['commercialAnd']);
2367                        if (!is_string($replacer) or strpos($replacer, "'") or strpos($replacer, '"'))
2368                        {
2369                                echo serialize(array(
2370                                        'msg' => lang('Invalid \'&\' replacer! This may be an attempt to bypass Security! Action aborted!'),
2371                                        'status' => 'fatal'
2372                                ));
2373
2374                                return;
2375                        }
2376
2377                        if ($data['id_contact'])
2378                        {
2379                                $id = $data['id_contact'];
2380                                $id_photo = $id;
2381                                unset($data['id_contact']);
2382                        }
2383                        else
2384                        {
2385                                $id_photo = '_new_';
2386                        }
2387
2388                        if ($data['owner'])
2389                        {
2390                                $owner = $data['owner'];
2391                                unset($data['owner']);
2392                        }
2393                        /*
2394                         * Process Photo, if available
2395                         */
2396                        $sleep_count = 0;
2397                        $photo_ok = $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter');
2398                        while($photo_ok[0]{0} !== 'o' and $photo_ok[1]{0} === 'y')
2399                        {
2400                                sleep(1);
2401                                $photo_ok = $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter');
2402                                $sleep_count++;
2403
2404                                if ($sleep_count > 35)
2405                                {
2406                                        // TODO
2407                                        return;
2408                                }
2409                        }
2410                        $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('wait', 'n'));
2411
2412                        if (isset($this->page_info['photos'][$id_photo]))
2413                        {
2414                                if (array_search($this->page_info['photos'][$id_photo]['status'], array('changed', 'sync')) === false)
2415                                {
2416                                        echo serialize(array(
2417                                                'msg' => $this->page_info['photos'][$id_photo]['msg'],
2418                                                'status' => $this->page_info['photos'][$id_photo]['status']
2419                                        ));
2420
2421                                        return;
2422                                }
2423
2424                                $data['photo'] = $this->page_info['photos'][$id_photo]['content'];
2425                                unset($this->page_info['photos'][$id_photo]);
2426                                $this->save_session();
2427                        }
2428
2429                        /*
2430                         * Arrange Date so it gets inserted correctly
2431                         */
2432
2433                        $dateformat = $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
2434
2435                        $j = 0;
2436                        for ($i = 0; $i < 5; $i+=2)
2437                        {
2438                                switch($dateformat{$i})
2439                                {
2440                                        case 'Y':
2441                                                $date[$j]['size'] = 4;
2442                                                $date[$j]['digit'] = 'Y';
2443                                                break;
2444
2445                                        case 'm':
2446                                        case 'M':
2447                                                $date[$j]['size'] = 2;
2448                                                $date[$j]['digit'] = 'M';
2449                                                break;
2450
2451                                        case 'd':
2452                                                $date[$j]['size'] = 2;
2453                                                $date[$j]['digit'] = 'D';
2454                                }
2455                                $j++;
2456                        }
2457                        $datecount = 0;
2458
2459                        /* Verify Data and performs insertion/update */
2460                        foreach($data as $field => &$value)
2461                        {
2462                                if ($value == '' or is_null($value))
2463                                {
2464                                        unset($data[$field]);
2465                                        continue;
2466                                }
2467
2468                                switch($field)
2469                                {
2470                                        case 'corporate_name':
2471                                        case 'job_title':
2472                                        case 'department':
2473                                        case 'web_page':
2474                                        case 'alias':
2475                                        case 'given_names':
2476                                        case 'family_names':
2477                                        case 'names_ordered':
2478                                        case 'pgp_key':
2479                                        case 'notes':
2480                                        case 'photo':
2481                                                $data[$field] = urldecode( $value );
2482                                                break;
2483
2484                                        case 'id_status':
2485                                        case 'id_prefix':
2486                                        case 'id_suffix':
2487                                                if ($data[$field] == 0)
2488                                                {
2489                                                        unset($data[$field]);
2490                                                }
2491                                                break;
2492
2493                                        case 'birthdate_0':
2494                                        case 'birthdate_1':
2495                                        case 'birthdate_2':
2496
2497                                                switch($date[$datecount]['digit'])
2498                                                {
2499                                                        case 'Y':
2500                                                                $date['value'][2] = (int) $data[$field];
2501                                                                break;
2502
2503                                                        case 'M':
2504                                                                $date['value'][0] = (int) $data[$field];
2505                                                                break;
2506
2507                                                        case 'D':
2508                                                                $date['value'][1] = (int) $data[$field];
2509                                                                break;
2510                                                }
2511                                                unset($data[$field]);
2512                                                $datecount++;
2513
2514                                                if ($datecount != 3)
2515                                                {
2516                                                        break;
2517                                                }
2518
2519                                                if (!checkdate($date['value'][0], $date['value'][1], $date['value'][2]))
2520                                                {
2521                                                        echo serialize(array(
2522                                                                'msg' => lang('Invalid Date'),
2523                                                                'status' => 'invalid_data'
2524                                                        ));
2525                                                        return;
2526                                                }
2527
2528                                                $data['birthdate'] = $date['value'][2].'-'.$date['value'][0].'-'.$date['value'][1];
2529                                                break;
2530
2531                                        case 'sex':
2532                                                if ($data[$field] !== 'M' and $data[$field] !== 'F')
2533                                                {
2534                                                        echo serialize(array(
2535                                                                'msg' => lang('Invalid Sex'),
2536                                                                'status' => 'invalid_data'
2537                                                        ));
2538                                                        return;
2539                                                }
2540                                                break;
2541
2542
2543                                        case 'addresses':
2544                                                /* Insert new cities/states */
2545                                                if (isset($value['new_states']))
2546                                                {
2547                                                        foreach($value['new_states'] as $type => $state_info)
2548                                                        {
2549                                                                $index = 'address'.$type;
2550
2551                                                                $id_state = $this->bo->catalog->add_state($state_info);
2552                                                                $data['addresses'][$index]['id_state'] = $id_state;
2553
2554                                                                if ($value['new_cities'][$type])
2555                                                                {
2556                                                                        $value['new_cities'][$type]['id_state'] = $id_state;
2557                                                                }
2558                                                        }
2559
2560                                                        unset($data['addresses']['new_states']);
2561                                                }
2562
2563                                                if (isset($value['new_cities']))
2564                                                {
2565                                                        foreach($value['new_cities'] as $type => $city_info)
2566                                                        {
2567                                                                $index = 'address'.$type;
2568
2569                                                                $id_city = $this->bo->catalog->add_city($city_info);
2570                                                                $data['addresses'][$index]['id_city'] = $id_city;
2571                                                        }
2572
2573                                                        unset($data['addresses']['new_cities']);
2574                                                }
2575
2576                                        break;
2577
2578                                        case 'connections':
2579                                                /* Does nothing... */
2580                                                break;
2581
2582                                        default:
2583                                                echo serialize(array(
2584                                                        'msg' => lang('Invalid field: ').$field,
2585                                                        'status' => 'invalid_data'
2586                                                ));
2587                                                return;
2588                                }
2589                        }
2590
2591                        $code = '$id = $this->bo->catalog->';
2592
2593                        if (!is_null($id) and $id !== '')
2594                        {
2595                                $code .= $code.'update_single_info($id, $data);';
2596                                $result = array(
2597                                        'msg' => lang('Updated Successfully!'),
2598                                        'status' => 'ok'
2599                                );
2600                        }
2601                        else
2602                        {
2603                                $code .= 'add_single_entry($data,'.$owner.');';
2604                                $result = array(
2605                                        'msg' => lang('Entry Added Successfully!'),
2606                                        'status' => 'ok'
2607                                );
2608                        }
2609
2610                        eval($code);
2611
2612                        if (!($id))
2613                        {
2614                                $result = array(
2615                                        'msg' => lang('Some problem occured when trying to insert/update contact information.<br>'.
2616                                                   'Report the problem to the Administrator.'),
2617                                        'status' => 'fail'
2618                                );
2619                        }
2620
2621                        echo serialize($result);
2622}
2623                /*!
2624
2625                        @function post_photo
2626                        @abstract Wrapper to post a photo without reload a page.
2627                        @author Raphael Derosso Pereira
2628
2629                */
2630                function post_photo($id)
2631                {
2632                        //print_r($_FILES);
2633                        $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('wait', 'y'));
2634
2635                        if (!is_array($_FILES) and is_array(!$_FILES['cc_pd_photo']))
2636                        {
2637                                $this->page_info['photos'][$id]['status'] = 'no_upload';
2638                                $this->page_info['photos'][$id]['msg'] = lang('No Photos uploaded to Server.');
2639
2640                                $this->save_session();
2641                                $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('ok', 'y'));
2642                                return;
2643                        }
2644
2645                        if (!function_exists('imagecreate'))
2646                        {
2647                                $this->page_info['photos'][$id]['status'] = 'no_GD_lib';
2648                                $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.');
2649
2650                                $this->save_session();
2651                                $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('ok', 'y'));
2652                                return;
2653                        }
2654
2655                        // TODO: Get Max Size from preferences!
2656                        if ($_FILES['cc_pd_photo']['size'] > 1000000)
2657                        {
2658                                $this->page_info['photos'][$id]['status'] = 'too_large';
2659                                $this->page_info['photos'][$id]['msg'] = lang('Image too large! ContactCenter limits the image size to 1 Mb');
2660
2661                                $this->save_session();
2662                                $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('ok', 'y'));
2663                                return;
2664                        }
2665
2666                        if ($_FILES['cc_pd_photo']['error'])
2667                        {
2668                                $this->page_info['photos'][$id]['status'] = 'error';
2669                                $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'];
2670
2671                                $this->save_session();
2672                                $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('ok', 'y'));
2673                                return;
2674                        }
2675
2676                        switch($_FILES['cc_pd_photo']['type'])
2677                        {
2678                                case 'image/jpeg':
2679                                case 'image/pjpeg':
2680                                        $src_img = imagecreatefromjpeg($_FILES['cc_pd_photo']['tmp_name']);
2681                                        if ($src_img == '')
2682                                        {
2683                                                $bogus = true;
2684                                        }
2685                                        break;
2686
2687                                case 'image/png':
2688                                case 'image/x-png':
2689                                        $src_img = imagecreatefrompng($_FILES['cc_pd_photo']['tmp_name']);
2690                                        if ($src_img == '')
2691                                        {
2692                                                $bogus = true;
2693                                        }
2694                                        break;
2695
2696                                case 'image/gif':
2697                                        $src_img = imagecreatefromgif($_FILES['cc_pd_photo']['tmp_name']);
2698                                        if ($src_img == '')
2699                                        {
2700                                                $bogus = true;
2701                                        }
2702                                        break;
2703
2704                                default:
2705
2706                                        $this->page_info['photos'][$id]['status'] = 'invalid_image';
2707                                        $this->page_info['photos'][$id]['msg'] = lang('The file must be an JPEG, PNG or GIF Image.');
2708
2709                                        $this->save_session();
2710                                        $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('ok', 'y'));
2711                                        return;
2712                        }
2713
2714                        if ($bogus)
2715                        {
2716                                        $this->page_info['photos'][$id]['status'] = 'invalid_file';
2717                                        $this->page_info['photos'][$id]['msg'] = lang('Couldn\'t open Image. It may be corrupted or internal library doesn\'t support this format.');
2718
2719                                        $this->save_session();
2720                                        $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('ok', 'y'));
2721                                        return;
2722                        }
2723
2724                        $img_size = getimagesize($_FILES['cc_pd_photo']['tmp_name']);
2725                        $dst_img = imagecreatetruecolor(60, 80);
2726
2727                        if (!imagecopyresized($dst_img, $src_img, 0, 0, 0, 0, 60, 80, $img_size[0], $img_size[1]))
2728                        {
2729                                $this->page_info['photos'][$id]['status'] = 'invalid_file';
2730                                $this->page_info['photos'][$id]['msg'] = lang('Couldn\'t open Image. It may be corrupted or internal library doesn\'t support this format.');
2731
2732                                $this->save_session();
2733                                $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('ok', 'y'));
2734                                return;
2735                        }
2736
2737                        ob_start();
2738                        imagepng($dst_img);
2739                        $this->page_info['photos'][$id]['content'] = ob_get_contents();
2740                        ob_end_clean();
2741
2742                        $this->page_info['photos'][$id]['status'] = 'changed';
2743                        $this->page_info['photos'][$id]['msg'] = lang('Photo Successfully Updated!');
2744
2745                        $this->save_session();
2746
2747                        $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('ok', 'y'));
2748
2749                        imagedestroy($src_img);
2750                        imagedestroy($dst_img);
2751                        echo 'ok';
2752                        return;
2753                }
2754
2755
2756                /*!
2757
2758                        @function get_photo
2759                        @abstract Returns the photo to the browser
2760                        @author Raphael Derosso Pereira
2761
2762                */
2763                function get_photo($id)
2764                {
2765                        $fields = $this->bo->catalog->get_fields(false);
2766                        $fields['photo'] = true;
2767
2768                        $contact = $this->bo->catalog->get_single_entry($id, $fields);
2769
2770                        if (!$contact['photo'])
2771                        {
2772                                header('Content-type: image/png');
2773                                echo file_get_contents(PHPGW_INCLUDE_ROOT.'/contactcenter/templates/default/images/photo_celepar.png');
2774                                return;
2775                        }
2776
2777                        header('Content-type: image/jpeg');
2778                        $photo = imagecreatefromstring ($contact['photo']);
2779                        $width = imagesx($photo);
2780                        $height = imagesy($photo);
2781                        $twidth = 70;
2782                        $theight = 90;
2783                        $small_photo = imagecreatetruecolor ($twidth, $theight);
2784                        imagecopyresampled($small_photo, $photo, 0, 0, 0, 0,$twidth, $theight, $width, $height);
2785                        imagejpeg($small_photo,"",100);
2786                        return;
2787                }
2788
2789                /*!
2790
2791                        @function get_states
2792                        @abstract Echos a serialized array containing all the states for the given country
2793                        @author Raphael Derosso Pereira
2794
2795                        @params $id_country The ID of the Country that contains the requested states
2796
2797                */
2798                function get_states($id_country)
2799                {
2800                        $states = $this->bo->catalog->get_all_states($id_country);
2801
2802                        if (!$states)
2803                        {
2804                                $result = array(
2805                                        'msg'    => lang('No States found for this Country.'),
2806                                        'status' => 'empty'
2807                                );
2808
2809                                echo serialize($result);
2810                                return;
2811                        }
2812
2813                        $result = array(
2814                                'msg'    => lang('States Successfully retrieved!'),
2815                                'status' => 'ok'
2816                        );
2817
2818                        foreach ($states as $state_info)
2819                        {
2820                                $result['data'][$state_info['id_state']] = $state_info['name'];
2821
2822                                if ($state_info['symbol'])
2823                                {
2824                                        $result['data'][$state_info['id_state']] .= ', '.$state_info['symbol'];
2825                                }
2826                        }
2827
2828                        echo serialize($result);
2829                }
2830
2831                /*!
2832
2833                        @function get_cities
2834                        @abstract Echos a serialized array containing all the cities of a given state
2835                        @author Raphael Derosso Pereira
2836
2837                        @param $id_country The ID of the Country that has the specified Cities (in case the
2838                                Country doesn't have any States)
2839                        @param $id_state The ID of the State that has the Cities requested
2840
2841                */
2842                function get_cities($id_country, $id_state=false)
2843                {
2844                        $cities = $this->bo->catalog->get_all_cities($id_country, $id_state);
2845
2846                        if (!$cities)
2847                        {
2848                                $result = array(
2849                                        'msg'    => lang('No Cities found for this State.'),
2850                                        'status' => 'empty'
2851                                );
2852
2853                                echo serialize($result);
2854                                return;
2855                        }
2856
2857                        $result = array(
2858                                'msg'    => lang('Cities Successfully retrieved!'),
2859                                'status' => 'ok'
2860                        );
2861
2862                        foreach ($cities as $city_info)
2863                        {
2864                                $result['data'][$city_info['id_city']] = $city_info['name'];
2865                        }
2866
2867                        echo serialize($result);
2868                }
2869
2870                //Traduz o campo na busca completa por entradas no catálogo do usuário.
2871                function aux_full_search ($field,$isldap) {
2872                        $retorno = '';
2873                        if($isldap) {
2874                                switch($field) {
2875                                        case 'mail':
2876                                                $retorno = 'contact.connection.mail';
2877                                                break;
2878                                        case 'phone':
2879                                                $retorno = 'contact.connection.phone';
2880                                                break;
2881                                }
2882                        }
2883                        else {
2884                                switch($field) {
2885                                        case 'corporate':
2886                                                $retorno = 'contact.corporate_name';
2887                                                break;
2888                                        case 'mail':
2889                                        case 'phone':
2890                                                $retorno = 'contact.contact_connection.connection.connection_value';
2891                                                break;
2892                                }
2893                        }
2894                        return $retorno;
2895                }
2896
2897                /*!
2898
2899                        @function search
2900                        @abstract Echos a serialized array containing the IDs
2901                                of the entries that matches the search argument
2902                        @author Raphael Derosso Pereira
2903                        @author Mário César Kolling (external catalogs)
2904
2905                        @param string $str_data A serialized array with two informations:
2906                                $data = array(
2907                                        'search_for' => (string),
2908                                        'recursive'  => (boolean),
2909                                );
2910
2911                */
2912                // SERPRO
2913                function search($str_data)
2914                {
2915                        $data = unserialize($str_data);
2916                        // It's an external catalog?
2917                        $external = $this->bo->is_external($this->page_info['actual_catalog']);
2918                        $full_search = isset($data['full_search'])?$data['full_search']:false;
2919                       
2920                        if (!is_array($data) || (!$data['search_for'] && !$full_search) || !is_array($data['fields']))
2921                        {
2922                                echo serialize(array(
2923                                        'msg'    => lang('Invalid parameters'),
2924                                        'status' => 'abort'
2925                                ));
2926
2927                                return array('error' => lang('Invalid parameters'));
2928                        }
2929
2930
2931                        /*
2932                         * TODO: look into the database to discover the database's encoding and convert the search_for field accordingly
2933                         */
2934                        // Support search parameters with accentuation
2935                        if ($this->page_info['actual_catalog']['class'] != 'bo_people_catalog' &&
2936/**rev 104**/
2937                                //$this->page_info['actual_catalog']['class'] != 'bo_group_manager')
2938                                $this->page_info['actual_catalog']['class'] != 'bo_group_manager' &&
2939                                $this->page_info['actual_catalog']['class'] != 'bo_shared_people_manager' &&
2940                                $this->page_info['actual_catalog']['class'] != 'bo_shared_group_manager')
2941/****/
2942                        {
2943
2944                                $data['search_for'] = utf8_encode($data['search_for']);
2945                        }
2946
2947                        $rules  = array();
2948
2949                        if ($data['search_for'] === '*')
2950                        {
2951                                $rules = array(
2952                                        0 => array(
2953                                                'field' => $data['fields']['search'],
2954                                                'type'  => 'LIKE',
2955                                                'value' => '%'
2956                                        )
2957                                );
2958                        }
2959                        else
2960                        {
2961                                $names = explode(' ', $data['search_for']);
2962
2963                                if (!is_array($names))
2964                                {
2965                                        if(!$full_search) {
2966                                                echo serialize(array(
2967                                                        'msg'    => lang('Invalid Search Parameter'),
2968                                                        'status' => 'abort'
2969                                                ));
2970                                                exit;
2971                                        }
2972                                        else
2973                                                $names = array();
2974
2975                                }
2976
2977                                if (!$external && $this->page_info['actual_catalog']['class'] != 'bo_people_catalog' &&
2978/**rev 104**/
2979                                        //$this->page_info['actual_catalog']['class'] != 'bo_group_manager')
2980                                        $this->page_info['actual_catalog']['class'] != 'bo_group_manager' &&
2981                                        $this->page_info['actual_catalog']['class'] != 'bo_shared_people_manager' &&
2982                                        $this->page_info['actual_catalog']['class'] != 'bo_shared_group_manager' )
2983/*****/
2984                                {
2985                                        /*
2986                                         * Restrict the returned contacts search to objectClass = phpgwAccount,
2987                                         * must have attibute phpgwAccountStatus, phpgwAccountVisible != -1
2988                                         */
2989                                       
2990                                        $rules = array(
2991                                                0 => array(
2992                                                        'field' => 'contact.object_class',
2993                                                        'type'  => '=',
2994                                                        'value' => 'phpgwAccount'
2995                                                ),
2996                                                1 => array(
2997                                                        'field' => 'contact.account_status',
2998                                                        'type'  => 'iLIKE',
2999                                                        'value' => '%'
3000                                                ),
3001/**rev 104**/
3002                                                ///
3003                                                //1 => array(
3004                                                2 => array(
3005/*****/
3006                                                        'field' => 'contact.account_visible',
3007                                                        'type'  => '!=',
3008                                                        'value' => '-1'
3009/**rev 104**/
3010        /*                                      ),
3011                                                2 => array(
3012                                                        'field' => 'contact.object_class',
3013                                                        'type'  => '=',
3014                                                        'value' => 'inetOrgPerson'
3015/****/
3016                                                ),
3017                                        );
3018
3019                                        foreach($full_search as $field => $value) {
3020                                                if(trim($value)!='')
3021                                                        array_push($rules,array(
3022                                                                                        'field' => $this->aux_full_search($field,true),
3023                                                                                        'type' => 'LIKE',
3024                                                                                        'value' => '*'.$value.'*'
3025                                                                                        ));
3026                                        }
3027
3028                                }
3029                                else if(!$external) {
3030                                       
3031                                        foreach($full_search as $field => $value) {
3032                                                if(trim($value)!='')
3033                                                        array_push($rules,array(
3034                                                                                        'field' => $this->aux_full_search($field,false),
3035                                                                                        'type' => 'iLIKE',
3036                                                                                        'value' => '%'.$value.'%'
3037                                                                                        ));
3038                                        }
3039                               
3040                                }
3041
3042                                foreach ($names as $name)
3043                                {
3044                                        if ($name != '')
3045                                        {
3046                                                array_push($rules, array(
3047                                                        'field' => $data['fields']['search'],
3048                                                        'type'  => 'iLIKE',
3049                                                        'value' => '%'.$name.'%'
3050                                                ));
3051                                        }
3052                                }
3053                        }
3054
3055                        if ($external || $this->page_info['actual_catalog']['class'] == 'bo_people_catalog' ||
3056/**rev 104**/
3057                                //$this->page_info['actual_catalog']['class'] == 'bo_group_manager')
3058                                $this->page_info['actual_catalog']['class'] == 'bo_group_manager' ||
3059                                $this->page_info['actual_catalog']['class'] == 'bo_shared_people_manager' ||
3060                                $this->page_info['actual_catalog']['class'] == 'bo_shared_group_manager')
3061
3062
3063/***/
3064                        {
3065                                // Get only this attributes: dn, cn for external catalogs,
3066                                // used to restrict the attributes used in filters
3067                                $ids = $this->bo->find(array($data['fields']['id'], $data['fields']['search']), $rules, array('order' => $data['fields']['search'], 'sort' => 'ASC'), $data['search_for'] != null);
3068                        }
3069                        else
3070                        {
3071                                // Get only this attributes: dn, cn, phpgwAccountType, objectClass, phpgwAccountStatus, phpghAccountVisible
3072                                // for non-external catalogs, used to restrict the attributes used in filters
3073                                $ids = $this->bo->find(array(
3074                                        $data['fields']['id'],
3075                                        $data['fields']['search'],
3076                                        'contact.object_class',
3077                                        //'contact.account_status',
3078                                        'contact.account_visible',
3079                                        'contact.connection.mail',
3080                                        'contact.connection.phone'
3081                                        ), $rules, array('order' => $data['fields']['search'], 'sort' => 'ASC'), $data['search_for_area'], $data['search_for'] != null );
3082                        }
3083
3084                        if (!is_array($ids) || !count($ids))
3085                        {
3086                                $this->last_search_ids = null;
3087                                $this->save_session();
3088                                return null;
3089                        }
3090
3091                        $id_field = substr($data['fields']['id'], strrpos($data['fields']['id'], '.')+1);
3092
3093                        $ids_f = array();
3094
3095                        foreach ($ids as $e_info)
3096                        {
3097/**rev 104**/
3098                                //$ids_f[] = $e_info[$id_field];
3099                                if($this->page_info['actual_catalog']['class'] != 'bo_shared_people_manager' && $this->page_info['actual_catalog']['class'] != 'bo_shared_group_manager')
3100                                {
3101                                        $ids_f[] = $e_info[$id_field];
3102                                } else{
3103                                        $ids_f[] = array(0=>$e_info[$id_field],1=>$e_info['perms'],2=>$e_info['owner']);
3104                                }
3105/****/
3106                        }
3107
3108                        return $ids_f;
3109                }
3110
3111                // CELEPAR
3112                /*
3113        function search($str_data)
3114        {
3115            $data = unserialize($str_data);
3116
3117            if (!is_array($data) || !$data['search_for'] || !is_array($data['fields']))
3118            {
3119                echo serialize(array(
3120                    'msg'    => lang('Invalid parameters'),
3121                    'status' => 'abort'
3122                ));
3123
3124                return;
3125            }
3126
3127            $rules  = array();
3128
3129            if ($data['search_for'] === '*')
3130            {
3131                $rules = array(
3132                    0 => array(
3133                        'field' => $data['fields']['search'],
3134                        'type'  => 'LIKE',
3135                        'value' => '%'
3136                    )
3137                );
3138            }
3139            else
3140            {
3141                $names = explode(' ', $data['search_for']);
3142
3143                if (!is_array($names))
3144                {
3145                    echo serialize(array(
3146                        'msg'    => lang('Invalid Search Parameter'),
3147                        'status' => 'abort'
3148                    ));
3149
3150                    return;
3151                }
3152
3153                foreach ($names as $name)
3154                {
3155                    if ($name != '')
3156                    {
3157                        array_push($rules, array(
3158                            'field' => $data['fields']['search'],
3159                            'type'  => 'iLIKE',
3160                            'value' => '%'.$name.'%'
3161                        ));
3162                    }
3163                }
3164            }
3165
3166
3167
3168            //$catalog = $this->bo->get_branch_by_level($this->bo->catalog_level[0]);
3169
3170            //if ($catalog['class'] === 'bo_people_catalog')
3171            //{
3172            //    array_push($rules, array(
3173            //        'field' => 'contact.id_owner',
3174            //        'type'  => '=',
3175            //        'value' => $GLOBALS['phpgw_info']['user']['account_id']
3176            //    ));
3177            //}
3178
3179
3180            $ids = $this->bo->find(array($data['fields']['id'], $data['fields']['search']), $rules, array('order' => $data['fields']['search'], 'sort' => 'ASC'));
3181
3182            if (!is_array($ids) || !count($ids))
3183            {
3184                echo serialize(array(
3185                    'msg'    => lang('No Entries Found!'),
3186                    'status' => 'empty'
3187                ));
3188
3189                return;
3190            }
3191            $id_field = substr($data['fields']['id'], strrpos($data['fields']['id'], '.')+1);
3192
3193            $ids_f = array();
3194            foreach ($ids as $e_info)
3195            {
3196                $ids_f[] = $e_info[$id_field];
3197            }
3198
3199            echo serialize(array(
3200                'data'   => $ids_f,
3201                'msg'    => lang('Found %1 Entries', count($ids)),
3202                'status' => 'ok'
3203            ));
3204
3205                        return;
3206        }*/
3207                /*!
3208
3209                        @function get_multiple_entries
3210                        @abstract Returns an array containing the specifiend data in the default
3211                                CC UI format
3212                        @author Raphael Derosso Pereira
3213
3214                        @param array str_data A serialized array containing the ID's of the entries
3215                                to be taken, the fields to be taken and the rules to be used on the
3216                                retrieval:
3217                                $data = array(
3218                                        'ids'    => array(...),
3219                                        'fields' => array(...),
3220                                        'rules'  => array(...)
3221                                );
3222
3223                */
3224                function get_multiple_entries($str_data)
3225                {
3226                        $data = unserialize($str_data);
3227
3228                        if (!is_array($data) or !count($data) or !count($data['fields']) or !count($data['ids']))
3229                        {
3230                                return array(
3231                                        'msg'    => lang('Invalid Parameters'),
3232                                        'status' => 'abort'
3233                                );
3234                        }
3235
3236                        $entries = $this->bo->catalog->get_multiple_entries($data['ids'], $data['fields']);
3237
3238                        if (!is_array($entries) or !count($entries))
3239                        {
3240                                return array(
3241                                        'msg'    => lang('No Entries Found!'),
3242                                        'status' => 'empty'
3243                                );
3244                        }
3245
3246                        return array(
3247                                'msg'    => lang('Found %1 Entries!', count($entries)),
3248                                'status' => 'ok',
3249                                'data'   => $entries
3250                        );
3251                }
3252
3253                /*
3254
3255                        @function get_all_entries
3256                        @abstract Returns the specified fields for all catalog's entries
3257                                in the default CC UI format
3258                        @author Raphael Derosso Pereira
3259
3260                        @params array str_data A serialized array containing the fields to
3261                                be grabbed, the maximum number of entries to be returned and a
3262                                boolean specifying if the calls refers to a new grab or to an
3263                                unfinished one.
3264
3265                */
3266                function get_all_entries($str_data)
3267                {
3268                        $data = unserialize($str_data);
3269
3270                        if (!is_array($data) or
3271                            !count($data) or
3272                                !count($data['fields']) or
3273                                !$data['maxlength'] or
3274                                (!$data['new'] and !$data['offset']))
3275                        {
3276                                return array(
3277                                        'msg'    => lang('Invalid Parameters'),
3278                                        'status' => 'abort'
3279                                );
3280                        }
3281
3282                        if ($data['new'])
3283                        {
3284                                $this->all_entries = $this->bo->catalog->get_all_entries_ids();
3285
3286                                $this->save_session();
3287
3288                                if (!is_array($this->all_entries) or !count($this->all_entries))
3289                                {
3290                                        return array(
3291                                                'msg'    => lang('No Entries Found!'),
3292                                                'status' => 'empty'
3293                                        );
3294                                }
3295
3296                                $data['offset'] = 0;
3297                        }
3298
3299                        if ($data['maxlength'] != -1)
3300                        {
3301                                $result = $this->bo->catalog->get_multiple_entries(array_slice($this->all_entries, $data['offset'], $data['maxlength']), $data['fields']);
3302                        }
3303                        else
3304                        {
3305                                $result = $this->bo->catalog->get_multiple_entries($this->all_entries, $data['fields']);
3306                        }
3307
3308                        $prefs = ExecMethod('contactcenter.ui_preferences.get_preferences');
3309
3310                        $jsCode = array();
3311                        $count = 0;
3312                        foreach ($result as $each)
3313                        {
3314                                if (!is_array($each))
3315                                {
3316                                        continue;
3317                                }
3318
3319                                if($this-> typeContact == 'groups') {
3320
3321                                        foreach ($each as $field => $value)     {
3322
3323                                                if ($field === 'title') {
3324                                                        $optionName = '\\"'.$value.'\\"';
3325
3326                                                }
3327                                                else if ($field === 'short_name')       {
3328
3329                                                        $jsCode[] = '_this.entries.options[_this.entries.options.length] = new Option("'.$optionName.' ('.$value.')", "'.$count.'");';
3330                                                        $count++;
3331                                                }
3332                                        }
3333                                }
3334
3335                                else  {
3336                                        foreach ($each as $field => $value)     {
3337                                                if ($field === 'names_ordered') {
3338                                                         if(is_array($value))
3339                                $value = $value[0];
3340                                                        $name = '\\"'.$value.'\\"';
3341                                                }
3342                                                else if ($field === 'connections')      {
3343
3344                                                        foreach ($value as $connection)         {
3345                                                                if ($connection['id_type'] == $prefs['personCardEmail'])        {
3346                                                                        $jsCode[] = '_this.entries.options[_this.entries.options.length] = new Option("'.$name.' <'.$connection['connection_value'].'>", "'.$count.'");';
3347                                                                        $count++;
3348                                                                }
3349                                                        }
3350                                                }
3351                                        }
3352                                }
3353                        }
3354
3355                        $jsCodeFinal = implode("\n", $jsCode);
3356
3357                        $nEntries = count($result);
3358
3359                        if (!$nEntries)
3360                        {
3361                                return array(
3362                                        'msg'    => lang('Error while getting user information...'),
3363                                        'status' => 'abort'
3364                                );
3365                        }
3366
3367                        return array(
3368                                'msg'      => lang('Found %1 Entries!', $nEntries),
3369                                'status'   => 'ok',
3370                                'typeContact'   => $this -> typeContact,
3371                                'final'    => $nEntries + $data['offset'] < count($this->all_entries) ? false : true,
3372                                'offset'   => $data['offset'] + $nEntries,
3373                                'data'     => $jsCodeFinal
3374                        );
3375                }
3376
3377                /*********************************************************************\
3378                 *                      Auxiliar Methods                             *
3379                \*********************************************************************/
3380
3381                /*!
3382
3383                        @function save_session
3384                        @abstract Saves the data on the session
3385                        @author Raphael Derosso Pereira
3386
3387                */
3388                function save_session()
3389                {
3390                        $GLOBALS['phpgw']->session->appsession('ui_data.page_info','contactcenter',$this->page_info);
3391                        $GLOBALS['phpgw']->session->appsession('ui_data.all_entries','contactcenter',$this->all_entries);
3392                }
3393
3394                /*!
3395
3396                        @function convert_tree
3397                        @abstract Converts the tree array in the BO format to a JS tree array compatible
3398                                with the one available in eGW
3399                        @author Raphael Derosso Pereira
3400
3401                        @param (array)  $tree    The tree in the BO format
3402                        @param (string) $name    The tree name
3403                        @param (string) $iconDir The dir where the icons are
3404                        @param (string) $parent  The parent
3405                */
3406
3407                function convert_tree($tree, &$iconDir, $parent='0')
3408                {
3409//                      echo "Entrou<br>\tPai: $parent <br>";
3410                        $rtree = array();
3411
3412                        if ($parent === '0')
3413                        {
3414//                              echo 'Root!<br>';
3415                                $rtree['0'] = array(
3416                                        'type'       => 'catalog_group',
3417                                        'id'         => '0',
3418                                        'pid'        => 'none',
3419                                        'caption'    => lang('Catalogues'),
3420                                        'class'      => 'bo_catalog_group_catalog',
3421                                        'class_args' => array('_ROOT_', '$this', '$this->get_branch_by_level($this->catalog_level[0])')
3422                                );
3423                        }
3424
3425                        foreach($tree as $id => $value)
3426                        {
3427//                              echo 'ID: '.$id.'<br>';
3428                                $rtree[$parent.'.'.$id] = array(
3429                                        'type'    => $value['type'],
3430                                        'id'      => $parent.'.'.$id,
3431                                        'pid'     => $parent,
3432                                        'caption' => $value['name']
3433                                );
3434
3435                                switch($value['type'])
3436                                {
3437                                        case 'catalog_group':
3438                                        case 'mixed_catalog_group':
3439                                                $rtree = $rtree + $this->convert_tree($value['sub_branch'],$iconDir,$parent.'.'.$id);
3440                                                break;
3441                                }
3442                        }
3443
3444                        if (count($rtree))
3445                        {
3446                                return $rtree;
3447                        }
3448                }
3449
3450                function get_catalog_add_contact($id){
3451
3452                        $array_participants = array();
3453                        if(!$this->bo->catalog->src_info) {
3454                                $ldap = CreateObject('contactcenter.bo_ldap_manager');
3455                                $this->bo->catalog->src_info = $ldap->srcs[1];
3456                        }
3457
3458                        $ds = $GLOBALS['phpgw']->common->ldapConnect($this->bo->catalog->src_info['host'], $this->bo->catalog->src_info['acc'], $this->bo->catalog->src_info['pw'], true);
3459                        $dn=$this->bo->catalog->src_info['dn'];
3460                        $justThese = array("givenname","givenname","sn","telephonenumber","mail");
3461                        $sr = ldap_read($ds,$id, "objectClass=*",$justThese);
3462                        $info = ldap_get_entries($ds, $sr);
3463                        for($z = 0; $z < 5; $z++) {
3464                                $participant = $info[0][$justThese[$z]];
3465                                array_push($array_participants, $participant);
3466                        }
3467
3468                        ldap_close($ds);
3469                        echo serialize($array_participants);
3470                }
3471
3472                function get_catalog_participants_group($id)
3473                {
3474                        if(!$this->bo->catalog->src_info) {
3475                                $ldap = CreateObject('contactcenter.bo_ldap_manager');
3476                                $this->bo->catalog->src_info = $ldap->srcs[1];
3477                        }
3478                        $ds = $GLOBALS['phpgw']->common->ldapConnect($this->bo->catalog->src_info['host'], $this->bo->catalog->src_info['acc'], $this->bo->catalog->src_info['pw'], true);
3479                        $justThese = array("description","memberuid");
3480                        $sr = ldap_read($ds,$id, "objectClass=*",$justThese);
3481                        $info = ldap_get_entries($ds, $sr);
3482                        $member_uids = $info[0]['memberuid'];
3483                        $contact['names_ordered'] = $info[0]['description'];
3484                        $filter = "";
3485                        for($z = 0; $z < count($member_uids); $z++) {
3486                                if($member_uids[$z])
3487                                        $filter.="(uid=".$member_uids[$z].")";
3488                        }
3489                        $array_participants = array();
3490                        if($filter) {
3491                                $filter = "(|".$filter.")";
3492                                $valarray = explode(',',$id);
3493                                array_shift($valarray);
3494                                $dn = implode(',',$valarray);
3495                                $justThese = array("cn","mail");
3496                                $sr = ldap_search($ds,$dn, $filter,$justThese);
3497                                $info = ldap_get_entries($ds, $sr);
3498                                for($z = 0; $z < $info['count']; $z++) {
3499                                        $participant =  '<font color=\'DARKBLUE\'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;'.$info[$z]['cn'][0].'&quot; &lt;'.$info[$z]['mail'][0].'&gt;</font><br>';
3500                                    $array_emails[$info[$z]['mail'][0]] = null;
3501                                        array_push($array_participants, $participant);
3502                                }
3503                                ldap_close($ds);
3504                        }
3505                        sort($array_participants);
3506                        $innerHTML = '';
3507                        foreach($array_participants as $index => $participant){
3508                                $innerHTML .= $participant;
3509                        }
3510                        $return = array('size' => count($array_participants), 'names_ordered'=> $contact['names_ordered'], 'inner_html' => $innerHTML);
3511                        echo serialize($return);
3512                }
3513
3514                function get_catalog_participants_list($id)
3515                {
3516
3517                        $fields = $this->bo->catalog->get_fields(false);
3518                        $fields['names_ordered'] = true;
3519                        $fields['mail_forwarding_address'] = true;
3520                        $contact = $this->bo->catalog->get_single_entry($id,$fields);
3521
3522                        $array_participants = array();
3523                        $array_emails = array();
3524
3525                        $filter = null;
3526                        for($z = 0; $z < $contact['mail_forwarding_address']['count']; $z++) {
3527                                        if(strstr($contact['mail_forwarding_address'][$z],'@')) {
3528                                                $filter.="(mail=".$contact['mail_forwarding_address'][$z].")";
3529                                                $array_emails[$contact['mail_forwarding_address'][$z]] = "<font color=black>".$contact['mail_forwarding_address'][$z]."</font>";
3530                                        }
3531                                        else
3532                                                $array_participants[$z] = "<font color=red>".$contact['mail_forwarding_address'][$z]."</font>";
3533                        }
3534
3535                        if($filter) {
3536                                $filter = "(|".$filter.")";
3537                                if(!$this->bo->catalog->src_info) {
3538                                        $ldap = CreateObject('contactcenter.bo_ldap_manager');
3539                                        $this->bo->catalog->src_info = $ldap->srcs[1];
3540                                }
3541                                $ds = $GLOBALS['phpgw']->common->ldapConnect($this->bo->catalog->src_info['host'], $this->bo->catalog->src_info['acc'], $this->bo->catalog->src_info['pw'], true);
3542                                $dn=$this->bo->catalog->src_info['dn'];
3543                                $justThese = array("cn","mail");
3544                                $sr = ldap_search($ds,$dn, $filter,$justThese);
3545                                $info = ldap_get_entries($ds, $sr);
3546                                for($z = 0; $z < $info['count']; $z++) {
3547                                        $participant =  '<font color=\'DARKBLUE\'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;'.$info[$z]['cn'][0].'&quot; &lt;'.$info[$z]['mail'][0].'&gt;</font><br>';
3548                                        $array_emails[$info[$z]['mail'][0]] = null;
3549                                        array_push($array_participants, $participant);
3550                                }
3551
3552                                foreach($array_emails as $index => $email)
3553                                        if($email)
3554                                                array_push($array_participants, "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".$email."<br>");
3555
3556                                ldap_close($ds);
3557                        }
3558                        sort($array_participants);
3559                        $innerHTML = '';
3560                        foreach($array_participants as $index => $participant){
3561                                $innerHTML .= $participant;
3562                        }
3563                        $return = array('size' => count($array_participants), 'names_ordered'=> $contact['names_ordered'], 'inner_html' => $innerHTML);
3564                        echo serialize($return);
3565                }
3566
3567                function export_contacts($typeExport){
3568
3569                        $boGroup = CreateObject('contactcenter.bo_group');
3570                        $contacts = $boGroup->get_all_contacts();
3571                        $streamBuffer = '';
3572
3573                        if(!count($contacts))
3574                                echo null;
3575
3576                        switch($typeExport) {
3577
3578                                case 'outlook_en':
3579                                        $streamBuffer = "Name;E-mail Address;Notes;Mobile Phone;Pager;Company;".
3580                                                        "Job Title;Home Phone;Home Fax;Business Phone;Business Fax\r\n";                                                       
3581                                        foreach($contacts as $index => $object){
3582                                                $streamBuffer.= "\"".$object[ 'names_ordered'] . "\";"
3583                                                        . "\"".$object[ 'main-mail' ] . "\";"
3584                                                        . "\"".str_replace("\r\n\x0a","\t",$object[ 'notes' ]) . "\";"
3585                                                        . "\"".$object[ 'mobile' ] . "\";"
3586                                                        . "\"".$object[ 'business-pager' ] . "\";"
3587                                                        . "\"".$object[ 'corporate_name' ] . "\";"
3588                                                        . "\"".$object[ 'job_title' ] . "\";"
3589                                                        . "\"".$object[ 'home-phone' ] . "\";"
3590                                                        . "\"".$object[ 'home-fax' ] . "\";"
3591                                                        . "\"".$object[ 'business-phone' ] . "\";"
3592                                                        . "\"".$object[ 'business-fax' ] . "\"\r\n";
3593                                        }
3594                                        break;
3595
3596                                case 'outlook_pt-BR':
3597                                        $streamBuffer = "Nome;Sobrenome;Segundo nome;Nome;Apelido;End. de email;Endereço residencial;"
3598                                                                        ."Cidade do endereço residencial;CEP do endereço residencial;Estado;País/região do endereço residencial;"
3599                                                                        ."Telefone residencial;Fax residencial;Telefone celular;Página pessoal da Web;Rua do endereço comercial;"
3600                                                                        ."Cidade do endereço comercial;CEP do endereço comercial;Estado do endereço comercial;"
3601                                                                        ."País/região do endereço comercial;Página comercial da Web;Telefone comercial;Fax comercial;Pager;Empresa;"
3602                                                                        ."Cargo;Departamento;End. comercial;Observações\r\n";
3603
3604                                        foreach($contacts as $index => $object){
3605                                                $streamBuffer.= "\"".$object[ 'names_ordered'] . "\";"
3606                                                        .";;;"
3607                                                        . "\"".$object[ 'alias' ] . "\";"
3608                                                        . "\"".$object[ 'main-mail' ] . "\";"
3609                                                        . "\"".$object[ 'home-address' ] . "\";"
3610                                                        . "\"".$object[ 'home-city_name' ] . "\";"
3611                                                        . "\"".$object[ 'home-postal_code' ] . "\";"
3612                                                        . "\"".$object[ 'home-state_name' ] . "\";"
3613                                                        . "\"".$object[ 'home-id_country' ] . "\";"
3614                                                        . "\"".$object[ 'home-phone' ] . "\";"
3615                                                        . "\"".$object[ 'home-fax' ] . "\";"
3616                                                        . "\"".$object[ 'mobile' ] . "\";"
3617                                                        . "\"".$object[ 'web_page' ] . "\";"
3618                                                        . "\"".$object[ 'business-address' ] . "\";"
3619                                                        . "\"".$object[ 'business-city_name' ] . "\";"
3620                                                        . "\"".$object[ 'business-postal_code' ] . "\";"
3621                                                        . "\"".$object[ 'business-state_name' ] . "\";"
3622                                                        . "\"".$object[ 'business-id_country' ] . "\";"
3623                                                        . "\"".$object[ 'web_page' ] . "\";"
3624                                                        . "\"".$object[ 'business-phone' ] . "\";"
3625                                                        . "\"".$object[ 'business-fax' ] . "\";"
3626                                                        . "\"".$object[ 'business-pager' ] . "\";"
3627                                                        . "\"".$object[ 'corporate_name' ] . "\";"
3628                                                        . "\"".$object[ 'job_title' ] . "\";"
3629                                                        . "\"".$object[ 'department' ] . "\";"
3630                                                        .";"
3631                                                        . "\"".str_replace("\r\n\x0a","\t",$object[ 'notes' ]) . "\"\r\n";
3632                                        }
3633
3634                                break;
3635
3636                                case 'outlook2000_pt-BR':
3637                                        $streamBuffer = "\"Tratamento\",\"Nome\",\"Segundo Nome\",\"Sobrenome\",\"Sufixo\",".
3638                                        "\"Empresa\",\"Departamento\",\"Cargo\",\"Rua do endereço comercial\",\"Rua do endereço comercial 2\",".
3639                                        "\"Rua do endereço comercial 3\",\"Cidade do endereço comercial\",\"Estado do endereço comercial\",".
3640                                        "\"CEP do endereço comercial\",\"País do endereço comercial\",\"Endereço residencial\",\"Rua residencial 2\",".
3641                                        "\"Rua residencial 3\",\"Cidade do endereço residencial\",\"Estado\",\"CEP do endereço residencial\",\"País do endereço residencial\",".
3642                                        "\"Outro endereço\",\"Outro endereço 2\",\"Outro endereço 3\",\"Cidade\",\"Estado\",\"CEP\",\"País\",".
3643                                        "\"Telefone do assistente\",\"Fax comercial\",\"Telefone comercial\",\"Telefone comercial 2\",\"Retorno de chamada\",".
3644                                        "\"Telefone do carro\",\"Telefone principal da empresa\",\"Fax residencial\",\"Telefone residencial\",".
3645                                        "\"Telefone residencial 2\",\"ISDN\",\"Telefone celular\",\"Outro fax\",\"Outro telefone\",\"Pager\",\"Telefone principal\",".
3646                                        "\"Radiofone\",\"Telefone TTY/TDD\",\"Telex\",\"Aniversário\",\"Anotações\",\"Caixa postal\",\"Categorias\",".
3647                                        "\"Código da empresa\",\"Código do governo\",\"Cônjuge\",\"Conta\",\"Endereço de correio eletrônico\",".
3648                                        "\"Nome de exibição do correio eletr.\",\"Endereço de correio eletrônico 2\",".
3649                                        "\"Nome de exibição do correio eletr.2\",\"Endereço de correio eletrônico 3\",".
3650                                        "\"Nome de exibição do correio eletr.3\",\"Datas especiais\",\"Disponibilidade da Internet\",".
3651                                        "\"Filhos\",\"Hobby\",\"Idioma\",\"Indicação\",\"Informações para cobrança\",\"Iniciais\",\"Local\",".
3652                                        "\"Nome do assistente\",\"Nome do gerenciador\",\"Página da Web\",\"Palavras-chave\",\"Particular\",\"Personalizado 1\",\"Personalizado 2\",".
3653                                        "\"Personalizado 3\",\"Personalizado 4\",\"Prioridade\",\"Profissão\",\"Quilometragem\",\"Sala\",\"Sensibilidade\",\"Servidor de diretório\",".
3654                                        "\"Sexo\"\r\n";
3655
3656
3657
3658                                        foreach($contacts as $index => $object){
3659                                $streamBuffer .= "\"".$object[ 'alias' ] . "\","                                   
3660                                                                . "\"".$object[ 'names_ordered' ] . "\","
3661                                                                .",,,"
3662                                                                . "\"".$object[ 'corporate_name' ] . "\","
3663                                                                . "\"".$object[ 'department' ] . "\","
3664                                                                . "\"".$object[ 'job_title' ] . "\","
3665                                                                . "\"".$object[ 'business-address' ] . "\","
3666                                                                . "\"".$object[ 'business-address-2' ] . "\","
3667                                                                .","
3668                                                                . "\"".$object[ 'business-city_name' ] . "\","
3669                                                                . "\"".$object[ 'business-state' ] . "\","
3670                                                                . "\"".$object[ 'business-postal_code' ] . "\","
3671                                                                . "\"".$object[ 'business-id_country' ] . "\","
3672                                                                . "\"".$object[ 'home-address' ] . "\","
3673                                                                . "\"".$object[ 'home-address-2' ] . "\","
3674                                                                .","
3675                                                                . "\"".$object[ 'home-city_name' ] . "\","
3676                                                                . "\"".$object[ 'home-state_name' ] . "\","
3677                                                                . "\"".$object[ 'home-postal_code' ] . "\","
3678                                                                . "\"".$object[ 'home-id_country' ] . "\","
3679                                                                .",,,,,,,,"
3680                                                                . "\"".$object[ 'business-fax' ] . "\","
3681                                                                . "\"".$object[ 'business-phone' ] . "\","
3682                                                                . "\"".$object[ 'business-mobile' ] . "\","
3683                                                                .",,,"
3684                                                                . "\"".$object[ 'home-fax' ] . "\","
3685                                                                . "\"".$object[ 'home-phone' ] . "\","
3686                                                                .",,"
3687                                                                . "\"".$object[ 'mobile' ] . "\","
3688                                                                .",,"
3689                                                                . "\"".$object[ 'home-pager' ] . "\","
3690                                                                . "\"".$object[ 'business-phone' ] . "\","
3691                                                                .",,,"
3692                                                                . "\"".$object[ 'birthdate' ] . "\","
3693                                                                . "\"".str_replace("\r\n\x0a","\t",$object[ 'notes' ]) . "\","
3694                                                                .",,,,,,"
3695                                                                . "\"".$object[ 'main-mail' ] . "\","
3696                                                                .","
3697                                                                . "\"".$object[ 'alternative-mail' ] . "\","
3698                                                                .",,,,,,,,,,,,,,"
3699                                                                . "\"".$object[ 'web_page' ] . "\","
3700                                                                .",,,,,,,,,,,,"
3701                                                                . "\"".$object[ 'sex' ] . "\"\r\n";                                                             
3702                            }
3703                                break;
3704
3705                                case 'outlook2000_en':
3706                                        $streamBuffer = "Title,First Name,Middle Name,Last Name,Suffix,Company,Department,Job Title,".
3707                                        "Business Street,Business Street 2,Business Street 3,Business City,Business State,Business Postal Code,".
3708                                        "Business Country,Home Street,Home Street 2,Home Street 3,Home City,Home State,Home Postal Code,Home Country,".
3709                                        "Other Street,Other Street 2,Other Street 3,Other City,Other State,Other Postal Code,Other Country,".
3710                                        "Assistant's Phone,Business Fax,Business Phone,Business Phone 2,Callback,Car Phone,Company Main Phone,Home Fax,".
3711                                        "Home Phone,Home Phone 2,ISDN,Mobile Phone,Other Fax,Other Phone,Pager,Primary Phone,Radio Phone,TTY/TDD Phone,Telex,".
3712                                        "Account,Anniversary,Assistant's Name,Billing Information,Birthday,Categories,Children,Directory Server,E-mail Address,".
3713                                        "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,".
3714                                        "Gender,Government ID Number,Hobby,Initials,Internet Free Busy,Keywords,Language,Location,Manager's Name,Mileage,Notes,".
3715                                        "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";
3716
3717                                        foreach($contacts as $index => $object){
3718                                                $streamBuffer.= "\"".$object[ 'alias' ] . "\","
3719                                                        . "\"".$object[ 'names_ordered'] . "\","
3720                                                        .",,,"
3721                                                        . "\"".$object[ 'corporate_name' ] . "\","
3722                                                        . "\"".$object[ 'department' ] . "\","
3723                                                        . "\"".$object[ 'job_title' ] . "\","
3724                                                        . "\"".$object[ 'business-address' ] . "\","
3725                                                        . "\"".$object[ 'business-address-2' ] . "\","
3726                                                        .","
3727                                                        . "\"".$object[ 'business-city_name' ] . "\","
3728                                                        . "\"".$object[ 'business-state' ] . "\","
3729                                                        . "\"".$object[ 'business-postal_code' ] . "\","
3730                                                        . "\"".$object[ 'business-id_country' ] . "\","
3731                                                        . "\"".$object[ 'home-address' ] . "\","
3732                                                        . "\"".$object[ 'home-address-2' ] . "\","
3733                                                        .","
3734                                                        . "\"".$object[ 'home-city_name' ] . "\","
3735                                                        . "\"".$object[ 'home-state_name' ] . "\","
3736                                                        . "\"".$object[ 'home-postal_code' ] . "\","
3737                                                        . "\"".$object[ 'home-id_country' ] . "\","
3738                                                        .",,,,,,,,"
3739                                                        . "\"".$object[ 'business-fax' ] . "\","
3740                                                        . "\"".$object[ 'business-phone' ] . "\","
3741                                                        . "\"".$object[ 'business-mobile' ] . "\","
3742                                                        .",,,"
3743                                                        . "\"".$object[ 'home-fax' ] . "\","
3744                                                        . "\"".$object[ 'home-phone' ] . "\","
3745                                                        .",,"
3746                                                        . "\"".$object[ 'mobile' ] . "\","
3747                                                        .",,"
3748                                                        . "\"".$object[ 'business-pager' ] . "\","
3749                                                        . "\"".$object[ 'home-pager' ] . "\","
3750                                                        .",,,,,,,,"
3751                                                        . "\"".$object[ 'birthdate' ] . "\","
3752                                                        .",,,"
3753                                                        . "\"".$object[ 'main-mail' ] . "\","
3754                                                        .",,"
3755                                                        . "\"".$object[ 'alternative-mail' ] . "\","
3756                                                        .",,,,,,,,,,,,,,,"
3757                                                        . "\"".str_replace("\r\n\x0a","\t",$object[ 'notes' ]) . "\","
3758                                                        .",,,,,,,,,,,,,"
3759                                                        . "\"".$object[ 'web_page' ] . "\"\r\n";
3760
3761                                        }
3762                                break;
3763
3764                                case 'thunderbird':
3765                                        $streamBuffer = "First Name,Last Name,Display Name,Nickname,Primary Email,Secondary Email,"
3766                                                ."Screen Name,Work Phone,Home Phone,Fax Number,Pager Number,Mobile Number,Home Address,"
3767                                                ."Home Address 2,Home City,Home State,Home ZipCode,Home Country,Work Address,Work Address 2,"
3768                                                ."Work City,Work State,Work ZipCode,Work Country,Job Title,Department,Organization,Web Page 1,"
3769                                                ."Web Page 2,Birth Year,Birth Month,Birth Day,Custom 1,Custom 2,Custom 3,Custom 4,Notes,\n";
3770
3771                                        foreach($contacts as $index => $object){
3772                                                $array_birth = explode("-",$object[ 'birthdate' ]);
3773                                                $streamBuffer.= "\"".$object[ 'names_ordered'] . "\","
3774                                                        .",,"
3775                                                        . "\"".$object[ 'alias' ] . "\","
3776                                                        . "\"".$object[ 'main-mail' ] . "\","
3777                                                        . "\"".$object[ 'alternative-mail' ] . "\","
3778                                                        .","
3779                                                        . "\"".$object[ 'business-phone' ] . "\","
3780                                                        . "\"".$object[ 'home-phone' ] . "\","
3781                                                        . "\"".$object[ 'business-fax' ] . "\","
3782                                                        . "\"".$object[ 'business-pager' ] . "\","
3783                                                        . "\"".$object[ 'mobile' ] . "\","
3784                                                        . "\"".$object[ 'home-address' ] . "\","
3785                                                        . "\"".$object[ 'home-address-2' ] . "\","
3786                                                        . "\"".$object[ 'home-city_name' ] . "\","
3787                                                        . "\"".$object[ 'home-state_name' ] . "\","
3788                                                        . "\"".$object[ 'home-postal_code' ] . "\","
3789                                                        . "\"".$object[ 'home-id_country' ] . "\","
3790                                                        . "\"".$object[ 'business-address' ] . "\","
3791                                                        . "\"".$object[ 'business-address-2' ] . "\","
3792                                                        . "\"".$object[ 'business-city_name' ] . "\","
3793                                                        . "\"".$object[ 'business-state_name' ] . "\","
3794                                                        . "\"".$object[ 'business-postal_code' ] . "\","
3795                                                        . "\"".$object[ 'business-id_country' ] . "\","
3796                                                        . "\"".$object[ 'job_title' ] . "\","
3797                                                        . "\"".$object[ 'department' ] . "\","
3798                                                        . "\"".$object[ 'corporate_name' ] . "\","
3799                                                        . "\"".$object[ 'web_page' ] . "\","
3800                                                        . "\"".$object[ 'web_page' ] . "\","
3801                                                        . "\"".$array_birth[0] . "\","
3802                                                        . "\"".$array_birth[1] . "\","
3803                                                        . "\"".$array_birth[2] . "\","
3804                                                        .",,,,"
3805                                                        . "\"".str_replace("\r\n\x0a","\t",$object[ 'notes' ]) . "\",\r\n";
3806
3807                                        }
3808                                break;
3809
3810                                case 'expresso':
3811                            $streamBuffer = 'Nome,Apelido,E-mail Principal,E-mail Alternativo,Celular,'
3812                                . 'Telefone Comercial,Endereço Comercial,Complemento End. Comercial,CEP Comercial,Cidade End. Comercial,Estado End. Comercial,País End. Comercial,'
3813                                . 'Telefone Residencial,Endereço Residencial,Complemento End. Residencial,CEP Residencial,Cidade End. Residencial,Estado End. Residencial,País End. Residencial,'
3814                                . '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'
3815                                                        . "\r\n";
3816
3817                            foreach($contacts as $index => $object){
3818                                $streamBuffer .= "\"".$object[ 'names_ordered'] . "\","
3819                                    . "\"".$object[ 'alias' ] . "\","
3820                                    . "\"".$object[ 'main-mail' ] . "\","
3821                                    . "\"".$object[ 'alternative-mail' ] . "\","
3822                                    . "\"".$object[ 'mobile' ] . "\","
3823                                    . "\"".$object[ 'business-phone' ] . "\","
3824                                    . "\"".$object[ 'business-address' ] . "\","
3825                                    . "\"".$object[ 'business-complement' ] . "\","
3826                                    . "\"".$object[ 'business-postal_code' ] . "\","
3827                                    . "\"".$object[ 'business-city_name' ] . "\","
3828                                    . "\"".$object[ 'business-state_name' ] . "\","
3829                                    . "\"".$object[ 'business-id_country' ] . "\","
3830                                    . "\"".$object[ 'home-phone' ] . "\","
3831                                    . "\"".$object[ 'home-address' ] . "\","
3832                                    . "\"".$object[ 'home-complement' ] . "\","
3833                                    . "\"".$object[ 'home-postal_code' ] . "\","
3834                                    . "\"".$object[ 'home-city_name' ] . "\","
3835                                    . "\"".$object[ 'home-state_name' ] . "\","
3836                                    . "\"".$object[ 'home-id_country' ] . "\","
3837                                                                . "\"".$object[ 'birthdate' ] . "\","
3838                                                                . "\"".$object[ 'sex' ] . "\","
3839                                                                . "\"".$object[ 'pgp_key' ] . "\","
3840                                                                . "\"".str_replace("\r\n\x0a","\t",$object[ 'notes' ]) . "\","
3841                                                                . "\"".$object[ 'web_page' ] . "\","
3842                                                                . "\"".$object[ 'corporate_name' ] . "\","
3843                                                                . "\"".$object[ 'job_title' ] . "\","
3844                                                                . "\"".$object[ 'department' ] . "\","
3845                                                                . "\"".$object[ 'business-fax' ] . "\","
3846                                                                . "\"".$object[ 'business-pager' ] . "\","
3847                                                                . "\"".$object[ 'business-mobile' ] . "\","
3848                                                                . "\"".$object[ 'home-fax' ] . "\","
3849                                                                . "\"".$object[ 'home-pager' ] . "\","
3850                                                                . "\"".$object[ 'business-address-2' ] . "\","
3851                                                                . "\"".$object[ 'home-address-2' ] . "\"\r\n";
3852                            }
3853                        break;
3854
3855                        }
3856
3857                        $file = "contacts_".md5(microtime()).".swp";
3858                        $tempDir = ini_get("session.save_path");
3859                        $f = fopen($tempDir.'/'.$file,"w");
3860                        if(!$f)
3861                                echo null;
3862
3863                        fputs($f,$streamBuffer);
3864                        fclose($f);
3865
3866                        echo $tempDir.'/'.$file;
3867                }
3868
3869                // Get the csv field and put into array, from php.net
3870                function parse_line($input_text, $delimiter = ',', $text_qualifier = '"') {
3871                        $text = trim($input_text);
3872                          if(is_string($delimiter) && is_string($text_qualifier)) {
3873                         $re_d = '\x' . dechex(ord($delimiter));            //format for regexp
3874                        $re_tq = '\x' . dechex(ord($text_qualifier));    //format for regexp
3875
3876                        $fields = array();
3877                        $field_num = 0;
3878                        while(strlen($text) > 0) {
3879                        if($text{0} == $text_qualifier) {
3880                                preg_match('/^' . $re_tq . '((?:[^' . $re_tq . ']|(?<=\x5c)' . $re_tq . ')*)' . $re_tq . $re_d . '?(.*)$/', $text, $matches);
3881
3882                                $value = str_replace('\\' . $text_qualifier, $text_qualifier, $matches[1]);
3883                                $text = trim($matches[2]);
3884
3885                                $fields[$field_num++] = $value;
3886                        } else {
3887                                preg_match('/^([^' . $re_d . ']*)' . $re_d . '?(.*)$/', $text, $matches);
3888
3889                                $value = $matches[1];
3890                                $text = trim($matches[2]);
3891
3892                                $fields[$field_num++] = $value;
3893                }
3894                }
3895                        return $fields;
3896                    } else
3897                        return false;
3898                }
3899
3900                //funcao alterada para importar outros campos alem de nome, telefone e email, de arquivo csv (Outlook 2000)
3901                //em 08/04/2009 - Rommel Cysne (rommel.cysne@serpro.gov.br);
3902                //Foi adicionada uma funcao (escapesheelcmd()) nas variaveis para que caracteres especiais sejam ignorados
3903                //durante a importacao dos contatos; o processo estava travando por causa de caracteres em campos como nome,
3904                //sobrenome, notas e e-mail;
3905                //em 19/06/2009 - Rommel Cysne (rommel.cysne@serpro.gov.br);
3906                function import_contacts($typeImport){
3907                        $this->so_group = CreateObject('contactcenter.so_group');
3908                        if($file = $_SESSION['contactcenter']['importCSV']) {
3909                                unset($_SESSION['contactcenter']['importCSV']);
3910                                $len = filesize($file);
3911                                $count = 0;
3912                                $return = array('error' => false, '_new' => 0, '_existing' => 0, '_failure' => 0);
3913                                $handle = @fopen($file, "r") or die(serialize($return['error'] = true));
3914
3915                                $input_header = fgets($handle);
3916                                if ($typeImport == 'outlook')
3917                                        $delim = ';';
3918                                else if ($typeImport == 'auto')
3919                                $delim = strstr($input_header,',') ? ',' : ';';
3920                                else
3921                                        $delim = ',';
3922                                $csv_header = $this->parse_line($input_header,$delim);
3923                                $firstContact = fgets($handle);
3924                                preg_match("/\"(.+)\"[,;]/sU",$firstContact,$matches); // yahoo csv
3925                                rewind($handle);
3926
3927                                $header = @fgetcsv($handle, $len, $delim) or die(serialize($return['error'] = true));
3928                                if(count($header)  < 2 || count($header) > 100) {
3929                                        $return['error'] = true;
3930                                        $return['sizeheader'] = count($header);
3931                                        echo serialize($return);
3932                                        return;
3933                                }
3934
3935                                if ($matches[0][strlen($matches[0])-1] == ';')
3936                                        $delim = ';';
3937
3938                                $boGroup = CreateObject('contactcenter.bo_group');
3939                                $boPeople = CreateObject('contactcenter.bo_people_catalog');
3940                                        switch($typeImport){
3941                                                case 'outlook2000':
3942                                                        $name_pos=1;
3943                                                        $name2_pos=2;
3944                                                        $name3_pos=3;
3945                                                        $corporate_street_pos=8;
3946                                                        $cep_pos=13;
3947                                                        $corporate_street_2_pos=22;
3948                                                        $fax_pos=30;
3949                                                        $phone_pos=31;
3950                                                        $home_phone_pos=37;
3951                                                        $personal_cell_pos=40;
3952                                                        $pager_pos=43;
3953                                                        $birth_pos=48;
3954                                                        $notes_pos=49;
3955                                                        $email_pos=56;
3956                                                        $aditionalEmail_pos=59;
3957
3958                                                        break;
3959                                                case 'outlook':
3960                                                        $name_pos=3;
3961                                                        $email_pos=4;
3962                                                        $phone_pos=7;
3963                                                        $home_phone_pos=10;
3964                                                        $personal_cell_pos=12;
3965                                                        $corporate_street_pos=13;
3966                                                        $cep_pos=15;
3967                                                        $phone_pos=18;
3968                                                        $fax_pos=19;
3969                                                        $pager_pos=20;
3970                                                        $notes_pos=25;
3971                                                        break;
3972                                                case 'thunderbird':
3973                                                        $name_pos=2;
3974                                                        $email_pos=4;
3975                                                        $phone_pos=7;
3976                                                        break;
3977                                                case 'expresso':
3978                                                        $name_pos=0;
3979                                                        $alias_pos=1;
3980                                                        $email_pos=2;
3981                                                        $aditionalEmail_pos=3;
3982                                                        $personal_cell_pos=4;
3983                                                        $corporate_phone_pos=5;
3984                                                        $corporate_street_pos=6;
3985                                                        $corporate_comp_pos=7;
3986                                                        $corporate_cep_pos=8;
3987                                                        $corporate_city_pos=9;
3988                                                        $corporate_state_pos=10;
3989                                                        $corporate_country_pos=11;
3990                                                        $home_phone_pos=12;
3991                                                        $street_pos=13;
3992                                                        $comp_pos=14;
3993                                                        $cep_pos=15;
3994                                                        $city_pos=16;
3995                                                        $state_pos=17;
3996                                                        $country_pos=18;
3997                                                        $birth_pos=19;
3998                                                        $sex_pos = 20;
3999                                                        $pgp_key_pos = 21;
4000                                                        $notes_pos=22;
4001                                                        $web_page_pos=23;
4002                                                        $corporate_name_pos=24;
4003                                                        $job_title_pos=25;
4004                                                        $department_pos=26;
4005                                                        $corporate_fax_pos=27;
4006                                                        $corporate_pager_pos=28;
4007                                                        $corporate_cell_pos=29;
4008                                                        $fax_pos=30;
4009                                                        $pager_pos=31;
4010                                                        $corporate_street_2_pos = 32;
4011                                                        $street_2_pos = 33;                                             
4012                                                        break;
4013                                        default:
4014                                                        foreach($csv_header as $index => $fieldName)
4015                                                        {
4016                                                                switch($fieldName){
4017                                                                case 'Name':
4018                                                                case 'Nome':
4019                                                                case 'First Name':
4020                                                                        $name_pos = $index;
4021                                                                        break;
4022                                                                case 'Second name':
4023                                                                case 'Segundo nome':
4024                                                                        $name2_pos = $index;
4025                                                                        break;
4026                                                                case 'Sobrenome':
4027                                                                case 'Surname':
4028                                                                        $name3_pos = $index;
4029                                                                        break;
4030                                                                case 'Business Street':
4031                                                                case 'Rua do endereço comercial':
4032                                                                        $corporate_street_pos = $index;
4033                                                                        break;
4034                                                                case 'Rua do endereço comercial 2':
4035                                                                case 'Outro endereço':
4036                                                                        $corporate_street_2_pos = $index;
4037                                                                        break;
4038                                                                case 'Business Postal Code':
4039                                                                case 'CEP do endereço comercial':
4040                                                                        $cep_pos = $index;
4041                                                                        break;
4042                                                                case 'Business Fax':
4043                                                                case 'Fax comercial':
4044                                                                case 'Fax':
4045                                                                        $fax_pos = $index;
4046                                                                        break;
4047                                                                case 'Home Phone':
4048                                                                case 'Telefone residencial':
4049                                                                        $home_phone_pos = $index;
4050                                                                        break;
4051                                                                case 'Mobile phone':
4052                                                                case 'Telefone celular':
4053                                                                        $personal_cell_pos = $index;
4054                                                                        break;
4055                                                                case 'Pager':
4056                                                                        $pager_pos = $index;
4057                                                                        break;
4058                                                                case 'Phone':
4059                                                                case 'Business Phone':
4060                                                                case 'Telefone':
4061                                                                case 'Telefone principal':
4062                                                                case 'Telefone comercial':
4063                                                                        $phone_pos = $index;
4064                                                                        break;
4065                                                                case 'Aniversário':
4066                                                                case 'Birthdate':
4067                                                                        $birth_pos = $index;
4068                                                                case 'Anotações':
4069                                                                case 'Notes':
4070                                                                        $notes_pos = $index;
4071                                                                case 'E-mail':
4072                                                                case 'Email':
4073                                                                case 'E-mail Address':
4074                                                                case 'Endereço de correio eletrônico':
4075                                                                case 'End. de email':
4076                                                                        $email_pos = $index;
4077                                                                        break;
4078                                                                case 'Endereço de correio eletrônico 2':
4079                                                                        $aditionalEmail_pos = $index;
4080                                                                        break;
4081                                                                }
4082                                                        }
4083                                                        break;
4084                                }
4085
4086                                while (($data = fgetcsv($handle, $len, $delim))) {
4087                                        foreach ($header as $key=>$heading)
4088                                $row[$heading]=(isset($data[$key])) ? $data[$key] : '';
4089
4090                                                $sdata = array();
4091                                                $full_name  = trim($row[$header[$name_pos]]);
4092                                                $email          = trim($row[$header[$email_pos]]);
4093                                                $phone          = trim($row[$header[$phone_pos]]);
4094                                                $name2          = trim($row[$header[$name2_pos]]);
4095                                                $name3          = trim($row[$header[$name3_pos]]);
4096
4097                                                $birth          = trim($row[$header[$birth_pos]]);
4098                                                $notes          = trim($row[$header[$notes_pos]]);
4099                                                $altEmail       = trim($row[$header[$altEmail_pos]]);
4100                                                $sdata['alias']                         = trim($row[$header[$alias_pos]]);
4101                                                $sdata['corporate_name']      = trim($row[$header[$corporate_name_pos]]);
4102                                                $sdata['job_title']             = trim($row[$header[$job_title_pos]]);
4103                                                $sdata['department']            = trim($row[$header[$department_pos]]);
4104                                                $sdata['web_page']                      = trim($row[$header[$web_page_pos]]);
4105                                               
4106                                                $sdata['sex']                   = trim($row[$header[$sex_pos]]);
4107                                                $sdata['pgp_key']      = trim($row[$header[$pgp_key_pos]]);
4108
4109
4110                                        $full_name = $full_name;
4111                                        $array_name = explode(' ', str_replace('"','',(str_replace('\'','',$full_name))));
4112                                        $sdata['given_names'] = $array_name[0];
4113                                        $array_name[0] = null;
4114                                        $sdata['family_names'] = trim(implode(' ',$array_name));
4115                                        if($sdata['family_names'] == '')
4116                                        {
4117                                                $sdata['family_names'] = $name2 . " " . $name3;
4118                                        }
4119                                                $sdata['connections']['default_email']['connection_name'] = lang('Main');
4120                                                $sdata['connections']['default_email']['connection_value'] = $email;
4121                                                $sdata['connections']['aditional_email']['connection_name'] = "Alternativo";
4122                                                $sdata['connections']['aditional_email']['connection_value'] = trim($row[$header[$aditionalEmail_pos]]);
4123
4124                                                $sdata['connections']['default_phone']['connection_name'] = lang('Main');
4125                                                $sdata['connections']['default_phone']['connection_value'] = $phone;
4126
4127                                                $sdata['connections']['aditional_phone']['cellphone']['connection_name'] = 'Celular';
4128                                                $sdata['connections']['aditional_phone']['cellphone']['connection_value'] = trim($row[$header[$personal_cell_pos]]);
4129                                               
4130                                                $sdata['connections']['aditional_phone']['corporate_phone']['connection_name'] = 'Trabalho';
4131                                                $sdata['connections']['aditional_phone']['corporate_phone']['connection_value'] = trim($row[$header[$corporate_phone_pos]]);
4132                                               
4133                                                $sdata['connections']['aditional_phone']['fax']['connection_name'] = 'Fax';
4134                                                $sdata['connections']['aditional_phone']['fax']['connection_value'] = trim($row[$header[$fax_pos]]);
4135                                               
4136                                                $sdata['connections']['aditional_phone']['corporate_fax']['connection_name'] = 'Fax Corporativo';
4137                                                $sdata['connections']['aditional_phone']['corporate_fax']['connection_value'] = trim($row[$header[$corporate_fax_pos]]);
4138                                                                                               
4139                                                $sdata['connections']['aditional_phone']['corporate_cell']['connection_name'] = 'Celular Corporativo';
4140                                                $sdata['connections']['aditional_phone']['corporate_cell']['connection_value'] = trim($row[$header[$corporate_cell_pos]]);
4141                                               
4142                                                $sdata['connections']['aditional_phone']['corporate_pager']['connection_name'] = 'Pager Corporativo';
4143                                                $sdata['connections']['aditional_phone']['corporate_pager']['connection_value'] = trim($row[$header[$corporate_pager_pos]]);
4144                                                                                                                               
4145                                               
4146                                                $sdata['connections']['aditional_phone']['home_phone']['connection_name'] = 'Casa';
4147                                                $sdata['connections']['aditional_phone']['home_phone']['connection_value'] = trim($row[$header[$home_phone_pos]]);
4148                                               
4149                                                $sdata['connections']['aditional_phone']['pager']['connection_name'] = 'Pager';
4150                                                $sdata['connections']['aditional_phone']['pager']['connection_value'] = trim($row[$header[$pager_pos]]);
4151
4152                                                $sdata['addresses']['address_corporative']['address1'] = trim($row[$header[$corporate_street_pos]]);
4153                                                $sdata['addresses']['address_corporative']['address2'] = trim($row[$header[$corporate_street_2_pos]]);
4154                                                $sdata['addresses']['address_corporative']['complement'] = trim($row[$header[$corporate_comp_pos]]);
4155                                                $sdata['addresses']['address_corporative']['postal_code'] = trim($row[$header[$corporate_cep_pos]]);                                           
4156                                                $sdata['addresses']['address_corporative']['id_country'] = "BR";
4157                                                $sdata['addresses']['address_corporative']['id_state'] = trim($row[$header[$corporate_state_pos]]);     
4158                                                $sdata['addresses']['address_corporative']['id_city'] = trim($row[$header[$corporate_city_pos]]);
4159                                               
4160                                                                                                       
4161                                                $sdata['addresses']['address_personal']['address1'] = trim($row[$header[$street_pos]]);
4162                                                $sdata['addresses']['address_personal']['address2'] = trim($row[$header[$street_2_pos]]);
4163                                                $sdata['addresses']['address_personal']['complement'] = trim($row[$header[$comp_pos]]);
4164                                                $sdata['addresses']['address_personal']['postal_code'] = trim($row[$header[$cep_pos]]);
4165                                                $sdata['addresses']['address_personal']['id_country'] = "BR";                                                   
4166                                                $sdata['addresses']['address_personal']['id_state'] = trim($row[$header[$state_pos]]); 
4167                                                $sdata['addresses']['address_personal']['id_city'] =  trim($row[$header[$city_pos]]);
4168
4169                                        $array_birth = explode("/",$birth);
4170
4171                                        $sdata['birthdate'] = date('Y-m-d', mktime(0,0,0,$array_birth[1],$array_birth[0],$array_birth[2]));
4172
4173                                        $sdata['notes'] = $notes;
4174                                        //$sdata['is_quick_add'] = true;
4175                                        $sdata['connections']['default_phone']['connection_value'] = $phone;
4176
4177                                        //      verifica se email já existe!
4178                                        $email = $email;
4179                                        $contact = $boGroup->verify_contact($email);
4180
4181                                        if(!$sdata['given_names'] && $email){
4182                                                        $a_email = explode("@",$email);
4183                                                        $sdata['given_names'] = $a_email[0];
4184                                        }
4185
4186                                        $line_iteration = $return['_failure'] + $return['_existing'] + $return['_new'];
4187
4188                                        if($contact){
4189                                                $return['_existing']++;
4190                                        }
4191                                        else if((!eregi("^[/_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) && $email) {
4192                                                $return['_failure']++;
4193                                                $return['_failure_status'] .= "Line: " . ($line_iteration + 2) . ", Invalid E-Mail address: " . $email ."<br>";
4194                                        }
4195                                        else if (!$sdata['given_names'] || !$boPeople ->quick_add($sdata)){
4196                                                $return['_failure']++;
4197                                                $return['_failure_status'] .= "Line: " . ($line_iteration + 2) . ", Invalid Name: " . $sdata['given_names'] ."<br>";
4198                                        }
4199                                        else{   
4200                                                        if($id_group != 0){                                                             
4201                                                                $this->so_group->add_user_by_name($id_group,$full_name);
4202                                                        }                                               
4203                                                        $return['_new']++;
4204                                                }
4205                        }
4206                                fclose($handle);
4207                                unlink($file);
4208                        }
4209                        else
4210                                $return['error'] = true;
4211
4212                        echo serialize($return);
4213                }
4214        }
4215
4216?>
Note: See TracBrowser for help on using the repository browser.