]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/ModuleBuilder/views/view.layoutview.php
Release 6.4.0
[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-2011 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         } else
64         {
65             global $app_list_strings ;
66             $moduleNames = array_change_key_case ( $app_list_strings [ 'moduleList' ] ) ;
67             $this->translatedEditModule = $moduleNames [ strtolower ( $this->editModule ) ] ;
68         }
69     }
70
71     /**
72          * @see SugarView::_getModuleTitleParams()
73          */
74         protected function _getModuleTitleParams($browserTitle = false)
75         {
76             global $mod_strings;
77             
78         return array(
79            translate('LBL_MODULE_NAME','Administration'),
80            ModuleBuilderController::getModuleTitle(),
81            );
82     }
83
84     // DO NOT REMOVE - overrides parent ViewEdit preDisplay() which attempts to load a bean for a non-existent module
85     function preDisplay ()
86     {
87     }
88
89     function display ($preview = false)
90     {
91
92         global $mod_strings ;
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);
101                 }
102         $smarty->assign('mod', $mod_strings);
103                 $smarty->assign('MOD', $mod_strings);
104         // assign buttons
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 )
107         {
108             $smarty->assign ( $image, SugarThemeRegistry::current()->getImage($file,'',null,null,'.gif',$file) ) ;
109         }
110
111         $requiredFields = implode($parser->getRequiredFields () , ',');
112         $slashedRequiredFields = addslashes($requiredFields);
113         $buttons = array ( ) ;
114         $disableLayout = false;
115
116         if ($preview)
117         {
118             $smarty->assign ( 'layouttitle', translate ( 'LBL_LAYOUT_PREVIEW', 'ModuleBuilder' ) ) ;
119         } else
120         {
121             $smarty->assign ( 'layouttitle', translate ( 'LBL_CURRENT_LAYOUT', 'ModuleBuilder' ) ) ;
122
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();
127                 }
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());
133                 }
134                     }
135
136             if (! $this->fromModuleBuilder)
137             {
138                     $buttons [] = array (
139                     'id' => 'saveBtn' , 
140                     'text' => translate ( 'LBL_BTN_SAVE' ) , 
141                     'actionScript' => "onclick='if(Studio2.checkGridLayout(\"{$this->editLayout}\")) Studio2.handleSave();'",
142                         'disabled' => $disableLayout, 
143                 ) ;
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, 
149                 ) ;
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,
156                 ) ;
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, 
162                 ) ;
163             } else
164             {
165                 $buttons [] = array ( 
166                     'id' => 'saveBtn' , 
167                     'text' => $GLOBALS [ 'mod_strings' ] [ 'LBL_BTN_SAVE' ] , 
168                     'actionScript' => "onclick='if(Studio2.checkGridLayout(\"{$this->editLayout}\")) Studio2.handlePublish();'",
169                     'disabled' => $disableLayout,
170                 ) ;
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, 
177                 ) ;
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, 
183                 ) ;
184             }
185
186
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,
193                 ) ;
194             }
195         }
196
197         $html = "" ;
198         foreach ( $buttons as $button )
199         {
200             if ($button['id'] == "spacer") {
201                 $html .= "<td style='width:{$button['width']}'> </td>";
202             } else {
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";
208                     }
209                     $html .= "></td>";
210             }
211         }
212
213         $smarty->assign ( 'buttons', $html ) ;
214
215         // assign fields and layout
216         $smarty->assign ( 'available_fields', $parser->getAvailableFields () ) ;
217         
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 ) ;
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         $viewType;
249
250         $translatedViewType = '' ;
251                 if ( isset ( $labels [ strtolower ( $this->editLayout ) ] ) )
252                         $translatedViewType = translate ( $labels [ strtolower( $this->editLayout ) ] , 'ModuleBuilder' ) ;
253
254         if ($this->fromModuleBuilder)
255         {
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, '' ) ;
261         } else
262         {
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, '' ) ;
267         }
268
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());
277                 }
278
279         $ajax->addSection ( 'center', $translatedViewType, $smarty->fetch ( 'modules/ModuleBuilder/tpls/layoutView.tpl' ) ) ;
280         if ($preview) {
281                 echo $smarty->fetch ( 'modules/ModuleBuilder/tpls/Preview/layoutView.tpl' );
282                 } else {
283                         echo $ajax->getJavascript () ;
284         }
285     }
286 }