]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Home/Dashlets/ChartsDashlet/ChartsDashlet.php
Release 6.4.0
[Github/sugarcrm.git] / modules / Home / Dashlets / ChartsDashlet / ChartsDashlet.php
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-2011 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
38
39 require_once('include/Dashlets/Dashlet.php');
40
41
42 class ChartsDashlet extends Dashlet {
43     var $width = '400';
44     var $height = '480';
45     var $report_id;
46
47     /**
48      * Constructor 
49      * 
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
54      */
55     function ChartsDashlet($id, $report_id, $def) {
56         $this->report_id = $report_id;  
57         
58         $this->loadLanguage('ChartsDashlet'); // load the language strings here
59
60         parent::Dashlet($id); // call parent constructor
61
62         $this->searchFields = array();
63         $this->isConfigurable = true; // dashlet is configurable
64         $this->hasScript = true;  // dashlet has javascript attached to it               
65     }
66
67     /**
68      * Displays the dashlet
69      * 
70      * @return string html to display dashlet
71      */
72     function display() {
73         require_once("modules/Reports/Report.php");
74                         
75         
76 //              ini_set('display_errors', 'false');
77                 
78                 $chartReport = new SavedReport();
79                 $chartExists = $chartReport->retrieve($this->report_id, false);
80                 
81                 if (!is_null($chartExists)){
82                 $this->title = $chartReport->name;
83                                 
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();
89                         
90                         require_once("modules/Reports/templates/templates_chart.php");
91         
92                         ob_start();     
93                         template_chart($reporter, true, true, $this->id);
94                         $str = ob_get_contents();       
95                         ob_end_clean();
96                         
97                         $xmlFile = get_cache_file_name($reporter);
98                         
99                         $html = parent::display() . "<div align='center'>" . $str . "</div>" . "<br />"; // return parent::display for title and such
100         
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();
106                         
107                 return parent::display() . "<div align='center'>" . $str . "</div>" . "<br />"; // return parent::display for title and such
108                 }
109     }
110     
111     /**
112      * Displays the javascript for the dashlet
113      * 
114      * @return string javascript to use with this dashlet
115      */
116     function displayScript() {
117         require_once("modules/Reports/Report.php");
118                         
119         
120                 $chartReport = new SavedReport();               
121                 $chartExists = $chartReport->retrieve($this->report_id, false);
122                 
123                 if (!is_null($chartExists)){
124                 $this->title = $chartReport->name;
125                                 
126                         require_once("modules/Reports/templates/templates_chart.php");
127                         require_once('include/SugarCharts/SugarChartFactory.php');
128
129                         $sugarChart = SugarChartFactory::getInstance();
130                 
131                 
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);
136
137                 $str = $sugarChart->getDashletScript($this->id,$xmlFile);
138                 return $str;
139                 }
140     }
141         
142     /**
143      * Displays the configuration form for the dashlet
144      * 
145      * @return string html to display form
146      */
147     function displayOptions() {
148     }  
149
150     /**
151      * called to filter out $_REQUEST object when the user submits the configure dropdown
152      * 
153      * @param array $req $_REQUEST
154      * @return array filtered options to save
155      */  
156     function saveOptions($req) {
157     }
158     
159     function setConfigureIcon(){
160         
161         
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>'
165
166                                . '';
167         else 
168             $additionalTitle = '<td nowrap width="1%" style="padding-right: 0px;"><div class="dashletToolSet">';        
169         
170         return $additionalTitle;
171     }    
172
173     function setRefreshIcon(){
174         
175         
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="' 
180
181                                 . SugarThemeRegistry::current()->getImageURL('dashlet-header-refresh.png') .'" /></a>'; 
182         return $additionalTitle;
183     }
184     
185 }
186
187 ?>