]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/ModuleBuilder/views/view.modulefields.php
Release 6.4.0
[Github/sugarcrm.git] / modules / ModuleBuilder / views / view.modulefields.php
1 <?php
2 /*********************************************************************************
3  * SugarCRM Community Edition is a customer relationship management program developed by
4  * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
5  * 
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.
12  * 
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
16  * details.
17  * 
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
21  * 02110-1301 USA.
22  * 
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.
25  * 
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.
29  * 
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  ********************************************************************************/
36
37 require_once('modules/ModuleBuilder/MB/AjaxCompose.php');
38 require_once('modules/ModuleBuilder/views/view.modulefield.php');
39  
40 class ViewModulefields extends SugarView
41 {
42     var $mbModule;
43     
44     /**
45          * @see SugarView::_getModuleTitleParams()
46          */
47         protected function _getModuleTitleParams($browserTitle = false)
48         {
49             global $mod_strings;
50             
51         return array(
52            translate('LBL_MODULE_NAME','Administration'),
53            ModuleBuilderController::getModuleTitle(),
54            );
55     }
56
57         function display()
58         {
59         $smarty = new Sugar_Smarty();
60         global $mod_strings;
61         $bak_mod_strings=$mod_strings;
62         $smarty->assign('mod_strings', $mod_strings);
63
64         $module_name = $_REQUEST['view_module'];
65
66         global $current_language;
67         $module_strings = return_module_language($current_language, $module_name);
68
69         $fieldsData = array();
70         $customFieldsData = array();
71
72         //use fieldTypes variable to map field type to displayed field type
73         $fieldTypes = $mod_strings['fieldTypes'];
74         //add datetimecombo type field from the vardef overrides to point to Datetime type
75         $fieldTypes['datetime'] = $fieldTypes['datetimecombo'];
76
77         if(!isset($_REQUEST['view_package']) || $_REQUEST['view_package'] == 'studio') {
78             //$this->loadPackageHelp($module_name);
79             $studioClass = new stdClass;
80             $studioClass->name = $module_name;
81
82             $objectName = BeanFactory::getObjectName($module_name);
83
84             VardefManager::loadVardef($module_name, $objectName, true);
85             global $dictionary;
86             $f = array($mod_strings['LBL_HCUSTOM']=>array(), $mod_strings['LBL_HDEFAULT']=>array());
87
88             foreach($dictionary[$objectName]['fields'] as $def) {
89                 if ($this->isValidStudioField($def))
90                 {
91                     $def['label'] = translate($def['vname'], $module_name);
92                                         //Custom relate fields will have a non-db source, but custom_module set
93                         if(isset($def['source']) && $def['source'] == 'custom_fields' || isset($def['custom_module'])) {
94                        $f[$mod_strings['LBL_HCUSTOM']][$def['name']] = $def;
95                        $def['custom'] = true;
96                     } else {
97                        $f[$mod_strings['LBL_HDEFAULT']][$def['name']] = $def;
98                        $def['custom'] = false;
99                     }
100
101                     $def['type'] = isset($fieldTypes[$def['type']]) ? $fieldTypes[$def['type']] : ucfirst($def['type']);
102                     $fieldsData[] = $def;
103                     $customFieldsData[$def['name']] = $def['custom'];
104                 }
105             }
106             $studioClass->mbvardefs->vardefs['fields'] = $f;
107             $smarty->assign('module', $studioClass);
108
109             $package = new stdClass;
110             $package->name = '';
111             $smarty->assign('package', $package);
112             global $current_user;
113             $sortPreferences = $current_user->getPreference('fieldsTableColumn', 'ModuleBuilder');
114             $smarty->assign('sortPreferences', $sortPreferences);
115             $smarty->assign('fieldsData', getJSONobj()->encode($fieldsData));
116             $smarty->assign('customFieldsData', getJSONobj()->encode($customFieldsData));
117             $smarty->assign('studio', true);
118             $ajax = new AjaxCompose();
119             $ajax->addCrumb($mod_strings['LBL_STUDIO'], 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard")');
120             $ajax->addCrumb(translate($module_name), 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard&view_module='.$module_name.'")');
121             $ajax->addCrumb($mod_strings['LBL_FIELDS'], '');
122             $ajax->addSection('center', $mod_strings['LBL_EDIT_FIELDS'],$smarty->fetch('modules/ModuleBuilder/tpls/MBModule/fields.tpl'));
123             $_REQUEST['field'] = '';
124
125             echo $ajax->getJavascript();
126         } else {
127             require_once('modules/ModuleBuilder/MB/ModuleBuilder.php');
128             $mb = new ModuleBuilder();
129             $mb->getPackage($_REQUEST['view_package']);
130             $package = $mb->packages[$_REQUEST['view_package']];
131
132             $package->getModule($module_name);
133             $this->mbModule = $package->modules[$module_name];
134             $this->loadPackageHelp($module_name);
135             $this->mbModule->getVardefs(true);
136             $this->mbModule->mbvardefs->vardefs['fields'] = array_reverse($this->mbModule->mbvardefs->vardefs['fields'], true);
137             $loadedFields = array();
138
139             if(file_exists($this->mbModule->path. '/language/'.$current_language.'.lang.php'))
140             {
141                 include($this->mbModule->path .'/language/'.$current_language.'.lang.php');
142                 $this->mbModule->setModStrings($current_language,$mod_strings);
143             }elseif(file_exists($this->mbModule->path. '/language/en_us.lang.php')){
144                 include($this->mbModule->path .'/language/en_us.lang.php');
145                 $this->mbModule->setModStrings('en_us',$mod_strings);
146             }
147
148             foreach($this->mbModule->mbvardefs->vardefs['fields'] as $k=>$v)
149             {
150                 if($k != $module_name)
151                 {
152                     $titleLBL[$k]=translate("LBL_".strtoupper($k),'ModuleBuilder');
153                 }else{
154                     $titleLBL[$k]=$k;
155                 }
156                 foreach($v as $field => $def)
157                 {
158                         if (isset($loadedFields[$field]))
159                     {
160                            unset($this->mbModule->mbvardefs->vardefs['fields'][$k][$field]);
161                     } else {
162                        $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;
163                        $customFieldsData[$field] = ($k == $this->mbModule->name) ? true : false;
164                        $loadedFields[$field] = true;
165                         
166                        $type = $this->mbModule->mbvardefs->vardefs['fields'][$k][$field]['type'];
167                        $this->mbModule->mbvardefs->vardefs['fields'][$k][$field]['type'] = isset($fieldTypes[$type]) ? $fieldTypes[$type] : ucfirst($type);
168                        $fieldsData[] = $this->mbModule->mbvardefs->vardefs['fields'][$k][$field];
169                     }
170                 }
171             }
172
173             $this->mbModule->mbvardefs->vardefs['fields'][$module_name] = $this->cullFields($this->mbModule->mbvardefs->vardefs['fields'][$module_name]);
174
175             $smarty->assign('fieldsData', getJSONobj()->encode($fieldsData));
176             $smarty->assign('customFieldsData', getJSONobj()->encode($customFieldsData));
177             global $current_user;
178             $sortPreferences = $current_user->getPreference('fieldsTableColumn', 'ModuleBuilder');
179             $smarty->assign('sortPreferences', $sortPreferences);
180             $smarty->assign('title', $titleLBL);
181             $smarty->assign('package', $package);
182             $smarty->assign('module', $this->mbModule);
183             $smarty->assign('editLabelsMb','1');
184             $smarty->assign('studio', false);
185
186             $ajax = new AjaxCompose();
187             $ajax->addCrumb($bak_mod_strings['LBL_MODULEBUILDER'], 'ModuleBuilder.main("mb")');
188             $ajax->addCrumb($package->name,'ModuleBuilder.getContent("module=ModuleBuilder&action=package&package='.$package->name.'")');
189             $ajax->addCrumb($module_name, 'ModuleBuilder.getContent("module=ModuleBuilder&action=module&view_package='.$package->name.'&view_module='. $module_name . '")');
190             $ajax->addCrumb($bak_mod_strings['LBL_FIELDS'], '');
191             $ajax->addSection('center', $bak_mod_strings["LBL_FIELDS"],$smarty->fetch('modules/ModuleBuilder/tpls/MBModule/fields.tpl'));
192             $_REQUEST['field'] = '';
193
194             echo $ajax->getJavascript();
195
196
197         }
198     }
199
200     function loadPackageHelp(
201         $name
202         )
203     {
204         $this->mbModule->help['default'] = (empty($name))?'create':'modify';
205         $this->mbModule->help['group'] = 'module';
206         $this->mbModule->help['group'] = 'module';
207     }
208
209     function cullFields(
210         $def
211         )
212     {
213         if(!empty($def['parent_id']))
214             unset($def['parent_id']);
215         if(!empty($def['parent_type']))
216             unset($def['parent_type']);
217         if(!empty($def['currency_id']))
218             unset($def['currency_id']);
219         return $def;
220     }
221         
222     function isValidStudioField(
223         $def
224         )
225         {
226         if (isset($def['studio'])) {
227             if (is_array($def [ 'studio' ]))
228             {
229                         if (isset($def['studio']['editField']) && $def['studio']['editField'] == true)
230                     return true;
231                         if (isset($def['studio']['required']) && $def['studio']['required'])
232                     return true;
233                     
234                 } else
235                 {
236                         if ($def['studio'] == 'visible')
237                     return true;
238                 if ($def['studio'] == 'hidden' || $def['studio'] == 'false' || !$def['studio'] )
239                     return false;
240             }
241         }
242         if (empty($def ['source']) || $def ['source'] == 'db' || $def ['source'] == 'custom_fields')
243                 {
244                 if ($def ['type'] != 'id' && (empty($def ['dbType']) || $def ['dbType'] != 'id'))
245                   return true;
246                 }
247                 
248                 return false;
249         }
250 }