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.
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 ********************************************************************************/
42 * Modify an exising Subpanel
43 * Typically called from Studio for a deployed (OOB or installed custom module)
45 * Uses the listview editor to modify the subpanel
46 * Uses SubPanelDefinitions to load the definitions for the subpanel, and SubPanel to save them, using the unique SubPanel override mechanism
47 * There are two relevant modules for every subpanel - the module whose detailview this subpanel will appear in ($module_name), and the module that is the source of the data for the subpanel ($subPanelParentModule)
50 require_once ('modules/ModuleBuilder/parsers/parser.modifylistview.php') ;
52 class ParserModifySubPanel extends ParserModifyListView
55 var $listViewDefs = false ;
56 var $defaults = array ( ) ;
57 var $additional = array ( ) ;
58 var $available = array ( ) ;
59 var $columns = array ( 'LBL_DEFAULT' => 'getDefaultFields' , 'LBL_HIDDEN' => 'getAvailableFields' ) ;
61 function init ($module_name , $subPanelName)
63 $GLOBALS [ 'log' ]->debug ( "in ParserModifySubPanel: module_name={$module_name} child_module={$subPanelName}" ) ;
64 $this->moduleName = $module_name ;
65 $this->subPanelName = $subPanelName ;
66 global $beanList, $beanFiles ;
68 // Sometimes we receive a module name which is not in the correct CamelCase, so shift to lower case for all beanList lookups
69 $beanListLower = array_change_key_case ( $beanList ) ;
71 // Retrieve the definitions for all the available subpanels for this module
72 $class = $beanListLower [ strtolower ( $this->moduleName ) ] ;
73 require_once ($beanFiles [ $class ]) ;
74 $module = new $class ( ) ;
75 require_once ('include/SubPanel/SubPanelDefinitions.php') ;
76 $spd = new SubPanelDefinitions ( $module ) ;
78 // Get the lists of fields already in the subpanel and those that can be added in
79 // Get the fields lists from an aSubPanel object describing this subpanel from the SubPanelDefinitions object
80 $this->originalListViewDefs = array ( ) ;
81 if (array_key_exists ( strtolower ( $this->subPanelName ), $spd->layout_defs [ 'subpanel_setup' ] ))
83 $originalPanel = $spd->load_subpanel ( $this->subPanelName, true ) ;
84 $this->originalListViewDefs = $originalPanel->get_list_fields () ;
85 $this->panel = $spd->load_subpanel ( $subPanelName, false ) ;
86 $this->listViewDefs = $this->panel->get_list_fields () ;
88 // Retrieve a copy of the bean for the parent module of this subpanel - so we can find additional fields for the layout
89 $subPanelParentModuleName = $this->panel->get_module_name () ;
90 $this->subPanelParentModule = null ;
92 if (! empty ( $subPanelParentModuleName ) && isset($beanListLower[strtolower($subPanelParentModuleName)]))
94 $class = $beanListLower[strtolower($subPanelParentModuleName)];
95 if (isset($beanFiles [ $class ]))
97 require_once ($beanFiles [ $class ]) ;
98 $this->subPanelParentModule = new $class ( ) ;
103 $this->language_module = $this->panel->template_instance->module_dir ;
107 * Return a list of the fields that will be displayed in the subpanel
109 function getDefaultFields ()
111 $this->defaults = array ( ) ;
112 foreach ( $this->listViewDefs as $key => $def )
114 if (! empty ( $def [ 'usage' ] ) && strcmp ( $def [ 'usage' ], 'query_only' ) == 0)
116 if (! empty ( $def [ 'vname' ] ))
117 $def [ 'label' ] = $def [ 'vname' ] ;
118 $this->defaults [ $key ] = $def ;
120 return $this->defaults ;
124 * Return a list of fields that are not currently included in the subpanel but that are available for use
126 function getAvailableFields ()
128 $this->availableFields = array ( ) ;
129 if ($this->subPanelParentModule != null)
131 $lowerFieldList = array_change_key_case ( $this->listViewDefs ) ;
132 foreach ( $this->originalListViewDefs as $key => $def )
134 $key = strtolower ( $key ) ;
135 if (! isset ( $lowerFieldList [ $key ] ))
137 $this->availableFields [ $key ] = $def ;
140 $GLOBALS [ 'log' ]->debug ( 'parser.modifylistview.php->getAvailableFields(): field_defs=' . print_r ( $this->availableFields, true ) ) ;
141 foreach ( $this->subPanelParentModule->field_defs as $key => $fieldDefinition )
143 $fieldName = strtolower ( $key ) ;
144 if (! isset ( $lowerFieldList [ $fieldName ] )) // bug 16728 - check this first, so that other conditions (e.g., studio == visible) can't override and add duplicate entries
146 if ((empty ( $fieldDefinition [ 'source' ] ) || $fieldDefinition [ 'source' ] == 'db' || $fieldDefinition [ 'source' ] == 'custom_fields') && $fieldDefinition [ 'type' ] != 'id' && strcmp ( $fieldName, 'deleted' ) != 0 || (isset ( $def [ 'name' ] ) && strpos ( $def [ 'name' ], "_name" ) != false) || ! empty ( $def [ 'custom_type' ] ) && (empty ( $fieldDefinition [ 'dbType' ] ) || $fieldDefinition [ 'dbType' ] != 'id') && (empty ( $fieldDefinition [ 'dbtype' ] ) || $fieldDefinition [ 'dbtype' ] != 'id') || (! empty ( $fieldDefinition [ 'studio' ] ) && $fieldDefinition [ 'studio' ] == 'visible'))
148 $label = (isset ( $fieldDefinition [ 'vname' ] )) ? $fieldDefinition [ 'vname' ] : (isset ( $fieldDefinition [ 'label' ] ) ? $fieldDefinition [ 'label' ] : $fieldDefinition [ 'name' ]) ;
149 $this->availableFields [ $fieldName ] = array ( 'width' => '10' , 'label' => $label ) ;
155 return $this->availableFields ;
158 function getField ($fieldName)
160 foreach ( $this->listViewDefs as $key => $def )
162 $key = strtolower ( $key ) ;
163 if ($key == $fieldName)
168 foreach ( $this->originalListViewDefs as $key => $def )
170 $key = strtolower ( $key ) ;
171 if ($key == $fieldName)
176 foreach ( $this->panel->template_instance->field_defs as $key => $def )
178 $key = strtolower ( $key ) ;
179 if ($key == $fieldName)
188 * Save the modified definitions for a subpanel
189 * Obtains the field definitions from a _REQUEST array, and merges them with the other fields from the original definitions
190 * Uses the subpanel override mechanism from SubPanel to save them
192 function handleSave ()
194 $GLOBALS [ 'log' ]->debug ( "in ParserModifySubPanel->handleSave()" ) ;
195 require_once ('include/SubPanel/SubPanel.php') ;
196 $subpanel = new SubPanel ( $this->moduleName, 'fab4', $this->subPanelName, $this->panel ) ;
198 $newFields = array ( ) ;
199 foreach ( $this->listViewDefs as $name => $field )
201 if (! isset ( $field [ 'usage' ] ) || $field [ 'usage' ] != 'query_only')
203 $existingFields [ $name ] = $field ;
207 $newFields [ $name ] = $field ;
211 // Loop through all of the fields defined in the 'Default' group of the ListView data in $_REQUEST
212 // Replace the field specification in the originalListViewDef with this new updated specification
213 foreach ( $_REQUEST [ 'group_0' ] as $field )
215 if (! empty ( $this->originalListViewDefs [ $field ] ))
217 $newFields [ $field ] = $this->originalListViewDefs [ $field ] ;
222 if (isset ( $this->panel->template_instance->field_defs [ $field ] ))
224 $vname = $this->panel->template_instance->field_defs [ $field ] [ 'vname' ] ;
226 if (($this->subPanelParentModule != null) && (isset ( $this->subPanelParentModule->field_name_map [ $field ] ) && ($this->subPanelParentModule->field_name_map [ $field ] [ 'type' ] == 'bool' || (isset ( $this->subPanelParentModule->field_name_map [ $field ] [ 'custom_type' ] ) && $this->subPanelParentModule->field_name_map [ $field ] [ 'custom_type' ] == 'bool'))))
228 $newFields [ $field ] = array ( 'name' => $field , 'vname' => $vname , 'widget_type' => 'checkbox' ) ;
231 $newFields [ $field ] = array ( 'name' => $field , 'vname' => $vname ) ;
235 // Now set the field width if specified in the $_REQUEST data
236 if (isset ( $_REQUEST [ strtolower ( $field ) . 'width' ] ))
238 $width = substr ( $_REQUEST [ strtolower ( $field ) . 'width' ], 6, 3 ) ;
239 if (strpos ( $width, "%" ) != false)
241 $width = substr ( $width, 0, 2 ) ;
243 if ($width < 101 && $width > 0)
245 $newFields [ $field ] [ 'width' ] = $width ;
247 } else if (isset ( $this->listViewDefs [ $field ] [ 'width' ] ))
249 $newFields [ $field ] [ 'width' ] = $this->listViewDefs [ $field ] [ 'width' ] ;
252 $subpanel->saveSubPanelDefOverride ( $this->panel, 'list_fields', $newFields ) ;