]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/ModuleBuilder/views/view.modulefields.php
Release 6.2.1
[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         if(! isset($_REQUEST['view_package']) || $_REQUEST['view_package'] == 'studio') {
67             //$this->loadPackageHelp($module_name);
68             $studioClass = new stdClass;
69             $studioClass->name = $module_name;
70             
71             global $beanList;
72             $objectName = $beanList[$module_name];
73             
74             if($objectName == 'aCase') // Bug 17614 - renamed aCase as Case in vardefs for backwards compatibililty with 451 modules
75                 $objectName = 'Case';
76                 
77             VardefManager::loadVardef($module_name, $objectName, true);
78             global $dictionary;
79             $f = array($mod_strings['LBL_HCUSTOM']=>array(), $mod_strings['LBL_HDEFAULT']=>array());
80
81             // TODO: replace this section to select fields to list with the algorithm in AbstractMetaDataImplmentation::validField()
82             $def = $this->cullFields($dictionary[$objectName]['fields']);
83             
84             foreach($dictionary[$objectName]['fields'] as $def) {
85                 if ($this->isValidStudioField($def))
86                 {
87                                         //Custom relate fields will have a non-db source, but custom_module set
88                         if(isset($def['source']) && $def['source'] == 'custom_fields' || isset($def['custom_module'])) {
89                        $f[$mod_strings['LBL_HCUSTOM']][$def['name']] = $def;
90                     } else {
91                        $f[$mod_strings['LBL_HDEFAULT']][$def['name']] = $def;
92                     }
93                 }
94             }
95             $studioClass->mbvardefs->vardefs['fields'] = $f;
96             $smarty->assign('module', $studioClass);
97
98             $package = new stdClass;
99             $package->name = '';
100             $smarty->assign('package', $package);
101             $ajax = new AjaxCompose();
102             $ajax->addCrumb($mod_strings['LBL_STUDIO'], 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard")');
103             $ajax->addCrumb(translate($module_name), 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard&view_module='.$module_name.'")');
104             $ajax->addCrumb($mod_strings['LBL_FIELDS'], '');
105             $ajax->addSection('center', $mod_strings['LBL_EDIT_FIELDS'],$smarty->fetch('modules/ModuleBuilder/tpls/MBModule/fields.tpl'));
106             $_REQUEST['field'] = '';
107
108             echo $ajax->getJavascript();
109         } else {
110             require_once('modules/ModuleBuilder/MB/ModuleBuilder.php');
111             $mb = new ModuleBuilder();
112             $mb->getPackage($_REQUEST['view_package']);
113             $package = $mb->packages[$_REQUEST['view_package']];
114
115             $package->getModule($module_name);
116             $this->mbModule = $package->modules[$module_name];
117             $this->loadPackageHelp($module_name);
118             $this->mbModule->getVardefs(true);
119             $this->mbModule->mbvardefs->vardefs['fields'] = array_reverse($this->mbModule->mbvardefs->vardefs['fields'], true);
120             $loadedFields = array();
121             foreach($this->mbModule->mbvardefs->vardefs['fields'] as $k=>$v){
122                 if($k != $module_name)
123                     $titleLBL[$k]=translate("LBL_".strtoupper($k),'ModuleBuilder');
124                 else{
125                     $titleLBL[$k]=$k;
126                 }
127                 foreach($v as $field => $def)
128                 {
129                         if (isset($loadedFields[$field]))
130                                 unset($this->mbModule->mbvardefs->vardefs['fields'][$k][$field]);
131                         else
132                            $loadedFields[$field] = true;
133                 }
134             }
135             $this->mbModule->mbvardefs->vardefs['fields'][$module_name] = $this->cullFields($this->mbModule->mbvardefs->vardefs['fields'][$module_name]);
136             if(file_exists($this->mbModule->path. '/language/'.$GLOBALS['current_language'].'.lang.php')){
137                 include($this->mbModule->path .'/language/'. $GLOBALS['current_language'].'.lang.php');
138                 $this->mbModule->setModStrings($GLOBALS['current_language'],$mod_strings);
139             }
140             elseif(file_exists($this->mbModule->path. '/language/en_us.lang.php')){
141                 include($this->mbModule->path .'/language/en_us.lang.php');
142                 $this->mbModule->setModStrings('en_us',$mod_strings);
143             }
144             $smarty->assign('title', $titleLBL);
145             $smarty->assign('package', $package);
146             $smarty->assign('module', $this->mbModule);
147             $smarty->assign('editLabelsMb','1'); //need to merge MB labels and studio labels. quick fix for now.
148
149
150             $ajax = new AjaxCompose();
151             $ajax->addCrumb($bak_mod_strings['LBL_MODULEBUILDER'], 'ModuleBuilder.main("mb")');
152             $ajax->addCrumb($package->name,'ModuleBuilder.getContent("module=ModuleBuilder&action=package&package='.$package->name.'")');
153             $ajax->addCrumb($module_name, 'ModuleBuilder.getContent("module=ModuleBuilder&action=module&view_package='.$package->name.'&view_module='. $module_name . '")');
154             $ajax->addCrumb($bak_mod_strings['LBL_FIELDS'], '');
155             $ajax->addSection('center', $bak_mod_strings["LBL_FIELDS"],$smarty->fetch('modules/ModuleBuilder/tpls/MBModule/fields.tpl'));
156             $_REQUEST['field'] = '';
157
158             echo $ajax->getJavascript();
159
160
161         }
162     }
163
164     function loadPackageHelp(
165         $name
166         )
167     {
168         $this->mbModule->help['default'] = (empty($name))?'create':'modify';
169         $this->mbModule->help['group'] = 'module';
170         $this->mbModule->help['group'] = 'module';
171     }
172
173     function cullFields(
174         $def
175         )
176     {
177         if(!empty($def['parent_id']))
178             unset($def['parent_id']);
179         if(!empty($def['parent_type']))
180             unset($def['parent_type']);
181         if(!empty($def['currency_id']))
182             unset($def['currency_id']);
183         return $def;
184     }
185         
186     function isValidStudioField(
187         $def
188         )
189         {
190         if (isset($def['studio'])) {
191             if (is_array($def [ 'studio' ]))
192             {
193                         if (isset($def['studio']['editField']) && $def['studio']['editField'] == true)
194                     return true;
195                         if (isset($def['studio']['required']) && $def['studio']['required'])
196                     return true;
197                     
198                 } else
199                 {
200                         if ($def['studio'] == 'visible')
201                     return true;
202                 if ($def['studio'] == 'hidden' || $def['studio'] == 'false' || !$def['studio'] )
203                     return false;
204             }
205         }
206         if (empty($def ['source']) || $def ['source'] == 'db' || $def ['source'] == 'custom_fields')
207                 {
208                 if ($def ['type'] != 'id' && (empty($def ['dbType']) || $def ['dbType'] != 'id'))
209                   return true;
210                 }
211                 
212                 return false;
213         }
214 }