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