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

Revision 3303, 118.3 KB checked in by rafaelraymundo, 14 years ago (diff)

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

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