source: trunk/contactcenter/inc/class.bo_shared_people_manager.inc.php @ 2363

Revision 2363, 43.0 KB checked in by amuller, 14 years ago (diff)

Ticket #1008 - Adicionando info sobre licença

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