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.
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 ********************************************************************************/
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
46 function SubPanelTiles(&$focus, $layout_def_key='', $layout_def_override = '')
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);
56 function getSubpanelGroupLayout($selectedGroup)
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'))
64 $layoutParams .= ':'.$selectedGroup;
67 // see if user current user has custom subpanel layout
68 return $current_user->getPreference('subpanelLayout', $layoutParams);
71 function applyUserCustomLayoutToTabs($tabs, $key='All')
73 //WDong Bug: 12258 "All" tab in the middle of a record's detail view is not localized.
76 $key=translate('LBL_TABGROUP_ALL');
78 $usersCustomLayout = SubPanelTilesTabs::getSubpanelGroupLayout($key);
79 if(!empty($usersCustomLayout))
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)
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')
102 function getTabs($tabs, $showTabs = true, $selectedGroup='All')
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');
108 require_once 'include/SubPanel/SubPanelDefinitions.php' ;
109 $spd = new SubPanelDefinitions ( $this->focus ) ;
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.
118 $moduleNames = array () ;
119 foreach ( $tabs as $subpanelID )
121 $subpanel = $spd->load_subpanel( $subpanelID );
122 if ($subpanel !== false)
123 $moduleNames [ $subpanelID ] = $subpanel->get_module_name() ;
129 foreach( $GLOBALS['tabStructure'] as $mainTab => $subModules)
131 foreach( $subModules['modules'] as $key => $subModule )
133 foreach ( $tabs as $subpanelID )
134 if (isset($moduleNames[ $subpanelID ] ) && strcasecmp( $subModule , $moduleNames[ $subpanelID ] ) === 0)
136 $groups [ translate ( $mainTab ) ] [ 'modules' ] [ $key ] = $subpanelID ;
137 $found [ $subpanelID ] = true ;
143 // Put all the remaining subpanels into the 'Other' tab.
145 foreach( $tabs as $subpanelID )
147 if ( ! isset ( $found [ $subpanelID ] ) )
148 $groups [ translate ('LBL_TABGROUP_OTHER') ]['modules'] [] = $subpanelID ;
151 /* Move history to same tab as activities */
152 if(in_array('history', $tabs) && in_array('activities', $tabs))
154 foreach($groups as $mainTab => $group)
156 if(in_array('activities', array_map('strtolower', $group['modules'])))
158 if(!in_array('history', array_map('strtolower', $group['modules'])))
160 /* Move hist from there to here */
161 $groups[$mainTab]['modules'] []= 'history';
164 else if(false !== ($i = array_search('history', array_map('strtolower', $group['modules']))))
166 unset($groups[$mainTab]['modules'][$i]);
167 if(empty($groups[$mainTab]['modules']))
169 unset($groups[$mainTab]);
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.
179 if(count($groups) <= 1)
180 $groups = array(translate('LBL_TABGROUP_ALL') => array('label' => translate('LBL_TABGROUP_ALL'), 'modules' => $tabs));
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.
192 require_once('include/SubPanel/SugarTab.php');
193 $sugarTab = new SugarTab();
195 $displayTabs = array();
196 $otherTabs = array();
198 foreach ($groups as $key=>$tab)
201 foreach($tab['modules'] as $subkey=>$subtab)
203 if(in_array(strtolower($subtab), $tabs))
212 if($selectedGroup == $key)
214 $selected = 'current';
219 $relevantTabs = SubPanelTilesTabs::applyUserCustomLayoutToTabs($tabs, $key);
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 ),
226 $otherTabs[$key] = array('key'=>$key, 'tabs'=>array());
228 $orderedTabs = array_intersect($relevantTabs, array_map('strtolower', $groups[$key]['modules']));
230 foreach($orderedTabs as $subkey => $subtab)
232 $otherTabs[$key]['tabs'][$subkey] = array('key'=>$subtab, 'label'=>translate($this->subpanel_definitions->layout_defs['subpanel_setup'][$subtab]['title_key']));
235 if($selectedGroup == $key)
237 $displayTabs = $otherTabs[$key]['tabs'];
238 $retTabs = $orderedTabs;
243 if(empty($displayTabs) && !empty($otherTabs))
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']));
252 if (!empty($sugarTabs) || !empty($otherTabs) ) {
253 $sugarTab->setup($sugarTabs, $otherTabs, $displayTabs, $selectedGroup);
254 $sugarTab->display();
259 $tabs = SubPanelTilesTabs::applyUserCustomLayoutToTabs($tabs, $selectedGroup);
261 $retTabs = array_intersect($tabs, array_map('strtolower', $groups[$selectedGroup]['modules']));