]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/ModuleBuilder/views/view.listview.php
Release 6.4.0
[Github/sugarcrm.git] / modules / ModuleBuilder / views / view.listview.php
1 <?php
2 if (! defined ( 'sugarEntry' ) || ! sugarEntry)
3     die ( 'Not A Valid Entry Point' ) ;
4 /*********************************************************************************
5  * SugarCRM Community Edition is a customer relationship management program developed by
6  * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
7  * 
8  * This program is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU Affero General Public License version 3 as published by the
10  * Free Software Foundation with the addition of the following permission added
11  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
12  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
13  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
14  * 
15  * This program is distributed in the hope that it will be useful, but WITHOUT
16  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
18  * details.
19  * 
20  * You should have received a copy of the GNU Affero General Public License along with
21  * this program; if not, see http://www.gnu.org/licenses or write to the Free
22  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23  * 02110-1301 USA.
24  * 
25  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
26  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
27  * 
28  * The interactive user interfaces in modified source and object code versions
29  * of this program must display Appropriate Legal Notices, as required under
30  * Section 5 of the GNU Affero General Public License version 3.
31  * 
32  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
33  * these Appropriate Legal Notices must retain the display of the "Powered by
34  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
35  * technical reasons, the Appropriate Legal Notices must display the words
36  * "Powered by SugarCRM".
37  ********************************************************************************/
38
39
40 //Load the parent view class if it exists.  Check for custom file first
41 loadParentView('edit');
42
43 require_once 'modules/ModuleBuilder/parsers/constants.php' ;
44 require_once ('include/SubPanel/SubPanel.php') ;
45
46 class ViewListView extends ViewEdit
47 {
48     /**
49          * @see SugarView::_getModuleTitleParams()
50          */
51         protected function _getModuleTitleParams($browserTitle = false)
52         {
53             global $mod_strings;
54             
55         return array(
56            translate('LBL_MODULE_NAME','Administration'),
57            ModuleBuilderController::getModuleTitle(),
58            );
59     }
60
61     /*
62      * Pseudo-constructor to enable subclasses to call a parent's constructor without knowing the parent in PHP4
63      */
64     function __construct()
65     {
66         $this->editModule = $_REQUEST [ 'view_module' ] ;
67         $this->editLayout = $_REQUEST [ 'view' ] ;
68         $this->subpanel = (! empty ( $_REQUEST [ 'subpanel' ] )) ? $_REQUEST [ 'subpanel' ] : false ;
69         $this->subpanelLabel = (! empty ( $_REQUEST [ 'subpanelLabel' ] )) ? $_REQUEST [ 'subpanelLabel' ] : false ;
70
71         $this->fromModuleBuilder = ! empty ( $_REQUEST [ 'view_package' ] ) ;
72         if (! $this->fromModuleBuilder)
73         {
74             $moduleNames = array_change_key_case ( $GLOBALS['app_list_strings'] [ 'moduleList' ] ) ;
75             $this->translatedEditModule = $moduleNames [ strtolower ( $this->editModule ) ] ;
76         }
77     }
78
79     // DO NOT REMOVE - overrides parent ViewEdit preDisplay() which attempts to load a bean for a non-existent module
80     function preDisplay ()
81     {
82     }
83
84     function display ($preview = false)
85     {
86
87         $packageName = (! empty ( $_REQUEST [ 'view_package' ] )) ? $_REQUEST [ 'view_package' ] : null ;
88         $subpanelName = (! empty ( $_REQUEST [ 'subpanel' ] )) ? $_REQUEST [ 'subpanel' ] : null ;
89         require_once 'modules/ModuleBuilder/parsers/ParserFactory.php' ;
90         $parser = ParserFactory::getParser (  $this->editLayout , $this->editModule , $packageName, $subpanelName ) ;
91         $smarty = $this->constructSmarty ( $parser ) ;
92
93         if ($preview)
94         {
95             echo $smarty->fetch ( "modules/ModuleBuilder/tpls/Preview/listView.tpl" ) ;
96         } else
97         {
98             $ajax = $this->constructAjax () ;
99             $ajax->addSection ( 'center', $this->translatedViewType, $smarty->fetch ( "modules/ModuleBuilder/tpls/listView.tpl" ) ) ;
100
101             echo $ajax->getJavascript () ;
102         }
103     }
104
105     function constructAjax ()
106     {
107         require_once ('modules/ModuleBuilder/MB/AjaxCompose.php') ;
108         $ajax = new AjaxCompose ( ) ;
109
110         $layoutLabel = 'LBL_LAYOUTS' ;
111         $layoutView = 'layouts' ;
112
113
114         $labels = array (
115                                 MB_LISTVIEW => 'LBL_LISTVIEW' ,
116                                 ) ;
117         $translatedViewType = '' ;
118                 if ( isset ( $labels [ strtolower ( $this->editLayout ) ] ) )
119                         $translatedViewType = translate ( $labels [ strtolower( $this->editLayout ) ] , 'ModuleBuilder' ) ;
120                 $this->translatedViewType = $translatedViewType;
121
122         if ($this->fromModuleBuilder)
123         {
124             $ajax->addCrumb ( translate ( 'LBL_MODULEBUILDER', 'ModuleBuilder' ), 'ModuleBuilder.main("mb")' ) ;
125             $ajax->addCrumb ( $_REQUEST [ 'view_package' ], 'ModuleBuilder.getContent("module=ModuleBuilder&action=package&package=' . $_REQUEST [ 'view_package' ] . '")' ) ;
126             $ajax->addCrumb ( $this->editModule, 'ModuleBuilder.getContent("module=ModuleBuilder&action=module&view_package=' . $_REQUEST [ 'view_package' ] . '&view_module=' . $_REQUEST [ 'view_module' ] . '")' ) ;
127             if ($this->subpanel != "")
128             {
129                 $ajax->addCrumb ( translate ( 'LBL_AVAILABLE_SUBPANELS', 'ModuleBuilder' ), '' ) ;
130                 if ($this->subpanelLabel)
131                 {
132                     $ajax->addCrumb ( $this->subpanelLabel, '' ) ;
133                     $this->translatedViewType = $this->subpanelLabel . "&nbsp;" . translate("LBL_SUBPANEL", "ModuleBuilder");
134                 } else
135                 {
136                     $ajax->addCrumb ( $this->subpanel, '' ) ;
137                     $this->translatedViewType = translate("LBL_SUBPANEL", "ModuleBuilder");
138                 }
139             } else
140             {
141                 $ajax->addCrumb ( translate ( $layoutLabel, 'ModuleBuilder' ), 'ModuleBuilder.getContent("module=ModuleBuilder&MB=true&action=wizard&view_module=' . $_REQUEST [ 'view_module' ] . '&view_package=' . $_REQUEST [ 'view_package' ] . '")' ) ;
142                 $ajax->addCrumb ( $translatedViewType, '' ) ;
143             }
144         } else
145         {
146             $ajax->addCrumb ( translate ( 'LBL_STUDIO', 'ModuleBuilder' ), 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard")' ) ;
147             $ajax->addCrumb ( $this->translatedEditModule, 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard&view_module=' . $this->editModule . '")' ) ;
148
149             if ($this->subpanel)
150             {
151                 $ajax->addCrumb ( translate ( 'LBL_SUBPANELS', 'ModuleBuilder' ), 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard&view=subpanels&view_module=' . $this->editModule . '")' ) ;
152                 if ($this->subpanelLabel)
153                 {
154                     $ajax->addCrumb ( $this->subpanelLabel, '' ) ;
155                     $this->translatedViewType = $this->subpanelLabel . "&nbsp;" . translate("LBL_SUBPANEL", "ModuleBuilder");
156                 } else
157                 {
158                     $ajax->addCrumb ( $this->subpanel, '' ) ;
159                     $this->translatedViewType = translate("LBL_SUBPANEL", "ModuleBuilder");
160                 }
161             } else
162             {
163                 $ajax->addCrumb ( translate ( $layoutLabel, 'ModuleBuilder' ), 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard&view='.$layoutView.'&view_module=' . $this->editModule . '")' ) ;
164                 $ajax->addCrumb ( $translatedViewType, '' ) ;
165             }
166         }
167         return $ajax ;
168     }
169
170     function constructSmarty ($parser)
171     {
172         global $mod_strings;
173         $smarty = new Sugar_Smarty ( ) ;
174         $smarty->assign ( 'translate', true ) ;
175         $smarty->assign ( 'language', $parser->getLanguage () ) ;
176
177         $smarty->assign ( 'view', $this->editLayout ) ;
178         $smarty->assign ( 'module', "ModuleBuilder" ) ;
179         $smarty->assign ( 'field_defs', $parser->getFieldDefs () ) ;
180         $smarty->assign ( 'action', 'listViewSave' ) ;
181         $smarty->assign ( 'view_module', $this->editModule ) ;
182         if (!empty ( $this->subpanel ) )
183         {
184             $smarty->assign ( 'subpanel', $this->subpanel ) ;
185             $smarty->assign ( 'subpanelLabel', $this->subpanelLabel ) ;
186             if (!$this->fromModuleBuilder) {
187                 $subList =  SubPanel::getModuleSubpanels ( $this->editModule);
188                 $subRef = $subList[strtolower($this->subpanel)];
189                 $subTitleKey = !empty($subRef) ? $subRef : "LBL_" . strtoupper($this->subpanel) . "_SUBPANEL_TITLE";
190                 $subTitle    = !empty($subRef) ? translate($subTitleKey, $this->editModule) : UCfirst($this->subpanel);
191                 $smarty->assign ( 'subpanel_label', $subTitleKey ) ;
192                 $smarty->assign ( 'subpanel_title', $subTitle ) ;
193             }
194         }
195         $helpName = $this->subpanel ? 'subPanelEditor' : 'listViewEditor';
196         $smarty->assign ( 'helpName', $helpName ) ;
197         $smarty->assign ( 'helpDefault', 'modify' ) ;
198
199         $smarty->assign ( 'title', $this->_constructTitle () ) ;
200         $groups = array ( ) ;
201         foreach ( $parser->columns as $column => $function )
202         {
203             // update this so that each field has a properties set
204             // properties are name, value, title (optional)
205             $groups [ $GLOBALS [ 'mod_strings' ] [ $column ] ] = $parser->$function () ; // call the parser functions to populate the list view columns, by default 'default', 'available' and 'hidden'
206         }
207         foreach ( $groups as $groupKey => $group )
208         {
209             foreach ( $group as $fieldKey => $field )
210             {
211                 if (isset ( $field [ 'width' ] ))
212                 {
213                     if (substr ( $field [ 'width' ], - 1, 1 ) == '%')
214                     {
215
216                         $groups [ $groupKey ] [ $fieldKey ] [ 'width' ] = substr ( $field [ 'width' ], 0, strlen ( $field [ 'width' ] ) - 1 ) ;
217                     }
218                 }
219             }
220         }
221
222         $smarty->assign ( 'groups', $groups ) ;
223         $smarty->assign('from_mb', $this->fromModuleBuilder);
224
225         global $image_path;
226         $imageSave = SugarThemeRegistry::current()->getImage('studio_save','',null,null,'.gif',$mod_strings['LBL_BTN_SAVE']) ;
227
228 //        $imageHelp = SugarThemeRegistry::current()->getImage('help') ;
229
230
231         $history = $parser->getHistory () ;
232
233         $histaction = "ModuleBuilder.history.browse(\"{$this->editModule}\", \"{$this->editLayout}\")" ;
234         if ($this->subpanel)
235             $histaction = "ModuleBuilder.history.browse(\"{$this->editModule}\", \"{$this->editLayout}\", \"{$this->subpanel}\")" ;
236
237         $restoreAction = "onclick='ModuleBuilder.history.revert(\"{$this->editModule}\", \"{$this->editLayout}\", \"{$history->getLast()}\", \"\")'";
238         if ($this->subpanel)
239             $restoreAction = "onclick='ModuleBuilder.history.revert(\"{$this->editModule}\", \"{$this->editLayout}\", \"{$history->getLast()}\", \"{$this->subpanel}\")'";
240
241         $buttons = array ( ) ;
242         $buttons [] = array ( 'id' =>'savebtn', 'name' => 'savebtn' , 'image' => $imageSave , 'text' => (! $this->fromModuleBuilder)?$GLOBALS [ 'mod_strings' ] [ 'LBL_BTN_SAVEPUBLISH' ]: $GLOBALS [ 'mod_strings' ] [ 'LBL_BTN_SAVE' ], 'actionScript' => "onclick='studiotabs.generateGroupForm(\"edittabs\");if (countListFields()==0) ModuleBuilder.layoutValidation.popup() ; else ModuleBuilder.handleSave(\"edittabs\" )'" ) ;
243         $buttons [] = array ( 'id' => 'spacer' , 'width' => '50px' ) ;
244         $buttons [] = array ( 'id' =>'historyBtn',       'name' => 'historyBtn' , 'text' => translate ( 'LBL_HISTORY' ) , 'actionScript' => "onclick='$histaction'" ) ;
245         $buttons [] = array ( 'id' => 'historyDefault' , 'name' => 'historyDefault',  'text' => translate ( 'LBL_RESTORE_DEFAULT' ) , 'actionScript' => $restoreAction ) ;
246
247         $smarty->assign ( 'buttons', $this->_buildImageButtons ( $buttons ) ) ;
248
249         $editImage = SugarThemeRegistry::current()->getImage('edit_inline','',null,null,'.gif',$mod_strings['LBL_EDIT']) ;
250
251         $smarty->assign ( 'editImage', $editImage ) ;
252         $deleteImage = SugarThemeRegistry::current()->getImage('delete_inline','',null,null,'.gif',$mod_strings['LBL_MB_DELETE']) ;
253
254         $smarty->assign ( 'deleteImage', $deleteImage ) ;
255         $smarty->assign ( 'MOD', $GLOBALS [ 'mod_strings' ] ) ;
256
257         if ($this->fromModuleBuilder)
258         {
259             $smarty->assign ( 'MB', true ) ;
260             $smarty->assign ( 'view_package', $_REQUEST [ 'view_package' ] ) ;
261             $mb = new ModuleBuilder ( ) ;
262             $module = & $mb->getPackageModule ( $_REQUEST [ 'view_package' ], $this->editModule ) ;
263             $smarty->assign('current_mod_strings', $module->getModStrings());
264             if ($this->subpanel)
265             {
266                 if (isset ( $_REQUEST [ 'local' ] ))
267                 {
268                     $smarty->assign ( 'local', '1' ) ;
269                 }
270                 $smarty->assign ( "subpanel", $this->subpanel ) ;
271             } else
272             {
273                 $smarty->assign ( 'description', $GLOBALS [ 'mod_strings' ] [ 'LBL_LISTVIEW_DESCRIPTION' ] ) ;
274
275             }
276
277         } else
278         {
279             if ($this->subpanel)
280             {
281                 $smarty->assign ( "subpanel", "$this->subpanel" ) ;
282             } else
283             {
284                 $smarty->assign ( 'description', $GLOBALS [ 'mod_strings' ] [ 'LBL_LISTVIEW_DESCRIPTION' ] ) ;
285             }
286         }
287
288         return $smarty ;
289     }
290
291     function _constructTitle ()
292
293     {
294
295         global $app_list_strings ;
296
297         if ($this->fromModuleBuilder)
298         {
299             $title = $this->editModule ;
300             if ($this->subpanel != "")
301             {
302                 $title .= ":$this->subpanel" ;
303             }
304         } else
305         {
306             $title = ($this->subpanel) ? ':' . $this->subpanel : $app_list_strings [ 'moduleList' ] [ $this->editModule ] ;
307         }
308         return $GLOBALS [ 'mod_strings' ] [ 'LBL_LISTVIEW_EDIT' ] . ':&nbsp;' . $title ;
309
310     }
311
312     function _buildImageButtons ($buttons , $horizontal = true)
313     {
314         $text = '<table cellspacing=2><tr>' ;
315         foreach ( $buttons as $button )
316         {
317             if (empty($button['id'])) {
318                 $button['id'] = $button['name'];
319             }
320             if (! $horizontal)
321             {
322                 $text .= '</tr><tr>' ;
323             }
324             if ($button['id'] == "spacer") {
325                 $text .= "<td style='width:{$button['width']}'> </td>";
326                 continue;
327             }
328
329             if (! empty ( $button [ 'plain' ] ))
330             {
331                 $text .= <<<EOQ
332                      <td><input name={$button['name']} id={$button['id']} class="button" type="button" valign='center' {$button['actionScript']}
333 EOQ;
334
335             } else
336             {
337                 $text .= <<<EOQ
338                   <td><input name={$button['name']} id={$button['id']} class="button" type="button" valign='center' style='cursor:default'  {$button['actionScript']}
339 EOQ;
340             }
341             $text .= "value=\"{$button['text']}\"/></td>" ;
342         }
343         $text .= '</tr></table>' ;
344         return $text ;
345     }
346 }