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.
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.
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
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
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.
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.
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 ********************************************************************************/
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(
131 'multienum' => array(
156 'radioenum' => array(
205 // create or update an existing custom field
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',
216 'return' => 'tns:error_value'
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;
226 $error = new SoapError();
228 $request_arr = array(
229 'action' => 'SaveField',
230 'is_update' => 'true',
231 'module' => 'ModuleBuilder',
232 'view_module' => $module_name,
233 'view_package' => 'studio'
237 if(!validate_authenticated($session)) {
238 $error->set_error('invalid_login');
239 return $error->get_soap_array();
242 if (!is_admin($current_user)) {
243 $error->set_error('no_admin');
244 return $error->get_soap_array();
247 if(empty($beanList[$module_name])){
248 $error->set_error('no_module');
249 return $error->get_soap_array();
252 if (empty($custom_field_meta[$type])) {
253 $error->set_error('custom_field_type_not_supported');
254 return $error->get_soap_array();
257 $new_properties = array();
258 foreach($properties as $value) {
259 $new_properties[$value['name']] = $value['value'];
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();
268 $request_arr[$property] = $new_properties[$property];
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);
276 require_once('include/MVC/Controller/SugarController.php');
277 require_once('modules/ModuleBuilder/controller.php');
278 require_once('modules/ModuleBuilder/parsers/ParserFactory.php');
280 $mbc = new ModuleBuilderController();
282 $mbc->action_SaveField();
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']
291 if (isset($new_properties['customCode'])) {
292 $layout_properties['customCode'] = $new_properties['customCode'];
294 if (isset($new_properties['customLabel'])) {
295 $layout_properties['customLabel'] = $new_properties['customLabel'];
298 // add the field to the DetailView
299 $parser = ParserFactory::getParser('layoutview', FALSE);
300 $parser->init($module_name, 'DetailView', FALSE);
302 $parser->_addField($layout_properties);
303 $parser->writeWorkingFile();
304 $parser->handleSave();
308 // add the field to the EditView
309 $parser = ParserFactory::getParser('layoutview', FALSE);
310 $parser->init($module_name, 'EditView', FALSE);
312 $parser->_addField($layout_properties);
313 $parser->writeWorkingFile();
314 $parser->handleSave();
317 return $error->get_soap_array();