id = $id;
}
/**
* Returns the HTML for the configure icon
*
* @return string HTML
*/
public function setConfigureIcon()
{
if($this->isConfigurable) {
$additionalTitle = '
| ';
return $additionalTitle;
}
/**
* @deprecated No longer needed, replaced with Dashlet::getHeader() and Dashlet::getFooter()
*
* @param string $text
* @return string HTML
*/
public function getTitle($text = '')
{
return '';
}
/**
* Called when Dashlet is displayed
*
* @param string $text text after the title
* @return string Header html
*/
public function getHeader($text = '')
{
global $sugar_config;
$title = '' . $text . ' | ';
$title .= $this->setConfigureIcon();
$title .= $this->setRefreshIcon();
$title .= $this->setDeleteIcon();
$str = 'id . '" class="hd">
' . get_form_header($this->title, $title, false) . '
';
return $str;
}
/**
* Called when Dashlet is displayed
*
* @return string footer HTML
*/
public function getFooter()
{
$footer = '
';
return $footer;
}
/**
* Called when Dashlet is displayed, override this
*
* @param string $text text after the title
* @return string title HTML
*/
public function display($text = '')
{
return '';
}
/**
* Called when Dashlets configuration options are called
*/
public function displayOptions()
{
}
/**
* Override if you need to do pre-processing before display is called
*/
public function process()
{
}
/**
* Processes and displays the auto refresh code for the dashlet
*
* @param int $dashletOffset
* @return string HTML code
*/
protected function processAutoRefresh($dashletOffset = 0)
{
global $sugar_config;
if ( empty($dashletOffset) ) {
$dashletOffset = 0;
$module = $_REQUEST['module'];
if(isset($_REQUEST[$module.'2_'.strtoupper($this->seedBean->object_name).'_offset'])) {
$dashletOffset = $_REQUEST[$module.'2_'.strtoupper($this->seedBean->object_name).'_offset'];
}
}
if ( !$this->isRefreshable ) {
return '';
}
if ( !empty($sugar_config['dashlet_auto_refresh_min']) && $sugar_config['dashlet_auto_refresh_min'] == -1 ) {
return '';
}
$autoRefreshSS = new Sugar_Smarty();
$autoRefreshSS->assign('dashletOffset', $dashletOffset);
$autoRefreshSS->assign('dashletId', $this->id);
$autoRefreshSS->assign('strippedDashletId', str_replace("-","",$this->id)); //javascript doesn't like "-" in function names
if ( empty($this->autoRefresh) ) {
$this->autoRefresh = 0;
}
elseif ( !empty($sugar_config['dashlet_auto_refresh_min']) && $sugar_config['dashlet_auto_refresh_min'] > $this->autoRefresh ) {
$this->autoRefresh = $sugar_config['dashlet_auto_refresh_min'];
}
$autoRefreshSS->assign('dashletRefreshInterval', $this->autoRefresh * 1000);
$tpl = 'include/Dashlets/DashletGenericAutoRefresh.tpl';
if ( $_REQUEST['action'] == "DynamicAction" ) {
$tpl = 'include/Dashlets/DashletGenericAutoRefreshDynamic.tpl';
}
return $autoRefreshSS->fetch($tpl);
}
/**
* Override this if your dashlet is configurable (this is called when the the configureDashlet form is shown)
* Filters the array for only the parameters it needs to save
*
* @param array $req the array to pull options from
* @return array options array
*/
public function saveOptions($req)
{
}
/**
* Sets the language strings
*
* @param string $dashletClassname classname of the dashlet
* @param string $dashletDirectory directory path of the dashlet
*/
public function loadLanguage($dashletClassname, $dashletDirectory = 'modules/Home/Dashlets/')
{
global $current_language, $dashletStrings;
if(!isset($dashletStrings[$dashletClassname])) {
// load current language strings for current language, else default to english
if(is_file($dashletDirectory . $dashletClassname . '/' . $dashletClassname . '.' . $current_language . '.lang.php')
|| is_file('custom/' . $dashletDirectory . $dashletClassname . '/' . $dashletClassname . '.' . $current_language . '.lang.php') ) {
if(is_file($dashletDirectory . $dashletClassname . '/' . $dashletClassname . '.' . $current_language . '.lang.php')) {
require($dashletDirectory . $dashletClassname . '/' . $dashletClassname . '.' . $current_language . '.lang.php');
}
if(is_file('custom/' . $dashletDirectory . $dashletClassname . '/' . $dashletClassname . '.' . $current_language . '.lang.php')) {
require('custom/' . $dashletDirectory . $dashletClassname . '/' . $dashletClassname . '.' . $current_language . '.lang.php');
}
}
else {
if(is_file($dashletDirectory . $dashletClassname . '/' . $dashletClassname . '.en_us.lang.php')) {
require($dashletDirectory . $dashletClassname . '/' . $dashletClassname . '.en_us.lang.php');
}
if(is_file('custom/' . $dashletDirectory . $dashletClassname . '/' . $dashletClassname . '.en_us.lang.php')) {
require('custom/' . $dashletDirectory . $dashletClassname . '/' . $dashletClassname . '.en_us.lang.php');
}
}
}
$this->dashletStrings = $dashletStrings[$dashletClassname];
}
/**
* Generic way to store an options array into UserPreferences
*
* @param array $optionsArray the array to save
*/
public function storeOptions($optionsArray)
{
global $current_user;
$dashletDefs = $current_user->getPreference('dashlets', 'Home'); // load user's dashlets config
$dashletDefs[$this->id]['options'] = $optionsArray;
$current_user->setPreference('dashlets', $dashletDefs, 0, 'Home');
}
/**
* Generic way to retrieve options array from UserPreferences
*
* @return array options array stored in UserPreferences
*/
public function loadOptions()
{
global $current_user;
$dashletDefs = $current_user->getPreference('dashlets', 'Home'); // load user's dashlets config
if(isset($dashletDefs[$this->id]['options']))
return $dashletDefs[$this->id]['options'];
else
return array();
}
/**
* Override this in the subclass. It is used to determine whether the dashlet can be displayed.
*
* @return bool indicating whether or not the current user has access to display this Dashlet.
*/
public function hasAccess()
{
return true;
}
/**
* Returns the available auto refresh settings you can set a dashlet to
*
* @return array options available
*/
protected function getAutoRefreshOptions()
{
$options = $GLOBALS['app_list_strings']['dashlet_auto_refresh_options'];
if ( isset($GLOBALS['sugar_config']['dashlet_auto_refresh_min']) ) {
foreach ( $options as $time => $desc ) {
if ( $time != -1 && $time < $GLOBALS['sugar_config']['dashlet_auto_refresh_min'] ) {
unset($options[$time]);
}
}
}
return $options;
}
/**
* Returns true if the dashlet is auto refreshable
*
* @return bool
*/
protected function isAutoRefreshable()
{
return $this->isRefreshable &&
( isset($GLOBALS['sugar_config']['dashlet_auto_refresh_min']) ?
$GLOBALS['sugar_config']['dashlet_auto_refresh_min'] != -1 : true );
}
}