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/Campaigns/Campaign.php (3 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:
44
 ********************************************************************************/
45
46
class Campaign extends SugarBean {
47
	var $field_name_map;
48
49
	// Stored fields
50
	var $id;
51
	var $date_entered;
52
	var $date_modified;
53
	var $modified_user_id;
54
	var $assigned_user_id;
55
	var $created_by;
56
	var $created_by_name;
57
    var $currency_id;
58
	var $modified_by_name;
59
	var $name;
60
	var $start_date;
61
	var $end_date;
62
	var $status;
63
	var $expected_cost;
64
	var $budget;
65
	var $actual_cost;
66
	var $expected_revenue;
67
	var $campaign_type;
68
	var $objective;
69
	var $content;
70
	var $tracker_key;
71
	var $tracker_text;
72
	var $tracker_count;
73
	var $refer_url;
74
    var $impressions;
75
76
	// These are related
77
	var $assigned_user_name;
78
79
	// module name definitions and table relations
80
	var $table_name = "campaigns";
81
	var $rel_prospect_list_table = "prospect_list_campaigns";
82
	var $object_name = "Campaign";
83
	var $module_dir = 'Campaigns';
84
	var $importable = true;
85
86
  	// This is used to retrieve related fields from form posts.
87
	var $additional_column_fields = array(
88
				'assigned_user_name', 'assigned_user_id',
89
	);
90
91
	var $relationship_fields = Array('prospect_list_id'=>'prospect_lists');
92
93
	var $new_schema = true;
94
95 1
	function list_view_parse_additional_sections(&$listTmpl) {
96 1
		global $locale;
97
98
		// take $assigned_user_id and get the Username value to assign
99 1
		$assId = $this->getFieldValue('assigned_user_id');
100
101 1
		$query = "SELECT first_name, last_name FROM users WHERE id = '".$assId."'";
102 1
		$result = $this->db->query($query);
103 1
		$user = $this->db->fetchByAssoc($result);
104
105
		//_ppd($user);
106 1
		if(!empty($user)) {
107
			if(is_array($user)) {
108
				$fullName = $locale->getLocaleFormattedName($user['first_name'], $user['last_name']);
109
			}
110
			else /*if(is_object($user))*/ {
111
				$fullName = $locale->getLocaleFormattedName($user->first_name, $user->last_name);
112
			}
113
			$listTmpl->assign('ASSIGNED_USER_NAME', $fullName);
114
		}
115 1
	}
116
117
118 2
	function get_summary_text()
119
	{
120 2
		return $this->name;
121
	}
122
123 1
        function create_export_query($order_by, $where, $relate_link_join='')
124
        {
125 1
            $custom_join = $this->getCustomJoin(true, true, $where);
126 1
            $custom_join['join'] .= $relate_link_join;
127
            $query = "SELECT
128
            campaigns.*,
129 1
            users.user_name as assigned_user_name ";
130 1
            $query .=  $custom_join['select'];
131 1
	        $query .= " FROM campaigns ";
132
			$query .= "LEFT JOIN users
133 1
                      ON campaigns.assigned_user_id=users.id";
134 1
            $query .=  $custom_join['join'];
135
136 1
		$where_auto = " campaigns.deleted=0";
137
138 1
        if($where != "")
139 1
                $query .= " where $where AND ".$where_auto;
140
        else
141 1
                $query .= " where ".$where_auto;
142
143 1
        if($order_by != "")
144 1
                $query .= " ORDER BY $order_by";
145
        else
146 1
                $query .= " ORDER BY campaigns.name";
147 1
        return $query;
148
    }
149
150
151
152 3
	function clear_campaign_prospect_list_relationship($campaign_id, $prospect_list_id='')
153
	{
154 3
		if(!empty($prospect_list_id))
155
			$prospect_clause = " and prospect_list_id = '$prospect_list_id' ";
156
		else
157 3
			$prospect_clause = '';
158
159 3
		$query = "DELETE FROM $this->rel_prospect_list_table WHERE campaign_id='$campaign_id' AND deleted = '0' " . $prospect_clause;
160 3
	 	$this->db->query($query, true, "Error clearing campaign to prospect_list relationship: ");
161 3
	}
162
163
164
165 2
	function mark_relationships_deleted($id)
166
	{
167 2
		$this->clear_campaign_prospect_list_relationship($id);
168 2
	}
169
170 1
	function fill_in_additional_list_fields()
171
	{
172 1
		parent::fill_in_additional_list_fields();
173 1
	}
174
175 2
	function fill_in_additional_detail_fields()
176
	{
177 2
        parent::fill_in_additional_detail_fields();
178
		//format numbers.
179
180
		//don't need additional formatting here.
181
		//$this->budget=format_number($this->budget);
182
		//$this->expected_cost=format_number($this->expected_cost);
183
		//$this->actual_cost=format_number($this->actual_cost);
184
		//$this->expected_revenue=format_number($this->expected_revenue);
185 2
	}
186
187
188 1
	function update_currency_id($fromid, $toid){
189 1
	}
190
191
192 1
	function get_list_view_data(){
193
194 1
		$temp_array = $this->get_list_view_array();
195 1
		if ($this->campaign_type != 'Email') {
196 1
			$temp_array['OPTIONAL_LINK']="display:none";
197
		}
198 1
		$temp_array['TRACK_CAMPAIGN_TITLE'] = translate("LBL_TRACK_BUTTON_TITLE",'Campaigns');
199 1
		$temp_array['TRACK_CAMPAIGN_IMAGE'] = SugarThemeRegistry::current()->getImageURL('view_status.gif');
200 1
		$temp_array['LAUNCH_WIZARD_TITLE'] = translate("LBL_TO_WIZARD_TITLE",'Campaigns');
201 1
		$temp_array['LAUNCH_WIZARD_IMAGE'] = SugarThemeRegistry::current()->getImageURL('edit_wizard.gif');
202 1
        $temp_array['TRACK_VIEW_ALT_TEXT'] = translate("LBL_TRACK_BUTTON_TITLE",'Campaigns');
203 1
        $temp_array['LAUNCH_WIZ_ALT_TEXT'] = translate("LBL_TO_WIZARD_TITLE",'Campaigns');
204
205 1
		return $temp_array;
206
	}
207
	/**
208
		builds a generic search based on the query string using or
209
		do not include any $this-> because this is called on without having the class instantiated
210
	*/
211 1
	function build_generic_where_clause ($the_query_string)
212
	{
213 1
		$where_clauses = Array();
214 1
		$the_query_string = $this->db->quote($the_query_string);
215 1
		array_push($where_clauses, "campaigns.name like '$the_query_string%'");
216
217 1
		$the_where = "";
218 1
		foreach($where_clauses as $clause)
219
		{
220 1
			if($the_where != "") $the_where .= " or ";
221 1
			$the_where .= $clause;
222
		}
223
224
225 1
		return $the_where;
226
	}
227
228 1
	function save($check_notify = FALSE) {
229
230
			//US DOLLAR
231 1
			if(isset($this->amount) && !empty($this->amount)){
232
233 1
				$currency = new Currency();
234 1
				$currency->retrieve($this->currency_id);
235 1
				$this->amount_usdollar = $currency->convertToDollar($this->amount);
236
237
			}
238
239
240
		// Bug53301
241 1
		if($this->campaign_type != 'NewsLetter') {
242 1
		    $this->frequency = '';
243
		}
244
		
245 1
		return parent::save($check_notify);
246
247
	}
248
249
250 1
	function mark_deleted($id){
251 1
        $query = "update contacts set campaign_id = null where campaign_id = '{$id}' ";
252 1
        $this->db->query($query);
253 1
        $query = "update accounts set campaign_id = null where campaign_id = '{$id}' ";
254 1
        $this->db->query($query);
255
        // bug49632 - delete campaign logs for the campaign as well
256 1
        $query = "update campaign_log set deleted = 1 where campaign_id = '{$id}' ";
257 1
        $this->db->query($query);
258 1
		return parent::mark_deleted($id);
259
	}
260
261 1
	function set_notification_body($xtpl, $camp)
262
	{
263 1
		$xtpl->assign("CAMPAIGN_NAME", $camp->name);
264 1
		$xtpl->assign("CAMPAIGN_AMOUNT", $camp->budget);
265 1
		$xtpl->assign("CAMPAIGN_CLOSEDATE", $camp->end_date);
266 1
		$xtpl->assign("CAMPAIGN_STATUS", $camp->status);
267 1
		$xtpl->assign("CAMPAIGN_DESCRIPTION", $camp->content);
268
269 1
		return $xtpl;
270
	}
271
272 1
    function track_log_leads()
273
    {
274 1
        $this->load_relationship('log_entries');
275 1
        $query_array = $this->log_entries->getQuery(true);
276
277 1
        $query_array['select'] = 'SELECT campaign_log.* ';
278 1
        $query_array['where']  = $query_array['where']. " AND activity_type = 'lead' AND archived = 0 AND target_id IS NOT NULL";
279
280 1
        return implode(' ', $query_array);
281
    }
282
283 1
	function track_log_entries($type=array()) {
284
        //get arguments being passed in
285 1
        $args = func_get_args();
286 1
        $mkt_id ='';
287
288 1
		$this->load_relationship('log_entries');
289 1
		$query_array = $this->log_entries->getQuery(true);
290
291
        //if one of the arguments is marketing ID, then we need to filter by it
292 1
        foreach($args as $arg){
293 1
            if(isset($arg['EMAIL_MARKETING_ID_VALUE'])){
294
                $mkt_id = $arg['EMAIL_MARKETING_ID_VALUE'];
295
            }
296
297 1
            if(isset($arg['group_by'])) {
298 1
            	$query_array['group_by'] = $arg['group_by'];
299
            }
300
        }
301
302
303
304 1
		if (empty($type))
305 1
			$type[0]='targeted';
306
307 1
		$query_array['select'] ="SELECT campaign_log.* ";
308 1
		$query_array['where'] = $query_array['where']. " AND activity_type='{$type[0]}' AND archived=0";
309
        //add filtering by marketing id, if it exists
310 1
        if (!empty($mkt_id)) $query_array['where'] = $query_array['where']. " AND marketing_id ='$mkt_id' ";
311
312
        //B.F. #37943
313 1
        if( isset($query_array['group_by']))
314
        {
315
			//perform the inner join with the group by if a marketing id is defined, which means we need to filter out duplicates.
316
			//if no marketing id is specified then we are displaying results from multiple marketing emails and it is understood there might be duplicate target entries
317
			if (!empty($mkt_id)){
318
				$group_by = str_replace("campaign_log", "cl", $query_array['group_by']);
319
				$join_where = str_replace("campaign_log", "cl", $query_array['where']);
320
				$query_array['from'] .= " INNER JOIN (select min(id) as id from campaign_log cl $join_where GROUP BY $group_by  ) secondary
321
					on campaign_log.id = secondary.id	";
322
			}
323
            unset($query_array['group_by']);
324 1
        } else if(isset($query_array['group_by'])) {
325
           $query_array['where'] = $query_array['where'] . ' GROUP BY ' . $query_array['group_by'];
326
           unset($query_array['group_by']);
327
        }
328
329 1
        $query = (implode(" ",$query_array));
330 1
        return $query;
331
	}
332
333
334 1
	function get_queue_items() {
335
        //get arguments being passed in
336 1
        $args = func_get_args();
337 1
        $mkt_id ='';
338
339 1
        $this->load_relationship('queueitems');
340 1
		$query_array = $this->queueitems->getQuery(true);
341
342
        //if one of the arguments is marketing ID, then we need to filter by it
343 1
        foreach($args as $arg){
344 1
            if(isset($arg['EMAIL_MARKETING_ID_VALUE'])){
345 1
                $mkt_id = $arg['EMAIL_MARKETING_ID_VALUE'];
346
            }
347
348 1
            if(isset($arg['group_by'])) {
349 1
            	$query_array['group_by'] = $arg['group_by'];
350
            }
351
        }
352
353
        //add filtering by marketing id, if it exists, and if where key is not empty
354 1
        if (!empty($mkt_id) && !empty($query_array['where'])){
355 1
             $query_array['where'] = $query_array['where']. " AND marketing_id ='$mkt_id' ";
356
        }
357
358
		//get select query from email man
359 1
		$man = new EmailMan();
360 1
		$listquery= $man->create_queue_items_query('',str_replace(array("WHERE","where"),"",$query_array['where']),null,$query_array);
361 1
		return $listquery;
362
363
	}
364
//	function get_prospect_list_entries() {
365
//		$this->load_relationship('prospectlists');
366
//		$query_array = $this->prospectlists->getQuery(true);
367
//
368
//		$query=<<<EOQ
369
//			SELECT distinct prospect_lists.*,
370
//			(case  when (email_marketing.id is null) then default_message.id else email_marketing.id end) marketing_id,
371
//			(case  when  (email_marketing.id is null) then default_message.name else email_marketing.name end) marketing_name
372
//
373
//			FROM prospect_lists
374
//
375
//			INNER JOIN prospect_list_campaigns ON (prospect_lists.id=prospect_list_campaigns.prospect_list_id AND prospect_list_campaigns.campaign_id='{$this->id}')
376
//
377
//			LEFT JOIN email_marketing on email_marketing.message_for = prospect_lists.id and email_marketing.campaign_id = '{$this->id}'
378
//			and email_marketing.deleted =0 and email_marketing.status='active'
379
//
380
//			LEFT JOIN email_marketing default_message on default_message.message_for = prospect_list_campaigns.campaign_id and
381
//			default_message.campaign_id = '{$this->id}' and default_message.deleted =0
382
//			and default_message.status='active'
383
//
384
//			WHERE prospect_list_campaigns.deleted=0 AND prospect_lists.deleted=0
385
//
386
//EOQ;
387
//		return $query;
388
//	}
389
390 24
	 function bean_implements($interface){
391
		switch($interface){
392 24
			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...
393
		}
394 2
		return false;
395
	}
396
397
398
	/**
399
	 * create_list_count_query
400
	 * Overrode this method from SugarBean to handle the distinct parameter used to filter out
401
	 * duplicate entries for some of the subpanel listivews.  Without the distinct filter, the
402
	 * list count would be inaccurate because one-to-many email_marketing entries may be associated
403
	 * with a campaign.
404
     *
405
     * @param string $query Select query string
406
     * @param array $param array of arguments
0 ignored issues
show
There is no parameter named $param. Did you maybe mean $params?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
407
     * @return string count query
408
     *
409
	 */
410 1
    function create_list_count_query($query, $params=array())
411
    {
412
		//include the distinct filter if a marketing id is defined, which means we need to filter out duplicates by the passed in group by.
413
		//if no marketing id is specified, it is understood there might be duplicate target entries so no need to filter out
414 1
		if((strpos($query,'marketing_id') !== false )&& isset($params['distinct'])) {
415
		   $pattern = '/SELECT(.*?)(\s){1}FROM(\s){1}/is';  // ignores the case
416
    	   $replacement = 'SELECT COUNT(DISTINCT ' . $params['distinct'] . ') c FROM ';
417
    	   $query = preg_replace($pattern, $replacement, $query, 1);
418
    	   return $query;
419
		}
420
421
		//If distinct parameter not found, default to SugarBean's function
422 1
    	return parent::create_list_count_query($query);
423
    }
424
425
    /**
426
     * Returns count of deleted leads,
427
     * which were created through generated lead form
428
     *
429
     * @return integer
430
     */
431 1
    function getDeletedCampaignLogLeadsCount()
432
    {
433 1
        $query = "SELECT COUNT(*) AS count FROM campaign_log WHERE campaign_id = '" . $this->getFieldValue('id') . "' AND target_id IS NULL AND activity_type = 'lead'";
434 1
        $result = $this->db->fetchOne($query);
435
436 1
        return (int)$result['count'];
437
    }
438
}
439
?>