2 /*********************************************************************************
3 * SugarCRM Community Edition is a customer relationship management program developed by
4 * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
6 * This program is free software; you can redistribute it and/or modify it under
7 * the terms of the GNU Affero General Public License version 3 as published by the
8 * Free Software Foundation with the addition of the following permission added
9 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
11 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
18 * You should have received a copy of the GNU Affero General Public License along with
19 * this program; if not, see http://www.gnu.org/licenses or write to the Free
20 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
24 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
26 * The interactive user interfaces in modified source and object code versions
27 * of this program must display Appropriate Legal Notices, as required under
28 * Section 5 of the GNU Affero General Public License version 3.
30 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31 * these Appropriate Legal Notices must retain the display of the "Powered by
32 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
33 * technical reasons, the Appropriate Legal Notices must display the words
34 * "Powered by SugarCRM".
35 ********************************************************************************/
37 require_once('modules/ModuleBuilder/MB/AjaxCompose.php');
38 require_once('modules/ModuleBuilder/views/view.modulefield.php');
40 class ViewModulefields extends SugarView
45 * @see SugarView::_getModuleTitleParams()
47 protected function _getModuleTitleParams($browserTitle = false)
52 translate('LBL_MODULE_NAME','Administration'),
53 ModuleBuilderController::getModuleTitle(),
59 $smarty = new Sugar_Smarty();
61 $bak_mod_strings=$mod_strings;
62 $smarty->assign('mod_strings', $mod_strings);
64 $module_name = $_REQUEST['view_module'];
66 global $current_language;
67 $module_strings = return_module_language($current_language, $module_name);
69 $fieldsData = array();
70 $customFieldsData = array();
72 if(!isset($_REQUEST['view_package']) || $_REQUEST['view_package'] == 'studio') {
73 //$this->loadPackageHelp($module_name);
74 $studioClass = new stdClass;
75 $studioClass->name = $module_name;
78 $objectName = $beanList[$module_name];
80 if($objectName == 'aCase') // Bug 17614 - renamed aCase as Case in vardefs for backwards compatibililty with 451 modules
83 VardefManager::loadVardef($module_name, $objectName, true);
85 $f = array($mod_strings['LBL_HCUSTOM']=>array(), $mod_strings['LBL_HDEFAULT']=>array());
87 // TODO: replace this section to select fields to list with the algorithm in AbstractMetaDataImplmentation::validField()
88 $def = $this->cullFields($dictionary[$objectName]['fields']);
90 foreach($dictionary[$objectName]['fields'] as $def) {
91 if ($this->isValidStudioField($def))
93 $def['label'] = isset($module_strings[$def['vname']]) ? $module_strings[$def['vname']] : $def['vname'];
94 //Custom relate fields will have a non-db source, but custom_module set
95 if(isset($def['source']) && $def['source'] == 'custom_fields' || isset($def['custom_module'])) {
96 $f[$mod_strings['LBL_HCUSTOM']][$def['name']] = $def;
97 $def['custom'] = true;
99 $f[$mod_strings['LBL_HDEFAULT']][$def['name']] = $def;
100 $def['custom'] = false;
103 $fieldsData[] = $def;
104 $customFieldsData[$def['name']] = $def['custom'];
107 $studioClass->mbvardefs->vardefs['fields'] = $f;
108 $smarty->assign('module', $studioClass);
110 $package = new stdClass;
112 $smarty->assign('package', $package);
113 global $current_user;
114 $sortPreferences = $current_user->getPreference('fieldsTableColumn', 'ModuleBuilder');
115 $smarty->assign('sortPreferences', $sortPreferences);
116 $smarty->assign('fieldsData', getJSONobj()->encode($fieldsData));
117 $smarty->assign('customFieldsData', getJSONobj()->encode($customFieldsData));
118 $smarty->assign('studio', true);
119 $ajax = new AjaxCompose();
120 $ajax->addCrumb($mod_strings['LBL_STUDIO'], 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard")');
121 $ajax->addCrumb(translate($module_name), 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard&view_module='.$module_name.'")');
122 $ajax->addCrumb($mod_strings['LBL_FIELDS'], '');
123 $ajax->addSection('center', $mod_strings['LBL_EDIT_FIELDS'],$smarty->fetch('modules/ModuleBuilder/tpls/MBModule/fields.tpl'));
124 $_REQUEST['field'] = '';
126 echo $ajax->getJavascript();
128 require_once('modules/ModuleBuilder/MB/ModuleBuilder.php');
129 $mb = new ModuleBuilder();
130 $mb->getPackage($_REQUEST['view_package']);
131 $package = $mb->packages[$_REQUEST['view_package']];
133 $package->getModule($module_name);
134 $this->mbModule = $package->modules[$module_name];
135 $this->loadPackageHelp($module_name);
136 $this->mbModule->getVardefs(true);
137 $this->mbModule->mbvardefs->vardefs['fields'] = array_reverse($this->mbModule->mbvardefs->vardefs['fields'], true);
138 $loadedFields = array();
140 if(file_exists($this->mbModule->path. '/language/'.$current_language.'.lang.php'))
142 include($this->mbModule->path .'/language/'.$current_language.'.lang.php');
143 $this->mbModule->setModStrings($current_language,$mod_strings);
144 }elseif(file_exists($this->mbModule->path. '/language/en_us.lang.php')){
145 include($this->mbModule->path .'/language/en_us.lang.php');
146 $this->mbModule->setModStrings('en_us',$mod_strings);
149 foreach($this->mbModule->mbvardefs->vardefs['fields'] as $k=>$v)
151 if($k != $module_name)
153 $titleLBL[$k]=translate("LBL_".strtoupper($k),'ModuleBuilder');
157 foreach($v as $field => $def)
159 if (isset($loadedFields[$field]))
161 unset($this->mbModule->mbvardefs->vardefs['fields'][$k][$field]);
163 $this->mbModule->mbvardefs->vardefs['fields'][$k][$field]['label'] = isset($def['vname']) && isset($this->mbModule->mblanguage->strings[$current_language][$def['vname']]) ? $this->mbModule->mblanguage->strings[$current_language][$def['vname']] : $field;
164 $customFieldsData[$field] = ($k == $this->mbModule->name) ? true : false;
165 $loadedFields[$field] = true;
166 $fieldsData[] = $this->mbModule->mbvardefs->vardefs['fields'][$k][$field];
171 $this->mbModule->mbvardefs->vardefs['fields'][$module_name] = $this->cullFields($this->mbModule->mbvardefs->vardefs['fields'][$module_name]);
173 $smarty->assign('fieldsData', getJSONobj()->encode($fieldsData));
174 $smarty->assign('customFieldsData', getJSONobj()->encode($customFieldsData));
175 global $current_user;
176 $sortPreferences = $current_user->getPreference('fieldsTableColumn', 'ModuleBuilder');
177 $smarty->assign('sortPreferences', $sortPreferences);
178 $smarty->assign('title', $titleLBL);
179 $smarty->assign('package', $package);
180 $smarty->assign('module', $this->mbModule);
181 $smarty->assign('editLabelsMb','1');
182 $smarty->assign('studio', false);
184 $ajax = new AjaxCompose();
185 $ajax->addCrumb($bak_mod_strings['LBL_MODULEBUILDER'], 'ModuleBuilder.main("mb")');
186 $ajax->addCrumb($package->name,'ModuleBuilder.getContent("module=ModuleBuilder&action=package&package='.$package->name.'")');
187 $ajax->addCrumb($module_name, 'ModuleBuilder.getContent("module=ModuleBuilder&action=module&view_package='.$package->name.'&view_module='. $module_name . '")');
188 $ajax->addCrumb($bak_mod_strings['LBL_FIELDS'], '');
189 $ajax->addSection('center', $bak_mod_strings["LBL_FIELDS"],$smarty->fetch('modules/ModuleBuilder/tpls/MBModule/fields.tpl'));
190 $_REQUEST['field'] = '';
192 echo $ajax->getJavascript();
198 function loadPackageHelp(
202 $this->mbModule->help['default'] = (empty($name))?'create':'modify';
203 $this->mbModule->help['group'] = 'module';
204 $this->mbModule->help['group'] = 'module';
211 if(!empty($def['parent_id']))
212 unset($def['parent_id']);
213 if(!empty($def['parent_type']))
214 unset($def['parent_type']);
215 if(!empty($def['currency_id']))
216 unset($def['currency_id']);
220 function isValidStudioField(
224 if (isset($def['studio'])) {
225 if (is_array($def [ 'studio' ]))
227 if (isset($def['studio']['editField']) && $def['studio']['editField'] == true)
229 if (isset($def['studio']['required']) && $def['studio']['required'])
234 if ($def['studio'] == 'visible')
236 if ($def['studio'] == 'hidden' || $def['studio'] == 'false' || !$def['studio'] )
240 if (empty($def ['source']) || $def ['source'] == 'db' || $def ['source'] == 'custom_fields')
242 if ($def ['type'] != 'id' && (empty($def ['dbType']) || $def ['dbType'] != 'id'))