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.
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.
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
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
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.
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.
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 ********************************************************************************/
41 class DashletsDialog {
42 var $dashlets = array();
44 function getDashlets($category='') {
45 global $app_strings, $current_language, $mod_strings;
47 require_once($GLOBALS['sugar_config']['cache_dir'].'dashlets/dashlets.php');
49 $categories = array( 'module' => 'Module Views',
53 'misc' => 'Miscellaneous',
56 $dashletStrings = array();
57 $dashletsList = array();
59 if (!empty($category)){
60 $dashletsList[$categories[$category]] = array();
63 $dashletsList['Module Views'] = array();
64 $dashletsList['Charts'] = array();
65 $dashletsList['Tools'] = array();
66 $dashletsList['Web'] = array();
69 asort($dashletsFiles);
71 foreach($dashletsFiles as $className => $files) {
72 if(!empty($files['meta']) && is_file($files['meta'])) {
73 require_once($files['meta']); // get meta file
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');
81 // try to translate the string
82 if(empty($dashletStrings[$files['class']][$dashletMeta[$files['class']]['title']]))
83 $title = $dashletMeta[$files['class']]['title'];
85 $title = $dashletStrings[$files['class']][$dashletMeta[$files['class']]['title']];
87 // try to translate the string
88 if(empty($dashletStrings[$files['class']][$dashletMeta[$files['class']]['description']]))
89 $description = $dashletMeta[$files['class']]['description'];
91 $description = $dashletStrings[$files['class']][$dashletMeta[$files['class']]['description']];
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.
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
109 if (empty($dashletMeta[$files['class']]['module'])){
110 $icon = get_dashlets_dialog_icon('default');
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']]);
117 $icon = get_dashlets_dialog_icon($dashletMeta[$files['class']]['module']);
122 // determine whether to display
123 if (!empty($dashletMeta[$files['class']]['hidden']) && $dashletMeta[$files['class']]['hidden'] === true){
124 $displayDashlet = false;
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;
131 $displayDashlet = true;
133 if(!empty($dashletMeta[$files['class']]['module']) && ACLController::moduleSupportsACL($dashletMeta[$files['class']]['module'])){
135 if($dashletMeta[$files['class']]['module'] == 'Trackers')
137 if(!ACLController::checkAccess($dashletMeta[$files['class']]['module'], 'view', true, $type)){
138 $displayDashlet = false;
140 if(!ACLController::checkAccess($dashletMeta[$files['class']]['module'], 'list', true, $type)){
141 $displayDashlet = false;
146 if ($dashletMeta[$files['class']]['category'] == 'Charts'){
147 $type = 'predefined_chart';
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'));
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'] : '' ) .'\');',
168 'id' => $files['class'] . '_select',
171 if (!empty($category) && $dashletMeta[$files['class']]['category'] == $categories[$category]){
172 array_push($dashletsList[$categories[$category]], $cell);
174 else if (empty($category)){
175 array_push($dashletsList[$dashletMeta[$files['class']]['category']], $cell);
180 if (!empty($category)){
181 asort($dashletsList[$categories[$category]]);
184 foreach($dashletsList as $key=>$value){
185 asort($dashletsList[$key]);
188 $this->dashlets = $dashletsList;