]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/ModuleBuilder/views/view.layoutview.php
Release 6.5.10
[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-2013 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 require_once ('modules/ModuleBuilder/parsers/ParserFactory.php') ;
42 require_once ('modules/ModuleBuilder/MB/AjaxCompose.php') ;
43 require_once 'modules/ModuleBuilder/parsers/constants.php' ;
44
45 class ViewLayoutView extends SugarView
46 {
47     function ViewLayoutView ()
48     {
49         $GLOBALS [ 'log' ]->debug ( 'in ViewLayoutView' ) ;
50         $this->editModule = $_REQUEST [ 'view_module' ] ;
51         $this->editLayout = $_REQUEST [ 'view' ] ;
52         $this->package = null;
53         $this->fromModuleBuilder = isset ( $_REQUEST [ 'MB' ] ) || !empty($_REQUEST [ 'view_package' ]);
54         if ($this->fromModuleBuilder)
55         {
56             $this->package = $_REQUEST [ 'view_package' ] ;
57             $this->type = $this->editLayout;
58         } else
59         {
60             global $app_list_strings ;
61             $moduleNames = array_change_key_case ( $app_list_strings [ 'moduleList' ] ) ;
62             $this->translatedEditModule = $moduleNames [ strtolower ( $this->editModule ) ] ;
63             $this->sm = StudioModuleFactory::getStudioModule($this->editModule);
64             $this->type = $this->sm->getViewType($this->editLayout);
65         }
66     }
67
68     /**
69          * @see SugarView::_getModuleTitleParams()
70          */
71         protected function _getModuleTitleParams($browserTitle = false)
72         {
73             global $mod_strings;
74             
75         return array(
76            translate('LBL_MODULE_NAME','Administration'),
77            ModuleBuilderController::getModuleTitle(),
78            );
79     }
80
81     // DO NOT REMOVE - overrides parent ViewEdit preDisplay() which attempts to load a bean for a non-existent module
82     function preDisplay ()
83     {
84     }
85
86     function display ($preview = false)
87     {
88
89         global $mod_strings ;
90         $parser = ParserFactory::getParser($this->editLayout,$this->editModule,$this->package);
91         $history = $parser->getHistory () ;
92         $smarty = new Sugar_Smarty ( ) ;
93         //Add in the module we are viewing to our current mod strings
94                 if (! $this->fromModuleBuilder) {
95                         global $current_language;
96                         $editModStrings = return_module_language($current_language, $this->editModule);
97                         $mod_strings = sugarArrayMerge($editModStrings, $mod_strings);
98                 }
99         $smarty->assign('mod', $mod_strings);
100                 $smarty->assign('MOD', $mod_strings);
101         // assign buttons
102         $images = array ( 'icon_save' => 'studio_save' , 'icon_publish' => 'studio_publish' , 'icon_address' => 'icon_Address' , 'icon_emailaddress' => 'icon_EmailAddress' , 'icon_phone' => 'icon_Phone' ) ;
103         foreach ( $images as $image => $file )
104         {
105             $smarty->assign ( $image, SugarThemeRegistry::current()->getImage($file,'',null,null,'.gif',$file) ) ;
106         }
107
108         $requiredFields = implode($parser->getRequiredFields () , ',');
109         $slashedRequiredFields = addslashes($requiredFields);
110         $buttons = array ( ) ;
111         $disableLayout = false;
112
113         if ($preview)
114         {
115             $smarty->assign ( 'layouttitle', translate ( 'LBL_LAYOUT_PREVIEW', 'ModuleBuilder' ) ) ;
116         } else
117         {
118             $smarty->assign ( 'layouttitle', translate ( 'LBL_CURRENT_LAYOUT', 'ModuleBuilder' ) ) ;
119
120             //Check if we need to synch edit view to other layouts
121             if($this->editLayout == MB_DETAILVIEW || $this->editLayout == MB_QUICKCREATE){
122                         $parser2 = ParserFactory::getParser(MB_EDITVIEW,$this->editModule,$this->package);
123                 if($this->editLayout == MB_DETAILVIEW){
124                             $disableLayout = $parser2->getSyncDetailEditViews();
125                 }
126                 if(!empty($_REQUEST['copyFromEditView'])){
127                     $editViewPanels = $parser2->convertFromCanonicalForm ( $parser2->_viewdefs [ 'panels' ] , $parser2->_fielddefs ) ;
128                     $parser->_viewdefs [ 'panels' ] = $editViewPanels;
129                     $parser->_fielddefs = $parser2->_fielddefs;
130                     $parser->setUseTabs($parser2->getUseTabs());
131                     $parser->setTabDefs($parser2->getTabDefs());
132                 }
133                     }
134
135             if (! $this->fromModuleBuilder)
136             {
137                     $buttons [] = array (
138                     'id' => 'saveBtn' , 
139                     'text' => translate ( 'LBL_BTN_SAVE' ) , 
140                     'actionScript' => "onclick='if(Studio2.checkGridLayout(\"{$this->editLayout}\")) Studio2.handleSave();'",
141                         'disabled' => $disableLayout, 
142                 ) ;
143                 $buttons [] = array ( 
144                     'id' => 'publishBtn' , 
145                     'text' => translate ( 'LBL_BTN_SAVEPUBLISH' ) , 
146                     'actionScript' => "onclick='if(Studio2.checkGridLayout(\"{$this->editLayout}\")) Studio2.handlePublish();'",
147                         'disabled' => $disableLayout, 
148                 ) ;
149                 $buttons [] = array ( 'id' => 'spacer' , 'width' => '33px' ) ;
150                 $buttons [] = array ( 
151                         'id' => 'historyBtn' , 
152                         'text' => translate ( 'LBL_HISTORY' ) , 
153                         'actionScript' => "onclick='ModuleBuilder.history.browse(\"{$this->editModule}\", \"{$this->editLayout}\")'",
154                     'disabled' => $disableLayout,
155                 ) ;
156                 $buttons [] = array ( 
157                         'id' => 'historyDefault' , 
158                         'text' => translate ( 'LBL_RESTORE_DEFAULT' ) , 
159                         'actionScript' => "onclick='ModuleBuilder.history.revert(\"{$this->editModule}\", \"{$this->editLayout}\", \"{$history->getLast()}\", \"\")'",
160                         'disabled' => $disableLayout, 
161                 ) ;
162             } else
163             {
164                 $buttons [] = array ( 
165                     'id' => 'saveBtn' , 
166                     'text' => $GLOBALS [ 'mod_strings' ] [ 'LBL_BTN_SAVE' ] , 
167                     'actionScript' => "onclick='if(Studio2.checkGridLayout(\"{$this->editLayout}\")) Studio2.handlePublish();'",
168                     'disabled' => $disableLayout,
169                 ) ;
170                 $buttons [] = array ( 'id' => 'spacer' , 'width' => '33px' ) ;
171                 $buttons [] = array (
172                     'id' => 'historyBtn' , 
173                     'text' => translate ( 'LBL_HISTORY' ) , 
174                     'actionScript' => "onclick='ModuleBuilder.history.browse(\"{$this->editModule}\", \"{$this->editLayout}\")'",
175                     'disabled' => $disableLayout, 
176                 ) ;
177                 $buttons [] = array ( 
178                     'id' => 'historyDefault' , 
179                     'text' => translate ( 'LBL_RESTORE_DEFAULT' ) , 
180                     'actionScript' => "onclick='ModuleBuilder.history.revert(\"{$this->editModule}\", \"{$this->editLayout}\", \"{$history->getLast()}\", \"\")'",
181                     'disabled' => $disableLayout, 
182                 ) ;
183             }
184
185
186             if($this->editLayout == MB_DETAILVIEW || $this->editLayout == MB_QUICKCREATE){
187                 $buttons [] = array (
188                 'id' => 'copyFromEditView' ,
189                 'text' => translate ( 'LBL_COPY_FROM_EDITVIEW' ) ,
190                 'actionScript' => "onclick='ModuleBuilder.copyFromView(\"{$this->editModule}\", \"{$this->editLayout}\")'",
191                 'disabled' => $disableLayout,
192                 ) ;
193             }
194         }
195
196         $html = "" ;
197         foreach ( $buttons as $button )
198         {
199             if ($button['id'] == "spacer") {
200                 $html .= "<td style='width:{$button['width']}'> </td>";
201             } else {
202                     $html .= "<td><input id='{$button['id']}' type='button' valign='center' class='button' style='cursor:pointer' "
203                        . "onmousedown='this.className=\"buttonOn\";return false;' onmouseup='this.className=\"button\"' "
204                        . "onmouseout='this.className=\"button\"' {$button['actionScript']} value = '{$button['text']}'" ;
205                     if(!empty($button['disabled'])){
206                          $html .= " disabled";
207                     }
208                     $html .= "></td>";
209             }
210         }
211
212         $smarty->assign ( 'buttons', $html ) ;
213
214         // assign fields and layout
215         $smarty->assign ( 'available_fields', $parser->getAvailableFields () ) ;
216         
217         $smarty->assign ( 'disable_layout', $disableLayout) ;
218         $smarty->assign ( 'required_fields', $requiredFields) ;
219         $smarty->assign ( 'layout', $parser->getLayout () ) ;
220         $smarty->assign ( 'field_defs', $parser->getFieldDefs () ) ;
221         $smarty->assign ( 'view_module', $this->editModule ) ;
222         $smarty->assign ( 'view', $this->editLayout ) ;
223         $smarty->assign ( 'maxColumns', $parser->getMaxColumns() ) ;
224         $smarty->assign ( 'nextPanelId', $parser->getFirstNewPanelId() ) ;
225         $smarty->assign ( 'displayAsTabs', $parser->getUseTabs() ) ;
226         $smarty->assign ( 'tabDefs', $parser->getTabDefs() ) ;
227         $smarty->assign ( 'syncDetailEditViews', $parser->getSyncDetailEditViews() ) ;
228         $smarty->assign ( 'fieldwidth', 150 ) ;
229         $smarty->assign ( 'translate', $this->fromModuleBuilder ? false : true ) ;
230
231         if ($this->fromModuleBuilder)
232         {
233             $smarty->assign ( 'fromModuleBuilder', $this->fromModuleBuilder ) ;
234             $smarty->assign ( 'view_package', $this->package ) ;
235         }
236
237         $labels = array (
238                                 MB_EDITVIEW => 'LBL_EDITVIEW' ,
239                                 MB_DETAILVIEW => 'LBL_DETAILVIEW' ,
240                                 MB_QUICKCREATE => 'LBL_QUICKCREATE',
241                                 ) ;
242
243         $layoutLabel = 'LBL_LAYOUTS' ;
244         $layoutView = 'layouts' ;
245
246
247         $ajax = new AjaxCompose ( ) ;
248
249         $translatedViewType = '' ;
250                 if ( isset ( $labels [ strtolower ( $this->editLayout ) ] ) )
251                         $translatedViewType = translate ( $labels [ strtolower( $this->editLayout ) ] , 'ModuleBuilder' ) ;
252         else if (isset($this->sm))
253         {
254             foreach($this->sm->sources as $file => $def)
255             {
256                 if (!empty($def['view']) && $def['view'] == $this->editLayout && !empty($def['name']))
257                 {
258                     $translatedViewType = $def['name'];
259                 }
260             }
261             if(empty($translatedViewType))
262             {
263                 $label = "LBL_" . strtoupper($this->editLayout);
264                 $translated = translate($label, $this->editModule);
265                 if ($translated != $label)
266                     $translatedViewType =  $translated;
267             }
268         }
269
270
271
272
273         if ($this->fromModuleBuilder)
274         {
275             $ajax->addCrumb ( translate ( 'LBL_MODULEBUILDER', 'ModuleBuilder' ), 'ModuleBuilder.main("mb")' ) ;
276             $ajax->addCrumb ( $this->package, 'ModuleBuilder.getContent("module=ModuleBuilder&action=package&package=' . $this->package . '")' ) ;
277             $ajax->addCrumb ( $this->editModule, 'ModuleBuilder.getContent("module=ModuleBuilder&action=module&view_package=' . $this->package . '&view_module=' . $this->editModule . '")' ) ;
278             $ajax->addCrumb ( translate ( $layoutLabel, 'ModuleBuilder' ), 'ModuleBuilder.getContent("module=ModuleBuilder&MB=true&action=wizard&view='.$layoutView.'&view_module=' . $this->editModule . '&view_package=' . $this->package . '")' ) ;
279             $ajax->addCrumb ( $translatedViewType, '' ) ;
280         } else
281         {
282             $ajax->addCrumb ( translate ( 'LBL_STUDIO', 'ModuleBuilder' ), 'ModuleBuilder.main("studio")' ) ;
283             $ajax->addCrumb ( $this->translatedEditModule, 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard&view_module=' . $this->editModule . '")' ) ;
284             $ajax->addCrumb ( translate ( $layoutLabel, 'ModuleBuilder' ), 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard&view='.$layoutView.'&view_module=' . $this->editModule . '")' ) ;
285             $ajax->addCrumb ( $translatedViewType, '' ) ;
286         }
287
288         // set up language files
289                 $smarty->assign ( 'language', $parser->getLanguage() ) ; // for sugar_translate in the smarty template
290         $smarty->assign('from_mb',$this->fromModuleBuilder);
291         $smarty->assign('calc_field_list', json_encode($parser->getCalculatedFields()));
292                 if ($this->fromModuleBuilder) {
293                         $mb = new ModuleBuilder ( ) ;
294             $module = & $mb->getPackageModule ( $this->package, $this->editModule ) ;
295                     $smarty->assign('current_mod_strings', $module->getModStrings());
296                 }
297
298         $ajax->addSection ( 'center', $translatedViewType, $smarty->fetch ( 'modules/ModuleBuilder/tpls/layoutView.tpl' ) ) ;
299         if ($preview) {
300                 echo $smarty->fetch ( 'modules/ModuleBuilder/tpls/Preview/layoutView.tpl' );
301                 } else {
302                         echo $ajax->getJavascript () ;
303         }
304     }
305 }