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

Revision 3322, 131.0 KB checked in by eduardoalex, 14 years ago (diff)

Ticket #1259 - adicionado campos para exportacao de todos os padroes

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