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.
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 ********************************************************************************/
38 require_once('include/Dashlets/Dashlet.php');
39 require_once('include/generic/LayoutManager.php');
41 abstract class DashletGenericChart extends Dashlet
44 * The title of the dashlet
50 * @see Dashlet::$isConfigurable
52 public $isConfigurable = true;
55 * @see Dashlet::$isRefreshable
57 public $isRefreshable = true;
60 * location of smarty template file for configuring
63 protected $_configureTpl = 'include/Dashlets/DashletGenericChartConfigure.tpl';
66 * Bean file used in this Dashlet
72 * Module used in this Dashlet
78 * Array of fields and thier defintions that we are searching on
81 protected $_searchFields;
84 * smarty object for the generic configuration template
87 private $_configureSS;
94 * @param array $options
96 public function __construct(
101 parent::Dashlet($id);
103 if ( isset($options) ) {
104 foreach ( $options as $key => $value ) {
105 $this->$key = $value;
110 $classname = get_class($this);
111 if ( is_file("modules/Charts/Dashlets/$classname/$classname.data.php") ) {
112 require("modules/Charts/Dashlets/$classname/$classname.data.php");
113 $this->_searchFields = $dashletData[$classname]['searchFields'];
116 // load language files
117 $this->loadLanguage($classname, 'modules/Charts/Dashlets/');
119 if ( empty($options['title']) )
120 $this->title = $this->dashletStrings['LBL_TITLE'];
122 $this->layoutManager = new LayoutManager();
123 $this->layoutManager->setAttribute('context', 'Report');
124 // fake a reporter object here just to pass along the db type used in many widgets.
125 // this should be taken out when sugarwidgets change
126 $temp = (object) array('db' => &$GLOBALS['db'], 'report_def_str' => '');
127 $this->layoutManager->setAttributePtr('reporter', $temp);
130 public function setRefreshIcon()
132 $additionalTitle = '';
133 if($this->isRefreshable)
134 $additionalTitle .= '<a href="#" onclick="SUGAR.mySugar.retrieveDashlet(\''
135 . $this->id . '\',\'predefined_chart\'); return false;"><img border="0" align="absmiddle" title="' . translate('LBL_DASHLET_REFRESH', 'Home') . '" alt="' . translate('LBL_DASHLET_REFRESH', 'Home') . '" src="'
136 . SugarThemeRegistry::current()->getImageURL('dashlet-header-refresh.png').'"/></a>';
137 return $additionalTitle;
141 * Displays the javascript for the dashlet
143 * @return string javascript to use with this dashlet
145 public function displayScript()
147 global $sugar_config, $current_user, $current_language;
149 $xmlFile = $sugar_config['tmp_dir']. $current_user->id . '_' . $this->id . '.xml';
150 $chartStringsXML = $GLOBALS['sugar_config']['tmp_dir'].'chart_strings.' . $current_language .'.lang.xml';
152 $ss = new Sugar_Smarty();
153 $ss->assign('chartName', $this->id);
154 $ss->assign('chartXMLFile', $xmlFile);
156 $ss->assign('chartStyleCSS', SugarThemeRegistry::current()->getCSSURL('chart.css'));
157 $ss->assign('chartColorsXML', SugarThemeRegistry::current()->getImageURL('sugarColors.xml'));
158 $ss->assign('chartStringsXML', $chartStringsXML);
160 $str = $ss->fetch('include/Dashlets/DashletGenericChartScript.tpl');
165 * Gets the smarty object for the config window. Designed to allow lazy loading the object
168 protected function getConfigureSmartyInstance()
170 if ( !($this->_configureSS instanceof Sugar_Smarty) ) {
172 $this->_configureSS = new Sugar_Smarty();
175 return $this->_configureSS;
179 * Saves the chart config options
180 * Filter the $_REQUEST and only save only the needed options
185 public function saveOptions(
193 foreach($req as $name => $value)
194 if(!is_array($value)) $req[$name] = trim($value);
196 foreach($this->_searchFields as $name => $params) {
197 $widgetDef = $params;
198 if ( isset($this->getSeedBean()->field_defs[$name]) )
199 $widgetDef = $this->getSeedBean()->field_defs[$name];
200 if ( $widgetDef['type'] == 'date') // special case date types
201 $options[$widgetDef['name']] = $timedate->swap_formats($req['type_'.$widgetDef['name']], $timedate->get_date_format(), $timedate->dbDayFormat);
202 elseif ( $widgetDef['type'] == 'time') // special case time types
203 $options[$widgetDef['name']] = $timedate->swap_formats($req['type_'.$widgetDef['name']], $timedate->get_time_format(), $timedate->dbTimeFormat);
204 elseif ( $widgetDef['type'] == 'datepicker') // special case datepicker types
205 $options[$widgetDef['name']] = $timedate->swap_formats($req[$widgetDef['name']], $timedate->get_date_format(), $timedate->dbDayFormat);
206 elseif (!empty($req[$widgetDef['name']]))
207 $options[$widgetDef['name']] = $req[$widgetDef['name']];
210 if (!empty($req['dashletTitle']))
211 $options['title'] = $req['dashletTitle'];
217 * Handles displaying the chart dashlet configuration popup window
219 * @return string HTML to return to the browser
221 public function displayOptions()
223 $currentSearchFields = array();
225 if ( is_array($this->_searchFields) ) {
226 foreach($this->_searchFields as $name=>$params) {
228 $name = strtolower($name);
229 $currentSearchFields[$name] = array();
231 $widgetDef = $params;
232 if ( isset($this->getSeedBean()->field_defs[$name]) )
233 $widgetDef = $this->getSeedBean()->field_defs[$name];
235 if($widgetDef['type'] == 'enum' || $widgetDef['type'] == 'singleenum') $widgetDef['remove_blank'] = true; // remove the blank option for the dropdown
237 if ( empty($widgetDef['input_name0']) )
238 $widgetDef['input_name0'] = empty($this->$name) ? '' : $this->$name;
239 $currentSearchFields[$name]['label'] = translate($widgetDef['vname'], $this->getSeedBean()->module_dir);
240 if ( $currentSearchFields[$name]['label'] == $widgetDef['vname'] )
241 $currentSearchFields[$name]['label'] = translate($widgetDef['vname'], 'Charts');
242 $currentSearchFields[$name]['input'] = $this->layoutManager->widgetDisplayInput($widgetDef, true, (empty($this->$name) ? '' : $this->$name));
244 else { // ability to create spacers in input fields
245 $currentSearchFields['blank' + $count]['label'] = '';
246 $currentSearchFields['blank' + $count]['input'] = '';
251 $this->currentSearchFields = $currentSearchFields;
252 $this->getConfigureSmartyInstance()->assign('title',translate('LBL_TITLE','Charts'));
253 $this->getConfigureSmartyInstance()->assign('save',$GLOBALS['app_strings']['LBL_SAVE_BUTTON_LABEL']);
254 $this->getConfigureSmartyInstance()->assign('id', $this->id);
255 $this->getConfigureSmartyInstance()->assign('searchFields', $this->currentSearchFields);
256 $this->getConfigureSmartyInstance()->assign('dashletTitle', $this->title);
257 $this->getConfigureSmartyInstance()->assign('dashletType', 'predefined_chart');
258 $this->getConfigureSmartyInstance()->assign('module', $_REQUEST['module']);
260 return parent::displayOptions() . $this->getConfigureSmartyInstance()->fetch($this->_configureTpl);
264 * Returns the DashletGenericChart::_seedBean object. Designed to allow lazy loading the object
269 protected function getSeedBean()
271 if ( !($this->_seedBean instanceof $this->_seedName) )
272 $this->_seedBean = loadBean($this->_seedName);
274 return $this->_seedBean;
278 * Returns the built query read to feed into SugarChart::getData()
280 * @return string SQL query
282 protected function constructQuery()
288 * Returns the array of group by parameters for SugarChart::$group_by
290 * @return string SQL query
292 protected function constructGroupBy()