PageRenderTime 44ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/modules/Home/Dashlets/ChartsDashlet/ChartsDashlet.php

https://gitlab.com/tjaafar/SuiteCRM
PHP | 195 lines | 89 code | 39 blank | 67 comment | 7 complexity | cb4d4fffde032dc93a106a37ff276564 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. * SuiteCRM is an extension to SugarCRM Community Edition developed by Salesagility Ltd.
  7. * Copyright (C) 2011 - 2014 Salesagility Ltd.
  8. *
  9. * This program is free software; you can redistribute it and/or modify it under
  10. * the terms of the GNU Affero General Public License version 3 as published by the
  11. * Free Software Foundation with the addition of the following permission added
  12. * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
  13. * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
  14. * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
  15. *
  16. * This program is distributed in the hope that it will be useful, but WITHOUT
  17. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  18. * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
  19. * details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License along with
  22. * this program; if not, see http://www.gnu.org/licenses or write to the Free
  23. * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  24. * 02110-1301 USA.
  25. *
  26. * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
  27. * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
  28. *
  29. * The interactive user interfaces in modified source and object code versions
  30. * of this program must display Appropriate Legal Notices, as required under
  31. * Section 5 of the GNU Affero General Public License version 3.
  32. *
  33. * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
  34. * these Appropriate Legal Notices must retain the display of the "Powered by
  35. * SugarCRM" logo and "Supercharged by SuiteCRM" logo. If the display of the logos is not
  36. * reasonably feasible for technical reasons, the Appropriate Legal Notices must
  37. * display the words "Powered by SugarCRM" and "Supercharged by SuiteCRM".
  38. ********************************************************************************/
  39. require_once('include/Dashlets/Dashlet.php');
  40. class ChartsDashlet extends Dashlet {
  41. var $width = '400';
  42. var $height = '480';
  43. var $report_id;
  44. /**
  45. * Constructor
  46. *
  47. * @global string current language
  48. * @param guid $id id for the current dashlet (assigned from Home module)
  49. * @param report_id $report_id id of the saved report
  50. * @param array $def options saved for this dashlet
  51. */
  52. function ChartsDashlet($id, $report_id, $def) {
  53. $this->report_id = $report_id;
  54. $this->loadLanguage('ChartsDashlet'); // load the language strings here
  55. parent::Dashlet($id); // call parent constructor
  56. $this->searchFields = array();
  57. $this->isConfigurable = true; // dashlet is configurable
  58. $this->hasScript = true; // dashlet has javascript attached to it
  59. }
  60. /**
  61. * Displays the dashlet
  62. *
  63. * @return string html to display dashlet
  64. */
  65. function display() {
  66. require_once("modules/Reports/Report.php");
  67. // ini_set('display_errors', 'false');
  68. $chartReport = new SavedReport();
  69. $chartExists = $chartReport->retrieve($this->report_id, false);
  70. if (!is_null($chartExists)){
  71. $title = getReportNameTranslation($chartReport->name);
  72. $this->title = $title;
  73. $reporter = new Report($chartReport->content);
  74. $reporter->is_saved_report = true;
  75. $reporter->saved_report_id = $chartReport->id;
  76. $reporter->get_total_header_row();
  77. $reporter->run_chart_queries();
  78. require_once("modules/Reports/templates/templates_chart.php");
  79. ob_start();
  80. template_chart($reporter, true, true, $this->id);
  81. $str = ob_get_contents();
  82. ob_end_clean();
  83. $xmlFile = get_cache_file_name($reporter);
  84. $html = parent::display() . "<div align='center'>" . $str . "</div>" . "<br />"; // return parent::display for title and such
  85. $ss = new Sugar_Smarty();
  86. $ss->assign('chartName', $this->id);
  87. $ss->assign('chartXMLFile', $xmlFile);
  88. $script = $ss->fetch('modules/Home/Dashlets/ChartsDashlet/ChartsDashletScript.tpl');
  89. $json = getJSONobj();
  90. return parent::display() . "<div align='center'>" . $str . "</div>" . "<br />"; // return parent::display for title and such
  91. }
  92. }
  93. /**
  94. * Displays the javascript for the dashlet
  95. *
  96. * @return string javascript to use with this dashlet
  97. */
  98. function displayScript() {
  99. require_once("modules/Reports/Report.php");
  100. $chartReport = new SavedReport();
  101. $chartExists = $chartReport->retrieve($this->report_id, false);
  102. if (!is_null($chartExists)){
  103. $this->title = $chartReport->name;
  104. require_once("modules/Reports/templates/templates_chart.php");
  105. require_once('include/SugarCharts/SugarChartFactory.php');
  106. $sugarChart = SugarChartFactory::getInstance();
  107. $reporter = new Report($chartReport->content);
  108. $reporter->is_saved_report = true;
  109. $reporter->saved_report_id = $chartReport->id;
  110. $xmlFile = get_cache_file_name($reporter);
  111. $str = $sugarChart->getDashletScript($this->id,$xmlFile);
  112. return $str;
  113. }
  114. }
  115. /**
  116. * Displays the configuration form for the dashlet
  117. *
  118. * @return string html to display form
  119. */
  120. function displayOptions() {
  121. }
  122. /**
  123. * called to filter out $_REQUEST object when the user submits the configure dropdown
  124. *
  125. * @param array $req $_REQUEST
  126. * @return array filtered options to save
  127. */
  128. function saveOptions($req) {
  129. }
  130. function setConfigureIcon(){
  131. if($this->isConfigurable)
  132. $additionalTitle = '<td nowrap width="1%" style="padding-right: 0px;"><div class="dashletToolSet"><a href="index.php?module=Reports&record=' . $this->report_id . '&action=ReportCriteriaResults&page=report">'
  133. . SugarThemeRegistry::current()->getImage('dashlet-header-edit','title="' . translate('LBL_DASHLET_EDIT', 'Home') . '" border="0" align="absmiddle"', null,null,'.gif',translate('LBL_DASHLET_EDIT', 'Home')).'</a>'
  134. . '';
  135. else
  136. $additionalTitle = '<td nowrap width="1%" style="padding-right: 0px;"><div class="dashletToolSet">';
  137. return $additionalTitle;
  138. }
  139. function setRefreshIcon(){
  140. $additionalTitle = '';
  141. if($this->isRefreshable)
  142. $additionalTitle .= '<a href="#" onclick="SUGAR.mySugar.retrieveDashlet(\''
  143. . $this->id . '\', \'chart\'); return false;"><!--not_in_theme!-->'
  144. . SugarThemeRegistry::current()->getImage(
  145. 'dashlet-header-refresh',
  146. 'border="0" align="absmiddle" title="'. translate('LBL_DASHLET_REFRESH', 'Home') . '"',
  147. null,
  148. null,
  149. '.gif',
  150. translate('LBL_DASHLET_REFRESH', 'Home')
  151. ) .'</a>';
  152. return $additionalTitle;
  153. }
  154. }
  155. ?>