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-2012 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 //Load the parent view class if it exists. Check for custom file first
42 loadParentView('edit');
44 require_once ('modules/ModuleBuilder/parsers/ParserFactory.php') ;
45 require_once ('modules/ModuleBuilder/MB/AjaxCompose.php') ;
46 require_once 'modules/ModuleBuilder/parsers/constants.php' ;
48 //require_once('include/Utils.php');
51 class ViewLayoutView extends ViewEdit
53 function ViewLayoutView ()
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)
62 $this->package = $_REQUEST [ 'view_package' ] ;
63 $this->type = $this->editLayout;
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);
75 * @see SugarView::_getModuleTitleParams()
77 protected function _getModuleTitleParams($browserTitle = false)
82 translate('LBL_MODULE_NAME','Administration'),
83 ModuleBuilderController::getModuleTitle(),
87 // DO NOT REMOVE - overrides parent ViewEdit preDisplay() which attempts to load a bean for a non-existent module
88 function preDisplay ()
92 function display ($preview = false)
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);
105 $smarty->assign('mod', $mod_strings);
106 $smarty->assign('MOD', $mod_strings);
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 )
111 $smarty->assign ( $image, SugarThemeRegistry::current()->getImage($file,'',null,null,'.gif',$file) ) ;
114 $requiredFields = implode($parser->getRequiredFields () , ',');
115 $slashedRequiredFields = addslashes($requiredFields);
116 $buttons = array ( ) ;
117 $disableLayout = false;
121 $smarty->assign ( 'layouttitle', translate ( 'LBL_LAYOUT_PREVIEW', 'ModuleBuilder' ) ) ;
124 $smarty->assign ( 'layouttitle', translate ( 'LBL_CURRENT_LAYOUT', 'ModuleBuilder' ) ) ;
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();
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());
140 if (! $this->fromModuleBuilder)
142 $buttons [] = array (
144 'text' => translate ( 'LBL_BTN_SAVE' ) ,
145 'actionScript' => "onclick='if(Studio2.checkGridLayout(\"{$this->editLayout}\")) Studio2.handleSave();'",
146 'disabled' => $disableLayout,
148 $buttons [] = array (
149 'id' => 'publishBtn' ,
150 'text' => translate ( 'LBL_BTN_SAVEPUBLISH' ) ,
151 'actionScript' => "onclick='if(Studio2.checkGridLayout(\"{$this->editLayout}\")) Studio2.handlePublish();'",
152 'disabled' => $disableLayout,
154 $buttons [] = array ( 'id' => 'spacer' , 'width' => '33px' ) ;
155 $buttons [] = array (
156 'id' => 'historyBtn' ,
157 'text' => translate ( 'LBL_HISTORY' ) ,
158 'actionScript' => "onclick='ModuleBuilder.history.browse(\"{$this->editModule}\", \"{$this->editLayout}\")'",
159 'disabled' => $disableLayout,
161 $buttons [] = array (
162 'id' => 'historyDefault' ,
163 'text' => translate ( 'LBL_RESTORE_DEFAULT' ) ,
164 'actionScript' => "onclick='ModuleBuilder.history.revert(\"{$this->editModule}\", \"{$this->editLayout}\", \"{$history->getLast()}\", \"\")'",
165 'disabled' => $disableLayout,
169 $buttons [] = array (
171 'text' => $GLOBALS [ 'mod_strings' ] [ 'LBL_BTN_SAVE' ] ,
172 'actionScript' => "onclick='if(Studio2.checkGridLayout(\"{$this->editLayout}\")) Studio2.handlePublish();'",
173 'disabled' => $disableLayout,
175 $buttons [] = array ( 'id' => 'spacer' , 'width' => '33px' ) ;
176 $buttons [] = array (
177 'id' => 'historyBtn' ,
178 'text' => translate ( 'LBL_HISTORY' ) ,
179 'actionScript' => "onclick='ModuleBuilder.history.browse(\"{$this->editModule}\", \"{$this->editLayout}\")'",
180 'disabled' => $disableLayout,
182 $buttons [] = array (
183 'id' => 'historyDefault' ,
184 'text' => translate ( 'LBL_RESTORE_DEFAULT' ) ,
185 'actionScript' => "onclick='ModuleBuilder.history.revert(\"{$this->editModule}\", \"{$this->editLayout}\", \"{$history->getLast()}\", \"\")'",
186 'disabled' => $disableLayout,
191 if($this->editLayout == MB_DETAILVIEW || $this->editLayout == MB_QUICKCREATE){
192 $buttons [] = array (
193 'id' => 'copyFromEditView' ,
194 'text' => translate ( 'LBL_COPY_FROM_EDITVIEW' ) ,
195 'actionScript' => "onclick='ModuleBuilder.copyFromView(\"{$this->editModule}\", \"{$this->editLayout}\")'",
196 'disabled' => $disableLayout,
202 foreach ( $buttons as $button )
204 if ($button['id'] == "spacer") {
205 $html .= "<td style='width:{$button['width']}'> </td>";
207 $html .= "<td><input id='{$button['id']}' type='button' valign='center' class='button' style='cursor:pointer' "
208 . "onmousedown='this.className=\"buttonOn\";return false;' onmouseup='this.className=\"button\"' "
209 . "onmouseout='this.className=\"button\"' {$button['actionScript']} value = '{$button['text']}'" ;
210 if(!empty($button['disabled'])){
211 $html .= " disabled";
217 $smarty->assign ( 'buttons', $html ) ;
219 // assign fields and layout
220 $smarty->assign ( 'available_fields', $parser->getAvailableFields () ) ;
222 $smarty->assign ( 'disable_layout', $disableLayout) ;
223 $smarty->assign ( 'required_fields', $requiredFields) ;
224 $smarty->assign ( 'layout', $parser->getLayout () ) ;
225 $smarty->assign ( 'field_defs', $parser->getFieldDefs () ) ;
226 $smarty->assign ( 'view_module', $this->editModule ) ;
227 $smarty->assign ( 'view', $this->editLayout ) ;
228 $smarty->assign ( 'maxColumns', $parser->getMaxColumns() ) ;
229 $smarty->assign ( 'nextPanelId', $parser->getFirstNewPanelId() ) ;
230 $smarty->assign ( 'displayAsTabs', $parser->getUseTabs() ) ;
231 $smarty->assign ( 'tabDefs', $parser->getTabDefs() ) ;
232 $smarty->assign ( 'syncDetailEditViews', $parser->getSyncDetailEditViews() ) ;
233 $smarty->assign ( 'fieldwidth', 150 ) ;
234 $smarty->assign ( 'translate', $this->fromModuleBuilder ? false : true ) ;
236 if ($this->fromModuleBuilder)
238 $smarty->assign ( 'fromModuleBuilder', $this->fromModuleBuilder ) ;
239 $smarty->assign ( 'view_package', $this->package ) ;
243 MB_EDITVIEW => 'LBL_EDITVIEW' ,
244 MB_DETAILVIEW => 'LBL_DETAILVIEW' ,
245 MB_QUICKCREATE => 'LBL_QUICKCREATE',
248 $layoutLabel = 'LBL_LAYOUTS' ;
249 $layoutView = 'layouts' ;
252 $ajax = new AjaxCompose ( ) ;
254 $translatedViewType = '' ;
255 if ( isset ( $labels [ strtolower ( $this->editLayout ) ] ) )
256 $translatedViewType = translate ( $labels [ strtolower( $this->editLayout ) ] , 'ModuleBuilder' ) ;
257 else if (isset($this->sm))
259 foreach($this->sm->sources as $file => $def)
261 if (!empty($def['view']) && $def['view'] == $this->editLayout && !empty($def['name']))
263 $translatedViewType = $def['name'];
266 if(empty($translatedViewType))
268 $label = "LBL_" . strtoupper($this->editLayout);
269 $translated = translate($label, $this->editModule);
270 if ($translated != $label)
271 $translatedViewType = $translated;
278 if ($this->fromModuleBuilder)
280 $ajax->addCrumb ( translate ( 'LBL_MODULEBUILDER', 'ModuleBuilder' ), 'ModuleBuilder.main("mb")' ) ;
281 $ajax->addCrumb ( $this->package, 'ModuleBuilder.getContent("module=ModuleBuilder&action=package&package=' . $this->package . '")' ) ;
282 $ajax->addCrumb ( $this->editModule, 'ModuleBuilder.getContent("module=ModuleBuilder&action=module&view_package=' . $this->package . '&view_module=' . $this->editModule . '")' ) ;
283 $ajax->addCrumb ( translate ( $layoutLabel, 'ModuleBuilder' ), 'ModuleBuilder.getContent("module=ModuleBuilder&MB=true&action=wizard&view='.$layoutView.'&view_module=' . $this->editModule . '&view_package=' . $this->package . '")' ) ;
284 $ajax->addCrumb ( $translatedViewType, '' ) ;
287 $ajax->addCrumb ( translate ( 'LBL_STUDIO', 'ModuleBuilder' ), 'ModuleBuilder.main("studio")' ) ;
288 $ajax->addCrumb ( $this->translatedEditModule, 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard&view_module=' . $this->editModule . '")' ) ;
289 $ajax->addCrumb ( translate ( $layoutLabel, 'ModuleBuilder' ), 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard&view='.$layoutView.'&view_module=' . $this->editModule . '")' ) ;
290 $ajax->addCrumb ( $translatedViewType, '' ) ;
293 // set up language files
294 $smarty->assign ( 'language', $parser->getLanguage() ) ; // for sugar_translate in the smarty template
295 $smarty->assign('from_mb',$this->fromModuleBuilder);
296 $smarty->assign('calc_field_list', json_encode($parser->getCalculatedFields()));
297 if ($this->fromModuleBuilder) {
298 $mb = new ModuleBuilder ( ) ;
299 $module = & $mb->getPackageModule ( $this->package, $this->editModule ) ;
300 $smarty->assign('current_mod_strings', $module->getModStrings());
303 $ajax->addSection ( 'center', $translatedViewType, $smarty->fetch ( 'modules/ModuleBuilder/tpls/layoutView.tpl' ) ) ;
305 echo $smarty->fetch ( 'modules/ModuleBuilder/tpls/Preview/layoutView.tpl' );
307 echo $ajax->getJavascript () ;