]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/SugarObjects/templates/person/Person.php
Release 6.5.0
[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-2012 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 require_once('include/SugarObjects/templates/basic/Basic.php');
39
40 class Person extends Basic
41 {
42     var $picture;
43     /**
44      * @var bool controls whether or not to invoke the getLocalFormatttedName method with title and salutation
45      */
46     var $createLocaleFormattedName = true;
47     
48         public function Person()
49         {
50                 parent::Basic();
51                 $this->emailAddress = new SugarEmailAddress();
52         }
53
54         /**
55          * need to override to have a name field created for this class
56          *
57          * @see parent::retrieve()
58          */
59     public function retrieve($id = -1, $encode=true, $deleted=true) {
60                 $ret_val = parent::retrieve($id, $encode, $deleted);
61                 $this->_create_proper_name_field();
62                 return $ret_val;
63         }
64
65         /**
66          * Populate email address fields here instead of retrieve() so that they are properly available for logic hooks
67          *
68          * @see parent::fill_in_relationship_fields()
69          */
70         public function fill_in_relationship_fields()
71         {
72             parent::fill_in_relationship_fields();
73             $this->emailAddress->handleLegacyRetrieve($this);
74         }
75
76         /**
77      * This function helps generate the name and full_name member field variables from the salutation, title, first_name and last_name fields.
78      * It takes into account the locale format settings as well as ACL settings if supported.
79          */
80         public function _create_proper_name_field()
81         {
82                 global $locale, $app_list_strings;
83
84         // Bug# 46125 - make first name, last name, salutation and title of Contacts respect field level ACLs
85         $first_name = ""; $last_name = ""; $salutation = ""; $title = "";
86
87            // first name has at least read access
88            $first_name = $this->first_name;
89
90             // last name has at least read access
91             $last_name = $this->last_name;
92
93
94             // salutation has at least read access
95             if(isset($this->field_defs['salutation']['options'])
96                           && isset($app_list_strings[$this->field_defs['salutation']['options']])
97                           && isset($app_list_strings[$this->field_defs['salutation']['options']][$this->salutation]) ) {
98
99                                 $salutation = $app_list_strings[$this->field_defs['salutation']['options']][$this->salutation];
100                         } // if
101
102             // last name has at least read access
103             $title = $this->title;
104
105         // Corner Case:
106         // Both first name and last name cannot be empty, at least one must be shown
107         // In that case, we can ignore field level ACL and just display last name...
108         // In the ACL field level access settings, last_name cannot be set to "none"
109         if (empty($first_name) && empty($last_name)) {
110             $full_name = $locale->getLocaleFormattedName("", $last_name, $salutation, $title);
111         } else {
112                         if($this->createLocaleFormattedName) {
113                                 $full_name = $locale->getLocaleFormattedName($first_name, $last_name, $salutation, $title);
114                         } else {
115                                 $full_name = $locale->getLocaleFormattedName($first_name, $last_name);
116                         }
117                 }
118
119                 $this->name = $full_name;
120                 $this->full_name = $full_name; //used by campaigns
121         }
122         
123
124         /**
125          * @see parent::save()
126          */
127         public function save($check_notify=false) 
128         {
129                 //If we are saving due to relationship changes, don't bother trying to update the emails
130         if(!empty($GLOBALS['resavingRelatedBeans']))
131         {
132             parent::save($check_notify);
133             return $this->id;
134         }
135         $this->add_address_streets('primary_address_street');
136         $this->add_address_streets('alt_address_street');
137         $ori_in_workflow = empty($this->in_workflow) ? false : true;
138         $this->emailAddress->handleLegacySave($this, $this->module_dir);
139         parent::save($check_notify);
140         $override_email = array();
141         if(!empty($this->email1_set_in_workflow)) {
142             $override_email['emailAddress0'] = $this->email1_set_in_workflow;
143         }
144         if(!empty($this->email2_set_in_workflow)) {
145             $override_email['emailAddress1'] = $this->email2_set_in_workflow;
146         }
147         if(!isset($this->in_workflow)) {
148             $this->in_workflow = false;
149         }
150         if($ori_in_workflow === false || !empty($override_email)){
151             $this->emailAddress->save($this->id, $this->module_dir, $override_email,'','','','',$this->in_workflow);
152         }
153                 return $this->id;
154         }
155
156         /**
157          * @see parent::get_summary_text()
158          */
159         public function get_summary_text() 
160         {
161                 $this->_create_proper_name_field();
162         return $this->name;
163         }
164
165         /**
166          * @see parent::get_list_view_data()
167          */
168         public function get_list_view_data() 
169         {
170                 global $system_config;
171                 global $current_user;
172                 $this->_create_proper_name_field();
173                 $temp_array = $this->get_list_view_array();
174                 $temp_array['NAME'] = $this->name;
175                 $temp_array['EMAIL1'] = $this->emailAddress->getPrimaryAddress($this);
176                 $this->email1 = $temp_array['EMAIL1'];
177                 $temp_array['EMAIL1_LINK'] = $current_user->getEmailLink('email1', $this, '', '', 'ListView');
178                 return $temp_array;
179         }
180
181     /**
182      * @see SugarBean::populateRelatedBean()
183          */
184     public function populateRelatedBean(
185         SugarBean $newbean
186         )
187     {
188         parent::populateRelatedBean($newbean);
189
190         if ( $newbean instanceOf Company ) {
191             $newbean->phone_fax = $this->phone_fax;
192             $newbean->phone_office = $this->phone_work;
193             $newbean->phone_alternate = $this->phone_other;
194             $newbean->email1 = $this->email1;
195             $this->add_address_streets('primary_address_street');
196             $newbean->billing_address_street = $this->primary_address_street;
197             $newbean->billing_address_city = $this->primary_address_city;
198             $newbean->billing_address_state = $this->primary_address_state;
199             $newbean->billing_address_postalcode = $this->primary_address_postalcode;
200             $newbean->billing_address_country = $this->primary_address_country;
201             $this->add_address_streets('alt_address_street');
202             $newbean->shipping_address_street = $this->alt_address_street;
203             $newbean->shipping_address_city = $this->alt_address_city;
204             $newbean->shipping_address_state = $this->alt_address_state;
205             $newbean->shipping_address_postalcode = $this->alt_address_postalcode;
206             $newbean->shipping_address_country = $this->alt_address_country;
207         }
208     }
209 }