PageRenderTime 64ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/custom/include/MySugar/DashletsDialog/DashletsDialog.php

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