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