PageRenderTime 41ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/custom/modules/Home/index.php

https://gitlab.com/tjaafar/SuiteCRM
PHP | 319 lines | 216 code | 49 blank | 54 comment | 40 complexity | 87f8d2b951790306b63b080bcdd41b75 MD5 | raw file
  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-2013 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($cachefile = sugar_cached('dashlets/dashlets.php'))) {
  41. require_once('include/Dashlets/DashletCacheBuilder.php');
  42. $dc = new DashletCacheBuilder();
  43. $dc->buildCache();
  44. }
  45. require_once $cachefile;
  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('titleLabel' => $GLOBALS['app_strings']['LBL_DISCOVER_SUITECRM'],
  90. 'url' => 'http://www.suitecrm.com',
  91. 'height' => 315,
  92. ));
  93. $dashlets[create_guid()] = array ('className' => 'SugarFeedDashlet',
  94. 'module' => 'SugarFeed',
  95. 'forceColumn' => 1,
  96. 'fileLocation' => $dashletsFiles['SugarFeedDashlet']['file'],
  97. );
  98. foreach($defaultDashlets as $dashletName=>$module){
  99. // clint - fixes bug #20398
  100. // only display dashlets that are from visibile modules and that the user has permission to list
  101. $myDashlet = new MySugar($module);
  102. $displayDashlet = $myDashlet->checkDashletDisplay();
  103. if (isset($dashletsFiles[$dashletName]) && $displayDashlet){
  104. $options = array();
  105. $prefsforthisdashlet = array_keys($prefstomove,$dashletName);
  106. foreach ( $prefsforthisdashlet as $pref ) {
  107. $options[$pref] = $current_user->getPreference($pref);
  108. }
  109. $dashlets[create_guid()] = array('className' => $dashletName,
  110. 'module' => $module,
  111. 'forceColumn' => 0,
  112. 'fileLocation' => $dashletsFiles[$dashletName]['file'],
  113. 'options' => $options);
  114. }
  115. }
  116. $count = 0;
  117. $columns = array();
  118. $columns[0] = array();
  119. $columns[0]['width'] = '60%';
  120. $columns[0]['dashlets'] = array();
  121. $columns[1] = array();
  122. $columns[1]['width'] = '40%';
  123. $columns[1]['dashlets'] = array();
  124. foreach($dashlets as $guid=>$dashlet) {
  125. if( $dashlet['forceColumn'] == 0 ) array_push($columns[0]['dashlets'], $guid);
  126. else array_push($columns[1]['dashlets'], $guid);
  127. $count++;
  128. }
  129. }
  130. $current_user->setPreference('dashlets', $dashlets, 0, 'Home');
  131. }
  132. // handles upgrading from versions that had the 'Dashboard' module; move those items over to the Home page
  133. $pagesDashboard = $current_user->getPreference('pages', 'Dashboard');
  134. $dashletsDashboard = $current_user->getPreference('dashlets', 'Dashboard');
  135. if ( !empty($pagesDashboard) ) {
  136. // move dashlets from the dashboard to be at the end of the home screen dashlets
  137. foreach ($pagesDashboard[0]['columns'] as $dashboardColumnKey => $dashboardColumn ) {
  138. foreach ($dashboardColumn['dashlets'] as $dashletItem ) {
  139. $pages[0]['columns'][$dashboardColumnKey]['dashlets'][] = $dashletItem;
  140. }
  141. }
  142. $pages = array_merge($pages,$pagesDashboard);
  143. $current_user->setPreference('pages', $pages, 0, 'Home');
  144. }
  145. if ( !empty($dashletsDashboard) ) {
  146. $dashlets = array_merge($dashlets,$dashletsDashboard);
  147. $current_user->setPreference('dashlets', $dashlets, 0, 'Home');
  148. }
  149. if ( !empty($pagesDashboard) || !empty($dashletsDashboard) )
  150. $current_user->resetPreferences('Dashboard');
  151. if (empty($pages)){
  152. $pages = array();
  153. $pageIndex = 0;
  154. $pages[0]['columns'] = $columns;
  155. $pages[0]['numColumns'] = '3';
  156. $pages[0]['pageTitleLabel'] = 'LBL_HOME_PAGE_1_NAME'; // "My Sugar"
  157. $pageIndex++;
  158. $current_user->setPreference('pages', $pages, 0, 'Home');
  159. $activePage = 0;
  160. }
  161. $sugar_smarty = new Sugar_Smarty();
  162. $activePage = 0;
  163. $divPages[] = $activePage;
  164. $numCols = $pages[$activePage]['numColumns'];
  165. $count = 0;
  166. $dashletIds = array(); // collect ids to pass to javascript
  167. $display = array();
  168. foreach($pages[$activePage]['columns'] as $colNum => $column) {
  169. if ($colNum == $numCols){
  170. break;
  171. }
  172. $display[$colNum]['width'] = $column['width'];
  173. $display[$colNum]['dashlets'] = array();
  174. foreach($column['dashlets'] as $num => $id) {
  175. // clint - fixes bug #20398
  176. // only display dashlets that are from visibile modules and that the user has permission to list
  177. if(!empty($id) && isset($dashlets[$id]) && is_file($dashlets[$id]['fileLocation'])) {
  178. $module = 'Home';
  179. if ( !empty($dashletsFiles[$dashlets[$id]['className']]['module']) )
  180. $module = $dashletsFiles[$dashlets[$id]['className']]['module'];
  181. // Bug 24772 - Look into the user preference for the module the dashlet is a part of in case
  182. // of the Report Chart dashlets.
  183. elseif ( !empty($dashlets[$id]['module']) )
  184. $module = $dashlets[$id]['module'];
  185. $myDashlet = new MySugar($module);
  186. if($myDashlet->checkDashletDisplay()) {
  187. require_once($dashlets[$id]['fileLocation']);
  188. $dashlet = new $dashlets[$id]['className']($id, (isset($dashlets[$id]['options']) ? $dashlets[$id]['options'] : array()));
  189. // Need to add support to dynamically display/hide dashlets
  190. // If it has a method 'shouldDisplay' we will call it to see if we should display it or not
  191. if (method_exists($dashlet,'shouldDisplay')) {
  192. if (!$dashlet->shouldDisplay()) {
  193. // This dashlet doesn't want us to show it, skip it.
  194. continue;
  195. }
  196. }
  197. array_push($dashletIds, $id);
  198. $dashlets = $current_user->getPreference('dashlets', 'Home'); // Using hardcoded 'Home' because DynamicAction.php $_REQUEST['module'] value is always Home
  199. $lvsParams = array();
  200. if(!empty($dashlets[$id]['sort_options'])){
  201. $lvsParams = $dashlets[$id]['sort_options'];
  202. }
  203. $dashlet->process($lvsParams);
  204. try {
  205. $display[$colNum]['dashlets'][$id]['display'] = $dashlet->display();
  206. $display[$colNum]['dashlets'][$id]['displayHeader'] = $dashlet->getHeader();
  207. $display[$colNum]['dashlets'][$id]['displayFooter'] = $dashlet->getFooter();
  208. if($dashlet->hasScript) {
  209. $display[$colNum]['dashlets'][$id]['script'] = $dashlet->displayScript();
  210. }
  211. } catch (Exception $ex) {
  212. $display[$colNum]['dashlets'][$id]['display'] = $ex->getMessage();
  213. $display[$colNum]['dashlets'][$id]['displayHeader'] = $dashlet->getHeader();
  214. $display[$colNum]['dashlets'][$id]['displayFooter'] = $dashlet->getFooter();
  215. }
  216. }
  217. }
  218. }
  219. }
  220. $i = 0;
  221. while($i < count($pages)){
  222. if($i == 0){
  223. $pageTabs[$i]['pageTitle'] = $GLOBALS['app_strings']['LBL_SUITE_DASHBOARD'];
  224. // $pageTabs[$i]['active'] = 'current';
  225. }else{
  226. $pageTabs[$i]['pageTitle'] = $pages[$i]['pageTitle'];
  227. $divPages[] = $i;
  228. }
  229. $i++;
  230. }
  231. if(!empty($sugar_config['lock_homepage']) && $sugar_config['lock_homepage'] == true) $sugar_smarty->assign('lock_homepage', true);
  232. $sugar_smarty->assign('sugarVersion', $sugar_version);
  233. $sugar_smarty->assign('sugarFlavor', $sugar_flavor);
  234. $sugar_smarty->assign('currentLanguage', $GLOBALS['current_language']);
  235. $sugar_smarty->assign('serverUniqueKey', $GLOBALS['server_unique_key']);
  236. $sugar_smarty->assign('imagePath', $GLOBALS['image_path']);
  237. $sugar_smarty->assign('maxCount', empty($sugar_config['max_dashlets_homepage']) ? 15 : $sugar_config['max_dashlets_homepage']);
  238. $sugar_smarty->assign('dashletCount', $count);
  239. $sugar_smarty->assign('dashletIds', '["' . implode('","', $dashletIds) . '"]');
  240. $sugar_smarty->assign('columns', $display);
  241. global $theme;
  242. $sugar_smarty->assign('theme', $theme);
  243. $sugar_smarty->assign('divPages', $divPages);
  244. $sugar_smarty->assign('activePage', $activePage);
  245. $sugar_smarty->assign('dashboardPages', $pageTabs);
  246. $sugar_smarty->assign('current_user', $current_user->id);
  247. $sugar_smarty->assign('lblAdd', $GLOBALS['app_strings']['LBL_ADD_BUTTON']);
  248. $sugar_smarty->assign('lblAddTab', $GLOBALS['app_strings']['LBL_ADD_TAB']);
  249. $sugar_smarty->assign('lblAddDashlets', $GLOBALS['app_strings']['LBL_ADD_DASHLETS']);
  250. $sugar_smarty->assign('lblLnkHelp', $GLOBALS['app_strings']['LNK_HELP']);
  251. $sugar_smarty->assign('mod', return_module_language($GLOBALS['current_language'], 'Home'));
  252. $sugar_smarty->assign('app', $GLOBALS['app_strings']);
  253. $sugar_smarty->assign('module', 'Home');
  254. //custom chart code
  255. require_once('include/SugarCharts/SugarChartFactory.php');
  256. $sugarChart = SugarChartFactory::getInstance();
  257. $resources = $sugarChart->getChartResources();
  258. $mySugarResources = $sugarChart->getMySugarChartResources();
  259. $sugar_smarty->assign('chartResources', $resources);
  260. $sugar_smarty->assign('mySugarChartResources', $mySugarResources);
  261. if (file_exists("themes/" . $theme ."/tpls/MySugar.tpl")) {
  262. echo $sugar_smarty->fetch("themes/" . $theme ."/tpls/MySugar.tpl");
  263. } else {
  264. echo $sugar_smarty->fetch('custom/include/MySugar/tpls/MySugar.tpl');
  265. }
  266. //init the quickEdit listeners after the dashlets have loaded on home page the first time
  267. echo"<script>if(typeof(qe_init) != 'undefined'){qe_init();}</script>";
  268. echo"<script> $( '#pageNum_'+ 0 +'_anchor').addClass( 'current' );</script>";
  269. echo"<script> $( '#pageNum_'+ 0).addClass( 'active' );</script>";
  270. ?>