SugarWidgetSubPanelTopSelectUsersButton   A
last analyzed

Complexity

Total Complexity 30

Size/Duplication

Total Lines 150
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 1 Features 1
Metric Value
c 1
b 1
f 1
dl 0
loc 150
ccs 0
cts 117
cp 0
rs 10
wmc 30
lcom 1
cbo 2

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A SugarWidgetSubPanelTopSelectUsersButton() 0 10 2
A getDisplayName() 0 4 1
F display() 0 121 26
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 SugarWidgetSubPanelTopSelectUsersButton 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 SugarWidgetSubPanelTopSelectUsersButton($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
    function getDisplayName()
70
    {
71
        return $GLOBALS['app_strings']['LBL_SELECT_USER_BUTTON_LABEL'];
72
    }
73
	//widget_data is the collection of attributes associated with the button in the layout_defs file.
74
	function display($widget_data, $additionalFormFields = NULL, $nonbutton = false)
75
	{
76
		global $app_strings;
77
		$initial_filter = '';
78
79
		$this->title = $app_strings['LBL_SELECT_USER_BUTTON_TITLE'];
80
		//$this->accesskey = $app_strings['LBL_SELECT_USER_BUTTON_KEY'];
81
		$this->value = $this->getDisplayName();
82
83
		$this->module_name = 'Users';
84
85
		if (is_array($this->button_properties)) {
86
			if( isset($this->button_properties['title'])) {
87
				$this->title = $app_strings[$this->button_properties['title']];
88
			}
89
			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...
90
				//$this->accesskey = $app_strings[$this->button_properties['accesskey']];
91
			}
92
			if( isset($this->button_properties['form_value'])) {
93
				$this->value = $app_strings[$this->button_properties['form_value']];
94
			}
95
			if( isset($this->button_properties['module'])) {
96
				$this->module_name = $this->button_properties['module'];
97
			}
98
		}
99
100
		$focus = $widget_data['focus'];
101
		if(ACLController::moduleSupportsACL($widget_data['module']) && !ACLController::checkAccess($widget_data['module'], 'list', true)){
102
			$button = ' <input type="button" name="' .$this->getWidgetId() . '" id="' .$this->getWidgetId() . '" class="button"' . "\"\n"
103
			. ' title="' . $this->title . '"'
104
			. ' value="' . $this->value . "\"\n"
105
			.' disabled />';
106
			return $button;
107
		}
108
109
		//refresh the whole page after end of action?
110
		$refresh_page = 0;
111
		if(!empty($widget_data['subpanel_definition']->_instance_properties['refresh_page'])){
112
			$refresh_page = 1;
113
		}
114
115
		$subpanel_definition = $widget_data['subpanel_definition'];
116
117
		$button_definition = $subpanel_definition->get_buttons();
118
		$subpanel_name = $subpanel_definition->get_module_name();
119
		if (empty($this->module_name)) {
120
			$this->module_name = $subpanel_name;
121
		}
122
123
		if ($subpanel_name == 'Project'){
124
			$link_field_name = 'project_users_1';
125
		}
126
		else{
127
			$link_field_name = $subpanel_definition->get_data_source_name(true);
128
		}
129
130
		$popup_mode='Single';
131
		if(isset($widget_data['mode'])){
132
			$popup_mode=$widget_data['mode'];
133
		}
134
		if(isset($widget_data['initial_filter_fields'])){
135
			if (is_array($widget_data['initial_filter_fields'])) {
136
				foreach ($widget_data['initial_filter_fields'] as $value=>$alias) {
137
					if (isset($focus->$value) and !empty($focus->$value)) {
138
						$initial_filter.="&".$alias . '='.urlencode($focus->$value);
139
					}
140
				}
141
			}
142
		}
143
144
		if (!empty($widget_data['filter_out_is_admin'])) {
145
            $initial_filter.="&is_admin_advanced=0";
146
        }
147
148
		$create="true";
149
		if(isset($widget_data['create'])){
150
			$create=$widget_data['create'];
151
		}
152
		$return_module = $_REQUEST['module'];
153
		$return_action = 'SubPanelViewer';
154
		$return_id = $_REQUEST['record'];
155
156
		//field_to_name_array
157
		$fton_array= array('id' => 'subpanel_id');
158
		if(isset($widget_data['field_to_name_array']) && is_array($widget_data['field_to_name_array'])){
159
			$fton_array=array_merge($fton_array,$widget_data['field_to_name_array']);
160
		}
161
162
		$return_url = "index.php?module=$return_module&action=$return_action&subpanel=$subpanel_name&record=$return_id&sugar_body_only=1";
163
164
		$popup_request_data = array(
165
			'call_back_function' => 'set_return_and_save_background',
166
			'form_name' => 'DetailView',
167
			'field_to_name_array' => $fton_array,
168
			'passthru_data' => array(
169
				'child_field' => $this->module_name,
170
				'return_url' => urlencode($return_url),
171
				'link_field_name' => $link_field_name,
172
				'module_name' => $this->module_name,
173
				'refresh_page' => 1,
174
			),
175
		);
176
177
		if (is_array($this->button_properties) && !empty($this->button_properties['add_to_passthru_data'])) {
178
			$popup_request_data['passthru_data']= array_merge($popup_request_data['passthru_data'],$this->button_properties['add_to_passthru_data']);
179
		}
180
181
		if (is_array($this->button_properties) && !empty($this->button_properties['add_to_passthru_data']['return_type'])) {
182
183
			if ($this->button_properties['add_to_passthru_data']['return_type']=='report') {
184
				$initial_filter = "&module_name=". urlencode($widget_data['module']);
185
			}
186
		}
187
		$json_encoded_php_array = $this->_create_json_encoded_popup_request($popup_request_data);
188
189
		return '<form action="index.php">' . "\n"
190
			. ' <input type="button" name="' .$this->getWidgetId() . '" id="' .$this->getWidgetId() . '" class="button"' . "\"\n"
191
				. ' title="' . $this->title . '"'
192
			. ' value="' . $this->value . "\"\n"
193
			. " onclick='open_popup(\"$this->module_name\",600,400,\"$initial_filter\",true,true,$json_encoded_php_array,\"$popup_mode\",$create);' /></form>\n";
194
	}
195
}
196
?>
197