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/Sugar_Smarty.php');
39 require_once('include/utils/layout_utils.php');
49 * Title of the Dashlet
52 var $title = 'Generic Dashlet';
54 * true if the Dashlet has configuration options.
57 var $isConfigurable = false;
59 * true if the Dashlet is refreshable (ie charts that provide their own refresh)
62 var $isRefreshable = true;
64 * true if the Dashlet contains javascript
67 var $hasScript = false;
69 * Language strings, must be loaded at the Dashlet level w/ loadLanguage
74 * Time period in minutes to refresh the dashlet (0 for never)
75 * Do not refresh if $isRefreshable is set to false
77 * To support auto refresh all refreshable dashlets that override process() must call processAutoRefresh()
80 var $autoRefresh = "0";
87 public function Dashlet($id)
93 * Returns the HTML for the configure icon
97 public function setConfigureIcon()
99 if($this->isConfigurable) {
100 $additionalTitle = '<td nowrap width="1%" style="padding-right: 0px;"><div class="dashletToolSet"><a href="javascript:void(0)" onclick="SUGAR.mySugar.configureDashlet(\''
101 . $this->id . '\'); return false;">'
102 . SugarThemeRegistry::current()->getImage('dashlet-header-edit','title="' . translate('LBL_DASHLET_EDIT', 'Home') . '" alt="' . translate('LBL_DASHLET_EDIT', 'Home') . '" border="0" align="absmiddle"').'</a>'
106 $additionalTitle = '<td nowrap width="1%" style="padding-right: 0px;"><div class="dashletToolSet">';
109 return $additionalTitle;
113 * Returns the HTML for the refresh icon
115 * @return string HTML
117 public function setRefreshIcon()
119 $additionalTitle = '';
120 if($this->isRefreshable) {
121 $additionalTitle .= '<a href="javascript:void(0)" onclick="SUGAR.mySugar.retrieveDashlet(\''
122 . $this->id . '\'); return false;">'
123 . SugarThemeRegistry::current()->getImage('dashlet-header-refresh','border="0" align="absmiddle" title="' . translate('LBL_DASHLET_REFRESH', 'Home') . '" alt="' . translate('LBL_DASHLET_REFRESH', 'Home') . '"')
127 return $additionalTitle;
131 * Returns the HTML for the delete icon
133 * @return string HTML
135 public function setDeleteIcon()
137 global $sugar_config;
139 if (!empty($sugar_config['lock_homepage']) && $sugar_config['lock_homepage'] == true) {
140 return '</div></td></tr></table>';
142 $additionalTitle = '<a href="javascript:void(0)" onclick="SUGAR.mySugar.deleteDashlet(\''
143 . $this->id . '\'); return false;">'
144 . SugarThemeRegistry::current()->getImage('dashlet-header-close','border="0" align="absmiddle" title="' . translate('LBL_DASHLET_DELETE', 'Home') . '" alt="' . translate('LBL_DASHLET_DELETE', 'Home') . '"')
145 . '</a></div></td></tr></table>';
146 return $additionalTitle;
150 * @deprecated No longer needed, replaced with Dashlet::getHeader() and Dashlet::getFooter()
152 * @param string $text
153 * @return string HTML
155 public function getTitle($text = '')
161 * Called when Dashlet is displayed
163 * @param string $text text after the title
164 * @return string Header html
166 public function getHeader($text = '')
168 global $sugar_config;
170 $title = '<table width="100%" cellspacing="0" cellpadding="0" border="0"><tr><td width="99%">' . $text . '</td>';
171 $title .= $this->setConfigureIcon();
172 $title .= $this->setRefreshIcon();
173 $title .= $this->setDeleteIcon();
176 if(empty($sugar_config['lock_homepage']) || $sugar_config['lock_homepage'] == false) $str .= 'onmouseover="this.style.cursor = \'move\';" ';
177 $str .= 'id="dashlet_header_' . $this->id . '" class="hd"><div class="tl"></div><div class="hd-center">' . get_form_header($this->title, $title, false) . '</div><div class="tr"></div></div><div class="bd"><div class="ml"></div><div class="bd-center">';
183 * Called when Dashlet is displayed
185 * @return string footer HTML
187 public function getFooter()
189 $footer = '</div><div class="mr"></div></div><div class="ft"><div class="bl"></div><div class="ft-center"></div><div class="br"></div></div>';
195 * Called when Dashlet is displayed, override this
197 * @param string $text text after the title
198 * @return string title HTML
200 public function display($text = '')
206 * Called when Dashlets configuration options are called
208 public function displayOptions()
213 * Override if you need to do pre-processing before display is called
215 public function process()
220 * Processes and displays the auto refresh code for the dashlet
222 * @param int $dashletOffset
223 * @return string HTML code
225 protected function processAutoRefresh($dashletOffset = 0)
227 global $sugar_config;
229 if ( empty($dashletOffset) ) {
231 $module = $_REQUEST['module'];
232 if(isset($_REQUEST[$module.'2_'.strtoupper($this->seedBean->object_name).'_offset'])) {
233 $dashletOffset = $_REQUEST[$module.'2_'.strtoupper($this->seedBean->object_name).'_offset'];
237 if ( !$this->isRefreshable ) {
240 if ( !empty($sugar_config['dashlet_auto_refresh_min']) && $sugar_config['dashlet_auto_refresh_min'] == -1 ) {
243 $autoRefreshSS = new Sugar_Smarty();
244 $autoRefreshSS->assign('dashletOffset', $dashletOffset);
245 $autoRefreshSS->assign('dashletId', $this->id);
246 $autoRefreshSS->assign('strippedDashletId', str_replace("-","",$this->id)); //javascript doesn't like "-" in function names
247 if ( empty($this->autoRefresh) ) {
248 $this->autoRefresh = 0;
250 elseif ( !empty($sugar_config['dashlet_auto_refresh_min']) ) {
251 $this->autoRefresh = min($sugar_config['dashlet_auto_refresh_min'],$this->autoRefresh);
253 $autoRefreshSS->assign('dashletRefreshInterval', $this->autoRefresh * 1000);
254 $tpl = 'include/Dashlets/DashletGenericAutoRefresh.tpl';
255 if ( $_REQUEST['action'] == "DynamicAction" ) {
256 $tpl = 'include/Dashlets/DashletGenericAutoRefreshDynamic.tpl';
259 return $autoRefreshSS->fetch($tpl);
263 * Override this if your dashlet is configurable (this is called when the the configureDashlet form is shown)
264 * Filters the array for only the parameters it needs to save
266 * @param array $req the array to pull options from
267 * @return array options array
269 public function saveOptions($req)
274 * Sets the language strings
276 * @param string $dashletClassname classname of the dashlet
277 * @param string $dashletDirectory directory path of the dashlet
279 public function loadLanguage($dashletClassname, $dashletDirectory = 'modules/Home/Dashlets/')
281 global $current_language, $dashletStrings;
283 if(!isset($dashletStrings[$dashletClassname])) {
284 // load current language strings for current language, else default to english
285 if(is_file($dashletDirectory . $dashletClassname . '/' . $dashletClassname . '.' . $current_language . '.lang.php')
286 || is_file('custom/' . $dashletDirectory . $dashletClassname . '/' . $dashletClassname . '.' . $current_language . '.lang.php') ) {
287 if(is_file($dashletDirectory . $dashletClassname . '/' . $dashletClassname . '.' . $current_language . '.lang.php')) {
288 require($dashletDirectory . $dashletClassname . '/' . $dashletClassname . '.' . $current_language . '.lang.php');
290 if(is_file('custom/' . $dashletDirectory . $dashletClassname . '/' . $dashletClassname . '.' . $current_language . '.lang.php')) {
291 require('custom/' . $dashletDirectory . $dashletClassname . '/' . $dashletClassname . '.' . $current_language . '.lang.php');
295 if(is_file($dashletDirectory . $dashletClassname . '/' . $dashletClassname . '.en_us.lang.php')) {
296 require($dashletDirectory . $dashletClassname . '/' . $dashletClassname . '.en_us.lang.php');
298 if(is_file('custom/' . $dashletDirectory . $dashletClassname . '/' . $dashletClassname . '.en_us.lang.php')) {
299 require('custom/' . $dashletDirectory . $dashletClassname . '/' . $dashletClassname . '.en_us.lang.php');
304 $this->dashletStrings = $dashletStrings[$dashletClassname];
308 * Generic way to store an options array into UserPreferences
310 * @param array $optionsArray the array to save
312 public function storeOptions($optionsArray)
314 global $current_user;
316 $dashletDefs = $current_user->getPreference('dashlets', 'Home'); // load user's dashlets config
317 $dashletDefs[$this->id]['options'] = $optionsArray;
318 $current_user->setPreference('dashlets', $dashletDefs, 0, 'Home');
322 * Generic way to retrieve options array from UserPreferences
324 * @return array options array stored in UserPreferences
326 public function loadOptions()
328 global $current_user;
330 $dashletDefs = $current_user->getPreference('dashlets', 'Home'); // load user's dashlets config
331 if(isset($dashletDefs[$this->id]['options']))
332 return $dashletDefs[$this->id]['options'];
338 * Override this in the subclass. It is used to determine whether the dashlet can be displayed.
340 * @return bool indicating whether or not the current user has access to display this Dashlet.
342 public function hasAccess()
348 * Returns the available auto refresh settings you can set a dashlet to
350 * @return array options available
352 protected function getAutoRefreshOptions()
354 $options = $GLOBALS['app_list_strings']['dashlet_auto_refresh_options'];
356 if ( isset($GLOBALS['sugar_config']['dashlet_auto_refresh_min']) ) {
357 foreach ( $options as $time => $desc ) {
358 if ( $time != -1 && $time < $GLOBALS['sugar_config']['dashlet_auto_refresh_min'] ) {
359 unset($options[$time]);
368 * Returns true if the dashlet is auto refreshable
372 protected function isAutoRefreshable()
374 return $this->isRefreshable &&
375 ( isset($GLOBALS['sugar_config']['dashlet_auto_refresh_min']) ?
376 $GLOBALS['sugar_config']['dashlet_auto_refresh_min'] != -1 : true );