source: trunk/contactcenter/inc/class.bo_people_catalog.inc.php @ 1392

Revision 1392, 42.4 KB checked in by eduardoalex, 15 years ago (diff)

Ticket #629 - Ajuste da função quick_add no momento da inserção

  • 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  *  sponsored by Thyamad - http://www.thyamad.com
8  * ------------------------------------------------------------------------- *
9  *  This program is free software; you can redistribute it and/or modify it  *
10  *  under the terms of the GNU General Public License as published by the    *
11  *  Free Software Foundation; either version 2 of the License, or (at your   *
12  *  option) any later version.                                               *
13  \***************************************************************************/
14
15        include_once('class.abo_catalog.inc.php');
16        class bo_people_catalog extends abo_catalog
17        {
18                       
19                var $fields = array(
20                        'id_contact'    => true,
21                        'status'        => true,
22                        'photo'         => true,
23                        'alias'         => true,
24                        'prefix'        => true,
25                        'given_names'   => true,
26                        'family_names'  => true,
27                        'names_ordered' => true,
28                        'suffix'        => true,
29                        'birthdate'     => true,
30                        'sex'           => true,
31                        'pgp_key'       => true,
32                        'notes'         => true,
33                       
34                        /* Array fields */
35                        'companies'     => true,
36                        'relations'     => true,
37                        'addresses'     => true,
38                        'connections'   => true
39                );
40       
41                /*!
42               
43                 @function bo_people_catalog
44                 @abstract Constructor
45                 @author Raphael Derosso Pereira
46                 
47                */
48                function bo_people_catalog()
49                {
50                        $this->init();
51                }
52
53                /*!
54                        @function find
55                        @abstract Find function for this catalog
56                        @author Raphael Derosso Pereira
57
58                */
59                function find($what, $rules=false, $other=false)
60                {
61                        if (is_array($what) and count($what))
62                        {
63                                $found = false;
64                               
65                                foreach ($what as $value)
66                                {
67                                        if (strpos($value, 'contact') === 0)
68                                        {
69                                                $found = true;
70                                        }
71                                }
72                               
73                                if (!$found)
74                                {
75                                        return $this->sql_find($what, $rules, $other);
76                                }
77                               
78                                if ($rules and is_array($rules))
79                                {
80                                        array_push($rules, array(
81                                                'field' => 'contact.id_owner',
82                                                'type'  => '=',
83                                                'value' => $GLOBALS['phpgw_info']['user']['account_id']
84                                        ));
85                                }
86                                else
87                                {
88                                        $rules = array(
89                                                0 => array(
90                                                        'field' => 'contact.id_owner',
91                                                        'type'  => '=',
92                                                        'value' => $GLOBALS['phpgw_info']['user']['account_id']
93                                                )
94                                        );
95                                }
96                        }
97
98                        return $this->sql_find($what, $rules, $other);
99                }
100                       
101                /*!
102               
103                 @function get_single_entry
104                 @abstract Returns all information requested about one contact
105                 @author Raphael Derosso Pereira
106                     
107                 @param integer $id_contact The contact ID
108                 @param array $fields The array returned by get_fields whith true
109                        on the fields to be taken.
110                       
111                */
112                function get_single_entry ( $id_contact, $fields )
113                {       
114                        if (!is_array($fields))
115                        {
116                                if (is_object($GLOBALS['phpgw']->log))
117                                {
118                                        $GLOBALS['phpgw']->log->message(array(
119                                                'text' => 'F-BadcontactcenterParam, wrong get_single_entry parameters type.',
120                                                'line' => __LINE__,
121                                                'file' => __FILE__));
122                                       
123                                        $GLOBALS['phpgw']->log->commit();
124                                }
125                                else
126                                {
127                                        exit('Argument Error on: <br>File:'.__FILE__.'<br>Line:'.__LINE__.'<br>');
128                                }
129                        }
130                       
131                        // Verify permissions
132                        $permissions = $this->security->get_permissions('entry', $id_contact);
133
134                        if (!$permissions['read'])
135                        {
136                                return false;
137                        }
138                       
139                        //$contact_data = $this->fields;
140       
141                        $contact = CreateObject('contactcenter.so_contact', $id_contact);
142
143                        foreach ($fields as $field => $trueness)
144                        {
145                                if (!$trueness)
146                                {
147                                        //unset($contact_data[$field]);
148                                        continue;
149                                }
150                                       
151                                switch ($field)
152                                {
153                                        case 'companies':
154                                                $companies = $this->get_companies($id_contact,$trueness);
155
156                                                if (is_array($companies) and count($companies))
157                                                {
158                                                        $contact_data['companies'] = $companies;
159                                                }
160                                                break;
161                                       
162                                        case 'relations':
163                                                $relations = $this->get_relations($id_contact,$trueness);
164
165                                                if (is_array($relations) and count($relations))
166                                                {
167                                                        $contact_data['relations'] = $relations;
168                                                }
169                                                break;
170                                       
171                                        case 'addresses':
172                                                $addresses = $this->get_addresses($id_contact,$trueness);
173
174                                                if (is_array($addresses) and count($addresses))
175                                                {
176                                                        $contact_data['addresses'] = $addresses;
177                                                }
178                                                break;
179                                       
180                                        case 'connections':
181                                                $connections = $this->get_connections($id_contact,$trueness);
182
183                                                if (is_array($connections) and count($connections))
184                                                {
185                                                        $contact_data['connections'] = $connections;
186                                                }
187                                                break;
188                                       
189                                        case 'prefix':
190                                                $id = $contact->get_prefix();
191                                                if ($id)
192                                                {
193                                                        $prefix = CreateObject('contactcenter.so_prefix', $id);
194                                                        $contact_data['id_prefix'] = $id;
195                                                        $contact_data['prefix'] = $prefix->get_prefix(); 
196                                                }
197                                                break;
198                                               
199                                        case 'suffix':
200                                                $id = $contact->get_suffix();
201                                                if ($id)
202                                                {
203                                                        $suffix = CreateObject('contactcenter.so_suffix', $id);
204                                                        $contact_data['id_suffix'] = $id;
205                                                        $contact_data['suffix'] = $suffix->get_suffix(); 
206                                                }
207                                                break;
208                                               
209                                        case 'status':
210                                                $id = $contact->get_status();
211                                                if ($id)
212                                                {
213                                                        $status = CreateObject('contactcenter.so_status', $id);
214                                                        $contact_data['id_status'] = $id;
215                                                        $contact_data['status'] = $status->get_status(); 
216                                                }
217                                                break;
218                                               
219                                        default:
220                                                //$func_name = 'contact->get_'.$field;
221                                                //$contact_data[$field] = $this->$func_name();
222                                                $contact_data[$field] = $contact->get_field($field);
223                                                break;
224                                }
225                        }
226                       
227                        if (!is_array($contact_data))
228                        {
229                                return false;
230                        }
231                       
232                        return $contact_data;
233                }
234       
235                /*!
236                 
237                 @function get_multiple_entries
238                 @abstract Returns multiple Contacts data into one array
239                 @author Raphael Derosso Pereira
240
241                 @param array $id_contacts The Contacts IDs
242                 @param array $fields The Contacts fields to be retrieved
243                 @param array $other_data Other informations. The format is:
244                        $other_data = array(
245                                'offset'    => <offset>,
246                                'limit'     => <max_num_returns>,
247                                'sort'      => <sort>,
248                                'order_by'  => <order by>
249                        );
250               
251                */
252                function get_multiple_entries ( $id_contacts, $fields, $other_data = false )
253                {
254                        if (!is_array($id_contacts) or !is_array($fields) or ($other_data != false and !is_array($other_data)))
255                        {
256                                if (is_object($GLOBALS['phpgw']->log))
257                                {
258                                        $GLOBALS['phpgw']->log->message(array(
259                                                'text' => 'F-BadcontactcenterParam, wrong get_multiple_entry parameter type.',
260                                                'line' => __LINE__,
261                                                'file' => __FILE__));
262                                       
263                                        $GLOBALS['phpgw']->log->commit();
264                                }
265                                else {
266                                        exit('Argument Error on: <br>File:'.__FILE__.'<br>Line:'.__LINE__.'<br>');
267                                }
268                        }
269                       
270                        $contacts = array();
271       
272                        if ($other_data)
273                        {
274                                //TODO
275                        }
276       
277                        foreach ($id_contacts as $id)
278                        {
279                                $contact = $this->get_single_entry($id,$fields);
280                                if ($contact)
281                                {
282                                        $contacts[$id] = $contact;
283                                }
284                        }
285                       
286                        return $contacts;
287                }
288
289                /*!
290               
291                        @function get_all_entries_ids
292                        @abstract Returns the IDs of all the entries in this catalog
293                        @author Raphael Derosso Pereira
294
295                */
296                function get_all_entries_ids ()
297                {
298                        $search_fields = array('contact.id_contact', 'contact.names_ordered');
299                        $search_other  = array('order' => 'contact.names_ordered');
300
301                        $result_i = $this->find($search_fields, null, $search_other);
302
303                        if (is_array($result_i) and count($result_i))
304                        {
305                                $result = array();
306                                foreach($result_i as $result_part)
307                                {
308                                        $result[] = $result_part['id_contact'];
309                                }
310
311                                return $result;
312                        }
313
314                        return null;
315                }
316       
317                /*!
318               
319                        @function get_relations
320                        @abstract Returns the IDs of all Contacts relations
321                        @author Raphael Derosso Pereira
322                 
323                        @param integer $id_contact The Contact ID
324                       
325                        @return The following array:
326                                 $return = array(
327                                        'relation1' => array(
328                                                'id_relation'     => <id_relation>,
329                                                'id_type'         => <id_type>,
330                                                'type'            => '<type_name>',
331                                                'is_subordinated' => <trueness>
332                                        ),
333                                        'relation2' => array(...),
334                                        ...
335                                 );
336                 
337                */
338                function get_relations ($id_contact,$extra=false)
339                {
340                        $contact = CreateObject('contactcenter.so_contact', $id_contact);
341                        $relations = $contact->get_relations();
342               
343                        $count = 1;     
344                        foreach($relations as $id => $type)
345                        {
346                                $relation = CreateObject('contactcenter.so_contact_relation_type', $type);
347                               
348                                if ($extra === 'subordinated' and $relation->get_is_subordinated())
349                                {
350                                        $return['relation'.$count]['id_relation'] = $id;
351                                        $return['relation'.$count]['id_type'] = $type;
352                                        $return['relation'.$count]['type'] = $relation->get_type_name();
353                                        $return['relation'.$count]['is_subordinated'] = $relation->get_is_subordinated();
354                                        $count++;
355                                }
356                                else if ($extra !== 'subordinated')
357                                {
358                                        $return['relation'.$count]['id_relation'] = $id;
359                                        $return['relation'.$count]['id_type'] = $type;
360                                        $return['relation'.$count]['type'] = $relation->get_type_name();
361                                        $return['relation'.$count]['is_subordinated'] = $relation->get_is_subordinated();
362                                        $count++;
363                                }
364                        }
365                       
366                        return $return;
367                }
368       
369                /*!
370               
371                        @function get_addresses
372                        @abstract Returns all Contacts Address Information
373                        @author Raphael Derosso Pereira
374                 
375                        @param integer $id_contact The Contact ID
376                       
377                        @return The following array:
378                                 $return = array(
379                                        'address1' => array(
380                                                'id_address'         => <id_address>,
381                                                'id_type'            => <id_type>,
382                                                'type'               => '<type_name>',
383                                                'address1'           => '<address1>',
384                                                'address2'           => '<address2>',
385                                                'complement'         => '<complement>',
386                                                'address_other'      => '<address_other>',
387                                                'postal_code'        => '<postal_code>',
388                                                'po_box'                     => '<po_box>',
389                                                'id_city'            => '<city>',
390                                                'city_name'          => (string),
391                                                'city_timezone'      => (int),
392                                                'city_geo_location'  => (string),
393                                                'id_state'           => (int),
394                                                'state_name'         => (string),
395                                                'state_symbol'       => (string),
396                                                'id_country'         => (int),
397                                                'country_name'       => (string),
398                                                'address_is_default' => <trueness>
399                                        ),
400                                        'address2' => array(...),
401                                        ...
402                                 );
403                 
404                */
405                function get_addresses ( $id_contact,$extra=false )
406                {
407                        $contact = CreateObject('contactcenter.so_contact', $id_contact);
408                        $addresses = $contact->get_addresses(extra);
409               
410                        foreach($addresses as $id => $type)
411                        {
412                                $address = CreateObject('contactcenter.so_address',$id);
413                                $address_type = CreateObject('contactcenter.so_contact_address_type',$type);
414                               
415                                if ($extra === 'default' and $address->is_default())
416                                {
417                                        $return['address'.$type]['id_address'] = $id;
418                                        $return['address'.$type]['id_typeof_address'] = $type;
419                                        $return['address'.$type]['type'] = $address_type->get_type_name();
420                                        $return['address'.$type]['address1'] = $address->get_address1();
421                                        $return['address'.$type]['address2'] = $address->get_address2();
422                                        $return['address'.$type]['complement'] = $address->get_complement();
423                                        $return['address'.$type]['address_other'] = $address->get_address_other();
424                                        $return['address'.$type]['postal_code'] = $address->get_postal_code();
425                                        $return['address'.$type]['po_box'] = $address->get_po_box();
426                                        $return['address'.$type]['address_is_default'] = true;
427                                        $return['address'.$type]['id_city'] = $id_city = $address->get_id_city();
428                                        $return['address'.$type]['id_state'] = $id_state = $address->get_id_state();
429                                        $return['address'.$type]['id_country'] = $id_country = $address->get_id_country();
430                                       
431                                        if ($id_city)
432                                        {
433                                                $city = CreateObject('contactcenter.so_city',$id_city);
434                                                $return['address'.$type]['city_name'] = $city->get_city_name();
435                                                $return['address'.$type]['city_timezone'] = $city->get_city_timezone();
436                                                $return['address'.$type]['city_geo_location'] = $city->get_city_geo_location();
437                                        }
438                                       
439                                        if ($id_state)
440                                        {
441                                                $state = CreateObject('contactcenter.so_state',$id_state);
442                                                $return['address'.$type]['state_name'] = $state->get_state_name();
443                                                $return['address'.$type]['state_symbol'] = $state->get_state_symbol();
444                                                $return['address'.$type]['id_country'] = $id_country = $state->get_id_country();
445                                        }
446
447                                        $country = CreateObject('contactcenter.so_country',$id_country);
448                                        $return['address'.$type]['country_name'] = $country->get_country_name();
449                                }
450                                else if ($extra !== 'default')
451                                {       
452                                        $return['address'.$type]['id_address'] = $id;
453                                        $return['address'.$type]['id_typeof_address'] = $type;
454                                        $return['address'.$type]['type'] = $address_type->get_type_name();
455                                        $return['address'.$type]['address1'] = $address->get_address1();
456                                        $return['address'.$type]['address2'] = $address->get_address2();
457                                        $return['address'.$type]['complement'] = $address->get_complement();
458                                        $return['address'.$type]['address_other'] = $address->get_address_other();
459                                        $return['address'.$type]['postal_code'] = $address->get_postal_code();
460                                        $return['address'.$type]['po_box'] = $address->get_po_box();
461                                        $return['address'.$type]['address_is_default'] = $address->is_default();
462                                        $return['address'.$type]['id_city'] = $id_city = $address->get_id_city();
463                                        $return['address'.$type]['id_state'] = $id_state = $address->get_id_state();
464                                        $return['address'.$type]['id_country'] = $id_country = $address->get_id_country();
465                                       
466                                        if ($id_city)
467                                        {
468                                                $city = CreateObject('contactcenter.so_city',$id_city);
469                                                $return['address'.$type]['city_name'] = $city->get_city_name();
470                                                $return['address'.$type]['city_timezone'] = $city->get_city_timezone();
471                                                $return['address'.$type]['city_geo_location'] = $city->get_city_geo_location();
472                                        }
473                                       
474                                        if ($id_state)
475                                        {
476                                                $state = CreateObject('contactcenter.so_state',$id_state);
477                                                $return['address'.$type]['state_name'] = $state->get_state_name();
478                                                $return['address'.$type]['state_symbol'] = $state->get_state_symbol();
479                                                $return['address'.$type]['id_country'] = $id_country = $state->get_id_country();
480                                        }
481
482                                        $country = CreateObject('contactcenter.so_country',$id_country);
483                                        $return['address'.$type]['country_name'] = $country->get_country_name();
484                                }
485                        }
486                       
487                        return $return;
488                }
489       
490       
491                /*!
492               
493                        @function get_connections
494                        @abstract Returns all Contacts connections information
495                        @author Raphael Derosso Pereira
496                 
497                        @param integer $id_contact The Contact ID
498                       
499                        @return The following array:
500                                 $return = array(
501                                        'connection1' => array(
502                                                'id_connection'         => <id_connection>,
503                                                'id_type'               => <id_type>,
504                                                'type'                  => '<type_name>',
505                                                'connection_name'       => '<connection_name>',
506                                                'connection_value'      => '<connection_value>',
507                                                'connection_is_default' => '<connection_is_default>'
508                                        ),
509                                        'connection2' => array(...),
510                                        ...
511                                 );
512                 
513                */
514                function get_connections ( $id_contact,$extra=false )
515                {
516                        $contact = CreateObject('contactcenter.so_contact', $id_contact);
517                        $connections = $contact->get_connections($extra);
518               
519                        $count = 1;     
520                        foreach($connections as $id => $type)
521                        {
522                                $connection = CreateObject('contactcenter.so_connection', $id);
523
524                                if ($extra === 'default' and $connection->is_default())
525                                {
526                                        $connection_type = CreateObject('contactcenter.so_contact_connection_type', $type);
527                                        $return['connection'.$count]['id_connection'] = $id;
528                                        $return['connection'.$count]['id_type'] = $type;
529                                        $return['connection'.$count]['type'] = $connection_type->get_type_name();
530                                        $return['connection'.$count]['connection_name'] = $connection->get_name();
531                                        $return['connection'.$count]['connection_value'] = $connection->get_value();
532                                        $return['connection'.$count]['connection_is_default'] = $connection->is_default();
533                                        $count++;
534                                }
535                                else if ($extra !== 'default')
536                                {
537                                        $connection_type = CreateObject('contactcenter.so_contact_connection_type', $type);
538                                        $return['connection'.$count]['id_connection'] = $id;
539                                        $return['connection'.$count]['id_type'] = $type;
540                                        $return['connection'.$count]['type'] = $connection_type->get_type_name();
541                                        $return['connection'.$count]['connection_name'] = $connection->get_name();
542                                        $return['connection'.$count]['connection_value'] = $connection->get_value();
543                                        $return['connection'.$count]['connection_is_default'] = $connection->is_default();
544                                        $count++;
545                                }
546                        }
547                       
548                        return $return;
549                }
550       
551                /*!
552               
553                        @function get_companies
554                        @abstract Returns all Contacts companies information
555                        @author Raphael Derosso Pereira
556                 
557                        @param integer $id_contact The Contact ID
558                       
559                        @return The following array:
560                                 $return = array(
561                                        'company1' => array(
562                                                'id_company'   => <id_company>,
563                                                'company_name' => '<company_name>'
564                                                'title'        => '<company_name>',
565                                                'department'   => '<company_value>',
566                                        ),
567                                        'company2' => array(...),
568                                        ...
569                                 );
570                 
571                */
572                function get_companies ( $id_contact,$extra=false )
573                {
574                        $contact = CreateObject('contactcenter.so_contact', $id_contact);
575                        $companies = $contact->get_companies($extra);
576               
577                        $count = 1;     
578                        foreach($companies as $id => $value)
579                        {
580                                $company = CreateObject('contactcenter.so_company', $id);
581
582                                if ($extra === 'default' and $value['default_company'])
583                                {
584                                        $return['company'.$count]['id_company'] = $id;
585                                        $return['company'.$count]['company_name'] = $company->get_company_name();
586                                        $return['company'.$count]['title'] = $value['title'];
587                                        $return['company'.$count]['department'] = $value['department'];
588                                        $return['company'.$count]['default_company'] = $value['default_company'];
589                                        $return['company'.$count]['default_contact'] = $value['default_contact'];
590                                        $count++;
591                                }
592                                else if ($extra !== 'default')
593                                {
594                                        $return['company'.$count]['id_company'] = $id;
595                                        $return['company'.$count]['company_name'] = $company->get_company_name();
596                                        $return['company'.$count]['title'] = $value['title'];
597                                        $return['company'.$count]['department'] = $value['department'];
598                                        $return['company'.$count]['default_company'] = $value['default_company'];
599                                        $return['company'.$count]['default_contact'] = $value['default_contact'];
600                                        $count++;
601                                }
602                        }
603                       
604                        return $return;
605                }
606               
607               
608                /*********************************************************************\
609                 *                Methods to get general fields                      *
610                \*********************************************************************/
611               
612                /*!
613               
614                 @function get_all_prefixes
615                 @abstract Returns all the registered prefixes
616                 @author Raphael Derosso Pereira
617                 
618                */
619                function get_all_prefixes (  )
620                {
621                        $fields = array('prefix.id_prefix','prefix.prefix');
622                       
623                        $prefixes = $this->find($fields);
624                       
625                        if (!is_array($prefixes))
626                        {
627                                return false;
628                        }
629                       
630                        while (list(,$prefix) = each($prefixes))
631                        {
632                                $result[$prefix['id_prefix']] = $prefix['prefix'];
633                        }
634                       
635                        return $result;
636                }
637               
638       
639                /*!
640               
641                 @function get_all_suffixes
642                 @abstract Returns all the registered suffixes
643                 @author Raphael Derosso Pereira
644                 @return An array as follows:
645                        $return = array(
646                                <id_suffix1> => '<suffix_name1>',
647                                <id_suffix2> => '<suffix_name2>',
648                                ...                             
649                        );
650                 
651                */
652                function get_all_suffixes (  )
653                {
654                        $fields = array('suffix.id_suffix','suffix.suffix');
655                       
656                        $suffixes = $this->find($fields);
657                       
658                        if (!is_array($suffixes))
659                        {
660                                return false;
661                        }
662                       
663                        while (list(,$suffix) = each($suffixes))
664                        {
665                                $result[$suffix['id_suffix']] = $suffix['suffix'];
666                        }
667                       
668                        return $result;
669                }
670       
671                /*!
672               
673                 @function get_all_status
674                 @abstract Returns all the registered status
675                 @author Raphael Derosso Pereira
676                 @return An array as follows:
677                        $return = array(
678                                <id_status1> => '<status_name1>',
679                                <id_status2> => '<status_name2>',
680                                ...                             
681                        );
682                 
683                */
684                function get_all_status (  )
685                {
686                        $fields = array('status.id_status','status.status_name');
687                       
688                        $status = $this->find($fields);
689                       
690                        if (!is_array($status))
691                        {
692                                return false;
693                        }
694                       
695                        while (list(,$status_) = each($status))
696                        {
697                                $result[$status_['id_status']] = $status_['status_name'];
698                        }
699                       
700                        return $result;
701                }
702
703                /*!
704               
705                 @function get_all_relations_types
706                 @abstract Returns all contacts relations types
707                 @author Raphael Derosso Pereira
708                 
709                 @return array The format of the return is:
710                        $return = array(
711                                <id_type1> => '<type1_name>',
712                                <id_type2> => '<type2_name>',
713                                ...);
714                */
715                function get_all_relations_types (  )
716                {
717                        $fields = array('typeof_contact_relation.id_typeof_contact_relation', 'typeof_contact_relation.contact_relation_type_name');
718                       
719                        $relation_types = $this->find($fields);
720                       
721                        if (!is_array($relation_types))
722                        {
723                                return false;
724                        }
725                       
726                        while (list(,$relation_type) = each($relation_types))
727                        {
728                                $result[$relation_type['id_typeof_contact_relation']] = $relation_type['contact_relation_type_name'];                           
729                        }
730                       
731                        return $result;
732                }
733       
734                /*!
735               
736                 @function get_all_addresses_types
737                 @abstract Returns all contacts addresses types
738                 @author Raphael Derosso Pereira
739                 
740                 @return array The format of the return is:
741                        $return = array(
742                                <id_type1> => '<type1_name>',
743                                <id_type2> => '<type2_name>',
744                                ...);
745                */
746                function get_all_addresses_types (  )
747                {
748                        $fields = array('typeof_contact_address.id_typeof_contact_address', 'typeof_contact_address.contact_address_type_name');
749                       
750                        $address_types = $this->find($fields);
751                       
752                        if (!is_array($address_types))
753                        {
754                                return false;
755                        }
756                       
757                        while (list(,$address_type) = each($address_types))
758                        {
759                                $result[$address_type['id_typeof_contact_address']] = $address_type['contact_address_type_name'];                               
760                        }
761                       
762                        return $result;
763                }
764
765                /*!
766               
767                 @function get_all_connections_types
768                 @abstract Returns all contacts connections types
769                 @author Raphael Derosso Pereira
770                 
771                 @return array The format of the return is:
772                        $return = array(
773                                <id_type1> => '<type1_name>',
774                                <id_type2> => '<type2_name>',
775                                ...);
776                */
777                function get_all_connections_types (  )
778                {
779                        $fields = array('typeof_contact_connection.id_typeof_contact_connection', 'typeof_contact_connection.contact_connection_type_name');
780                       
781                        $connection_types = $this->find($fields);
782                       
783                        if (!is_array($connection_types))
784                        {
785                                return false;
786                        }
787                       
788                        while (list(,$connection_type) = each($connection_types))
789                        {
790                                $result[$connection_type['id_typeof_contact_connection']] = $connection_type['contact_connection_type_name'];                           
791                        }
792                       
793                        return $result;
794                }
795
796                /*!
797               
798                        @function get_vcard
799                        @abstract Returns an URL that points to the file
800                                that contains a vCard of the specified Contact
801                        @author Raphael Derosso Pereira
802               
803                        @param integer $id_status The Contact ID
804                       
805                */
806                function get_vcard ( $id_contact )
807                {
808                }
809
810
811                /*********************************************************************\
812                 *                   Methods to Include Data                         *
813                \*********************************************************************/
814
815                /*!
816               
817                        @function add_single_entry
818                        @abstract Insert a new Contact record in the DB
819                        @author Raphael Derosso Pereira
820               
821                        @param array $data The Contact Information.
822                       
823                        Format:
824               
825                                $data = array(
826                                        'id_status'          => <id_status>,
827                                        'photo'              => '<photo_bin_stream>',
828                                        'alias'              => '<alias>',
829                                        'id_prefix'          => <id_prefix>,
830                                        'given_names'        => '<given_names>',
831                                        'family_names'       => '<family_names>',
832                                        'names_ordered'      => '<names_ordered>',
833                                        'id_suffix'          => <id_suffix>,
834                                        'birthdate'          => '<birthdate>',
835                                        'sex'                => '<sex>',
836                                        'pgp_key'            => '<pgp_key>',
837                                        'notes'              => '<notes>',
838                                       
839                                        'companies'          => array(
840                                                company1 => array(
841                                                        'id_company'      => <id_company>,
842                                                        'company_name'    => <company_name>,
843                                                        'title'           => <title>,
844                                                        'department'      => <department>,
845                                                        'default_company' => (bool),
846                                                        'default_contact' => (bool)
847                                                ),
848                                                company2 => array(...),
849                                                ...
850                                        ),
851                                       
852                                        'relations'          => array(
853                                                'relation1' => array(
854                                                        'id_relation'        => <id_relation>,
855                                                        'id_typeof_relation' => <id_typeof_relation>,
856                                                ),
857                                                'relation2' => array(...),
858                                                ...
859                                        ),
860                                       
861                                        'addresses'          => array(
862                                                'address1' => array(
863                                                        'id_typeof_address'  => <id_typeof_address>,
864                                                        'address1'           => '<address1>',
865                                                        'address2'           => '<address2>',
866                                                        'complement'         => '<complement>',
867                                                        'address_other'      => '<address_other>',
868                                                        'postal_code'        => '<postal_code>',
869                                                        'po_box'                     => '<po_box>',
870                                                        'id_city'            => '<city>',
871                                                        'address_is_default' => <trueness>
872                                                ),
873                                                'address2' => array(...),
874                                                ...
875                                        ),
876                                       
877                                        'connections'        => array(
878                                                'connection1' => array(
879                                                        'id_typeof_connection'  => <id_typeof_connection>,
880                                                        'connection_name'       => <connection_name>,
881                                                        'connection_value'      => <connection_value>,
882                                                        'connection_is_default' => <trueness>
883                                                ),
884                                                'connection2' => array(...),
885                                                ...
886                                        ),
887                                       
888                                );
889                       
890                        If any of the above fields doesn't have a value, it should hold false.
891                        In the case of the multiple-values fields, instead of the array, there
892                        should be a false.
893
894                        @return integer $id The Contact ID
895                */     
896                function add_single_entry ( $data )
897                {
898                        $permissions = $this->security->get_permissions();
899                       
900                        if (!$permissions['create'])
901                        {
902                                //return false;
903                        }
904                       
905                        $contact = CreateObject('contactcenter.so_contact');
906                        $contact->reset_values();
907                       
908                        $altered = false;
909                        foreach($data as $field => $value)
910                        {
911                                if ($value === false)
912                                {
913                                        continue;
914                                }
915                               
916                                $altered = true;
917                                switch($field)
918                                {
919                                        case 'photo':
920                                        case 'alias':
921                                        case 'id_prefix':
922                                        case 'id_status':
923                                        case 'id_suffix':
924                                        case 'given_names':
925                                        case 'family_names':
926                                        case 'names_ordered':
927                                        case 'birthdate':
928                                        case 'sex':
929                                        case 'pgp_key':
930                                        case 'notes':
931                                                $contact->set_field($field,$value);
932                                                break;
933
934                                        case 'companies':                                       
935                                                foreach($value as $company_fields)
936                                                {
937                                                        if ($company_fields['company_name'])
938                                                        {
939                                                                $fields = array('company.id_company');
940                                                                $restric = array(
941                                                                        0 => array(
942                                                                                'field' => 'company.company_name',
943                                                                                'type'  => 'iLIKE',
944                                                                                'value' => $company_fields['company_name']
945                                                                        )
946                                                                );
947                                                               
948                                                                if($result = $this->find($fields,$restric))
949                                                                {
950                                                                        $id = $result[0]['id_company'];
951                                                                        $company_fields['id_company'] = $id;
952                                                                }
953                                                                else
954                                                                {
955                                                                        $company = CreateObject('contactcenter.so_company');
956                                                                        $company->reset_values();
957                                                                        $company->set_company_name($company_fields['company_name']);
958                                                                        $company->set_field('id_company_owner',$GLOBALS['phpgw_info']['user']['account_id']);
959                                                                        $company_fields['id_company'] = $company->commit();
960                                                                }
961                                                        }
962                                                       
963                                                        $contact->set_company($company_fields);
964                                                }
965                                                break;
966                                       
967                                        case 'relations':
968                                                foreach($value as $relation_fields)
969                                                {
970                                                        $contact->set_relation($relation_fields['id_relation'], $relation_fields['id_typeof_relation']);
971                                                }
972                                                break;
973                                       
974                                        case 'addresses':
975                                                foreach($value as $address_fields)
976                                                {
977                                                        $address = CreateObject('contactcenter.so_address');
978                                                        $address->reset_values();
979                                                        foreach($address_fields as $a_field => $a_value)
980                                                        {
981                                                                if ($a_field !== 'id_typeof_address')
982                                                                {
983                                                                        $address->set_field($a_field,$a_value);
984                                                                }
985                                                        }
986                                                        $address->commit();
987                                                        $id_address = $address->get_id();
988                                                        $contact->set_address($id_address, $address_fields['id_typeof_address']);
989                                                }
990                                                break;
991                                       
992                                        case 'connections':
993                                                foreach($value as $connection_name => $connection_fields)
994                                                {
995                                                        $connection = CreateObject('contactcenter.so_connection');
996                                                        $connection->reset_values();
997                                                       
998                                                        foreach($connection_fields as $a_field => $a_value)
999                                                        {
1000                                                                if ($a_field !== 'id_typeof_connection')
1001                                                                {
1002                                                                        $connection->set_field($a_field,$a_value);
1003                                                                }
1004                                                        }
1005                                                       
1006                                                        $connection->commit();
1007                                                        $id_connection = $connection->get_id();
1008                                                        $contact->set_connection($id_connection, $connection_fields['id_typeof_connection']);
1009                                                }
1010                                                break;
1011                                               
1012                                        default:
1013                                                return false;
1014                                }
1015                        }
1016                       
1017                        if ($altered)
1018                        {
1019                                $contact->set_field('id_owner',$GLOBALS['phpgw_info']['user']['account_id']);
1020                                return $contact->commit();
1021                        }
1022                       
1023                        return false;
1024                }
1025               
1026                /*!
1027               
1028                        @function quick_add
1029                        @abstract Insert a new Contact record in the DB with just the
1030                                main fields
1031                        @author Raphael Derosso Pereira
1032               
1033                        @param array $data The Contact Information.
1034                       
1035                        Format:
1036               
1037                                $data = array(
1038                                        'alias'              => '<alias>',
1039                                        'given_names'        => '<given_names>',
1040                                        'family_names'       => '<family_names>',
1041
1042                                        'connections'        => array(
1043                                                'default_email' => array(
1044                                                        'connection_name'       => <connection_name>,
1045                                                        'connection_value'      => <connection_value>
1046                                                ),
1047                                                'default_phone' => array(
1048                                                        'connection_name'       => <connection_name>,
1049                                                        'connection_value'      => <connection_value>
1050                                                )
1051                                        )
1052                                );
1053                */
1054                function quick_add ( $data )
1055                {
1056                        $permissions = $this->security->get_permissions();
1057                       
1058                        if (!$permissions['create'])
1059                        {
1060                                return false;
1061                        }
1062
1063                        // TODO: GET THE ORDER TO PUT names_ordered FROM PREFERENCES!
1064
1065                        $preferences = ExecMethod('contactcenter.ui_preferences.get_preferences');
1066                       
1067                        if (!is_array($preferences))
1068                        {
1069                                $preferences['personCardEmail'] = 1;
1070                                $preferences['personCardPhone'] = 2;
1071                        }
1072                       
1073                        $new_data = array(
1074                                'alias'              => $data['alias'],
1075                                'id_status'          => 1,
1076                                'given_names'        => $data['given_names'],
1077                                'family_names'       => $data['family_names'],
1078                                'names_ordered'      => $data['given_names'].' '.$data['family_names'],
1079                        );
1080
1081                        $i = 1;
1082                        if ($data['connections']['default_email']['connection_value'])
1083                        {
1084                                $new_data['connections']['connection'.$i] = array(
1085                                        'id_typeof_connection'  => $preferences['personCardEmail'],
1086                                        'connection_name'       => $data['connections']['default_email']['connection_name'],
1087                                        'connection_value'      => $data['connections']['default_email']['connection_value'],
1088                                        'connection_is_default' => 1,
1089                                );
1090                                $i++;
1091                        }
1092
1093                        if ($data['connections']['default_phone']['connection_value'])
1094                        {
1095                                $new_data['connections']['connection'.$i] = array(
1096                                        'id_typeof_connection'  => $preferences['personCardPhone'],
1097                                        'connection_name'       => $data['connections']['default_phone']['connection_name'],
1098                                        'connection_value'      => $data['connections']['default_phone']['connection_value'],
1099                                        'connection_is_default' => 1,
1100                                );
1101                                $i++;
1102                        }
1103                       
1104                        if(!$data['is_quick_add']){                     
1105                                $new_data['addresses']['address'.$i] = array(
1106                                        'id_typeof_address'  => 1,
1107                                        'address1'       => $data['addresses']['address_personal']['address1'],
1108                                        'postal_code'      => $data['addresses']['address_personal']['postal_code'],
1109                                        'id_country'    => $data['addresses']['address_personal']['id_country'],
1110                                        'id_state'      => $personal_state['id_state'],
1111                                        'id_city'       => $personal_city['id_city'],
1112                                        'address_is_default' => 1,
1113                                );
1114                                $i++;
1115                       
1116                                $new_data['addresses']['address'.$i] = array(
1117                                        'id_typeof_address'  => 2,
1118                                        'address1'       => $data['addresses']['address_corporative']['address1'],
1119                                        'postal_code'      => $data['addresses']['address_corporative']['postal_code'],
1120                                        'id_country'    => $data['addresses']['address_corporative']['id_country'],
1121                                        'id_state'      => $corporative_state['id_state'],
1122                                        'id_city'       => $corporative_city['id_city'],
1123                                        'address_is_default' => 0,
1124                                );                                                     
1125                                $i++;
1126                        }
1127                       
1128                        return $this->add_single_entry($new_data);
1129                }
1130       
1131                /*!
1132               
1133                        @function add_prefix
1134                        @abstract Insert a new Prefix in the DB
1135                        @author Raphael Derosso Pereira
1136               
1137                        @param string $prefix The Prefix
1138                        @return integer The new ID
1139                       
1140                */
1141                function add_prefix ( $prefix )
1142                {
1143                        $permissions = $this->security->get_type_permissions();
1144                       
1145                        if (!$permissions['create'])
1146                        {
1147                                return false;
1148                        }
1149                }
1150       
1151                /*!
1152               
1153                        @function add_suffix
1154                        @abstract Insert a new suffix in the DB
1155                        @author Raphael Derosso Pereira
1156               
1157                        @param string $suffix The suffix
1158                        @return integer The new ID
1159                       
1160                */
1161                function add_suffix ( $suffix )
1162                {
1163                        $permissions = $this->security->get_type_permissions();
1164                       
1165                        if (!$permissions['create'])
1166                        {
1167                                return false;
1168                        }
1169                }
1170       
1171                /*!
1172               
1173                        @function add_status
1174                        @abstract Insert a new Status in the DB
1175                        @author Raphael Derosso Pereira
1176               
1177                        @param string $status The Status
1178                        @return integer The new ID
1179                       
1180                */
1181                function add_status ( $status )
1182                {
1183                        $permissions = $this->security->get_type_permissions();
1184                       
1185                        if (!$permissions['create'])
1186                        {
1187                                return false;
1188                        }
1189                }
1190       
1191                /*!
1192               
1193                        @function add_relation_type
1194                        @abstract Insert a new Relation Type in the DB
1195                        @author Raphael Derosso Pereira
1196               
1197                        @param string $type_name The Relation Type
1198                        @return integer The new ID
1199                       
1200                */
1201                function add_relation_type ( $type_name )
1202                {
1203                        $permissions = $this->security->get_type_permissions();
1204                       
1205                        if (!$permissions['create'])
1206                        {
1207                                return false;
1208                        }
1209                }
1210       
1211                /*!
1212               
1213                        @function add_address_type
1214                        @abstract Insert a new Address Type in the DB
1215                        @author Raphael Derosso Pereira
1216               
1217                        @param string $type_name The Address Type
1218                        @return integer The new ID
1219                       
1220                */
1221                function add_address_type ( $type_name )
1222                {
1223                        $permissions = $this->security->get_type_permissions();
1224                       
1225                        if (!$permissions['create'])
1226                        {
1227                                return false;
1228                        }
1229                }
1230       
1231                /*!
1232               
1233                        @function add_connection_type
1234                        @abstract Insert a new Connection Type in the DB
1235                        @author Raphael Derosso Pereira
1236               
1237                        @param string $type_name The Connection Type
1238                        @return integer The new ID
1239                       
1240                */
1241                function add_connection_type ( $type_name )
1242                {
1243                        $permissions = $this->security->get_type_permissions();
1244                       
1245                        if (!$permissions['create'])
1246                        {
1247                                return false;
1248                        }
1249                }
1250       
1251
1252
1253                /*********************************************************************\
1254                 *                   Methods to Alter Data                           *
1255                \*********************************************************************/
1256
1257                /*!
1258               
1259                        @function update_single_info
1260                        @abstract Update information of an existing Contact
1261                        @author Raphael Derosso Pereira
1262               
1263                        @param integer $id_status The Contact ID
1264                        @param string $status The new Status value
1265                       
1266                */
1267                function update_single_info ( $id_contact, $data )
1268                {
1269                        $permissions = $this->security->get_permissions($id_contact);
1270                       
1271                        if (!$permissions['write'])
1272                        {
1273                                return false;
1274                        }
1275                       
1276                        $contact = CreateObject('contactcenter.so_contact', $id_contact);
1277                       
1278                        $altered = false;
1279//                      print_r($data);
1280                        foreach($data as $field => $value)
1281                        {
1282                                if ($value === false)
1283                                {
1284                                        continue;
1285                                }
1286                               
1287                                $altered = true;
1288                                switch($field)
1289                                {
1290                                        case 'photo':
1291                                        case 'alias':
1292                                        case 'id_prefix':
1293                                        case 'id_status':
1294                                        case 'id_suffix':
1295                                        case 'given_names':
1296                                        case 'family_names':
1297                                        case 'names_ordered':
1298                                        case 'birthdate':
1299                                        case 'sex':
1300                                        case 'pgp_key':
1301                                        case 'notes':
1302                                                $contact->set_field($field,$value);
1303                                                break;
1304
1305                                        case 'companies':                                       
1306                                                foreach($value as $company_fields)
1307                                                {
1308                                                        if ($company_fields['company_name'])
1309                                                        {
1310                                                                $fields = array('company.id_company');
1311                                                                $restric = array(
1312                                                                        0 => array(
1313                                                                                'field' => 'company.company_name',
1314                                                                                'type'  => 'iLIKE',
1315                                                                                'value' => $company_fields['company_name']
1316                                                                        )
1317                                                                );
1318                                                               
1319                                                                if($result = $this->find($fields,$restric))
1320                                                                {
1321                                                                        $id = $result[0]['id_company'];
1322                                                                        $company_fields['id_company'] = $id;
1323                                                                }
1324                                                                else
1325                                                                {
1326                                                                        $company = CreateObject('contactcenter.so_company');
1327                                                                        $company->reset_values();
1328                                                                        $company->set_company_name($company_fields['company_name']);
1329                                                                        $company->set_field('id_company_owner',$GLOBALS['phpgw_info']['user']['account_id']);
1330                                                                        $company_fields['id_company'] = $company->commit();
1331                                                                }
1332                                                        }
1333                                                       
1334                                                        $contact->set_company($company_fields);
1335                                                }
1336                                                break;
1337                                       
1338                                        case 'relations':
1339                                                foreach($value as $relation_fields)
1340                                                {
1341                                                        $contact->set_relation($relation_fields['id_relation'], $relation_fields['id_typeof_relation']);
1342                                                }
1343                                                break;
1344                                       
1345                                        case 'addresses':
1346                                                foreach($value as $address_name => $address_fields)
1347                                                {
1348                                                        if ($address_fields['id_address'] && $address_fields['id_address'] !== '')
1349                                                        {
1350                                                                $address = CreateObject('contactcenter.so_address', $address_fields['id_address']);
1351                                                        }
1352                                                        else
1353                                                        {
1354                                                                $address = CreateObject('contactcenter.so_address');
1355                                                                $address->reset_values();
1356                                                        }
1357
1358                                                        if (!isset($address_fields['id_country']) or $address_fields['id_country'] === false)
1359                                                        {
1360                                                                #var_dump($address_fields);
1361                                                                echo(serialize(array(
1362                                                                        'file' => __FILE__,
1363                                                                        'line' => __LINE__,
1364                                                                        'msg'  => lang('An Address must have at least a Country'),
1365                                                                        'status' => 'aborted'
1366                                                                )));
1367                                                                return;
1368                                                        }
1369                                                       
1370                                                        foreach ($address_fields as $f_name => $f_value)
1371                                                        {
1372                                                                if ($f_value === false)
1373                                                                {
1374                                                                        $address->set_field($f_name, null);
1375                                                                }
1376                                                                elseif (isset($f_value))
1377                                                                {
1378                                                                        $address->set_field($f_name, $f_value);
1379                                                                }
1380                                                        }
1381                                                               
1382                                                        $address->commit();
1383                                                        $id_address = $address->get_id();
1384                                                        $contact->set_address($id_address, $address_fields['id_typeof_address']);
1385                                                }
1386                                                break;
1387                                       
1388                                        case 'connections':
1389                                                foreach($value as $connection_name => $connection_fields)
1390                                                {
1391                                                        if ($connection_name === 'removed_conns')
1392                                                        {
1393                                                                foreach($connection_fields as $id)
1394                                                                {
1395                                                                        $connection = CreateObject('contactcenter.so_connection', $id);
1396                                                                        if (!($connection->remove()))
1397                                                                        {
1398                                                                                return false;
1399                                                                        }
1400
1401                                                                        $contact->remove_connection($id);
1402                                                                }
1403
1404                                                                continue;
1405                                                        }
1406                                                       
1407                                                        $id_connection = $connection_fields['id_connection'];
1408                                                        if ($id_connection === '_NEW_' or
1409                                                            $id_connection === '')
1410                                                        {
1411                                                                $connection = CreateObject('contactcenter.so_connection');
1412                                                                $connection->reset_values();
1413                                                        }
1414                                                        else
1415                                                        {
1416                                                                $connection = CreateObject('contactcenter.so_connection', $id_connection);
1417                                                        }
1418                                                               
1419                                                        foreach($connection_fields as $a_field => $a_value)
1420                                                        {
1421                                                                if ($a_field !== 'id_typeof_connection')
1422                                                                {
1423                                                                        $connection->set_field($a_field,$a_value);
1424                                                                }
1425                                                        }
1426                                                       
1427                                                        if (!$connection->commit())
1428                                                        {
1429                                                                return false;
1430                                                        }
1431                                                        $id_connection = $connection->get_id();
1432                                                        $contact->set_connection($id_connection, $connection_fields['id_typeof_connection']);
1433                                                }
1434                                                break;
1435                                               
1436                                        default:
1437                                                echo 'Invalid Field: '.$field.'<br>Value: '.$value;
1438                                                return false;
1439                                }
1440                        }
1441                       
1442                        if ($altered)
1443                        {
1444                                $contact->set_field("last_status", 'U');
1445                                $contact->set_field("last_update",time()."000");
1446                                return $contact->commit();
1447                        }
1448                       
1449                        return false;
1450                }
1451       
1452                /*!
1453               
1454                        @function update_prefix
1455                        @abstract Update an existing Prefix
1456                        @author Raphael Derosso Pereira
1457               
1458                        @param integer $id_prefix The Prefix ID
1459                        @param string $prefix The new Prefix value
1460                       
1461                */
1462                function update_prefix ( $id_prefix, $prefix )
1463                {
1464                        $permissions = $this->security->get_type_permissions();
1465                       
1466                        if (!$permissions['alter'])
1467                        {
1468                                return false;
1469                        }
1470                }
1471       
1472                /*!
1473               
1474                        @function update_suffix
1475                        @abstract Update an existing suffix
1476                        @author Raphael Derosso Pereira
1477               
1478                        @param integer $id_suffix The suffix ID
1479                        @param string $suffix The new suffix value
1480                       
1481                */
1482                function update_suffix ( $id_suffix, $suffix )
1483                {
1484                        $permissions = $this->security->get_type_permissions();
1485                       
1486                        if (!$permissions['alter'])
1487                        {
1488                                return false;
1489                        }
1490                }
1491       
1492                /*!
1493               
1494                        @function update_status
1495                        @abstract Update an existing Status
1496                        @author Raphael Derosso Pereira
1497               
1498                        @param integer $id_status The Status ID
1499                        @param string $status The new Status value
1500                       
1501                */
1502                function update_status ( $id_status, $status )
1503                {
1504                        $permissions = $this->security->get_type_permissions();
1505                       
1506                        if (!$permissions['alter'])
1507                        {
1508                                return false;
1509                        }
1510                }
1511       
1512                /*!
1513               
1514                        @function update_relation_type
1515                        @abstract Update an existing Relation Type
1516                        @author Raphael Derosso Pereira
1517               
1518                        @param integer $id_type The Type ID
1519                        @param string $type The new type value
1520                       
1521                */
1522                function update_relation_type ( $old_name, $relation_name )
1523                {
1524                }
1525       
1526                /*!
1527               
1528                        @function update_address_type
1529                        @abstract Update an existing Address Type
1530                        @author Raphael Derosso Pereira
1531               
1532                        @param integer $id_uype The Type ID
1533                        @param string $type The new type value
1534                       
1535                */
1536                function update_address_type ( $id_type, $type )
1537                {
1538                }
1539       
1540                /*!
1541               
1542                        @function update_connection_type
1543                        @abstract Update an existing Connection Type
1544                        @author Raphael Derosso Pereira
1545               
1546                        @param integer $id_type The Type ID
1547                        @param string $type The new type value
1548                       
1549                */
1550                function update_connection_type ( $id_type, $type )
1551                {
1552                }
1553
1554
1555                /*********************************************************************\
1556                 *                   Methods to Remove Data                          *
1557                \*********************************************************************/
1558
1559                /*!
1560               
1561                        @function remove_single_entry
1562                        @abstract Remove one contact from the DB
1563                        @author Raphael Derosso Pereira
1564               
1565                        @param integer $id_contact The Contact ID
1566                       
1567                */
1568                function remove_single_entry ( $id_contact )
1569                {
1570                        $permissions = $this->security->get_permissions();
1571                       
1572                        if (!$permissions['remove'])
1573                        {
1574                                return false;
1575                        }
1576                       
1577                        $contact = CreateObject('contactcenter.so_contact', $id_contact);
1578                       
1579                        if ($contact->get_state() === 'new')
1580                        {
1581                                return false;
1582                        }
1583                       
1584                        $addresses = $contact->get_addresses();
1585                        $connections = $contact->get_connections();
1586                       
1587                        if (!$contact->remove())
1588                        {
1589                                return false;
1590                        }
1591                       
1592                        foreach ($addresses as $id => $type)
1593                        {
1594                                if (!($address = CreateObject('contactcenter.so_address', $id)))
1595                                {
1596                                        return false;
1597                                }
1598                               
1599                                if (!($address->remove()))
1600                                {
1601                                        return false;
1602                                }
1603                               
1604                        }
1605
1606                        foreach ($connections as $id => $type)
1607                        {
1608                                if (!($connection = CreateObject('contactcenter.so_connection',$id)))
1609                                {                                       
1610                                        return false;
1611                                }
1612                               
1613                                if (!($connection->remove()))
1614                                {
1615                                        return false;
1616                                }
1617                               
1618                        }
1619                       
1620                        return true;
1621                }
1622        }
1623?>
Note: See TracBrowser for help on using the repository browser.