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