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

Revision 3282, 117.4 KB checked in by eduardoalex, 14 years ago (diff)

Ticket #1251 - Commit principal com adição da melhoria no módulo

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