PageRenderTime 44ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/include/SubPanel/SubPanelTilesTabs.php

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