2 if (! defined ( 'sugarEntry' ) || ! sugarEntry)
3 die ( 'Not A Valid Entry Point' ) ;
5 /*********************************************************************************
6 * SugarCRM Community Edition is a customer relationship management program developed by
7 * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc.
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.
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
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
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.
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.
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 ********************************************************************************/
41 require_once ('modules/ModuleBuilder/parsers/ParserFactory.php') ;
42 require_once ('modules/ModuleBuilder/MB/AjaxCompose.php') ;
43 require_once 'modules/ModuleBuilder/parsers/constants.php' ;
45 class ViewLayoutView extends SugarView
47 function ViewLayoutView ()
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)
56 $this->package = $_REQUEST [ 'view_package' ] ;
57 $this->type = $this->editLayout;
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);
69 * @see SugarView::_getModuleTitleParams()
71 protected function _getModuleTitleParams($browserTitle = false)
76 translate('LBL_MODULE_NAME','Administration'),
77 ModuleBuilderController::getModuleTitle(),
81 // DO NOT REMOVE - overrides parent ViewEdit preDisplay() which attempts to load a bean for a non-existent module
82 function preDisplay ()
86 function display ($preview = false)
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);
99 $smarty->assign('mod', $mod_strings);
100 $smarty->assign('MOD', $mod_strings);
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 )
105 $smarty->assign ( $image, SugarThemeRegistry::current()->getImage($file,'',null,null,'.gif',$file) ) ;
108 $requiredFields = implode($parser->getRequiredFields () , ',');
109 $slashedRequiredFields = addslashes($requiredFields);
110 $buttons = array ( ) ;
111 $disableLayout = false;
115 $smarty->assign ( 'layouttitle', translate ( 'LBL_LAYOUT_PREVIEW', 'ModuleBuilder' ) ) ;
118 $smarty->assign ( 'layouttitle', translate ( 'LBL_CURRENT_LAYOUT', 'ModuleBuilder' ) ) ;
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();
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());
135 if (! $this->fromModuleBuilder)
137 $buttons [] = array (
139 'text' => translate ( 'LBL_BTN_SAVE' ) ,
140 'actionScript' => "onclick='if(Studio2.checkGridLayout(\"{$this->editLayout}\")) Studio2.handleSave();'",
141 'disabled' => $disableLayout,
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,
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,
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,
164 $buttons [] = array (
166 'text' => $GLOBALS [ 'mod_strings' ] [ 'LBL_BTN_SAVE' ] ,
167 'actionScript' => "onclick='if(Studio2.checkGridLayout(\"{$this->editLayout}\")) Studio2.handlePublish();'",
168 'disabled' => $disableLayout,
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,
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,
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,
197 foreach ( $buttons as $button )
199 if ($button['id'] == "spacer") {
200 $html .= "<td style='width:{$button['width']}'> </td>";
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";
212 $smarty->assign ( 'buttons', $html ) ;
214 // assign fields and layout
215 $smarty->assign ( 'available_fields', $parser->getAvailableFields () ) ;
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 ) ;
231 if ($this->fromModuleBuilder)
233 $smarty->assign ( 'fromModuleBuilder', $this->fromModuleBuilder ) ;
234 $smarty->assign ( 'view_package', $this->package ) ;
238 MB_EDITVIEW => 'LBL_EDITVIEW' ,
239 MB_DETAILVIEW => 'LBL_DETAILVIEW' ,
240 MB_QUICKCREATE => 'LBL_QUICKCREATE',
243 $layoutLabel = 'LBL_LAYOUTS' ;
244 $layoutView = 'layouts' ;
247 $ajax = new AjaxCompose ( ) ;
249 $translatedViewType = '' ;
250 if ( isset ( $labels [ strtolower ( $this->editLayout ) ] ) )
251 $translatedViewType = translate ( $labels [ strtolower( $this->editLayout ) ] , 'ModuleBuilder' ) ;
252 else if (isset($this->sm))
254 foreach($this->sm->sources as $file => $def)
256 if (!empty($def['view']) && $def['view'] == $this->editLayout && !empty($def['name']))
258 $translatedViewType = $def['name'];
261 if(empty($translatedViewType))
263 $label = "LBL_" . strtoupper($this->editLayout);
264 $translated = translate($label, $this->editModule);
265 if ($translated != $label)
266 $translatedViewType = $translated;
273 if ($this->fromModuleBuilder)
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, '' ) ;
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, '' ) ;
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());
298 $ajax->addSection ( 'center', $translatedViewType, $smarty->fetch ( 'modules/ModuleBuilder/tpls/layoutView.tpl' ) ) ;
300 echo $smarty->fetch ( 'modules/ModuleBuilder/tpls/Preview/layoutView.tpl' );
302 echo $ajax->getJavascript () ;