Completed
Push — console-installer ( e2b50d...6ce748 )
by Adam
22:30
created

display()   F

Complexity

Conditions 25
Paths 19601

Size

Total Lines 116
Code Lines 72

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 25
eloc 72
nc 19601
nop 3
dl 0
loc 116
rs 2
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
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 - 2016 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
44
45
46
class SugarWidgetSubPanelTopSelectContactsButton extends SugarWidgetSubPanelTopSelectButton
47
{
48
	//button_properties is a collection of properties associated with the widget_class definition. layoutmanager
49
	function __construct($button_properties=array())
50
	{
51
		$this->button_properties=$button_properties;
52
	}
53
54
    /**
55
     * @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
56
     */
57
    function SugarWidgetSubPanelTopSelectContactsButton($button_properties=array()){
58
        $deprecatedMessage = 'PHP4 Style Constructors are deprecated and will be remove in 7.8, please update your code';
59
        if(isset($GLOBALS['log'])) {
60
            $GLOBALS['log']->deprecated($deprecatedMessage);
61
        }
62
        else {
63
            trigger_error($deprecatedMessage, E_USER_DEPRECATED);
64
        }
65
        self::__construct($button_properties);
66
    }
67
68
69
    public function getWidgetId($buttonSuffix = true)
70
    {
71
        return parent::getWidgetId() . '_select_button';
72
    }
73
74
	//widget_data is the collection of attributes associated with the button in the layout_defs file.
75
	function display($widget_data, $additionalFormFields = NULL, $nonbutton = false)
76
	{
77
		global $app_strings;
78
		$initial_filter = '';
79
80
		$this->title = $app_strings['LBL_SELECT_CONTACT_BUTTON_TITLE'];
81
		//$this->accesskey = $app_strings['LBL_SELECT_CONTACT_BUTTON_KEY'];
82
		$this->value = $app_strings['LBL_SELECT_CONTACT_BUTTON_LABEL'];
83
84
		$this->module_name = 'Contacts';
85
86
		if (is_array($this->button_properties)) {
87
			if( isset($this->button_properties['title'])) {
88
				$this->title = $app_strings[$this->button_properties['title']];
89
			}
90
			if( isset($this->button_properties['accesskey'])) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
91
				//$this->accesskey = $app_strings[$this->button_properties['accesskey']];
92
			}
93
			if( isset($this->button_properties['form_value'])) {
94
				$this->value = $app_strings[$this->button_properties['form_value']];
95
			}
96
			if( isset($this->button_properties['module'])) {
97
				$this->module_name = $this->button_properties['module'];
98
			}
99
		}
100
101
		$focus = $widget_data['focus'];
102
		if(ACLController::moduleSupportsACL($widget_data['module']) && !ACLController::checkAccess($widget_data['module'], 'list', true)){
103
			$button = ' <input type="button" name="' .$this->getWidgetId() . '" id="' .$this->getWidgetId() . '" class="button"' . "\"\n"
104
			. ' title="' . $this->title . '"'
105
			. ' value="' . $this->value . "\"\n"
106
			.' disabled />';
107
			return $button;
108
		}
109
110
		//refresh the whole page after end of action?
111
		$refresh_page = 0;
112
		if(!empty($widget_data['subpanel_definition']->_instance_properties['refresh_page'])){
113
			$refresh_page = 1;
114
		}
115
116
		$subpanel_definition = $widget_data['subpanel_definition'];
117
118
		$button_definition = $subpanel_definition->get_buttons();
119
		$subpanel_name = $subpanel_definition->get_module_name();
120
		if (empty($this->module_name)) {
121
			$this->module_name = $subpanel_name;
122
		}
123
124
		if ($subpanel_name == 'Project'){
125
			$link_field_name = 'project_contacts_1';
126
		}
127
		else{
128
			$link_field_name = $subpanel_definition->get_data_source_name(true);
129
		}
130
131
		$popup_mode='Single';
132
		if(isset($widget_data['mode'])){
133
			$popup_mode=$widget_data['mode'];
134
		}
135
		if(isset($widget_data['initial_filter_fields'])){
136
			if (is_array($widget_data['initial_filter_fields'])) {
137
				foreach ($widget_data['initial_filter_fields'] as $value=>$alias) {
138
					if (isset($focus->$value) and !empty($focus->$value)) {
139
						$initial_filter.="&".$alias . '='.urlencode($focus->$value);
140
					}
141
				}
142
			}
143
		}
144
		$create="true";
145
		if(isset($widget_data['create'])){
146
			$create=$widget_data['create'];
147
		}
148
		$return_module = $_REQUEST['module'];
149
		$return_action = 'SubPanelViewer';
150
		$return_id = $_REQUEST['record'];
151
152
		//field_to_name_array
153
		$fton_array= array('id' => 'subpanel_id');
154
		if(isset($widget_data['field_to_name_array']) && is_array($widget_data['field_to_name_array'])){
155
			$fton_array=array_merge($fton_array,$widget_data['field_to_name_array']);
156
		}
157
158
		$return_url = "index.php?module=$return_module&action=$return_action&subpanel=$subpanel_name&record=$return_id&sugar_body_only=1";
159
160
		$popup_request_data = array(
161
			'call_back_function' => 'set_return_and_save_background',
162
			'form_name' => 'DetailView',
163
			'field_to_name_array' => $fton_array,
164
			'passthru_data' => array(
165
				'child_field' => $this->module_name,
166
				'return_url' => urlencode($return_url),
167
				'link_field_name' => $link_field_name,
168
				'module_name' => $this->module_name,
169
				'refresh_page' => 1,
170
			),
171
		);
172
173
		if (is_array($this->button_properties) && !empty($this->button_properties['add_to_passthru_data'])) {
174
			$popup_request_data['passthru_data']= array_merge($popup_request_data['passthru_data'],$this->button_properties['add_to_passthru_data']);
175
		}
176
177
		if (is_array($this->button_properties) && !empty($this->button_properties['add_to_passthru_data']['return_type'])) {
178
179
			if ($this->button_properties['add_to_passthru_data']['return_type']=='report') {
180
				$initial_filter = "&module_name=". urlencode($widget_data['module']);
181
			}
182
		}
183
		$json_encoded_php_array = $this->_create_json_encoded_popup_request($popup_request_data);
184
185
		return '<form action="index.php">' . "\n"
186
			. ' <input type="button" name="' .$this->getWidgetId() . '" id="' .$this->getWidgetId() . '" class="button"' . "\"\n"
187
				. ' title="' . $this->title . '"'
188
			. ' value="' . $this->value . "\"\n"
189
			. " onclick='open_popup(\"$this->module_name\",600,400,\"$initial_filter\",true,true,$json_encoded_php_array,\"$popup_mode\",$create);' /></form>\n";
190
	}
191
}
192
?>
193