]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/SubPanel/SubPanelTilesTabs.php
Release 6.2.0
[Github/sugarcrm.git] / include / SubPanel / SubPanelTilesTabs.php
1 <?php
2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4  * SugarCRM Community Edition is a customer relationship management program developed by
5  * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
6  * 
7  * This program is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU Affero General Public License version 3 as published by the
9  * Free Software Foundation with the addition of the following permission added
10  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
11  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
12  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
13  * 
14  * This program is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
17  * details.
18  * 
19  * You should have received a copy of the GNU Affero General Public License along with
20  * this program; if not, see http://www.gnu.org/licenses or write to the Free
21  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22  * 02110-1301 USA.
23  * 
24  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
25  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
26  * 
27  * The interactive user interfaces in modified source and object code versions
28  * of this program must display Appropriate Legal Notices, as required under
29  * Section 5 of the GNU Affero General Public License version 3.
30  * 
31  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
32  * these Appropriate Legal Notices must retain the display of the "Powered by
33  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
34  * technical reasons, the Appropriate Legal Notices must display the words
35  * "Powered by SugarCRM".
36  ********************************************************************************/
37
38
39
40 require_once('include/SubPanel/SubPanel.php');
41 require_once('include/SubPanel/SubPanelDefinitions.php');
42 require_once('include/SubPanel/SubPanelTiles.php');
43 class SubPanelTilesTabs extends SubPanelTiles
44 {
45
46         function SubPanelTiles(&$focus, $layout_def_key='', $layout_def_override = '')
47         {
48
49                 $this->focus = $focus;
50                 $this->id = $focus->id;
51                 $this->module = $focus->module_dir;
52                 $this->layout_def_key = $layout_def_key;
53                 $this->subpanel_definitions = new SubPanelDefinitions($focus, $layout_def_key, $layout_def_override);
54         }
55
56     function getSubpanelGroupLayout($selectedGroup)
57     {
58         global $current_user;
59
60         $layoutParams = $this->module;
61         //WDong Bug: 12258 "All" tab in the middle of a record's detail view is not localized.
62         if($selectedGroup != translate('LBL_TABGROUP_ALL'))
63         {
64             $layoutParams .= ':'.$selectedGroup;
65         }
66
67         // see if user current user has custom subpanel layout
68         return $current_user->getPreference('subpanelLayout', $layoutParams);
69     }
70
71     function applyUserCustomLayoutToTabs($tabs, $key='All')
72     {
73         //WDong Bug: 12258 "All" tab in the middle of a record's detail view is not localized.
74         if($key=='All')
75         {
76                 $key=translate('LBL_TABGROUP_ALL');
77         }
78         $usersCustomLayout = SubPanelTilesTabs::getSubpanelGroupLayout($key);
79         if(!empty($usersCustomLayout))
80         {
81             /* Return elements of the custom layout
82              * which occur in $tabs in unchanged order.
83              * Then append elements of $tabs which are
84              * not included in the layout. */
85             $diff = array_diff($tabs, $usersCustomLayout);
86             $tabs = array_intersect($usersCustomLayout, $tabs);
87             foreach($diff as $subpanel)
88             {
89                 $tabs []= $subpanel;
90             }
91         }
92
93         return $tabs;
94     }
95
96     /*
97      * Place subpanels into tabs for display on a DetailView
98      * @param array $tabs       Array containing the ids of all subpanels to be placed into tabs
99      * @param boolean $showTabs Call the view code to display the generated tabs
100      * @param string $selectedGroup     (Optional) Name of any selected tab (defaults to 'All')
101      */
102         function getTabs($tabs, $showTabs = true, $selectedGroup='All')
103     {
104         //WDong Bug: 12258 "All" tab in the middle of a record's detail view is not localized.
105         if($selectedGroup=='All')
106                 $selectedGroup=translate('LBL_TABGROUP_ALL');
107
108         require_once 'include/SubPanel/SubPanelDefinitions.php' ;
109         $spd = new SubPanelDefinitions ( $this->focus ) ;
110
111         // Set up a mapping from subpanelID, found in the $tabs list, to the source module name
112         // As the $GLOBALS['tabStructure'] array holds the Group Tabs by module name we need to efficiently convert between the two
113         // when constructing the subpanel tabs
114         // Note that we can't use the very similar GroupedTabStructure class as it lacks this mapping, and logically, it is designed
115         // for use when constructing the module by module tabs, not the subpanel tabs, as we move away from using module names to represent
116         // subpanels, and use unique subpanel IDs instead.
117
118         $moduleNames = array () ;
119         foreach ( $tabs as $subpanelID )
120         {
121                 $subpanel =  $spd->load_subpanel( $subpanelID );
122                 if ($subpanel !== false)
123                   $moduleNames [ $subpanelID ] = $subpanel->get_module_name() ;
124         }
125
126         $groups =  array () ;
127         $found = array () ;
128
129         foreach( $GLOBALS['tabStructure'] as $mainTab => $subModules)
130         {
131             foreach( $subModules['modules'] as $key => $subModule )
132             {
133                         foreach ( $tabs as $subpanelID )
134                     if (isset($moduleNames[ $subpanelID ] ) && strcasecmp( $subModule , $moduleNames[ $subpanelID ] ) === 0)
135                     {
136                         $groups [ translate ( $mainTab ) ] [ 'modules' ] [ $key ] = $subpanelID ;
137                         $found [ $subpanelID ] = true ;
138                         break;
139                         }
140             }
141         }
142
143         // Put all the remaining subpanels into the 'Other' tab.
144
145         foreach( $tabs as $subpanelID )
146         {
147                 if ( ! isset ( $found [ $subpanelID ] ) )
148                         $groups [ translate ('LBL_TABGROUP_OTHER') ]['modules'] [] = $subpanelID ;
149         }
150
151         /* Move history to same tab as activities */
152         if(in_array('history', $tabs) && in_array('activities', $tabs))
153         {
154             foreach($groups as $mainTab => $group)
155             {
156                 if(in_array('activities', array_map('strtolower', $group['modules'])))
157                 {
158                         if(!in_array('history', array_map('strtolower', $group['modules'])))
159                     {
160                         /* Move hist from there to here */
161                         $groups[$mainTab]['modules'] []= 'history';
162                     }
163                 }
164                 else if(false !== ($i = array_search('history', array_map('strtolower', $group['modules']))))
165                 {
166                     unset($groups[$mainTab]['modules'][$i]);
167                     if(empty($groups[$mainTab]['modules']))
168                     {
169                         unset($groups[$mainTab]);
170                     }
171                 }
172             }
173         }
174
175         /* Add the 'All' group.
176          * Note that if a tab group already exists with the name 'All',
177          * it will be overwritten in this union operation.
178          */
179         if(count($groups) <= 1)
180                 $groups = array(translate('LBL_TABGROUP_ALL') => array('label' => translate('LBL_TABGROUP_ALL'), 'modules' => $tabs));
181         else
182             $groups = array(translate('LBL_TABGROUP_ALL') => array('label' => translate('LBL_TABGROUP_ALL'), 'modules' => $tabs)) + $groups;
183         /* Note - all $display checking and array_intersects with $tabs
184          * are now redundant (thanks to GroupedTabStructure), and could
185          * be removed for performance, but for now can stay to help ensure
186          * that the tabs get renedered correctly.
187          */
188
189         $retTabs = array();
190         if($showTabs)
191         {
192                 require_once('include/SubPanel/SugarTab.php');
193                 $sugarTab = new SugarTab();
194
195             $displayTabs = array();
196             $otherTabs = array();
197
198             foreach ($groups as $key=>$tab)
199                 {
200                 $display = false;
201                 foreach($tab['modules'] as $subkey=>$subtab)
202                 {
203                     if(in_array(strtolower($subtab), $tabs))
204                     {
205                         $display = true;
206                         break;
207                     }
208                 }
209
210                 $selected = '';
211
212                 if($selectedGroup == $key)
213                 {
214                     $selected = 'current';
215                 }
216
217                 if($display)
218                 {
219                     $relevantTabs = SubPanelTilesTabs::applyUserCustomLayoutToTabs($tabs, $key);
220
221                     $sugarTabs[$key] = array(//'url'=>'index.php?module=' . $_REQUEST['module'] . '&record=' . $_REQUEST['record'] . '&action=' . $_REQUEST['action']. '&subpanel=' . $key.'#tabs',
222                                          //'url'=>"javascript:SUGAR.util.retrieveAndFill('index.php?to_pdf=1&module=MySettings&action=LoadTabSubpanels&loadModule={$_REQUEST['module']}&record={$_REQUEST['record']}&subpanel=$key','subpanel_list',null,null,null);",
223                                          'label'=>( !empty($tab['label']) ? $tab['label']: $key ),
224                                          'type'=>$selected);
225
226                     $otherTabs[$key] = array('key'=>$key, 'tabs'=>array());
227
228                     $orderedTabs = array_intersect($relevantTabs, array_map('strtolower', $groups[$key]['modules']));
229
230                     foreach($orderedTabs as $subkey => $subtab)
231                     {
232                         $otherTabs[$key]['tabs'][$subkey] = array('key'=>$subtab, 'label'=>translate($this->subpanel_definitions->layout_defs['subpanel_setup'][$subtab]['title_key']));
233                     }
234
235                     if($selectedGroup == $key)
236                     {
237                         $displayTabs = $otherTabs[$key]['tabs'];
238                         $retTabs = $orderedTabs;
239                     }
240                 }
241                 }
242
243             if(empty($displayTabs) && !empty($otherTabs))
244             {
245                 //WDong Bug: 12258 "All" tab in the middle of a record's detail view is not localized.
246                 $selectedGroup = translate('LBL_TABGROUP_ALL');
247                 $displayTabs = $otherTabs[$selectedGroup]['tabs'];
248                 $sugarTabs[$selectedGroup]['type'] = 'current';
249                 $retTabs = array_intersect($tabs, array_map('strtolower', $groups[$selectedGroup]['modules']));
250             }
251
252             if (!empty($sugarTabs) || !empty($otherTabs) ) {
253                 $sugarTab->setup($sugarTabs, $otherTabs, $displayTabs, $selectedGroup);
254                 $sugarTab->display();
255             }
256         }
257         else
258         {
259             $tabs = SubPanelTilesTabs::applyUserCustomLayoutToTabs($tabs, $selectedGroup);
260
261             $retTabs = array_intersect($tabs, array_map('strtolower', $groups[$selectedGroup]['modules']));
262         }
263
264                 return $retTabs;
265         }
266 }
267 ?>