2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4 * SugarCRM Community Edition is a customer relationship management program developed by
5 * SugarCRM, Inc. Copyright (C) 2004-2012 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 ********************************************************************************/
39 global $current_user, $sugar_version, $sugar_config, $beanFiles;
42 require_once('include/MySugar/MySugar.php');
44 // build dashlet cache file if not found
45 if(!is_file($cachefile = sugar_cached('dashlets/dashlets.php'))) {
46 require_once('include/Dashlets/DashletCacheBuilder.php');
48 $dc = new DashletCacheBuilder();
51 require_once $cachefile;
53 require('modules/Home/dashlets.php');
55 $pages = $current_user->getPreference('pages', 'Home');
56 $dashlets = $current_user->getPreference('dashlets', 'Home');
58 $defaultHomepage = false;
59 // BEGIN fill in with default homepage and dashlet selections
61 $hasUserPreferences = (!isset($pages) || empty($pages) || !isset($dashlets) || empty($dashlets)) ? false : true;
63 if(!$hasUserPreferences){
66 //list of preferences to move over and to where
68 'mypbss_date_start' => 'MyPipelineBySalesStageDashlet',
69 'mypbss_date_end' => 'MyPipelineBySalesStageDashlet',
70 'mypbss_sales_stages' => 'MyPipelineBySalesStageDashlet',
71 'mypbss_chart_type' => 'MyPipelineBySalesStageDashlet',
72 'lsbo_lead_sources' => 'OpportunitiesByLeadSourceByOutcomeDashlet',
73 'lsbo_ids' => 'OpportunitiesByLeadSourceByOutcomeDashlet',
74 'pbls_lead_sources' => 'OpportunitiesByLeadSourceDashlet',
75 'pbls_ids' => 'OpportunitiesByLeadSourceDashlet',
76 'pbss_date_start' => 'PipelineBySalesStageDashlet',
77 'pbss_date_end' => 'PipelineBySalesStageDashlet',
78 'pbss_sales_stages' => 'PipelineBySalesStageDashlet',
79 'pbss_chart_type' => 'PipelineBySalesStageDashlet',
80 'obm_date_start' => 'OutcomeByMonthDashlet',
81 'obm_date_end' => 'OutcomeByMonthDashlet',
82 'obm_ids' => 'OutcomeByMonthDashlet');
84 //upgrading from pre-5.0 homepage
85 $old_columns = $current_user->getPreference('columns', 'home');
86 $old_dashlets = $current_user->getPreference('dashlets', 'home');
88 if (isset($old_columns) && !empty($old_columns) && isset($old_dashlets) && !empty($old_dashlets)){
89 $columns = $old_columns;
90 $dashlets = $old_dashlets;
92 // resetting old columns and dashlets to have no preference and data
93 $old_columns = array();
94 $old_dashlets = array();
95 $current_user->setPreference('columns', $old_columns, 0, 'home');
96 $current_user->setPreference('dashlets', $old_dashlets, 0, 'home');
99 // This is here to get Sugar dashlets added above the rest
100 $dashlets[create_guid()] = array('className' => 'iFrameDashlet',
103 'fileLocation' => $dashletsFiles['iFrameDashlet']['file'],
104 'options' => array('title' => translate('LBL_DASHLET_DISCOVER_SUGAR_PRO','Home'),
105 'url' => 'http://www.sugarcrm.com/crm/product/gopro',
109 $dashlets[create_guid()] = array ('className' => 'SugarFeedDashlet',
110 'module' => 'SugarFeed',
112 'fileLocation' => $dashletsFiles['SugarFeedDashlet']['file'],
115 $dashlets[create_guid()] = array('className' => 'iFrameDashlet',
118 'fileLocation' => $dashletsFiles['iFrameDashlet']['file'],
119 'options' => array('title' => translate('LBL_DASHLET_SUGAR_NEWS','Home'),
120 'url' => 'http://www.sugarcrm.com/crm/product/news',
124 foreach($defaultDashlets as $dashletName=>$module){
125 // clint - fixes bug #20398
126 // only display dashlets that are from visibile modules and that the user has permission to list
127 $myDashlet = new MySugar($module);
128 $displayDashlet = $myDashlet->checkDashletDisplay();
129 if (isset($dashletsFiles[$dashletName]) && $displayDashlet){
131 $prefsforthisdashlet = array_keys($prefstomove,$dashletName);
132 foreach ( $prefsforthisdashlet as $pref ) {
133 $options[$pref] = $current_user->getPreference($pref);
135 $dashlets[create_guid()] = array('className' => $dashletName,
138 'fileLocation' => $dashletsFiles[$dashletName]['file'],
139 'options' => $options);
145 $columns[0] = array();
146 $columns[0]['width'] = '60%';
147 $columns[0]['dashlets'] = array();
148 $columns[1] = array();
149 $columns[1]['width'] = '40%';
150 $columns[1]['dashlets'] = array();
152 foreach($dashlets as $guid=>$dashlet) {
153 if( $dashlet['forceColumn'] == 0 ) array_push($columns[0]['dashlets'], $guid);
154 else array_push($columns[1]['dashlets'], $guid);
162 $current_user->setPreference('dashlets', $dashlets, 0, 'Home');
165 // handles upgrading from versions that had the 'Dashboard' module; move those items over to the Home page
166 $pagesDashboard = $current_user->getPreference('pages', 'Dashboard');
167 $dashletsDashboard = $current_user->getPreference('dashlets', 'Dashboard');
168 if ( !empty($pagesDashboard) ) {
169 // move dashlets from the dashboard to be at the end of the home screen dashlets
170 foreach ($pagesDashboard[0]['columns'] as $dashboardColumnKey => $dashboardColumn ) {
171 foreach ($dashboardColumn['dashlets'] as $dashletItem ) {
172 $pages[0]['columns'][$dashboardColumnKey]['dashlets'][] = $dashletItem;
175 $pages = array_merge($pages,$pagesDashboard);
176 $current_user->setPreference('pages', $pages, 0, 'Home');
178 if ( !empty($dashletsDashboard) ) {
179 $dashlets = array_merge($dashlets,$dashletsDashboard);
180 $current_user->setPreference('dashlets', $dashlets, 0, 'Home');
182 if ( !empty($pagesDashboard) || !empty($dashletsDashboard) )
183 $current_user->resetPreferences('Dashboard');
188 $pages[0]['columns'] = $columns;
189 $pages[0]['numColumns'] = '2';
190 $pages[0]['pageTitle'] = $mod_strings['LBL_HOME_PAGE_1_NAME']; // "My Sugar"
192 $current_user->setPreference('pages', $pages, 0, 'Home');
196 $sugar_smarty = new Sugar_Smarty();
200 $divPages[] = $activePage;
202 $numCols = $pages[$activePage]['numColumns'];
206 $dashletIds = array(); // collect ids to pass to javascript
209 foreach($pages[$activePage]['columns'] as $colNum => $column) {
210 if ($colNum == $numCols){
213 $display[$colNum]['width'] = $column['width'];
214 $display[$colNum]['dashlets'] = array();
215 foreach($column['dashlets'] as $num => $id) {
216 // clint - fixes bug #20398
217 // only display dashlets that are from visibile modules and that the user has permission to list
218 if(!empty($id) && isset($dashlets[$id]) && is_file($dashlets[$id]['fileLocation'])) {
220 if ( !empty($dashletsFiles[$dashlets[$id]['className']]['module']) )
221 $module = $dashletsFiles[$dashlets[$id]['className']]['module'];
222 // Bug 24772 - Look into the user preference for the module the dashlet is a part of in case
223 // of the Report Chart dashlets.
224 elseif ( !empty($dashlets[$id]['module']) )
225 $module = $dashlets[$id]['module'];
227 $myDashlet = new MySugar($module);
229 if($myDashlet->checkDashletDisplay()) {
230 require_once($dashlets[$id]['fileLocation']);
231 $dashlet = new $dashlets[$id]['className']($id, (isset($dashlets[$id]['options']) ? $dashlets[$id]['options'] : array()));
232 // Need to add support to dynamically display/hide dashlets
233 // If it has a method 'shouldDisplay' we will call it to see if we should display it or not
234 if (method_exists($dashlet,'shouldDisplay')) {
235 if (!$dashlet->shouldDisplay()) {
236 // This dashlet doesn't want us to show it, skip it.
241 array_push($dashletIds, $id);
243 $dashlets = $current_user->getPreference('dashlets', 'Home'); // Using hardcoded 'Home' because DynamicAction.php $_REQUEST['module'] value is always Home
244 $lvsParams = array();
245 if(!empty($dashlets[$id]['sort_options'])){
246 $lvsParams = $dashlets[$id]['sort_options'];
249 $dashlet->process($lvsParams);
251 $display[$colNum]['dashlets'][$id]['display'] = $dashlet->display();
252 $display[$colNum]['dashlets'][$id]['displayHeader'] = $dashlet->getHeader();
253 $display[$colNum]['dashlets'][$id]['displayFooter'] = $dashlet->getFooter();
254 if($dashlet->hasScript) {
255 $display[$colNum]['dashlets'][$id]['script'] = $dashlet->displayScript();
257 } catch (Exception $ex) {
258 $display[$colNum]['dashlets'][$id]['display'] = $ex->getMessage();
259 $display[$colNum]['dashlets'][$id]['displayHeader'] = $dashlet->getHeader();
260 $display[$colNum]['dashlets'][$id]['displayFooter'] = $dashlet->getFooter();
268 if(!empty($sugar_config['lock_homepage']) && $sugar_config['lock_homepage'] == true) $sugar_smarty->assign('lock_homepage', true);
271 $sugar_smarty->assign('sugarVersion', $sugar_version);
272 $sugar_smarty->assign('sugarFlavor', $sugar_flavor);
273 $sugar_smarty->assign('currentLanguage', $GLOBALS['current_language']);
274 $sugar_smarty->assign('serverUniqueKey', $GLOBALS['server_unique_key']);
275 $sugar_smarty->assign('imagePath', $GLOBALS['image_path']);
277 $sugar_smarty->assign('maxCount', empty($sugar_config['max_dashlets_homepage']) ? 15 : $sugar_config['max_dashlets_homepage']);
278 $sugar_smarty->assign('dashletCount', $count);
279 $sugar_smarty->assign('dashletIds', '["' . implode('","', $dashletIds) . '"]');
280 $sugar_smarty->assign('columns', $display);
283 $sugar_smarty->assign('theme', $theme);
285 $sugar_smarty->assign('divPages', $divPages);
286 $sugar_smarty->assign('activePage', $activePage);
288 $sugar_smarty->assign('current_user', $current_user->id);
290 $sugar_smarty->assign('lblAdd', $GLOBALS['app_strings']['LBL_ADD_BUTTON']);
291 $sugar_smarty->assign('lblAddDashlets', $GLOBALS['app_strings']['LBL_ADD_DASHLETS']);
292 $sugar_smarty->assign('lblLnkHelp', $GLOBALS['app_strings']['LNK_HELP']);
294 $sugar_smarty->assign('mod', return_module_language($GLOBALS['current_language'], 'Home'));
295 $sugar_smarty->assign('app', $GLOBALS['app_strings']);
296 $sugar_smarty->assign('module', 'Home');
298 require_once('include/SugarCharts/SugarChartFactory.php');
299 $sugarChart = SugarChartFactory::getInstance();
300 $resources = $sugarChart->getChartResources();
301 $mySugarResources = $sugarChart->getMySugarChartResources();
302 $sugar_smarty->assign('chartResources', $resources);
303 $sugar_smarty->assign('mySugarChartResources', $mySugarResources);
304 echo $sugar_smarty->fetch('include/MySugar/tpls/MySugar.tpl');
305 //init the quickEdit listeners after the dashlets have loaded on home page the first time
306 echo"<script>if(typeof(qe_init) != 'undefined'){qe_init();}</script>";