PageRenderTime 43ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/include/SubPanel/SubPanelTilesTabs.php

https://github.com/jacknicole/sugarcrm_dev
PHP | 267 lines | 164 code | 35 blank | 68 comment | 30 complexity | 1cb4c27d253c46049261c2468f7135bc MD5 | raw file
  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. require_once('include/SubPanel/SubPanel.php');
  38. require_once('include/SubPanel/SubPanelDefinitions.php');
  39. require_once('include/SubPanel/SubPanelTiles.php');
  40. class SubPanelTilesTabs extends SubPanelTiles
  41. {
  42. function SubPanelTiles(&$focus, $layout_def_key='', $layout_def_override = '')
  43. {
  44. $this->focus = $focus;
  45. $this->id = $focus->id;
  46. $this->module = $focus->module_dir;
  47. $this->layout_def_key = $layout_def_key;
  48. $this->subpanel_definitions = new SubPanelDefinitions($focus, $layout_def_key, $layout_def_override);
  49. }
  50. function getSubpanelGroupLayout($selectedGroup)
  51. {
  52. global $current_user;
  53. $layoutParams = $this->module;
  54. //WDong Bug: 12258 "All" tab in the middle of a record's detail view is not localized.
  55. if($selectedGroup != translate('LBL_TABGROUP_ALL'))
  56. {
  57. $layoutParams .= ':'.$selectedGroup;
  58. }
  59. // see if user current user has custom subpanel layout
  60. return $current_user->getPreference('subpanelLayout', $layoutParams);
  61. }
  62. function applyUserCustomLayoutToTabs($tabs, $key='All')
  63. {
  64. //WDong Bug: 12258 "All" tab in the middle of a record's detail view is not localized.
  65. if($key=='All')
  66. {
  67. $key=translate('LBL_TABGROUP_ALL');
  68. }
  69. $usersCustomLayout = SubPanelTilesTabs::getSubpanelGroupLayout($key);
  70. if(!empty($usersCustomLayout))
  71. {
  72. /* Return elements of the custom layout
  73. * which occur in $tabs in unchanged order.
  74. * Then append elements of $tabs which are
  75. * not included in the layout. */
  76. $diff = array_diff($tabs, $usersCustomLayout);
  77. $tabs = array_intersect($usersCustomLayout, $tabs);
  78. foreach($diff as $subpanel)
  79. {
  80. $tabs []= $subpanel;
  81. }
  82. }
  83. return $tabs;
  84. }
  85. /*
  86. * Place subpanels into tabs for display on a DetailView
  87. * @param array $tabs Array containing the ids of all subpanels to be placed into tabs
  88. * @param boolean $showTabs Call the view code to display the generated tabs
  89. * @param string $selectedGroup (Optional) Name of any selected tab (defaults to 'All')
  90. */
  91. function getTabs($tabs, $showTabs = true, $selectedGroup='All')
  92. {
  93. //WDong Bug: 12258 "All" tab in the middle of a record's detail view is not localized.
  94. if($selectedGroup=='All')
  95. $selectedGroup=translate('LBL_TABGROUP_ALL');
  96. require_once 'include/SubPanel/SubPanelDefinitions.php' ;
  97. $spd = new SubPanelDefinitions ( $this->focus ) ;
  98. // Set up a mapping from subpanelID, found in the $tabs list, to the source module name
  99. // As the $GLOBALS['tabStructure'] array holds the Group Tabs by module name we need to efficiently convert between the two
  100. // when constructing the subpanel tabs
  101. // Note that we can't use the very similar GroupedTabStructure class as it lacks this mapping, and logically, it is designed
  102. // for use when constructing the module by module tabs, not the subpanel tabs, as we move away from using module names to represent
  103. // subpanels, and use unique subpanel IDs instead.
  104. $moduleNames = array () ;
  105. foreach ( $tabs as $subpanelID )
  106. {
  107. $subpanel = $spd->load_subpanel( $subpanelID );
  108. if ($subpanel !== false)
  109. $moduleNames [ $subpanelID ] = $subpanel->get_module_name() ;
  110. }
  111. $groups = array () ;
  112. $found = array () ;
  113. foreach( $GLOBALS['tabStructure'] as $mainTab => $subModules)
  114. {
  115. foreach( $subModules['modules'] as $key => $subModule )
  116. {
  117. foreach ( $tabs as $subpanelID )
  118. if (isset($moduleNames[ $subpanelID ] ) && strcasecmp( $subModule , $moduleNames[ $subpanelID ] ) === 0)
  119. {
  120. $groups [ translate ( $mainTab ) ] [ 'modules' ] [ $key ] = $subpanelID ;
  121. $found [ $subpanelID ] = true ;
  122. break;
  123. }
  124. }
  125. }
  126. // Put all the remaining subpanels into the 'Other' tab.
  127. foreach( $tabs as $subpanelID )
  128. {
  129. if ( ! isset ( $found [ $subpanelID ] ) )
  130. $groups [ translate ('LBL_TABGROUP_OTHER') ]['modules'] [] = $subpanelID ;
  131. }
  132. /* Move history to same tab as activities */
  133. if(in_array('history', $tabs) && in_array('activities', $tabs))
  134. {
  135. foreach($groups as $mainTab => $group)
  136. {
  137. if(in_array('activities', array_map('strtolower', $group['modules'])))
  138. {
  139. if(!in_array('history', array_map('strtolower', $group['modules'])))
  140. {
  141. /* Move hist from there to here */
  142. $groups[$mainTab]['modules'] []= 'history';
  143. }
  144. }
  145. else if(false !== ($i = array_search('history', array_map('strtolower', $group['modules']))))
  146. {
  147. unset($groups[$mainTab]['modules'][$i]);
  148. if(empty($groups[$mainTab]['modules']))
  149. {
  150. unset($groups[$mainTab]);
  151. }
  152. }
  153. }
  154. }
  155. /* Add the 'All' group.
  156. * Note that if a tab group already exists with the name 'All',
  157. * it will be overwritten in this union operation.
  158. */
  159. if(count($groups) <= 1)
  160. $groups = array(translate('LBL_TABGROUP_ALL') => array('label' => translate('LBL_TABGROUP_ALL'), 'modules' => $tabs));
  161. else
  162. $groups = array(translate('LBL_TABGROUP_ALL') => array('label' => translate('LBL_TABGROUP_ALL'), 'modules' => $tabs)) + $groups;
  163. /* Note - all $display checking and array_intersects with $tabs
  164. * are now redundant (thanks to GroupedTabStructure), and could
  165. * be removed for performance, but for now can stay to help ensure
  166. * that the tabs get renedered correctly.
  167. */
  168. $retTabs = array();
  169. if($showTabs)
  170. {
  171. require_once('include/SubPanel/SugarTab.php');
  172. $sugarTab = new SugarTab();
  173. $displayTabs = array();
  174. $otherTabs = array();
  175. foreach ($groups as $key=>$tab)
  176. {
  177. $display = false;
  178. foreach($tab['modules'] as $subkey=>$subtab)
  179. {
  180. if(in_array(strtolower($subtab), $tabs))
  181. {
  182. $display = true;
  183. break;
  184. }
  185. }
  186. $selected = '';
  187. if($selectedGroup == $key)
  188. {
  189. $selected = 'current';
  190. }
  191. if($display)
  192. {
  193. $relevantTabs = SubPanelTilesTabs::applyUserCustomLayoutToTabs($tabs, $key);
  194. $sugarTabs[$key] = array(//'url'=>'index.php?module=' . $_REQUEST['module'] . '&record=' . $_REQUEST['record'] . '&action=' . $_REQUEST['action']. '&subpanel=' . $key.'#tabs',
  195. //'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);",
  196. 'label'=>( !empty($tab['label']) ? $tab['label']: $key ),
  197. 'type'=>$selected);
  198. $otherTabs[$key] = array('key'=>$key, 'tabs'=>array());
  199. $orderedTabs = array_intersect($relevantTabs, array_map('strtolower', $groups[$key]['modules']));
  200. foreach($orderedTabs as $subkey => $subtab)
  201. {
  202. $otherTabs[$key]['tabs'][$subkey] = array('key'=>$subtab, 'label'=>translate($this->subpanel_definitions->layout_defs['subpanel_setup'][$subtab]['title_key']));
  203. }
  204. if($selectedGroup == $key)
  205. {
  206. $displayTabs = $otherTabs[$key]['tabs'];
  207. $retTabs = $orderedTabs;
  208. }
  209. }
  210. }
  211. if(empty($displayTabs) && !empty($otherTabs))
  212. {
  213. //WDong Bug: 12258 "All" tab in the middle of a record's detail view is not localized.
  214. $selectedGroup = translate('LBL_TABGROUP_ALL');
  215. $displayTabs = $otherTabs[$selectedGroup]['tabs'];
  216. $sugarTabs[$selectedGroup]['type'] = 'current';
  217. $retTabs = array_intersect($tabs, array_map('strtolower', $groups[$selectedGroup]['modules']));
  218. }
  219. if (!empty($sugarTabs) || !empty($otherTabs) ) {
  220. $sugarTab->setup($sugarTabs, $otherTabs, $displayTabs, $selectedGroup);
  221. $sugarTab->display();
  222. }
  223. }
  224. else
  225. {
  226. $tabs = SubPanelTilesTabs::applyUserCustomLayoutToTabs($tabs, $selectedGroup);
  227. $retTabs = array_intersect($tabs, array_map('strtolower', $groups[$selectedGroup]['modules']));
  228. }
  229. return $retTabs;
  230. }
  231. }
  232. ?>