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 ********************************************************************************/
46 * Title of the Dashlet
49 var $title = 'Generic Dashlet';
51 * true if the Dashlet has configuration options.
54 var $isConfigurable = false;
56 * true if the Dashlet is refreshable (ie charts that provide their own refresh)
59 var $isRefreshable = true;
61 * true if the Dashlet contains javascript
64 var $hasScript = false;
66 * Language strings, must be loaded at the Dashlet level w/ loadLanguage
71 function Dashlet($id) {
75 function setConfigureIcon(){
78 if($this->isConfigurable)
79 $additionalTitle = '<td nowrap width="1%" style="padding-right: 0px;"><div class="dashletToolSet"><a href="#" onclick="SUGAR.mySugar.configureDashlet(\''
80 . $this->id . '\'); return false;">'
81 . SugarThemeRegistry::current()->getImage('dashlet-header-edit','title="' . translate('LBL_DASHLET_EDIT', 'Home') . '" alt="' . translate('LBL_DASHLET_EDIT', 'Home') . '" border="0" align="absmiddle"').'</a>'
84 $additionalTitle = '<td nowrap width="1%" style="padding-right: 0px;"><div class="dashletToolSet">';
86 return $additionalTitle;
89 function setRefreshIcon(){
92 $additionalTitle = '';
93 if($this->isRefreshable)
94 $additionalTitle .= '<a href="#" onclick="SUGAR.mySugar.retrieveDashlet(\''
95 . $this->id . '\'); return false;">'
96 . SugarThemeRegistry::current()->getImage('dashlet-header-refresh','border="0" align="absmiddle" title="' . translate('LBL_DASHLET_REFRESH', 'Home') . '" alt="' . translate('LBL_DASHLET_REFRESH', 'Home') . '"')
98 return $additionalTitle;
101 function setDeleteIcon(){
102 global $image_path, $sugar_config, $current_user;
103 if (!empty($sugar_config['lock_homepage']) && $sugar_config['lock_homepage'] == true)
104 return '</div></td></tr></table>';
105 $additionalTitle = '';
106 $additionalTitle .= '<a href="#" onclick="SUGAR.mySugar.deleteDashlet(\''
107 . $this->id . '\'); return false;">'
108 . SugarThemeRegistry::current()->getImage('dashlet-header-close','border="0" align="absmiddle" title="' . translate('LBL_DASHLET_DELETE', 'Home') . '" alt="' . translate('LBL_DASHLET_DELETE', 'Home') . '"')
109 . '</a></div></td></tr></table>';
110 return $additionalTitle;
113 // No longer needed, replaced with getHeader/getFooter
114 function getTitle($text = '') {
119 * Called when Dashlet is displayed
121 * @param string $text text after the title
122 * @return string Header html
124 function getHeader($text = '') {
125 global $app_strings, $sugar_config;
127 $title = '<table width="100%" cellspacing="0" cellpadding="0" border="0"><tr><td width="99%">' . $text . '</td>';
128 $title .= $this->setConfigureIcon();
129 $title .= $this->setRefreshIcon();
130 $title .= $this->setDeleteIcon();
132 if(!function_exists('get_form_header')) {
138 if(empty($sugar_config['lock_homepage']) || $sugar_config['lock_homepage'] == false) $str .= ' onmouseover="this.style.cursor = \'move\';"';
139 $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">';
145 * Called when Dashlet is displayed
147 * @param string $text text after the title
148 * @return string footer html
150 function getFooter($text = '') {
151 //$footer = '</div>';
153 $footer = '</div><div class="mr"></div></div><div class="ft"><div class="bl"></div><div class="ft-center"></div><div class="br"></div></div>';
158 * Called when Dashlet is displayed, override this
160 * @param string $text text after the title
161 * @return string title html
163 function display($text = '') {
168 * Called when Dashlets configuration options are called
171 function displayOptions() {
175 * override if you need to do pre-processing before display is called
185 * Override this if your dashlet is configurable (this is called when the the configureDashlet form is shown)
186 * Filters the array for only the parameters it needs to save
188 * @param array $req the array to pull options from
190 * @return array options array
192 function saveOptions($req) {
196 * Sets the language strings
198 * @param string $dashletClassname classname of the dashlet
201 function loadLanguage($dashletClassname, $dashletDirectory = 'modules/Home/Dashlets/') {
202 global $current_language, $dashletStrings;
204 if(!isset($dashletStrings[$dashletClassname])) {
205 // load current language strings for current language, else default to english
206 if(is_file($dashletDirectory . $dashletClassname . '/' . $dashletClassname . '.' . $current_language . '.lang.php')
207 || is_file('custom/' . $dashletDirectory . $dashletClassname . '/' . $dashletClassname . '.' . $current_language . '.lang.php') ) {
208 if(is_file($dashletDirectory . $dashletClassname . '/' . $dashletClassname . '.' . $current_language . '.lang.php')) {
209 require($dashletDirectory . $dashletClassname . '/' . $dashletClassname . '.' . $current_language . '.lang.php');
211 if(is_file('custom/' . $dashletDirectory . $dashletClassname . '/' . $dashletClassname . '.' . $current_language . '.lang.php')) {
212 require('custom/' . $dashletDirectory . $dashletClassname . '/' . $dashletClassname . '.' . $current_language . '.lang.php');
216 if(is_file($dashletDirectory . $dashletClassname . '/' . $dashletClassname . '.en_us.lang.php')) {
217 require($dashletDirectory . $dashletClassname . '/' . $dashletClassname . '.en_us.lang.php');
219 if(is_file('custom/' . $dashletDirectory . $dashletClassname . '/' . $dashletClassname . '.en_us.lang.php')) {
220 require('custom/' . $dashletDirectory . $dashletClassname . '/' . $dashletClassname . '.en_us.lang.php');
225 $this->dashletStrings = $dashletStrings[$dashletClassname];
229 * Generic way to store an options array into UserPreferences
231 * @param array $optionsArray the array to save
233 function storeOptions($optionsArray) {
234 global $current_user;
235 $dashletDefs = $current_user->getPreference('dashlets', 'Home'); // load user's dashlets config
236 $dashletDefs[$this->id]['options'] = $optionsArray;
237 $current_user->setPreference('dashlets', $dashletDefs, 0, 'Home');
241 * Generic way to retrieve options array from UserPreferences
243 * @return array options array stored in UserPreferences
245 function loadOptions() {
246 global $current_user;
247 $dashletDefs = $current_user->getPreference('dashlets', 'Home'); // load user's dashlets config
248 if(isset($dashletDefs[$this->id]['options']))
249 return $dashletDefs[$this->id]['options'];
255 * Override this in the subclass. It is used to determine whether the dashlet can be displayed.
257 * @return bool indicating whether or not the current user has access to display this Dashlet.
259 function hasAccess(){