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

Revision 418, 94.4 KB checked in by niltonneto, 16 years ago (diff)

Ocorrência #328
Incluir as contas institucionais na busca do Catálogo Geral

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