]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/ModuleBuilder/views/view.listview.php
Release 6.2.3
[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         $smarty = new Sugar_Smarty ( ) ;
173         $smarty->assign ( 'translate', true ) ;
174         $smarty->assign ( 'language', $parser->getLanguage () ) ;
175
176         $smarty->assign ( 'view', $this->editLayout ) ;
177         $smarty->assign ( 'module', "ModuleBuilder" ) ;
178         $smarty->assign ( 'field_defs', $parser->getFieldDefs () ) ;
179         $smarty->assign ( 'action', 'listViewSave' ) ;
180         $smarty->assign ( 'view_module', $this->editModule ) ;
181         if (!empty ( $this->subpanel ) )
182         {
183             $smarty->assign ( 'subpanel', $this->subpanel ) ;
184             if (!$this->fromModuleBuilder) {
185                 $subList =  SubPanel::getModuleSubpanels ( $this->editModule);
186                 $subRef = $subList[strtolower($this->subpanel)];
187                 $subTitleKey = !empty($subRef) ? $subRef : "LBL_" . strtoupper($this->subpanel) . "_SUBPANEL_TITLE";
188                 $subTitle    = !empty($subRef) ? translate($subTitleKey, $this->editModule) : UCfirst($this->subpanel);
189                 $smarty->assign ( 'subpanel_label', $subTitleKey ) ;
190                 $smarty->assign ( 'subpanel_title', $subTitle ) ;
191             }
192         }
193         $helpName = $this->subpanel ? 'subPanelEditor' : 'listViewEditor';
194         $smarty->assign ( 'helpName', $helpName ) ;
195         $smarty->assign ( 'helpDefault', 'modify' ) ;
196
197         $smarty->assign ( 'title', $this->_constructTitle () ) ;
198         $groups = array ( ) ;
199         foreach ( $parser->columns as $column => $function )
200         {
201             // update this so that each field has a properties set
202             // properties are name, value, title (optional)
203             $groups [ $GLOBALS [ 'mod_strings' ] [ $column ] ] = $parser->$function () ; // call the parser functions to populate the list view columns, by default 'default', 'available' and 'hidden'
204         }
205         foreach ( $groups as $groupKey => $group )
206         {
207             foreach ( $group as $fieldKey => $field )
208             {
209                 if (isset ( $field [ 'width' ] ))
210                 {
211                     if (substr ( $field [ 'width' ], - 1, 1 ) == '%')
212                     {
213
214                         $groups [ $groupKey ] [ $fieldKey ] [ 'width' ] = substr ( $field [ 'width' ], 0, strlen ( $field [ 'width' ] ) - 1 ) ;
215                     }
216                 }
217             }
218         }
219
220         $smarty->assign ( 'groups', $groups ) ;
221         $smarty->assign('from_mb', $this->fromModuleBuilder);
222
223         global $image_path ;
224         $imageSave = SugarThemeRegistry::current()->getImage('studio_save') ;
225 //        $imageHelp = SugarThemeRegistry::current()->getImage('help') ;
226
227         $history = $parser->getHistory () ;
228
229         $histaction = "ModuleBuilder.history.browse(\"{$this->editModule}\", \"{$this->editLayout}\")" ;
230         if ($this->subpanel)
231             $histaction = "ModuleBuilder.history.browse(\"{$this->editModule}\", \"{$this->editLayout}\", \"{$this->subpanel}\")" ;
232
233         $restoreAction = "onclick='ModuleBuilder.history.revert(\"{$this->editModule}\", \"{$this->editLayout}\", \"{$history->getLast()}\", \"\")'";
234         if ($this->subpanel)
235             $restoreAction = "onclick='ModuleBuilder.history.revert(\"{$this->editModule}\", \"{$this->editLayout}\", \"{$history->getLast()}\", \"{$this->subpanel}\")'";
236
237         $buttons = array ( ) ;
238         $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\" )'" ) ;
239         $buttons [] = array ( 'id' => 'spacer' , 'width' => '50px' ) ;
240         $buttons [] = array ( 'id' =>'historyBtn',       'name' => 'historyBtn' , 'text' => translate ( 'LBL_HISTORY' ) , 'actionScript' => "onclick='$histaction'" ) ;
241         $buttons [] = array ( 'id' => 'historyDefault' , 'name' => 'historyDefault',  'text' => translate ( 'LBL_RESTORE_DEFAULT' ) , 'actionScript' => $restoreAction ) ;
242
243         $smarty->assign ( 'buttons', $this->_buildImageButtons ( $buttons ) ) ;
244
245         $editImage = SugarThemeRegistry::current()->getImage('edit_inline') ;
246         $smarty->assign ( 'editImage', $editImage ) ;
247         $deleteImage = SugarThemeRegistry::current()->getImage('delete_inline') ;
248         $smarty->assign ( 'deleteImage', $deleteImage ) ;
249         $smarty->assign ( 'MOD', $GLOBALS [ 'mod_strings' ] ) ;
250
251         if ($this->fromModuleBuilder)
252         {
253             $smarty->assign ( 'MB', true ) ;
254             $smarty->assign ( 'view_package', $_REQUEST [ 'view_package' ] ) ;
255             $mb = new ModuleBuilder ( ) ;
256             $module = & $mb->getPackageModule ( $_REQUEST [ 'view_package' ], $this->editModule ) ;
257             $smarty->assign('current_mod_strings', $module->getModStrings());
258             if ($this->subpanel)
259             {
260                 if (isset ( $_REQUEST [ 'local' ] ))
261                 {
262                     $smarty->assign ( 'local', '1' ) ;
263                 }
264                 $smarty->assign ( "subpanel", $this->subpanel ) ;
265             } else
266             {
267                 $smarty->assign ( 'description', $GLOBALS [ 'mod_strings' ] [ 'LBL_LISTVIEW_DESCRIPTION' ] ) ;
268
269             }
270
271         } else
272         {
273             if ($this->subpanel)
274             {
275                 $smarty->assign ( "subpanel", "$this->subpanel" ) ;
276             } else
277             {
278                 $smarty->assign ( 'description', $GLOBALS [ 'mod_strings' ] [ 'LBL_LISTVIEW_DESCRIPTION' ] ) ;
279             }
280         }
281
282         return $smarty ;
283     }
284
285     function _constructTitle ()
286
287     {
288
289         global $app_list_strings ;
290
291         if ($this->fromModuleBuilder)
292         {
293             $title = $this->editModule ;
294             if ($this->subpanel != "")
295             {
296                 $title .= ":$this->subpanel" ;
297             }
298         } else
299         {
300             $title = ($this->subpanel) ? ':' . $this->subpanel : $app_list_strings [ 'moduleList' ] [ $this->editModule ] ;
301         }
302         return $GLOBALS [ 'mod_strings' ] [ 'LBL_LISTVIEW_EDIT' ] . ':&nbsp;' . $title ;
303
304     }
305
306     function _buildImageButtons ($buttons , $horizontal = true)
307     {
308         $text = '<table cellspacing=2><tr>' ;
309         foreach ( $buttons as $button )
310         {
311             if (empty($button['id'])) {
312                 $button['id'] = $button['name'];
313             }
314             if (! $horizontal)
315             {
316                 $text .= '</tr><tr>' ;
317             }
318             if ($button['id'] == "spacer") {
319                 $text .= "<td style='width:{$button['width']}'> </td>";
320                 continue;
321             }
322
323             if (! empty ( $button [ 'plain' ] ))
324             {
325                 $text .= <<<EOQ
326                      <td><input name={$button['name']} id={$button['id']} class="button" type="button" valign='center' {$button['actionScript']}
327 EOQ;
328
329             } else
330             {
331                 $text .= <<<EOQ
332                   <td><input name={$button['name']} id={$button['id']} class="button" type="button" valign='center' style='cursor:default'  {$button['actionScript']}
333 EOQ;
334             }
335             $text .= "value=\"{$button['text']}\"/></td>" ;
336         }
337         $text .= '</tr></table>' ;
338         return $text ;
339     }
340 }