]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/Dashlets/Dashlet.php
Release 6.1.4
[Github/sugarcrm.git] / include / Dashlets / Dashlet.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 class Dashlet {
40    /**
41      * Id of the Dashlet
42      * @var guid
43      */ 
44     var $id; 
45     /**
46      * Title of the Dashlet
47      * @var string
48      */
49     var $title = 'Generic Dashlet';
50     /**
51      * true if the Dashlet has configuration options. 
52      * @var bool
53      */
54     var $isConfigurable = false;
55     /**
56      * true if the Dashlet is refreshable (ie charts that provide their own refresh) 
57      * @var bool
58      */
59     var $isRefreshable = true;
60     /**
61      * true if the Dashlet contains javascript 
62      * @var bool
63      */
64     var $hasScript = false;
65     /**
66      * Language strings, must be loaded at the Dashlet level w/ loadLanguage
67      * @var array
68      */
69     var $dashletStrings;
70     
71     function Dashlet($id) {
72         $this->id = $id;
73     }
74     
75     function setConfigureIcon(){
76         
77         
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>' 
82                                . '';
83         else 
84             $additionalTitle = '<td nowrap width="1%" style="padding-right: 0px;"><div class="dashletToolSet">';        
85         
86         return $additionalTitle;
87     }
88     
89     function setRefreshIcon(){
90         
91         
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') . '"')
97                                 . '</a>';
98         return $additionalTitle;
99     }
100     
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;                                        
111     }
112     
113     // No longer needed, replaced with getHeader/getFooter
114     function getTitle($text = '') {
115         return '';
116     }
117
118     /**
119      * Called when Dashlet is displayed
120      * 
121      * @param string $text text after the title
122      * @return string Header html
123      */
124     function getHeader($text = '') {
125         global $app_strings, $sugar_config;
126         
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();
131             
132         if(!function_exists('get_form_header')) {
133             global $theme;
134             
135         }
136         
137         $str = '<div ';
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">';
140         
141         return $str;
142     }
143
144     /**
145      * Called when Dashlet is displayed
146      * 
147      * @param string $text text after the title
148      * @return string footer html
149      */
150     function getFooter($text = '') {
151         //$footer = '</div>';
152
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>';
154         return $footer;
155     }
156
157     /**
158      * Called when Dashlet is displayed, override this
159      * 
160      * @param string $text text after the title
161      * @return string title html
162      */
163     function display($text = '') {
164         return '';
165     }
166     
167     /**
168      * Called when Dashlets configuration options are called
169      * 
170      */
171     function displayOptions() {
172     }
173     
174     /**
175      * override if you need to do pre-processing before display is called
176      * 
177      */
178     function process() {
179     }    
180     
181     function save() {
182     }
183     
184     /**
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
187      * 
188      * @param array $req the array to pull options from
189      * 
190      * @return array options array
191      */
192     function saveOptions($req) {
193     }
194     
195     /**
196      * Sets the language strings
197      * 
198      * @param string $dashletClassname classname of the dashlet
199      * 
200      */
201     function loadLanguage($dashletClassname, $dashletDirectory = 'modules/Home/Dashlets/') {
202         global $current_language, $dashletStrings;
203         
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');
210                 }
211                 if(is_file('custom/' . $dashletDirectory . $dashletClassname . '/' . $dashletClassname . '.' . $current_language . '.lang.php')) {
212                     require('custom/' . $dashletDirectory . $dashletClassname . '/' . $dashletClassname . '.' . $current_language . '.lang.php');
213                 }
214             }
215             else {
216                 if(is_file($dashletDirectory . $dashletClassname . '/' . $dashletClassname . '.en_us.lang.php')) {
217                     require($dashletDirectory . $dashletClassname . '/' . $dashletClassname . '.en_us.lang.php');
218                 }
219                 if(is_file('custom/' . $dashletDirectory . $dashletClassname . '/' . $dashletClassname . '.en_us.lang.php')) {
220                     require('custom/' . $dashletDirectory . $dashletClassname . '/' . $dashletClassname . '.en_us.lang.php');
221                 }
222             }
223         }
224
225         $this->dashletStrings = $dashletStrings[$dashletClassname];
226     }
227     
228     /**
229      * Generic way to store an options array into UserPreferences
230      * 
231      * @param array $optionsArray the array to save
232      */
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');   
238     }
239     
240     /**
241      * Generic way to retrieve options array from UserPreferences
242      * 
243      * @return array options array stored in UserPreferences
244      */
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'];
250         else 
251             return array();   
252     }
253     
254     /**
255      * Override this in the subclass. It is used to determine whether the dashlet can be displayed.
256      * 
257      * @return bool indicating whether or not the current user has access to display this Dashlet.
258      */
259     function hasAccess(){
260         return true;
261     }
262 }
263 ?>