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

Revision 3333, 130.9 KB checked in by rafaelraymundo, 14 years ago (diff)

Ticket #1292 - Ao clicar mostrar cartões no contactcenter, este dispara consulta

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