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-2011 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' ] ;
65 global $app_list_strings ;
66 $moduleNames = array_change_key_case ( $app_list_strings [ 'moduleList' ] ) ;
67 $this->translatedEditModule = $moduleNames [ strtolower ( $this->editModule ) ] ;
72 * @see SugarView::_getModuleTitleParams()
74 protected function _getModuleTitleParams($browserTitle = false)
79 translate('LBL_MODULE_NAME','Administration'),
80 ModuleBuilderController::getModuleTitle(),
84 // DO NOT REMOVE - overrides parent ViewEdit preDisplay() which attempts to load a bean for a non-existent module
85 function preDisplay ()
89 function display ($preview = false)
93 $parser = ParserFactory::getParser($this->editLayout,$this->editModule,$this->package);
94 $history = $parser->getHistory () ;
95 $smarty = new Sugar_Smarty ( ) ;
96 //Add in the module we are viewing to our current mod strings
97 if (! $this->fromModuleBuilder) {
98 global $current_language;
99 $editModStrings = return_module_language($current_language, $this->editModule);
100 $mod_strings = sugarArrayMerge($editModStrings, $mod_strings);
102 $smarty->assign('mod', $mod_strings);
103 $smarty->assign('MOD', $mod_strings);
105 $images = array ( 'icon_save' => 'studio_save' , 'icon_publish' => 'studio_publish' , 'icon_address' => 'icon_Address' , 'icon_emailaddress' => 'icon_EmailAddress' , 'icon_phone' => 'icon_Phone' ) ;
106 foreach ( $images as $image => $file )
108 $smarty->assign ( $image, SugarThemeRegistry::current()->getImage($file) ) ;
111 $requiredFields = implode($parser->getRequiredFields () , ',');
112 $slashedRequiredFields = addslashes($requiredFields);
113 $buttons = array ( ) ;
114 $disableLayout = false;
118 $smarty->assign ( 'layouttitle', translate ( 'LBL_LAYOUT_PREVIEW', 'ModuleBuilder' ) ) ;
121 $smarty->assign ( 'layouttitle', translate ( 'LBL_CURRENT_LAYOUT', 'ModuleBuilder' ) ) ;
123 if($this->editLayout == MB_DETAILVIEW || $this->editLayout == MB_QUICKCREATE){
124 $parser2 = ParserFactory::getParser(MB_EDITVIEW,$this->editModule,$this->package);
125 if($this->editLayout == MB_DETAILVIEW){
126 $disableLayout = $parser2->getSyncDetailEditViews();
128 if(!empty($_REQUEST['copyFromEditView'])){
129 $editViewPanels = $parser2->convertFromCanonicalForm ( $parser2->_viewdefs [ 'panels' ] , $parser2->_fielddefs ) ;
130 $parser->_viewdefs [ 'panels' ] = $editViewPanels;
131 $parser->_fielddefs = $parser2->_fielddefs;
132 $parser->setUseTabs($parser2->getUseTabs());
136 if (! $this->fromModuleBuilder)
138 $buttons [] = array (
140 'text' => translate ( 'LBL_BTN_SAVE' ) ,
141 'actionScript' => "onclick='if(Studio2.checkGridLayout(\"{$this->editLayout}\")) Studio2.handleSave();'",
142 'disabled' => $disableLayout,
144 $buttons [] = array (
145 'id' => 'publishBtn' ,
146 'text' => translate ( 'LBL_BTN_SAVEPUBLISH' ) ,
147 'actionScript' => "onclick='if(Studio2.checkGridLayout(\"{$this->editLayout}\")) Studio2.handlePublish();'",
148 'disabled' => $disableLayout,
150 $buttons [] = array ( 'id' => 'spacer' , 'width' => '33px' ) ;
151 $buttons [] = array (
152 'id' => 'historyBtn' ,
153 'text' => translate ( 'LBL_HISTORY' ) ,
154 'actionScript' => "onclick='ModuleBuilder.history.browse(\"{$this->editModule}\", \"{$this->editLayout}\")'",
155 'disabled' => $disableLayout,
157 $buttons [] = array (
158 'id' => 'historyDefault' ,
159 'text' => translate ( 'LBL_RESTORE_DEFAULT' ) ,
160 'actionScript' => "onclick='ModuleBuilder.history.revert(\"{$this->editModule}\", \"{$this->editLayout}\", \"{$history->getLast()}\", \"\")'",
161 'disabled' => $disableLayout,
165 $buttons [] = array (
167 'text' => $GLOBALS [ 'mod_strings' ] [ 'LBL_BTN_SAVE' ] ,
168 'actionScript' => "onclick='if(Studio2.checkGridLayout(\"{$this->editLayout}\")) Studio2.handlePublish();'",
169 'disabled' => $disableLayout,
171 $buttons [] = array ( 'id' => 'spacer' , 'width' => '33px' ) ;
172 $buttons [] = array (
173 'id' => 'historyBtn' ,
174 'text' => translate ( 'LBL_HISTORY' ) ,
175 'actionScript' => "onclick='ModuleBuilder.history.browse(\"{$this->editModule}\", \"{$this->editLayout}\")'",
176 'disabled' => $disableLayout,
178 $buttons [] = array (
179 'id' => 'historyDefault' ,
180 'text' => translate ( 'LBL_RESTORE_DEFAULT' ) ,
181 'actionScript' => "onclick='ModuleBuilder.history.revert(\"{$this->editModule}\", \"{$this->editLayout}\", \"{$history->getLast()}\", \"\")'",
182 'disabled' => $disableLayout,
187 if($this->editLayout == MB_DETAILVIEW || $this->editLayout == MB_QUICKCREATE){
188 $buttons [] = array (
189 'id' => 'copyFromEditView' ,
190 'text' => translate ( 'LBL_COPY_FROM_EDITVIEW' ) ,
191 'actionScript' => "onclick='ModuleBuilder.copyFromView(\"{$this->editModule}\", \"{$this->editLayout}\")'",
192 'disabled' => $disableLayout,
198 foreach ( $buttons as $button )
200 if ($button['id'] == "spacer") {
201 $html .= "<td style='width:{$button['width']}'> </td>";
203 $html .= "<td><input id='{$button['id']}' type='button' valign='center' class='button' style='cursor:pointer' "
204 . "onmousedown='this.className=\"buttonOn\";return false;' onmouseup='this.className=\"button\"' "
205 . "onmouseout='this.className=\"button\"' {$button['actionScript']} value = '{$button['text']}'" ;
206 if(!empty($button['disabled'])){
207 $html .= " disabled";
213 $smarty->assign ( 'buttons', $html ) ;
215 // assign fields and layout
216 $smarty->assign ( 'available_fields', $parser->getAvailableFields () ) ;
218 $smarty->assign ( 'disable_layout', $disableLayout) ;
219 $smarty->assign ( 'required_fields', $requiredFields) ;
220 $smarty->assign ( 'layout', $parser->getLayout () ) ;
221 $smarty->assign ( 'field_defs', $parser->getFieldDefs () ) ;
222 $smarty->assign ( 'view_module', $this->editModule ) ;
223 $smarty->assign ( 'view', $this->editLayout ) ;
224 $smarty->assign ( 'maxColumns', $parser->getMaxColumns() ) ;
225 $smarty->assign ( 'nextPanelId', $parser->getFirstNewPanelId() ) ;
226 $smarty->assign ( 'displayAsTabs', $parser->getUseTabs() ) ;
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 ( ) ;
250 $translatedViewType = '' ;
251 if ( isset ( $labels [ strtolower ( $this->editLayout ) ] ) )
252 $translatedViewType = translate ( $labels [ strtolower( $this->editLayout ) ] , 'ModuleBuilder' ) ;
254 if ($this->fromModuleBuilder)
256 $ajax->addCrumb ( translate ( 'LBL_MODULEBUILDER', 'ModuleBuilder' ), 'ModuleBuilder.main("mb")' ) ;
257 $ajax->addCrumb ( $this->package, 'ModuleBuilder.getContent("module=ModuleBuilder&action=package&package=' . $this->package . '")' ) ;
258 $ajax->addCrumb ( $this->editModule, 'ModuleBuilder.getContent("module=ModuleBuilder&action=module&view_package=' . $this->package . '&view_module=' . $this->editModule . '")' ) ;
259 $ajax->addCrumb ( translate ( $layoutLabel, 'ModuleBuilder' ), 'ModuleBuilder.getContent("module=ModuleBuilder&MB=true&action=wizard&view='.$layoutView.'&view_module=' . $this->editModule . '&view_package=' . $this->package . '")' ) ;
260 $ajax->addCrumb ( $translatedViewType, '' ) ;
263 $ajax->addCrumb ( translate ( 'LBL_STUDIO', 'ModuleBuilder' ), 'ModuleBuilder.main("studio")' ) ;
264 $ajax->addCrumb ( $this->translatedEditModule, 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard&view_module=' . $this->editModule . '")' ) ;
265 $ajax->addCrumb ( translate ( $layoutLabel, 'ModuleBuilder' ), 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard&view='.$layoutView.'&view_module=' . $this->editModule . '")' ) ;
266 $ajax->addCrumb ( $translatedViewType, '' ) ;
269 // set up language files
270 $smarty->assign ( 'language', $parser->getLanguage() ) ; // for sugar_translate in the smarty template
271 $smarty->assign('from_mb',$this->fromModuleBuilder);
272 $smarty->assign('calc_field_list', json_encode($parser->getCalculatedFields()));
273 if ($this->fromModuleBuilder) {
274 $mb = new ModuleBuilder ( ) ;
275 $module = & $mb->getPackageModule ( $this->package, $this->editModule ) ;
276 $smarty->assign('current_mod_strings', $module->getModStrings());
279 $ajax->addSection ( 'center', $translatedViewType, $smarty->fetch ( 'modules/ModuleBuilder/tpls/layoutView.tpl' ) ) ;
281 echo $smarty->fetch ( 'modules/ModuleBuilder/tpls/Preview/layoutView.tpl' );
283 echo $ajax->getJavascript () ;