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 ********************************************************************************/
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 require_once 'include/SubPanel/SubPanelDefinitions.php' ;
111 $spd = new SubPanelDefinitions ( $this->focus ) ;
113 // Set up a mapping from subpanelID, found in the $tabs list, to the source module name
114 // As the $GLOBALS['tabStructure'] array holds the Group Tabs by module name we need to efficiently convert between the two
115 // when constructing the subpanel tabs
116 // Note that we can't use the very similar GroupedTabStructure class as it lacks this mapping, and logically, it is designed
117 // for use when constructing the module by module tabs, not the subpanel tabs, as we move away from using module names to represent
118 // subpanels, and use unique subpanel IDs instead.
120 $moduleNames = array () ;
121 foreach ( $tabs as $subpanelID )
123 $subpanel = $spd->load_subpanel( $subpanelID );
124 if ($subpanel !== false)
125 $moduleNames [ $subpanelID ] = $subpanel->get_module_name() ;
131 foreach( $GLOBALS['tabStructure'] as $mainTab => $subModules)
133 foreach( $subModules['modules'] as $key => $subModule )
135 foreach ( $tabs as $subpanelID )
136 if (isset($moduleNames[ $subpanelID ] ) && strcasecmp( $subModule , $moduleNames[ $subpanelID ] ) === 0)
138 $groups [ translate ( $mainTab ) ] [ 'modules' ] [ $key ] = $subpanelID ;
139 $found [ $subpanelID ] = true ;
145 // Put all the remaining subpanels into the 'Other' tab.
147 foreach( $tabs as $subpanelID )
149 if ( ! isset ( $found [ $subpanelID ] ) )
150 $groups [ translate ('LBL_TABGROUP_OTHER') ]['modules'] [] = $subpanelID ;
153 /* Move history to same tab as activities */
154 if(in_array('history', $tabs) && in_array('activities', $tabs))
156 foreach($groups as $mainTab => $group)
158 if(in_array('activities', array_map('strtolower', $group['modules'])))
160 if(!in_array('history', array_map('strtolower', $group['modules'])))
162 /* Move hist from there to here */
163 $groups[$mainTab]['modules'] []= 'history';
166 else if(false !== ($i = array_search('history', array_map('strtolower', $group['modules']))))
168 unset($groups[$mainTab]['modules'][$i]);
169 if(empty($groups[$mainTab]['modules']))
171 unset($groups[$mainTab]);
177 /* Add the 'All' group.
178 * Note that if a tab group already exists with the name 'All',
179 * it will be overwritten in this union operation.
181 if(count($groups) <= 1)
182 $groups = array(translate('LBL_TABGROUP_ALL') => array('label' => translate('LBL_TABGROUP_ALL'), 'modules' => $tabs));
184 $groups = array(translate('LBL_TABGROUP_ALL') => array('label' => translate('LBL_TABGROUP_ALL'), 'modules' => $tabs)) + $groups;
185 /* Note - all $display checking and array_intersects with $tabs
186 * are now redundant (thanks to GroupedTabStructure), and could
187 * be removed for performance, but for now can stay to help ensure
188 * that the tabs get renedered correctly.
194 require_once('include/SubPanel/SugarTab.php');
195 $sugarTab = new SugarTab();
197 $displayTabs = array();
198 $otherTabs = array();
200 foreach ($groups as $key=>$tab)
203 foreach($tab['modules'] as $subkey=>$subtab)
205 if(in_array(strtolower($subtab), $tabs))
214 if($selectedGroup == $key)
216 $selected = 'current';
221 $relevantTabs = SubPanelTilesTabs::applyUserCustomLayoutToTabs($tabs, $key);
223 $sugarTabs[$key] = array(//'url'=>'index.php?module=' . $_REQUEST['module'] . '&record=' . $_REQUEST['record'] . '&action=' . $_REQUEST['action']. '&subpanel=' . $key.'#tabs',
224 //'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);",
225 'label'=>( !empty($tab['label']) ? $tab['label']: $key ),
228 $otherTabs[$key] = array('key'=>$key, 'tabs'=>array());
230 $orderedTabs = array_intersect($relevantTabs, array_map('strtolower', $groups[$key]['modules']));
232 foreach($orderedTabs as $subkey => $subtab)
234 $otherTabs[$key]['tabs'][$subkey] = array('key'=>$subtab, 'label'=>translate($this->subpanel_definitions->layout_defs['subpanel_setup'][$subtab]['title_key']));
237 if($selectedGroup == $key)
239 $displayTabs = $otherTabs[$key]['tabs'];
240 $retTabs = $orderedTabs;
245 if(empty($displayTabs) && !empty($otherTabs))
247 //WDong Bug: 12258 "All" tab in the middle of a record's detail view is not localized.
248 $selectedGroup = translate('LBL_TABGROUP_ALL');
249 $displayTabs = $otherTabs[$selectedGroup]['tabs'];
250 $sugarTabs[$selectedGroup]['type'] = 'current';
251 $retTabs = array_intersect($tabs, array_map('strtolower', $groups[$selectedGroup]['modules']));
254 if (!empty($sugarTabs) || !empty($otherTabs) ) {
255 $sugarTab->setup($sugarTabs, $otherTabs, $displayTabs, $selectedGroup);
256 $sugarTab->display();
261 $tabs = SubPanelTilesTabs::applyUserCustomLayoutToTabs($tabs, $selectedGroup);
263 $retTabs = array_intersect($tabs, array_map('strtolower', $groups[$selectedGroup]['modules']));