]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/MySugar/DashletsDialog/DashletsDialog.php
Release 6.4.0
[Github/sugarcrm.git] / include / MySugar / DashletsDialog / DashletsDialog.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-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
38
39
40
41 class DashletsDialog {
42         var $dashlets = array();
43         
44     function getDashlets($category='') {
45         global $app_strings, $current_language, $mod_strings;
46         
47         require_once($GLOBALS['sugar_config']['cache_dir'].'dashlets/dashlets.php');
48         
49         $categories = array( 'module'   => 'Module Views',
50                                                  'portal'       => 'Portal',
51                                                  'charts'       => 'Charts',
52                                                  'tools'        => 'Tools',
53                                                  'misc'         => 'Miscellaneous',
54                                                  'web'      => 'Web');
55         
56         $dashletStrings = array();
57         $dashletsList = array();
58         
59         if (!empty($category)){
60                         $dashletsList[$categories[$category]] = array();                
61         }
62         else{
63                 $dashletsList['Module Views'] = array();
64                 $dashletsList['Charts'] = array();
65                 $dashletsList['Tools'] = array();
66                 $dashletsList['Web'] = array();
67         }
68               
69         asort($dashletsFiles);
70         
71         foreach($dashletsFiles as $className => $files) {
72             if(!empty($files['meta']) && is_file($files['meta'])) {
73                 require_once($files['meta']); // get meta file
74                 
75                 $directory = substr($files['meta'], 0, strrpos($files['meta'], '/') + 1);
76                 if(is_file($directory . $files['class'] . '.' . $current_language . '.lang.php')) 
77                     require_once($directory . $files['class'] . '.' . $current_language . '.lang.php');
78                 elseif(is_file($directory . $files['class'] . '.en_us.lang.php')) 
79                     require_once($directory . $files['class'] . '.en_us.lang.php');
80
81                 // try to translate the string
82                 if(empty($dashletStrings[$files['class']][$dashletMeta[$files['class']]['title']]))
83                     $title = $dashletMeta[$files['class']]['title'];
84                 else 
85                     $title = $dashletStrings[$files['class']][$dashletMeta[$files['class']]['title']];
86                 
87                 // try to translate the string
88                 if(empty($dashletStrings[$files['class']][$dashletMeta[$files['class']]['description']]))
89                     $description = $dashletMeta[$files['class']]['description']; 
90                 else 
91                     $description = $dashletStrings[$files['class']][$dashletMeta[$files['class']]['description']];
92                                 
93                                 // generate icon
94                 if (!empty($dashletMeta[$files['class']]['icon'])) {
95                     // here we'll support image inheritance if the supplied image has a path in it
96                     // i.e. $dashletMeta[$files['class']]['icon'] = 'themes/default/images/dog.gif'
97                     // in this case, we'll strip off the path information to check for the image existing
98                     // in the current theme.
99                    
100                     $imageName = SugarThemeRegistry::current()->getImageURL(basename($dashletMeta[$files['class']]['icon']), false);
101                     if ( !empty($imageName) ) {
102                         if (sugar_is_file($imageName))
103                             $icon = '<img src="' . $imageName .'" alt="" border="0" align="absmiddle" />';  //leaving alt tag blank on purpose for 508
104                         else
105                             $icon = '';
106                     }
107                 }
108                 else{
109                         if (empty($dashletMeta[$files['class']]['module'])){
110                                 $icon = get_dashlets_dialog_icon('default');
111                         }
112                                         else{
113                                                 if((!in_array($dashletMeta[$files['class']]['module'], $GLOBALS['moduleList']) && !in_array($dashletMeta[$files['class']]['module'], $GLOBALS['modInvisList'])) && (!in_array('Activities', $GLOBALS['moduleList']))){
114                                                         unset($dashletMeta[$files['class']]);
115                                                         continue;
116                                                 }else{
117                                 $icon = get_dashlets_dialog_icon($dashletMeta[$files['class']]['module']);
118                                                 }
119                         }
120                 }
121                 
122                 // determine whether to display
123                 if (!empty($dashletMeta[$files['class']]['hidden']) && $dashletMeta[$files['class']]['hidden'] === true){
124                         $displayDashlet = false;
125                 }
126                                 //co: fixes 20398 to respect ACL permissions
127                                 elseif(!empty($dashletMeta[$files['class']]['module']) && (!in_array($dashletMeta[$files['class']]['module'], $GLOBALS['moduleList']) && !in_array($dashletMeta[$files['class']]['module'], $GLOBALS['modInvisList'])) && (!in_array('Activities', $GLOBALS['moduleList']))){
128                         $displayDashlet = false;
129                 }
130                                 else{
131                         $displayDashlet = true;
132                         //check ACL ACCESS
133                         if(!empty($dashletMeta[$files['class']]['module']) && ACLController::moduleSupportsACL($dashletMeta[$files['class']]['module'])){
134                                 $type = 'module';
135                                 if($dashletMeta[$files['class']]['module'] == 'Trackers')
136                                         $type = 'Tracker';
137                                 if(!ACLController::checkAccess($dashletMeta[$files['class']]['module'], 'view', true, $type)){
138                                         $displayDashlet = false;
139                                 }
140                                 if(!ACLController::checkAccess($dashletMeta[$files['class']]['module'], 'list', true, $type)){
141                                         $displayDashlet = false;
142                                 }
143                         }
144                 }
145                                                 
146                 if ($dashletMeta[$files['class']]['category'] == 'Charts'){
147                         $type = 'predefined_chart';
148                 }
149                 else{
150                         $type = 'module';
151                 }
152                 
153                 if ($displayDashlet && isset($dashletMeta[$files['class']]['dynamic_hide']) && $dashletMeta[$files['class']]['dynamic_hide']){
154                     if ( file_exists($files['file']) ) {
155                         require_once($files['file']);
156                         if ( class_exists($files['class']) ) {
157                             $dashletClassName = $files['class'];
158                             $displayDashlet = call_user_func(array($files['class'],'shouldDisplay'));
159                         }
160                     }
161                 }
162                         
163                 if ($displayDashlet){    
164                                         $cell = array( 'title' => $title,
165                                                                    'description' => $description,
166                                                                    'onclick' => 'return SUGAR.mySugar.addDashlet(\'' . $className . '\', \'' . $type . '\', \''.(!empty($dashletMeta[$files['class']]['module']) ? $dashletMeta[$files['class']]['module'] : '' ) .'\');',
167                                    'icon' => $icon,
168                                    'id' => $files['class'] . '_select',
169                                );
170
171                         if (!empty($category) && $dashletMeta[$files['class']]['category'] == $categories[$category]){
172                                 array_push($dashletsList[$categories[$category]], $cell);
173                         }
174                         else if (empty($category)){
175                                                 array_push($dashletsList[$dashletMeta[$files['class']]['category']], $cell);
176                         }
177                 }
178             }
179         }
180         if (!empty($category)){
181                 asort($dashletsList[$categories[$category]]);
182         }
183         else{
184                 foreach($dashletsList as $key=>$value){
185                         asort($dashletsList[$key]);
186                 }
187         }
188         $this->dashlets = $dashletsList;        
189     }
190         
191 }
192
193 ?>