Passed
Push — scrutinizer-code-quality ( 09f5a1...c4c5fb )
by Adam
56:05 queued 14:08
created

SugarWidgetSubPanelTopSelectButton()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 1 Features 1
Metric Value
cc 2
eloc 7
c 1
b 1
f 1
nc 2
nop 1
dl 0
loc 10
ccs 0
cts 10
cp 0
crap 6
rs 9.4285
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 - 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
44
require_once('include/generic/SugarWidgets/SugarWidgetSubPanelTopButton.php');
45
46
class SugarWidgetSubPanelTopSelectButton extends SugarWidgetSubPanelTopButton
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 SugarWidgetSubPanelTopSelectButton($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(false) . 'select_button';
72
    }
73
74
    public function getDisplayName()
75
    {
76
        return $GLOBALS['app_strings']['LBL_SELECT_BUTTON_LABEL'];
77
    }
78
	//widget_data is the collection of attributes associated with the button in the layout_defs file.
79
	function display($widget_data, $additionalFormFields = NULL, $nonbutton = false)
80
	{
81
		global $app_strings;
82
		$initial_filter = '';
83
84
	    $this->title     = $this->getTitle();
85
        $this->accesskey = $this->getAccesskey();
86
        $this->value     = $this->getDisplayName();
87
88
		if (is_array($this->button_properties)) {
89
			if( isset($this->button_properties['title'])) {
90
				$this->title = $app_strings[$this->button_properties['title']];
91
			}
92
			if( isset($this->button_properties['accesskey'])) {
93
				$this->accesskey = $app_strings[$this->button_properties['accesskey']];
94
			}
95
			if( isset($this->button_properties['form_value'])) {
96
				$this->value = $app_strings[$this->button_properties['form_value']];
97
			}
98
			if( isset($this->button_properties['module'])) {
99
				$this->module_name = $this->button_properties['module'];
100
			}
101
		}
102
103
104
		$focus = $widget_data['focus'];
105
		if(ACLController::moduleSupportsACL($widget_data['module']) && !ACLController::checkAccess($widget_data['module'], 'list', true)){
106
			$button = ' <input type="button" name="' . $this->getWidgetId() . '" id="' . $this->getWidgetId() . '" class="button"' . "\n"
107
			. ' title="' . $this->title . '"'
108
			. ' value="' . $this->value . "\"\n"
109
			.' disabled />';
110
			return $button;
111
		}
112
113
		//refresh the whole page after end of action?
114
		$refresh_page = 0;
115
		if(!empty($widget_data['subpanel_definition']->_instance_properties['refresh_page'])){
116
			$refresh_page = 1;
117
		}
118
119
		$subpanel_definition = $widget_data['subpanel_definition'];
120
		$button_definition = $subpanel_definition->get_buttons();
121
122
        $subpanel_name = $subpanel_definition->get_name();
123
		if (empty($this->module_name)) {
124
			$this->module_name = $subpanel_definition->get_module_name();
125
		}
126
		$link_field_name = $subpanel_definition->get_data_source_name(true);
127
		$popup_mode='Single';
128
		if(isset($widget_data['mode'])){
129
			$popup_mode=$widget_data['mode'];
130
		}
131
		if(isset($widget_data['initial_filter_fields'])){
132
			if (is_array($widget_data['initial_filter_fields'])) {
133
				foreach ($widget_data['initial_filter_fields'] as $value=>$alias) {
134
					if (isset($focus->$value) and !empty($focus->$value)) {
135
						$initial_filter.="&".$alias . '='.urlencode($focus->$value);
136
					}
137
				}
138
			}
139
		}
140
		$create="true";
141
		if(isset($widget_data['create'])){
142
			$create=$widget_data['create'];
143
		}
144
		$return_module = $_REQUEST['module'];
145
		$return_action = 'SubPanelViewer';
146
		$return_id = $_REQUEST['record'];
147
148
		//field_to_name_array
149
		$fton_array= array('id' => 'subpanel_id');
150
		if(isset($widget_data['field_to_name_array']) && is_array($widget_data['field_to_name_array'])){
151
			$fton_array=array_merge($fton_array,$widget_data['field_to_name_array']);
152
		}
153
154
		$return_url = "index.php?module=$return_module&action=$return_action&subpanel=$subpanel_name&record=$return_id&sugar_body_only=1";
155
156
		$popup_request_data = array(
157
			'call_back_function' => 'set_return_and_save_background',
158
			'form_name' => 'DetailView',
159
			'field_to_name_array' => $fton_array,
160
			'passthru_data' => array(
161
				'child_field' => $subpanel_name,
162
				'return_url' => urlencode($return_url),
163
				'link_field_name' => $link_field_name,
164
				'module_name' => $subpanel_name,
165
				'refresh_page'=>$refresh_page,
166
			),
167
		);
168
169
                // bugfix #57850 add marketing_id to the request data to allow filtering based on it
170
                if (!empty($_REQUEST['mkt_id']))
171
                {
172
                    $popup_request_data['passthru_data']['marketing_id'] = $_REQUEST['mkt_id'];
173
                }
174
175
                if (is_array($this->button_properties) && !empty($this->button_properties['add_to_passthru_data']))
176
                {
177
                    $popup_request_data['passthru_data']= array_merge($popup_request_data['passthru_data'],$this->button_properties['add_to_passthru_data']);
178
                }
179
180
		if (is_array($this->button_properties) && !empty($this->button_properties['add_to_passthru_data']['return_type'])) {
181
182
			if ($this->button_properties['add_to_passthru_data']['return_type']=='report') {
183
				$initial_filter = "&module_name=". urlencode($widget_data['module']);
184
			}
185
		}
186
        //acl_roles_users_selectuser_button
187
188
        $json_encoded_php_array = $this->_create_json_encoded_popup_request($popup_request_data);
189
		return ' <input type="button" name="' . $this->getWidgetId() . '" id="' . $this->getWidgetId() . '" class="button"' . "\n"
190
				. ' title="' . $this->title . '"'
191
			. ' value="' . $this->value . "\"\n"
192
			. " onclick='open_popup(\"$this->module_name\",600,400,\"$initial_filter\",true,true,$json_encoded_php_array,\"$popup_mode\",$create);' />\n";
193
	}
194
195
    /**
196
    * @return string
197
    */
198
    protected function getTitle()
199
    {
200
       return translate('LBL_SELECT_BUTTON_TITLE');
201
    }
202
203
    /**
204
    * @return string
205
    */
206
    protected function getAccesskey()
207
    {
208
       return translate('LBL_SELECT_BUTTON_KEY');
209
    }
210
211
}
212
?>
213