]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - soap/SoapStudio.php
Release 6.5.0
[Github/sugarcrm.git] / soap / SoapStudio.php
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-2012 SugarCRM Inc.
6  * 
7  * This program is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU Affero General Public License version 3 as published by the
9  * Free Software Foundation with the addition of the following permission added
10  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
11  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
12  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
13  * 
14  * This program is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
17  * details.
18  * 
19  * You should have received a copy of the GNU Affero General Public License along with
20  * this program; if not, see http://www.gnu.org/licenses or write to the Free
21  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22  * 02110-1301 USA.
23  * 
24  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
25  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
26  * 
27  * The interactive user interfaces in modified source and object code versions
28  * of this program must display Appropriate Legal Notices, as required under
29  * Section 5 of the GNU Affero General Public License version 3.
30  * 
31  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
32  * these Appropriate Legal Notices must retain the display of the "Powered by
33  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
34  * technical reasons, the Appropriate Legal Notices must display the words
35  * "Powered by SugarCRM".
36  ********************************************************************************/
37
38
39 // this is a list of what values are expected for a given custom field type
40 // will eventually be moved to the SugarFields classes
41 $custom_field_meta = array(
42         'address' => array(
43                 'default',
44                 'duplicate_merge',
45                 'help',
46                 'label',
47                 'label_value',
48                 'len',
49                 'name',
50                 'reportable'
51         ),
52         'bool' => array(
53                 'duplicate_merge',
54                 'help',
55                 'label',
56                 'label_value',
57                 'name',
58                 'reportable'
59         ),
60         'currency' => array(
61                 'duplicate_merge',
62                 'help',
63                 'label',
64                 'label_value',
65                 'name',
66                 'reportable'
67         ),
68         'date' => array(
69                 'audited',
70                 'default_value',
71                 'duplicate_merge',
72                 'help',
73                 'label',
74                 'label_value',
75                 'massupdate',
76                 'name',
77                 'reportable',
78                 'required'
79         ),
80         'enum' => array(
81                 'audited',
82                 'default',
83                 'duplicate_merge',
84                 'help',
85                 'label',
86                 'label_value',
87                 'massupdate',
88                 'name',
89                 'options',
90                 'reportable',
91                 'required'
92         ),
93         'float' => array(
94                 'audited',
95                 'default',
96                 'duplicate_merge',
97                 'help',
98                 'label',
99                 'label_value',
100                 'len',
101                 'name',
102                 'precision',
103                 'reportable',
104                 'required'
105         ),
106         'html' => array(
107                 'audited',
108                 'duplicate_merge',
109                 'ext4',
110                 'help',
111                 'label',
112                 'label_value',
113                 'name',
114                 'reportable',
115                 'required'
116         ),
117         'int' => array(
118                 'audited',
119                 'default',
120                 'duplicate_merge',
121                 'help',
122                 'label',
123                 'label_value',
124                 'len',
125                 'max',
126                 'min',
127                 'name',
128                 'reportable',
129                 'required'
130         ),
131         'multienum' => array(
132                 'audited',
133                 'default',
134                 'duplicate_merge',
135                 'help',
136                 'label',
137                 'label_value',
138                 'massupdate',
139                 'name',
140                 'options',
141                 'reportable',
142                 'required'
143         ),
144         'phone' => array(
145                 'audited',
146                 'default',
147                 'duplicate_merge',
148                 'help',
149                 'label',
150                 'label_value',
151                 'len',
152                 'name',
153                 'reportable',
154                 'required'
155         ),
156         'radioenum' => array(
157                 'audited',
158                 'default',
159                 'duplicate_merge',
160                 'help',
161                 'label',
162                 'label_value',
163                 'massupdate',
164                 'name',
165                 'options',
166                 'reportable',
167                 'required'
168         ),
169         'relate' => array(
170                 'audited',
171                 'duplicate_merge',
172                 'ext2',
173                 'help',
174                 'label',
175                 'label_value',
176                 'name',
177                 'reportable',
178                 'required'
179         ),
180         'text' => array(
181                 'audited',
182                 'default',
183                 'duplicate_merge',
184                 'help',
185                 'label',
186                 'label_value',
187                 'name',
188                 'reportable',
189                 'required'
190         ),
191         'varchar' => array(
192                 'audited',
193                 'default',
194                 'duplicate_merge',
195                 'help',
196                 'label',
197                 'label_value',
198                 'len',
199                 'name',
200                 'reportable',
201                 'required'
202         )
203 );
204
205 // create or update an existing custom field
206 $server->register(
207         'set_custom_field',
208         array(
209                 'session' => 'xsd:string',
210                 'module_name' => 'xsd:string',
211                 'type' => 'xsd:string',
212                 'properties' => 'tns:name_value_list',
213                 'add_to_layout' => 'xsd:int',
214         ),
215         array(
216                 'return' => 'tns:error_value'
217         ),
218         $NAMESPACE
219 );
220
221 function set_custom_field($session, $module_name, $type, $properties, $add_to_layout) {
222         global $current_user;
223         global $beanList, $beanFiles;
224         global $custom_field_meta;
225
226         $error = new SoapError();
227
228         $request_arr = array(
229                 'action' => 'SaveField',
230                 'is_update' => 'true',
231                 'module' => 'ModuleBuilder',
232                 'view_module' => $module_name,
233                 'view_package' => 'studio'
234         );
235
236         // ERROR CHECKING
237         if(!validate_authenticated($session)) {
238                 $error->set_error('invalid_login');
239                 return $error->get_soap_array();
240         }
241
242         if (!is_admin($current_user)) {
243                 $error->set_error('no_admin');
244                 return $error->get_soap_array();
245         }
246
247         if(empty($beanList[$module_name])){
248                 $error->set_error('no_module');
249                 return $error->get_soap_array();
250         }
251
252         if (empty($custom_field_meta[$type])) {
253                 $error->set_error('custom_field_type_not_supported');
254                 return $error->get_soap_array();
255         }
256
257         $new_properties = array();
258         foreach($properties as $value) {
259                 $new_properties[$value['name']] = $value['value'];
260         }
261
262         foreach ($custom_field_meta[$type] as $property) {
263                 if (!isset($new_properties[$property])) {
264                         $error->set_error('custom_field_property_not_supplied');
265                         return $error->get_soap_array();
266                 }
267
268                 $request_arr[$property] = $new_properties[$property];
269         }
270
271         // $request_arr should now contain all the necessary information to create a custom field
272         // merge $request_arr with $_POST/$_REQUEST, where the action_saveField() method expects them
273         $_REQUEST = array_merge($_REQUEST, $request_arr);
274         $_POST = array_merge($_POST, $request_arr);
275
276         require_once('include/MVC/Controller/SugarController.php');
277         require_once('modules/ModuleBuilder/controller.php');
278         require_once('modules/ModuleBuilder/parsers/ParserFactory.php');
279
280         $mbc = new ModuleBuilderController();
281         $mbc->setup();
282         $mbc->action_SaveField();
283
284         // add the field to the given module's EditView and DetailView layouts
285         if ($add_to_layout == 1) {
286                 $layout_properties = array(
287                         'name' => $new_properties['name'],
288                         'label' => $new_properties['label']
289                 );
290
291                 if (isset($new_properties['customCode'])) {
292                         $layout_properties['customCode'] = $new_properties['customCode'];
293                 }
294                 if (isset($new_properties['customLabel'])) {
295                         $layout_properties['customLabel'] = $new_properties['customLabel'];
296                 }
297
298                 // add the field to the DetailView
299                 $parser = ParserFactory::getParser('layoutview', FALSE);
300                 $parser->init($module_name, 'DetailView', FALSE);
301
302                 $parser->_addField($layout_properties);
303                 $parser->writeWorkingFile();
304                 $parser->handleSave();
305
306                 unset($parser);
307
308                 // add the field to the EditView
309                 $parser = ParserFactory::getParser('layoutview', FALSE);
310                 $parser->init($module_name, 'EditView', FALSE);
311
312                 $parser->_addField($layout_properties);
313                 $parser->writeWorkingFile();
314                 $parser->handleSave();
315         }
316
317         return $error->get_soap_array();
318 }
319 ?>