source: branches/2.0/contactcenter/inc/class.ui_data.inc.php @ 2894

Revision 2894, 100.2 KB checked in by amuller, 14 years ago (diff)

Ticket #820 - Remoção %%20 das strings

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