/
LayoutManager.php
executable file
·380 lines (345 loc) · 15.5 KB
/
LayoutManager.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
<?php
if (!defined('sugarEntry') || !sugarEntry) {
die('Not A Valid Entry Point');
}
/**
*
* SugarCRM Community Edition is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc.
*
* SuiteCRM is an extension to SugarCRM Community Edition developed by SalesAgility Ltd.
* Copyright (C) 2011 - 2018 SalesAgility Ltd.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo and "Supercharged by SuiteCRM" logo. If the display of the logos is not
* reasonably feasible for technical reasons, the Appropriate Legal Notices must
* display the words "Powered by SugarCRM" and "Supercharged by SuiteCRM".
*/
/**
* Form layout manager
* @api
*/
#[\AllowDynamicProperties]
class LayoutManager
{
public $defs = array();
public $widget_prefix = 'SugarWidget';
public $default_widget_name = 'Field';
public $DBManager;
public function __construct()
{
// set a sane default for context
$this->defs['context'] = 'Detail';
$this->DBManager = DBManagerFactory::getInstance();
}
public function setAttribute($key, $value)
{
$this->defs[$key] = $value;
}
public function setAttributePtr($key, &$value)
{
$this->defs[$key] = $value;
}
public function getAttribute($key)
{
if (isset($this->defs[$key])) {
return $this->defs[$key];
} else {
return null;
}
}
// Take the class name from the widget definition and use the class to look it up
// $use_default will default classes to SugarWidgetFieldxxxxx
public function getClassFromWidgetDef($widget_def, $use_default = false)
{
static $class_map = array(
'SugarWidgetSubPanelTopCreateButton' => array(
'widget_class'=>'SugarWidgetSubPanelTopButton',
'title'=>'LBL_NEW_BUTTON_TITLE',
'access_key'=>'LBL_NEW_BUTTON_KEY',
'form_value'=>'LBL_NEW_BUTTON_LABEL',
'ACL'=>'edit',
),
'SugarWidgetSubPanelTopButtonQuickCreate' => array(
'widget_class'=>'SugarWidgetSubPanelTopButtonQuickCreate',
'title'=>'LBL_NEW_BUTTON_TITLE',
'access_key'=>'LBL_NEW_BUTTON_KEY',
'form_value'=>'LBL_NEW_BUTTON_LABEL',
'ACL'=>'edit',
),
'SugarWidgetSubPanelTopCreateLeadNameButton' => array(
'widget_class'=>'SugarWidgetSubPanelTopCreateLeadNameButton',
'title'=>'LBL_NEW_BUTTON_TITLE',
'access_key'=>'LBL_NEW_BUTTON_KEY',
'form_value'=>'LBL_NEW_BUTTON_LABEL',
'ACL'=>'edit',
),
'SugarWidgetSubPanelTopScheduleMeetingButton' => array(
'widget_class'=>'SugarWidgetSubPanelTopScheduleMeetingButton',
'module'=>'Meetings',
'title'=>'LBL_NEW_BUTTON_TITLE',
'access_key'=>'LBL_NEW_BUTTON_KEY',
'form_value'=>'LNK_NEW_MEETING',
'ACL'=>'edit',
),
'SugarWidgetSubPanelTopScheduleCallButton' => array(
'widget_class'=>'SugarWidgetSubPanelTopScheduleCallButton',
'module'=>'Calls',
'title'=>'LBL_NEW_BUTTON_TITLE',
'access_key'=>'LBL_NEW_BUTTON_KEY',
'form_value'=>'LNK_NEW_CALL',
'ACL'=>'edit',
),
'SugarWidgetSubPanelTopCreateTaskButton' => array(
'widget_class'=>'SugarWidgetSubPanelTopCreateTaskButton',
'module'=>'Tasks',
'title'=>'LBL_NEW_BUTTON_TITLE',
'access_key'=>'LBL_NEW_BUTTON_KEY',
'form_value'=>'LNK_NEW_TASK',
'ACL'=>'edit',
),
'SugarWidgetSubPanelTopCreateNoteButton' => array(
'widget_class'=>'SugarWidgetSubPanelTopCreateNoteButton',
'module'=>'Notes',
'title'=>'LBL_NEW_BUTTON_TITLE',
'access_key'=>'LBL_NEW_BUTTON_KEY',
'form_value'=>'LNK_NEW_NOTE',
'ACL'=>'edit',
),
'SugarWidgetSubPanelTopCreateContactAccountButton' => array(
'widget_class'=>'SugarWidgetSubPanelTopButton',
'module'=>'Contacts',
'title'=>'LBL_NEW_BUTTON_TITLE',
'access_key'=>'LBL_NEW_BUTTON_KEY',
'form_value'=>'LBL_NEW_BUTTON_LABEL',
'additional_form_fields' => array(
'primary_address_street' => 'shipping_address_street',
'primary_address_city' => 'shipping_address_city',
'primary_address_state' => 'shipping_address_state',
'primary_address_country' => 'shipping_address_country',
'primary_address_postalcode' => 'shipping_address_postalcode',
'to_email_addrs' => 'email1'
),
'ACL'=>'edit',
),
'SugarWidgetSubPanelTopCreateContact' => array(
'widget_class'=>'SugarWidgetSubPanelTopButton',
'module'=>'Contacts',
'title'=>'LBL_NEW_BUTTON_TITLE',
'access_key'=>'LBL_NEW_BUTTON_KEY',
'form_value'=>'LBL_NEW_BUTTON_LABEL',
'additional_form_fields' => array(
'account_id' => 'account_id',
'account_name' => 'account_name',
),
'ACL'=>'edit',
),
'SugarWidgetSubPanelTopCreateRevisionButton'=> array(
'widget_class'=>'SugarWidgetSubPanelTopButton',
'module'=>'DocumentRevisions',
'title'=>'LBL_NEW_BUTTON_TITLE',
'access_key'=>'LBL_NEW_BUTTON_KEY',
'form_value'=>'LBL_NEW_BUTTON_LABEL',
'additional_form_fields' => array(
'parent_name'=>'document_name',
'document_name' => 'document_name',
'document_revision' => 'latest_revision',
'document_filename' => 'filename',
'document_revision_id' => 'document_revision_id',
),
'ACL'=>'edit',
),
'SugarWidgetSubPanelTopCreateDirectReport' => array(
'widget_class'=>'SugarWidgetSubPanelTopButton',
'module'=>'Contacts',
'title'=>'LBL_NEW_BUTTON_TITLE',
'access_key'=>'LBL_NEW_BUTTON_KEY',
'form_value'=>'LBL_NEW_BUTTON_LABEL',
'additional_form_fields' => array(
'reports_to_name' => 'name',
'reports_to_id' => 'id',
),
'ACL'=>'edit',
),
'SugarWidgetSubPanelTopSelectFromReportButton' => array(
'widget_class'=>'SugarWidgetSubPanelTopSelectReportsButton',
'module'=>'Reports',
'title'=>'LBL_SELECT_REPORTS_BUTTON_LABEL',
'access_key'=>'LBL_SELECT_BUTTON_KEY',
'form_value'=>'LBL_SELECT_REPORTS_BUTTON_LABEL',
'ACL'=>'edit',
'add_to_passthru_data'=>array(
'return_type'=>'report',
)
),
'SugarWidgetSubPanelTopCreateAccountNameButton' => array(
'widget_class'=>'SugarWidgetSubPanelTopCreateAccountNameButton',
'module'=>'Contacts',
'title'=>'LBL_NEW_BUTTON_TITLE',
'access_key'=>'LBL_NEW_BUTTON_KEY',
'form_value'=>'LBL_NEW_BUTTON_LABEL',
'ACL'=>'edit',
),
'SugarWidgetSubPanelAddToProspectListButton' => array(
'widget_class'=>'SugarWidgetSubPanelTopSelectButton',
'module'=>'ProspectLists',
'title'=>'LBL_ADD_TO_PROSPECT_LIST_BUTTON_LABEL',
'access_key'=>'LBL_ADD_TO_PROSPECT_LIST_BUTTON_KEY',
'form_value'=>'LBL_ADD_TO_PROSPECT_LIST_BUTTON_LABEL',
'ACL'=>'edit',
'add_to_passthru_data'=>array(
'return_type'=>'addtoprospectlist',
'parent_module'=>'ProspectLists',
'parent_type'=>'ProspectList',
'child_id'=>'target_id',
'link_attribute'=>'target_type',
'link_type'=>'polymorphic', //polymorphic or default
)
),
);
$fieldDef = $this->getFieldDef($widget_def);
if (!empty($fieldDef) && !empty($fieldDef['type']) && strtolower(trim($fieldDef['type'])) == 'multienum') {
$widget_def['widget_class'] = 'Fieldmultienum';
}
if (!empty($fieldDef) && !empty($fieldDef['type']) && strtolower(trim($fieldDef['type'])) == 'bool') {
$widget_def['widget_class'] = 'Fieldbool';
}
if ($use_default) {
switch ($widget_def['name']) {
case 'assigned_user_id':
//bug 39170 - begin
case 'created_by':
case 'modified_user_id':
//bug 39170 - end
$widget_def['widget_class'] = 'Fielduser_name';
break;
default:
if (isset($widget_def['type'])) {
$widget_def['widget_class'] = 'Field' . $widget_def['type'];
} else {
$widget_def['widget_class'] = 'Field' . $this->DBManager->getFieldType($widget_def);
}
}
}
if (!empty($widget_def['name']) && $widget_def['name'] == 'team_set_id') {
$widget_def['widget_class'] = 'Fieldteam_set_id';
}
if (empty($widget_def['widget_class'])) {
// Default the class to SugarWidgetField
$class_name = $this->widget_prefix.$this->default_widget_name;
} else {
$class_name = $this->widget_prefix.$widget_def['widget_class'];
}
// Check to see if this is one of the known class mappings.
if (!empty($class_map[$class_name])) {
if (empty($class_map[$class_name]['widget_class'])) {
$widget = new SugarWidgetSubPanelTopButton($class_map[$class_name]);
} else {
if (!class_exists($class_map[$class_name]['widget_class'])) {
require_once('include/generic/SugarWidgets/'.$class_map[$class_name]['widget_class'].'.php');
}
$widget = new $class_map[$class_name]['widget_class']($class_map[$class_name]);
}
return $widget;
}
// At this point, we have a class name and we do not have a valid class defined.
if (!class_exists($class_name)) {
// The class does not exist. Try including it.
if (file_exists('custom/include/generic/SugarWidgets/'.$class_name.'.php')) {
require_once('custom/include/generic/SugarWidgets/'.$class_name.'.php');
} else {
if (file_exists('include/generic/SugarWidgets/'.$class_name.'.php')) {
require_once('include/generic/SugarWidgets/'.$class_name.'.php');
}
}
if (!class_exists($class_name)) {
// If we still do not have a class, oops....
die("LayoutManager: Class not found:".$class_name);
}
}
$parent_bean = null;
if (isset($widget_def['parent_bean'])) {
$parent_bean = $widget_def['parent_bean'];
} elseif (isset($widget_def['focus'])) {
$parent_bean = $widget_def['focus'];
}
$widget = new $class_name($this); // cache disabled $this->getClassFromCache($class_name);
$widget->setParentBean($parent_bean);
return $widget;
}
// 27426
public function getFieldDef($widget_def)
{
static $beanCache;
if (!empty($widget_def['module']) &&!empty($GLOBALS['beanList'][$widget_def['module']]) && !empty($GLOBALS['beanFiles'][$GLOBALS['beanList'][$widget_def['module']]])) {
if (!isset($beanCache[$widget_def['module']])) {
$beanCache[$widget_def['module']] = new $GLOBALS['beanList'][$widget_def['module']]();
}
$bean = $beanCache[$widget_def['module']];
if (!empty($widget_def['name']) && !empty($bean->field_name_map) &&!empty($bean->field_name_map[$widget_def['name']])) {
return $bean->field_name_map[$widget_def['name']];
}
}
return null;
}
public function widgetDisplay($widget_def, $use_default = false, $grabName = false, $grabId = false)
{
$theclass = $this->getClassFromWidgetDef($widget_def, $use_default);
$label = isset($widget_def['module']) ? $widget_def['module'] : '';
if (is_subclass_of($theclass, 'SugarWidgetSubPanelTopButton')) {
$label = $theclass->get_subpanel_relationship_name($widget_def);
}
$theclass->setWidgetId($label);
//#27426
$fieldDef = $this->getFieldDef($widget_def);
if (!empty($fieldDef) && !empty($fieldDef['type']) && strtolower(trim($fieldDef['type'])) == 'multienum') {
$widget_def['fields'] = sugarArrayMerge($widget_def['fields'], $fieldDef);
$widget_def['fields']['module'] = $label;
}
//end
if ($grabName) {
return $theclass->getDisplayName();
}
if ($grabId) {
return $theclass->getWidgetId();
}
return $theclass->display($widget_def, null, null);
}
public function widgetQuery($widget_def, $use_default = false)
{
$theclass = $this->getClassFromWidgetDef($widget_def, $use_default);
return $theclass->query($widget_def);
}
// display an input field
// module is the parent module of the def
public function widgetDisplayInput($widget_def, $use_default = false)
{
$theclass = $this->getClassFromWidgetDef($widget_def, $use_default);
return $theclass->displayInput($widget_def);
}
}