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

Revision 5509, 43.3 KB checked in by gustavo, 12 years ago (diff)

Ticket #2488 - Adicionar cabecalho de licenca em arquivos que nao o possuem

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