]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/ModuleBuilder/views/view.listview.php
Release 6.5.10
[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-2013 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 require_once 'modules/ModuleBuilder/parsers/constants.php' ;
41 require_once ('include/SubPanel/SubPanel.php') ;
42
43 class ViewListView extends SugarView
44 {
45     /**
46          * @see SugarView::_getModuleTitleParams()
47          */
48         protected function _getModuleTitleParams($browserTitle = false)
49         {
50             global $mod_strings;
51             
52         return array(
53            translate('LBL_MODULE_NAME','Administration'),
54            ModuleBuilderController::getModuleTitle(),
55            );
56     }
57
58     /*
59      * Pseudo-constructor to enable subclasses to call a parent's constructor without knowing the parent in PHP4
60      */
61     function __construct()
62     {
63         $this->editModule = $_REQUEST [ 'view_module' ] ;
64         $this->editLayout = $_REQUEST [ 'view' ] ;
65         $this->subpanel = (! empty ( $_REQUEST [ 'subpanel' ] )) ? $_REQUEST [ 'subpanel' ] : false ;
66         $this->subpanelLabel = (! empty ( $_REQUEST [ 'subpanelLabel' ] )) ? $_REQUEST [ 'subpanelLabel' ] : false ;
67
68         $this->fromModuleBuilder = ! empty ( $_REQUEST [ 'view_package' ] ) ;
69         if (! $this->fromModuleBuilder)
70         {
71             $moduleNames = array_change_key_case ( $GLOBALS['app_list_strings'] [ 'moduleList' ] ) ;
72             $this->translatedEditModule = $moduleNames [ strtolower ( $this->editModule ) ] ;
73         }
74     }
75
76     // DO NOT REMOVE - overrides parent ViewEdit preDisplay() which attempts to load a bean for a non-existent module
77     function preDisplay ()
78     {
79     }
80
81     function display ($preview = false)
82     {
83
84         $packageName = (! empty ( $_REQUEST [ 'view_package' ] )) ? $_REQUEST [ 'view_package' ] : null ;
85         $subpanelName = (! empty ( $_REQUEST [ 'subpanel' ] )) ? $_REQUEST [ 'subpanel' ] : null ;
86         require_once 'modules/ModuleBuilder/parsers/ParserFactory.php' ;
87         $parser = ParserFactory::getParser (  $this->editLayout , $this->editModule , $packageName, $subpanelName ) ;
88         $smarty = $this->constructSmarty ( $parser ) ;
89
90         if ($preview)
91         {
92             echo $smarty->fetch ( "modules/ModuleBuilder/tpls/Preview/listView.tpl" ) ;
93         } else
94         {
95             $ajax = $this->constructAjax () ;
96             $ajax->addSection ( 'center', $this->translatedViewType, $smarty->fetch ( "modules/ModuleBuilder/tpls/listView.tpl" ) ) ;
97
98             echo $ajax->getJavascript () ;
99         }
100     }
101
102     function constructAjax ()
103     {
104         require_once ('modules/ModuleBuilder/MB/AjaxCompose.php') ;
105         $ajax = new AjaxCompose ( ) ;
106
107         $layoutLabel = 'LBL_LAYOUTS' ;
108         $layoutView = 'layouts' ;
109
110
111         $labels = array (
112                                 MB_LISTVIEW => 'LBL_LISTVIEW' ,
113                                 ) ;
114         $translatedViewType = '' ;
115                 if ( isset ( $labels [ strtolower ( $this->editLayout ) ] ) )
116                         $translatedViewType = translate ( $labels [ strtolower( $this->editLayout ) ] , 'ModuleBuilder' ) ;
117                 $this->translatedViewType = $translatedViewType;
118
119         if ($this->fromModuleBuilder)
120         {
121             $ajax->addCrumb ( translate ( 'LBL_MODULEBUILDER', 'ModuleBuilder' ), 'ModuleBuilder.main("mb")' ) ;
122             $ajax->addCrumb ( $_REQUEST [ 'view_package' ], 'ModuleBuilder.getContent("module=ModuleBuilder&action=package&package=' . $_REQUEST [ 'view_package' ] . '")' ) ;
123             $ajax->addCrumb ( $this->editModule, 'ModuleBuilder.getContent("module=ModuleBuilder&action=module&view_package=' . $_REQUEST [ 'view_package' ] . '&view_module=' . $_REQUEST [ 'view_module' ] . '")' ) ;
124             if ($this->subpanel != "")
125             {
126                 $ajax->addCrumb ( translate ( 'LBL_AVAILABLE_SUBPANELS', 'ModuleBuilder' ), '' ) ;
127                 if ($this->subpanelLabel)
128                 {
129                     $subpanelLabel = $this->subpanelLabel;
130                     // If the subpanel title has changed, use that for the label instead
131                     if( !empty($_REQUEST['subpanel_title'] ) && $_REQUEST['subpanelLabel'] != $_REQUEST['subpanel_title'] )
132                         $subpanelLabel = $_REQUEST['subpanel_title'];
133
134                     $ajax->addCrumb( $subpanelLabel, '' );
135                     $this->translatedViewType = $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                     $subpanelLabel = $this->subpanelLabel;
157                     // If the subpanel title has changed, use that for the label instead
158                     if( !empty($_REQUEST['subpanel_title'] ) && $_REQUEST['subpanelLabel'] != $_REQUEST['subpanel_title'] )
159                         $subpanelLabel = $_REQUEST['subpanel_title'];
160
161                     $ajax->addCrumb( $subpanelLabel, '' );
162                     $this->translatedViewType = $subpanelLabel . "&nbsp;" . translate("LBL_SUBPANEL", "ModuleBuilder");
163                 } else
164                 {
165                     $ajax->addCrumb ( $this->subpanel, '' ) ;
166                     $this->translatedViewType = translate("LBL_SUBPANEL", "ModuleBuilder");
167                 }
168             } else
169             {
170                 $ajax->addCrumb ( translate ( $layoutLabel, 'ModuleBuilder' ), 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard&view='.$layoutView.'&view_module=' . $this->editModule . '")' ) ;
171                 $ajax->addCrumb ( $translatedViewType, '' ) ;
172             }
173         }
174         return $ajax ;
175     }
176
177     function constructSmarty ($parser)
178     {
179         global $mod_strings;
180         $smarty = new Sugar_Smarty ( ) ;
181         $smarty->assign ( 'translate', true ) ;
182         $smarty->assign ( 'language', $parser->getLanguage () ) ;
183
184         $smarty->assign ( 'view', $this->editLayout ) ;
185         $smarty->assign ( 'module', "ModuleBuilder" ) ;
186         $smarty->assign ( 'field_defs', $parser->getFieldDefs () ) ;
187         $smarty->assign ( 'action', 'listViewSave' ) ;
188         $smarty->assign ( 'view_module', $this->editModule ) ;
189         if (!empty ( $this->subpanel ) )
190         {
191             $smarty->assign ( 'subpanel', $this->subpanel ) ;
192             $smarty->assign ( 'subpanelLabel', $this->subpanelLabel ) ;
193             if (!$this->fromModuleBuilder) {
194                 $subList =  SubPanel::getModuleSubpanels ( $this->editModule);
195                 $subRef = $subList[strtolower($this->subpanel)];
196                 $subTitleKey = !empty($subRef) ? $subRef : "LBL_" . strtoupper($this->subpanel) . "_SUBPANEL_TITLE";
197                 $subTitle    = !empty($subRef) ? translate($subTitleKey, $this->editModule) : UCfirst($this->subpanel);
198                 $smarty->assign ( 'subpanel_label', $subTitleKey ) ;
199                 $smarty->assign ( 'subpanel_title', $subTitle ) ;
200             }
201         }
202         $helpName = $this->subpanel ? 'subPanelEditor' : 'listViewEditor';
203         $smarty->assign ( 'helpName', $helpName ) ;
204         $smarty->assign ( 'helpDefault', 'modify' ) ;
205
206         $smarty->assign ( 'title', $this->_constructTitle () ) ;
207         $groups = array ( ) ;
208         foreach ( $parser->columns as $column => $function )
209         {
210             // update this so that each field has a properties set
211             // properties are name, value, title (optional)
212             $groups [ $GLOBALS [ 'mod_strings' ] [ $column ] ] = $parser->$function () ; // call the parser functions to populate the list view columns, by default 'default', 'available' and 'hidden'
213         }
214         foreach ( $groups as $groupKey => $group )
215         {
216             foreach ( $group as $fieldKey => $field )
217             {
218                 if (isset ( $field [ 'width' ] ))
219                 {
220                     if (substr ( $field [ 'width' ], - 1, 1 ) == '%')
221                     {
222
223                         $groups [ $groupKey ] [ $fieldKey ] [ 'width' ] = substr ( $field [ 'width' ], 0, strlen ( $field [ 'width' ] ) - 1 ) ;
224                     }
225                 }
226             }
227         }
228
229         $smarty->assign ( 'groups', $groups ) ;
230         $smarty->assign('from_mb', $this->fromModuleBuilder);
231
232         global $image_path;
233         $imageSave = SugarThemeRegistry::current()->getImage('studio_save','',null,null,'.gif',$mod_strings['LBL_BTN_SAVE']) ;
234
235 //        $imageHelp = SugarThemeRegistry::current()->getImage('help') ;
236
237
238         $history = $parser->getHistory () ;
239
240         $histaction = "ModuleBuilder.history.browse(\"{$this->editModule}\", \"{$this->editLayout}\")" ;
241         if ($this->subpanel)
242             $histaction = "ModuleBuilder.history.browse(\"{$this->editModule}\", \"{$this->editLayout}\", \"{$this->subpanel}\")" ;
243
244         $restoreAction = "onclick='ModuleBuilder.history.revert(\"{$this->editModule}\", \"{$this->editLayout}\", \"{$history->getLast()}\", \"\")'";
245         if ($this->subpanel)
246             $restoreAction = "onclick='ModuleBuilder.history.revert(\"{$this->editModule}\", \"{$this->editLayout}\", \"{$history->getLast()}\", \"{$this->subpanel}\")'";
247
248         $buttons = array ( ) ;
249         $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\" )'" ) ;
250         $buttons [] = array ( 'id' => 'spacer' , 'width' => '50px' ) ;
251         $buttons [] = array ( 'id' =>'historyBtn',       'name' => 'historyBtn' , 'text' => translate ( 'LBL_HISTORY' ) , 'actionScript' => "onclick='$histaction'" ) ;
252         $buttons [] = array ( 'id' => 'historyDefault' , 'name' => 'historyDefault',  'text' => translate ( 'LBL_RESTORE_DEFAULT' ) , 'actionScript' => $restoreAction ) ;
253
254         $smarty->assign ( 'buttons', $this->_buildImageButtons ( $buttons ) ) ;
255
256         $editImage = SugarThemeRegistry::current()->getImage('edit_inline','',null,null,'.gif',$mod_strings['LBL_EDIT']) ;
257
258         $smarty->assign ( 'editImage', $editImage ) ;
259         $deleteImage = SugarThemeRegistry::current()->getImage('delete_inline','',null,null,'.gif',$mod_strings['LBL_MB_DELETE']) ;
260
261         $smarty->assign ( 'deleteImage', $deleteImage ) ;
262         $smarty->assign ( 'MOD', $GLOBALS [ 'mod_strings' ] ) ;
263
264         if ($this->fromModuleBuilder)
265         {
266             $smarty->assign ( 'MB', true ) ;
267             $smarty->assign ( 'view_package', $_REQUEST [ 'view_package' ] ) ;
268             $mb = new ModuleBuilder ( ) ;
269             $module = & $mb->getPackageModule ( $_REQUEST [ 'view_package' ], $this->editModule ) ;
270             $smarty->assign('current_mod_strings', $module->getModStrings());
271             if ($this->subpanel)
272             {
273                 if (isset ( $_REQUEST [ 'local' ] ))
274                 {
275                     $smarty->assign ( 'local', '1' ) ;
276                 }
277                 $smarty->assign ( "subpanel", $this->subpanel ) ;
278             } else
279             {
280                 $smarty->assign ( 'description', $GLOBALS [ 'mod_strings' ] [ 'LBL_LISTVIEW_DESCRIPTION' ] ) ;
281
282             }
283
284         } else
285         {
286             if ($this->subpanel)
287             {
288                 $smarty->assign ( "subpanel", "$this->subpanel" ) ;
289             } else
290             {
291                 $smarty->assign ( 'description', $GLOBALS [ 'mod_strings' ] [ 'LBL_LISTVIEW_DESCRIPTION' ] ) ;
292             }
293         }
294
295         return $smarty ;
296     }
297
298     function _constructTitle ()
299
300     {
301
302         global $app_list_strings ;
303
304         if ($this->fromModuleBuilder)
305         {
306             $title = $this->editModule ;
307             if ($this->subpanel != "")
308             {
309                 $title .= ":$this->subpanel" ;
310             }
311         } else
312         {
313             $title = ($this->subpanel) ? ':' . $this->subpanel : $app_list_strings [ 'moduleList' ] [ $this->editModule ] ;
314         }
315         return $GLOBALS [ 'mod_strings' ] [ 'LBL_LISTVIEW_EDIT' ] . ':&nbsp;' . $title ;
316
317     }
318
319     function _buildImageButtons ($buttons , $horizontal = true)
320     {
321         $text = '<table cellspacing=2><tr>' ;
322         foreach ( $buttons as $button )
323         {
324             if (empty($button['id'])) {
325                 $button['id'] = $button['name'];
326             }
327             if (! $horizontal)
328             {
329                 $text .= '</tr><tr>' ;
330             }
331             if ($button['id'] == "spacer") {
332                 $text .= "<td style='width:{$button['width']}'> </td>";
333                 continue;
334             }
335
336             if (! empty ( $button [ 'plain' ] ))
337             {
338                 $text .= <<<EOQ
339                      <td><input name={$button['name']} id={$button['id']} class="button" type="button" valign='center' {$button['actionScript']}
340 EOQ;
341
342             } else
343             {
344                 $text .= <<<EOQ
345                   <td><input name={$button['name']} id={$button['id']} class="button" type="button" valign='center' style='cursor:default'  {$button['actionScript']}
346 EOQ;
347             }
348             $text .= "value=\"{$button['text']}\"/></td>" ;
349         }
350         $text .= '</tr></table>' ;
351         return $text ;
352     }
353 }