PageRenderTime 28ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/include/MySugar/DashletsDialog/DashletsDialog.php

https://github.com/nerdystudmuffin/dashlet-subpanels
PHP | 261 lines | 122 code | 95 blank | 44 comment | 44 complexity | 3f238e59e5b9909fdea745fbcf547e38 MD5 | raw file
Possible License(s): LGPL-2.1, MPL-2.0-no-copyleft-exception
  1. <?php
  2. if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
  3. /*********************************************************************************
  4. * SugarCRM is a customer relationship management program developed by
  5. * SugarCRM, Inc. Copyright (C) 2004 - 2009 SugarCRM Inc.
  6. *
  7. * This program is free software; you can redistribute it and/or modify it under
  8. * the terms of the GNU 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 General Public License for more
  17. * details.
  18. *
  19. * You should have received a copy of the GNU 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 General Public License version 3.
  30. *
  31. * In accordance with Section 7(b) of the GNU 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. class DashletsDialog {
  38. var $dashlets = array();
  39. function getDashlets($category='') {
  40. global $app_strings, $current_language, $mod_strings;
  41. require_once($GLOBALS['sugar_config']['cache_dir'].'dashlets/dashlets.php');
  42. $categories = array( 'module' => 'Module Views',
  43. 'portal' => 'Portal',
  44. 'charts' => 'Charts',
  45. 'tools' => 'Tools',
  46. 'misc' => 'Miscellaneous' );
  47. $dashletStrings = array();
  48. $dashletsList = array();
  49. if (!empty($category)){
  50. $dashletsList[$categories[$category]] = array();
  51. }
  52. else{
  53. $dashletsList['Module Views'] = array();
  54. $dashletsList['Charts'] = array();
  55. $dashletsList['Tools'] = array();
  56. }
  57. asort($dashletsFiles);
  58. foreach($dashletsFiles as $className => $files) {
  59. if(!empty($files['meta']) && is_file($files['meta'])) {
  60. require_once($files['meta']); // get meta file
  61. $directory = substr($files['meta'], 0, strrpos($files['meta'], '/') + 1);
  62. if(is_file($directory . $files['class'] . '.' . $current_language . '.lang.php'))
  63. require_once($directory . $files['class'] . '.' . $current_language . '.lang.php');
  64. elseif(is_file($directory . $files['class'] . '.en_us.lang.php'))
  65. require_once($directory . $files['class'] . '.en_us.lang.php');
  66. // try to translate the string
  67. if(empty($dashletStrings[$files['class']][$dashletMeta[$files['class']]['title']]))
  68. $title = $dashletMeta[$files['class']]['title'];
  69. else
  70. $title = $dashletStrings[$files['class']][$dashletMeta[$files['class']]['title']];
  71. // try to translate the string
  72. if(empty($dashletStrings[$files['class']][$dashletMeta[$files['class']]['description']]))
  73. $description = $dashletMeta[$files['class']]['description'];
  74. else
  75. $description = $dashletStrings[$files['class']][$dashletMeta[$files['class']]['description']];
  76. // generate icon
  77. if (!empty($dashletMeta[$files['class']]['icon'])) {
  78. // here we'll support image inheritance if the supplied image has a path in it
  79. // i.e. $dashletMeta[$files['class']]['icon'] = 'themes/default/images/dog.gif'
  80. // in this case, we'll strip off the path information to check for the image existing
  81. // in the current theme.
  82. $imageName = SugarThemeRegistry::current()->getImageURL(basename($dashletMeta[$files['class']]['icon']), false);
  83. if ( !empty($imageName) ) {
  84. if (sugar_is_file('custom/'. $imageName))
  85. $icon = '<img src="custom/' . $dashletMeta[$files['class']]['icon'] .'" border="0" align="absmiddle" />';
  86. elseif (sugar_is_file($imageName))
  87. $icon = '<img src="' . $dashletMeta[$files['class']]['icon'] .'" border="0" align="absmiddle" />';
  88. }
  89. }
  90. else{
  91. if (empty($dashletMeta[$files['class']]['module'])){
  92. $icon = get_dashlets_dialog_icon('default');
  93. }
  94. else{
  95. if((!in_array($dashletMeta[$files['class']]['module'], $GLOBALS['moduleList']) && !in_array($dashletMeta[$files['class']]['module'], $GLOBALS['modInvisList'])) && (!in_array('Activities', $GLOBALS['moduleList']) || !in_array($dashletMeta[$files['class']]['module'], $GLOBALS['modInvisListActivities']))){
  96. unset($dashletMeta[$files['class']]);
  97. continue;
  98. }else{
  99. $icon = get_dashlets_dialog_icon($dashletMeta[$files['class']]['module']);
  100. }
  101. }
  102. }
  103. // determine whether to display
  104. if (!empty($dashletMeta[$files['class']]['hidden']) && $dashletMeta[$files['class']]['hidden'] === true){
  105. $displayDashlet = false;
  106. }
  107. //co: fixes 20398 to respect ACL permissions
  108. 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']) || !in_array($dashletMeta[$files['class']]['module'], $GLOBALS['modInvisListActivities']))){
  109. $displayDashlet = false;
  110. }
  111. else{
  112. $displayDashlet = true;
  113. //check ACL ACCESS
  114. if(!empty($dashletMeta[$files['class']]['module']) && ACLController::moduleSupportsACL($dashletMeta[$files['class']]['module'])){
  115. $type = 'module';
  116. if($dashletMeta[$files['class']]['module'] == 'Trackers')
  117. $type = 'Tracker';
  118. if(!ACLController::checkAccess($dashletMeta[$files['class']]['module'], 'view', true, $type)){
  119. $displayDashlet = false;
  120. }
  121. if(!ACLController::checkAccess($dashletMeta[$files['class']]['module'], 'list', true, $type)){
  122. $displayDashlet = false;
  123. }
  124. }
  125. }
  126. if ($dashletMeta[$files['class']]['category'] == 'Charts'){
  127. $type = 'predefined_chart';
  128. }
  129. else{
  130. $type = 'module';
  131. }
  132. if ($displayDashlet && isset($dashletMeta[$files['class']]['dynamic_hide']) && $dashletMeta[$files['class']]['dynamic_hide']){
  133. if ( file_exists($files['file']) ) {
  134. require_once($files['file']);
  135. if ( class_exists($files['class']) ) {
  136. $dashletClassName = $files['class'];
  137. $displayDashlet = call_user_func(array($files['class'],'shouldDisplay'));
  138. }
  139. }
  140. }
  141. if ($displayDashlet){
  142. $cell = array( 'title' => $title,
  143. 'description' => $description,
  144. 'onclick' => 'return SUGAR.mySugar.addDashlet(\'' . $className . '\', \'' . $type . '\', \''.(!empty($dashletMeta[$files['class']]['module']) ? $dashletMeta[$files['class']]['module'] : '' ) .'\');',
  145. 'icon' => $icon, );
  146. if (!empty($category) && $dashletMeta[$files['class']]['category'] == $categories[$category]){
  147. array_push($dashletsList[$categories[$category]], $cell);
  148. }
  149. else if (empty($category)){
  150. array_push($dashletsList[$dashletMeta[$files['class']]['category']], $cell);
  151. }
  152. }
  153. }
  154. }
  155. if (!empty($category)){
  156. asort($dashletsList[$categories[$category]]);
  157. }
  158. else{
  159. foreach($dashletsList as $key=>$value){
  160. asort($dashletsList[$key]);
  161. }
  162. }
  163. $this->dashlets = $dashletsList;
  164. }
  165. }
  166. ?>