]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Home/Dashlets/ChartsDashlet/ChartsDashlet.php
Release 6.1.4
[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 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                                 
128                         $reporter = new Report($chartReport->content);
129                         $reporter->is_saved_report = true;
130                         $reporter->saved_report_id = $chartReport->id;
131                         $xmlFile = get_cache_file_name($reporter);
132                         
133                 $ss = new Sugar_Smarty();
134                 $ss->assign('chartName', $this->id);
135                 $ss->assign('chartXMLFile', $xmlFile);
136                 
137                 $ss->assign('chartStyleCSS', SugarThemeRegistry::current()->getCSSURL('chart.css'));
138                 $ss->assign('chartColorsXML', SugarThemeRegistry::current()->getImageURL('sugarColors.xml'));
139                 $ss->assign('chartLangFile', $GLOBALS['sugar_config']['tmp_dir'].'chart_strings.' . $GLOBALS['current_language'] .'.lang.xml');
140                 
141                 $str = $ss->fetch('modules/Home/Dashlets/ChartsDashlet/ChartsDashletScript.tpl');
142                 return $str;
143                 }
144     }
145         
146     /**
147      * Displays the configuration form for the dashlet
148      * 
149      * @return string html to display form
150      */
151     function displayOptions() {
152     }  
153
154     /**
155      * called to filter out $_REQUEST object when the user submits the configure dropdown
156      * 
157      * @param array $req $_REQUEST
158      * @return array filtered options to save
159      */  
160     function saveOptions($req) {
161     }
162     
163     function setConfigureIcon(){
164         
165         
166         if($this->isConfigurable) 
167             $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">'
168                                . SugarThemeRegistry::current()->getImage('dashlet-header-edit','title="' . translate('LBL_DASHLET_EDIT', 'Home') . '" alt="' . translate('LBL_DASHLET_EDIT', 'Home') . '"  border="0"  align="absmiddle"').'</a>' 
169                                . '';
170         else 
171             $additionalTitle = '<td nowrap width="1%" style="padding-right: 0px;"><div class="dashletToolSet">';        
172         
173         return $additionalTitle;
174     }    
175
176     function setRefreshIcon(){
177         
178         
179         $additionalTitle = '';
180         if($this->isRefreshable)
181             $additionalTitle .= '<a href="#" onclick="SUGAR.mySugar.retrieveDashlet(\'' 
182                                 . $this->id . '\', \'chart\'); return false;"><img border="0" align="absmiddle" title="' . translate('LBL_DASHLET_REFRESH', 'Home') . '" alt="' . translate('LBL_DASHLET_REFRESH', 'Home') . '" src="' 
183                                 . SugarThemeRegistry::current()->getImageURL('dashlet-header-refresh.png') .'" /></a>'; 
184         return $additionalTitle;
185     }
186     
187 }
188
189 ?>