]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/ModuleBuilder/views/view.layoutview.php
Release 6.1.4
[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 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
42  * Description: This file is used to override the default Meta-data EditView behavior
43  * to provide customization specific to the Calls module.
44  * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
45  * All Rights Reserved.
46  * Contributor(s): ______________________________________..
47  ********************************************************************************/
48
49 require_once ('include/MVC/View/views/view.edit.php') ;
50 require_once ('modules/ModuleBuilder/parsers/ParserFactory.php') ;
51 require_once ('modules/ModuleBuilder/MB/AjaxCompose.php') ;
52 require_once 'modules/ModuleBuilder/parsers/constants.php' ;
53
54 //require_once('include/Utils.php');
55
56
57 class ViewLayoutView extends ViewEdit
58 {
59     function ViewLayoutView ()
60     {
61         $GLOBALS [ 'log' ]->debug ( 'in ViewLayoutView' ) ;
62         $this->editModule = $_REQUEST [ 'view_module' ] ;
63         $this->editLayout = $_REQUEST [ 'view' ] ;
64         $this->package = null;
65         $this->fromModuleBuilder = isset ( $_REQUEST [ 'MB' ] ) || !empty($_REQUEST [ 'view_package' ]);
66         if ($this->fromModuleBuilder)
67         {
68             $this->package = $_REQUEST [ 'view_package' ] ;
69         } else
70         {
71             global $app_list_strings ;
72             $moduleNames = array_change_key_case ( $app_list_strings [ 'moduleList' ] ) ;
73             $this->translatedEditModule = $moduleNames [ strtolower ( $this->editModule ) ] ;
74         }
75     }
76
77     /**
78          * @see SugarView::_getModuleTitleParams()
79          */
80         protected function _getModuleTitleParams()
81         {
82             global $mod_strings;
83             
84         return array(
85            translate('LBL_MODULE_NAME','Administration'),
86            $mod_strings['LBL_MODULEBUILDER'],
87            );
88     }
89
90     // DO NOT REMOVE - overrides parent ViewEdit preDisplay() which attempts to load a bean for a non-existent module
91     function preDisplay ()
92     {
93     }
94
95     function display ($preview = false)
96     {
97
98         global $mod_strings ;
99         $parser = ParserFactory::getParser($this->editLayout,$this->editModule,$this->package);
100         $history = $parser->getHistory () ;
101         $smarty = new Sugar_Smarty ( ) ;
102         //Add in the module we are viewing to our current mod strings
103                 if (! $this->fromModuleBuilder) {
104                         global $current_language;
105                         $editModStrings = return_module_language($current_language, $this->editModule);
106                         $mod_strings = sugarArrayMerge($editModStrings, $mod_strings);
107                 }
108         $smarty->assign('mod', $mod_strings);
109                 $smarty->assign('MOD', $mod_strings);
110         // assign buttons
111         $images = array ( 'icon_save' => 'studio_save' , 'icon_publish' => 'studio_publish' , 'icon_address' => 'icon_Address' , 'icon_emailaddress' => 'icon_EmailAddress' , 'icon_phone' => 'icon_Phone' ) ;
112         foreach ( $images as $image => $file )
113         {
114             $smarty->assign ( $image, SugarThemeRegistry::current()->getImage($file) ) ;
115         }
116
117         $requiredFields = implode($parser->getRequiredFields () , ',');
118         $slashedRequiredFields = addslashes($requiredFields);
119         $buttons = array ( ) ;
120
121         if ($preview)
122         {
123             $smarty->assign ( 'layouttitle', translate ( 'LBL_LAYOUT_PREVIEW', 'ModuleBuilder' ) ) ;
124         } else
125         {
126             $smarty->assign ( 'layouttitle', translate ( 'LBL_CURRENT_LAYOUT', 'ModuleBuilder' ) ) ;
127             if (! $this->fromModuleBuilder)
128             {
129                 $buttons [] = array ( 
130                     'id' => 'saveBtn' , 
131                     'text' => translate ( 'LBL_BTN_SAVE' ) , 
132                     'actionScript' => "onclick='if(Studio2.checkGridLayout(\"{$this->editLayout}\")) Studio2.handleSave();'" 
133                 ) ;
134                 $buttons [] = array ( 
135                     'id' => 'publishBtn' , 
136                     'text' => translate ( 'LBL_BTN_SAVEPUBLISH' ) , 
137                     'actionScript' => "onclick='if(Studio2.checkGridLayout(\"{$this->editLayout}\")) Studio2.handlePublish();'" 
138                 ) ;
139                 $buttons [] = array ( 'id' => 'spacer' , 'width' => '50px' ) ;
140                 $buttons [] = array ( 
141                         'id' => 'historyBtn' , 
142                         'text' => translate ( 'LBL_HISTORY' ) , 
143                         'actionScript' => "onclick='ModuleBuilder.history.browse(\"{$this->editModule}\", \"{$this->editLayout}\")'"
144                 ) ;
145                 $buttons [] = array ( 
146                         'id' => 'historyDefault' , 
147                         'text' => translate ( 'LBL_RESTORE_DEFAULT' ) , 
148                         'actionScript' => "onclick='ModuleBuilder.history.revert(\"{$this->editModule}\", \"{$this->editLayout}\", \"{$history->getLast()}\", \"\")'" 
149                 ) ;
150             } else
151             {
152                 $buttons [] = array ( 
153                     'id' => 'saveBtn' , 
154                     'text' => $GLOBALS [ 'mod_strings' ] [ 'LBL_BTN_SAVE' ] , 
155                     'actionScript' => "onclick='if(Studio2.checkGridLayout(\"{$this->editLayout}\")) Studio2.handlePublish();'" 
156                 ) ;
157                 $buttons [] = array ( 'id' => 'spacer' , 'width' => '50px' ) ;
158                 $buttons [] = array (
159                     'id' => 'historyBtn' , 
160                     'text' => translate ( 'LBL_HISTORY' ) , 
161                     'actionScript' => "onclick='ModuleBuilder.history.browse(\"{$this->editModule}\", \"{$this->editLayout}\")'" 
162                 ) ;
163                 $buttons [] = array ( 
164                     'id' => 'historyDefault' , 
165                     'text' => translate ( 'LBL_RESTORE_DEFAULT' ) , 
166                     'actionScript' => "onclick='ModuleBuilder.history.revert(\"{$this->editModule}\", \"{$this->editLayout}\", \"{$history->getLast()}\", \"\")'" 
167                 ) ;
168             }
169         }
170
171         $html = "" ;
172         foreach ( $buttons as $button )
173         {
174             if ($button['id'] == "spacer") {
175                 $html .= "<td style='width:{$button['width']}'> </td>";
176             } else {
177                     $html .= "<td><input id='{$button['id']}' type='button' valign='center' class='button' style='cursor:pointer' "
178                        . "onmousedown='this.className=\"buttonOn\";return false;' onmouseup='this.className=\"button\"' "
179                        . "onmouseout='this.className=\"button\"' {$button['actionScript']} value = '{$button['text']}' ></td>" ;
180             }
181         }
182
183         $smarty->assign ( 'buttons', $html ) ;
184
185         // assign fields and layout
186         $smarty->assign ( 'available_fields', $parser->getAvailableFields () ) ;
187         $smarty->assign ( 'required_fields', $requiredFields) ;
188         $smarty->assign ( 'layout', $parser->getLayout () ) ;
189         $smarty->assign ( 'view_module', $this->editModule ) ;
190         $smarty->assign ( 'view', $this->editLayout ) ;
191         $smarty->assign ( 'maxColumns', $parser->getMaxColumns() ) ;
192         $smarty->assign ( 'nextPanelId', $parser->getFirstNewPanelId() ) ;
193         $smarty->assign ( 'displayAsTabs', $parser->getUseTabs() ) ;
194         $smarty->assign ( 'fieldwidth', 150 ) ;
195         $smarty->assign ( 'translate', $this->fromModuleBuilder ? false : true ) ;
196
197         if ($this->fromModuleBuilder)
198         {
199             $smarty->assign ( 'fromModuleBuilder', $this->fromModuleBuilder ) ;
200             $smarty->assign ( 'view_package', $this->package ) ;
201         }
202
203         $labels = array (
204                                 MB_EDITVIEW => 'LBL_EDITVIEW' ,
205                                 MB_DETAILVIEW => 'LBL_DETAILVIEW' ,
206                                 MB_QUICKCREATE => 'LBL_QUICKCREATE',
207                                 ) ;
208
209         $layoutLabel = 'LBL_LAYOUTS' ;
210         $layoutView = 'layouts' ;
211
212
213         $ajax = new AjaxCompose ( ) ;
214         $viewType;
215
216         $translatedViewType = '' ;
217                 if ( isset ( $labels [ strtolower ( $this->editLayout ) ] ) )
218                         $translatedViewType = translate ( $labels [ strtolower( $this->editLayout ) ] , 'ModuleBuilder' ) ;
219
220         if ($this->fromModuleBuilder)
221         {
222             $ajax->addCrumb ( translate ( 'LBL_MODULEBUILDER', 'ModuleBuilder' ), 'ModuleBuilder.main("mb")' ) ;
223             $ajax->addCrumb ( $this->package, 'ModuleBuilder.getContent("module=ModuleBuilder&action=package&package=' . $this->package . '")' ) ;
224             $ajax->addCrumb ( $this->editModule, 'ModuleBuilder.getContent("module=ModuleBuilder&action=module&view_package=' . $this->package . '&view_module=' . $this->editModule . '")' ) ;
225             $ajax->addCrumb ( translate ( $layoutLabel, 'ModuleBuilder' ), 'ModuleBuilder.getContent("module=ModuleBuilder&MB=true&action=wizard&view='.$layoutView.'&view_module=' . $this->editModule . '&view_package=' . $this->package . '")' ) ;
226             $ajax->addCrumb ( $translatedViewType, '' ) ;
227         } else
228         {
229             $ajax->addCrumb ( translate ( 'LBL_STUDIO', 'ModuleBuilder' ), 'ModuleBuilder.main("studio")' ) ;
230             $ajax->addCrumb ( $this->translatedEditModule, 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard&view_module=' . $this->editModule . '")' ) ;
231             $ajax->addCrumb ( translate ( $layoutLabel, 'ModuleBuilder' ), 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard&view='.$layoutView.'&view_module=' . $this->editModule . '")' ) ;
232             $ajax->addCrumb ( $translatedViewType, '' ) ;
233         }
234
235         // set up language files
236                 $smarty->assign ( 'language', $parser->getLanguage() ) ; // for sugar_translate in the smarty template
237         $smarty->assign('from_mb',$this->fromModuleBuilder);
238         $smarty->assign('calc_field_list', json_encode($parser->getCalculatedFields()));
239                 if ($this->fromModuleBuilder) {
240                         $mb = new ModuleBuilder ( ) ;
241             $module = & $mb->getPackageModule ( $this->package, $this->editModule ) ;
242                     $smarty->assign('current_mod_strings', $module->getModStrings());
243                 }
244
245         $ajax->addSection ( 'center', $translatedViewType, $smarty->fetch ( 'modules/ModuleBuilder/tpls/layoutView.tpl' ) ) ;
246         if ($preview) {
247                 echo $smarty->fetch ( 'modules/ModuleBuilder/tpls/Preview/layoutView.tpl' );
248                 } else {
249                         echo $ajax->getJavascript () ;
250         }
251     }
252 }