PageRenderTime 20ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/Home/index.php

https://github.com/yinhm/sugarcrm
PHP | 284 lines | 187 code | 48 blank | 49 comment | 34 complexity | 85b0dd6a6d2bc8e3a57a265a284c58b3 MD5 | raw file
Possible License(s): LGPL-2.1, MPL-2.0-no-copyleft-exception
  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-2010 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. global $current_user, $sugar_version, $sugar_config, $beanFiles;
  38. require_once('include/MySugar/MySugar.php');
  39. // build dashlet cache file if not found
  40. if(!is_file($GLOBALS['sugar_config']['cache_dir'].'dashlets/dashlets.php')) {
  41. require_once('include/Dashlets/DashletCacheBuilder.php');
  42. $dc = new DashletCacheBuilder();
  43. $dc->buildCache();
  44. }
  45. require_once($GLOBALS['sugar_config']['cache_dir'].'dashlets/dashlets.php');
  46. require('modules/Home/dashlets.php');
  47. $pages = $current_user->getPreference('pages', 'Home');
  48. $dashlets = $current_user->getPreference('dashlets', 'Home');
  49. $defaultHomepage = false;
  50. // BEGIN fill in with default homepage and dashlet selections
  51. $hasUserPreferences = (!isset($pages) || empty($pages) || !isset($dashlets) || empty($dashlets)) ? false : true;
  52. if(!$hasUserPreferences){
  53. $dashlets = array();
  54. //list of preferences to move over and to where
  55. $prefstomove = array(
  56. 'mypbss_date_start' => 'MyPipelineBySalesStageDashlet',
  57. 'mypbss_date_end' => 'MyPipelineBySalesStageDashlet',
  58. 'mypbss_sales_stages' => 'MyPipelineBySalesStageDashlet',
  59. 'mypbss_chart_type' => 'MyPipelineBySalesStageDashlet',
  60. 'lsbo_lead_sources' => 'OpportunitiesByLeadSourceByOutcomeDashlet',
  61. 'lsbo_ids' => 'OpportunitiesByLeadSourceByOutcomeDashlet',
  62. 'pbls_lead_sources' => 'OpportunitiesByLeadSourceDashlet',
  63. 'pbls_ids' => 'OpportunitiesByLeadSourceDashlet',
  64. 'pbss_date_start' => 'PipelineBySalesStageDashlet',
  65. 'pbss_date_end' => 'PipelineBySalesStageDashlet',
  66. 'pbss_sales_stages' => 'PipelineBySalesStageDashlet',
  67. 'pbss_chart_type' => 'PipelineBySalesStageDashlet',
  68. 'obm_date_start' => 'OutcomeByMonthDashlet',
  69. 'obm_date_end' => 'OutcomeByMonthDashlet',
  70. 'obm_ids' => 'OutcomeByMonthDashlet');
  71. //upgrading from pre-5.0 homepage
  72. $old_columns = $current_user->getPreference('columns', 'home');
  73. $old_dashlets = $current_user->getPreference('dashlets', 'home');
  74. if (isset($old_columns) && !empty($old_columns) && isset($old_dashlets) && !empty($old_dashlets)){
  75. $columns = $old_columns;
  76. $dashlets = $old_dashlets;
  77. // resetting old columns and dashlets to have no preference and data
  78. $old_columns = array();
  79. $old_dashlets = array();
  80. $current_user->setPreference('columns', $old_columns, 0, 'home');
  81. $current_user->setPreference('dashlets', $old_dashlets, 0, 'home');
  82. }
  83. else{
  84. // This is here to get Sugar dashlets added above the rest
  85. $dashlets[create_guid()] = array('className' => 'iFrameDashlet',
  86. 'module' => 'Home',
  87. 'forceColumn' => 0,
  88. 'fileLocation' => $dashletsFiles['iFrameDashlet']['file'],
  89. 'options' => array('title' => translate('LBL_DASHLET_DISCOVER_SUGAR_PRO','Home'),
  90. 'url' => 'http://apps.sugarcrm.com/dashlet/5.2.0/go-pro.html?lang=@@LANG@@&edition=@@EDITION@@&ver=@@VER@@',
  91. 'height' => 315,
  92. ));
  93. $dashlets[create_guid()] = array ('className' => 'SugarFeedDashlet',
  94. 'module' => 'SugarFeed',
  95. 'forceColumn' => 1,
  96. 'fileLocation' => $dashletsFiles['SugarFeedDashlet']['file'],
  97. );
  98. $dashlets[create_guid()] = array('className' => 'iFrameDashlet',
  99. 'module' => 'Home',
  100. 'forceColumn' => 1,
  101. 'fileLocation' => $dashletsFiles['iFrameDashlet']['file'],
  102. 'options' => array('title' => translate('LBL_DASHLET_SUGAR_NEWS','Home'),
  103. 'url' => 'http://apps.sugarcrm.com/dashlet/5.2.0/sugarcrm-news-dashlet.html?lang=@@LANG@@&edition=@@EDITION@@&ver=@@VER@@',
  104. 'height' => 315,
  105. ));
  106. foreach($defaultDashlets as $dashletName=>$module){
  107. // clint - fixes bug #20398
  108. // only display dashlets that are from visibile modules and that the user has permission to list
  109. $myDashlet = new MySugar($module);
  110. $displayDashlet = $myDashlet->checkDashletDisplay();
  111. if (isset($dashletsFiles[$dashletName]) && $displayDashlet){
  112. $options = array();
  113. $prefsforthisdashlet = array_keys($prefstomove,$dashletName);
  114. foreach ( $prefsforthisdashlet as $pref ) {
  115. $options[$pref] = $current_user->getPreference($pref);
  116. }
  117. $dashlets[create_guid()] = array('className' => $dashletName,
  118. 'module' => $module,
  119. 'forceColumn' => 0,
  120. 'fileLocation' => $dashletsFiles[$dashletName]['file'],
  121. 'options' => $options);
  122. }
  123. }
  124. $count = 0;
  125. $columns = array();
  126. $columns[0] = array();
  127. $columns[0]['width'] = '60%';
  128. $columns[0]['dashlets'] = array();
  129. $columns[1] = array();
  130. $columns[1]['width'] = '40%';
  131. $columns[1]['dashlets'] = array();
  132. foreach($dashlets as $guid=>$dashlet) {
  133. if( $dashlet['forceColumn'] == 0 ) array_push($columns[0]['dashlets'], $guid);
  134. else array_push($columns[1]['dashlets'], $guid);
  135. $count++;
  136. }
  137. }
  138. $current_user->setPreference('dashlets', $dashlets, 0, 'Home');
  139. }
  140. // handles upgrading from versions that had the 'Dashboard' module; move those items over to the Home page
  141. $pagesDashboard = $current_user->getPreference('pages', 'Dashboard');
  142. $dashletsDashboard = $current_user->getPreference('dashlets', 'Dashboard');
  143. if ( !empty($pagesDashboard) ) {
  144. // move dashlets from the dashboard to be at the end of the home screen dashlets
  145. foreach ($pagesDashboard[0]['columns'] as $dashboardColumnKey => $dashboardColumn ) {
  146. foreach ($dashboardColumn['dashlets'] as $dashletItem ) {
  147. $pages[0]['columns'][$dashboardColumnKey]['dashlets'][] = $dashletItem;
  148. }
  149. }
  150. $pages = array_merge($pages,$pagesDashboard);
  151. $current_user->setPreference('pages', $pages, 0, 'Home');
  152. }
  153. if ( !empty($dashletsDashboard) ) {
  154. $dashlets = array_merge($dashlets,$dashletsDashboard);
  155. $current_user->setPreference('dashlets', $dashlets, 0, 'Home');
  156. }
  157. if ( !empty($pagesDashboard) || !empty($dashletsDashboard) )
  158. $current_user->resetPreferences('Dashboard');
  159. if (empty($pages)){
  160. $pages = array();
  161. $pageIndex = 0;
  162. $pages[0]['columns'] = $columns;
  163. $pages[0]['numColumns'] = '2';
  164. $pages[0]['pageTitle'] = $mod_strings['LBL_HOME_PAGE_1_NAME']; // "My Sugar"
  165. $pageIndex++;
  166. $current_user->setPreference('pages', $pages, 0, 'Home');
  167. $activePage = 0;
  168. }
  169. $sugar_smarty = new Sugar_Smarty();
  170. $activePage = 0;
  171. $divPages[] = $activePage;
  172. $numCols = $pages[$activePage]['numColumns'];
  173. $count = 0;
  174. $dashletIds = array(); // collect ids to pass to javascript
  175. $display = array();
  176. foreach($pages[$activePage]['columns'] as $colNum => $column) {
  177. if ($colNum == $numCols){
  178. break;
  179. }
  180. $display[$colNum]['width'] = $column['width'];
  181. $display[$colNum]['dashlets'] = array();
  182. foreach($column['dashlets'] as $num => $id) {
  183. // clint - fixes bug #20398
  184. // only display dashlets that are from visibile modules and that the user has permission to list
  185. if(!empty($id) && isset($dashlets[$id]) && is_file($dashlets[$id]['fileLocation'])) {
  186. $module = 'Home';
  187. if ( isset($dashletsFiles[$dashlets[$id]['className']]['module']) )
  188. $module = $dashletsFiles[$dashlets[$id]['className']]['module'];
  189. $myDashlet = new MySugar($module);
  190. if($myDashlet->checkDashletDisplay()) {
  191. require_once($dashlets[$id]['fileLocation']);
  192. $dashlet = new $dashlets[$id]['className']($id, (isset($dashlets[$id]['options']) ? $dashlets[$id]['options'] : array()));
  193. // Need to add support to dynamically display/hide dashlets
  194. // If it has a method 'shouldDisplay' we will call it to see if we should display it or not
  195. if (method_exists($dashlet,'shouldDisplay')) {
  196. if (!$dashlet->shouldDisplay()) {
  197. // This dashlet doesn't want us to show it, skip it.
  198. continue;
  199. }
  200. }
  201. array_push($dashletIds, $id);
  202. $dashlet->process();
  203. $display[$colNum]['dashlets'][$id]['display'] = $dashlet->display();
  204. $display[$colNum]['dashlets'][$id]['displayHeader'] = $dashlet->getHeader();
  205. $display[$colNum]['dashlets'][$id]['displayFooter'] = $dashlet->getFooter();
  206. if($dashlet->hasScript) {
  207. $display[$colNum]['dashlets'][$id]['script'] = $dashlet->displayScript();
  208. }
  209. }
  210. }
  211. }
  212. }
  213. if(!empty($sugar_config['lock_homepage']) && $sugar_config['lock_homepage'] == true) $sugar_smarty->assign('lock_homepage', true);
  214. $sugar_smarty->assign('sugarVersion', $sugar_version);
  215. $sugar_smarty->assign('sugarFlavor', $sugar_flavor);
  216. $sugar_smarty->assign('currentLanguage', $GLOBALS['current_language']);
  217. $sugar_smarty->assign('serverUniqueKey', $GLOBALS['server_unique_key']);
  218. $sugar_smarty->assign('imagePath', $GLOBALS['image_path']);
  219. $sugar_smarty->assign('jsCustomVersion', $sugar_config['js_custom_version']);
  220. $sugar_smarty->assign('maxCount', empty($sugar_config['max_dashlets_homepage']) ? 15 : $sugar_config['max_dashlets_homepage']);
  221. $sugar_smarty->assign('dashletCount', $count);
  222. $sugar_smarty->assign('dashletIds', '["' . implode('","', $dashletIds) . '"]');
  223. $sugar_smarty->assign('columns', $display);
  224. global $theme;
  225. $sugar_smarty->assign('theme', $theme);
  226. $sugar_smarty->assign('divPages', $divPages);
  227. $sugar_smarty->assign('activePage', $activePage);
  228. $sugar_smarty->assign('current_user', $current_user->id);
  229. $sugar_smarty->assign('lblAdd', $GLOBALS['app_strings']['LBL_ADD_BUTTON']);
  230. $sugar_smarty->assign('lblAddDashlets', $GLOBALS['app_strings']['LBL_ADD_DASHLETS']);
  231. $sugar_smarty->assign('lblLnkHelp', $GLOBALS['app_strings']['LNK_HELP']);
  232. $sugar_smarty->assign('mod', return_module_language($sugar_config['default_language'], 'Home'));
  233. $sugar_smarty->assign('app', $GLOBALS['app_strings']);
  234. $sugar_smarty->assign('module', 'Home');
  235. echo $sugar_smarty->fetch('include/MySugar/tpls/MySugar.tpl');
  236. ?>