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

Revision 79, 75.7 KB checked in by wmerlotto, 17 years ago (diff)

Remocao de strings hardcoded para internacionalizacao

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