source: companies/serpro/contactcenter/inc/class.bo_people_catalog.inc.php @ 903

Revision 903, 44.4 KB checked in by niltonneto, 15 years ago (diff)

Importacao inicial do Expresso do Serpro

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                //alterada para receber a informacao em 'notes' - Rommel Cysne - rommel.cysne@serpro.gov.br
897                function add_single_entry ( $data )
898                {
899                        $permissions = $this->security->get_permissions();
900                       
901                        if (!$permissions['create'])
902                        {
903                                //return false;
904                        }
905                       
906                        $contact = CreateObject('contactcenter.so_contact');
907                        $contact->reset_values();
908                       
909                        $altered = false;
910                        foreach($data as $field => $value)
911                        {
912                                if ($value === false)
913                                {
914                                        continue;
915                                }
916                               
917                                $altered = true;
918                                switch($field)
919                                {
920                                        case 'photo':
921                                        case 'alias':
922                                        case 'id_prefix':
923                                        case 'id_status':
924                                        case 'id_suffix':
925                                        case 'given_names':
926                                        case 'family_names':
927                                        case 'names_ordered':
928                                        case 'birthdate':
929                                        case 'sex':
930                                        case 'pgp_key':
931
932                                        case 'notes':
933                                                $contact->set_field($field,$value);
934                                                break;
935
936                                        case 'companies':                                       
937                                                foreach($value as $company_fields)
938                                                {
939                                                        if ($company_fields['company_name'])
940                                                        {
941                                                                $fields = array('company.id_company');
942                                                                $restric = array(
943                                                                        0 => array(
944                                                                                'field' => 'company.company_name',
945                                                                                'type'  => 'iLIKE',
946                                                                                'value' => $company_fields['company_name']
947                                                                        )
948                                                                );
949                                                               
950                                                                if($result = $this->find($fields,$restric))
951                                                                {
952                                                                        $id = $result[0]['id_company'];
953                                                                        $company_fields['id_company'] = $id;
954                                                                }
955                                                                else
956                                                                {
957                                                                        $company = CreateObject('contactcenter.so_company');
958                                                                        $company->reset_values();
959                                                                        $company->set_company_name($company_fields['company_name']);
960                                                                        $company->set_field('id_company_owner',$GLOBALS['phpgw_info']['user']['account_id']);
961                                                                        $company_fields['id_company'] = $company->commit();
962                                                                }
963                                                        }
964                                                       
965                                                        $contact->set_company($company_fields);
966                                                }
967                                                break;
968                                       
969                                        case 'relations':
970                                                foreach($value as $relation_fields)
971                                                {
972                                                        $contact->set_relation($relation_fields['id_relation'], $relation_fields['id_typeof_relation']);
973                                                }
974                                                break;
975                                       
976                                        case 'addresses':
977                                                foreach($value as $address_fields)
978                                                {
979                                                        $address = CreateObject('contactcenter.so_address');
980                                                        $address->reset_values();
981                                                        foreach($address_fields as $a_field => $a_value)
982                                                        {
983                                                                if ($a_field !== 'id_typeof_address')
984                                                                {
985                                                                        $address->set_field($a_field,$a_value);
986                                                                }
987                                                        }
988                                                        $address->commit();
989                                                        $id_address = $address->get_id();
990                                                        $contact->set_address($id_address, $address_fields['id_typeof_address']);
991                                                }
992                                                break;
993                                       
994                                        case 'connections':
995                                                foreach($value as $connection_name => $connection_fields)
996                                                {
997                                                        $connection = CreateObject('contactcenter.so_connection');
998                                                        $connection->reset_values();
999                                                       
1000                                                        foreach($connection_fields as $a_field => $a_value)
1001                                                        {
1002                                                                if ($a_field !== 'id_typeof_connection')
1003                                                                {
1004                                                                        $connection->set_field($a_field,$a_value);
1005                                                                }
1006                                                        }
1007                                                       
1008                                                        $connection->commit();
1009                                                        $id_connection = $connection->get_id();
1010                                                        $contact->set_connection($id_connection, $connection_fields['id_typeof_connection']);
1011                                                }
1012                                                break;
1013                                               
1014                                        default:
1015                                                return false;
1016                                }
1017                        }
1018                       
1019                        if ($altered)
1020                        {
1021                                $contact->set_field('id_owner',$GLOBALS['phpgw_info']['user']['account_id']);
1022                                return $contact->commit();
1023                        }
1024                       
1025                        return false;
1026                }
1027               
1028                /*!
1029               
1030                        @function quick_add
1031                        @abstract Insert a new Contact record in the DB with just the
1032                                main fields
1033                        @author Raphael Derosso Pereira
1034               
1035                        @param array $data The Contact Information.
1036                       
1037                        Format:
1038               
1039                                $data = array(
1040                                        'alias'              => '<alias>',
1041                                        'given_names'        => '<given_names>',
1042                                        'family_names'       => '<family_names>',
1043
1044                                        'connections'        => array(
1045                                                'default_email' => array(
1046                                                        'connection_name'       => <connection_name>,
1047                                                        'connection_value'      => <connection_value>
1048                                                ),
1049                                                'default_phone' => array(
1050                                                        'connection_name'       => <connection_name>,
1051                                                        'connection_value'      => <connection_value>
1052                                                )
1053                                        )
1054                                );
1055                */
1056                //alterada para receber os outros parametros existentes na adicao completa de contatos pessoais
1057                //Rommel Cysne - rommel.cysne@serpro.gov.br
1058                function quick_add ( $data )
1059                {
1060                        $permissions = $this->security->get_permissions();
1061                       
1062                        if (!$permissions['create'])
1063                        {
1064                                return false;
1065                        }
1066
1067                        // TODO: GET THE ORDER TO PUT names_ordered FROM PREFERENCES!
1068
1069                        $preferences = ExecMethod('contactcenter.ui_preferences.get_preferences');
1070                       
1071                        if (!is_array($preferences))
1072                        {
1073                                $preferences['personCardEmail'] = 1;
1074                                $preferences['personCardPhone'] = 2;
1075                        }
1076                       
1077                        $new_data = array(
1078                                'alias'                 => $data['alias'],
1079                                'id_status'             => 1,
1080                                'given_names'           => $data['given_names'],
1081                                'family_names'          => $data['family_names'],
1082                                'names_ordered'         => $data['given_names'].' '.$data['family_names'],
1083                                'birthdate'             => $data['birthdate'],
1084                                'notes'                 => $data['notes'],
1085                        );
1086
1087                        $i = 1;
1088                        if ($data['connections']['default_email']['connection_value'])
1089                        {
1090                                $new_data['connections']['connection'.$i] = array(
1091                                        'id_typeof_connection'  => $preferences['personCardEmail'],
1092                                        'connection_name'       => $data['connections']['default_email']['connection_name'],
1093                                        'connection_value'      => $data['connections']['default_email']['connection_value'],
1094                                        'connection_is_default' => 1,
1095                                );
1096                                $i++;
1097                        }
1098
1099                        if ($data['connections']['default_phone']['connection_value'])
1100                        {
1101                                $new_data['connections']['connection'.$i] = array(
1102                                        'id_typeof_connection'  => $preferences['personCardPhone'],
1103                                        'connection_name'       => $data['connections']['default_phone']['connection_name'],
1104                                        'connection_value'      => $data['connections']['default_phone']['connection_value'],
1105                                        'connection_is_default' => 1,
1106                                );
1107                                $i++;
1108                        }
1109
1110                        if($data['connections']['fax']['connection_value'])
1111                        {
1112                                $new_data['connections']['connection'.$i] = array(
1113                                        'id_typeof_connection'  => $preferences['personCardPhone'],
1114                                        'connection_name'       => $data['connections']['fax']['connection_name'],
1115                                        'connection_value'      => $data['connections']['fax']['connection_value'],
1116                                        'connection_is_default' => 'false',
1117                                );
1118                                $i++;
1119                        }
1120
1121                        if($data['connections']['residencial_phone']['connection_value'])
1122                        {
1123                                $new_data['connections']['connection'.$i] = array(
1124                                        'id_typeof_connection'  => $preferences['personCardPhone'],
1125                                        'connection_name'       => $data['connections']['residencial_phone']['connection_name'],
1126                                        'connection_value'      => $data['connections']['residencial_phone']['connection_value'],
1127                                        'connection_is_default' => 'false',
1128                                );
1129                                $i++;
1130                        }
1131
1132                        if($data['connections']['cellular_phone']['connection_value'])
1133                        {
1134                                $new_data['connections']['connection'.$i] = array(
1135                                        'id_typeof_connection'  => $preferences['personCardPhone'],
1136                                        'connection_name'       => $data['connections']['cellular_phone']['connection_name'],
1137                                        'connection_value'      => $data['connections']['cellular_phone']['connection_value'],
1138                                        'connection_is_default' => 'false',
1139                                );
1140                                $i++;
1141                        }
1142
1143                        if($data['connections']['pager']['connection_value'])
1144                        {
1145                                $new_data['connections']['connection'.$i] = array(
1146                                        'id_typeof_connection'  => $preferences['personCardPhone'],
1147                                        'connection_name'       => $data['connections']['pager']['connection_name'],
1148                                        'connection_value'      => $data['connections']['pager']['connection_value'],
1149                                        'connection_is_default' => 'false',
1150                                );
1151                                $i++;
1152                        }
1153
1154                        if($data['connections']['alternative_email']['connection_value'])
1155                        {
1156                                $new_data['connections']['connection'.$i] = array(
1157                                        'id_typeof_connection'  => $preferences['personCardEmail'],
1158                                        'connection_name'       => $data['connections']['alternative_email']['connection_name'],
1159                                        'connection_value'      => $data['connections']['alternative_email']['connection_value'],
1160                                        'connection_is_default' => 'false',
1161                                );
1162                                $i++;
1163                        }
1164
1165                        $j = 1;
1166                        if($data['addresses']['addr1']['address_value'])
1167                        {
1168                                $new_data['addresses']['address'.$j] = array(
1169                                        'id_typeof_address'     => 2, //<id_typeof_address> - 1 - Residencial; 2 - Comercial
1170                                        'address1'              => $data['addresses']['addr1']['address_value'],
1171                                        'address2'              => $data['addresses']['addr2']['address_value'],
1172                                        'id_country'            => 'BR',
1173                                        //'complement'          => '<complement>',
1174                                        //'address_other'       => '<address_other>',
1175                                        'postal_code'           => $data['addresses']['cep']['address_value'],
1176                                        //'po_box'              => '<po_box>',
1177                                        //'id_city'             => '<city>',
1178                                        'address_is_default'    => 'false',
1179                                );
1180                                $j++;
1181                        }
1182
1183                        return $this->add_single_entry($new_data);
1184                }
1185       
1186                /*!
1187               
1188                        @function add_prefix
1189                        @abstract Insert a new Prefix in the DB
1190                        @author Raphael Derosso Pereira
1191               
1192                        @param string $prefix The Prefix
1193                        @return integer The new ID
1194                       
1195                */
1196                function add_prefix ( $prefix )
1197                {
1198                        $permissions = $this->security->get_type_permissions();
1199                       
1200                        if (!$permissions['create'])
1201                        {
1202                                return false;
1203                        }
1204                }
1205       
1206                /*!
1207               
1208                        @function add_suffix
1209                        @abstract Insert a new suffix in the DB
1210                        @author Raphael Derosso Pereira
1211               
1212                        @param string $suffix The suffix
1213                        @return integer The new ID
1214                       
1215                */
1216                function add_suffix ( $suffix )
1217                {
1218                        $permissions = $this->security->get_type_permissions();
1219                       
1220                        if (!$permissions['create'])
1221                        {
1222                                return false;
1223                        }
1224                }
1225       
1226                /*!
1227               
1228                        @function add_status
1229                        @abstract Insert a new Status in the DB
1230                        @author Raphael Derosso Pereira
1231               
1232                        @param string $status The Status
1233                        @return integer The new ID
1234                       
1235                */
1236                function add_status ( $status )
1237                {
1238                        $permissions = $this->security->get_type_permissions();
1239                       
1240                        if (!$permissions['create'])
1241                        {
1242                                return false;
1243                        }
1244                }
1245       
1246                /*!
1247               
1248                        @function add_relation_type
1249                        @abstract Insert a new Relation Type in the DB
1250                        @author Raphael Derosso Pereira
1251               
1252                        @param string $type_name The Relation Type
1253                        @return integer The new ID
1254                       
1255                */
1256                function add_relation_type ( $type_name )
1257                {
1258                        $permissions = $this->security->get_type_permissions();
1259                       
1260                        if (!$permissions['create'])
1261                        {
1262                                return false;
1263                        }
1264                }
1265       
1266                /*!
1267               
1268                        @function add_address_type
1269                        @abstract Insert a new Address Type in the DB
1270                        @author Raphael Derosso Pereira
1271               
1272                        @param string $type_name The Address Type
1273                        @return integer The new ID
1274                       
1275                */
1276                function add_address_type ( $type_name )
1277                {
1278                        $permissions = $this->security->get_type_permissions();
1279                       
1280                        if (!$permissions['create'])
1281                        {
1282                                return false;
1283                        }
1284                }
1285       
1286                /*!
1287               
1288                        @function add_connection_type
1289                        @abstract Insert a new Connection Type in the DB
1290                        @author Raphael Derosso Pereira
1291               
1292                        @param string $type_name The Connection Type
1293                        @return integer The new ID
1294                       
1295                */
1296                function add_connection_type ( $type_name )
1297                {
1298                        $permissions = $this->security->get_type_permissions();
1299                       
1300                        if (!$permissions['create'])
1301                        {
1302                                return false;
1303                        }
1304                }
1305       
1306
1307
1308                /*********************************************************************\
1309                 *                   Methods to Alter Data                           *
1310                \*********************************************************************/
1311
1312                /*!
1313               
1314                        @function update_single_info
1315                        @abstract Update information of an existing Contact
1316                        @author Raphael Derosso Pereira
1317               
1318                        @param integer $id_status The Contact ID
1319                        @param string $status The new Status value
1320                       
1321                */
1322                function update_single_info ( $id_contact, $data )
1323                {
1324                        $permissions = $this->security->get_permissions($id_contact);
1325                       
1326                        if (!$permissions['write'])
1327                        {
1328                                return false;
1329                        }
1330                       
1331                        $contact = CreateObject('contactcenter.so_contact', $id_contact);
1332                       
1333                        $altered = false;
1334//                      print_r($data);
1335                        foreach($data as $field => $value)
1336                        {
1337                                if ($value === false)
1338                                {
1339                                        continue;
1340                                }
1341                               
1342                                $altered = true;
1343                                switch($field)
1344                                {
1345                                        case 'photo':
1346                                        case 'alias':
1347                                        case 'id_prefix':
1348                                        case 'id_status':
1349                                        case 'id_suffix':
1350                                        case 'given_names':
1351                                        case 'family_names':
1352                                        case 'names_ordered':
1353                                        case 'birthdate':
1354                                        case 'sex':
1355                                        case 'pgp_key':
1356                                        case 'notes':
1357                                                $contact->set_field($field,$value);
1358                                                break;
1359
1360                                        case 'companies':                                       
1361                                                foreach($value as $company_fields)
1362                                                {
1363                                                        if ($company_fields['company_name'])
1364                                                        {
1365                                                                $fields = array('company.id_company');
1366                                                                $restric = array(
1367                                                                        0 => array(
1368                                                                                'field' => 'company.company_name',
1369                                                                                'type'  => 'iLIKE',
1370                                                                                'value' => $company_fields['company_name']
1371                                                                        )
1372                                                                );
1373                                                               
1374                                                                if($result = $this->find($fields,$restric))
1375                                                                {
1376                                                                        $id = $result[0]['id_company'];
1377                                                                        $company_fields['id_company'] = $id;
1378                                                                }
1379                                                                else
1380                                                                {
1381                                                                        $company = CreateObject('contactcenter.so_company');
1382                                                                        $company->reset_values();
1383                                                                        $company->set_company_name($company_fields['company_name']);
1384                                                                        $company->set_field('id_company_owner',$GLOBALS['phpgw_info']['user']['account_id']);
1385                                                                        $company_fields['id_company'] = $company->commit();
1386                                                                }
1387                                                        }
1388                                                       
1389                                                        $contact->set_company($company_fields);
1390                                                }
1391                                                break;
1392                                       
1393                                        case 'relations':
1394                                                foreach($value as $relation_fields)
1395                                                {
1396                                                        $contact->set_relation($relation_fields['id_relation'], $relation_fields['id_typeof_relation']);
1397                                                }
1398                                                break;
1399                                       
1400                                        case 'addresses':
1401                                                foreach($value as $address_name => $address_fields)
1402                                                {
1403                                                        if ($address_fields['id_address'] && $address_fields['id_address'] !== '')
1404                                                        {
1405                                                                $address = CreateObject('contactcenter.so_address', $address_fields['id_address']);
1406                                                        }
1407                                                        else
1408                                                        {
1409                                                                $address = CreateObject('contactcenter.so_address');
1410                                                                $address->reset_values();
1411                                                        }
1412
1413                                                        if (!isset($address_fields['id_country']) or $address_fields['id_country'] === false)
1414                                                        {
1415                                                                #var_dump($address_fields);
1416                                                                echo(serialize(array(
1417                                                                        'file' => __FILE__,
1418                                                                        'line' => __LINE__,
1419                                                                        'msg'  => lang('An Address must have at least a Country'),
1420                                                                        'status' => 'aborted'
1421                                                                )));
1422                                                                return;
1423                                                        }
1424                                                       
1425                                                        foreach ($address_fields as $f_name => $f_value)
1426                                                        {
1427                                                                if ($f_value === false)
1428                                                                {
1429                                                                        $address->set_field($f_name, null);
1430                                                                }
1431                                                                elseif (isset($f_value))
1432                                                                {
1433                                                                        $address->set_field($f_name, $f_value);
1434                                                                }
1435                                                        }
1436                                                               
1437                                                        $address->commit();
1438                                                        $id_address = $address->get_id();
1439                                                        $contact->set_address($id_address, $address_fields['id_typeof_address']);
1440                                                }
1441                                                break;
1442                                       
1443                                        case 'connections':
1444                                                foreach($value as $connection_name => $connection_fields)
1445                                                {
1446                                                        if ($connection_name === 'removed_conns')
1447                                                        {
1448                                                                foreach($connection_fields as $id)
1449                                                                {
1450                                                                        $connection = CreateObject('contactcenter.so_connection', $id);
1451                                                                        if (!($connection->remove()))
1452                                                                        {
1453                                                                                return false;
1454                                                                        }
1455
1456                                                                        $contact->remove_connection($id);
1457                                                                }
1458
1459                                                                continue;
1460                                                        }
1461                                                       
1462                                                        $id_connection = $connection_fields['id_connection'];
1463                                                        if ($id_connection === '_NEW_' or
1464                                                            $id_connection === '')
1465                                                        {
1466                                                                $connection = CreateObject('contactcenter.so_connection');
1467                                                                $connection->reset_values();
1468                                                        }
1469                                                        else
1470                                                        {
1471                                                                $connection = CreateObject('contactcenter.so_connection', $id_connection);
1472                                                        }
1473                                                               
1474                                                        foreach($connection_fields as $a_field => $a_value)
1475                                                        {
1476                                                                if ($a_field !== 'id_typeof_connection')
1477                                                                {
1478                                                                        $connection->set_field($a_field,$a_value);
1479                                                                }
1480                                                        }
1481                                                       
1482                                                        if (!$connection->commit())
1483                                                        {
1484                                                                return false;
1485                                                        }
1486                                                        $id_connection = $connection->get_id();
1487                                                        $contact->set_connection($id_connection, $connection_fields['id_typeof_connection']);
1488                                                }
1489                                                break;
1490                                               
1491                                        default:
1492                                                echo 'Invalid Field: '.$field.'<br>Value: '.$value;
1493                                                return false;
1494                                }
1495                        }
1496                       
1497                        if ($altered)
1498                        {
1499                                $contact->set_field("last_status", 'U');
1500                                $contact->set_field("last_update",time()."000");
1501                                return $contact->commit();
1502                        }
1503                       
1504                        return false;
1505                }
1506       
1507                /*!
1508               
1509                        @function update_prefix
1510                        @abstract Update an existing Prefix
1511                        @author Raphael Derosso Pereira
1512               
1513                        @param integer $id_prefix The Prefix ID
1514                        @param string $prefix The new Prefix value
1515                       
1516                */
1517                function update_prefix ( $id_prefix, $prefix )
1518                {
1519                        $permissions = $this->security->get_type_permissions();
1520                       
1521                        if (!$permissions['alter'])
1522                        {
1523                                return false;
1524                        }
1525                }
1526       
1527                /*!
1528               
1529                        @function update_suffix
1530                        @abstract Update an existing suffix
1531                        @author Raphael Derosso Pereira
1532               
1533                        @param integer $id_suffix The suffix ID
1534                        @param string $suffix The new suffix value
1535                       
1536                */
1537                function update_suffix ( $id_suffix, $suffix )
1538                {
1539                        $permissions = $this->security->get_type_permissions();
1540                       
1541                        if (!$permissions['alter'])
1542                        {
1543                                return false;
1544                        }
1545                }
1546       
1547                /*!
1548               
1549                        @function update_status
1550                        @abstract Update an existing Status
1551                        @author Raphael Derosso Pereira
1552               
1553                        @param integer $id_status The Status ID
1554                        @param string $status The new Status value
1555                       
1556                */
1557                function update_status ( $id_status, $status )
1558                {
1559                        $permissions = $this->security->get_type_permissions();
1560                       
1561                        if (!$permissions['alter'])
1562                        {
1563                                return false;
1564                        }
1565                }
1566       
1567                /*!
1568               
1569                        @function update_relation_type
1570                        @abstract Update an existing Relation Type
1571                        @author Raphael Derosso Pereira
1572               
1573                        @param integer $id_type The Type ID
1574                        @param string $type The new type value
1575                       
1576                */
1577                function update_relation_type ( $old_name, $relation_name )
1578                {
1579                }
1580       
1581                /*!
1582               
1583                        @function update_address_type
1584                        @abstract Update an existing Address Type
1585                        @author Raphael Derosso Pereira
1586               
1587                        @param integer $id_uype The Type ID
1588                        @param string $type The new type value
1589                       
1590                */
1591                function update_address_type ( $id_type, $type )
1592                {
1593                }
1594       
1595                /*!
1596               
1597                        @function update_connection_type
1598                        @abstract Update an existing Connection Type
1599                        @author Raphael Derosso Pereira
1600               
1601                        @param integer $id_type The Type ID
1602                        @param string $type The new type value
1603                       
1604                */
1605                function update_connection_type ( $id_type, $type )
1606                {
1607                }
1608
1609
1610                /*********************************************************************\
1611                 *                   Methods to Remove Data                          *
1612                \*********************************************************************/
1613
1614                /*!
1615               
1616                        @function remove_single_entry
1617                        @abstract Remove one contact from the DB
1618                        @author Raphael Derosso Pereira
1619               
1620                        @param integer $id_contact The Contact ID
1621                       
1622                */
1623                function remove_single_entry ( $id_contact )
1624                {
1625                        $permissions = $this->security->get_permissions();
1626                       
1627                        if (!$permissions['remove'])
1628                        {
1629                                return false;
1630                        }
1631                       
1632                        $contact = CreateObject('contactcenter.so_contact', $id_contact);
1633                       
1634                        if ($contact->get_state() === 'new')
1635                        {
1636                                return false;
1637                        }
1638                       
1639                        $addresses = $contact->get_addresses();
1640                        $connections = $contact->get_connections();
1641                       
1642                        if (!$contact->remove())
1643                        {
1644                                return false;
1645                        }
1646                       
1647                        foreach ($addresses as $id => $type)
1648                        {
1649                                if (!($address = CreateObject('contactcenter.so_address', $id)))
1650                                {
1651                                        return false;
1652                                }
1653                               
1654                                if (!($address->remove()))
1655                                {
1656                                        return false;
1657                                }
1658                               
1659                        }
1660
1661                        foreach ($connections as $id => $type)
1662                        {
1663                                if (!($connection = CreateObject('contactcenter.so_connection',$id)))
1664                                {                                       
1665                                        return false;
1666                                }
1667                               
1668                                if (!($connection->remove()))
1669                                {
1670                                        return false;
1671                                }
1672                               
1673                        }
1674                       
1675                        return true;
1676                }
1677        }
1678?>
Note: See TracBrowser for help on using the repository browser.