2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4 * SugarCRM is a customer relationship management program developed by
5 * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
7 * This program is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU Affero General Public License version 3 as published by the
9 * Free Software Foundation with the addition of the following permission added
10 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
11 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
12 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
19 * You should have received a copy of the GNU Affero General Public License along with
20 * this program; if not, see http://www.gnu.org/licenses or write to the Free
21 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
25 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
27 * The interactive user interfaces in modified source and object code versions
28 * of this program must display Appropriate Legal Notices, as required under
29 * Section 5 of the GNU Affero General Public License version 3.
31 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
32 * these Appropriate Legal Notices must retain the display of the "Powered by
33 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
34 * technical reasons, the Appropriate Legal Notices must display the words
35 * "Powered by SugarCRM".
36 ********************************************************************************/
38 /*********************************************************************************
40 * Description: Defines the Account SugarBean Account entity with the necessary
41 * methods and variables.
42 ********************************************************************************/
44 require_once("include/SugarObjects/templates/company/Company.php");
46 // Account is used to store account information.
47 class Account extends Company {
48 var $field_name_map = array();
52 var $modified_user_id;
53 var $assigned_user_id;
55 var $billing_address_street;
56 var $billing_address_city;
57 var $billing_address_state;
58 var $billing_address_country;
59 var $billing_address_postalcode;
61 var $billing_address_street_2;
62 var $billing_address_street_3;
63 var $billing_address_street_4;
80 var $shipping_address_street;
81 var $shipping_address_city;
82 var $shipping_address_state;
83 var $shipping_address_country;
84 var $shipping_address_postalcode;
86 var $shipping_address_street_2;
87 var $shipping_address_street_3;
88 var $shipping_address_street_4;
98 var $modified_by_name;
100 // These are for related fields
111 var $assigned_user_name;
112 var $account_id = '';
113 var $account_name = '';
115 var $module_dir = 'Accounts';
119 var $table_name = "accounts";
120 var $object_name = "Account";
121 var $importable = true;
122 var $new_schema = true;
123 // This is used to retrieve related fields from form posts.
124 var $additional_column_fields = Array('assigned_user_name', 'assigned_user_id', 'opportunity_id', 'bug_id', 'case_id', 'contact_id', 'task_id', 'note_id', 'meeting_id', 'call_id', 'email_id', 'parent_name', 'member_id'
126 var $relationship_fields = Array('opportunity_id'=>'opportunities', 'bug_id' => 'bugs', 'case_id'=>'cases',
127 'contact_id'=>'contacts', 'task_id'=>'tasks', 'note_id'=>'notes',
128 'meeting_id'=>'meetings', 'call_id'=>'calls', 'email_id'=>'emails','member_id'=>'members',
129 'project_id'=>'project',
132 //Meta-Data Framework fields
139 $this->setupCustomFields('Accounts');
141 foreach ($this->field_defs as $field) {
142 $this->field_name_map[$field['name']] = $field;
146 //Combine the email logic original here with bug #26450.
147 if( (!empty($_REQUEST['parent_id']) && !empty($_REQUEST['parent_type']) && $_REQUEST['parent_type'] == 'Emails'
148 && !empty($_REQUEST['return_module']) && $_REQUEST['return_module'] == 'Emails' )
150 (!empty($_REQUEST['parent_type']) && $_REQUEST['parent_type'] != 'Accounts' &&
151 !empty($_REQUEST['return_module']) && $_REQUEST['return_module'] != 'Accounts') ){
152 $_REQUEST['parent_name'] = '';
153 $_REQUEST['parent_id'] = '';
157 function get_summary_text()
162 function get_contacts() {
163 return $this->get_linked_beans('contacts','Contact');
168 function clear_account_case_relationship($account_id='', $case_id='')
170 if (empty($case_id)) $where = '';
171 else $where = " and id = '$case_id'";
172 $query = "UPDATE cases SET account_name = '', account_id = '' WHERE account_id = '$account_id' AND deleted = 0 " . $where;
173 $this->db->query($query,true,"Error clearing account to case relationship: ");
177 * This method is used to provide backward compatibility with old data that was prefixed with http://
178 * We now automatically prefix http://
181 function remove_redundant_http()
183 if(preg_match("@http://@", $this->website))
185 $this->website = substr($this->website, 7);
190 function fill_in_additional_list_fields()
192 parent::fill_in_additional_list_fields();
193 // Fill in the assigned_user_name
194 // $this->assigned_user_name = get_assigned_user_name($this->assigned_user_id);
198 function fill_in_additional_detail_fields()
200 parent::fill_in_additional_detail_fields();
202 //rrs bug: 28184 - instead of removing this code altogether just adding this check to ensure that if the parent_name
203 //is empty then go ahead and fill it.
204 if(empty($this->parent_name)){
205 $query = "SELECT a1.name from accounts a1, accounts a2 where a1.id = a2.parent_id and a2.id = '$this->id' and a1.deleted=0";
206 $result = $this->db->query($query,true," Error filling in additional detail fields: ");
208 // Get the id and the name.
209 $row = $this->db->fetchByAssoc($result);
213 $this->parent_name = $row['name'];
217 $this->parent_name = '';
222 function get_list_view_data(){
223 global $system_config,$current_user;
224 $temp_array = $this->get_list_view_array();
225 $temp_array["ENCODED_NAME"]=$this->name;
226 // $temp_array["ENCODED_NAME"]=htmlspecialchars($this->name, ENT_QUOTES);
227 if(!empty($this->billing_address_state))
229 $temp_array["CITY"] = $this->billing_address_city . ', '. $this->billing_address_state;
233 $temp_array["CITY"] = $this->billing_address_city;
235 $temp_array["BILLING_ADDRESS_STREET"] = preg_replace("/[\r]/",'',$this->billing_address_street);
236 $temp_array["SHIPPING_ADDRESS_STREET"] = preg_replace("/[\r]/",'',$this->shipping_address_street);
237 $temp_array["BILLING_ADDRESS_STREET"] = preg_replace("/[\n]/",'\n',$temp_array["BILLING_ADDRESS_STREET"] );
238 $temp_array["SHIPPING_ADDRESS_STREET"] = preg_replace("/[\n]/",'\n',$temp_array["SHIPPING_ADDRESS_STREET"] );
239 if(isset($system_config->settings['system_skypeout_on']) && $system_config->settings['system_skypeout_on'] == 1){
240 if(!empty($temp_array['PHONE_OFFICE']) && skype_formatted($temp_array['PHONE_OFFICE'])){
241 $temp_array['PHONE_OFFICE'] = '<a href="callto://' . $temp_array['PHONE_OFFICE']. '">'.$temp_array['PHONE_OFFICE']. '</a>' ;
243 $temp_array["EMAIL1"] = $this->emailAddress->getPrimaryAddress($this);
244 $this->email1 = $temp_array['EMAIL1'];
245 $temp_array["EMAIL1_LINK"] = $current_user->getEmailLink('email1', $this, '', '', 'ListView');
249 builds a generic search based on the query string using or
250 do not include any $this-> because this is called on without having the class instantiated
252 function build_generic_where_clause ($the_query_string) {
253 $where_clauses = Array();
254 $the_query_string = $this->db->quote($the_query_string);
255 array_push($where_clauses, "accounts.name like '$the_query_string%'");
256 if (is_numeric($the_query_string)) {
257 array_push($where_clauses, "accounts.phone_alternate like '%$the_query_string%'");
258 array_push($where_clauses, "accounts.phone_fax like '%$the_query_string%'");
259 array_push($where_clauses, "accounts.phone_office like '%$the_query_string%'");
263 foreach($where_clauses as $clause)
265 if(!empty($the_where)) $the_where .= " or ";
266 $the_where .= $clause;
273 function create_export_query(&$order_by, &$where, $relate_link_join='')
275 $custom_join = $this->custom_fields->getJOIN(true, true,$where);
277 $custom_join['join'] .= $relate_link_join;
279 accounts.*,email_addresses.email_address email1,
280 accounts.name as account_name,
281 users.user_name as assigned_user_name ";
283 $query .= $custom_join['select'];
285 $query .= " FROM accounts ";
286 $query .= "LEFT JOIN users
287 ON accounts.assigned_user_id=users.id ";
289 //join email address table too.
290 $query .= ' LEFT JOIN email_addr_bean_rel on accounts.id = email_addr_bean_rel.bean_id and email_addr_bean_rel.bean_module=\'Accounts\' and email_addr_bean_rel.deleted=0 and email_addr_bean_rel.primary_address=1 ';
291 $query .= ' LEFT JOIN email_addresses on email_addresses.id = email_addr_bean_rel.email_address_id ' ;
294 $query .= $custom_join['join'];
297 $where_auto = "( accounts.deleted IS NULL OR accounts.deleted=0 )";
300 $query .= "where ($where) AND ".$where_auto;
302 $query .= "where ".$where_auto;
304 if(!empty($order_by))
305 $query .= " ORDER BY ". $this->process_order_by($order_by, null);
310 function set_notification_body($xtpl, $account)
312 $xtpl->assign("ACCOUNT_NAME", $account->name);
313 $xtpl->assign("ACCOUNT_TYPE", $account->account_type);
314 $xtpl->assign("ACCOUNT_DESCRIPTION", $account->description);
319 function bean_implements($interface){
321 case 'ACL':return true;
325 function get_unlinked_email_query($type=array()) {
327 return get_unlinked_email_query($type, $this);