forked from salesagility/SuiteCRM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SoapStudio.php
executable file
·325 lines (301 loc) · 8.67 KB
/
SoapStudio.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
<?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 [email protected].
*
* 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".
*/
// this is a list of what values are expected for a given custom field type
// will eventually be moved to the SugarFields classes
$custom_field_meta = array(
'address' => array(
'default',
'duplicate_merge',
'help',
'label',
'label_value',
'len',
'name',
'reportable'
),
'bool' => array(
'duplicate_merge',
'help',
'label',
'label_value',
'name',
'reportable'
),
'currency' => array(
'duplicate_merge',
'help',
'label',
'label_value',
'name',
'reportable'
),
'date' => array(
'audited',
'default_value',
'duplicate_merge',
'help',
'label',
'label_value',
'massupdate',
'name',
'reportable',
'required'
),
'enum' => array(
'audited',
'default',
'duplicate_merge',
'help',
'label',
'label_value',
'massupdate',
'name',
'options',
'reportable',
'required'
),
'float' => array(
'audited',
'default',
'duplicate_merge',
'help',
'label',
'label_value',
'len',
'name',
'precision',
'reportable',
'required'
),
'html' => array(
'audited',
'duplicate_merge',
'ext4',
'help',
'label',
'label_value',
'name',
'reportable',
'required'
),
'int' => array(
'audited',
'default',
'duplicate_merge',
'help',
'label',
'label_value',
'len',
'max',
'min',
'name',
'reportable',
'required'
),
'multienum' => array(
'audited',
'default',
'duplicate_merge',
'help',
'label',
'label_value',
'massupdate',
'name',
'options',
'reportable',
'required'
),
'phone' => array(
'audited',
'default',
'duplicate_merge',
'help',
'label',
'label_value',
'len',
'name',
'reportable',
'required'
),
'radioenum' => array(
'audited',
'default',
'duplicate_merge',
'help',
'label',
'label_value',
'massupdate',
'name',
'options',
'reportable',
'required'
),
'relate' => array(
'audited',
'duplicate_merge',
'ext2',
'help',
'label',
'label_value',
'name',
'reportable',
'required'
),
'text' => array(
'audited',
'default',
'duplicate_merge',
'help',
'label',
'label_value',
'name',
'reportable',
'required'
),
'varchar' => array(
'audited',
'default',
'duplicate_merge',
'help',
'label',
'label_value',
'len',
'name',
'reportable',
'required'
)
);
// create or update an existing custom field
$server->register(
'set_custom_field',
array(
'session' => 'xsd:string',
'module_name' => 'xsd:string',
'type' => 'xsd:string',
'properties' => 'tns:name_value_list',
'add_to_layout' => 'xsd:int',
),
array(
'return' => 'tns:error_value'
),
$NAMESPACE
);
function set_custom_field($session, $module_name, $type, $properties, $add_to_layout)
{
global $current_user;
global $beanList, $beanFiles;
global $custom_field_meta;
$error = new SoapError();
$request_arr = array(
'action' => 'SaveField',
'is_update' => 'true',
'module' => 'ModuleBuilder',
'view_module' => $module_name,
'view_package' => 'studio'
);
// ERROR CHECKING
if (!validate_authenticated($session)) {
$error->set_error('invalid_login');
return $error->get_soap_array();
}
if (!is_admin($current_user)) {
$error->set_error('no_admin');
return $error->get_soap_array();
}
if (empty($beanList[$module_name])) {
$error->set_error('no_module');
return $error->get_soap_array();
}
if (empty($custom_field_meta[$type])) {
$error->set_error('custom_field_type_not_supported');
return $error->get_soap_array();
}
$new_properties = array();
foreach ($properties as $value) {
$new_properties[$value['name']] = $value['value'];
}
foreach ($custom_field_meta[$type] as $property) {
if (!isset($new_properties[$property])) {
$error->set_error('custom_field_property_not_supplied');
return $error->get_soap_array();
}
$request_arr[$property] = $new_properties[$property];
}
// $request_arr should now contain all the necessary information to create a custom field
// merge $request_arr with $_POST/$_REQUEST, where the action_saveField() method expects them
$_REQUEST = array_merge($_REQUEST, $request_arr);
$_POST = array_merge($_POST, $request_arr);
require_once('include/MVC/Controller/SugarController.php');
require_once('modules/ModuleBuilder/controller.php');
require_once('modules/ModuleBuilder/parsers/ParserFactory.php');
$mbc = new ModuleBuilderController();
$mbc->setup();
$mbc->action_SaveField();
// add the field to the given module's EditView and DetailView layouts
if ($add_to_layout == 1) {
$layout_properties = array(
'name' => $new_properties['name'],
'label' => $new_properties['label']
);
if (isset($new_properties['customCode'])) {
$layout_properties['customCode'] = $new_properties['customCode'];
}
if (isset($new_properties['customLabel'])) {
$layout_properties['customLabel'] = $new_properties['customLabel'];
}
// add the field to the DetailView
$parser = ParserFactory::getParser('layoutview', false);
$parser->init($module_name, 'DetailView', false);
$parser->_addField($layout_properties);
$parser->writeWorkingFile();
$parser->handleSave();
unset($parser);
// add the field to the EditView
$parser = ParserFactory::getParser('layoutview', false);
$parser->init($module_name, 'EditView', false);
$parser->_addField($layout_properties);
$parser->writeWorkingFile();
$parser->handleSave();
}
return $error->get_soap_array();
}