source: branches/2.3/contactcenter/inc/class.bo_shared_people_manager.inc.php @ 3339

Revision 3339, 42.6 KB checked in by eduardoalex, 14 years ago (diff)

Ticket #1247 - Adicionado os campos necessarios para aba corporativa

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