source: trunk/contactcenter/inc/class.so_contact.inc.php @ 2

Revision 2, 27.8 KB checked in by niltonneto, 17 years ago (diff)

Removida todas as tags usadas pelo CVS ($Id, $Source).
Primeira versão no CVS externo.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1<?php
2  /***************************************************************************\
3  * eGroupWare - Contacts Center                                              *
4  * http://www.egroupware.org                                                 *
5  *                                                                           *
6  * Storage Object Classes                                                    *
7  * Written by:                                                               *
8  *  - Raphael Derosso Pereira <raphaelpereira@users.sourceforge.net>         *
9  *  sponsored by Thyamad - http://www.thyamad.com                            *
10  * ------------------------------------------------------------------------- *
11  *  This program is free software; you can redistribute it and/or modify it  *
12  *  under the terms of the GNU General Public License as published by the    *
13  *  Free Software Foundation; either version 2 of the License, or (at your   *
14  *  option) any later version.                                               *
15  \***************************************************************************/
16
17        /**
18         * This class handles the Contact DB Table
19         *
20         */
21
22        include_once("class.so_main.inc.php");
23
24        class so_contact extends so_main {
25               
26                function so_contact ( $id_contact = false)
27                {
28                        $this->init();
29                                               
30                        $this->main_fields = array(
31                                'id_contact'    => array(
32                                        'name'          => 'id_contact',
33                                        'type'          => 'primary',
34                                        'state'         => 'empty',
35                                        'value'         => &$this->id),
36                                'id_owner'              => array(
37                                        'name'          => 'id_owner',         
38                                        'type'          => false,
39                                        'state'         => 'empty',
40                                        'value'         => false),
41                                'id_status'             => array(
42                                        'name'          => 'id_status',
43                                        'type'          => 'foreign',
44                                        'association'   => array(
45                                                'table'                 => 'phpgw_cc_status',
46                                                'field'                 => 'id_status'),
47                                        'state'         => 'empty',
48                                        'value'         => false),
49                                'photo'                 => array(
50                                        'name'          => 'photo',
51                                        'type'          => false,
52                                        'state'         => 'empty',
53                                        'value'         => false),
54                                'alias'                 => array(
55                                        'name'          => 'alias',
56                                        'type'          => false,
57                                        'state'         => 'empty',
58                                        'value'         => false),
59                                'id_prefix'             => array(
60                                        'name'                  => 'id_prefix',
61                                        'type'                  => 'foreign',
62                                        'association'   => array(
63                                                'table'                 => 'phpgw_cc_prefixes',
64                                                'field'                 => 'id_prefix'),
65                                        'state'         => 'empty',
66                                        'value'         => false),
67                                'given_names'   => array(
68                                        'name'          => 'given_names',
69                                        'type'          => false,
70                                        'state'         => 'empty',
71                                        'value'         => false),
72                                'family_names'  => array(
73                                        'name'          => 'family_names',
74                                        'type'          => false,
75                                        'state'         => 'empty',
76                                        'value'         => false),
77                                'names_ordered' => array(
78                                        'name'          => 'names_ordered',
79                                        'type'          => false,
80                                        'state'         => 'empty',
81                                        'value'         => false),
82                                'id_suffix'             => array(
83                                        'name'                  => 'id_suffix',
84                                        'type'                  => 'foreign',
85                                        'association'   => array(
86                                                'table'                 => 'phpgw_cc_suffixes',
87                                                'field'                 => 'id_suffix'),
88                                        'state'         => 'empty',
89                                        'value'         => false),
90                                'birthdate'             => array(
91                                        'name'          => 'birthdate',
92                                        'type'          => false,
93                                        'state'         => 'empty',
94                                        'value'         => false),
95                                'sex'                   => array(
96                                        'name'          => 'sex',
97                                        'type'          => false,
98                                        'state'         => 'empty',
99                                        'value'         => false),
100                                'pgp_key'               => array(
101                                        'name'          => 'pgp_key',
102                                        'type'          => false,
103                                        'state'         => 'empty',
104                                        'value'         => false),
105                                'notes'                 => array(
106                                        'name'          => 'notes',
107                                        'type'          => false,
108                                        'state'         => 'empty',
109                                        'value'         => false),
110                                'is_global'             => array(
111                                        'name'          => 'is_global',
112                                        'type'          => false,
113                                        'state'         => 'empty',
114                                        'value'         => false));
115                                       
116                        $this->companies        = array(
117                                'id_contact' => array(
118                                        'name'        => 'id_contact',
119                                        'type'        => array('foreign', 'primary'),
120                                        'association' => array(
121                                                'table'   => 'phpgw_cc_contact',
122                                                'field'   => 'id_contact'
123                                        ),
124                                        'states'      => array(),
125                                        'values'      => array()
126                                ),
127                                'id_company' => array(
128                                        'name'        => 'id_company',
129                                        'type'        => array('foreign', 'primary'),
130                                        'association' => array(
131                                                'table'   => 'phpgw_cc_company',
132                                                'field'   => 'id_company'
133                                        ),
134                                        'states'      => array(),
135                                        'values'      => array()
136                                ),
137                                'title'      => array(
138                                        'name'   => 'title',
139                                        'type'   => false,
140                                        'states' => array(),
141                                        'values' => array()
142                                ),
143                                'department' => array(
144                                        'name'   => 'department',
145                                        'type'   => false,
146                                        'states' => array(),
147                                        'values' => array()
148                                ),
149                                'default_contact' => array(
150                                        'name'   => 'default_contact',
151                                        'type'   => false,
152                                        'states' => array(),
153                                        'values' => array()
154                                ),
155                                'default_company' => array(
156                                        'name'   => 'default_company',
157                                        'type'   => false,
158                                        'states' => array(),
159                                        'values' => array()
160                                )
161                        );
162                                               
163                        $this->addresses        = array(
164                                'id_contact'    => array(
165                                        'name'                  => 'id_contact',
166                                        'type'                  => array('foreign', 'primary'),
167                                        'association'   => array(
168                                                'table'                 => 'phpgw_cc_contact',
169                                                'field'                 => 'id_contact'),
170                                        'states'                =>      array(),
171                                        'values'                => array()),
172                                'id_address'    => array(
173                                        'name'                  => 'id_address',
174                                        'type'                  => array('foreign', 'primary'),
175                                        'association'   => array(
176                                                'table'                 => 'phpgw_cc_addresses',
177                                                'field'                 => 'id_address'),
178                                        'states'                =>      array(),
179                                        'values'                => array()),
180                                'id_typeof_contact_address'     => array(
181                                        'name'                  => 'id_typeof_contact_address',
182                                        'type'                  => 'foreign',
183                                        'association'   => array(
184                                                'table'                 => 'phpgw_cc_typeof_ct_addrs',
185                                                'field'                 => 'id_typeof_contact_address'),
186                                        'states'                =>      array(),
187                                        'values'                => array()));
188                               
189                               
190                        $this->connections      = array(
191                                'id_contact'    => array(
192                                        'name'                  => 'id_contact',
193                                        'type'                  => array('foreign', 'primary'),
194                                        'association'   => array(
195                                                'table'                 => 'phpgw_cc_contact',
196                                                'field'                 => 'id_contact'),
197                                        'states'                =>      array(),
198                                        'values'                => array()),
199                                'id_connection' => array(
200                                        'name'                  => 'id_connection',
201                                        'type'                  => array('foreign', 'primary'),
202                                        'association'   => array(
203                                                'table'                 => 'phpgw_cc_connections',
204                                                'field'                 => 'id_connection'),
205                                        'states'                =>      array(),
206                                        'values'                => array()),
207                                'id_typeof_contact_connection'  => array(
208                                        'name'                  => 'id_typeof_contact_connection',
209                                        'type'                  => array('foreign', 'primary'),
210                                        'association'   => array(
211                                                'table'                 => 'phpgw_cc_typeof_ct_conns',
212                                                'field'                 => 'id_typeof_contact_connection'),
213                                        'states'                =>      array(),
214                                        'values'                => array()));
215                       
216                        $this->relations        = array(
217                                'id_contact'    => array(
218                                        'name'                  => 'id_contact',
219                                        'type'                  => array('foreign', 'primary'),
220                                        'association'   => array(
221                                                'table'                 => 'phpgw_cc_contact',
222                                                'field'                 => 'id_contact'
223                                        ),
224                                        'states'                =>      array(),
225                                        'values'        => array()
226                                ),
227                                'id_related'    => array(
228                                        'name'                  => 'id_related',
229                                        'type'                  => array('foreign', 'primary'),
230                                        'association'   => array(
231                                                'table'                 => 'phpgw_cc_contact',
232                                                'field'                 => 'id_contact'
233                                        ),
234                                        'states'                =>      array(),
235                                        'values'        => array()
236                                ),
237                                'id_typeof_contact_relation'    => array(
238                                        'name'                  => 'id_typeof_contact_relation',
239                                        'type'                  => array('foreign', 'primary'),
240                                        'association'   => array(
241                                                'table'                 => 'phpgw_cc_typeof_ct_rels',
242                                                'field'                 => 'id_typeof_contact_relation'
243                                        ),
244                                        'states'                =>      array(),
245                                        'values'        => array()
246                                )
247                        );
248                               
249
250                        $this->db_tables = array(
251                                'phpgw_cc_contact'      => array(
252                                        'type'          => 'main',
253                                        'keys'          => array(
254                                                'primary' => array(&$this->main_fields['id_contact']),
255                                                'foreign' => array(
256                                                        &$this->main_fields['id_status'],
257                                                        &$this->main_fields['id_prefix'],
258                                                        &$this->main_fields['id_suffix'])),
259                                        'fields'        => & $this->main_fields),
260                                'phpgw_cc_contact_company'      => array(
261                                        'type'          => 'multi',
262                                        'keys'          => array(
263                                                'primary' => array(
264                                                        &$this->companies['id_contact'],
265                                                        &$this->companies['id_company']),
266                                                'foreign' => array(
267                                                        &$this->companies['id_contact'],
268                                                        &$this->companies['id_company'])),
269                                        'fields'        => & $this->companies),
270                                'phpgw_cc_contact_rels' => array(
271                                        'type'          => 'multi',
272                                        'keys'          => array(
273                                                'primary' => array(
274                                                        &$this->relations['id_contact'],
275                                                        &$this->relations['id_related']),
276                                                'foreign' => array(
277                                                        &$this->relations['id_contact'],
278                                                        &$this->relations['id_related'])),
279                                        'fields'        => & $this->relations),
280                                'phpgw_cc_contact_addrs'        => array(
281                                        'type'          => 'multi',
282                                        'keys'          => array(
283                                                'primary' => array(
284                                                        &$this->addresses['id_contact'],
285                                                        &$this->addresses['id_address']),
286                                                'foreign' => array(
287                                                        &$this->addresses['id_contact'],
288                                                        &$this->addresses['id_address'],
289                                                        &$this->addresses['id_typeof_contact_address'])),
290                                        'fields'        => & $this->addresses),
291                                'phpgw_cc_contact_conns'        => array(
292                                        'type'          => 'multi',
293                                        'keys'          => array(
294                                                'primary' => array(
295                                                        &$this->connections['id_contact'],
296                                                        &$this->connections['id_connection']),
297                                                'foreign' => array(
298                                                        &$this->connections['id_contact'],
299                                                        &$this->connections['id_connection'],
300                                                        &$this->connections['id_typeof_contact_connection'])),
301                                        'fields'        => & $this->connections));
302                                       
303
304                        if ($id_contact)
305                        {
306                                $this->id = $id_contact;
307                                if (!$this->checkout($id_contact))
308                                {
309                                        $this->reset_values();
310                                        $this->state = 'new';
311                                }
312                        }
313                        else
314                        {
315                                $this->state = 'new';
316                        }
317                                               
318                }
319       
320                /*********************************************************************\
321                 *                   Methods to Obtain Data                          *
322                \*********************************************************************/
323       
324                /*!
325               
326                        @function get_photo
327                        @abstract Returns the Contact's photo binary string
328                        @author Raphael Derosso Pereira
329               
330                */
331                function get_photo (  )
332                {
333                        return $this->main_fields['photo']['value'];
334                }
335       
336                /*!
337               
338                        @function get_alias
339                        @abstract Returns the Contact alias
340                        @author Raphael Derosso Pereira
341               
342                */
343                function get_alias (  )
344                {
345                        return $this->main_fields['alias']['value'];
346                }
347       
348                /*!
349               
350                        @function get_prefix
351                        @abstract Returns the Contact prefix ID
352                        @author Raphael Derosso Pereira
353               
354                */
355                function get_prefix (  )
356                {
357                        return $this->main_fields['id_prefix']['value'];
358                }
359       
360                /*!
361               
362                        @function get_given_names
363                        @abstract Returns the Contact's given names
364                        @author Raphael Derosso Pereira
365               
366                */
367                function get_given_names (  )
368                {
369                        return $this->main_fields['given_names']['value'];
370                }
371       
372                /*!
373               
374                        @function get_family_names
375                        @abstract Returns the Contact's family names
376                        @author Raphael Derosso Pereira
377               
378                */
379                function get_family_names (  )
380                {
381                        return $this->main_fields['family_names']['value'];
382                }
383       
384                /*!
385               
386                        @function get_names_ordered
387                        @abstract Returns the Contact's names ordered
388                        @author Raphael Derosso Pereira
389               
390                */
391                function get_names_ordered (  )
392                {
393                        return $this->main_fields['names_ordered']['value'];
394                }
395       
396                /*!
397               
398                        @function get_suffix
399                        @abstract Returns the Contact's suffix
400                        @author Raphael Derosso Pereira
401               
402                */
403                function get_suffix (  )
404                {
405                        return $this->main_fields['id_suffix']['value'];
406                }
407       
408                /*!
409               
410                        @function get_birthdate
411                        @abstract Returns the Contact's birthdata
412                        @author Raphael Derosso Pereira
413               
414                */
415                function get_birthdate (  )
416                {
417                        return $this->main_fields['birthdate']['value'];
418                }
419       
420                /*!
421               
422                        @function get_sex
423                        @abstract Returns the Contact's sex
424                        @author Raphael Derosso Pereira
425               
426                */
427                function get_sex (  )
428                {
429                        return $this->main_fields['sex']['value'];
430                }
431       
432                /*!
433               
434                        @function get_pgp_key
435                        @abstract Returns the Contact's PGP Key
436                        @author Raphael Derosso Pereira
437               
438                */
439                function get_pgp_key (  )
440                {
441                        return $this->main_fields['pgp_key']['value'];
442                }
443       
444                /*!
445               
446                        @function get_notes
447                        @abstract Returns the Contact's notes
448                        @author Raphael Derosso Pereira
449               
450                */
451                function get_notes (  )
452                {
453                        return $this->main_fields['notes']['value'];
454                }
455       
456                /*!
457               
458                        @function get_status
459                        @abstract Returns the Contact's status ID
460                        @author Raphael Derosso Pereira
461
462                */
463                function get_status (  )
464                {
465                        return $this->main_fields['status']['value'];
466                }
467       
468                /*!
469               
470                        @function get_relations
471                        @abstract Returns the Contact's Relations
472                        @author Raphael Derosso Pereira
473               
474                        @return array Format:
475                                $return = array(
476                                        '<id_related1>' => '<id_relation1_type>',
477                                        '<id_related2>' => '<id_relation2_type>',
478                                        ...);
479                */
480                function get_relations (  )
481                {
482                        $return = array();
483                       
484                        reset($this->relations['id_related']['values']);
485                        reset($this->relations['id_typeof_contact_relation']['values']);
486                        while(list(,$id_related) = each($this->relations['id_related']['values']) and
487                                list(,$id_relation_type) = each($this->relations['id_typeof_contact_relation']['values']))
488                        {
489                                $return[$id_related] = $id_relation_type;                               
490                        }
491                       
492                        return $return;
493                }
494       
495                /*!
496               
497                        @function get_addresses
498                        @abstract Returns the Contact's Addresses
499                        @author Raphael Derosso Pereira
500               
501                        @return array Format:
502                                $return = array(
503                                        '<id_address1>' => '<id_address1_type>',
504                                        '<id_address2>' => '<id_address2_type>',
505                                        ...);
506                */
507                function get_addresses (  )
508                {
509                        $return = array();
510                       
511                        reset($this->addresses['id_address']['values']);
512                        reset($this->addresses['id_typeof_contact_address']['values']);
513                        while(list(,$id_address) = each($this->addresses['id_address']['values']) and
514                                list(,$id_address_type) = each($this->addresses['id_typeof_contact_address']['values']))
515                        {
516                                $return[$id_address] = $id_address_type;                               
517                        }
518                       
519                        return $return;
520                }
521       
522                /*!
523               
524                        @function get_connections
525                        @abstract Returns the Contact's Connections
526                        @author Raphael Derosso Pereira
527               
528                        @return array Format:
529                                $return = array(
530                                        '<id_connection1>' => '<id_connection1_type>',
531                                        '<id_connection2>' => '<id_connection2_type>',
532                                        ...);
533                */
534                function get_connections (  )
535                {
536                        $return = array();
537                       
538                        reset($this->connections['id_connection']['values']);
539                        reset($this->connections['id_typeof_contact_connection']['values']);
540                        while(list(,$id_connection) = each($this->connections['id_connection']['values']) and
541                                list(,$id_connection_type) = each($this->connections['id_typeof_contact_connection']['values']))
542                        {
543                                $return[$id_connection] = $id_connection_type;                         
544                        }
545                       
546                        return $return;
547                }
548       
549                /*!
550               
551                        @function get_companies
552                        @abstract Returns the Contact's Companies IDs and
553                                bussiness info
554                        @author Raphael Derosso Pereira
555               
556                        @return array Format:
557                                $return = array(
558                                        '<id_company1>' => array(
559                                                'title'                 => '<title>',
560                                                'department'    => '<department>'
561                                        ),
562                                        '<id_company2>' => array(
563                                                'title'                 => '<title>',
564                                                'department'    => '<department>'
565                                        ),
566                                        ...
567                                );
568                               
569                */
570                function get_companies (  )
571                {
572                        $return = array();
573                       
574                        reset($this->companies['id_company']['values']);
575                        reset($this->companies['title']['values']);
576                        reset($this->companies['department']['values']);
577                        reset($this->companies['default_company']['values']);
578                        reset($this->companies['default_contact']['values']);
579                        while(list(,$id_company) = each($this->companies['id_company']['values']) and
580                                list(,$title) = each($this->companies['title']['values']) and
581                                list(,$department) = each($this->companies['department']['values']) and
582                                list(,$default_company) = each($this->companies['default_company']['values']) and
583                                list(,$default_contact) = each($this->companies['default_contact']['values']))
584                        {
585                                $return[$id_company] = array(
586                                        'title'           => $title,
587                                        'department'      => $department,
588                                        'default_company' => $default_company,
589                                        'default_contact' => $default_contact,
590                                );
591                        }
592                       
593                        return $return;
594                }
595       
596                /*********************************************************************\
597                 *                   Methods to Alter Data                           *
598                \*********************************************************************/
599
600       
601                /*!
602               
603                        @function set_photo
604                        @abstract Sets the Contact's Photo binary string
605                        @author Raphael Derosso Pereira
606                        @param string $photo The binary photo string
607               
608                */
609                function set_photo ( $photo )
610                {
611                        $this->main_fields['photo']['value'] = $photo;
612                        $this->manage_fields($this->main_fields['photo'], 'changed');
613                }
614       
615                /*!
616               
617                        @function set_alias
618                        @abstract Sets the Contact's Alias
619                        @author Raphael Derosso Pereira
620                        @param string $alias The new Contact alias
621               
622                */
623                function set_alias ( $alias )
624                {
625                        $this->main_fields['alias']['value'] = $alias;
626                        $this->manage_fields($this->main_fields['alias'], 'changed');
627                }
628       
629                /*!
630               
631                        @function set_id_prefix
632                        @abstract Sets the Contact's Prefix
633                        @author Raphael Derosso Pereira
634                        @param string $id_prefix The new Contact prefix ID
635               
636                */
637                function set_id_prefix ( $id_prefix )
638                {
639                        $this->main_fields['prefix']['value'] = $id_prefix;
640                        $this->manage_fields($this->main_fields['prefix'], 'changed');
641                }
642       
643                /*!
644               
645                        @function set_given_names
646                        @abstract Sets the Contact's Given Names
647                        @author Raphael Derosso Pereira
648                        @param string $names The new Contact's Given Names
649               
650                */
651                function set_given_names ( $names )
652                {
653                        $this->main_fields['given_names']['value'] = $names;
654                        $this->manage_fields($this->main_fields['given_names'], 'changed');
655                }
656       
657                /*!
658               
659                        @function set_family_names
660                        @abstract Sets the Contact's Family Names
661                        @author Raphael Derosso Pereira
662                        @param string $names The new Contact's Family Names
663               
664                */
665                function set_family_names ( $names )
666                {
667                        $this->main_fields['family_names']['value'] = $names;
668                        $this->manage_fields($this->main_fields['family_names'], 'changed');
669                }
670       
671                /*!
672               
673                        @function set_names_ordered
674                        @abstract Sets the Contact's Names Ordered
675                        @author Raphael Derosso Pereira
676                        @param string $names The new Contact's Names Ordered
677               
678                */
679                function set_names_ordered ( $names )
680                {
681                        $this->main_fields['names_ordered']['value'] = $names;
682                        $this->manage_fields($this->main_fields['names_ordered'], 'changed');
683                }
684       
685                /*!
686               
687                        @function set_id_suffix
688                        @abstract Sets the Contact's Sulfix
689                        @author Raphael Derosso Pereira
690                        @param string $id_suffix The new Contact's Sulfix
691               
692                */
693                function set_id_suffix ( $id_suffix )
694                {
695                        $this->main_fields['suffix']['value'] = $names;
696                        $this->manage_fields($this->main_fields['suffix'], 'changed');
697                }
698       
699                /*!
700               
701                        @function set_birthdate
702                        @abstract Sets the Contact's Birthdate
703                        @author Raphael Derosso Pereira
704                        @param string $date The new Contact's Birthdate
705               
706                */
707                function set_birthdate ( $date )
708                {
709                        $this->main_fields['birthdate']['value'] = $names;
710                        $this->manage_fields($this->main_fields['birthdate'], 'changed');
711                }
712       
713                /*!
714               
715                        @function set_sex
716                        @abstract Sets the Contact's Sex
717                        @author Raphael Derosso Pereira
718                        @param string $sex The new Contact's Sex
719               
720                */
721                function set_sex ( $sex )
722                {
723                        $this->main_fields['birthdate']['value'] = $names;
724                        $this->manage_fields($this->main_fields['birthdate'], 'changed');
725                }
726       
727                /*!
728               
729                        @function set_pgp_key
730                        @abstract Sets the Contact's PGP Key
731                        @author Raphael Derosso Pereira
732                        @param string $pgp_key The new Contact's PGP Key
733               
734                */
735                function set_pgp_key ( $pgp_key )
736                {
737                        $this->main_fields['birthdate']['value'] = $names;
738                        $this->manage_fields($this->main_fields['birthdate'], 'changed');
739                }
740       
741                /*!
742               
743                        @function set_notes
744                        @abstract Sets the Contact's Notes
745                        @author Raphael Derosso Pereira
746                        @param string $notes The new Contact's Notes
747               
748                */
749                function set_notes ( $notes )
750                {
751                        $this->main_fields['birthdate']['value'] = $names;
752                        $this->manage_fields($this->main_fields['birthdate'], 'changed');
753                }
754       
755                /*!
756               
757                        @function set_status
758                        @abstract Change the Contact's set Status
759                        @author Raphael Derosso Pereira
760                        @param integer $id_status The new Contact's set Status
761               
762                */
763                function set_id_status ( $id_status )
764                {
765                        $this->main_fields['id_status']['value'] = $names;
766                        $this->manage_fields($this->main_fields['id_status'], 'changed');
767                }
768       
769                /*!
770               
771                        @function set_relation
772                        @abstract Sets the Contact's Relation
773                        @author Raphael Derosso Pereira
774                        @param integer $id_related The new Contact's Relation type ID
775                        @param integer $id_type The new Contact's Relation ID
776               
777                */
778                function set_relation ( $id_related, $id_type )
779                {
780                        if (($pos = array_search($id_related, $this->relations['id_related']['values'])) !== false)
781                        {
782                                $this->relations['id_typeof_contact_relation']['values'][$pos] = $id_type;
783                                $this->manage_fields($this->relations['id_typeof_contact_relation'], 'changed', $pos);
784                               
785                                return;
786                        }
787                       
788                        array_push($this->relations['id_contact']['values'], & $this->id);
789                        array_push($this->relations['id_related']['values'], $id_related);
790                        array_push($this->relations['id_typeof_contact_relation']['values'], $id_type);
791                       
792                        $this->manage_fields($this->relations['id_typeof_contact_relation'], 'new', 'new');
793                        $this->manage_fields($this->relations['id_related'], 'new', 'new');
794                        $this->manage_fields($this->relations['id_contact'], 'new', 'new');
795                }
796       
797                /*!
798               
799                        @function set_address
800                        @abstract Sets the Contact's Address
801                        @author Raphael Derosso Pereira
802                        @param integer $id_address The new Contact's Address ID
803                        @param integer $id_type The new Contact's Address type ID
804               
805                */
806                function set_address ( $id_address, $id_type )
807                {
808                        if (($pos = array_search($id_address, $this->addresses['id_address']['values'])) !== false)
809                        {
810                                $this->addresses['id_typeof_contact_address']['values'][$pos] = $id_type;
811                                $this->manage_fields($this->addresses['id_typeof_contact_address'], 'changed', $pos);
812                               
813                                return;
814                        }
815                       
816                        array_push($this->addresses['id_contact']['values'], & $this->id);
817                        array_push($this->addresses['id_address']['values'], $id_address);
818                        array_push($this->addresses['id_typeof_contact_address']['values'], $id_type);
819                       
820                        $this->manage_fields($this->addresses['id_typeof_contact_address'], 'new', 'new');
821                        $this->manage_fields($this->addresses['id_address'], 'new', 'new');
822                        $this->manage_fields($this->addresses['id_contact'], 'new', 'new');
823                }
824       
825                /*!
826               
827                        @function set_connection
828                        @abstract Sets the Contact's Connection
829                        @author Raphael Derosso Pereira
830                        @param integer $id_connection The new Contact's Connection ID
831                        @param integer $id_type The new Contact's Connection type ID
832               
833                */
834                function set_connection ( $id_connection, $id_type )
835                {
836                        if (($pos = array_search($id_connection, $this->connections['id_connection']['values'])) !== false)
837                        {
838                                $this->connections['id_typeof_contact_connection']['values'][$pos] = $id_type;
839                                $this->manage_fields($this->connections['id_typeof_contact_connection'], 'changed', $pos);
840                               
841                                return;
842                        }
843                       
844                        array_push($this->connections['id_contact']['values'], & $this->id);
845                        array_push($this->connections['id_connection']['values'], $id_connection);
846                        array_push($this->connections['id_typeof_contact_connection']['values'], $id_type);
847                       
848                        $this->manage_fields($this->connections['id_typeof_contact_connection'], 'new', 'new');
849                        $this->manage_fields($this->connections['id_connection'], 'new', 'new');
850                        $this->manage_fields($this->connections['id_contact'], 'new', 'new');
851                }
852       
853                /*!
854               
855                        @function set_company
856                        @abstract Sets the Contact's Company and bussiness information
857                        @author Raphael Derosso Pereira
858                        @param array $company_info The new Contact's Company Information
859               
860                */
861                function set_company ( $company_info )
862                {
863                        if (is_array($company_info))
864                        {
865                                if (($pos = array_search($company_info['id_company'], $this->companies['id_company']['values'])) !== false)
866                                {
867                                        $this->companies['title']['values'][$pos] = $company_info['title'];
868                                        $this->companies['department']['values'][$pos] = $company_info['department'];
869                                        $this->companies['default_company']['values'][$pos] = $company_info['default_company'];
870                                        $this->companies['default_contact']['values'][$pos] = $company_info['default_contact'];
871                                       
872                                        $this->manage_fields($this->companies['title'], 'changed', $pos);
873                                        $this->manage_fields($this->companies['department'], 'changed', $pos);
874                                        $this->manage_fields($this->companies['default_company'], 'changed', $pos);
875                                        $this->manage_fields($this->companies['default_contact'], 'changed', $pos);
876                                       
877                                        return true;
878                                }
879                               
880                                array_push($this->companies['id_contact']['values'], & $this->id);
881                                array_push($this->companies['id_company']['values'], $company_info['id_company']);
882                                array_push($this->companies['title']['values'], $company_info['title']);
883                                array_push($this->companies['department']['values'], $company_info['department']);
884                                array_push($this->companies['default_company']['values'], $company_info['default_company']);
885                                array_push($this->companies['default_contact']['values'], $company_info['default_contact']);
886                               
887                                $this->manage_fields($this->companies['id_company'], 'new', 'new');
888                                $this->manage_fields($this->companies['id_contact'], 'new', 'new');
889                                $this->manage_fields($this->companies['title'], 'new', 'new');
890                                $this->manage_fields($this->companies['department'], 'new', 'new');
891                                $this->manage_fields($this->companies['default_company'], 'new', 'new');
892                                $this->manage_fields($this->companies['default_contact'], 'new', 'new');
893                               
894                                return true;
895                        }
896                       
897                        return false;
898                }
899
900
901                /*********************************************************************\
902                 *                   Methods to Remove Data                          *
903                \*********************************************************************/
904
905
906                /*!
907               
908                        @function remove_relation
909                        @abstract Remove one Contact's Relation
910                        @author Raphael Derosso Pereira
911                        @param integer $id_related The ID of the relation to be removed
912               
913                */
914                function remove_relation ( $id_related )
915                {
916                        if (($pos = array_search($id_related, $this->relations['id_related']['values'])) !== false)
917                        {
918                                $this->manage_fields($this->relations['id_contact'], 'deleted', $pos);
919                                $this->manage_fields($this->relations['id_related'], 'deleted', $pos);
920                                $this->manage_fields($this->relations['id_typeof_contact_relation'], 'deleted', $pos);
921                               
922                                return true;
923                        }
924                       
925                        return false;
926                }
927       
928                /*!
929               
930                        @function remove_address
931                        @abstract Remove one Contact's Address
932                        @author Raphael Derosso Pereira
933                        @param integer $id_address The ID of the address to be removed
934               
935                */
936                function remove_address ( $id_address )
937                {
938                        if (($pos = array_search($id_address, $this->addresses['id_address']['values'])) !== false)
939                        {
940                                $this->manage_fields($this->addresses['id_contact'], 'deleted', $pos);
941                                $this->manage_fields($this->addresses['id_address'], 'deleted', $pos);
942                                $this->manage_fields($this->addresses['id_typeof_contact_address'], 'deleted', $pos);
943                               
944                                return true;
945                        }
946                       
947                        return false;
948                }
949       
950                /*!
951               
952                        @function remove_connection
953                        @abstract Remove one Contact's Connection
954                        @author Raphael Derosso Pereira
955                        @param integer $id_connection The ID of the connection to be removed
956               
957                */
958                function remove_connection ( $id_connection )
959                {
960                        if (($pos = array_search($id_connection, $this->connections['id_connection']['values'])) !== false)
961                        {
962                                $this->manage_fields($this->connections['id_contact'], 'deleted', $pos);
963                                $this->manage_fields($this->connections['id_connection'], 'deleted', $pos);
964                                $this->manage_fields($this->connections['id_typeof_contact_connection'], 'deleted', $pos);
965                               
966                                return true;
967                        }
968                       
969                        return false;
970                }
971       
972                /*!
973               
974                        @function remove_company
975                        @abstract Remove one Contact's Company
976                        @author Raphael Derosso Pereira
977                        @param integer $id_company The ID of the compay to be removed
978               
979                */
980                function remove_company ( $id_company )
981                {
982                        if (($pos = array_search($id_company, $this->companies['id_company']['values'])) !== false)
983                        {
984                                $this->manage_fields($this->companies['id_contact'], 'deleted', $pos);
985                                $this->manage_fields($this->companies['id_company'], 'deleted', $pos);
986                                $this->manage_fields($this->companies['title'], 'deleted', $pos);
987                                $this->manage_fields($this->companies['department'], 'deleted', $pos);
988                               
989                                return true;
990                        }
991                       
992                        return false;
993                }
994               
995        }
996?>
Note: See TracBrowser for help on using the repository browser.