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

Revision 3334, 131.7 KB checked in by eduardoalex, 14 years ago (diff)

Ticket #1370 - Adicionada a opcao de escolha do grupo para os contatos importados

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