2 /*********************************************************************************
3 * SugarCRM Community Edition is a customer relationship management program developed by
4 * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
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.
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
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
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.
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.
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 ********************************************************************************/
39 require_once('include/SugarObjects/templates/basic/Basic.php');
42 class Person extends Basic
45 //Variable to control whether or not to invoke the getLocalFormatttedName method with title and salutation
46 var $createLocaleFormattedName = true;
50 $this->emailAddress = new SugarEmailAddress();
53 // need to override to have a name field created for this class
54 function retrieve($id = -1, $encode=true) {
55 $ret_val = parent::retrieve($id, $encode);
56 $this->_create_proper_name_field();
57 $this->emailAddress->handleLegacyRetrieve($this);
62 * Generate the name field from the first_name and last_name fields.
64 function _create_proper_name_field()
66 global $locale, $app_list_strings;
68 // Bug# 46125 - make first name, last name, salutation and title of Contacts respect field level ACLs
69 $first_name = ""; $last_name = ""; $salutation = ""; $title = "";
71 // first name has at least read access
72 $first_name = $this->first_name;
74 // last name has at least read access
75 $last_name = $this->last_name;
78 // salutation has at least read access
79 if(isset($this->field_defs['salutation']['options'])
80 && isset($app_list_strings[$this->field_defs['salutation']['options']])
81 && isset($app_list_strings[$this->field_defs['salutation']['options']][$this->salutation]) ) {
83 $salutation = $app_list_strings[$this->field_defs['salutation']['options']][$this->salutation];
86 // last name has at least read access
87 $title = $this->title;
90 // Both first name and last name cannot be empty, at least one must be shown
91 // In that case, we can ignore field level ACL and just display last name...
92 // In the ACL field level access settings, last_name cannot be set to "none"
93 if (empty($first_name) && empty($last_name)) {
94 $full_name = $locale->getLocaleFormattedName("", $last_name, $salutation, $title);
96 if($this->createLocaleFormattedName) {
97 $full_name = $locale->getLocaleFormattedName($first_name, $last_name, $salutation, $title);
99 $full_name = $locale->getLocaleFormattedName($first_name, $last_name);
103 $this->name = $full_name;
104 $this->full_name = $full_name; //used by campaigns
107 function save($check_notify=false) {
108 $this->add_address_streets('primary_address_street');
109 $this->add_address_streets('alt_address_street');
110 $ori_in_workflow = empty($this->in_workflow) ? false : true;
111 $this->emailAddress->handleLegacySave($this, $this->module_dir);
112 parent::save($check_notify);
113 $override_email = array();
114 if(!empty($this->email1_set_in_workflow)) {
115 $override_email['emailAddress0'] = $this->email1_set_in_workflow;
117 if(!empty($this->email2_set_in_workflow)) {
118 $override_email['emailAddress1'] = $this->email2_set_in_workflow;
120 if(!isset($this->in_workflow)) {
121 $this->in_workflow = false;
123 if($ori_in_workflow === false || !empty($override_email)){
124 $this->emailAddress->save($this->id, $this->module_dir, $override_email,'','','','',$this->in_workflow);
129 function get_summary_text() {
130 $this->_create_proper_name_field();
134 function get_list_view_data() {
136 global $system_config;
137 global $current_user;
138 $this->_create_proper_name_field();
139 $temp_array = $this->get_list_view_array();
140 $temp_array['NAME'] = $this->name;
141 $temp_array['EMAIL1'] = $this->emailAddress->getPrimaryAddress($this);
142 $this->email1 = $temp_array['EMAIL1'];
143 $temp_array['EMAIL1_LINK'] = $current_user->getEmailLink('email1', $this, '', '', 'ListView');
148 * @see SugarBean::populateRelatedBean()
150 public function populateRelatedBean(
154 parent::populateRelatedBean($newbean);
156 if ( $newbean instanceOf Company ) {
157 $newbean->phone_fax = $this->phone_fax;
158 $newbean->phone_office = $this->phone_work;
159 $newbean->phone_alternate = $this->phone_other;
160 $newbean->email1 = $this->email1;
161 $this->add_address_streets('primary_address_street');
162 $newbean->billing_address_street = $this->primary_address_street;
163 $newbean->billing_address_city = $this->primary_address_city;
164 $newbean->billing_address_state = $this->primary_address_state;
165 $newbean->billing_address_postalcode = $this->primary_address_postalcode;
166 $newbean->billing_address_country = $this->primary_address_country;
167 $this->add_address_streets('alt_address_street');
168 $newbean->shipping_address_street = $this->alt_address_street;
169 $newbean->shipping_address_city = $this->alt_address_city;
170 $newbean->shipping_address_state = $this->alt_address_state;
171 $newbean->shipping_address_postalcode = $this->alt_address_postalcode;
172 $newbean->shipping_address_country = $this->alt_address_country;