source: trunk/contactcenter/inc/class.ui_data.inc.php @ 962

Revision 962, 99.6 KB checked in by niltonneto, 15 years ago (diff)

Ticket #480 - Alteração de filtro LDAP que traz participantes de um grupo LDAP foi revertida.

  • 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
[285]16       
[2]17        class ui_data
18        {
19                var $public_functions = array(
20                        'data_manager' => true,
21                );
[285]22               
[2]23                var $bo;
24                var $typeContact;
[285]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                );
[285]36               
[2]37                /*!
[285]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
[285]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');
[285]49                       
[2]50                        $this->bo = CreateObject('contactcenter.bo_contactcenter');
[285]51                       
[2]52                        if ($temp)
53                        {
54                                $this->page_info = $temp;
55                        }
56
57                        if ($temp2)
58                        {
59                                $this->all_entries = $temp2;
60                        }
[285]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                        }
[285]67                       
68                        $this->page_info['actual_catalog'] =& $this->bo->set_catalog($this->page_info['actual_catalog']);                       
69                       
[2]70                        if($this->page_info['actual_catalog']['class'] == 'bo_group_manager')
71                                $this -> typeContact = 'groups';
[752]72                        else if($this->page_info['actual_catalog']['class'] == 'bo_shared_group_manager')
73                                $this -> typeContact = 'shared_groups';
74                        else if($this->page_info['actual_catalog']['class'] == 'bo_shared_people_manager')
75                                $this -> typeContact = 'shared_contacts';
[2]76                        else
77                                $this -> typeContact = 'contacts';
78                }
79
80                /*!
[285]81               
[2]82                        @function index
83                        @abstract Builds the Main Page
84                        @author Raphael Derosso Pereira
85                        @author Jonas Goes
[285]86                       
87                */             
[2]88                function index()
[285]89                {       
[2]90                        if(!@is_object($GLOBALS['phpgw']->js))
91                        {
92                                $GLOBALS['phpgw']->js = CreateObject('phpgwapi.javascript');
93                        }
94                        $GLOBALS['phpgw']->js->validate_file('venus','table');
95                        $GLOBALS['phpgw']->js->validate_file('venus','shapes');
96                        $GLOBALS['phpgw']->js->validate_file('venus','jsStructUtil');
97                        $GLOBALS['phpgw']->js->validate_file('venus','cssUtil');
[285]98                       
[2]99//                      $GLOBALS['phpgw']->js->set_onload('setTimeout(\'updateCards()\',1000)');
100                        $GLOBALS['phpgw']->common->phpgw_header();
[285]101                       
[2]102                        $GLOBALS['phpgw']->template->set_file(array('index' => 'index.tpl'));
103                        $GLOBALS['phpgw']->template->set_var('cc_root_dir', $GLOBALS['phpgw_info']['server']['webserver_url'].'/contactcenter/');
[285]104                       
[2]105                        /* Quick Add */
106                        $GLOBALS['phpgw']->template->set_var('cc_qa_alias',lang('Alias').':');
107                        $GLOBALS['phpgw']->template->set_var('cc_qa_given_names',lang('Given Names').':');
108                        $GLOBALS['phpgw']->template->set_var('cc_qa_family_names',lang('Family Names').':');
109                        $GLOBALS['phpgw']->template->set_var('cc_qa_phone',lang('Phone').':');
110                        $GLOBALS['phpgw']->template->set_var('cc_qa_email',lang('Email').':');
111                        $GLOBALS['phpgw']->template->set_var('cc_qa_save',lang('Save'));
112                        $GLOBALS['phpgw']->template->set_var('cc_qa_clear',lang('Clear'));
[285]113                        $GLOBALS['phpgw']->template->set_var('cc_qa_close',lang('Close'));
[2]114                        /* End Quick Add */
[285]115                       
[2]116                        $cc_css_file = $GLOBALS['phpgw_info']['server']['webserver_url'].'/contactcenter/styles/cc.css';
117                        $cc_card_image_file = $GLOBALS['phpgw_info']['server']['webserver_url'].'/contactcenter/templates/default/images/card.png';
118                        $GLOBALS['phpgw']->template->set_var('cc_css',$cc_css_file);
119                        $GLOBALS['phpgw']->template->set_var('cc_dtree_css', $cc_dtree_file);
120                        $GLOBALS['phpgw']->template->set_var('cc_card_image',$cc_card_image_file);
[285]121                       
[2]122                        $GLOBALS['phpgw']->template->set_var('cc_personal',lang('Personal'));
[285]123                       
[575]124                        $GLOBALS['phpgw']->template->set_var('cc_full_add_button',lang('Full Add'));
[2]125                        $GLOBALS['phpgw']->template->set_var('cc_reset',lang('Reset'));
[285]126                       
[2]127                        $GLOBALS['phpgw']->template->set_var('cc_personal_data',lang('Personal Data'));
128                        $GLOBALS['phpgw']->template->set_var('cc_addresses',lang('Addresses'));
129                        $GLOBALS['phpgw']->template->set_var('cc_connections',lang('Connections'));
130                        $GLOBALS['phpgw']->template->set_var('cc_relations',lang('Relations'));
131
132                        $GLOBALS['phpgw']->template->set_var('cc_quick_add',lang('Quick Add'));
133                        $GLOBALS['phpgw']->template->set_var('cc_catalogs',lang('Catalogues'));
134                        $GLOBALS['phpgw']->template->set_var('cc_group_add',lang('Group Add'));
[285]135                       
[2]136                        /* Panel */
137                        $GLOBALS['phpgw']->template->set_var('cc_panel_new',lang('New').'...');
138                        $GLOBALS['phpgw']->template->set_var('cc_panel_search',lang('Search').'...');
139                        $GLOBALS['phpgw']->template->set_var('cc_panel_table',lang('Table View'));
140                        $GLOBALS['phpgw']->template->set_var('cc_panel_cards',lang('Cards View'));
[285]141                        $GLOBALS['phpgw']->template->set_var('cc_btn_import_export', lang('Import/Export'));
142                        $GLOBALS['phpgw']->template->set_var('cc_btn_new', lang("New..."));
143                       
[2]144                        $GLOBALS['phpgw']->template->set_var('cc_panel_search_found',lang('Showing found entries'));
145                        $GLOBALS['phpgw']->template->set_var('cc_panel_first_page',lang('First Page'));
146                        $GLOBALS['phpgw']->template->set_var('cc_panel_previous_page',lang('Previous Page'));
147                        $GLOBALS['phpgw']->template->set_var('cc_panel_next_page',lang('Next Page'));
148                        $GLOBALS['phpgw']->template->set_var('cc_panel_last_page',lang('Last Page'));
149                        $GLOBALS['phpgw']->template->set_var('cc_all',lang('all'));
150                        /* End Panel */
[285]151                       
[2]152                        /* Messages */
[503]153                        $GLOBALS['phpgw']->template->set_var('cc_msg_not_allowed',lang('Not Allowed'));
[752]154                        $GLOBALS['phpgw']->template->set_var('cc_msg_unavailable',lang('Unavailable function'));                       
[2]155                        $GLOBALS['phpgw']->template->set_var('cc_msg_no_cards',lang('No Cards'));
156                        $GLOBALS['phpgw']->template->set_var('cc_msg_err_no_room',lang('No Room for Cards! Increase your browser area.'));
157                        $GLOBALS['phpgw']->template->set_var('cc_msg_card_new',lang('New from same Company'));
158                        $GLOBALS['phpgw']->template->set_var('cc_msg_card_edit',lang('Edit Contact'));
159                        $GLOBALS['phpgw']->template->set_var('cc_msg_card_remove',lang('Remove Contact'));
160                        $GLOBALS['phpgw']->template->set_var('cc_send_mail',lang('Send Mail'));
161                        $GLOBALS['phpgw']->template->set_var('cc_msg_group_edit',lang('Edit Group'));
162                        $GLOBALS['phpgw']->template->set_var('cc_msg_group_remove',lang('Remove Group'));
163                        $GLOBALS['phpgw']->template->set_var('cc_msg_group_remove_confirm',lang('Confirm Removal of this Group?'));
164                        $GLOBALS['phpgw']->template->set_var('cc_msg_card_remove_confirm',lang('Confirm Removal of this Contact?'));
165                        $GLOBALS['phpgw']->template->set_var('cc_participants',lang('Participants'));
166                        $GLOBALS['phpgw']->template->set_var('cc_empty',lang('Empty'));
167                        /* End Messages */
[285]168                       
[2]169                        $GLOBALS['phpgw']->template->set_var('cc_results',lang('Results'));
170                        $GLOBALS['phpgw']->template->set_var('cc_is_my',lang('Is My'));
[285]171                        $GLOBALS['phpgw']->template->set_var('cc_ie_personal',lang('Import/Export pesonal contacts'));
[2]172                        $GLOBALS['phpgw']->template->set_var('cc_btn_search',lang('Search'));
173                        $GLOBALS['phpgw']->template->set_var('cc_add_relation',lang('Add Relation'));
[285]174                        $GLOBALS['phpgw']->template->set_var('cc_del_relation',lang('Remove Selected Relations'));                     
[38]175                        $GLOBALS['phpgw']->template->set_var('cc_msg_group',lang('Group'));
176                        $GLOBALS['phpgw']->template->set_var('cc_msg_contact_full',lang('Contact [Full]'));
177                        $GLOBALS['phpgw']->template->set_var('cc_msg_contact_qa',lang('Contact [Quick Add]'));
[2]178                        $GLOBALS['phpgw']->template->set_var('cc_contact_title',lang('Contact Center').' - '.lang('Contacts'));
179                        $GLOBALS['phpgw']->template->set_var('cc_window_views_title',lang('Contact Center').' - '.lang('Views'));
180                        $GLOBALS['phpgw']->template->set_var('phpgw_img_dir', $GLOBALS['phpgw_info']['server']['webserver_url'] . '/phpgwapi/images');
[118]181
[285]182                        $GLOBALS['phpgw']->template->set_var('cc_msg_import_contacts', lang('Import Contacts'));
183                        $GLOBALS['phpgw']->template->set_var('cc_msg_export_contacts', lang('Export Contacts'));
184                        $GLOBALS['phpgw']->template->set_var('cc_msg_expresso_info_csv', lang('The Expresso supports the contacts importation in the CSV file format.'));
185                        $GLOBALS['phpgw']->template->set_var('cc_msg_choose_file_type', lang('Select the file type'));
186                        $GLOBALS['phpgw']->template->set_var('cc_msg_outlook_express', lang('Outlook Express'));
187                        $GLOBALS['phpgw']->template->set_var('cc_msg_outlook2k', lang('Outlook 2000'));
188                        $GLOBALS['phpgw']->template->set_var('cc_msg_expresso_default', lang('Expresso (default)'));
189                        $GLOBALS['phpgw']->template->set_var('cc_msg_choose_contacts_file', lang('Select the file that contains the contacts to be imported:'));
190                        $GLOBALS['phpgw']->template->set_var('cc_msg_close_win', lang('Close'));
191                        $GLOBALS['phpgw']->template->set_var('cc_msg_close', lang('Close'));
192                        $GLOBALS['phpgw']->template->set_var('cc_msg_ie_personal', lang('Import / Export personal Contacts'));
193                        $GLOBALS['phpgw']->template->set_var('cc_msg_import_fail', lang('The importation has failed. Verify the file format.'));
194                        $GLOBALS['phpgw']->template->set_var('cc_msg_importing_contacts', lang('Importing Contacts...'));
195                        $GLOBALS['phpgw']->template->set_var('cc_msg_import_finished', lang('The importation has finished.'));
196                        $GLOBALS['phpgw']->template->set_var('cc_msg_new', lang(' new'));
197                        $GLOBALS['phpgw']->template->set_var('cc_msg_failure', lang(' failed'));
198                        $GLOBALS['phpgw']->template->set_var('cc_msg_exists', lang(' were existent'));
199                        $GLOBALS['phpgw']->template->set_var('cc_msg_show_more_info', lang('show more info'));
200                        $GLOBALS['phpgw']->template->set_var('cc_msg_clean', lang('Clean'));
201                        $GLOBALS['phpgw']->template->set_var('cc_msg_invalid_csv', lang('Select a valid CSV file to import your contacts'));
202                        $GLOBALS['phpgw']->template->set_var('cc_msg_export_csv', lang('Select the format type that you want to export your contacts'));
203                        $GLOBALS['phpgw']->template->set_var('cc_msg_automatic', lang('Automatic'));
204                        $GLOBALS['phpgw']->template->set_var('cc_msg_export_error', lang('An error has occurred while the exportation.'));
205                        $GLOBALS['phpgw']->template->set_var('cc_msg_new_email', lang('New Email'));
206                        $GLOBALS['phpgw']->template->set_var('cc_msg_main', lang('Main'));
207                        $GLOBALS['phpgw']->template->set_var('cc_msg_alternative', lang('Alternative'));
208                        $GLOBALS['phpgw']->template->set_var('cc_msg_select_email', lang('Select E-Mail'));
209                        $GLOBALS['phpgw']->template->set_var('cc_msg_new_phone', lang('New Telephone'));
210                        $GLOBALS['phpgw']->template->set_var('cc_msg_home', lang('Home'));
211                        $GLOBALS['phpgw']->template->set_var('cc_msg_cellphone', lang('Cellphone'));
212                        $GLOBALS['phpgw']->template->set_var('cc_msg_work', lang('Work'));
213                        $GLOBALS['phpgw']->template->set_var('cc_msg_fax', lang('Fax'));
214                        $GLOBALS['phpgw']->template->set_var('cc_msg_pager', lang('Pager'));
215                        $GLOBALS['phpgw']->template->set_var('cc_msg_choose_phone', lang('Select the telephone'));
216                        $GLOBALS['phpgw']->template->set_var('cc_msg_warn_firefox', lang('Warning: Too old version of Firefox'));
217                        $GLOBALS['phpgw']->template->set_var('cc_msg_firefox_half1', lang('For this application work correctly</u>'));
218                        $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'));
219                        $GLOBALS['phpgw']->template->set_var('cc_msg_click_close', lang('click Close'));
220                        $GLOBALS['phpgw']->template->set_var('cc_msg_install_now', lang('Install Now'));
221                        $GLOBALS['phpgw']->template->set_var('cc_msg_install_new_firefox', lang('Install a new Firefox version'));
222                        $GLOBALS['phpgw']->template->set_var('cc_msg_moz_thunderbird', lang('Export as Mozilla Thunderbird CSV.'));
223                        $GLOBALS['phpgw']->template->set_var('cc_msg_outlook_express_pt', lang('Export as Outlook Express (Portuguese) CSV.'));
224                        $GLOBALS['phpgw']->template->set_var('cc_msg_outlook_express_en', lang('Export as Outlook Express (English) CSV.'));
225                        $GLOBALS['phpgw']->template->set_var('cc_msg_outlook_2k_pt', lang('Export as Outlook 2000 (Portuguese) CSV.'));
226                        $GLOBALS['phpgw']->template->set_var('cc_msg_outlook_2k_en', lang('Export as Outlook 2000 (English) CSV.'));
227                        $GLOBALS['phpgw']->template->set_var('cc_msg_expresso_default_csv', lang('Export as Expresso (Default) CSV.'));
228                        $GLOBALS['phpgw']->template->set_var('cc_msg_copy_to_catalog', lang('Copy to personal catalog.'));
229                        $GLOBALS['phpgw']->template->set_var('cc_msg_add_contact_to_group', lang('You did not add any contact for this group.'));
230                        $GLOBALS['phpgw']->template->set_var('cc_msg_fill_field_name', lang('Fill the field Full Name'));
231                       
[2]232                        $GLOBALS['phpgw']->template->parse('out','index');
[285]233                       
[2]234                        $api = CreateObject('contactcenter.ui_api');
235                        $main = $api->get_full_add();
236                        $main .= $api->get_search_obj();
237                        $main .= $api->get_quick_add_plugin();
238                        $main .= $api->get_add_group();
239                        $main .= $GLOBALS['phpgw']->template->get_var('out');
240
241                        echo $main;
242                }
243
[285]244               
[2]245                /*!
[285]246               
[2]247                        @function data_manager
[285]248                        @abstract Calls the right method and passes to it the right
[2]249                                parameters
250                        @author Raphael Derosso Pereira
[285]251               
[2]252                */
253                function data_manager()
254                {
255                        switch($_GET['method'])
256                        {
257                                /* Cards Methods */
258                                case 'set_n_cards':
259                                        return $this->set_n_cards((int)$_GET['ncards']);
[285]260                                       
261                                case 'get_cards_data':                                 
[284]262                                        $ids = false;
263                                        // To support ldap catalogs using accentuation
264                                        if ($_POST['letter'] == 'search' && isset($_POST['data']))
265                                        {
[285]266                                                $ids = utf8_decode($this->search($_POST['data']));
[284]267                                        }
[285]268                                       
269                                        if(isset($_SESSION['ids']))
270                                                $ids = $_SESSION['ids'];
271                                       
272                                        return $this->get_cards_data($_POST['letter'], $_POST['page'], $ids);                                           
[2]273                                case 'get_cards_data_get':
274                                        return $this->get_cards_data($_GET['letter'], $_GET['page'], unserialize(str_replace('\\"','"',$_GET['ids'])));
275
276
277                                case 'get_photo':
278                                        return $this->get_photo($_GET['id']);
279
[285]280                                case 'get_visible_all_ldap':
281                                        echo $this->get_visible_all_ldap();
282                                        return;
283                                       
[2]284                                /* Catalog Methods */
285                                case 'set_catalog':
286                                        return $this->set_catalog($_GET['catalog']);
[285]287                                       
[2]288                                case 'get_catalog_tree':
289                                        echo serialize($this->get_catalog_tree($_GET['level']));
290                                        return;
291
292                                case 'get_actual_catalog':
293                                        echo serialize($this->get_actual_catalog());
294                                        return;
295
296                                case 'get_catalog_participants_list':
297                                        echo serialize($this->get_catalog_participants_list($_POST['id']));
298                                        return;
[880]299                               
300                                case 'get_catalog_participants_group':
301                                        echo serialize($this->get_catalog_participants_group($_POST['id']));
302                                        return;
[2]303
304                                case 'get_catalog_add_contact':
[284]305                                        // To support ldap catalogs with accentuation
306                                        echo serialize($this->get_catalog_add_contact(utf8_decode($_POST['id'])));
[2]307                                        return;
[285]308                                       
[2]309                                /* Full Add Methods */
310                                case 'get_full_data':
[503]311                                        return $this->get_full_data($_GET['id'],$_GET['catalog']);
[285]312                               
[2]313                                case 'get_group':
314                                        return $this->get_group_data($_GET['id']);
[285]315                                       
[2]316                                case 'get_contact_full_add_const':
317                                        return $this->get_contact_full_add_const();
318
319                                case 'post_full_add':
320                                        return $this->post_full_add();
321
322                                case 'post_photo':
323                                        return $this->post_photo((int) $_GET['id'] ? (int) $_GET['id'] : '_new_');
324
325                                case 'get_states':
326                                        return $this->get_states($_GET['country']);
[285]327                                       
[2]328                                case 'get_cities':
329                                        return $this->get_cities($_GET['country'], $_GET['state'] ? $_GET['state'] : null);
[285]330                                       
331                                       
[2]332                                /* Other Methods */
[285]333                                case 'quick_add':                                                                                                                       
[2]334                                        return $this->quick_add($_POST['add']);
[285]335                               
336                                case 'add_group':                                                                                                                       
[2]337                                        return $this->add_group($_POST['add']);
[285]338                                                                       
[2]339                                case 'remove_entry':
340                                        return $this->remove_entry((int)$_GET['remove']);
[285]341                               
[2]342                                case 'remove_all_entries':
343                                        return $this->remove_all_entries();
344
345                                case 'remove_group':
[285]346                                                                               
347                                        return $this->remove_group((int)$_GET['remove']);                                       
[2]348
349                                case 'search':
[285]350                                        $ids = false;
351                                        $ids = $this->search($_GET['data']);
352                                        return $this->get_cards_data('search', '1', $ids);
[2]353
354                                case 'email_win':
355                                        $GLOBALS['phpgw']->common->phpgw_header();
356                                        $api = CreateObject('contactcenter.ui_api');
357                                        $win = $api->get_email_win();
358                                        $win .= $api->get_quick_add_plugin();
359                                        $win .= '<input id="QAbutton" type="button" value="QuickAdd" />'
360                                                .'<br><input type="button" value="EmailWin" onclick="ccEmailWin.open()" />'
361                                                .'<script type="text/javascript">'
362                                                .'      ccQuickAdd.associateAsButton(Element("QAbutton"));'
363                                                .'</script>';
364                                        echo $win;
365                                        return;
366
367                                /* Information Gathering */
368                                case 'get_multiple_entries':
369                                        echo serialize($this->get_multiple_entries(str_replace('\\"','"',$_POST['data'])));
370                                        return;
371
372                                case 'get_all_entries':
373                                        echo serialize($this->get_all_entries(str_replace('\\"','"',$_POST['data'])));
374                                        return;
375
376                                case 'import_contacts':
377                                        return $this->import_contacts($_GET['typeImport']);
378
379                                case 'export_contacts':
380                                        return $this->export_contacts($_POST['typeExport']);
381
382                        }
383                }
384
385                /*!
[285]386               
[2]387                        @function set_n_cards
388                        @abstract Informs the class the number of cards the page can show
389                        @author Raphael Derosso Pereira
[285]390                       
[2]391                        @param integer $n_cards The number of cards
[285]392                       
[2]393                */
394                function set_n_cards($n_cards)
395                {
396                        if (is_int($n_cards))
397                        {
398                                $this->page_info['n_cards'] = $n_cards;
399                                echo 1;
400                        }
[285]401                       
[2]402                        $this->save_session();
403                }
[285]404                               
[2]405                /*!
[285]406               
[2]407                        @function set_catalog
408                        @abstract Sets the current catalog selected by the user
409                        @author Raphael Derosso Pereira
[285]410                       
[2]411                        @param string $id_catalog The sequence of IDs to reach the catalog
412                                separated by commas
[285]413               
[2]414                */
415                function set_catalog($id_catalog)
416                {
417                        $id_catalog = str_replace('\\"', '"', $id_catalog);
418                        $temp =& $this->bo->set_catalog($id_catalog);
[285]419                       
[2]420                        if ($temp)
421                        {
422                                $this->page_info['changed'] = true;
423                                $this->page_info['actual_entries'] = false;
424                                $this->page_info['actual_catalog'] =& $temp;
425                                $this->save_session();
[285]426                               
[2]427                                $catalog_info = $this->bo->get_branch_by_level($this->bo->catalog_level[0]);
[285]428                               
[2]429                                if ($catalog_info['class'] === 'bo_global_ldap_catalog' ||
430                                    $catalog_info['class'] === 'bo_catalog_group_catalog')
431                                {
432                                        $perms = 1;
433                                }
434                                else
435                                {
436                                        $perms = 15;
437                                }
[285]438                               
[2]439                                echo serialize(array(
440                                        'status' => 'ok',
441                                        'perms'  => $perms
442                                ));
443
444                                return;
445                        }
[285]446                       
[2]447                        echo serialize(array(
448                                'status' => 'ok',
449                                'perms'  => 0
450                        ));
451                }
[285]452               
453               
[2]454                /*!
[285]455               
[2]456                        @function get_catalog_tree
457                        @abstract Returns the JS serialized array to used as the tree
458                                level
459                        @author Raphael Derosso Pereira
[285]460            @author Mário César Kolling (error messages and timeout)
461                       
462                        @param (string) $level The level to be taken
463               
[2]464                */
465                function get_catalog_tree($level)
466                {
467                        if ($level === '0')
468                        {
469                                $folderImageDir = $GLOBALS['phpgw_info']['server']['webserver_url'] . '/phpgwapi/dftree/images/';
470
471                                $parent = '0';
[285]472                               
[2]473                                if (!($tree = $this->bo->get_catalog_tree($level)))
474                                {
475                                        return array(
476                                                'msg'    => lang('Couldn\'t get the Catalogue Tree. Please contact the Administrator.'),
477                                                'status' => 'fatal'
478                                        );
479                                }
480                        }
481                        else
482                        {
483                                $last_dot = strrpos($level,'.');
484                                $parent = substr($level, 0, $last_dot);
485                                $child = substr($level, $last_dot+1, strlen($level));
[285]486                       
[2]487                                if (!($tree[$child] = $this->bo->get_catalog_tree($level)))
488                                {
489                                        return array(
490                                                'msg'    => lang('Couldn\'t get the Catalogue Tree. Please contact the Administrator.'),
491                                                'status' => 'fatal'
492                                        );
493                                }
[284]494                                // Deals with timeout and returns the generated message to the browser
495                                else if (!empty($tree[$child]['timeout']) && !empty($tree[$child]['msg']))
496                                {
497                                        $tmp = array(
498                                                'msg'    => $tree[$child]['msg'],
499                                                'status' => 'fatal'
500                                        );
501                                        unset($tree[$child]);
502                                        return $tmp;
503                                }
[2]504                        }
[285]505                       
[2]506                        $folderImageDir = $GLOBALS['phpgw']->common->image('contactcenter','globalcatalog-mini.png');
507                        $folderImageDir = substr($folderImageDir, 0, strpos($folderImageDir, 'globalcatalog-mini.png'));
[285]508                       
[284]509                        // Deals with error messages from the server and returns them to the browser
510                        if ($tree['msg'])
511                        {
512                                $msg = $tree['msg'];
513                                unset($tree['msg']);
514                        }
515
[2]516                        $tree_js = $this->convert_tree($tree, $folderImageDir, $parent);
[284]517
518                        // Return status = ok, or else return generated message to the browser
519                        if (!$msg)
520                        {
521                                return array(
522                                        'data' => $tree_js,
523                                        'msg'  => lang('Catalog Tree Successfully taken!'),
524                                        'status' => 'ok'
525                                );
526                        }
527                        else
528                        {
529                                return array(
530                                        'data' => $tree_js,
531                                        'msg'  => $msg,
532                                        'status' => 'error'
533                                );
534                        }
[2]535                }
[285]536               
[2]537                /*!
[285]538               
[2]539                        @function get_actual_catalog
540                        @abstract Returns the actual selected Catalog
541                        @author Raphael Derosso Pereira
542
543                */
544                function get_actual_catalog()
[285]545                {                       
[2]546                        $level = $this->bo->get_level_by_branch($this->bo->get_actual_catalog(), $this->bo->tree['branches'], '0');
[285]547                       
[2]548                        if ($level)
549                        {
550                                return array(
551                                        'status' => 'ok',
552                                        'data'   => $level
553                                );
554                        }
555
556                        return array(
557                                'status' => 'fatal',
558                                'msg'    => lang('Couldn\'t get the actual catalog.'),
559                        );
560                }
[285]561               
[2]562                /*!
[285]563               
[2]564                        @function get_cards_data
565                        @abstract Returns the information that is placed on the cards
566                        @author Raphael Derosso Pereira
[285]567                       
[2]568                        @param string $letter The first letter to be searched
[285]569                        @param (int)  $page The page to be taken
[2]570                        @param (str)  $ids The ids to be taken in case of search
571
572                        TODO: This function is not well done. It must be rewritten
573                                using the new array 'msg','status','data' schema.
574                */
575                function get_cards_data($letter, $page, $ids)
576                {
[285]577                        if( $ids )
578                                $_SESSION['ids'] = $ids;                   
[284]579
580                        // It's an external catalog?
581                        $external = $this->bo->is_external($this->page_info['actual_catalog']);
[2]582                        //echo $page."\n";
583                        if ($letter !== 'search' and ($letter != $this->page_info['actual_letter'] or
[285]584                            ($letter == $this->page_info['actual_letter'] and $page == $this->page_info['actual_page']) or
[2]585                            $this->page_info['changed']))
586                        {
587                                unset($ids);
588                                $this->page_info['changed'] = false;
[503]589
[2]590                                switch ($this->page_info['actual_catalog']['class'])
591                                {
[752]592                                        case 'bo_shared_people_manager':
593                                        case 'bo_people_catalog':
[503]594                                                $field_name = 'id_contact';
595
596                                                if ($letter !== 'number')
597                                                {
598                                                        $find_restric[0] = array(
599                                                                0 => array(
600                                                                        'field' => 'contact.names_ordered',
601                                                                        'type'  => 'iLIKE',
602                                                                        'value' => $letter !== 'all' ? $letter.'%' : '%'
[752]603                                                                )                                                               
[503]604                                                        );
[752]605                                                        if($this->page_info['actual_catalog']['class'] == 'bo_people_catalog'){                                                         
606                                                                $find_restric[0][1] = array(
607                                                                                'field' => 'contact.id_owner',
608                                                                                'type'  => '=',
609                                                                                'value' => $GLOBALS['phpgw_info']['user']['account_id']
610                                                                );
611                                                        }
[503]612                                                }
613                                                else
614                                                {
615                                                        $find_restric[0] = array(
616                                                                0 => array(
617                                                                        'type'  => 'branch',
618                                                                        'value' => 'OR',
619                                                                        'sub_branch' => array(
620                                                                                0 => array(
621                                                                                        'field' => 'contact.names_ordered',
622                                                                                        'type'  => 'LIKE',
623                                                                                        'value' => '0%'
624                                                                                ),
625                                                                                1 => array(
626                                                                                        'field' => 'contact.names_ordered',
627                                                                                        'type'  => 'LIKE',
628                                                                                        'value' => '1%'
629                                                                                ),
630                                                                                2 => array(
631                                                                                        'field' => 'contact.names_ordered',
632                                                                                        'type'  => 'LIKE',
633                                                                                        'value' => '2%'
634                                                                                ),
635                                                                                3 => array(
636                                                                                        'field' => 'contact.names_ordered',
637                                                                                        'type'  => 'LIKE',
638                                                                                        'value' => '3%'
639                                                                                ),
640                                                                                4 => array(
641                                                                                        'field' => 'contact.names_ordered',
642                                                                                        'type'  => 'LIKE',
643                                                                                        'value' => '4%'
644                                                                                ),
645                                                                                5 => array(
646                                                                                        'field' => 'contact.names_ordered',
647                                                                                        'type'  => 'LIKE',
648                                                                                        'value' => '5%'
649                                                                                ),
650                                                                                6 => array(
651                                                                                        'field' => 'contact.names_ordered',
652                                                                                        'type'  => 'LIKE',
653                                                                                        'value' => '6%'
654                                                                                ),
655                                                                                7 => array(
656                                                                                        'field' => 'contact.names_ordered',
657                                                                                        'type'  => 'LIKE',
658                                                                                        'value' => '7%'
659                                                                                ),
660                                                                                8 => array(
661                                                                                        'field' => 'contact.names_ordered',
662                                                                                        'type'  => 'LIKE',
663                                                                                        'value' => '8%'
664                                                                                ),
665                                                                                9 => array(
666                                                                                        'field' => 'contact.names_ordered',
667                                                                                        'type'  => 'LIKE',
668                                                                                        'value' => '9%'
[752]669                                                                                ),
670                                                                        ),
[503]671                                                                )
672                                                        );
673                                                }
[2]674
[752]675                                                if($this->page_info['actual_catalog']['class'] == 'bo_people_catalog'){                                                         
676                                                        $find_restric[0][1]     = array(
677                                                                'field' => 'contact.id_owner',
678                                                                'type'  => '=',
679                                                                'value' => $GLOBALS['phpgw_info']['user']['account_id']
[2]680                                                        );
681                                                }
[285]682                                               
[752]683                                               
[2]684                                                $find_field[0] = array('contact.id_contact','contact.names_ordered');
[285]685                                               
[2]686                                                $find_other[0] = array(
687                                                        'order'  => 'contact.names_ordered'
688                                                );
[285]689                                               
[2]690                                                break;
[285]691                                       
[2]692                                        case 'bo_global_ldap_catalog':
[285]693                                       
[2]694                                                $field_name = 'id_contact';
695
696                                                if ($letter !== 'number')
697                                                {
698                                                        $find_restric[0] = array(
699                                                                0 => array(
700                                                                        'field' => 'contact.names_ordered',
701                                                                        'type'  => 'iLIKE',
702                                                                        'value' => $letter !== 'all' ? $letter.'%' : '%'
[284]703                                                                ),
704                                                                /*
705                                                                 * Restrict the returned contacts in a "first letter" search
706                                                                 * to objectClass = phpgwAccount, must have attibute phpgwAccountStatus,
[880]707                                                                 * phpgwAccountVisible != -1
[284]708                                                                 */
709                                                                1 => array(
710                                                                        'field' => 'contact.object_class',
711                                                                        'type'  => '=',
712                                                                        'value' => 'phpgwAccount'
713                                                                ),
714                                                                2 => array(
715                                                                        'field' => 'contact.account_status',
716                                                                        'type'  => 'iLIKE',
717                                                                        'value' => '%'
718                                                                ),
719                                                                3 => array(
720                                                                        'field' => 'contact.account_visible',
721                                                                        'type'  => '!=',
722                                                                        'value' => '-1'
[880]723                                                                )
[2]724                                                        );
[284]725                                                        // If not external catalog get only phpgwAccountType = u ou l
726                                                        if (!$external)
727                                                        {
728                                                                $find_restric[0][5] =  array(
729                                                                                'type'  => 'branch',
730                                                                                'value' => 'OR',
731                                                                                'sub_branch' => array(
732                                                                                        0 => array(
733                                                                                        'field' => 'contact.account_type',
734                                                                                        'type'  => '=',
735                                                                                        'value' => 'u'
736                                                                                        ),
[285]737                                                                                        1 => array(
[284]738                                                                                        'field' => 'contact.account_type',
739                                                                                        'type'  => '=',
[418]740                                                                                        'value' => 'i'
741                                                                                        ),
742                                                                                        2 => array(
743                                                                                        'field' => 'contact.account_type',
744                                                                                        'type'  => '=',
[284]745                                                                                        'value' => 'l'
[880]746                                                                                        ),
747                                                                                        3 => array(
748                                                                                        'field' => 'contact.account_type',
749                                                                                        'type'  => '=',
750                                                                                        'value' => 'g'
[284]751                                                                                        )
[2]752                                                                                )
[284]753                                                                );
754                                                        }
[2]755                                                }
756                                                else
757                                                {
758                                                        $find_restric[0] = array(
[284]759                                                                /*
760                                                                 * Restrict the returned contacts in a "first number" search
761                                                                 * to objectClass = phpgwAccount, must have attibute phpgwAccountStatus,
[880]762                                                                 * phpgwAccountVisible != -1
[284]763                                                                 */
[2]764                                                                0 => array(
[284]765                                                                        'field' => 'contact.object_class',
766                                                                        'type'  => '=',
767                                                                        'value' => 'phpgwAccount'
768                                                                ),
769                                                                1 => array(
770                                                                        'field' => 'contact.account_status',
771                                                                        'type'  => 'iLIKE',
772                                                                        'value' => '%'
773                                                                ),
774                                                                2 => array(
775                                                                        'field' => 'contact.account_visible',
776                                                                        'type'  => '!=',
777                                                                        'value' => '-1'
778                                                                ),
779                                                                3 => array(
[2]780                                                                        'type'  => 'branch',
781                                                                        'value' => 'OR',
782                                                                        'sub_branch' => array(
783                                                                                0 => array(
784                                                                                        'field' => 'contact.names_ordered',
785                                                                                        'type'  => 'LIKE',
786                                                                                        'value' => '0%'
787                                                                                ),
788                                                                                1 => array(
789                                                                                        'field' => 'contact.names_ordered',
790                                                                                        'type'  => 'LIKE',
791                                                                                        'value' => '1%'
792                                                                                ),
793                                                                                2 => array(
794                                                                                        'field' => 'contact.names_ordered',
795                                                                                        'type'  => 'LIKE',
796                                                                                        'value' => '2%'
797                                                                                ),
798                                                                                3 => array(
799                                                                                        'field' => 'contact.names_ordered',
800                                                                                        'type'  => 'LIKE',
801                                                                                        'value' => '3%'
802                                                                                ),
803                                                                                4 => array(
804                                                                                        'field' => 'contact.names_ordered',
805                                                                                        'type'  => 'LIKE',
806                                                                                        'value' => '4%'
807                                                                                ),
808                                                                                5 => array(
809                                                                                        'field' => 'contact.names_ordered',
810                                                                                        'type'  => 'LIKE',
811                                                                                        'value' => '5%'
812                                                                                ),
813                                                                                6 => array(
814                                                                                        'field' => 'contact.names_ordered',
815                                                                                        'type'  => 'LIKE',
816                                                                                        'value' => '6%'
817                                                                                ),
818                                                                                7 => array(
819                                                                                        'field' => 'contact.names_ordered',
820                                                                                        'type'  => 'LIKE',
821                                                                                        'value' => '7%'
822                                                                                ),
823                                                                                8 => array(
824                                                                                        'field' => 'contact.names_ordered',
825                                                                                        'type'  => 'LIKE',
826                                                                                        'value' => '8%'
827                                                                                ),
828                                                                                9 => array(
829                                                                                        'field' => 'contact.names_ordered',
830                                                                                        'type'  => 'LIKE',
831                                                                                        'value' => '9%'
832                                                                                ),
833                                                                        ),
834                                                                ),
835                                                        );
[284]836                                                        // If not external catalog get only phpgwAccountType = u ou l
837                                                        if (!$external)
838                                                        {
839                                                                $find_restric[0][5] =  array(
840                                                                        'type'  => 'branch',
841                                                                        'value' => 'OR',
842                                                                        'sub_branch' => array(
843                                                                                0 => array(
844                                                                                'field' => 'contact.account_type',
845                                                                                'type'  => '=',
846                                                                                'value' => 'u'
847                                                                                ),
[418]848                                                                                1 => array(
849                                                                                'field' => 'contact.account_type',
850                                                                                'type'  => '=',
851                                                                                'value' => 'i'
852                                                                                ),
[880]853                                                                                2 => array(
[284]854                                                                                'field' => 'contact.account_type',
855                                                                                'type'  => '=',
[880]856                                                                                'value' => 'l'
857                                                                                ),
858                                                                                3 => array(
[284]859                                                                                'field' => 'contact.account_type',
860                                                                                'type'  => '=',
[880]861                                                                                'value' => 'g'
[284]862                                                                                )
[880]863                                                                               
[2]864                                                                        )
[284]865                                                                );
866                                                        }
[2]867                                                }
[284]868
869                                                if (!$external)
870                                                {
871                                                        // Get only this attributes: dn, cn, phpgwAccountType, objectClass, phpgwAccountStatus, phpghAccountVisible
872                                                        // for non-external catalogs, used to restrict the attributes used in filters
873                                                        $find_field[0] = array('contact.id_contact','contact.names_ordered','contact.account_type',
[304]874                                                                'contact.object_class',/*'contact.account_status',*/'contact.account_visible');
[284]875                                                }
876                                                else
877                                                {
878                                                        // Get only this attributes: dn, cn for external catalogs,
879                                                        // used to restrict the attributes used in filters
880                                                        $find_field[0] = array('contact.id_contact','contact.names_ordered');
881                                                }
[285]882                                               
[2]883                                                $find_other[0] = array(
884                                                        //'offset' => (($page-1)*$this->page_info['n_cards']),
885                                                        //'limit'  => $this->page_info['n_cards'],
886                                                        'order'  => 'contact.names_ordered'
887                                                );
[285]888                                               
[2]889                                                break;
[285]890                                       
[2]891                                        case 'bo_company_manager':
892                                                $field_name = 'id_company';
[285]893       
[2]894                                                $find_field[0] = array('company.id_company','company.company_name');
[285]895                                               
[2]896                                                $find_other[0] = array(
897                                                        //'offset' => (($page-1)*$this->page_info['n_cards']),
898                                                        //'limit'  => $this->page_info['n_cards'],
899                                                        'order'  => 'company.company_name'
900                                                );
[285]901       
[2]902                                                $find_restric[0] = array(
903                                                        0 => array(
904                                                                'field' => 'company.company_name',
905                                                                'type'  => 'iLIKE',
906                                                                'value' => $letter !== 'all' ? $letter.'%' : '%'
907                                                        )
908                                                );
[285]909                                                       
[2]910                                                break;
911
912                                        case 'bo_group_manager':
[752]913                                        case 'bo_shared_group_manager':
914                                                                                               
[2]915                                                $field_name = 'id_group';
[285]916                                               
[2]917                                                if ($letter !== 'number')       {
[285]918                                                       
[2]919                                                        $find_restric[0] = array(
920                                                                0 => array(
921                                                                        'field' => 'group.title',
922                                                                        'type'  => 'iLIKE',
923                                                                        'value' => $letter !== 'all' ? $letter.'%' : '%'
924                                                                )
925                                                        );
926                                                }
927                                                 else {
[285]928                                                       
[2]929                                                        $find_restric[0] = array(
930                                                                0 => array(
931                                                                                        'field' => 'group.title',
932                                                                                        'type'  => 'LIKE',
[285]933                                                                                        'value' => '0%'                                                                         
[2]934                                                                )
[285]935                                                        );                                             
[2]936                                                }
[285]937                                               
[752]938                                                if($this->page_info['actual_catalog']['class'] == 'bo_group_manager'){
939                                                        array_push($find_restric[0],  array(
[2]940                                                                                        'field' => 'group.owner',
941                                                                                        'type'  => '=',
[285]942                                                                                        'value' => $GLOBALS['phpgw_info']['user']['account_id']                                                                         
[752]943                                                                        )
944                                                        );
945                                                }
[285]946                                               
947                                                $find_field[0] = array('group.id_group','group.title','group.short_name');                                             
[2]948                                                $find_other[0] = array(
949                                                        'order'  => 'group.title'
[752]950                                                );                                             
[2]951                                                break;
[752]952                                       
[2]953                                        case 'bo_catalog_group_catalog':
954                                                $this->page_info['actual_entries'] = false;
[285]955                                               
[2]956                                                $this->page_info['actual_letter'] = $letter;
957                                                $this->page_info['actual_page'] = 0;
[285]958                                               
[2]959                                                $this->save_session();
960                                                $final[0] = 0;
[285]961                                                $final[1] = $this->typeContact;
962                                                echo serialize($final);                                         
[2]963                                                return;
964
965                                }
[285]966                               
[2]967                                $result = $this->bo->find($find_field[0],$find_restric[0],$find_other[0]);
[752]968                               
[2]969                                $n_entries = count($result);
[285]970                               
[2]971                                if ($n_entries)
972                                {
973                                        //echo 'N_entries: '.$n_entries.'<br>';
974                                        $this->page_info['n_pages'] = ceil($n_entries/($this->page_info['n_cards'] ? $this->page_info['n_cards'] : 1));
975                                }
976                                else
977                                {
978                                        $this->page_info['n_pages'] = 0;
979                                }
980
981                                if (!$result)
982                                {
[752]983                                       
[2]984                                        $this->page_info['actual_entries'] = false;
[285]985                                       
[2]986                                        $this->page_info['actual_letter'] = $letter;
987                                        $this->page_info['actual_page'] = 0;
[285]988                                       
989                                        $this->save_session();                         
[2]990                                        $final[0] = 0;
[285]991                                        $final[1] = $this->typeContact;
992                                        echo serialize($final);                                                                                 
[2]993                                        return;
994                                }
995                                else
996                                {
997                                        unset($this->page_info['actual_entries']);
998                                        foreach ($result as $id => $value)
999                                        {
[752]1000                                                if($this->page_info['actual_catalog']['class'] != 'bo_shared_people_manager' && $this->page_info['actual_catalog']['class'] != 'bo_shared_group_manager')
[503]1001                                                        $this->page_info['actual_entries'][] = $value[$field_name];
1002                                                else
[752]1003                                                        $this->page_info['actual_entries'][] = array(0=>$value[$field_name],1=>$value['perms'],2=>$value['owner']);
[285]1004                                        }
1005                                        //print_r($this->page_info['actual_entries']);
[2]1006                                }
1007                        }
1008                        else if ($letter === 'search')
1009                        {
[284]1010                                //if (!$ids and $this->page_info['actual_letter'] !== 'search')
[285]1011                                if (!$ids)
[2]1012                                {
[315]1013                                        //error_log('!$ids e $this->page_info[\'actual_letter\'] != search');
[2]1014                                        $this->page_info['actual_entries'] = false;
[285]1015                                       
[2]1016                                        $this->page_info['actual_letter'] = $letter;
1017                                        $this->page_info['actual_page'] = 0;
[285]1018                                       
[2]1019                                        $this->save_session();
1020                                        $final[0] = 0;
1021                                        $final[1] = $this -> typeContact;
[285]1022                                        echo serialize($final);                                 
[2]1023                                        return;
1024                                }
[284]1025                                else if ($ids['error'])
1026                                {
1027                                        $this->page_info['actual_entries'] = false;
1028                                        $this->page_info['actual_letter'] = $letter;
1029                                        $this->page_info['actual_page'] = 0;
1030
1031                                        $this->save_session();
1032                                        $final[0] = 0;
1033                                        $final[1] = $this -> typeContact;
1034                                        $final['error'] = $ids['error'];
1035                                        echo serialize($final);
1036                                        return;
1037                                }
[285]1038                                else if ($ids)
1039                                {                               
[2]1040                                        $this->page_info['actual_letter']  = $letter;
1041                                        $this->page_info['actual_entries'] = $ids;
1042                                        $this->page_info['n_pages'] = ceil(count($ids)/($this->page_info['n_cards'] ? $this->page_info['n_cards'] : 1));
1043                                }
1044                        }
1045                        else
1046                        {
1047                                unset($ids);
1048                        }
1049
1050                        if ($this->page_info['actual_entries'])
1051                        {
1052                                if ($page >= $this->page_info['n_pages'])
1053                                {
1054                                        $page = $this->page_info['n_pages'];
1055                                }
[285]1056                               
[2]1057                                $final = array(
1058                                        0 => (int)$this->page_info['n_pages'],
1059                                        1 => (int)$page,
1060                                        2 => array(
1061                                                0 => 'cc_company',
1062                                                1 => 'cc_name',
1063                                                2 => 'cc_title',
1064                                                3 => 'cc_phone',
1065                                                4 => 'cc_mail',
1066                                                5 => 'cc_alias',
1067                                                6 => 'cc_id',
[752]1068                                                7 => 'cc_forwarding_address'                                           
[2]1069                                        )
1070                                );
[285]1071                               
[2]1072                                //echo 'Page: '.$page.'<br>';
1073                                $id_i = (($page-1)*$this->page_info['n_cards']);
1074                                $id_f = $id_i + $this->page_info['n_cards'];
1075                                $n_entries = count($this->page_info['actual_entries']);
[285]1076                               
[2]1077                                //echo 'ID_I: '.$id_i.'<br>';
1078                                //echo 'ID_F: '.$id_f.'<br>';
[752]1079                               
[2]1080                                $ids = array();
[503]1081                                $perms = array();
[752]1082                                $owners = array();
[285]1083                                $array_temp = array();                 
[752]1084                               
[2]1085                                foreach($this->page_info['actual_entries'] as $key=>$tmp){
[503]1086                                                $array_temp[] = $tmp;                           
[285]1087                                }       
1088                               
[2]1089                                for($i = $id_i; $i < $id_f and $i < $n_entries; $i++)
1090                                {
[752]1091                                        if($this->page_info['actual_catalog']['class'] != 'bo_shared_people_manager' && $this->page_info['actual_catalog']['class'] != 'bo_shared_group_manager')
[503]1092                                                $ids[] = $array_temp[$i];
1093                                        else {
1094                                                $ids[] = $array_temp[$i][0];
1095                                                $perms[] = $array_temp[$i][1];
[752]1096                                                $owners[] = $array_temp[$i][2];
[503]1097                                        }
1098                                        //$perms[] = $array_temp[$i];
[2]1099                                }
[285]1100                               
[752]1101                               
1102                                // Carrega o nome completo dos donos dos objetos (contatos e grupos);
1103                                $owner_names = array();
1104                                                       
1105                                if($owners) {
1106                                        $filter = "(|";
1107                                        foreach($owners as $i => $owner) {
1108                                                $filter .= "(uidNumber=".$owner.")";
1109                                        }
1110                                        $filter .= ")";
1111                                       
1112                                        if(!$this->bo->catalog->src_info) {
1113                                                $ldap = CreateObject('contactcenter.bo_ldap_manager');
1114                                                $this->bo->catalog->src_info = $ldap->srcs[1];
1115                                        }
1116                                        $ds = $GLOBALS['phpgw']->common->ldapConnect($this->bo->catalog->src_info['host'], $this->bo->catalog->src_info['acc'], $this->bo->catalog->src_info['pw'], false);                             
1117                                        $dn=$this->bo->catalog->src_info['dn'];
1118                                        $justThese = array("cn","uidnumber","uid");
1119                                        $sr = ldap_search($ds,$dn, $filter,$justThese);                                                         
1120                                        $info = ldap_get_entries($ds, $sr);
1121                                        ldap_close($ds);                                                                                       
1122                                        for($z = 0; $z < $info['count']; $z++) {
1123                                                $owner_names[$info[$z]['uidnumber'][0]] = array("cn" => $info[$z]['cn'][0], "uid" => $info[$z]['uid'][0]);
1124                                        }                               
1125                                }
[2]1126                                /// Original
1127                                //for($i = $id_i; $i < $id_f and $i < $n_entries; $i++)
1128                                //{
1129                                //      $ids[] = $this->page_info['actual_entries'][$i];
1130                                //}
1131                                ///
[285]1132                               
[2]1133                                $fields = $this->bo->catalog->get_fields(false);
[752]1134                                if( $this->typeContact == 'groups' || $this->typeContact == 'shared_groups') {
[2]1135                                        $final = array(
1136                                                0 => (int)$this->page_info['n_pages'],
1137                                                1 => (int)$page,
1138                                                2 => array(
1139                                                        0 => 'cc_title',
1140                                                        1 => 'cc_short_name',
1141                                                        2 => 'cc_id',
1142                                                        3 => 'cc_contacts'
[285]1143                                                )                                               
1144                                        );                                     
[2]1145                                        $groups =& $this->bo->catalog->get_multiple_entries($ids,$fields);
[752]1146                                                                                                                       
[2]1147                                        $i = 0;
1148                                        // contatos do grupo
[285]1149                                        $boGroups = CreateObject('contactcenter.bo_group');                                     
[2]1150                                        $contacts = array();
[752]1151                                       
1152                                        foreach($groups as $group)              {       
[2]1153                                                $final[3][$i][0] = $group['title'] ? $group['title'] : 'none';
[285]1154                                                $final[3][$i][1] = $group['short_name'] ? $group['short_name'] : 'none';                                               
[2]1155                                                $final[3][$i][2] = $group['id_group'] ? $group['id_group'] : 'none';
1156                                                $contacts = $boGroups -> get_contacts_by_group($group['id_group']);
1157                                                $final[3][$i][3] = $contacts;
[752]1158                                                $final[3][$i][4] = $perms[$i];
1159                                                if($this->typeContact == 'shared_groups'){
1160                                                        $final[3][$i][5] = lang('Shared').": ".$owner_names[$owners[$i]]['cn'];
1161                                                        $final[3][$i][6] = $owner_names[$owners[$i]]['uid'];
1162                                                }                                               
[285]1163                                                $i++;                                                   
[2]1164                                        }
[285]1165                                       
[2]1166                                        $this->page_info['actual_letter'] = $letter;
[285]1167                                        $this->page_info['actual_page'] = $page;                                       
1168                                       
1169                                       
[2]1170                                        $lnk_compose = "location.href=('../expressoMail1_2/index.php?to=";
[285]1171                                       
[752]1172                                        $final[5] = '<span class="link"  onclick="'.$lnk_compose;                                       
1173                                        $final[10] = $this->typeContact;                                                                                                                                                                                                               
[285]1174                                        $this->save_session();                                 
[2]1175                                        echo serialize($final);
[285]1176                                        return;                                 
[2]1177                                }
[503]1178                                $final[10] = $this -> typeContact;
[285]1179                               
[2]1180                                $fields['photo'] = true;
1181                                $fields['names_ordered'] = true;
1182                                $fields['alias'] = true;
1183                                $fields['account_type'] = true;
1184                                $fields['companies'] = 'default';
1185                                $fields['connections'] = 'default';
[285]1186                                // ?aqui alterar a chamada desse método para receber o base dn?
1187                                $contacts = &$this->bo->catalog->get_multiple_entries($ids,$fields);
1188                               
1189                               
[2]1190                                if (!is_array($contacts) or !count($contacts))
1191                                {
1192                                        $final[0] = 0;
1193                                        $final[1] = $this -> typeContact;
1194                                        echo serialize($final);
1195                                        return;
1196                                }
[285]1197                               
[2]1198                                $i = 0;
[284]1199                                foreach($contacts as $index => $contact)
[2]1200                                {
[284]1201                                        /*
[285]1202                                         * TODO: Os timeouts de conexão foram retirados, ver se será necessário retornar essa funcionalidade, e,
1203                                         * neste caso, terminar a implementação das mensagens de retorno.
[284]1204                                         */
1205                                        if ($index !== 'error'){
1206                                                $final[3][$i][0] = $contact['companies']['company1']['company_name']?$contact['companies']['company1']['company_name']:'none';
1207                                                $final[3][$i][1] = $contact['names_ordered'] ? $contact['names_ordered'] : 'none';
1208                                                $final[3][$i][2] = $contact['companies']['company1']['title']?$contact['companies']['company1']['title']:'none';
[2]1209
[284]1210                                                /* Select the correct Email and Telephone to be shown */
1211                                                $preferences = ExecMethod('contactcenter.ui_preferences.get_preferences');
[285]1212                                               
[284]1213                                                if (!is_array($preferences))
[2]1214                                                {
[284]1215                                                        $preferences['personCardEmail'] = 1;
1216                                                        $preferences['personCardPhone'] = 2;
1217                                                }
1218                                                if ($contact['connections'])
1219                                                {
1220                                                        $default_email_found = false;
1221                                                        $default_phone_found = false;
1222                                                        foreach($contact['connections'] as $conn_info)
[2]1223                                                        {
[284]1224                                                                if ($conn_info['id_type'] == $preferences['personCardEmail'] and !$default_email_found)
[2]1225                                                                {
[284]1226                                                                        if ($conn_info['connection_is_default'])
1227                                                                        {
1228                                                                                $default_email_found = true;
1229                                                                        }
1230                                                                        $final[3][$i][4] = $conn_info['connection_value'] ? $conn_info['connection_value'] : 'none';
[2]1231                                                                }
[284]1232                                                                else if ($conn_info['id_type'] == $preferences['personCardPhone'] and !$default_phone_found)
[2]1233                                                                {
[284]1234                                                                        if ($conn_info['connection_is_default'])
1235                                                                        {
1236                                                                                $default_phone_found = true;
1237                                                                        }
[285]1238                                                                        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]1239                                                                                $conn_info['connection_value'] = "<a title=\"".lang("Call Extension")."\" href=\"#\" onclick=\"connectVoip('".$conn_info['connection_value']."', 'com')\">".$conn_info['connection_value']."</a>";
[285]1240                                                                        }
[284]1241                                                                        $final[3][$i][3] = $conn_info['connection_value'] ? $conn_info['connection_value'] : 'none';
1242                                                                }
[2]1243                                                        }
1244                                                }
[285]1245                                               
[284]1246                                                if (!$final[3][$i][3])
1247                                                {
1248                                                        $final[3][$i][3] = 'none';
1249                                                }
1250
1251                                                if (!$final[3][$i][4])
1252                                                {
1253                                                        $final[3][$i][4] = 'none';
1254                                                }
1255
1256                                                $final[3][$i][5] = $contact['alias']?$contact['alias']:'none';
1257                                                $final[3][$i][6] = $ids[$i];
1258
[880]1259                                        //      If contact is a public list or a group, then load the forwarding addresses.
1260                                                if($contact['account_type'][0] == 'l' || $contact['account_type'][0] == 'g')
1261                                                        $final[3][$i][7] = ($contact['account_type'][0] == 'l' ? 'list' : 'group');
[503]1262                                                       
[752]1263                                                if($this->page_info['actual_catalog']['class']=='bo_shared_people_manager') {
[503]1264                                                        $final[3][$i][8] = $perms[$i];
[752]1265                                                        $final[3][$i][9] = lang('Shared').": ".$owner_names[$owners[$i]]['cn'];
[503]1266                                                }
[284]1267
1268                                                $final[4][$i] = $contact['photo'] ? 1  : 0;
1269                                                $i++;
[2]1270                                        }
[284]1271                                        else
[2]1272                                        {
[284]1273                                                // coloca mensagem de erro no vetor que retorna para o browser
[2]1274                                        }
[284]1275                                }
1276                                $lnk_compose = "location.href=('../expressoMail1_2/index.php?to=";
1277                                $final[5] = '<span class="link" onclick="'.$lnk_compose;
[2]1278
1279
1280                                $this->page_info['actual_letter'] = $letter;
1281                                $this->page_info['actual_page'] = $page;
[285]1282                               
1283                                $this->save_session();                         
[2]1284                                echo serialize($final);
1285                                return;
1286                        }
[285]1287                       
[2]1288                        $this->page_info['actual_letter'] = $letter;
1289                        $this->page_info['actual_page'] = $page;
[285]1290                       
[2]1291                        $this->save_session();
[285]1292                       
[2]1293                        $final[0] = 0;
1294                        $final[1] = $this -> typeContact;
1295                        echo serialize($final);
1296                }
[285]1297               
1298                function get_visible_all_ldap()
1299                {
1300                        $bo = CreateObject('contactcenter.bo_ldap_manager');
1301                        $ldap_query = $bo->srcs;
1302                        return $ldap_query[1]['visible'];       
1303                }
[284]1304
[285]1305 
[2]1306                /*!
[285]1307               
[2]1308                        @function get_group_data
1309                        @abstract Returns all the information of a given Group
1310                        @author Nilton Emilio Buhrer Neto
[285]1311                       
[2]1312                        @param (integer) $id The id to get information
[285]1313               
1314                */             
[2]1315                function get_group_data($id)
1316                {
1317                        $this->bo->catalog = CreateObject('contactcenter.bo_group_manager');
1318                        $fields = $this->bo->catalog->get_fields(true);
1319                        $data = $this->bo->catalog->get_single_entry($id,$fields);
[285]1320                       
1321                        if($id) {                       
[2]1322                                // get All Contacts by group.
[285]1323                                $data['contact_in_list'] = $this->bo->catalog->get_contacts_by_group($id);                                                             
[2]1324                        }
[285]1325                       
[2]1326                        $boGroup = CreateObject('contactcenter.bo_group');
[285]1327                                               
[702]1328                        $all_contacts = $boGroup->get_all_contacts('only_email');
[285]1329                       
1330                        $contact_options = "";
1331                        if(count($all_contacts)) {                                     
1332                                foreach($all_contacts as $idx => $contact) {                           
1333                                        $contact_options .= "<OPTION value='".$contact['id_connection']."'>".$contact['names_ordered']." (".$contact['connection_value'].")</OPTION>";
1334                                }
1335                        }
[752]1336                        $data['contact_list'] = $contact_options;                       
1337                        $data['result'] = 'ok';
1338                                                                                       
[285]1339                        echo serialize($data);                 
1340                }               
1341               
[2]1342                /*!
[285]1343               
[2]1344                        @function get_full_data
1345                        @abstract Returns all the information of a given Entry
1346                        @author Raphael Derosso Pereira
[285]1347                       
[2]1348                        @param (integer) $id The id to get information
[285]1349               
[2]1350                */
[503]1351                function get_full_data($id,$catalog='bo_people_catalog')
[2]1352                {
1353                        $dateformat = $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
[503]1354                        $this->bo->catalog = CreateObject('contactcenter.'.$catalog);           
[2]1355                        $fields = $this->bo->catalog->get_fields(true);
1356                        $fields['photo'] = false;
1357                        $entry = $this->bo->catalog->get_single_entry($id,$fields);
1358
1359                        if (is_bool($entry['given_names']))
1360                        {
1361                                $data['result'] = 'false';
1362                                echo serialize($data);
1363                                return;
1364                        }
1365
1366                        $date = explode('-', $entry['birthdate']);
1367                        $j = 0;
1368                        for ($i = 0; $i < 5; $i+=2)
1369                        {
1370                                switch($dateformat{$i})
1371                                {
1372                                        case 'Y':
1373                                                $birthdate[$j] = $date[0];
1374                                                break;
1375
1376                                        case 'm':
1377                                        case 'M':
1378                                                $birthdate[$j] = $date[1];
1379                                                break;
1380
1381                                        case 'd':
1382                                                $birthdate[$j] = $date[2];
1383                                }
1384                                $j++;
1385                        }
1386                        $datecount = 0;
[285]1387                       
[2]1388                        $data['result'] = 'ok';
1389                        $data['cc_full_add_contact_id'] = $id;
1390
1391                        /* Personal Data */
1392                        $data['personal']['cc_pd_photo'] = '../index.php?menuaction=contactcenter.ui_data.data_manager&method=get_photo&id='.$id;
1393                        $data['personal']['cc_pd_alias'] = $entry['alias'];
1394                        $data['personal']['cc_pd_given_names'] = $entry['given_names'];
1395                        $data['personal']['cc_pd_family_names'] = $entry['family_names'];
1396                        $data['personal']['cc_pd_full_name'] = $entry['names_ordered'];
1397                        $data['personal']['cc_pd_suffix'] = $entry['id_suffix'];
1398                        $data['personal']['cc_pd_birthdate_0'] = $birthdate[0];
1399                        $data['personal']['cc_pd_birthdate_1'] = $birthdate[1];
1400                        $data['personal']['cc_pd_birthdate_2'] = $birthdate[2];
1401                        //$data['personal']['cc_pd_sex'] = $entry['sex'] === 'M' ? 1 : ($entry['sex'] === 'F' ? 2 : 0);
1402                        $data['personal']['cc_pd_prefix'] = $entry['id_prefix'];
1403                        $data['personal']['cc_pd_gpg_finger_print'] = $entry['pgp_key'];
1404                        $data['personal']['cc_pd_notes'] = $entry['notes'];
1405
1406                        /* Addresses */
1407                        if (is_array($entry['addresses']))
1408                        {
1409                                $data['addresses'] = $entry['addresses'];
1410                        }
1411
1412                        /* Connections */
1413                        if (is_array($entry['connections']))
1414                        {
1415                                $data['connections'] = array();
1416                                foreach ($entry['connections'] as $connection)
1417                                {
1418                                        $type = $connection['id_type'];
1419                                        $i = count($data['connections'][$type]);
1420                                        $data['connections'][$type][$i]['id'] = $connection['id_connection'];
1421                                        $data['connections'][$type][$i]['name'] = $connection['connection_name'];
1422                                        $data['connections'][$type][$i]['value'] = $connection['connection_value'];
1423                                        $data['connections'][$type][$i]['is_default'] = $connection['connection_is_default'];
1424                                }
1425                        }
1426//                      print_r($data);
1427
1428                        /* Relations */
[285]1429                       
[2]1430                        echo serialize($data);
1431                }
1432
1433                /*!
1434
1435                        @function get_contact_full_add_const
1436                        @abstract Returns all the constant fields in Contact Full Add Window to the JS
1437                        @author Raphael Derosso Pereira
1438                */
1439                function get_contact_full_add_const()
1440                {
1441                        $data = array();
1442                        $boPeopleCatalog = CreateObject('contactcenter.bo_people_catalog');
1443                        $predata[] = $boPeopleCatalog -> get_all_prefixes();
1444                        $predata[] = $boPeopleCatalog -> get_all_suffixes();
1445                        $predata[] = $boPeopleCatalog -> get_all_addresses_types();
1446                        $predata[] = $boPeopleCatalog -> get_all_countries();
1447                        $predata[] = $boPeopleCatalog -> get_all_connections_types();
1448                        //$predata[] = $this->bo->catalog->get_all_relations_types();
1449
1450                        $i = 0;
1451                        foreach($predata as $data_)
1452                        {
1453                                if ($data_)
1454                                {
1455                                        $data[$i] = $data_;
1456                                }
1457
1458                                $i++;
1459                        }
1460
1461                        if (count($data))
1462                        {
1463                                echo serialize($data);
1464                                return;
1465                        }
[285]1466                       
[2]1467                        echo 0;
1468                }
[285]1469               
[2]1470                /*!
[285]1471               
[2]1472                        @function quick_add
1473                        @abstract Adds a new Contact using the Quick Add interface
1474                        @author Raphael Derosso Pereira
[285]1475                       
[2]1476                        @param string $sdata Serialized data
1477                */
1478                function quick_add($sdata)
1479                {
[285]1480                       
[2]1481                        $sdata = str_replace('\\"', '"', $sdata);
1482                        $new_array = unserialize($sdata);
1483                        $tdata = array();
[285]1484                       
[2]1485                        foreach($new_array as $tmp)
1486                                $tdata[] = $tmp;
[285]1487                       
[2]1488                        if (!$tdata)
1489                        {
1490                                echo serialize(array(
1491                                        'msg'    => lang('Problems on adding your Contact. Invalid Data came from client. No Contact added!'),
1492                                        'status' => 'abort'
1493                                ));
[285]1494                               
[2]1495                                return;
1496                        }
[285]1497                       
1498                        // verifica se email já existe!
[2]1499                        $boGroup = CreateObject('contactcenter.bo_group');
1500                        $contact = $boGroup->verify_contact($tdata[4]);
[285]1501                                                                                               
[2]1502                        if($contact)
[285]1503                        {                                                       
[2]1504                                $str_contact = "\r\n - ".implode("\r\n - ",$contact);
[285]1505                               
[2]1506                                echo serialize(array(
1507                                        'msg'    => lang('Problems on adding your Contact. The email "%1" already exists in: %2',$tdata[4], $str_contact),
1508                                        'status' => 'alreadyExists'
1509                                ));
[285]1510                               
1511                                return;                 
[2]1512                        }
1513
1514                        $data['alias'] = $tdata[0];
1515                        $data['given_names'] = $tdata[1];
1516                        $data['family_names'] = $tdata[2];
1517//                      $data['connections']['default_phone']['id_typeof_connection'] = 1;
1518                        $data['connections']['default_phone']['connection_name'] = lang('Main');
1519                        $data['connections']['default_phone']['connection_value'] = $tdata[3];
1520//                      $data['connections']['default_email']['id_typeof_connection'] = 2;
1521                        $data['connections']['default_email']['connection_name'] = lang('Main');
1522                        $data['connections']['default_email']['connection_value'] = $tdata[4];
1523
1524                        $boPeople = CreateObject('contactcenter.bo_people_catalog');
1525
1526                        if ($boPeople ->quick_add($data))
[285]1527                        {                               
[2]1528                                $this->page_info['changed'] = true;
[285]1529                               
[2]1530                                echo serialize(array(
1531                                        'msg'    => lang('Entry added with success!'),
1532                                        'status' => 'ok'
1533                                ));
1534                        }
1535                        else
1536                        {
1537                                echo serialize(array(
1538                                        'msg'    => lang('Problems on adding your Contact. No Contact added!'),
1539                                        'status' => 'error'
1540                                ));
1541                        }
1542
[285]1543                        $this->save_session(); 
1544                       
[2]1545                }
1546
1547                /*!
[285]1548               
[2]1549                        @function add_group
1550                        @abstract Adds a new Group using the Add Group interface
1551                        @author Nilton Emilio Buhrer Neto
[285]1552                       
[2]1553                        @param string $sdata Serialized data
1554                */
1555                function add_group($sdata)
1556                {
1557                        $sdata = str_replace('\\"', '"', $sdata);
1558                        $tdata = unserialize($sdata);
1559                        $new_tdata = array();
[285]1560                       
[2]1561                        if (!$tdata)
1562                        {
1563                                echo serialize(array(
1564                                        'msg'    => lang('Problems on adding your Contact. Invalid Data came from client. No Contact added!'),
1565                                        'status' => 'abort'
1566                                ));
[285]1567                               
[2]1568                                return;
1569                        }
[285]1570                       
[2]1571                        foreach($tdata as $tmp)
1572                                $new_tdata[] = $tmp;
[285]1573                       
1574                        $data['title'] = $new_tdata[0];                 
[2]1575                        $data['contact_in_list'] = $new_tdata[1];
1576                        $data['id_group'] = $new_tdata[2];
[285]1577                                               
[2]1578                        $boGroup = CreateObject('contactcenter.bo_group_manager');
1579                        $id = $boGroup -> add_group($data);
[285]1580                       
[2]1581                        if ($id)
1582                        {
1583                                $this->page_info['changed'] = true;
[285]1584                               
[2]1585                                echo serialize(array(
1586                                        'msg'    => lang('Entry added with success!'),
1587                                        'status' => 'ok'
1588                                ));
1589                        }
1590                        else
1591                        {
1592                                echo serialize(array(
1593                                        'msg'    => lang('Problems on adding your Contact. No Contact added!'),
1594                                        'status' => 'error'
1595                                ));
1596                        }
1597
1598                        $this->save_session();
1599                }
1600
1601                /*!
[285]1602               
[2]1603                        @function remove_group
1604                        @abstract Removes a group if the user has the right to do it
[285]1605                        @author Nilton Emilio Buhrer Neto                       
[2]1606                        @param (integer) $id The id to be removed
[285]1607                               
[2]1608                */
1609                function remove_group($id)
[285]1610                {                               
1611                                $soGroup = CreateObject('contactcenter.so_group');                             
[2]1612                                $data = array ('id_group' => $id);
1613                                if($soGroup -> delete($data)) {
1614                                        echo serialize(array(
1615                                                'msg'    => lang('Removed Entry ID '.$id.'!'),
1616                                                'status' => 'ok'
[285]1617                                        ));                                                     
[2]1618                                }
1619                                else {
1620                                        echo serialize(array(
1621                                                'msg'    => lang('Problems on adding your Contact. No Contact added!'),
1622                                                'status' => 'error'
1623                                        ));
1624                                }
1625
[285]1626                        $this->save_session();                         
[2]1627                }
1628
1629
1630                function remove_all_entries (){
[285]1631               
[2]1632                        $error = false;
1633                        $this->all_entries = $this->bo->catalog->get_all_entries_ids();
1634
1635                        foreach($this->all_entries as $index => $id) {
1636                                $result = $this->bo->catalog->remove_single_entry($id);
1637                                if(!$result) {
1638                                        $error = true;
[285]1639                                        break;         
[2]1640                                }
1641                        }
1642
1643                        if(!$error) {
1644                                echo serialize(array(
1645                                        'msg'    => lang('Removed Entry ID '.$id.'!'),
1646                                        'status' => 'ok'
1647                                ));
[285]1648                        }
[2]1649                        else {
1650                                echo serialize(array(
1651                                        'msg'    => lang('Couldn\'t remove this entry. Inform the Site Admin!'),
1652                                        'status' => 'fail'
1653                                ));
1654                        }
1655
1656                        $this->save_session();
1657                }
1658
1659                /*!
[285]1660               
[2]1661                        @function remove_entry
1662                        @abstract Removes an entry if the user has the right to do it
1663                        @author Raphael Derosso Pereira
[285]1664                       
[2]1665                        @param (integer) $id The id to be removed
[285]1666                               
[2]1667                */
1668                function remove_entry ($id)
1669                {
1670                        if (!is_int($id))
1671                        {
1672                                echo lang('Couldn\'t remove entry! Problem passing data to the server. Please inform admin!');
1673                                return;
1674                        }
[285]1675                       
[2]1676                        $this->page_info['changed'] = true;
1677                        $result = $this->bo->catalog->remove_single_entry($id);
[285]1678                       
[2]1679                        if ($result)
1680                        {
1681                                if ($pos = array_search($id, $this->page_info['actual_entries']))
1682                                {
1683                                        unset($this->page_info['actual_entries'][$pos]);
1684                                }
[285]1685                               
[2]1686                                $temp = false;
1687                                reset($this->page_info['actual_entries']);
1688                                foreach($this->page_info['actual_entries'] as $t)
1689                                {
1690                                        $temp[] = $t;
1691                                }
[285]1692                               
[2]1693                                $this->page_info['actual_entries'] = $temp;
1694
1695                                echo serialize(array(
1696                                        'msg'    => lang('Removed Entry ID '.$id.'!'),
1697                                        'status' => 'ok'
1698                                ));
1699                        }
1700                        else
1701                        {
1702                                echo serialize(array(
1703                                        'msg'    => lang('Couldn\'t remove this entry. Inform the Site Admin!'),
1704                                        'status' => 'fail'
1705                                ));
1706                        }
[285]1707                       
[2]1708                        $this->save_session();
1709                }
1710
[285]1711               
[2]1712                /*!
[285]1713               
[2]1714                        @function post_full_add
1715                        @abstract Saves all the information altered/entered in the Full Add
1716                                window
1717                        @author Raphael Derosso Pereira
1718
1719                */
1720                function post_full_add()
1721                {
[285]1722                        $data =  $_POST['data'];
1723                        // Exceptions!!! utf8 special chars.
1724                        $data = preg_replace("/\%u2(\d+)(\d+)(\d+)/","-",$data);
1725                        $data = unserialize(str_replace('\\"', '"', $data));
[2]1726                        $this -> bo -> catalog = CreateObject('contactcenter.bo_people_catalog');
1727
1728                        if (!is_array($data))
1729                        {
1730                                echo serialize(array(
1731                                        'msg' => lang('<p>Some problem receiving data from browser. This is probably a bug in ContactCenter<br>'.
1732                                                  'Please go to eGroupWare Bug Reporting page and report this bug.<br>'.
1733                                                          'Sorry for the inconvenient!<br><br>'.
1734                                                          '<b><i>ContactCenter Developer Team</i></b></p>'),
1735                                        'status' => 'fatal'
1736                                ));
1737                                return;
1738                        }
1739//                      print_r($data);
1740//                      echo '<br><br>';
1741
1742                        $replacer = $data['commercialAnd'];
1743                        unset($data['commercialAnd']);
1744                        if (!is_string($replacer) or strpos($replacer, "'") or strpos($replacer, '"'))
1745                        {
1746                                echo serialize(array(
1747                                        'msg' => lang('Invalid \'&\' replacer! This may be an attempt to bypass Security! Action aborted!'),
1748                                        'status' => 'fatal'
1749                                ));
[285]1750                               
[2]1751                                return;
1752                        }
1753
1754                        if ($data['id_contact'])
1755                        {
1756                                $id = $data['id_contact'];
1757                                $id_photo = $id;
1758                                unset($data['id_contact']);
1759                        }
1760                        else
1761                        {
1762                                $id_photo = '_new_';
1763                        }
[285]1764                       
1765                        /*
1766                         * Process Photo, if available
[2]1767                         */
1768                        $sleep_count = 0;
1769                        $photo_ok = $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter');
1770                        while($photo_ok[0]{0} !== 'o' and $photo_ok[1]{0} === 'y')
1771                        {
1772                                sleep(1);
1773                                $photo_ok = $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter');
1774                                $sleep_count++;
1775
1776                                if ($sleep_count > 35)
1777                                {
1778                                        // TODO
1779                                        return;
1780                                }
1781                        }
1782                        $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('wait', 'n'));
[285]1783                       
[2]1784                        if (isset($this->page_info['photos'][$id_photo]))
1785                        {
1786                                if (array_search($this->page_info['photos'][$id_photo]['status'], array('changed', 'sync')) === false)
1787                                {
1788                                        echo serialize(array(
1789                                                'msg' => $this->page_info['photos'][$id_photo]['msg'],
1790                                                'status' => $this->page_info['photos'][$id_photo]['status']
1791                                        ));
1792
1793                                        return;
1794                                }
1795
1796                                $data['photo'] = $this->page_info['photos'][$id_photo]['content'];
1797                                unset($this->page_info['photos'][$id_photo]);
1798                                $this->save_session();
1799                        }
[285]1800                       
[2]1801                        /*
1802                         * Arrange Date so it gets inserted correctly
1803                         */
[285]1804                         
[2]1805                        $dateformat = $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
[285]1806               
[2]1807                        $j = 0;
1808                        for ($i = 0; $i < 5; $i+=2)
1809                        {
1810                                switch($dateformat{$i})
1811                                {
1812                                        case 'Y':
1813                                                $date[$j]['size'] = 4;
1814                                                $date[$j]['digit'] = 'Y';
1815                                                break;
1816
1817                                        case 'm':
1818                                        case 'M':
1819                                                $date[$j]['size'] = 2;
1820                                                $date[$j]['digit'] = 'M';
1821                                                break;
1822
1823                                        case 'd':
1824                                                $date[$j]['size'] = 2;
1825                                                $date[$j]['digit'] = 'D';
1826                                }
1827                                $j++;
1828                        }
1829                        $datecount = 0;
1830
1831                        /* Verify Data and performs insertion/update */
1832                        foreach($data as $field => $value)
1833                        {
1834                                if ($value == '' or is_null($value))
1835                                {
1836                                        unset($data[$field]);
1837                                        continue;
1838                                }
[285]1839                               
[2]1840                                switch($field)
1841                                {
1842                                        case 'alias':
1843                                        case 'given_names':
1844                                        case 'family_names':
1845                                        case 'names_ordered':
1846                                        case 'pgp_key':
1847                                        case 'notes':
1848                                        case 'photo':
1849                                                /* Do Nothing. This is just to make sure no invalid field is passed */
1850                                                break;
[285]1851                                       
[2]1852                                        case 'id_status':
1853                                        case 'id_prefix':
1854                                        case 'id_suffix':
1855                                                if ($data[$field] == 0)
1856                                                {
1857                                                        unset($data[$field]);
1858                                                }
1859                                                break;
[285]1860                                       
[2]1861                                        case 'birthdate_0':
1862                                        case 'birthdate_1':
1863                                        case 'birthdate_2':
[285]1864                                       
[2]1865                                                switch($date[$datecount]['digit'])
1866                                                {
1867                                                        case 'Y':
1868                                                                $date['value'][2] = (int) $data[$field];
1869                                                                break;
1870
1871                                                        case 'M':
1872                                                                $date['value'][0] = (int) $data[$field];
1873                                                                break;
1874
1875                                                        case 'D':
1876                                                                $date['value'][1] = (int) $data[$field];
1877                                                                break;
1878                                                }
1879                                                unset($data[$field]);
1880                                                $datecount++;
1881
1882                                                if ($datecount != 3)
1883                                                {
1884                                                        break;
1885                                                }
[285]1886                                               
[2]1887                                                if (!checkdate($date['value'][0], $date['value'][1], $date['value'][2]))
1888                                                {
1889                                                        echo serialize(array(
1890                                                                'msg' => lang('Invalid Date'),
1891                                                                'status' => 'invalid_data'
1892                                                        ));
1893                                                        return;
1894                                                }
[285]1895                                               
[2]1896                                                $data['birthdate'] = $date['value'][2].'-'.$date['value'][0].'-'.$date['value'][1];
1897                                                break;
1898
1899                                        case 'sex':
1900                                                if ($data[$field] !== 'M' and $data[$field] !== 'F')
1901                                                {
1902                                                        echo serialize(array(
1903                                                                'msg' => lang('Invalid Sex'),
1904                                                                'status' => 'invalid_data'
1905                                                        ));
1906                                                        return;
1907                                                }
1908                                                break;
1909
1910
1911                                        case 'addresses':
1912                                                /* Insert new cities/states */
1913                                                if (isset($value['new_states']))
1914                                                {
1915                                                        foreach($value['new_states'] as $type => $state_info)
1916                                                        {
1917                                                                $index = 'address'.$type;
[285]1918                                                               
[2]1919                                                                $id_state = $this->bo->catalog->add_state($state_info);
1920                                                                $data['addresses'][$index]['id_state'] = $id_state;
1921
1922                                                                if ($value['new_cities'][$type])
1923                                                                {
1924                                                                        $value['new_cities'][$type]['id_state'] = $id_state;
1925                                                                }
1926                                                        }
1927
1928                                                        unset($data['addresses']['new_states']);
1929                                                }
1930
1931                                                if (isset($value['new_cities']))
1932                                                {
1933                                                        foreach($value['new_cities'] as $type => $city_info)
1934                                                        {
1935                                                                $index = 'address'.$type;
[285]1936                                                               
[2]1937                                                                $id_city = $this->bo->catalog->add_city($city_info);
1938                                                                $data['addresses'][$index]['id_city'] = $id_city;
1939                                                        }
1940
1941                                                        unset($data['addresses']['new_cities']);
1942                                                }
1943
1944                                        break;
1945
1946                                        case 'connections':
1947                                                /* Does nothing... */
1948                                                break;
1949
1950                                        default:
1951                                                echo serialize(array(
1952                                                        'msg' => lang('Invalid field: ').$field,
1953                                                        'status' => 'invalid_data'
1954                                                ));
1955                                                return;
1956                                }
1957                        }
1958
1959                        $code = '$id = $this->bo->catalog->';
1960
1961                        if (!is_null($id) and $id !== '')
1962                        {
1963                                $code .= $code.'update_single_info($id, $data);';
1964                                $result = array(
1965                                        'msg' => lang('Updated Successfully!'),
1966                                        'status' => 'ok'
1967                                );
1968                        }
1969                        else
1970                        {
1971                                $code .= 'add_single_entry($data);';
1972                                $result = array(
1973                                        'msg' => lang('Entry Added Successfully!'),
1974                                        'status' => 'ok'
1975                                );
1976                        }
[285]1977                       
[2]1978                        eval($code);
1979
1980                        if (!($id))
1981                        {
1982                                $result = array(
1983                                        'msg' => lang('Some problem occured when trying to insert/update contact information.<br>'.
1984                                                   'Report the problem to the Administrator.'),
1985                                        'status' => 'fail'
1986                                );
1987                        }
1988
1989                        echo serialize($result);
1990                }
1991
1992                /*!
[285]1993               
[2]1994                        @function post_photo
1995                        @abstract Wrapper to post a photo without reload a page.
1996                        @author Raphael Derosso Pereira
1997
1998                */
1999                function post_photo($id)
2000                {
2001                        //print_r($_FILES);
2002                        $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('wait', 'y'));
[285]2003                       
[2]2004                        if (!is_array($_FILES) and is_array(!$_FILES['cc_pd_photo']))
2005                        {
2006                                $this->page_info['photos'][$id]['status'] = 'no_upload';
2007                                $this->page_info['photos'][$id]['msg'] = lang('No Photos uploaded to Server.');
[285]2008                               
[2]2009                                $this->save_session();
2010                                $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('ok', 'y'));
2011                                return;
2012                        }
2013
2014                        if (!function_exists('imagecreate'))
2015                        {
2016                                $this->page_info['photos'][$id]['status'] = 'no_GD_lib';
2017                                $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.');
[285]2018                               
[2]2019                                $this->save_session();
2020                                $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('ok', 'y'));
2021                                return;
2022                        }
2023
2024                        // TODO: Get Max Size from preferences!
2025                        if ($_FILES['cc_pd_photo']['size'] > 1000000)
2026                        {
2027                                $this->page_info['photos'][$id]['status'] = 'too_large';
2028                                $this->page_info['photos'][$id]['msg'] = lang('Image too large! ContactCenter limits the image size to 1 Mb');
2029
2030                                $this->save_session();
2031                                $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('ok', 'y'));
2032                                return;
2033                        }
2034
2035                        if ($_FILES['cc_pd_photo']['error'])
2036                        {
2037                                $this->page_info['photos'][$id]['status'] = 'error';
2038                                $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'];
2039
2040                                $this->save_session();
2041                                $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('ok', 'y'));
2042                                return;
2043                        }
[285]2044                       
[2]2045                        switch($_FILES['cc_pd_photo']['type'])
2046                        {
2047                                case 'image/jpeg':
2048                                case 'image/pjpeg':
2049                                        $src_img = imagecreatefromjpeg($_FILES['cc_pd_photo']['tmp_name']);
2050                                        if ($src_img == '')
2051                                        {
2052                                                $bogus = true;
2053                                        }
2054                                        break;
2055
2056                                case 'image/png':
2057                                case 'image/x-png':
2058                                        $src_img = imagecreatefrompng($_FILES['cc_pd_photo']['tmp_name']);
2059                                        if ($src_img == '')
2060                                        {
2061                                                $bogus = true;
2062                                        }
2063                                        break;
2064
2065                                case 'image/gif':
2066                                        $src_img = imagecreatefromgif($_FILES['cc_pd_photo']['tmp_name']);
2067                                        if ($src_img == '')
2068                                        {
2069                                                $bogus = true;
2070                                        }
2071                                        break;
2072
2073                                default:
[285]2074                                       
[2]2075                                        $this->page_info['photos'][$id]['status'] = 'invalid_image';
2076                                        $this->page_info['photos'][$id]['msg'] = lang('The file must be an JPEG, PNG or GIF Image.');
2077
2078                                        $this->save_session();
2079                                        $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('ok', 'y'));
2080                                        return;
2081                        }
2082
2083                        if ($bogus)
2084                        {
2085                                        $this->page_info['photos'][$id]['status'] = 'invalid_file';
2086                                        $this->page_info['photos'][$id]['msg'] = lang('Couldn\'t open Image. It may be corrupted or internal library doesn\'t support this format.');
[285]2087                                       
[2]2088                                        $this->save_session();
2089                                        $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('ok', 'y'));
2090                                        return;
2091                        }
[285]2092                       
[2]2093                        $img_size = getimagesize($_FILES['cc_pd_photo']['tmp_name']);
2094                        $dst_img = imagecreatetruecolor(60, 80);
[285]2095                       
[2]2096                        if (!imagecopyresized($dst_img, $src_img, 0, 0, 0, 0, 60, 80, $img_size[0], $img_size[1]))
2097                        {
2098                                $this->page_info['photos'][$id]['status'] = 'invalid_file';
2099                                $this->page_info['photos'][$id]['msg'] = lang('Couldn\'t open Image. It may be corrupted or internal library doesn\'t support this format.');
[285]2100                               
[2]2101                                $this->save_session();
2102                                $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('ok', 'y'));
2103                                return;
2104                        }
[285]2105                       
[2]2106                        ob_start();
2107                        imagepng($dst_img);
2108                        $this->page_info['photos'][$id]['content'] = ob_get_contents();
2109                        ob_end_clean();
2110
2111                        $this->page_info['photos'][$id]['status'] = 'changed';
2112                        $this->page_info['photos'][$id]['msg'] = lang('Photo Successfully Updated!');
2113
2114                        $this->save_session();
[285]2115               
[2]2116                        $GLOBALS['phpgw']->session->appsession('ui_data.photo','contactcenter', array('ok', 'y'));
2117
2118                        imagedestroy($src_img);
2119                        imagedestroy($dst_img);
2120                        echo 'ok';
2121                        return;
2122                }
2123
2124
2125                /*!
2126
2127                        @function get_photo
2128                        @abstract Returns the photo to the browser
2129                        @author Raphael Derosso Pereira
2130
2131                */
2132                function get_photo($id)
2133                {
2134                        $fields = $this->bo->catalog->get_fields(false);
2135                        $fields['photo'] = true;
[285]2136                       
[2]2137                        $contact = $this->bo->catalog->get_single_entry($id, $fields);
2138
2139                        if (!$contact['photo'])
2140                        {
2141                                header('Content-type: image/png');
2142                                echo file_get_contents(PHPGW_INCLUDE_ROOT.'/contactcenter/templates/default/images/photo_celepar.png');
2143                                return;
2144                        }
[285]2145                       
[2]2146                        header('Content-type: image/jpeg');
2147                        $photo = imagecreatefromstring ($contact['photo']);
2148                        $width = imagesx($photo);
2149                        $height = imagesy($photo);
[16]2150                        $twidth = 70;
2151                        $theight = 90;
[2]2152                        $small_photo = imagecreatetruecolor ($twidth, $theight);
2153                        imagecopyresampled($small_photo, $photo, 0, 0, 0, 0,$twidth, $theight, $width, $height);
2154                        imagejpeg($small_photo,"",100);
2155                        return;
2156                }
[285]2157               
[2]2158                /*!
[285]2159               
[2]2160                        @function get_states
2161                        @abstract Echos a serialized array containing all the states for the given country
2162                        @author Raphael Derosso Pereira
2163
2164                        @params $id_country The ID of the Country that contains the requested states
2165
2166                */
2167                function get_states($id_country)
2168                {
2169                        $states = $this->bo->catalog->get_all_states($id_country);
2170
2171                        if (!$states)
2172                        {
2173                                $result = array(
2174                                        'msg'    => lang('No States found for this Country.'),
2175                                        'status' => 'empty'
2176                                );
2177
2178                                echo serialize($result);
2179                                return;
2180                        }
[285]2181                       
[2]2182                        $result = array(
2183                                'msg'    => lang('States Successfully retrieved!'),
2184                                'status' => 'ok'
2185                        );
[285]2186                       
[2]2187                        foreach ($states as $state_info)
2188                        {
2189                                $result['data'][$state_info['id_state']] = $state_info['name'];
2190
2191                                if ($state_info['symbol'])
2192                                {
2193                                        $result['data'][$state_info['id_state']] .= ', '.$state_info['symbol'];
2194                                }
2195                        }
2196
2197                        echo serialize($result);
2198                }
2199
2200                /*!
2201
2202                        @function get_cities
2203                        @abstract Echos a serialized array containing all the cities of a given state
2204                        @author Raphael Derosso Pereira
2205
2206                        @param $id_country The ID of the Country that has the specified Cities (in case the
2207                                Country doesn't have any States)
2208                        @param $id_state The ID of the State that has the Cities requested
2209
2210                */
2211                function get_cities($id_country, $id_state=false)
2212                {
2213                        $cities = $this->bo->catalog->get_all_cities($id_country, $id_state);
2214
2215                        if (!$cities)
2216                        {
2217                                $result = array(
2218                                        'msg'    => lang('No Cities found for this State.'),
2219                                        'status' => 'empty'
2220                                );
2221
2222                                echo serialize($result);
2223                                return;
2224                        }
[285]2225                       
[2]2226                        $result = array(
2227                                'msg'    => lang('Cities Successfully retrieved!'),
2228                                'status' => 'ok'
2229                        );
[285]2230                       
[2]2231                        foreach ($cities as $city_info)
2232                        {
2233                                $result['data'][$city_info['id_city']] = $city_info['name'];
2234                        }
[285]2235                       
[2]2236                        echo serialize($result);
2237                }
2238
2239
2240                /*!
[285]2241               
[2]2242                        @function search
2243                        @abstract Echos a serialized array containing the IDs
2244                                of the entries that matches the search argument
2245                        @author Raphael Derosso Pereira
[285]2246                        @author Mário César Kolling (external catalogs)
[2]2247
2248                        @param string $str_data A serialized array with two informations:
2249                                $data = array(
2250                                        'search_for' => (string),
2251                                        'recursive'  => (boolean),
2252                                );
2253
2254                */
[285]2255                // SERPRO
[2]2256                function search($str_data)
2257                {
2258                        $data = unserialize($str_data);
[284]2259                        // It's an external catalog?
2260                        $external = $this->bo->is_external($this->page_info['actual_catalog']);
[285]2261                       
2262            if (!is_array($data) || !$data['search_for'] || !is_array($data['fields']))
2263            {
2264                echo serialize(array(                                                                                                   
2265                   'msg'    => lang('Invalid parameters'),                                                                             
2266                    'status' => 'abort'
2267                ));
2268           
2269                return array('error' => lang('Invalid parameters'));                                                                                                                 
2270            }   
[2]2271
[285]2272           
[284]2273                        /*
2274                         * TODO: look into the database to discover the database's encoding and convert the search_for field accordingly
2275                         */
2276                        // Support search parameters with accentuation
2277                        if ($this->page_info['actual_catalog']['class'] != 'bo_people_catalog' &&
[503]2278                                $this->page_info['actual_catalog']['class'] != 'bo_group_manager' &&
[752]2279                                $this->page_info['actual_catalog']['class'] != 'bo_shared_people_manager' &&
2280                                $this->page_info['actual_catalog']['class'] != 'bo_shared_group_manager')
[284]2281                        {
2282
2283                                $data['search_for'] = utf8_encode($data['search_for']);
2284                        }
[285]2285           
2286            $rules  = array();                                                                                                         
2287           
2288           
2289            if ($data['search_for'] === '*')                                                                                           
2290            {
2291                $rules = array(                                                                                                         
2292                    0 => array(                                                                                                         
2293                        'field' => $data['fields']['search'],                                                                           
2294                        'type'  => 'LIKE',
2295                        'value' => '%'
2296                    )   
2297                ); 
2298            }   
2299            else                                                                                                                       
2300            {
2301                $names = explode(' ', $data['search_for']);                                                                             
2302               
2303                if (!is_array($names))                                                                                                 
2304                {
2305                    echo serialize(array(                                                                                               
2306                        'msg'    => lang('Invalid Search Parameter'),                                                                   
2307                        'status' => 'abort'
2308                    ));
2309 
2310                }
[284]2311
2312                                if (!$external && $this->page_info['actual_catalog']['class'] != 'bo_people_catalog' &&
[503]2313                                        $this->page_info['actual_catalog']['class'] != 'bo_group_manager' &&
[752]2314                                        $this->page_info['actual_catalog']['class'] != 'bo_shared_people_manager' &&                                   
2315                                        $this->page_info['actual_catalog']['class'] != 'bo_shared_group_manager' )
[284]2316                                {
2317                                        /*
2318                                         * Restrict the returned contacts search to objectClass = phpgwAccount,
[880]2319                                         * must have attibute phpgwAccountStatus, phpgwAccountVisible != -1
[284]2320                                         */
2321                                        $rules = array(
2322                                                0 => array(
2323                                                        'field' => 'contact.object_class',
2324                                                        'type'  => '=',
2325                                                        'value' => 'phpgwAccount'
2326                                                ),
2327                                                1 => array(
2328                                                        'field' => 'contact.account_status',
2329                                                        'type'  => 'iLIKE',
2330                                                        'value' => '%'
2331                                                ),
2332                                                2 => array(
2333                                                        'field' => 'contact.account_visible',
2334                                                        'type'  => '!=',
2335                                                        'value' => '-1'
2336                                                ),
2337                                        );
2338                                }
[285]2339               
2340                foreach ($names as $name)
2341                {
2342                    if ($name != '')
2343                    {
2344                        array_push($rules, array(
2345                            'field' => $data['fields']['search'],
2346                            'type'  => 'iLIKE',
2347                            'value' => '%'.$name.'%'
2348                        ));
2349                    }
2350                }
2351            }
[284]2352
2353                        if ($external || $this->page_info['actual_catalog']['class'] == 'bo_people_catalog' ||
[503]2354                                $this->page_info['actual_catalog']['class'] == 'bo_group_manager' ||
[752]2355                                $this->page_info['actual_catalog']['class'] == 'bo_shared_people_manager' ||
2356                                $this->page_info['actual_catalog']['class'] == 'bo_shared_group_manager'        )
[2]2357                        {
[284]2358                                // Get only this attributes: dn, cn for external catalogs,
2359                                // used to restrict the attributes used in filters
2360                                $ids = $this->bo->find(array($data['fields']['id'], $data['fields']['search']), $rules, array('order' => $data['fields']['search'], 'sort' => 'ASC'));
[2]2361                        }
[284]2362                        else
2363                        {
2364                                // Get only this attributes: dn, cn, phpgwAccountType, objectClass, phpgwAccountStatus, phpghAccountVisible
2365                                // for non-external catalogs, used to restrict the attributes used in filters
2366                                $ids = $this->bo->find(array(
2367                                        $data['fields']['id'],
2368                                        $data['fields']['search'],
2369                                        'contact.object_class',
[304]2370                                        //'contact.account_status',
[284]2371                                        'contact.account_visible'
2372                                        ), $rules, array('order' => $data['fields']['search'], 'sort' => 'ASC'));
2373                        }
[2]2374
[285]2375            if (!is_array($ids) || !count($ids))
2376            {
[284]2377                                $this->last_search_ids = null;
2378                                $this->save_session();
2379                                return null;
[285]2380            }
[2]2381
[285]2382            $id_field = substr($data['fields']['id'], strrpos($data['fields']['id'], '.')+1);
2383                       
2384            $ids_f = array();
[2]2385
[285]2386            foreach ($ids as $e_info)
2387            {
[752]2388                                if($this->page_info['actual_catalog']['class'] != 'bo_shared_people_manager' && $this->page_info['actual_catalog']['class'] != 'bo_shared_group_manager')
[503]2389                        $ids_f[] = $e_info[$id_field];
2390                else
2391                        $ids_f[] = array(0=>$e_info[$id_field],1=>$e_info['perms']);
[285]2392            }
[284]2393
2394                        return $ids_f;
[2]2395                }
[285]2396               
2397                // CELEPAR
2398                /*
2399        function search($str_data)
2400        {
2401            $data = unserialize($str_data);
[2]2402
[285]2403            if (!is_array($data) || !$data['search_for'] || !is_array($data['fields']))
2404            {
2405                echo serialize(array(
2406                    'msg'    => lang('Invalid parameters'),
2407                    'status' => 'abort'
2408                ));
2409
2410                return;
2411            }
2412
2413            $rules  = array();
2414
2415            if ($data['search_for'] === '*')
2416            {
2417                $rules = array(
2418                    0 => array(
2419                        'field' => $data['fields']['search'],
2420                        'type'  => 'LIKE',
2421                        'value' => '%'
2422                    )
2423                );
2424            }
2425            else
2426            {
2427                $names = explode(' ', $data['search_for']);
2428
2429                if (!is_array($names))
2430                {
2431                    echo serialize(array(
2432                        'msg'    => lang('Invalid Search Parameter'),
2433                        'status' => 'abort'
2434                    ));
2435                   
2436                    return;
2437                }
2438               
2439                foreach ($names as $name)
2440                {
2441                    if ($name != '')
2442                    {
2443                        array_push($rules, array(
2444                            'field' => $data['fields']['search'],
2445                            'type'  => 'iLIKE',
2446                            'value' => '%'.$name.'%'
2447                        ));
2448                    }
2449                }
2450            }
2451
2452           
2453           
2454            //$catalog = $this->bo->get_branch_by_level($this->bo->catalog_level[0]);
2455           
2456            //if ($catalog['class'] === 'bo_people_catalog')
2457            //{
2458            //    array_push($rules, array(
2459            //        'field' => 'contact.id_owner',
2460            //        'type'  => '=',
2461            //        'value' => $GLOBALS['phpgw_info']['user']['account_id']
2462            //    ));
2463            //}
2464           
2465           
2466            $ids = $this->bo->find(array($data['fields']['id'], $data['fields']['search']), $rules, array('order' => $data['fields']['search'], 'sort' => 'ASC'));
2467
2468            if (!is_array($ids) || !count($ids))
2469            {
2470                echo serialize(array(
2471                    'msg'    => lang('No Entries Found!'),
2472                    'status' => 'empty'
2473                ));
2474
2475                return;
2476            }
2477            $id_field = substr($data['fields']['id'], strrpos($data['fields']['id'], '.')+1);
2478
2479            $ids_f = array();
2480            foreach ($ids as $e_info)
2481            {
2482                $ids_f[] = $e_info[$id_field];
2483            }
2484
2485            echo serialize(array(
2486                'data'   => $ids_f,
2487                'msg'    => lang('Found %1 Entries', count($ids)),
2488                'status' => 'ok'
2489            ));
2490                       
2491                        return;
2492        }*/
[2]2493                /*!
2494
2495                        @function get_multiple_entries
2496                        @abstract Returns an array containing the specifiend data in the default
2497                                CC UI format
2498                        @author Raphael Derosso Pereira
2499
[285]2500                        @param array str_data A serialized array containing the ID's of the entries
[2]2501                                to be taken, the fields to be taken and the rules to be used on the
2502                                retrieval:
2503                                $data = array(
2504                                        'ids'    => array(...),
2505                                        'fields' => array(...),
2506                                        'rules'  => array(...)
2507                                );
2508
2509                */
2510                function get_multiple_entries($str_data)
2511                {
2512                        $data = unserialize($str_data);
[285]2513                       
[2]2514                        if (!is_array($data) or !count($data) or !count($data['fields']) or !count($data['ids']))
2515                        {
2516                                return array(
2517                                        'msg'    => lang('Invalid Parameters'),
2518                                        'status' => 'abort'
2519                                );
2520                        }
2521
2522                        $entries = $this->bo->catalog->get_multiple_entries($data['ids'], $data['fields']);
[285]2523                       
[2]2524                        if (!is_array($entries) or !count($entries))
2525                        {
2526                                return array(
2527                                        'msg'    => lang('No Entries Found!'),
2528                                        'status' => 'empty'
2529                                );
2530                        }
2531
2532                        return array(
2533                                'msg'    => lang('Found %1 Entries!', count($entries)),
2534                                'status' => 'ok',
2535                                'data'   => $entries
2536                        );
2537                }
2538
2539                /*
2540
2541                        @function get_all_entries
[285]2542                        @abstract Returns the specified fields for all catalog's entries
[2]2543                                in the default CC UI format
2544                        @author Raphael Derosso Pereira
2545
[285]2546                        @params array str_data A serialized array containing the fields to
[2]2547                                be grabbed, the maximum number of entries to be returned and a
2548                                boolean specifying if the calls refers to a new grab or to an
2549                                unfinished one.
2550
2551                */
2552                function get_all_entries($str_data)
2553                {
2554                        $data = unserialize($str_data);
[285]2555                       
2556                        if (!is_array($data) or
2557                            !count($data) or
2558                                !count($data['fields']) or
[2]2559                                !$data['maxlength'] or
2560                                (!$data['new'] and !$data['offset']))
2561                        {
2562                                return array(
2563                                        'msg'    => lang('Invalid Parameters'),
2564                                        'status' => 'abort'
2565                                );
2566                        }
2567
2568                        if ($data['new'])
2569                        {
2570                                $this->all_entries = $this->bo->catalog->get_all_entries_ids();
2571
2572                                $this->save_session();
2573
2574                                if (!is_array($this->all_entries) or !count($this->all_entries))
2575                                {
2576                                        return array(
2577                                                'msg'    => lang('No Entries Found!'),
2578                                                'status' => 'empty'
2579                                        );
2580                                }
2581
2582                                $data['offset'] = 0;
2583                        }
[285]2584                       
[2]2585                        if ($data['maxlength'] != -1)
2586                        {
2587                                $result = $this->bo->catalog->get_multiple_entries(array_slice($this->all_entries, $data['offset'], $data['maxlength']), $data['fields']);
2588                        }
2589                        else
2590                        {
2591                                $result = $this->bo->catalog->get_multiple_entries($this->all_entries, $data['fields']);
2592                        }
2593
2594                        $prefs = ExecMethod('contactcenter.ui_preferences.get_preferences');
[285]2595                       
[2]2596                        $jsCode = array();
2597                        $count = 0;
2598                        foreach ($result as $each)
2599                        {
2600                                if (!is_array($each))
2601                                {
2602                                        continue;
2603                                }
2604
[285]2605                                if($this-> typeContact == 'groups') {                           
2606                                       
[2]2607                                        foreach ($each as $field => $value)     {
[285]2608                                                                               
[2]2609                                                if ($field === 'title') {
2610                                                        $optionName = '\\"'.$value.'\\"';
[285]2611                                                         
[2]2612                                                }
2613                                                else if ($field === 'short_name')       {
[285]2614                                                       
[2]2615                                                        $jsCode[] = '_this.entries.options[_this.entries.options.length] = new Option("'.$optionName.' ('.$value.')", "'.$count.'");';
[285]2616                                                        $count++;                                                                                                                                                                       
2617                                                }                                       
[2]2618                                        }
2619                                }
[285]2620                               
2621                                else  {
[2]2622                                        foreach ($each as $field => $value)     {
2623                                                if ($field === 'names_ordered') {
2624                                                         if(is_array($value))
2625                                $value = $value[0];
2626                                                        $name = '\\"'.$value.'\\"';
2627                                                }
2628                                                else if ($field === 'connections')      {
[285]2629                                                       
[2]2630                                                        foreach ($value as $connection)         {
2631                                                                if ($connection['id_type'] == $prefs['personCardEmail'])        {
2632                                                                        $jsCode[] = '_this.entries.options[_this.entries.options.length] = new Option("'.$name.' <'.$connection['connection_value'].'>", "'.$count.'");';
2633                                                                        $count++;
2634                                                                }
2635                                                        }
2636                                                }
2637                                        }
2638                                }
2639                        }
2640
2641                        $jsCodeFinal = implode("\n", $jsCode);
[285]2642                       
[2]2643                        $nEntries = count($result);
[285]2644                       
[2]2645                        if (!$nEntries)
2646                        {
2647                                return array(
2648                                        'msg'    => lang('Error while getting user information...'),
2649                                        'status' => 'abort'
2650                                );
2651                        }
2652
2653                        return array(
2654                                'msg'      => lang('Found %1 Entries!', $nEntries),
2655                                'status'   => 'ok',
2656                                'typeContact'   => $this -> typeContact,
2657                                'final'    => $nEntries + $data['offset'] < count($this->all_entries) ? false : true,
2658                                'offset'   => $data['offset'] + $nEntries,
2659                                'data'     => $jsCodeFinal
2660                        );
2661                }
[285]2662               
[2]2663                /*********************************************************************\
2664                 *                      Auxiliar Methods                             *
2665                \*********************************************************************/
2666
2667                /*!
[285]2668               
[2]2669                        @function save_session
2670                        @abstract Saves the data on the session
2671                        @author Raphael Derosso Pereira
[285]2672               
[2]2673                */
2674                function save_session()
2675                {
2676                        $GLOBALS['phpgw']->session->appsession('ui_data.page_info','contactcenter',$this->page_info);
2677                        $GLOBALS['phpgw']->session->appsession('ui_data.all_entries','contactcenter',$this->all_entries);
2678                }
2679
2680                /*!
[285]2681               
[2]2682                        @function convert_tree
2683                        @abstract Converts the tree array in the BO format to a JS tree array compatible
2684                                with the one available in eGW
2685                        @author Raphael Derosso Pereira
[285]2686               
[2]2687                        @param (array)  $tree    The tree in the BO format
2688                        @param (string) $name    The tree name
2689                        @param (string) $iconDir The dir where the icons are
2690                        @param (string) $parent  The parent
2691                */
2692
2693                function convert_tree($tree, &$iconDir, $parent='0')
2694                {
2695//                      echo "Entrou<br>\tPai: $parent <br>";
2696                        $rtree = array();
2697
2698                        if ($parent === '0')
2699                        {
2700//                              echo 'Root!<br>';
2701                                $rtree['0'] = array(
2702                                        'type'       => 'catalog_group',
2703                                        'id'         => '0',
2704                                        'pid'        => 'none',
2705                                        'caption'    => lang('Catalogues'),
2706                                        'class'      => 'bo_catalog_group_catalog',
2707                                        'class_args' => array('_ROOT_', '$this', '$this->get_branch_by_level($this->catalog_level[0])')
2708                                );
2709                        }
2710
2711                        foreach($tree as $id => $value)
2712                        {
2713//                              echo 'ID: '.$id.'<br>';
2714                                $rtree[$parent.'.'.$id] = array(
2715                                        'type'    => $value['type'],
2716                                        'id'      => $parent.'.'.$id,
2717                                        'pid'     => $parent,
2718                                        'caption' => $value['name']
2719                                );
[285]2720                               
[2]2721                                switch($value['type'])
2722                                {
2723                                        case 'catalog_group':
2724                                        case 'mixed_catalog_group':
2725                                                $rtree = $rtree + $this->convert_tree($value['sub_branch'],$iconDir,$parent.'.'.$id);
2726                                                break;
2727                                }
2728                        }
2729
2730                        if (count($rtree))
2731                        {
2732                                return $rtree;
2733                        }
2734                }
2735
2736                function get_catalog_add_contact($id){
2737
2738                        $array_participants = array();
[13]2739                        if(!$this->bo->catalog->src_info) {
2740                                $ldap = CreateObject('contactcenter.bo_ldap_manager');
2741                                $this->bo->catalog->src_info = $ldap->srcs[1];
[2]2742                        }
[285]2743                       
2744                        $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]2745                        $dn=$this->bo->catalog->src_info['dn'];
2746                        $justThese = array("givenname","givenname","sn","telephonenumber","mail");
[285]2747                        $sr = ldap_read($ds,$id, "objectClass=*",$justThese);                                                   
2748                        $info = ldap_get_entries($ds, $sr);                                                     
[13]2749                        for($z = 0; $z < 5; $z++) {
[285]2750                                $participant = $info[0][$justThese[$z]];                                                                                                       
[13]2751                                array_push($array_participants, $participant);
2752                        }
2753
2754                        ldap_close($ds);
[2]2755                        echo serialize($array_participants);
[285]2756                }       
2757               
[880]2758                function get_catalog_participants_group($id)
2759                {
2760                        if(!$this->bo->catalog->src_info) {
2761                                $ldap = CreateObject('contactcenter.bo_ldap_manager');
2762                                $this->bo->catalog->src_info = $ldap->srcs[1];
2763                        }                       
2764                        $ds = $GLOBALS['phpgw']->common->ldapConnect($this->bo->catalog->src_info['host'], $this->bo->catalog->src_info['acc'], $this->bo->catalog->src_info['pw'], true);                     
2765                        $justThese = array("description","memberuid");                 
2766                        $sr = ldap_read($ds,$id, "objectClass=*",$justThese);                                                   
2767                        $info = ldap_get_entries($ds, $sr);
2768                        $member_uids = $info[0]['memberuid'];
2769                        $contact['names_ordered'] = $info[0]['description'];
2770                        $filter = "";                   
2771                        for($z = 0; $z < count($member_uids); $z++) {
2772                                if($member_uids[$z])
2773                                        $filter.="(uid=".$member_uids[$z].")"; 
2774                        }
2775                        $array_participants = array();
2776                        if($filter) {
[962]2777                                $filter = "(|".$filter.")";
[904]2778                                $valarray = explode(',',$id);
2779                                array_shift($valarray);
2780                                $dn = implode(',',$valarray);
[880]2781                                $justThese = array("cn","mail");
2782                                $sr = ldap_search($ds,$dn, $filter,$justThese);                                                         
2783                                $info = ldap_get_entries($ds, $sr);                                                     
2784                                for($z = 0; $z < $info['count']; $z++) {
2785                                        $participant =  '<font color=\'DARKBLUE\'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;'.$info[$z]['cn'][0].'&quot; &lt;'.$info[$z]['mail'][0].'&gt;</font><br>';
2786                                        $array_emails[$info[$z]['mail'][0]] = null;                                                             
2787                                        array_push($array_participants, $participant);                                 
2788                                }
2789                                ldap_close($ds);
2790                        }                       
2791                        sort($array_participants);
2792                        $innerHTML = '';                       
2793                        foreach($array_participants as $index => $participant){
2794                                $innerHTML .= $participant;
2795                        }
2796                        $return = array('size' => count($array_participants), 'names_ordered'=> $contact['names_ordered'], 'inner_html' => $innerHTML);                 
2797                        echo serialize($return);
2798                }
2799
[285]2800                function get_catalog_participants_list($id)
[2]2801                {
[285]2802                       
2803                        $fields = $this->bo->catalog->get_fields(false);                       
[2]2804                        $fields['names_ordered'] = true;
[285]2805                        $fields['mail_forwarding_address'] = true;                     
2806                        $contact = $this->bo->catalog->get_single_entry($id,$fields);                   
2807                       
[2]2808                        $array_participants = array();
2809                        $array_emails = array();
[880]2810
[2]2811                        $filter = null;
[285]2812                        for($z = 0; $z < $contact['mail_forwarding_address']['count']; $z++) {                 
[2]2813                                        if(strstr($contact['mail_forwarding_address'][$z],'@')) {
2814                                                $filter.="(mail=".$contact['mail_forwarding_address'][$z].")";
2815                                                $array_emails[$contact['mail_forwarding_address'][$z]] = "<font color=black>".$contact['mail_forwarding_address'][$z]."</font>";
[285]2816                                        }                                                                                                                               
2817                                        else
[2]2818                                                $array_participants[$z] = "<font color=red>".$contact['mail_forwarding_address'][$z]."</font>";
[285]2819                        }                                       
2820                       
[2]2821                        if($filter) {
[285]2822                                $filter = "(|".$filter.")";                                                     
[2]2823                                if(!$this->bo->catalog->src_info) {
2824                                        $ldap = CreateObject('contactcenter.bo_ldap_manager');
2825                                        $this->bo->catalog->src_info = $ldap->srcs[1];
2826                                }
[880]2827                                $ds = $GLOBALS['phpgw']->common->ldapConnect($this->bo->catalog->src_info['host'], $this->bo->catalog->src_info['acc'], $this->bo->catalog->src_info['pw'], true);
2828                               
[2]2829                                $dn=$this->bo->catalog->src_info['dn'];
2830                                $justThese = array("cn","mail");
[285]2831                                $sr = ldap_search($ds,$dn, $filter,$justThese);                                                         
2832                                $info = ldap_get_entries($ds, $sr);                                                     
[2]2833                                for($z = 0; $z < $info['count']; $z++) {
[24]2834                                        $participant =  '<font color=\'DARKBLUE\'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;'.$info[$z]['cn'][0].'&quot; &lt;'.$info[$z]['mail'][0].'&gt;</font><br>';
[285]2835                                        $array_emails[$info[$z]['mail'][0]] = null;                                                             
2836                                        array_push($array_participants, $participant);                                 
[2]2837                                }
[285]2838                               
[2]2839                                foreach($array_emails as $index => $email)
[285]2840                                        if($email)
2841                                                array_push($array_participants, "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".$email."<br>");                         
2842                                                                                               
[2]2843                                ldap_close($ds);
2844                        }
2845                        sort($array_participants);
[285]2846                        $innerHTML = '';                       
[24]2847                        foreach($array_participants as $index => $participant){
2848                                $innerHTML .= $participant;
2849                        }
[285]2850                        $return = array('size' => count($array_participants), 'names_ordered'=> $contact['names_ordered'], 'inner_html' => $innerHTML);                 
[24]2851                        echo serialize($return);
[285]2852                }       
2853               
[2]2854                function export_contacts($typeExport){
2855
2856                        $boGroup = CreateObject('contactcenter.bo_group');
2857                        $contacts = $boGroup->get_all_contacts();
2858                        $streamBuffer = '';
2859
2860                        if(!count($contacts))
2861                                echo null;
[285]2862                       
[2]2863                        switch($typeExport) {
2864
2865                                case 'outlook_en':
2866                                        $streamBuffer = "Name;E-mail Address;Notes;Mobile Phone;Pager;Company;".
[285]2867                                                        "Job Title;Home Phone;Home Fax;Business Phone;Business Fax\r\n";                                                       
[293]2868                                        foreach($contacts as $index => $object){
2869                                                $streamBuffer.= $object['names_ordered'].";".$object['connection_value'].";;;;;;".$object['phone'].";;;\r\n";
[2]2870                                        }
2871                                break;
[285]2872                               
[2]2873                                case 'outlook_pt-BR':
[285]2874                                        $streamBuffer = "Nome;End. de email;Endereço residencial;".
2875                                        "Cidade do endereço residencial;CEP do endereço residencial;".
2876                                        "Estado;País/região do endereço residencial;Telefone residencial;".
2877                                        "Rua do endereço comercial;Cidade do endereço comercial;".
2878                                        "CEP do endereço comercial;Estado do endereço comercial;".
2879                                        "País/região do endereço comercial;Telefone comercial;Empresa;Cargo\r\n";                                                       
[293]2880                                        foreach($contacts as $index => $object){
2881                                                $streamBuffer.= $object['names_ordered'].";".$object['connection_value'].";;;;;;".$object['phone'].";;;;;;;;\r\n";
[2]2882                                        }
2883                                break;
[285]2884                               
[15]2885                                case 'outlook2000_pt-BR':
2886                                        $streamBuffer = "\"Tratamento\",\"Nome\",\"Segundo Nome\",\"Sobrenome\",\"Sufixo\",".
[285]2887                                        "\"Empresa\",\"Departamento\",\"Cargo\",\"Rua do endereço comercial\",\"Rua do endereço comercial 2\",".
2888                                        "\"Rua do endereço comercial 3\",\"Cidade do endereço comercial\",\"Estado do endereço comercial\",".
2889                                        "\"CEP do endereço comercial\",\"País do endereço comercial\",\"Endereço residencial\",\"Rua residencial 2\",".
2890                                        "\"Rua residencial 3\",\"Cidade do endereço residencial\",\"Estado\",\"CEP do endereço residencial\",\"País do endereço residencial\",".
2891                                        "\"Outro endereço\",\"Outro endereço 2\",\"Outro endereço 3\",\"Cidade\",\"Estado\",\"CEP\",\"País\",".
[15]2892                                        "\"Telefone do assistente\",\"Fax comercial\",\"Telefone comercial\",\"Telefone comercial 2\",\"Retorno de chamada\",".
2893                                        "\"Telefone do carro\",\"Telefone principal da empresa\",\"Fax residencial\",\"Telefone residencial\",".
2894                                        "\"Telefone residencial 2\",\"ISDN\",\"Telefone celular\",\"Outro fax\",\"Outro telefone\",\"Pager\",\"Telefone principal\",".
[285]2895                                        "\"Radiofone\",\"Telefone TTY/TDD\",\"Telex\",\"Aniversário\",\"Anotações\",\"Caixa postal\",\"Categorias\",".
2896                                        "\"Código da empresa\",\"Código do governo\",\"Cônjuge\",\"Conta\",\"Endereço de correio eletrônico\",".
2897                                        "\"Nome de exibição do correio eletr.\",\"Endereço de correio eletrônico 2\",".
2898                                        "\"Nome de exibição do correio eletr.2\",\"Endereço de correio eletrônico 3\",".
2899                                        "\"Nome de exibição do correio eletr.3\",\"Datas especiais\",\"Disponibilidade da Internet\",".
2900                                        "\"Filhos\",\"Hobby\",\"Idioma\",\"Indicação\",\"Informações para cobrança\",\"Iniciais\",\"Local\",".
2901                                        "\"Nome do assistente\",\"Nome do gerenciador\",\"Página da Web\",\"Palavras-chave\",\"Particular\",\"Personalizado 1\",\"Personalizado 2\",".
2902                                        "\"Personalizado 3\",\"Personalizado 4\",\"Prioridade\",\"Profissão\",\"Quilometragem\",\"Sala\",\"Sensibilidade\",\"Servidor de diretório\",".
[15]2903                                        "\"Sexo\"\r\n";
[293]2904                                        foreach($contacts as $index => $object){
2905                                                $streamBuffer.= ",\"".$object['names_ordered']."\",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,".$object['phone'].",,,,,,,,,,,,\"".$object['connection_value']."\",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,\r\n";
[15]2906                                        }
2907                                break;
[285]2908                               
[15]2909                                case 'outlook2000_en':
2910                                        $streamBuffer = "Title,First Name,Middle Name,Last Name,Suffix,Company,Department,Job Title,".
2911                                        "Business Street,Business Street 2,Business Street 3,Business City,Business State,Business Postal Code,".
2912                                        "Business Country,Home Street,Home Street 2,Home Street 3,Home City,Home State,Home Postal Code,Home Country,".
2913                                        "Other Street,Other Street 2,Other Street 3,Other City,Other State,Other Postal Code,Other Country,".
2914                                        "Assistant's Phone,Business Fax,Business Phone,Business Phone 2,Callback,Car Phone,Company Main Phone,Home Fax,".
2915                                        "Home Phone,Home Phone 2,ISDN,Mobile Phone,Other Fax,Other Phone,Pager,Primary Phone,Radio Phone,TTY/TDD Phone,Telex,".
2916                                        "Account,Anniversary,Assistant's Name,Billing Information,Birthday,Categories,Children,Directory Server,E-mail Address,".
2917                                        "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,".
2918                                        "Gender,Government ID Number,Hobby,Initials,Internet Free Busy,Keywords,Language,Location,Manager's Name,Mileage,Notes,".
2919                                        "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";
[293]2920                                        foreach($contacts as $index => $object){
2921                                                $streamBuffer.= ",".$object['names_ordered'].",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,".$object['phone'].",,,,,,,,,,,,".$object['connection_value'].",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,\r\n";
[15]2922                                        }
2923                                break;
[285]2924                                       
[2]2925                                case 'thunderbird':
[285]2926                                        $streamBuffer = "\n";                                                   
[293]2927                                        foreach($contacts as $index => $object){
2928                                                $streamBuffer.= ",,".$object['names_ordered'].",,".$object['connection_value'].",,".$object['phone'].",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,\r\n";
[2]2929                                        }
2930                                break;
[285]2931                               
2932                                case 'expresso':
[16]2933                                        $streamBuffer = "Nome,Email,Telefone\r\n";
[293]2934                                        foreach($contacts as $index => $object){
2935                                                $streamBuffer.= $object['names_ordered'].",".$object['connection_value'].",".$object['phone']."\r\n";
[2]2936                                        }
2937                                break;
[285]2938                               
[2]2939                        }
2940
2941                        $file = "contacts_".md5(microtime()).".swp";
2942                        $tempDir = ini_get("session.save_path");
2943                        $f = fopen($tempDir.'/'.$file,"w");
2944                        if(!$f)
2945                                echo null;
[285]2946               
[2]2947                        fputs($f,$streamBuffer);
2948                        fclose($f);
2949
2950                        echo $tempDir.'/'.$file;
2951                }
2952
[285]2953                // Get the csv field and put into array, from php.net
2954                function parse_line($input_text, $delimiter = ',', $text_qualifier = '"') {
2955                        $text = trim($input_text);
2956                          if(is_string($delimiter) && is_string($text_qualifier)) {
2957                         $re_d = '\x' . dechex(ord($delimiter));            //format for regexp
2958                        $re_tq = '\x' . dechex(ord($text_qualifier));    //format for regexp
2959                       
2960                        $fields = array();
2961                        $field_num = 0;
2962                        while(strlen($text) > 0) {
2963                        if($text{0} == $text_qualifier) {
2964                                preg_match('/^' . $re_tq . '((?:[^' . $re_tq . ']|(?<=\x5c)' . $re_tq . ')*)' . $re_tq . $re_d . '?(.*)$/', $text, $matches);
2965                               
2966                                $value = str_replace('\\' . $text_qualifier, $text_qualifier, $matches[1]);
2967                                $text = trim($matches[2]);
2968               
2969                                $fields[$field_num++] = $value;
2970                        } else {
2971                                preg_match('/^([^' . $re_d . ']*)' . $re_d . '?(.*)$/', $text, $matches);
2972                               
2973                                $value = $matches[1];
2974                                $text = trim($matches[2]);
2975               
2976                                $fields[$field_num++] = $value;
2977                }
2978                }
2979                        return $fields;
2980                    } else
2981                        return false;
2982                }
[16]2983
[2]2984                function import_contacts($typeImport){
[276]2985
[285]2986                        if($file = $_SESSION['contactcenter']['importCSV']) {                           
2987                                unset($_SESSION['contactcenter']['importCSV']);                         
[2]2988                                $len = filesize($file);
2989                                $count = 0;
2990                                $return = array('error' => false, '_new' => 0, '_existing' => 0, '_failure' => 0);
[276]2991                                $handle = @fopen($file, "r") or die(serialize($return['error'] = true));
[285]2992                               
2993                                $input_header = fgets($handle);
2994                                if ($typeImport == 'outlook')
2995                                        $delim = ';';
2996                                else if ($typeImport == 'auto')
2997                                $delim = strstr($input_header,',') ? ',' : ';';
2998                                else 
2999                                        $delim = ',';
3000                                $csv_header = $this->parse_line($input_header,$delim);
3001                                $firstContact = fgets($handle);
3002                                preg_match("/\"(.+)\"[,;]/sU",$firstContact,$matches); // yahoo csv
3003                                rewind($handle);                               
3004
[2]3005                                $header = @fgetcsv($handle, $len, $delim) or die(serialize($return['error'] = true));
[15]3006                                if(count($header)  < 2 || count($header) > 100) {
[2]3007                                        $return['error'] = true;
3008                                        $return['sizeheader'] = count($header);
3009                                        echo serialize($return);
3010                                        return;
3011                                }
[285]3012                               
3013                                if ($matches[0][strlen($matches[0])-1] == ';')
3014                                        $delim = ';';
3015                               
3016                        $boGroup = CreateObject('contactcenter.bo_group');
3017                        $boPeople = CreateObject('contactcenter.bo_people_catalog');
[15]3018                                switch($typeImport){
3019                                        case 'outlook2000':
[16]3020                                                $name_pos=1;
3021                                                $email_pos=56;
3022                                                $phone_pos=44;
[15]3023                                                break;
[16]3024                                        case 'outlook':
3025                                                $name_pos=0;
3026                                                $email_pos=1;
3027                                                $phone_pos=7;
3028                                                break;
[15]3029                                        case 'thunderbird':
[16]3030                                                $name_pos=2;
3031                                                $email_pos=4;
[19]3032                                                $phone_pos=7;
[15]3033                                                break;
[285]3034                                        case 'expresso':
[16]3035                                                $name_pos=0;
3036                                                $email_pos=1;
3037                                                $phone_pos=2;
[285]3038                                                break;
3039                                        default:
3040                                                foreach($csv_header as $index => $fieldName)
3041                                                {
[575]3042                                                        switch(strtoupper($fieldName)){
3043                                                        case 'NAME':
3044                                                        case 'NOME':
3045                                                        case 'FIRST NAME':
[285]3046                                                                $name_pos = $index;
3047                                                                break;
[575]3048                                                        case 'E-MAIL':
3049                                                        case 'EMAIL':
3050                                                        case 'E-MAIL ADDRESS':
3051                                                        case 'ENDEREÇO DE CORREIO ELETRÔNICO':
3052                                                        case 'END. DE EMAIL':
[285]3053                                                                $email_pos = $index;
3054                                                                break;
[575]3055                                                        case 'HOME PHONE':
3056                                                        case 'PHONE':
3057                                                        case 'TELEFONE':
3058                                                        case 'TELEFONE PRINCIPAL':
3059                                                        case 'TELEFONE COMERCIAL':
[285]3060                                                                $phone_pos = $index;
3061                                                                break;
3062                                                        }
[575]3063                                                }
[285]3064                                                break;
[15]3065                                }
[285]3066                               
[276]3067
[2]3068                                while (($data = fgetcsv($handle, $len, $delim))) {
3069                                foreach ($header as $key=>$heading)
3070                                $row[$heading]=(isset($data[$key])) ? $data[$key] : '';
[285]3071                               
[2]3072                                        $sdata = array();
[16]3073                                        $full_name  = trim($row[$header[$name_pos]]);
3074                                        $email          = trim($row[$header[$email_pos]]);
3075                                        $phone          = trim($row[$header[$phone_pos]]);
[2]3076                                        $array_name = explode(' ', str_replace('"','',(str_replace('\'','',$full_name))));
3077                                        $sdata['given_names'] = $array_name[0];
3078                                        $array_name[0] = null;
3079                                        $sdata['family_names'] = trim(implode(' ',$array_name));
3080                                        $sdata['connections']['default_email']['connection_name'] = lang('Main');
[16]3081                                        $sdata['connections']['default_email']['connection_value'] = $email;
[2]3082
[16]3083                                        $sdata['connections']['default_phone']['connection_name'] = lang('Main');
3084                                        $sdata['connections']['default_phone']['connection_value'] = $phone;
[285]3085                                       
3086                                        //      verifica se email já existe!
[2]3087                                        $contact = $boGroup->verify_contact($email);
[285]3088                                                                               
3089                                        if(!$sdata['given_names'] && $email){
3090                                                        $a_email = explode("@",$email);
3091                                                        $sdata['given_names'] = $a_email[0];
3092                                        }
[2]3093
[285]3094                                        $line_iteration = $return['_failure'] + $return['_existing'] + $return['_new'];
[2]3095                                        if($contact){
3096                                                $return['_existing']++;
[285]3097                                        }                                                                                                               
[2]3098                                        else if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) {
3099                                                $return['_failure']++;
[285]3100                                                $return['_failure_status'] .= "Line: " . ($line_iteration + 2) . ", Invalid E-Mail address: " . $email ."<br>";
[16]3101                                        }
[284]3102                                        else if (!$sdata['given_names'] || !$email || !$boPeople ->quick_add($sdata)){
[285]3103                                                $return['_failure']++;                                                 
3104                                                $return['_failure_status'] .= "Line: " . ($line_iteration + 2) . ", Invalid Name: " . $sdata['given_names'] ."<br>";
[2]3105                                        }
3106                                        else
3107                                                $return['_new']++;
[285]3108                        }                               
[2]3109                                fclose($handle);
[15]3110                                unlink($file);
[2]3111                        }
3112                        else
3113                                $return['error'] = true;
3114
3115                        echo serialize($return);
3116                }
3117/*
3118                function convert_tree($tree, $name, &$iconDir, $parent='0')
3119                {
3120                        $new = null;
3121                        $code = null;
[285]3122                       
[2]3123                        if ($parent === '0')
3124                        {
3125
3126                                $code .= $name.".add(new dNode({id:'0', caption: '".lang('Catalogues')."'}),'none');\n";
3127                        }
[285]3128                       
[2]3129                        foreach ($tree as $id => $value)
3130                        {
3131                                $title = $value['name'];
3132
3133                                switch ($value['type'])
[285]3134                                {                                       
[2]3135                                        case 'unknown':
[285]3136                                                $code .= $name.".add(new dNode({id: '{$parent}.{$id}', caption:'{$value['name']}', onFirstOpen: 'getCatalogTree(\\'{$parent}.{$id}\\');', onClick: 'getCatalogTree(\\'{$parent}.{$id}\\'); waitForTree(\\'{$parent}.{$id}\\', 0)'}),'$parent');\n";
[2]3137                                                break;
[285]3138                                       
[2]3139                                        case 'catalog_group':
[285]3140                                                $code .= $name.".add(new dNode({id: '{$parent}.{$id}', caption: '{$value['name']}'}),'$parent');\n";
[2]3141                                                $code .= $this->convert_tree($value['sub_branch'],$name,$iconDir,$parent.'.'.$id);
3142                                                break;
3143
3144                                        case 'mixed_catalog_group':
3145                                                $code .= $name.".add(new dNode({id: '{$parent}.{$id}', caption: '{$value['name']}', onClick: 'setCatalog(\\'{$parent}.{$id}\\')'}),'$parent');\n";
3146
3147                                                $code .= $this->convert_tree($value['sub_branch'],$name,$iconDir,$parent.'.'.$id);
3148                                                break;
[285]3149                                       
[2]3150                                        case 'catalog':
3151                                                $code .= $name.".add(new dNode({id: '{$parent}.{$id}', caption: '{$value['name']}', onClick: 'setCatalog(\\'{$parent}.{$id}\\')'}),'$parent');\n";
[285]3152                                               
[2]3153                                }
3154                        }
[285]3155                       
[2]3156                        return $code;
3157                }
3158*/
3159        }
3160
3161?>
Note: See TracBrowser for help on using the repository browser.