]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/ModuleBuilder/views/view.layoutview.php
Release 6.5.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-2012 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             $this->type = $this->editLayout;
64         } else
65         {
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);
71         }
72     }
73
74     /**
75          * @see SugarView::_getModuleTitleParams()
76          */
77         protected function _getModuleTitleParams($browserTitle = false)
78         {
79             global $mod_strings;
80             
81         return array(
82            translate('LBL_MODULE_NAME','Administration'),
83            ModuleBuilderController::getModuleTitle(),
84            );
85     }
86
87     // DO NOT REMOVE - overrides parent ViewEdit preDisplay() which attempts to load a bean for a non-existent module
88     function preDisplay ()
89     {
90     }
91
92     function display ($preview = false)
93     {
94
95         global $mod_strings ;
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);
104                 }
105         $smarty->assign('mod', $mod_strings);
106                 $smarty->assign('MOD', $mod_strings);
107         // assign buttons
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 )
110         {
111             $smarty->assign ( $image, SugarThemeRegistry::current()->getImage($file,'',null,null,'.gif',$file) ) ;
112         }
113
114         $requiredFields = implode($parser->getRequiredFields () , ',');
115         $slashedRequiredFields = addslashes($requiredFields);
116         $buttons = array ( ) ;
117         $disableLayout = false;
118
119         if ($preview)
120         {
121             $smarty->assign ( 'layouttitle', translate ( 'LBL_LAYOUT_PREVIEW', 'ModuleBuilder' ) ) ;
122         } else
123         {
124             $smarty->assign ( 'layouttitle', translate ( 'LBL_CURRENT_LAYOUT', 'ModuleBuilder' ) ) ;
125
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();
131                 }
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());
137                 }
138                     }
139
140             if (! $this->fromModuleBuilder)
141             {
142                     $buttons [] = array (
143                     'id' => 'saveBtn' , 
144                     'text' => translate ( 'LBL_BTN_SAVE' ) , 
145                     'actionScript' => "onclick='if(Studio2.checkGridLayout(\"{$this->editLayout}\")) Studio2.handleSave();'",
146                         'disabled' => $disableLayout, 
147                 ) ;
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, 
153                 ) ;
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,
160                 ) ;
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, 
166                 ) ;
167             } else
168             {
169                 $buttons [] = array ( 
170                     'id' => 'saveBtn' , 
171                     'text' => $GLOBALS [ 'mod_strings' ] [ 'LBL_BTN_SAVE' ] , 
172                     'actionScript' => "onclick='if(Studio2.checkGridLayout(\"{$this->editLayout}\")) Studio2.handlePublish();'",
173                     'disabled' => $disableLayout,
174                 ) ;
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, 
181                 ) ;
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, 
187                 ) ;
188             }
189
190
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,
197                 ) ;
198             }
199         }
200
201         $html = "" ;
202         foreach ( $buttons as $button )
203         {
204             if ($button['id'] == "spacer") {
205                 $html .= "<td style='width:{$button['width']}'> </td>";
206             } else {
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";
212                     }
213                     $html .= "></td>";
214             }
215         }
216
217         $smarty->assign ( 'buttons', $html ) ;
218
219         // assign fields and layout
220         $smarty->assign ( 'available_fields', $parser->getAvailableFields () ) ;
221         
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 ( 'syncDetailEditViews', $parser->getSyncDetailEditViews() ) ;
232         $smarty->assign ( 'fieldwidth', 150 ) ;
233         $smarty->assign ( 'translate', $this->fromModuleBuilder ? false : true ) ;
234
235         if ($this->fromModuleBuilder)
236         {
237             $smarty->assign ( 'fromModuleBuilder', $this->fromModuleBuilder ) ;
238             $smarty->assign ( 'view_package', $this->package ) ;
239         }
240
241         $labels = array (
242                                 MB_EDITVIEW => 'LBL_EDITVIEW' ,
243                                 MB_DETAILVIEW => 'LBL_DETAILVIEW' ,
244                                 MB_QUICKCREATE => 'LBL_QUICKCREATE',
245                                 ) ;
246
247         $layoutLabel = 'LBL_LAYOUTS' ;
248         $layoutView = 'layouts' ;
249
250
251         $ajax = new AjaxCompose ( ) ;
252
253         $translatedViewType = '' ;
254                 if ( isset ( $labels [ strtolower ( $this->editLayout ) ] ) )
255                         $translatedViewType = translate ( $labels [ strtolower( $this->editLayout ) ] , 'ModuleBuilder' ) ;
256         else if (isset($this->sm))
257         {
258             foreach($this->sm->sources as $file => $def)
259             {
260                 if (!empty($def['view']) && $def['view'] == $this->editLayout && !empty($def['name']))
261                 {
262                     $translatedViewType = $def['name'];
263                 }
264             }
265             if(empty($translatedViewType))
266             {
267                 $label = "LBL_" . strtoupper($this->editLayout);
268                 $translated = translate($label, $this->editModule);
269                 if ($translated != $label)
270                     $translatedViewType =  $translated;
271             }
272         }
273
274
275
276
277         if ($this->fromModuleBuilder)
278         {
279             $ajax->addCrumb ( translate ( 'LBL_MODULEBUILDER', 'ModuleBuilder' ), 'ModuleBuilder.main("mb")' ) ;
280             $ajax->addCrumb ( $this->package, 'ModuleBuilder.getContent("module=ModuleBuilder&action=package&package=' . $this->package . '")' ) ;
281             $ajax->addCrumb ( $this->editModule, 'ModuleBuilder.getContent("module=ModuleBuilder&action=module&view_package=' . $this->package . '&view_module=' . $this->editModule . '")' ) ;
282             $ajax->addCrumb ( translate ( $layoutLabel, 'ModuleBuilder' ), 'ModuleBuilder.getContent("module=ModuleBuilder&MB=true&action=wizard&view='.$layoutView.'&view_module=' . $this->editModule . '&view_package=' . $this->package . '")' ) ;
283             $ajax->addCrumb ( $translatedViewType, '' ) ;
284         } else
285         {
286             $ajax->addCrumb ( translate ( 'LBL_STUDIO', 'ModuleBuilder' ), 'ModuleBuilder.main("studio")' ) ;
287             $ajax->addCrumb ( $this->translatedEditModule, 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard&view_module=' . $this->editModule . '")' ) ;
288             $ajax->addCrumb ( translate ( $layoutLabel, 'ModuleBuilder' ), 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard&view='.$layoutView.'&view_module=' . $this->editModule . '")' ) ;
289             $ajax->addCrumb ( $translatedViewType, '' ) ;
290         }
291
292         // set up language files
293                 $smarty->assign ( 'language', $parser->getLanguage() ) ; // for sugar_translate in the smarty template
294         $smarty->assign('from_mb',$this->fromModuleBuilder);
295         $smarty->assign('calc_field_list', json_encode($parser->getCalculatedFields()));
296                 if ($this->fromModuleBuilder) {
297                         $mb = new ModuleBuilder ( ) ;
298             $module = & $mb->getPackageModule ( $this->package, $this->editModule ) ;
299                     $smarty->assign('current_mod_strings', $module->getModStrings());
300                 }
301
302         $ajax->addSection ( 'center', $translatedViewType, $smarty->fetch ( 'modules/ModuleBuilder/tpls/layoutView.tpl' ) ) ;
303         if ($preview) {
304                 echo $smarty->fetch ( 'modules/ModuleBuilder/tpls/Preview/layoutView.tpl' );
305                 } else {
306                         echo $ajax->getJavascript () ;
307         }
308     }
309 }