]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/GroupedTabs/GroupedTabStructure.php
Release 6.5.16
[Github/sugarcrm.git] / include / GroupedTabs / GroupedTabStructure.php
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  * 
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
38
39 class GroupedTabStructure
40 {
41         /** 
42      * Prepare the tabs structure.
43      * Uses 'Other' tab functionality.
44      * If $modList is not specified, $modListHeader is used as default.
45      * 
46      * @param   array   optional list of modules considered valid
47      * @param   array   optional array to temporarily union into the root of the tab structure 
48     * @param bool  if  we set this param true, the other group tab will be returned no matter  $sugar_config['other_group_tab_displayed'] is true or false
49      * @param bool  We use label value as return array key by default. But we can set this param true, that we can use the label name as return array key.
50      * 
51      * @return  array   the complete tab-group structure
52          */
53     function get_tab_structure($modList = '', $patch = '', $ignoreSugarConfig=false, $labelAsKey=false)
54     {
55         global $modListHeader, $app_strings, $app_list_strings, $modInvisListActivities;
56         
57         /* Use default if not provided */
58         if(!$modList)
59         {
60                 $modList =& $modListHeader;
61         }
62
63         require 'include/tabConfig.php';
64
65         /* Apply patch, use a reference if we can */
66         if($patch)
67         {
68                 $tabStructure = $GLOBALS['tabStructure'];
69                 
70             foreach($patch as $mainTab => $subModules)
71             {
72                 $tabStructure[$mainTab]['modules'] = array_merge($tabStructure[$mainTab]['modules'], $subModules);
73             }
74         }
75         else
76         {
77                 $tabStructure =& $GLOBALS['tabStructure'];
78         }
79         
80         $retStruct = array();
81         $mlhUsed = array();
82                 //the invisible list should be merged if activities is set to be hidden
83         if(in_array('Activities', $modList)){
84                 $modList = array_merge($modList,$modInvisListActivities);
85                 }
86                 
87                 //Add any iFrame tabs to the 'other' group.
88                 $moduleExtraMenu = array();
89                 if(!should_hide_iframes()) {
90                         $iFrame = new iFrame();
91                         $frames = $iFrame->lookup_frames('tab');        
92                 foreach($frames as $key => $values){
93                         $moduleExtraMenu[$key] = $values;
94                 }
95                 } else if(isset($modList['iFrames'])) {
96                     unset($modList['iFrames']);
97                 }
98                                 
99         $modList = array_merge($modList,$moduleExtraMenu);
100                 
101         /* Only return modules which exists in the modList */
102         foreach($tabStructure as $mainTab => $subModules)
103         {
104             //Ensure even empty groups are returned
105                 if($labelAsKey){
106                 $retStruct[$subModules['label']]['modules'] = array();
107             }else{
108                 $retStruct[$app_strings[$subModules['label']]]['modules']= array();
109             }
110
111             foreach($subModules['modules'] as $key => $subModule)
112             {
113                /* Perform a case-insensitive in_array check
114                 * and mark whichever module matched as used.
115                 */ 
116                 foreach($modList as $module)
117                 {
118                     if(is_string($module) && strcasecmp($subModule, $module) === 0)
119                     {
120                         if($labelAsKey){
121                                 $retStruct[$subModules['label']]['modules'][$module] = $app_list_strings['moduleList'][$module];
122                         }else{
123                                 $retStruct[$app_strings[$subModules['label']]]['modules'][$module] = $app_list_strings['moduleList'][$module];
124                         }                        
125                         $mlhUsed[$module] = true;
126                         break;
127                     }
128                 }
129             }
130                         //remove the group tabs if it has no sub modules under it               
131             if($labelAsKey){
132                     if (empty($retStruct[$subModules['label']]['modules'])){
133                     unset($retStruct[$subModules['label']]);
134                     }
135                     }else{
136                     if (empty($retStruct[$app_strings[$subModules['label']]]['modules'])){
137                     unset($retStruct[$app_strings[$subModules['label']]]);
138                     }
139                         }
140         }
141         
142 //        _pp($retStruct);
143         return $retStruct;
144     }
145 }
146
147 ?>