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.
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.
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
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
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.
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.
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 ********************************************************************************/
40 //Load the parent view class if it exists. Check for custom file first
41 loadParentView('edit');
43 require_once 'modules/ModuleBuilder/parsers/constants.php' ;
44 require_once ('include/SubPanel/SubPanel.php') ;
46 class ViewListView extends ViewEdit
49 * @see SugarView::_getModuleTitleParams()
51 protected function _getModuleTitleParams($browserTitle = false)
56 translate('LBL_MODULE_NAME','Administration'),
57 ModuleBuilderController::getModuleTitle(),
62 * Pseudo-constructor to enable subclasses to call a parent's constructor without knowing the parent in PHP4
64 function __construct()
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 ;
71 $this->fromModuleBuilder = ! empty ( $_REQUEST [ 'view_package' ] ) ;
72 if (! $this->fromModuleBuilder)
74 $moduleNames = array_change_key_case ( $GLOBALS['app_list_strings'] [ 'moduleList' ] ) ;
75 $this->translatedEditModule = $moduleNames [ strtolower ( $this->editModule ) ] ;
79 // DO NOT REMOVE - overrides parent ViewEdit preDisplay() which attempts to load a bean for a non-existent module
80 function preDisplay ()
84 function display ($preview = false)
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 ) ;
95 echo $smarty->fetch ( "modules/ModuleBuilder/tpls/Preview/listView.tpl" ) ;
98 $ajax = $this->constructAjax () ;
99 $ajax->addSection ( 'center', $this->translatedViewType, $smarty->fetch ( "modules/ModuleBuilder/tpls/listView.tpl" ) ) ;
101 echo $ajax->getJavascript () ;
105 function constructAjax ()
107 require_once ('modules/ModuleBuilder/MB/AjaxCompose.php') ;
108 $ajax = new AjaxCompose ( ) ;
110 $layoutLabel = 'LBL_LAYOUTS' ;
111 $layoutView = 'layouts' ;
115 MB_LISTVIEW => 'LBL_LISTVIEW' ,
117 $translatedViewType = '' ;
118 if ( isset ( $labels [ strtolower ( $this->editLayout ) ] ) )
119 $translatedViewType = translate ( $labels [ strtolower( $this->editLayout ) ] , 'ModuleBuilder' ) ;
120 $this->translatedViewType = $translatedViewType;
122 if ($this->fromModuleBuilder)
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 != "")
129 $ajax->addCrumb ( translate ( 'LBL_AVAILABLE_SUBPANELS', 'ModuleBuilder' ), '' ) ;
130 if ($this->subpanelLabel)
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'];
137 $ajax->addCrumb( $subpanelLabel, '' );
138 $this->translatedViewType = $subpanelLabel . " " . translate("LBL_SUBPANEL", "ModuleBuilder");
141 $ajax->addCrumb ( $this->subpanel, '' ) ;
142 $this->translatedViewType = translate("LBL_SUBPANEL", "ModuleBuilder");
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, '' ) ;
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 . '")' ) ;
156 $ajax->addCrumb ( translate ( 'LBL_SUBPANELS', 'ModuleBuilder' ), 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard&view=subpanels&view_module=' . $this->editModule . '")' ) ;
157 if ($this->subpanelLabel)
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'];
164 $ajax->addCrumb( $subpanelLabel, '' );
165 $this->translatedViewType = $subpanelLabel . " " . translate("LBL_SUBPANEL", "ModuleBuilder");
168 $ajax->addCrumb ( $this->subpanel, '' ) ;
169 $this->translatedViewType = translate("LBL_SUBPANEL", "ModuleBuilder");
173 $ajax->addCrumb ( translate ( $layoutLabel, 'ModuleBuilder' ), 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard&view='.$layoutView.'&view_module=' . $this->editModule . '")' ) ;
174 $ajax->addCrumb ( $translatedViewType, '' ) ;
180 function constructSmarty ($parser)
183 $smarty = new Sugar_Smarty ( ) ;
184 $smarty->assign ( 'translate', true ) ;
185 $smarty->assign ( 'language', $parser->getLanguage () ) ;
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 ) )
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 ) ;
205 $helpName = $this->subpanel ? 'subPanelEditor' : 'listViewEditor';
206 $smarty->assign ( 'helpName', $helpName ) ;
207 $smarty->assign ( 'helpDefault', 'modify' ) ;
209 $smarty->assign ( 'title', $this->_constructTitle () ) ;
210 $groups = array ( ) ;
211 foreach ( $parser->columns as $column => $function )
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'
217 foreach ( $groups as $groupKey => $group )
219 foreach ( $group as $fieldKey => $field )
221 if (isset ( $field [ 'width' ] ))
223 if (substr ( $field [ 'width' ], - 1, 1 ) == '%')
226 $groups [ $groupKey ] [ $fieldKey ] [ 'width' ] = substr ( $field [ 'width' ], 0, strlen ( $field [ 'width' ] ) - 1 ) ;
232 $smarty->assign ( 'groups', $groups ) ;
233 $smarty->assign('from_mb', $this->fromModuleBuilder);
236 $imageSave = SugarThemeRegistry::current()->getImage('studio_save','',null,null,'.gif',$mod_strings['LBL_BTN_SAVE']) ;
238 // $imageHelp = SugarThemeRegistry::current()->getImage('help') ;
241 $history = $parser->getHistory () ;
243 $histaction = "ModuleBuilder.history.browse(\"{$this->editModule}\", \"{$this->editLayout}\")" ;
245 $histaction = "ModuleBuilder.history.browse(\"{$this->editModule}\", \"{$this->editLayout}\", \"{$this->subpanel}\")" ;
247 $restoreAction = "onclick='ModuleBuilder.history.revert(\"{$this->editModule}\", \"{$this->editLayout}\", \"{$history->getLast()}\", \"\")'";
249 $restoreAction = "onclick='ModuleBuilder.history.revert(\"{$this->editModule}\", \"{$this->editLayout}\", \"{$history->getLast()}\", \"{$this->subpanel}\")'";
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 ) ;
257 $smarty->assign ( 'buttons', $this->_buildImageButtons ( $buttons ) ) ;
259 $editImage = SugarThemeRegistry::current()->getImage('edit_inline','',null,null,'.gif',$mod_strings['LBL_EDIT']) ;
261 $smarty->assign ( 'editImage', $editImage ) ;
262 $deleteImage = SugarThemeRegistry::current()->getImage('delete_inline','',null,null,'.gif',$mod_strings['LBL_MB_DELETE']) ;
264 $smarty->assign ( 'deleteImage', $deleteImage ) ;
265 $smarty->assign ( 'MOD', $GLOBALS [ 'mod_strings' ] ) ;
267 if ($this->fromModuleBuilder)
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());
276 if (isset ( $_REQUEST [ 'local' ] ))
278 $smarty->assign ( 'local', '1' ) ;
280 $smarty->assign ( "subpanel", $this->subpanel ) ;
283 $smarty->assign ( 'description', $GLOBALS [ 'mod_strings' ] [ 'LBL_LISTVIEW_DESCRIPTION' ] ) ;
291 $smarty->assign ( "subpanel", "$this->subpanel" ) ;
294 $smarty->assign ( 'description', $GLOBALS [ 'mod_strings' ] [ 'LBL_LISTVIEW_DESCRIPTION' ] ) ;
301 function _constructTitle ()
305 global $app_list_strings ;
307 if ($this->fromModuleBuilder)
309 $title = $this->editModule ;
310 if ($this->subpanel != "")
312 $title .= ":$this->subpanel" ;
316 $title = ($this->subpanel) ? ':' . $this->subpanel : $app_list_strings [ 'moduleList' ] [ $this->editModule ] ;
318 return $GLOBALS [ 'mod_strings' ] [ 'LBL_LISTVIEW_EDIT' ] . ': ' . $title ;
322 function _buildImageButtons ($buttons , $horizontal = true)
324 $text = '<table cellspacing=2><tr>' ;
325 foreach ( $buttons as $button )
327 if (empty($button['id'])) {
328 $button['id'] = $button['name'];
332 $text .= '</tr><tr>' ;
334 if ($button['id'] == "spacer") {
335 $text .= "<td style='width:{$button['width']}'> </td>";
339 if (! empty ( $button [ 'plain' ] ))
342 <td><input name={$button['name']} id={$button['id']} class="button" type="button" valign='center' {$button['actionScript']}
348 <td><input name={$button['name']} id={$button['id']} class="button" type="button" valign='center' style='cursor:default' {$button['actionScript']}
351 $text .= "value=\"{$button['text']}\"/></td>" ;
353 $text .= '</tr></table>' ;