]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/ModuleBuilder/views/view.layoutview.php
Release 6.5.6
[Github/sugarcrm.git] / modules / ModuleBuilder / views / view.layoutview.php
1 <?php
2 if (! defined ( 'sugarEntry' ) || ! sugarEntry)
3     die ( 'Not A Valid Entry Point' ) ;
4
5 /*********************************************************************************
6  * SugarCRM Community Edition is a customer relationship management program developed by
7  * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
8  * 
9  * This program is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU Affero General Public License version 3 as published by the
11  * Free Software Foundation with the addition of the following permission added
12  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
13  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
14  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
15  * 
16  * This program is distributed in the hope that it will be useful, but WITHOUT
17  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
19  * details.
20  * 
21  * You should have received a copy of the GNU Affero General Public License along with
22  * this program; if not, see http://www.gnu.org/licenses or write to the Free
23  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24  * 02110-1301 USA.
25  * 
26  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
27  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
28  * 
29  * The interactive user interfaces in modified source and object code versions
30  * of this program must display Appropriate Legal Notices, as required under
31  * Section 5 of the GNU Affero General Public License version 3.
32  * 
33  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
34  * these Appropriate Legal Notices must retain the display of the "Powered by
35  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
36  * technical reasons, the Appropriate Legal Notices must display the words
37  * "Powered by SugarCRM".
38  ********************************************************************************/
39
40
41 //Load the parent view class if it exists.  Check for custom file first
42 loadParentView('edit');
43
44 require_once ('modules/ModuleBuilder/parsers/ParserFactory.php') ;
45 require_once ('modules/ModuleBuilder/MB/AjaxCompose.php') ;
46 require_once 'modules/ModuleBuilder/parsers/constants.php' ;
47
48 //require_once('include/Utils.php');
49
50
51 class ViewLayoutView extends ViewEdit
52 {
53     function ViewLayoutView ()
54     {
55         $GLOBALS [ 'log' ]->debug ( 'in ViewLayoutView' ) ;
56         $this->editModule = $_REQUEST [ 'view_module' ] ;
57         $this->editLayout = $_REQUEST [ 'view' ] ;
58         $this->package = null;
59         $this->fromModuleBuilder = isset ( $_REQUEST [ 'MB' ] ) || !empty($_REQUEST [ 'view_package' ]);
60         if ($this->fromModuleBuilder)
61         {
62             $this->package = $_REQUEST [ 'view_package' ] ;
63             $this->type = $this->editLayout;
64         } else
65         {
66             global $app_list_strings ;
67             $moduleNames = array_change_key_case ( $app_list_strings [ 'moduleList' ] ) ;
68             $this->translatedEditModule = $moduleNames [ strtolower ( $this->editModule ) ] ;
69             $this->sm = StudioModuleFactory::getStudioModule($this->editModule);
70             $this->type = $this->sm->getViewType($this->editLayout);
71         }
72     }
73
74     /**
75          * @see SugarView::_getModuleTitleParams()
76          */
77         protected function _getModuleTitleParams($browserTitle = false)
78         {
79             global $mod_strings;
80             
81         return array(
82            translate('LBL_MODULE_NAME','Administration'),
83            ModuleBuilderController::getModuleTitle(),
84            );
85     }
86
87     // DO NOT REMOVE - overrides parent ViewEdit preDisplay() which attempts to load a bean for a non-existent module
88     function preDisplay ()
89     {
90     }
91
92     function display ($preview = false)
93     {
94
95         global $mod_strings ;
96         $parser = ParserFactory::getParser($this->editLayout,$this->editModule,$this->package);
97         $history = $parser->getHistory () ;
98         $smarty = new Sugar_Smarty ( ) ;
99         //Add in the module we are viewing to our current mod strings
100                 if (! $this->fromModuleBuilder) {
101                         global $current_language;
102                         $editModStrings = return_module_language($current_language, $this->editModule);
103                         $mod_strings = sugarArrayMerge($editModStrings, $mod_strings);
104                 }
105         $smarty->assign('mod', $mod_strings);
106                 $smarty->assign('MOD', $mod_strings);
107         // assign buttons
108         $images = array ( 'icon_save' => 'studio_save' , 'icon_publish' => 'studio_publish' , 'icon_address' => 'icon_Address' , 'icon_emailaddress' => 'icon_EmailAddress' , 'icon_phone' => 'icon_Phone' ) ;
109         foreach ( $images as $image => $file )
110         {
111             $smarty->assign ( $image, SugarThemeRegistry::current()->getImage($file,'',null,null,'.gif',$file) ) ;
112         }
113
114         $requiredFields = implode($parser->getRequiredFields () , ',');
115         $slashedRequiredFields = addslashes($requiredFields);
116         $buttons = array ( ) ;
117         $disableLayout = false;
118
119         if ($preview)
120         {
121             $smarty->assign ( 'layouttitle', translate ( 'LBL_LAYOUT_PREVIEW', 'ModuleBuilder' ) ) ;
122         } else
123         {
124             $smarty->assign ( 'layouttitle', translate ( 'LBL_CURRENT_LAYOUT', 'ModuleBuilder' ) ) ;
125
126             //Check if we need to synch edit view to other layouts
127             if($this->editLayout == MB_DETAILVIEW || $this->editLayout == MB_QUICKCREATE){
128                         $parser2 = ParserFactory::getParser(MB_EDITVIEW,$this->editModule,$this->package);
129                 if($this->editLayout == MB_DETAILVIEW){
130                             $disableLayout = $parser2->getSyncDetailEditViews();
131                 }
132                 if(!empty($_REQUEST['copyFromEditView'])){
133                     $editViewPanels = $parser2->convertFromCanonicalForm ( $parser2->_viewdefs [ 'panels' ] , $parser2->_fielddefs ) ;
134                     $parser->_viewdefs [ 'panels' ] = $editViewPanels;
135                     $parser->_fielddefs = $parser2->_fielddefs;
136                     $parser->setUseTabs($parser2->getUseTabs());
137                     $parser->setTabDefs($parser2->getTabDefs());
138                 }
139                     }
140
141             if (! $this->fromModuleBuilder)
142             {
143                     $buttons [] = array (
144                     'id' => 'saveBtn' , 
145                     'text' => translate ( 'LBL_BTN_SAVE' ) , 
146                     'actionScript' => "onclick='if(Studio2.checkGridLayout(\"{$this->editLayout}\")) Studio2.handleSave();'",
147                         'disabled' => $disableLayout, 
148                 ) ;
149                 $buttons [] = array ( 
150                     'id' => 'publishBtn' , 
151                     'text' => translate ( 'LBL_BTN_SAVEPUBLISH' ) , 
152                     'actionScript' => "onclick='if(Studio2.checkGridLayout(\"{$this->editLayout}\")) Studio2.handlePublish();'",
153                         'disabled' => $disableLayout, 
154                 ) ;
155                 $buttons [] = array ( 'id' => 'spacer' , 'width' => '33px' ) ;
156                 $buttons [] = array ( 
157                         'id' => 'historyBtn' , 
158                         'text' => translate ( 'LBL_HISTORY' ) , 
159                         'actionScript' => "onclick='ModuleBuilder.history.browse(\"{$this->editModule}\", \"{$this->editLayout}\")'",
160                     'disabled' => $disableLayout,
161                 ) ;
162                 $buttons [] = array ( 
163                         'id' => 'historyDefault' , 
164                         'text' => translate ( 'LBL_RESTORE_DEFAULT' ) , 
165                         'actionScript' => "onclick='ModuleBuilder.history.revert(\"{$this->editModule}\", \"{$this->editLayout}\", \"{$history->getLast()}\", \"\")'",
166                         'disabled' => $disableLayout, 
167                 ) ;
168             } else
169             {
170                 $buttons [] = array ( 
171                     'id' => 'saveBtn' , 
172                     'text' => $GLOBALS [ 'mod_strings' ] [ 'LBL_BTN_SAVE' ] , 
173                     'actionScript' => "onclick='if(Studio2.checkGridLayout(\"{$this->editLayout}\")) Studio2.handlePublish();'",
174                     'disabled' => $disableLayout,
175                 ) ;
176                 $buttons [] = array ( 'id' => 'spacer' , 'width' => '33px' ) ;
177                 $buttons [] = array (
178                     'id' => 'historyBtn' , 
179                     'text' => translate ( 'LBL_HISTORY' ) , 
180                     'actionScript' => "onclick='ModuleBuilder.history.browse(\"{$this->editModule}\", \"{$this->editLayout}\")'",
181                     'disabled' => $disableLayout, 
182                 ) ;
183                 $buttons [] = array ( 
184                     'id' => 'historyDefault' , 
185                     'text' => translate ( 'LBL_RESTORE_DEFAULT' ) , 
186                     'actionScript' => "onclick='ModuleBuilder.history.revert(\"{$this->editModule}\", \"{$this->editLayout}\", \"{$history->getLast()}\", \"\")'",
187                     'disabled' => $disableLayout, 
188                 ) ;
189             }
190
191
192             if($this->editLayout == MB_DETAILVIEW || $this->editLayout == MB_QUICKCREATE){
193                 $buttons [] = array (
194                 'id' => 'copyFromEditView' ,
195                 'text' => translate ( 'LBL_COPY_FROM_EDITVIEW' ) ,
196                 'actionScript' => "onclick='ModuleBuilder.copyFromView(\"{$this->editModule}\", \"{$this->editLayout}\")'",
197                 'disabled' => $disableLayout,
198                 ) ;
199             }
200         }
201
202         $html = "" ;
203         foreach ( $buttons as $button )
204         {
205             if ($button['id'] == "spacer") {
206                 $html .= "<td style='width:{$button['width']}'> </td>";
207             } else {
208                     $html .= "<td><input id='{$button['id']}' type='button' valign='center' class='button' style='cursor:pointer' "
209                        . "onmousedown='this.className=\"buttonOn\";return false;' onmouseup='this.className=\"button\"' "
210                        . "onmouseout='this.className=\"button\"' {$button['actionScript']} value = '{$button['text']}'" ;
211                     if(!empty($button['disabled'])){
212                          $html .= " disabled";
213                     }
214                     $html .= "></td>";
215             }
216         }
217
218         $smarty->assign ( 'buttons', $html ) ;
219
220         // assign fields and layout
221         $smarty->assign ( 'available_fields', $parser->getAvailableFields () ) ;
222         
223         $smarty->assign ( 'disable_layout', $disableLayout) ;
224         $smarty->assign ( 'required_fields', $requiredFields) ;
225         $smarty->assign ( 'layout', $parser->getLayout () ) ;
226         $smarty->assign ( 'field_defs', $parser->getFieldDefs () ) ;
227         $smarty->assign ( 'view_module', $this->editModule ) ;
228         $smarty->assign ( 'view', $this->editLayout ) ;
229         $smarty->assign ( 'maxColumns', $parser->getMaxColumns() ) ;
230         $smarty->assign ( 'nextPanelId', $parser->getFirstNewPanelId() ) ;
231         $smarty->assign ( 'displayAsTabs', $parser->getUseTabs() ) ;
232         $smarty->assign ( 'tabDefs', $parser->getTabDefs() ) ;
233         $smarty->assign ( 'syncDetailEditViews', $parser->getSyncDetailEditViews() ) ;
234         $smarty->assign ( 'fieldwidth', 150 ) ;
235         $smarty->assign ( 'translate', $this->fromModuleBuilder ? false : true ) ;
236
237         if ($this->fromModuleBuilder)
238         {
239             $smarty->assign ( 'fromModuleBuilder', $this->fromModuleBuilder ) ;
240             $smarty->assign ( 'view_package', $this->package ) ;
241         }
242
243         $labels = array (
244                                 MB_EDITVIEW => 'LBL_EDITVIEW' ,
245                                 MB_DETAILVIEW => 'LBL_DETAILVIEW' ,
246                                 MB_QUICKCREATE => 'LBL_QUICKCREATE',
247                                 ) ;
248
249         $layoutLabel = 'LBL_LAYOUTS' ;
250         $layoutView = 'layouts' ;
251
252
253         $ajax = new AjaxCompose ( ) ;
254
255         $translatedViewType = '' ;
256                 if ( isset ( $labels [ strtolower ( $this->editLayout ) ] ) )
257                         $translatedViewType = translate ( $labels [ strtolower( $this->editLayout ) ] , 'ModuleBuilder' ) ;
258         else if (isset($this->sm))
259         {
260             foreach($this->sm->sources as $file => $def)
261             {
262                 if (!empty($def['view']) && $def['view'] == $this->editLayout && !empty($def['name']))
263                 {
264                     $translatedViewType = $def['name'];
265                 }
266             }
267             if(empty($translatedViewType))
268             {
269                 $label = "LBL_" . strtoupper($this->editLayout);
270                 $translated = translate($label, $this->editModule);
271                 if ($translated != $label)
272                     $translatedViewType =  $translated;
273             }
274         }
275
276
277
278
279         if ($this->fromModuleBuilder)
280         {
281             $ajax->addCrumb ( translate ( 'LBL_MODULEBUILDER', 'ModuleBuilder' ), 'ModuleBuilder.main("mb")' ) ;
282             $ajax->addCrumb ( $this->package, 'ModuleBuilder.getContent("module=ModuleBuilder&action=package&package=' . $this->package . '")' ) ;
283             $ajax->addCrumb ( $this->editModule, 'ModuleBuilder.getContent("module=ModuleBuilder&action=module&view_package=' . $this->package . '&view_module=' . $this->editModule . '")' ) ;
284             $ajax->addCrumb ( translate ( $layoutLabel, 'ModuleBuilder' ), 'ModuleBuilder.getContent("module=ModuleBuilder&MB=true&action=wizard&view='.$layoutView.'&view_module=' . $this->editModule . '&view_package=' . $this->package . '")' ) ;
285             $ajax->addCrumb ( $translatedViewType, '' ) ;
286         } else
287         {
288             $ajax->addCrumb ( translate ( 'LBL_STUDIO', 'ModuleBuilder' ), 'ModuleBuilder.main("studio")' ) ;
289             $ajax->addCrumb ( $this->translatedEditModule, 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard&view_module=' . $this->editModule . '")' ) ;
290             $ajax->addCrumb ( translate ( $layoutLabel, 'ModuleBuilder' ), 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard&view='.$layoutView.'&view_module=' . $this->editModule . '")' ) ;
291             $ajax->addCrumb ( $translatedViewType, '' ) ;
292         }
293
294         // set up language files
295                 $smarty->assign ( 'language', $parser->getLanguage() ) ; // for sugar_translate in the smarty template
296         $smarty->assign('from_mb',$this->fromModuleBuilder);
297         $smarty->assign('calc_field_list', json_encode($parser->getCalculatedFields()));
298                 if ($this->fromModuleBuilder) {
299                         $mb = new ModuleBuilder ( ) ;
300             $module = & $mb->getPackageModule ( $this->package, $this->editModule ) ;
301                     $smarty->assign('current_mod_strings', $module->getModStrings());
302                 }
303
304         $ajax->addSection ( 'center', $translatedViewType, $smarty->fetch ( 'modules/ModuleBuilder/tpls/layoutView.tpl' ) ) ;
305         if ($preview) {
306                 echo $smarty->fetch ( 'modules/ModuleBuilder/tpls/Preview/layoutView.tpl' );
307                 } else {
308                         echo $ajax->getJavascript () ;
309         }
310     }
311 }