]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/ModuleBuilder/parsers/parser.modifysubpanel.php
Release 6.5.0
[Github/sugarcrm.git] / modules / ModuleBuilder / parsers / parser.modifysubpanel.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
41 /*
42  * Modify an exising Subpanel
43  * Typically called from Studio for a deployed (OOB or installed custom module)
44  * 
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)
48  */
49
50 require_once ('modules/ModuleBuilder/parsers/parser.modifylistview.php') ;
51
52 class ParserModifySubPanel extends ParserModifyListView
53 {
54     
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' ) ;
60     
61     function init ($module_name , $subPanelName)
62     {
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 ;
67         
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 ) ;
70         
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 ) ;
77         
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' ] ))
82         {
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 () ;
87             
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 ;
91
92             if (! empty ( $subPanelParentModuleName ) && isset($beanListLower[strtolower($subPanelParentModuleName)]))
93             {
94                 $class = $beanListLower[strtolower($subPanelParentModuleName)];
95                 if (isset($beanFiles [ $class ]))
96                 {
97                     require_once ($beanFiles [ $class ]) ;
98                     $this->subPanelParentModule = new $class ( ) ;
99                 }
100             }
101         }
102         
103         $this->language_module = $this->panel->template_instance->module_dir ;
104     }
105     
106     /**
107      * Return a list of the fields that will be displayed in the subpanel
108      */
109     function getDefaultFields ()
110     {
111         $this->defaults = array ( ) ;
112         foreach ( $this->listViewDefs as $key => $def )
113         {
114             if (! empty ( $def [ 'usage' ] ) && strcmp ( $def [ 'usage' ], 'query_only' ) == 0)
115                 continue ;
116             if (! empty ( $def [ 'vname' ] ))
117                 $def [ 'label' ] = $def [ 'vname' ] ;
118             $this->defaults [ $key ] = $def ;
119         }
120         return $this->defaults ;
121     }
122     
123     /**
124      * Return a list of fields that are not currently included in the subpanel but that are available for use
125      */
126     function getAvailableFields ()
127     {
128         $this->availableFields = array ( ) ;
129         if ($this->subPanelParentModule != null)
130         {
131             $lowerFieldList = array_change_key_case ( $this->listViewDefs ) ;
132             foreach ( $this->originalListViewDefs as $key => $def )
133             {
134                 $key = strtolower ( $key ) ;
135                 if (! isset ( $lowerFieldList [ $key ] ))
136                 {
137                     $this->availableFields [ $key ] = $def ;
138                 }
139             }
140             $GLOBALS [ 'log' ]->debug ( 'parser.modifylistview.php->getAvailableFields(): field_defs=' . print_r ( $this->availableFields, true ) ) ;
141             foreach ( $this->subPanelParentModule->field_defs as $key => $fieldDefinition )
142             {
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
145                 {
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'))
147                     {
148                         $label = (isset ( $fieldDefinition [ 'vname' ] )) ? $fieldDefinition [ 'vname' ] : (isset ( $fieldDefinition [ 'label' ] ) ? $fieldDefinition [ 'label' ] : $fieldDefinition [ 'name' ]) ;
149                         $this->availableFields [ $fieldName ] = array ( 'width' => '10' , 'label' => $label ) ;
150                     }
151                 }
152             }
153         }
154         
155         return $this->availableFields ;
156     }
157     
158     function getField ($fieldName)
159     {
160         foreach ( $this->listViewDefs as $key => $def )
161         {
162             $key = strtolower ( $key ) ;
163             if ($key == $fieldName)
164             {
165                 return $def ;
166             }
167         }
168         foreach ( $this->originalListViewDefs as $key => $def )
169         {
170             $key = strtolower ( $key ) ;
171             if ($key == $fieldName)
172             {
173                 return $def ;
174             }
175         }
176         foreach ( $this->panel->template_instance->field_defs as $key => $def )
177         {
178             $key = strtolower ( $key ) ;
179             if ($key == $fieldName)
180             {
181                 return $def ;
182             }
183         }
184         return array ( ) ;
185     }
186     
187     /*
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 
191      */
192     function handleSave ()
193     {
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 ) ;
197         
198         $newFields = array ( ) ;
199         foreach ( $this->listViewDefs as $name => $field )
200         {
201             if (! isset ( $field [ 'usage' ] ) || $field [ 'usage' ] != 'query_only')
202             {
203                 $existingFields [ $name ] = $field ;
204             
205             } else
206             {
207                 $newFields [ $name ] = $field ;
208             }
209         }
210         
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 )
214         {
215             if (! empty ( $this->originalListViewDefs [ $field ] ))
216             {
217                 $newFields [ $field ] = $this->originalListViewDefs [ $field ] ;
218             } else
219             {
220                 
221                 $vname = '' ;
222                 if (isset ( $this->panel->template_instance->field_defs [ $field ] ))
223                 {
224                     $vname = $this->panel->template_instance->field_defs [ $field ] [ 'vname' ] ;
225                 }
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'))))
227                 {
228                     $newFields [ $field ] = array ( 'name' => $field , 'vname' => $vname , 'widget_type' => 'checkbox' ) ;
229                 } else
230                 {
231                     $newFields [ $field ] = array ( 'name' => $field , 'vname' => $vname ) ;
232                 }
233             }
234             
235             // Now set the field width if specified in the $_REQUEST data
236             if (isset ( $_REQUEST [ strtolower ( $field ) . 'width' ] ))
237             {
238                 $width = substr ( $_REQUEST [ strtolower ( $field ) . 'width' ], 6, 3 ) ;
239                 if (strpos ( $width, "%" ) != false)
240                 {
241                     $width = substr ( $width, 0, 2 ) ;
242                 }
243                 if ($width < 101 && $width > 0)
244                 {
245                     $newFields [ $field ] [ 'width' ] = $width ;
246                 }
247             } else if (isset ( $this->listViewDefs [ $field ] [ 'width' ] ))
248             {
249                 $newFields [ $field ] [ 'width' ] = $this->listViewDefs [ $field ] [ 'width' ] ;
250             }
251         }
252         $subpanel->saveSubPanelDefOverride ( $this->panel, 'list_fields', $newFields ) ;
253     
254     }
255
256 }
257 ?>