Issues (4069)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

modules/Accounts/Account.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2 1
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3
/*********************************************************************************
4
 * SugarCRM Community Edition is a customer relationship management program developed by
5
 * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc.
6
7
 * SuiteCRM is an extension to SugarCRM Community Edition developed by Salesagility Ltd.
8
 * Copyright (C) 2011 - 2014 Salesagility Ltd.
9
 *
10
 * This program is free software; you can redistribute it and/or modify it under
11
 * the terms of the GNU Affero General Public License version 3 as published by the
12
 * Free Software Foundation with the addition of the following permission added
13
 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
14
 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
15
 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
16
 *
17
 * This program is distributed in the hope that it will be useful, but WITHOUT
18
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19
 * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
20
 * details.
21
 *
22
 * You should have received a copy of the GNU Affero General Public License along with
23
 * this program; if not, see http://www.gnu.org/licenses or write to the Free
24
 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25
 * 02110-1301 USA.
26
 *
27
 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
28
 * SW2-130, Cupertino, CA 95014, USA. or at email address [email protected].
29
 *
30
 * The interactive user interfaces in modified source and object code versions
31
 * of this program must display Appropriate Legal Notices, as required under
32
 * Section 5 of the GNU Affero General Public License version 3.
33
 *
34
 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
35
 * these Appropriate Legal Notices must retain the display of the "Powered by
36
 * SugarCRM" logo and "Supercharged by SuiteCRM" logo. If the display of the logos is not
37
 * reasonably feasible for  technical reasons, the Appropriate Legal Notices must
38
 * display the words  "Powered by SugarCRM" and "Supercharged by SuiteCRM".
39
 ********************************************************************************/
40
41
/*********************************************************************************
42
43
 * Description:  Defines the Account SugarBean Account entity with the necessary
44
 * methods and variables.
45
 ********************************************************************************/
46
47 1
require_once("include/SugarObjects/templates/company/Company.php");
48
49
// Account is used to store account information.
50
class Account extends Company {
51
	var $field_name_map = array();
52
	// Stored fields
53
	var $date_entered;
54
	var $date_modified;
55
	var $modified_user_id;
56
	var $assigned_user_id;
57
	var $annual_revenue;
58
	var $billing_address_street;
59
	var $billing_address_city;
60
	var $billing_address_state;
61
	var $billing_address_country;
62
	var $billing_address_postalcode;
63
64
    var $billing_address_street_2;
65
    var $billing_address_street_3;
66
    var $billing_address_street_4;
67
68
	var $description;
69
	var $email1;
70
	var $email2;
71
	var $email_opt_out;
72
	var $invalid_email;
73
	var $employees;
74
	var $id;
75
	var $industry;
76
	var $name;
77
	var $ownership;
78
	var $parent_id;
79
	var $phone_alternate;
80
	var $phone_fax;
81
	var $phone_office;
82
	var $rating;
83
	var $shipping_address_street;
84
	var $shipping_address_city;
85
	var $shipping_address_state;
86
	var $shipping_address_country;
87
	var $shipping_address_postalcode;
88
89
    var $shipping_address_street_2;
90
    var $shipping_address_street_3;
91
    var $shipping_address_street_4;
92
93
    var $campaign_id;
94
95
	var $sic_code;
96
	var $ticker_symbol;
97
	var $account_type;
98
	var $website;
99
	var $custom_fields;
100
101
	var $created_by;
102
	var $created_by_name;
103
	var $modified_by_name;
104
105
	// These are for related fields
106
	var $opportunity_id;
107
	var $case_id;
108
	var $contact_id;
109
	var $task_id;
110
	var $note_id;
111
	var $meeting_id;
112
	var $call_id;
113
	var $email_id;
114
	var $member_id;
115
	var $parent_name;
116
	var $assigned_user_name;
117
	var $account_id = '';
118
	var $account_name = '';
119
	var $bug_id ='';
120
	var $module_dir = 'Accounts';
121
	var $emailAddress;
122
123
124
	var $table_name = "accounts";
125
	var $object_name = "Account";
126
	var $importable = true;
127
	var $new_schema = true;
128
	// This is used to retrieve related fields from form posts.
129
	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'
130
	);
131
	var $relationship_fields = Array('opportunity_id'=>'opportunities', 'bug_id' => 'bugs', 'case_id'=>'cases',
132
									'contact_id'=>'contacts', 'task_id'=>'tasks', 'note_id'=>'notes',
133
									'meeting_id'=>'meetings', 'call_id'=>'calls', 'email_id'=>'emails','member_id'=>'members',
134
									'project_id'=>'project',
135
									);
