]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Home/index.php
Release 6.4.0
[Github/sugarcrm.git] / modules / Home / index.php
1 <?php
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-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 global $current_user, $sugar_version, $sugar_config, $beanFiles;
40
41
42 require_once('include/MySugar/MySugar.php');
43
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');
47
48     $dc = new DashletCacheBuilder();
49     $dc->buildCache();
50 }
51 require_once $cachefile;
52
53 require('modules/Home/dashlets.php');
54
55 $pages = $current_user->getPreference('pages', 'Home');
56 $dashlets = $current_user->getPreference('dashlets', 'Home');
57
58 $defaultHomepage = false;
59 // BEGIN fill in with default homepage and dashlet selections
60
61 $hasUserPreferences = (!isset($pages) || empty($pages) || !isset($dashlets) || empty($dashlets)) ? false : true;
62
63 if(!$hasUserPreferences){
64     $dashlets = array();
65
66     //list of preferences to move over and to where
67     $prefstomove = array(
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');
83
84         //upgrading from pre-5.0 homepage
85         $old_columns = $current_user->getPreference('columns', 'home');
86         $old_dashlets = $current_user->getPreference('dashlets', 'home');
87
88         if (isset($old_columns) && !empty($old_columns) && isset($old_dashlets) && !empty($old_dashlets)){
89                 $columns = $old_columns;
90                 $dashlets = $old_dashlets;
91
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');
97         }
98         else{
99         // This is here to get Sugar dashlets added above the rest
100         $dashlets[create_guid()] = array('className' => 'iFrameDashlet',
101                                          'module' => 'Home',
102                                          'forceColumn' => 0,
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',
106                                                             'height' => 315,
107                                              ));
108
109         $dashlets[create_guid()] = array ('className' => 'SugarFeedDashlet',
110                                           'module' => 'SugarFeed',
111                                           'forceColumn' => 1,
112                                           'fileLocation' => $dashletsFiles['SugarFeedDashlet']['file'],
113                                           );
114
115         $dashlets[create_guid()] = array('className' => 'iFrameDashlet',
116                                          'module' => 'Home',
117                                          'forceColumn' => 1,
118                                          'fileLocation' => $dashletsFiles['iFrameDashlet']['file'],
119                                          'options' => array('title' => translate('LBL_DASHLET_SUGAR_NEWS','Home'),
120                                                             'url' => 'http://www.sugarcrm.com/crm/product/news',
121                                                             'height' => 315,
122                                              ));
123
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){
130                         $options = array();
131                $prefsforthisdashlet = array_keys($prefstomove,$dashletName);
132                foreach ( $prefsforthisdashlet as $pref ) {
133                    $options[$pref] = $current_user->getPreference($pref);
134                }
135                 $dashlets[create_guid()] = array('className' => $dashletName,
136                                                                                                  'module' => $module,
137                                                      'forceColumn' => 0,
138                                                      'fileLocation' => $dashletsFiles[$dashletName]['file'],
139                                                  'options' => $options);
140                 }
141             }
142
143             $count = 0;
144             $columns = array();
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();
151
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);
155                 $count++;
156             }
157         }
158
159
160
161
162     $current_user->setPreference('dashlets', $dashlets, 0, 'Home');
163 }
164
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;
173         }
174     }
175     $pages = array_merge($pages,$pagesDashboard);
176     $current_user->setPreference('pages', $pages, 0, 'Home');
177 }
178 if ( !empty($dashletsDashboard) ) {
179     $dashlets = array_merge($dashlets,$dashletsDashboard);
180     $current_user->setPreference('dashlets', $dashlets, 0, 'Home');
181 }
182 if ( !empty($pagesDashboard) || !empty($dashletsDashboard) )
183     $current_user->resetPreferences('Dashboard');
184
185 if (empty($pages)){
186         $pages = array();
187         $pageIndex = 0;
188         $pages[0]['columns'] = $columns;
189         $pages[0]['numColumns'] = '2';
190         $pages[0]['pageTitle'] = $mod_strings['LBL_HOME_PAGE_1_NAME'];  // "My Sugar"
191         $pageIndex++;
192         $current_user->setPreference('pages', $pages, 0, 'Home');
193     $activePage = 0;
194 }
195
196 $sugar_smarty = new Sugar_Smarty();
197
198     $activePage = 0;
199
200 $divPages[] = $activePage;
201
202 $numCols = $pages[$activePage]['numColumns'];
203
204
205 $count = 0;
206 $dashletIds = array(); // collect ids to pass to javascript
207 $display = array();
208
209 foreach($pages[$activePage]['columns'] as $colNum => $column) {
210         if ($colNum == $numCols){
211                 break;
212         }
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'])) {
219                         $module = 'Home';
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'];
226
227                         $myDashlet = new MySugar($module);
228
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.
237                         continue;
238                     }
239                 }
240
241                 array_push($dashletIds, $id);
242
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'];
247                 }
248
249                 $dashlet->process($lvsParams);
250                 try {
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();
256                         }
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();
261                 }
262                 }
263         }
264         }
265 }
266
267
268 if(!empty($sugar_config['lock_homepage']) && $sugar_config['lock_homepage'] == true) $sugar_smarty->assign('lock_homepage', true);
269
270
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']);
276
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);
281
282 global $theme;
283 $sugar_smarty->assign('theme', $theme);
284
285 $sugar_smarty->assign('divPages', $divPages);
286 $sugar_smarty->assign('activePage', $activePage);
287
288 $sugar_smarty->assign('current_user', $current_user->id);
289
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']);
293
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');
297 //custom chart code
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>";
307 ?>