]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/ModuleBuilder/views/view.listview.php
Release 6.2.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
41
42
43 require_once ('include/MVC/View/views/view.edit.php') ;
44
45 require_once 'modules/ModuleBuilder/parsers/constants.php' ;
46 require_once ('include/SubPanel/SubPanel.php') ;
47
48 class ViewListView extends ViewEdit
49 {
50     /**
51          * @see SugarView::_getModuleTitleParams()
52          */
53         protected function _getModuleTitleParams($browserTitle = false)
54         {
55             global $mod_strings;
56             
57         return array(
58            translate('LBL_MODULE_NAME','Administration'),
59            ModuleBuilderController::getModuleTitle(),
60            );
61     }
62
63     /*
64      * Pseudo-constructor to enable subclasses to call a parent's constructor without knowing the parent in PHP4
65      */
66     function __construct()
67     {
68         $this->editModule = $_REQUEST [ 'view_module' ] ;
69         $this->editLayout = $_REQUEST [ 'view' ] ;
70         $this->subpanel = (! empty ( $_REQUEST [ 'subpanel' ] )) ? $_REQUEST [ 'subpanel' ] : false ;
71         $this->subpanelLabel = (! empty ( $_REQUEST [ 'subpanelLabel' ] )) ? $_REQUEST [ 'subpanelLabel' ] : false ;
72
73         $this->fromModuleBuilder = ! empty ( $_REQUEST [ 'view_package' ] ) ;
74         if (! $this->fromModuleBuilder)
75         {
76             $moduleNames = array_change_key_case ( $GLOBALS['app_list_strings'] [ 'moduleList' ] ) ;
77             $this->translatedEditModule = $moduleNames [ strtolower ( $this->editModule ) ] ;
78         }
79     }
80
81     // DO NOT REMOVE - overrides parent ViewEdit preDisplay() which attempts to load a bean for a non-existent module
82     function preDisplay ()
83     {
84     }
85
86     function display ($preview = false)
87     {
88
89         $packageName = (! empty ( $_REQUEST [ 'view_package' ] )) ? $_REQUEST [ 'view_package' ] : null ;
90         $subpanelName = (! empty ( $_REQUEST [ 'subpanel' ] )) ? $_REQUEST [ 'subpanel' ] : null ;
91         require_once 'modules/ModuleBuilder/parsers/ParserFactory.php' ;
92         $parser = ParserFactory::getParser (  $this->editLayout , $this->editModule , $packageName, $subpanelName ) ;
93         $smarty = $this->constructSmarty ( $parser ) ;
94
95         if ($preview)
96         {
97             echo $smarty->fetch ( "modules/ModuleBuilder/tpls/Preview/listView.tpl" ) ;
98         } else
99         {
100             $ajax = $this->constructAjax () ;
101             $ajax->addSection ( 'center', $this->translatedViewType, $smarty->fetch ( "modules/ModuleBuilder/tpls/listView.tpl" ) ) ;
102
103             echo $ajax->getJavascript () ;
104         }
105     }
106
107     function constructAjax ()
108     {
109         require_once ('modules/ModuleBuilder/MB/AjaxCompose.php') ;
110         $ajax = new AjaxCompose ( ) ;
111
112         $layoutLabel = 'LBL_LAYOUTS' ;
113         $layoutView = 'layouts' ;
114
115
116         $labels = array (
117                                 MB_LISTVIEW => 'LBL_LISTVIEW' ,
118                                 ) ;
119         $translatedViewType = '' ;
120                 if ( isset ( $labels [ strtolower ( $this->editLayout ) ] ) )
121                         $translatedViewType = translate ( $labels [ strtolower( $this->editLayout ) ] , 'ModuleBuilder' ) ;
122                 $this->translatedViewType = $translatedViewType;
123
124         if ($this->fromModuleBuilder)
125         {
126             $ajax->addCrumb ( translate ( 'LBL_MODULEBUILDER', 'ModuleBuilder' ), 'ModuleBuilder.main("mb")' ) ;
127             $ajax->addCrumb ( $_REQUEST [ 'view_package' ], 'ModuleBuilder.getContent("module=ModuleBuilder&action=package&package=' . $_REQUEST [ 'view_package' ] . '")' ) ;
128             $ajax->addCrumb ( $this->editModule, 'ModuleBuilder.getContent("module=ModuleBuilder&action=module&view_package=' . $_REQUEST [ 'view_package' ] . '&view_module=' . $_REQUEST [ 'view_module' ] . '")' ) ;
129             if ($this->subpanel != "")
130             {
131                 $ajax->addCrumb ( translate ( 'LBL_AVAILABLE_SUBPANELS', 'ModuleBuilder' ), '' ) ;
132                 if ($this->subpanelLabel)
133                 {
134                     $ajax->addCrumb ( $this->subpanelLabel, '' ) ;
135                     $this->translatedViewType = $this->subpanelLabel . "&nbsp;" . translate("LBL_SUBPANEL", "ModuleBuilder");
136                 } else
137                 {
138                     $ajax->addCrumb ( $this->subpanel, '' ) ;
139                     $this->translatedViewType = translate("LBL_SUBPANEL", "ModuleBuilder");
140                 }
141             } else
142             {
143                 $ajax->addCrumb ( translate ( $layoutLabel, 'ModuleBuilder' ), 'ModuleBuilder.getContent("module=ModuleBuilder&MB=true&action=wizard&view_module=' . $_REQUEST [ 'view_module' ] . '&view_package=' . $_REQUEST [ 'view_package' ] . '")' ) ;
144                 $ajax->addCrumb ( $translatedViewType, '' ) ;
145             }
146         } else
147         {
148             $ajax->addCrumb ( translate ( 'LBL_STUDIO', 'ModuleBuilder' ), 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard")' ) ;
149             $ajax->addCrumb ( $this->translatedEditModule, 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard&view_module=' . $this->editModule . '")' ) ;
150
151             if ($this->subpanel)
152             {
153                 $ajax->addCrumb ( translate ( 'LBL_SUBPANELS', 'ModuleBuilder' ), 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard&view=subpanels&view_module=' . $this->editModule . '")' ) ;
154                 if ($this->subpanelLabel)
155                 {
156                     $ajax->addCrumb ( $this->subpanelLabel, '' ) ;
157                     $this->translatedViewType = $this->subpanelLabel . "&nbsp;" . translate("LBL_SUBPANEL", "ModuleBuilder");
158                 } else
159                 {
160                     $ajax->addCrumb ( $this->subpanel, '' ) ;
161                     $this->translatedViewType = translate("LBL_SUBPANEL", "ModuleBuilder");
162                 }
163             } else
164             {
165                 $ajax->addCrumb ( translate ( $layoutLabel, 'ModuleBuilder' ), 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard&view='.$layoutView.'&view_module=' . $this->editModule . '")' ) ;
166                 $ajax->addCrumb ( $translatedViewType, '' ) ;
167             }
168         }
169         return $ajax ;
170     }
171
172     function constructSmarty ($parser)
173     {
174         $smarty = new Sugar_Smarty ( ) ;
175         $smarty->assign ( 'translate', true ) ;
176         $smarty->assign ( 'language', $parser->getLanguage () ) ;
177
178         $smarty->assign ( 'view', $this->editLayout ) ;
179         $smarty->assign ( 'module', "ModuleBuilder" ) ;
180         $smarty->assign ( 'field_defs', $parser->getFieldDefs () ) ;
181         $smarty->assign ( 'action', 'listViewSave' ) ;
182         $smarty->assign ( 'view_module', $this->editModule ) ;
183         if (!empty ( $this->subpanel ) )
184         {
185             $smarty->assign ( 'subpanel', $this->subpanel ) ;
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') ;
227 //        $imageHelp = SugarThemeRegistry::current()->getImage('help') ;
228
229         $history = $parser->getHistory () ;
230
231         $histaction = "ModuleBuilder.history.browse(\"{$this->editModule}\", \"{$this->editLayout}\")" ;
232         if ($this->subpanel)
233             $histaction = "ModuleBuilder.history.browse(\"{$this->editModule}\", \"{$this->editLayout}\", \"{$this->subpanel}\")" ;
234
235         $restoreAction = "onclick='ModuleBuilder.history.revert(\"{$this->editModule}\", \"{$this->editLayout}\", \"{$history->getLast()}\", \"\")'";
236         if ($this->subpanel)
237             $restoreAction = "onclick='ModuleBuilder.history.revert(\"{$this->editModule}\", \"{$this->editLayout}\", \"{$history->getLast()}\", \"{$this->subpanel}\")'";
238
239         $buttons = array ( ) ;
240         $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\" )'" ) ;
241         $buttons [] = array ( 'id' => 'spacer' , 'width' => '50px' ) ;
242         $buttons [] = array ( 'id' =>'historyBtn',       'name' => 'historyBtn' , 'text' => translate ( 'LBL_HISTORY' ) , 'actionScript' => "onclick='$histaction'" ) ;
243         $buttons [] = array ( 'id' => 'historyDefault' , 'name' => 'historyDefault',  'text' => translate ( 'LBL_RESTORE_DEFAULT' ) , 'actionScript' => $restoreAction ) ;
244
245         $smarty->assign ( 'buttons', $this->_buildImageButtons ( $buttons ) ) ;
246
247         $editImage = SugarThemeRegistry::current()->getImage('edit_inline') ;
248         $smarty->assign ( 'editImage', $editImage ) ;
249         $deleteImage = SugarThemeRegistry::current()->getImage('delete_inline') ;
250         $smarty->assign ( 'deleteImage', $deleteImage ) ;
251         $smarty->assign ( 'MOD', $GLOBALS [ 'mod_strings' ] ) ;
252
253         if ($this->fromModuleBuilder)
254         {
255             $smarty->assign ( 'MB', true ) ;
256             $smarty->assign ( 'view_package', $_REQUEST [ 'view_package' ] ) ;
257             $mb = new ModuleBuilder ( ) ;
258             $module = & $mb->getPackageModule ( $_REQUEST [ 'view_package' ], $this->editModule ) ;
259             $smarty->assign('current_mod_strings', $module->getModStrings());
260             if ($this->subpanel)
261             {
262                 if (isset ( $_REQUEST [ 'local' ] ))
263                 {
264                     $smarty->assign ( 'local', '1' ) ;
265                 }
266                 $smarty->assign ( "subpanel", $this->subpanel ) ;
267             } else
268             {
269                 $smarty->assign ( 'description', $GLOBALS [ 'mod_strings' ] [ 'LBL_LISTVIEW_DESCRIPTION' ] ) ;
270
271             }
272
273         } else
274         {
275             if ($this->subpanel)
276             {
277                 $smarty->assign ( "subpanel", "$this->subpanel" ) ;
278             } else
279             {
280                 $smarty->assign ( 'description', $GLOBALS [ 'mod_strings' ] [ 'LBL_LISTVIEW_DESCRIPTION' ] ) ;
281             }
282         }
283
284         return $smarty ;
285     }
286
287     function _constructTitle ()
288
289     {
290
291         global $app_list_strings ;
292
293         if ($this->fromModuleBuilder)
294         {
295             $title = $this->editModule ;
296             if ($this->subpanel != "")
297             {
298                 $title .= ":$this->subpanel" ;
299             }
300         } else
301         {
302             $title = ($this->subpanel) ? ':' . $this->subpanel : $app_list_strings [ 'moduleList' ] [ $this->editModule ] ;
303         }
304         return $GLOBALS [ 'mod_strings' ] [ 'LBL_LISTVIEW_EDIT' ] . ':&nbsp;' . $title ;
305
306     }
307
308     function _buildImageButtons ($buttons , $horizontal = true)
309     {
310         $text = '<table cellspacing=2><tr>' ;
311         foreach ( $buttons as $button )
312         {
313             if (empty($button['id'])) {
314                 $button['id'] = $button['name'];
315             }
316             if (! $horizontal)
317             {
318                 $text .= '</tr><tr>' ;
319             }
320             if ($button['id'] == "spacer") {
321                 $text .= "<td style='width:{$button['width']}'> </td>";
322                 continue;
323             }
324
325             if (! empty ( $button [ 'plain' ] ))
326             {
327                 $text .= <<<EOQ
328                      <td><input name={$button['name']} id={$button['id']} class="button" type="button" valign='center' {$button['actionScript']}
329 EOQ;
330
331             } else
332             {
333                 $text .= <<<EOQ
334                   <td><input name={$button['name']} id={$button['id']} class="button" type="button" valign='center' style='cursor:default'  {$button['actionScript']}
335 EOQ;
336             }
337             $text .= "value=\"{$button['text']}\"/></td>" ;
338         }
339         $text .= '</tr></table>' ;
340         return $text ;
341     }
342 }