136
137
    //Meta-Data Framework fields
138
    var $push_billing;
139
    var $push_shipping;
140
141 58
	public function __construct() {
142 58
        parent::__construct();
143
144
145 58
        $this->setupCustomFields('Accounts');
146
147 58
		foreach ($this->field_defs as $field)
148
		{
149 58
			if(isset($field['name']))
150
			{
151 58
				$this->field_name_map[$field['name']] = $field;
152
			}
153
		}
154
155
156
        //Email logic
157 58
		if (!empty($_REQUEST['parent_id']) && !empty($_REQUEST['parent_type']) && $_REQUEST['parent_type'] == 'Emails'
158 58
        	&& !empty($_REQUEST['return_module']) && $_REQUEST['return_module'] == 'Emails') {
159
			$_REQUEST['parent_name'] = '';
160
			$_REQUEST['parent_id'] = '';
161
		}
162 58
	}
163
164
	/**
165
	 * @deprecated deprecated since version 7.6, PHP4 Style Constructors are deprecated and will be remove in 7.8, please update your code, use __construct instead
166
	 */
167
	public function Account(){
168
		$deprecatedMessage = 'PHP4 Style Constructors are deprecated and will be remove in 7.8, please update your code';
169
		if(isset($GLOBALS['log'])) {
170
			$GLOBALS['log']->deprecated($deprecatedMessage);
171
		}
172
		else {
173
			trigger_error($deprecatedMessage, E_USER_DEPRECATED);
174
		}
175
		self::__construct();
176
	}
177
178 1
	function get_summary_text()
179
	{
180 1
		return $this->name;
181
	}
182
183 1
	function get_contacts() {
184 1
		return $this->get_linked_beans('contacts','Contact');
185
	}
186
187
188
189
	function clear_account_case_relationship($account_id='', $case_id='')
190
	{
191
		if (empty($case_id)) $where = '';
192
		else $where = " and id = '$case_id'";
193
		$query = "UPDATE cases SET account_name = '', account_id = '' WHERE account_id = '$account_id' AND deleted = 0 " . $where;
194
		$this->db->query($query,true,"Error clearing account to case relationship: ");
195
	}
196
197
	/**
198
	* This method is used to provide backward compatibility with old data that was prefixed with http://
199
	* We now automatically prefix http://
200
	* @deprecated.
201
 	*/
202 1
	function remove_redundant_http()
203
	{	/*
204
		if(preg_match("@http://@", $this->website))
205
		{
206
			$this->website = substr($this->website, 7);
207
		}
208
		*/
209 1
	}
210
211 1
	function fill_in_additional_list_fields()
212
	{
213 1
		parent::fill_in_additional_list_fields();
214
	// Fill in the assigned_user_name
215
	//	$this->assigned_user_name = get_assigned_user_name($this->assigned_user_id);
216
217 1
	}
218
219 4
	function fill_in_additional_detail_fields()
220
	{
221 4
        parent::fill_in_additional_detail_fields();
222
223
        //rrs bug: 28184 - instead of removing this code altogether just adding this check to ensure that if the parent_name
224
        //is empty then go ahead and fill it.
225 4
        if(empty($this->parent_name) && !empty($this->id)){
226 1
			$query = "SELECT a1.name from accounts a1, accounts a2 where a1.id = a2.parent_id and a2.id = '$this->id' and a1.deleted=0";
227 1
			$result = $this->db->query($query,true," Error filling in additional detail fields: ");
228
229
			// Get the id and the name.
230 1
			$row = $this->db->fetchByAssoc($result);
231
232 1
			if($row != null)
233
			{
234
				$this->parent_name = $row['name'];
235
			}
236
			else
237
			{
238 1
				$this->parent_name = '';
239
			}
240
        }
241
242
        // Set campaign name if there is a campaign id
243 4
		if( !empty($this->campaign_id)){
244
245
			$camp = new Campaign();
246
		    $where = "campaigns.id='{$this->campaign_id}'";
247
		    $campaign_list = $camp->get_full_list("campaigns.name", $where, true);
248
		    $this->campaign_name = $campaign_list[0]->name;
249
		}
250 4
	}
