]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/SugarObjects/templates/person/Person.php
Release 6.2.1
[Github/sugarcrm.git] / include / SugarObjects / templates / person / Person.php
1 <?php
2 /*********************************************************************************
3  * SugarCRM Community Edition is a customer relationship management program developed by
4  * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
5  * 
6  * This program is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Affero General Public License version 3 as published by the
8  * Free Software Foundation with the addition of the following permission added
9  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
11  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12  * 
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
16  * details.
17  * 
18  * You should have received a copy of the GNU Affero General Public License along with
19  * this program; if not, see http://www.gnu.org/licenses or write to the Free
20  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  * 02110-1301 USA.
22  * 
23  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
24  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
25  * 
26  * The interactive user interfaces in modified source and object code versions
27  * of this program must display Appropriate Legal Notices, as required under
28  * Section 5 of the GNU Affero General Public License version 3.
29  * 
30  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31  * these Appropriate Legal Notices must retain the display of the "Powered by
32  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
33  * technical reasons, the Appropriate Legal Notices must display the words
34  * "Powered by SugarCRM".
35  ********************************************************************************/
36
37
38
39 require_once('include/SugarObjects/templates/basic/Basic.php');
40
41
42 class Person extends Basic
43 {       
44     var $picture;
45     var $createLocaleFormattedName = true;
46     
47         function Person(){
48                 parent::Basic();
49                 $this->emailAddress = new SugarEmailAddress();
50         }
51         
52         // need to override to have a name field created for this class
53         function retrieve($id = -1, $encode=true) {
54                 $ret_val = parent::retrieve($id, $encode);
55                 $this->_create_proper_name_field();
56                 $this->emailAddress->handleLegacyRetrieve($this);
57                 return $ret_val;
58         }
59         
60         /**
61          * Generate the name field from the first_name and last_name fields.
62          */
63         function _create_proper_name_field() 
64         {
65                 global $locale, $app_list_strings;
66                         if($this->createLocaleFormattedName)
67                         {
68                             // Bug 38648 - If the given saluation doesn't exist in the dropdown, don't display it as part of the full name
69                                 $salutation = '';
70                             if(isset($this->field_defs['salutation']['options']) 
71                                     && isset($app_list_strings[$this->field_defs['salutation']['options']])
72                                     && isset($app_list_strings[$this->field_defs['salutation']['options']][$this->salutation]) ) {
73                                 $salutation = $app_list_strings[$this->field_defs['salutation']['options']][$this->salutation];
74                             }
75                                 $full_name = $locale->getLocaleFormattedName($this->first_name, $this->last_name, $salutation, $this->title);
76                         } else {
77                                 $full_name = $locale->getLocaleFormattedName($this->first_name, $this->last_name);
78                         }
79                 $this->name = $full_name;
80                 $this->full_name = $full_name; //used by campaigns
81         }
82         
83         function save($check_notify=false) {
84                 $this->add_address_streets('primary_address_street');
85                 $this->add_address_streets('alt_address_street');
86         $ori_in_workflow = empty($this->in_workflow) ? false : true;
87                 $this->emailAddress->handleLegacySave($this, $this->module_dir);
88         parent::save($check_notify);
89         $override_email = array();
90         if(!empty($this->email1_set_in_workflow)) {
91             $override_email['emailAddress0'] = $this->email1_set_in_workflow;
92         }
93         if(!empty($this->email2_set_in_workflow)) {
94             $override_email['emailAddress1'] = $this->email2_set_in_workflow;
95         }
96         if(!isset($this->in_workflow)) {
97             $this->in_workflow = false;
98         }
99         if($ori_in_workflow === false || !empty($override_email)){
100             $this->emailAddress->save($this->id, $this->module_dir, $override_email,'','','','',$this->in_workflow);
101         }
102                 return $this->id;
103         }
104         
105         function get_summary_text() {
106                 $this->_create_proper_name_field();
107         return $this->name;
108         }
109         
110         function get_list_view_data() {
111                 
112                 global $system_config;
113                 global $current_user;
114                 $this->_create_proper_name_field();
115                 $temp_array = $this->get_list_view_array();
116                 $temp_array['NAME'] = $this->name;
117                 $temp_array['EMAIL1'] = $this->emailAddress->getPrimaryAddress($this);
118                 $this->email1 = $temp_array['EMAIL1'];
119                 $temp_array['EMAIL1_LINK'] = $current_user->getEmailLink('email1', $this, '', '', 'ListView');
120                 return $temp_array;
121         }
122     
123     /**
124      * @see SugarBean::populateRelatedBean()
125          */
126     public function populateRelatedBean(
127         SugarBean $newbean
128         )
129     {
130         parent::populateRelatedBean($newbean);
131         
132         if ( $newbean instanceOf Company ) {
133             $newbean->phone_fax = $this->phone_fax;
134             $newbean->phone_office = $this->phone_work;
135             $newbean->phone_alternate = $this->phone_other;
136             $newbean->email1 = $this->email1;
137             $this->add_address_streets('primary_address_street');
138             $newbean->billing_address_street = $this->primary_address_street;
139             $newbean->billing_address_city = $this->primary_address_city;
140             $newbean->billing_address_state = $this->primary_address_state;
141             $newbean->billing_address_postalcode = $this->primary_address_postalcode;
142             $newbean->billing_address_country = $this->primary_address_country;
143             $this->add_address_streets('alt_address_street');
144             $newbean->shipping_address_street = $this->alt_address_street;
145             $newbean->shipping_address_city = $this->alt_address_city;
146             $newbean->shipping_address_state = $this->alt_address_state;
147             $newbean->shipping_address_postalcode = $this->alt_address_postalcode;
148             $newbean->shipping_address_country = $this->alt_address_country;
149         }
150     }
151 }
152
153 ?>