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-2013 SugarCRM Inc.
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.
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
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
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.
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.
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 ********************************************************************************/
38 require_once('include/SubPanel/SubPanel.php');
39 require_once('include/SubPanel/SubPanelDefinitions.php');
40 require_once('include/SubPanel/SubPanelTiles.php');
42 * Tabbed subpanel tiles
45 class SubPanelTilesTabs extends SubPanelTiles
48 function SubPanelTiles(&$focus, $layout_def_key='', $layout_def_override = '')
51 $this->focus = $focus;
52 $this->id = $focus->id;
53 $this->module = $focus->module_dir;
54 $this->layout_def_key = $layout_def_key;
55 $this->subpanel_definitions = new SubPanelDefinitions($focus, $layout_def_key, $layout_def_override);
58 function getSubpanelGroupLayout($selectedGroup)
62 $layoutParams = $this->module;
63 //WDong Bug: 12258 "All" tab in the middle of a record's detail view is not localized.
64 if($selectedGroup != translate('LBL_TABGROUP_ALL'))
66 $layoutParams .= ':'.$selectedGroup;
69 // see if user current user has custom subpanel layout
70 return $current_user->getPreference('subpanelLayout', $layoutParams);
73 function applyUserCustomLayoutToTabs($tabs, $key='All')
75 //WDong Bug: 12258 "All" tab in the middle of a record's detail view is not localized.
78 $key=translate('LBL_TABGROUP_ALL');
80 $usersCustomLayout = SubPanelTilesTabs::getSubpanelGroupLayout($key);
81 if(!empty($usersCustomLayout))
83 /* Return elements of the custom layout
84 * which occur in $tabs in unchanged order.
85 * Then append elements of $tabs which are
86 * not included in the layout. */
87 $diff = array_diff($tabs, $usersCustomLayout);
88 $tabs = array_intersect($usersCustomLayout, $tabs);
89 foreach($diff as $subpanel)
99 * Place subpanels into tabs for display on a DetailView
100 * @param array $tabs Array containing the ids of all subpanels to be placed into tabs
101 * @param boolean $showTabs Call the view code to display the generated tabs
102 * @param string $selectedGroup (Optional) Name of any selected tab (defaults to 'All')
104 function getTabs($tabs, $showTabs = true, $selectedGroup='All')
106 //WDong Bug: 12258 "All" tab in the middle of a record's detail view is not localized.
107 if($selectedGroup=='All')
108 $selectedGroup=translate('LBL_TABGROUP_ALL');
110 // Set up a mapping from subpanelID, found in the $tabs list, to the source module name
111 // As the $GLOBALS['tabStructure'] array holds the Group Tabs by module name we need to efficiently convert between the two
112 // when constructing the subpanel tabs
113 // Note that we can't use the very similar GroupedTabStructure class as it lacks this mapping, and logically, it is designed
114 // for use when constructing the module by module tabs, not the subpanel tabs, as we move away from using module names to represent
115 // subpanels, and use unique subpanel IDs instead.
117 $moduleNames = array () ;
118 foreach ( $tabs as $subpanelID )
120 // Bug #44344 : Custom relationships under same module only show once in subpanel tabs
121 // use object property instead new object to have ability run unit test (can override subpanel_definitions)
122 $subpanel = $this->subpanel_definitions->load_subpanel( $subpanelID );
123 if ($subpanel !== false)
124 $moduleNames [ $subpanelID ] = $subpanel->get_module_name() ;
130 foreach( $GLOBALS['tabStructure'] as $mainTab => $subModules)
132 foreach( $subModules['modules'] as $key => $subModule )
134 foreach ( $tabs as $subpanelID )
135 if (isset($moduleNames[ $subpanelID ] ) && strcasecmp( $subModule , $moduleNames[ $subpanelID ] ) === 0)
137 // Bug #44344 : Custom relationships under same module only show once in subpanel tabs
138 $groups [ translate ( $mainTab ) ] [ 'modules' ] [] = $subpanelID ;
139 $found [ $subpanelID ] = true ;
144 // Put all the remaining subpanels into the 'Other' tab.
146 foreach( $tabs as $subpanelID )
148 if ( ! isset ( $found [ $subpanelID ] ) )
149 $groups [ translate ('LBL_TABGROUP_OTHER') ]['modules'] [] = $subpanelID ;
152 /* Move history to same tab as activities */
153 if(in_array('history', $tabs) && in_array('activities', $tabs))
155 foreach($groups as $mainTab => $group)
157 if(in_array('activities', array_map('strtolower', $group['modules'])))
159 if(!in_array('history', array_map('strtolower', $group['modules'])))
161 /* Move hist from there to here */
162 $groups[$mainTab]['modules'] []= 'history';
165 else if(false !== ($i = array_search('history', array_map('strtolower', $group['modules']))))
167 unset($groups[$mainTab]['modules'][$i]);
168 if(empty($groups[$mainTab]['modules']))
170 unset($groups[$mainTab]);
176 /* Add the 'All' group.
177 * Note that if a tab group already exists with the name 'All',
178 * it will be overwritten in this union operation.
180 if(count($groups) <= 1)
181 $groups = array(translate('LBL_TABGROUP_ALL') => array('label' => translate('LBL_TABGROUP_ALL'), 'modules' => $tabs));
183 $groups = array(translate('LBL_TABGROUP_ALL') => array('label' => translate('LBL_TABGROUP_ALL'), 'modules' => $tabs)) + $groups;
184 /* Note - all $display checking and array_intersects with $tabs
185 * are now redundant (thanks to GroupedTabStructure), and could
186 * be removed for performance, but for now can stay to help ensure
187 * that the tabs get renedered correctly.
193 require_once('include/SubPanel/SugarTab.php');
194 $sugarTab = new SugarTab();
196 $displayTabs = array();
197 $otherTabs = array();
199 foreach ($groups as $key=>$tab)
202 foreach($tab['modules'] as $subkey=>$subtab)
204 if(in_array(strtolower($subtab), $tabs))
213 if($selectedGroup == $key)
215 $selected = 'current';
220 $relevantTabs = SubPanelTilesTabs::applyUserCustomLayoutToTabs($tabs, $key);
222 $sugarTabs[$key] = array(//'url'=>'index.php?module=' . $_REQUEST['module'] . '&record=' . $_REQUEST['record'] . '&action=' . $_REQUEST['action']. '&subpanel=' . $key.'#tabs',
223 //'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);",
224 'label'=>( !empty($tab['label']) ? $tab['label']: $key ),
227 $otherTabs[$key] = array('key'=>$key, 'tabs'=>array());
229 $orderedTabs = array_intersect($relevantTabs, array_map('strtolower', $groups[$key]['modules']));
231 foreach($orderedTabs as $subkey => $subtab)
233 $otherTabs[$key]['tabs'][$subkey] = array('key'=>$subtab, 'label'=>translate($this->subpanel_definitions->layout_defs['subpanel_setup'][$subtab]['title_key']));
236 if($selectedGroup == $key)
238 $displayTabs = $otherTabs[$key]['tabs'];
239 $retTabs = $orderedTabs;
244 if(empty($displayTabs) && !empty($otherTabs))
246 //WDong Bug: 12258 "All" tab in the middle of a record's detail view is not localized.
247 $selectedGroup = translate('LBL_TABGROUP_ALL');
248 $displayTabs = $otherTabs[$selectedGroup]['tabs'];
249 $sugarTabs[$selectedGroup]['type'] = 'current';
250 $retTabs = array_intersect($tabs, array_map('strtolower', $groups[$selectedGroup]['modules']));
253 if (!empty($sugarTabs) || !empty($otherTabs) ) {
254 $sugarTab->setup($sugarTabs, $otherTabs, $displayTabs, $selectedGroup);
255 $sugarTab->display();
260 $tabs = SubPanelTilesTabs::applyUserCustomLayoutToTabs($tabs, $selectedGroup);
262 $retTabs = array_intersect($tabs, array_map('strtolower', $groups[$selectedGroup]['modules']));