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 ********************************************************************************/
39 require_once('include/Dashlets/Dashlet.php');
42 class ChartsDashlet extends Dashlet {
50 * @global string current language
51 * @param guid $id id for the current dashlet (assigned from Home module)
52 * @param report_id $report_id id of the saved report
53 * @param array $def options saved for this dashlet
55 function ChartsDashlet($id, $report_id, $def) {
56 $this->report_id = $report_id;
58 $this->loadLanguage('ChartsDashlet'); // load the language strings here
60 parent::Dashlet($id); // call parent constructor
62 $this->searchFields = array();
63 $this->isConfigurable = true; // dashlet is configurable
64 $this->hasScript = true; // dashlet has javascript attached to it
68 * Displays the dashlet
70 * @return string html to display dashlet
73 require_once("modules/Reports/Report.php");
76 // ini_set('display_errors', 'false');
78 $chartReport = new SavedReport();
79 $chartExists = $chartReport->retrieve($this->report_id, false);
81 if (!is_null($chartExists)){
82 $this->title = $chartReport->name;
84 $reporter = new Report($chartReport->content);
85 $reporter->is_saved_report = true;
86 $reporter->saved_report_id = $chartReport->id;
87 $reporter->get_total_header_row();
88 $reporter->run_chart_queries();
90 require_once("modules/Reports/templates/templates_chart.php");
93 template_chart($reporter, true, true, $this->id);
94 $str = ob_get_contents();
97 $xmlFile = get_cache_file_name($reporter);
99 $html = parent::display() . "<div align='center'>" . $str . "</div>" . "<br />"; // return parent::display for title and such
101 $ss = new Sugar_Smarty();
102 $ss->assign('chartName', $this->id);
103 $ss->assign('chartXMLFile', $xmlFile);
104 $script = $ss->fetch('modules/Home/Dashlets/ChartsDashlet/ChartsDashletScript.tpl');
105 $json = getJSONobj();
107 return parent::display() . "<div align='center'>" . $str . "</div>" . "<br />"; // return parent::display for title and such
112 * Displays the javascript for the dashlet
114 * @return string javascript to use with this dashlet
116 function displayScript() {
117 require_once("modules/Reports/Report.php");
120 $chartReport = new SavedReport();
121 $chartExists = $chartReport->retrieve($this->report_id, false);
123 if (!is_null($chartExists)){
124 $this->title = $chartReport->name;
126 require_once("modules/Reports/templates/templates_chart.php");
127 require_once('include/SugarCharts/SugarChartFactory.php');
129 $sugarChart = SugarChartFactory::getInstance();
132 $reporter = new Report($chartReport->content);
133 $reporter->is_saved_report = true;
134 $reporter->saved_report_id = $chartReport->id;
135 $xmlFile = get_cache_file_name($reporter);
137 $str = $sugarChart->getDashletScript($this->id,$xmlFile);
143 * Displays the configuration form for the dashlet
145 * @return string html to display form
147 function displayOptions() {
151 * called to filter out $_REQUEST object when the user submits the configure dropdown
153 * @param array $req $_REQUEST
154 * @return array filtered options to save
156 function saveOptions($req) {
159 function setConfigureIcon(){
162 if($this->isConfigurable)
163 $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">'
164 . 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>'
168 $additionalTitle = '<td nowrap width="1%" style="padding-right: 0px;"><div class="dashletToolSet">';
170 return $additionalTitle;
173 function setRefreshIcon(){
176 $additionalTitle = '';
177 if($this->isRefreshable)
178 $additionalTitle .= '<a href="#" onclick="SUGAR.mySugar.retrieveDashlet(\''
179 . $this->id . '\', \'chart\'); return false;"><!--not_in_theme!--><img border="0" align="absmiddle" title="' . translate('LBL_DASHLET_REFRESH', 'Home') . '" alt="' . translate('LBL_DASHLET_REFRESH', 'Home') . '" src="'
181 . SugarThemeRegistry::current()->getImageURL('dashlet-header-refresh.png') .'" /></a>';
182 return $additionalTitle;