251
252 1
	function get_list_view_data(){
253
254 1
		$temp_array = parent::get_list_view_data();
255
256 1
		$temp_array["ENCODED_NAME"] = $this->name;
257
258 1
		if(!empty($this->billing_address_state))
259
		{
260
			$temp_array["CITY"] = $this->billing_address_city . ', '. $this->billing_address_state;
261
		}
262
		else
263
		{
264 1
			$temp_array["CITY"] = $this->billing_address_city;
265
		}
266 1
		$temp_array["BILLING_ADDRESS_STREET"]  = $this->billing_address_street;
267 1
		$temp_array["SHIPPING_ADDRESS_STREET"] = $this->shipping_address_street;
268
269 1
		return $temp_array;
270
	}
271
	/**
272
		builds a generic search based on the query string using or
273
		do not include any $this-> because this is called on without having the class instantiated
274
	*/
275 1
	function build_generic_where_clause ($the_query_string) {
276 1
	$where_clauses = Array();
277 1
	$the_query_string = $this->db->quote($the_query_string);
278 1
	array_push($where_clauses, "accounts.name like '$the_query_string%'");
279 1
	if (is_numeric($the_query_string)) {
280 1
		array_push($where_clauses, "accounts.phone_alternate like '%$the_query_string%'");
281 1
		array_push($where_clauses, "accounts.phone_fax like '%$the_query_string%'");
282 1
		array_push($where_clauses, "accounts.phone_office like '%$the_query_string%'");
283
	}
284
285 1
	$the_where = "";
286 1
	foreach($where_clauses as $clause)
287
	{
288 1
		if(!empty($the_where)) $the_where .= " or ";
289 1
		$the_where .= $clause;
290
	}
291
292 1
	return $the_where;
293
}
294
295
296 1
        function create_export_query($order_by, $where, $relate_link_join='')
297
        {
298 1
            $custom_join = $this->getCustomJoin(true, true, $where);
299 1
            $custom_join['join'] .= $relate_link_join;
300
                         $query = "SELECT
301
                                accounts.*,
302
                                email_addresses.email_address email_address,
303
                                '' email_addresses_non_primary, " . // email_addresses_non_primary needed for get_field_order_mapping()
304
                                "accounts.name as account_name,
305 1
                                users.user_name as assigned_user_name ";
306 1
            $query .= $custom_join['select'];
307 1
						 $query .= " FROM accounts ";
308
                         $query .= "LEFT JOIN users
309 1
	                                ON accounts.assigned_user_id=users.id ";
310
311
						//join email address table too.
312 1
						$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 ';
313 1
						$query .=  ' LEFT JOIN email_addresses on email_addresses.id = email_addr_bean_rel.email_address_id ' ;
314
315 1
            $query .= $custom_join['join'];
316
317 1
		        $where_auto = "( accounts.deleted IS NULL OR accounts.deleted=0 )";
318
319 1
                if($where != "")
320 1
                        $query .= "where ($where) AND ".$where_auto;
321
                else
322 1
                        $query .= "where ".$where_auto;
323
324 1
        $order_by = $this->process_order_by($order_by);
325 1
        if (!empty($order_by)) {
326 1
            $query .= ' ORDER BY ' . $order_by;
327
        }
328
329 1
                return $query;
330
        }
331
332 1
	function set_notification_body($xtpl, $account)
333
	{
334 1
		$xtpl->assign("ACCOUNT_NAME", $account->name);
335 1
		$xtpl->assign("ACCOUNT_TYPE", $account->account_type);
336 1
		$xtpl->assign("ACCOUNT_DESCRIPTION", $account->description);
337
338 1
		return $xtpl;
339
	}
340
341 58
	function bean_implements($interface){
342
		switch($interface){
343 58
			case 'ACL':return true;
0 ignored issues
show
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
344
		}
345 1
		return false;
346
	}
347 1
	function get_unlinked_email_query($type=array()) {
348
349 1
		return get_unlinked_email_query($type, $this);
350
	}
351
352
	/**
353
	 * Create a query string for select Products/Services Purchased list from database.
354
	 * @return string final query
355
	 */
356 1
	public function getProductsServicesPurchasedQuery() {
357
		$query = "
358
			SELECT
359
				aos_products_quotes.*
360
			FROM
361
				aos_products_quotes
362
			JOIN aos_quotes ON aos_quotes.id = aos_products_quotes.parent_id AND aos_quotes.stage LIKE 'Closed Accepted' AND aos_quotes.deleted = 0 AND aos_products_quotes.deleted = 0
363 1
			JOIN accounts ON accounts.id = aos_quotes.billing_account_id AND accounts.id = '{$this->id}'
364
365 1
			";
366 1
		return $query;
367
	}
368
369
}
370