if ($colNum == $numCols) { break; } $display[$colNum]['width'] = $column['width']; $display[$colNum]['dashlets'] = array(); foreach ($column['dashlets'] as $num => $id) { // clint - fixes bug #20398 // only display dashlets that are from visibile modules and that the user has permission to list if (!empty($id) && isset($dashlets[$id]) && is_file($dashlets[$id]['fileLocation'])) { $module = 'Home'; if (!empty($dashletsFiles[$dashlets[$id]['className']]['module'])) { $module = $dashletsFiles[$dashlets[$id]['className']]['module']; } elseif (!empty($dashlets[$id]['module'])) { $module = $dashlets[$id]['module']; } $myDashlet = new MySugar($module); if ($myDashlet->checkDashletDisplay()) { require_once $dashlets[$id]['fileLocation']; $dashlet = new $dashlets[$id]['className']($id, isset($dashlets[$id]['options']) ? $dashlets[$id]['options'] : array()); // Need to add support to dynamically display/hide dashlets // If it has a method 'shouldDisplay' we will call it to see if we should display it or not if (method_exists($dashlet, 'shouldDisplay')) { if (!$dashlet->shouldDisplay()) { // This dashlet doesn't want us to show it, skip it. continue; } } array_push($dashletIds, $id); $dashlets = $current_user->getPreference('dashlets', 'Home'); // Using hardcoded 'Home' because DynamicAction.php $_REQUEST['module'] value is always Home $lvsParams = array();
public function run() { if (!($this->from_flavor == 'ce' && $this->toFlavor('pro'))) { return; } $dashletsFiles = array(); if (file_exists($cachedfile = sugar_cached('dashlets/dashlets.php'))) { require $cachedfile; } if (file_exists('modules/Home/dashlets.php')) { require 'modules/Home/dashlets.php'; } require_once 'include/MySugar/MySugar.php'; $prefstomove = array('mypbss_date_start' => 'MyPipelineBySalesStageDashlet', 'mypbss_date_end' => 'MyPipelineBySalesStageDashlet', 'mypbss_sales_stages' => 'MyPipelineBySalesStageDashlet', 'mypbss_chart_type' => 'MyPipelineBySalesStageDashlet', 'lsbo_lead_sources' => 'OpportunitiesByLeadSourceByOutcomeDashlet', 'lsbo_ids' => 'OpportunitiesByLeadSourceByOutcomeDashlet', 'pbls_lead_sources' => 'OpportunitiesByLeadSourceDashlet', 'pbls_ids' => 'OpportunitiesByLeadSourceDashlet', 'pbss_date_start' => 'PipelineBySalesStageDashlet', 'pbss_date_end' => 'PipelineBySalesStageDashlet', 'pbss_sales_stages' => 'PipelineBySalesStageDashlet', 'pbss_chart_type' => 'PipelineBySalesStageDashlet', 'obm_date_start' => 'OutcomeByMonthDashlet', 'obm_date_end' => 'OutcomeByMonthDashlet', 'obm_ids' => 'OutcomeByMonthDashlet'); $result = $this->db->query("SELECT id FROM users where deleted = '0' AND status != 'Reserved' AND portal_only = 0"); while ($row = $this->db->fetchByAssoc($result)) { $current_user = BeanFactory::getBean('Users', $row['id']); // Set the user theme to be 'Sugar' theme since this is run for CE // flavor conversions $current_user->setPreference('user_theme', 'Sugar', 0, 'global'); $pages = $current_user->getPreference('pages', 'Home'); if (empty($pages)) { continue; } $empty_dashlets = array(); $dashlets = $current_user->getPreference('dashlets', 'Home'); $dashlets = !empty($dashlets) ? $dashlets : $empty_dashlets; $existingDashlets = array(); foreach ($dashlets as $id => $dashlet) { if (!empty($dashlet['className']) && !is_array($dashlet['className'])) { $existingDashlets[$dashlet['className']] = $dashlet['className']; } } // foreach // BEGIN 'Sales Page' $salesDashlets = array(); foreach ($defaultSalesDashlets as $salesDashletName => $module) { // clint - fixes bug #20398 // only display dashlets that are from visibile modules and that // the user has permission to list $myDashlet = new MySugar($module); $displayDashlet = $myDashlet->checkDashletDisplay(); if (isset($dashletsFiles[$salesDashletName]) && $displayDashlet) { $options = array(); $prefsforthisdashlet = array_keys($prefstomove, $salesDashletName); foreach ($prefsforthisdashlet as $pref) { $options[$pref] = $current_user->getPreference($pref); } $salesDashlets[create_guid()] = array('className' => $salesDashletName, 'module' => $module, 'fileLocation' => $dashletsFiles[$salesDashletName]['file'], 'options' => $options); } } foreach ($defaultSalesChartDashlets as $salesChartDashlet => $module) { $savedReport = new SavedReport(); $reportId = $savedReport->retrieveReportIdByName($salesChartDashlet); // clint - fixes bug #20398 // only display dashlets that are from visibile modules and that // the user has permission to list $myDashlet = new MySugar($module); $displayDashlet = $myDashlet->checkDashletDisplay(); if (isset($reportId) && $displayDashlet) { $salesDashlets[create_guid()] = array('className' => 'ChartsDashlet', 'module' => $module, 'fileLocation' => $dashletsFiles['ChartsDashlet']['file'], 'reportId' => $reportId); } } $count = 0; $salesColumns = array(); $salesColumns[0] = array(); $salesColumns[0]['width'] = '60%'; $salesColumns[0]['dashlets'] = array(); $salesColumns[1] = array(); $salesColumns[1]['width'] = '40%'; $salesColumns[1]['dashlets'] = array(); foreach ($salesDashlets as $guid => $dashlet) { if ($count % 2 == 0) { array_push($salesColumns[0]['dashlets'], $guid); } else { array_push($salesColumns[1]['dashlets'], $guid); } $count++; } // END 'Sales Page' // BEGIN 'Marketing Page' $marketingDashlets = array(); foreach ($defaultMarketingChartDashlets as $marketingChartDashlet => $module) { $savedReport = new SavedReport(); $reportId = $savedReport->retrieveReportIdByName($marketingChartDashlet); // clint - fixes bug #20398 // only display dashlets that are from visibile modules and that // the user has permission to list $myDashlet = new MySugar($module); $displayDashlet = $myDashlet->checkDashletDisplay(); if (isset($reportId) && $displayDashlet) { $marketingDashlets[create_guid()] = array('className' => 'ChartsDashlet', 'module' => $module, 'fileLocation' => $dashletsFiles['ChartsDashlet']['file'], 'reportId' => $reportId); } } foreach ($defaultMarketingDashlets as $marketingDashletName => $module) { // clint - fixes bug #20398 // only display dashlets that are from visibile modules and that // the user has permission to list $myDashlet = new MySugar($module); $displayDashlet = $myDashlet->checkDashletDisplay(); if (isset($dashletsFiles[$marketingDashletName]) && $displayDashlet) { $options = array(); $prefsforthisdashlet = array_keys($prefstomove, $marketingDashletName); foreach ($prefsforthisdashlet as $pref) { $options[$pref] = $current_user->getPreference($pref); } // foreach $marketingDashlets[create_guid()] = array('className' => $marketingDashletName, 'module' => $module, 'fileLocation' => $dashletsFiles[$marketingDashletName]['file'], 'options' => $options); } } $count = 0; $marketingColumns = array(); $marketingColumns[0] = array(); $marketingColumns[0]['width'] = '30%'; $marketingColumns[0]['dashlets'] = array(); $marketingColumns[1] = array(); $marketingColumns[1]['width'] = '30%'; $marketingColumns[1]['dashlets'] = array(); $marketingColumns[2] = array(); $marketingColumns[2]['width'] = '40%'; $marketingColumns[2]['dashlets'] = array(); foreach ($marketingDashlets as $guid => $dashlet) { if ($count % 3 == 0) { array_push($marketingColumns[0]['dashlets'], $guid); } else { if ($count % 3 == 1) { array_push($marketingColumns[1]['dashlets'], $guid); } else { array_push($marketingColumns[2]['dashlets'], $guid); } } $count++; } // END 'Marketing Page' // BEGIN 'Support Page'- bug46195 $supportDashlets = array(); foreach ($defaultSupportChartDashlets as $supportChartDashlet => $module) { $savedReport = new SavedReport(); $reportId = $savedReport->retrieveReportIdByName($supportChartDashlet); $myDashlet = new MySugar($module); $displayDashlet = $myDashlet->checkDashletDisplay(); if (isset($reportId) && $displayDashlet) { $supportDashlets[create_guid()] = array('className' => 'ChartsDashlet', 'module' => $module, 'fileLocation' => $dashletsFiles['ChartsDashlet']['file'], 'reportId' => $reportId); } } foreach ($defaultSupportDashlets as $supportDashletName => $module) { $myDashlet = new MySugar($module); $displayDashlet = $myDashlet->checkDashletDisplay(); if (isset($dashletsFiles[$supportDashletName]) && $displayDashlet) { $options = array(); $prefsforthisdashlet = array_keys($prefstomove, $supportDashletName); foreach ($prefsforthisdashlet as $pref) { $options[$pref] = $current_user->getPreference($pref); } // foreach $supportDashlets[create_guid()] = array('className' => $supportDashletName, 'module' => $module, 'fileLocation' => $dashletsFiles[$supportDashletName]['file'], 'options' => $options); } } $count = 0; $supportColumns = array(); $supportColumns[0] = array(); $supportColumns[0]['width'] = '30%'; $supportColumns[0]['dashlets'] = array(); $supportColumns[1] = array(); $supportColumns[1]['width'] = '30%'; $supportColumns[1]['dashlets'] = array(); $supportColumns[2] = array(); $supportColumns[2]['width'] = '40%'; $supportColumns[2]['dashlets'] = array(); foreach ($supportDashlets as $guid => $dashlet) { if ($count % 3 == 0) { array_push($supportColumns[0]['dashlets'], $guid); } else { if ($count % 3 == 1) { array_push($supportColumns[1]['dashlets'], $guid); } else { array_push($supportColumns[2]['dashlets'], $guid); } } $count++; } // END ' Support Page' - bug 46195 // Set the dashlets pages to user preferences table $pageIndex = count($pages); $pages[$pageIndex]['columns'] = $salesColumns; $pages[$pageIndex]['numColumns'] = '2'; $pages[$pageIndex]['pageTitle'] = $this->mod_strings['LBL_HOME_PAGE_2_NAME']; // "Sales Page" $pageIndex++; $pages[$pageIndex]['columns'] = $marketingColumns; $pages[$pageIndex]['numColumns'] = '3'; $pages[$pageIndex]['pageTitle'] = $this->mod_strings['LBL_HOME_PAGE_6_NAME']; // "Marketing Page" $pageIndex++; $pages[$pageIndex]['columns'] = $supportColumns; $pages[$pageIndex]['numColumns'] = '4'; $pages[$pageIndex]['pageTitle'] = $this->mod_strings['LBL_HOME_PAGE_3_NAME']; // "Support Page" - bug 46195 $dashlets = array_merge($dashlets, $salesDashlets, $marketingDashlets, $supportDashlets); $current_user->setPreference('dashlets', $dashlets, 0, 'Home'); $current_user->setPreference('pages', $pages, 0, 'Home'); } // while }
function getReportCharts($category) { global $current_user; $chartsList = array(); require_once 'modules/Reports/SavedReport.php'; $sq = new SugarQuery(); $savedReportBean = BeanFactory::getBean('Reports'); $sq->from($savedReportBean); // Make sure the user isn't seeing reports they don't have access to $modules = array_keys(getACLDisAllowedModules()); if (count($modules)) { $sq->where()->notIn('module', $modules); } //create the $where statement(s) $sq->where()->notEquals('chart_type', 'none'); switch ($category) { case 'global': // build global where string $sq->where()->equals('saved_reports.team_set_id', '1'); break; case 'myTeams': // build myTeams where string $myTeams = $current_user->get_my_teams(); $teamWhere = ''; foreach ($myTeams as $team_id => $team_name) { if ($team_id != '1' && $team_id != $current_user->getPrivateTeamID()) { if ($teamWhere == '') { $teamWhere .= ' '; } else { $teamWhere .= 'OR '; } $teamWhere .= "saved_reports.team_set_id='" . $team_id . "' "; } } $sq->whereRaw($teamWhere); break; case 'mySaved': // build mySaved where string $sq->where()->equals('saved_reports.team_set_id', $current_user->getPrivateTeamID()); break; case 'myFavorites': global $current_user; $sugaFav = BeanFactory::getBean('SugarFavorites'); $current_favorites_beans = $sugaFav->getUserFavoritesByModule('Reports', $current_user); $current_favorites = array(); foreach ((array) $current_favorites_beans as $key => $val) { array_push($current_favorites, $val->record_id); } if (is_array($current_favorites) && !empty($current_favorites)) { $sq->where()->in('saved_reports.id', array_values($current_favorites)); } else { $sq->where()->in('saved_reports.id', array('-1')); } break; default: break; } //retrieve array of reports $savedReports = $savedReportBean->fetchFromQuery($sq); $chartsList = array(); if (!empty($savedReports)) { foreach ($savedReports as $savedReport) { // clint - fixes bug #20398 // only display dashlets that are from visibile modules and that the user has permission to list require_once 'include/MySugar/MySugar.php'; $myDashlet = new MySugar($savedReport->module); $displayDashlet = $myDashlet->checkDashletDisplay(); if ($displayDashlet) { $title = getReportNameTranslation($savedReport->name); $report_def = array('title' => $title, 'onclick' => 'return SUGAR.mySugar.addDashlet(\'' . $savedReport->id . '\', \'chart\', \'' . $savedReport->module . '\');'); array_push($chartsList, $report_def); } } } asort($chartsList); $this->dashlets[$category] = $chartsList; }
/** * @todo the css is not fully inherited in this file */ function retrievePage() { global $current_user, $sugar_version, $sugar_config, $sugar_flavor, $current_language; global $app_strings, $theme; // build dashlet cache file if not found if (!is_file(sugar_cached('dashlets/dashlets.php'))) { require_once 'include/Dashlets/DashletCacheBuilder.php'; $dc = new DashletCacheBuilder(); $dc->buildCache(); } require_once sugar_cached('dashlets/dashlets.php'); $pages = $current_user->getPreference('pages', $this->type); $dashlets = $current_user->getPreference('dashlets', $this->type); $count = 0; $dashletIds = array(); // collect ids to pass to javascript $display = array(); $predefinedChartsList = array('MyPipelineBySalesStageDashlet', 'OpportunitiesByLeadSourceDashlet', 'OpportunitiesByLeadSourceByOutcomeDashlet', 'OutcomeByMonthDashlet', 'PipelineBySalesStageDashlet', 'CampaignROIChartDashlet', 'MyOpportunitiesGaugeDashlet', 'MyForecastingChartDashlet', 'MyModulesUsedChartDashlet', 'MyTeamModulesUsedChartDashlet'); $pageData = array(); $chartsArray = array(); $chartStyleCSS = SugarThemeRegistry::current()->getCSSURL('chart.css'); $chartColorsXML = SugarThemeRegistry::current()->getImageURL('sugarColors.xml'); $chartStringsXML = $sugar_config['tmp_dir'] . 'chart_strings.' . $current_language . '.lang.xml'; require_once 'include/SugarCharts/SugarChartFactory.php'; $sugarChart = SugarChartFactory::getInstance(); if (!file_exists($chartStringsXML)) { $sugarChart->generateChartStrings($chartStringsXML); } $selectedPage = $_REQUEST['pageId']; $numCols = $pages[$selectedPage]['numColumns']; $trackerScript = ''; $dashletScript = ''; $trackerScriptArray = "<script>var trackerGridArray = ["; $toggleHeaderToolsetScript = ""; foreach ($pages[$selectedPage]['columns'] as $colNum => $column) { if ($colNum == $numCols) { break; } $display[$colNum]['width'] = $column['width']; $display[$colNum]['dashlets'] = array(); foreach ($column['dashlets'] as $num => $id) { if (!empty($id) && isset($dashlets[$id]) && is_file($dashlets[$id]['fileLocation'])) { // clint - fixes bug #20398 // only display dashlets that are from visibile modules and that the user has permission to list $module = 'Home'; if (isset($dashletsFiles[$dashlets[$id]['className']]['module'])) { $module = $dashletsFiles[$dashlets[$id]['className']]['module']; } $myDashlet = new MySugar($module); if ($myDashlet->checkDashletDisplay()) { require_once $dashlets[$id]['fileLocation']; if ($dashlets[$id]['className'] == 'ChartsDashlet') { $dashlet = new $dashlets[$id]['className']($id, $dashlets[$id]['reportId'], isset($dashlets[$id]['options']) ? $dashlets[$id]['options'] : array()); $chartsArray[$id] = array(); $chartsArray[$id]['id'] = $id; $chartsArray[$id]['xmlFile'] = sugar_cached("xml/") . $dashlets[$id]['reportId'] . '_saved_chart.xml'; $chartsArray[$id]['width'] = '100%'; $chartsArray[$id]['height'] = '480'; $chartsArray[$id]['styleSheet'] = $chartStyleCSS; $chartsArray[$id]['colorScheme'] = $chartColorsXML; $chartsArray[$id]['langFile'] = $chartStringsXML; } else { $dashlet = new $dashlets[$id]['className']($id, isset($dashlets[$id]['options']) ? $dashlets[$id]['options'] : array()); if (in_array($dashlets[$id]['className'], $predefinedChartsList)) { $chartsArray[$id] = array(); $chartsArray[$id]['id'] = $id; $chartsArray[$id]['xmlFile'] = $sugarChart->getXMLFileName($id); $chartsArray[$id]['width'] = '100%'; $chartsArray[$id]['height'] = '480'; $chartsArray[$id]['styleSheet'] = $chartStyleCSS; $chartsArray[$id]['colorScheme'] = $chartColorsXML; $chartsArray[$id]['langFile'] = $chartStringsXML; } } // Need to add support to dynamically display/hide dashlets // If it has a method 'shouldDisplay' we will call it to see if we should display it or not if (method_exists($dashlet, 'shouldDisplay')) { if (!$dashlet->shouldDisplay()) { // This dashlet doesn't want us to show it, skip it. continue; } } array_push($dashletIds, $id); try { $dashlet->process(); $display[$colNum]['dashlets'][$id]['display'] = $dashlet->display(); $display[$colNum]['dashlets'][$id]['displayHeader'] = $dashlet->getHeader(); $display[$colNum]['dashlets'][$id]['displayFooter'] = $dashlet->getFooter(); if ($dashlet->hasScript) { $dashletScript .= $dashlet->displayScript(); } if ($dashlets[$id]['className'] == 'TrackerDashlet') { $trackerScriptArray .= "'{$id}',"; $trackerScript = empty($trackerScript) ? $dashlet->displayScript() : $trackerScript; } $toggleHeaderToolsetScript .= "SUGAR.mySugar.attachToggleToolsetEvent('{$id}');"; } catch (Exception $ex) { $display[$colNum]['dashlets'][$id]['display'] = $ex->getMessage(); $display[$colNum]['dashlets'][$id]['displayHeader'] = $dashlet->getHeader(); $display[$colNum]['dashlets'][$id]['displayFooter'] = $dashlet->getFooter(); } } } } } $sugar_smarty = new Sugar_Smarty(); $sugar_smarty->assign('sugarVersion', $sugar_version); $sugar_smarty->assign('sugarFlavor', $sugar_flavor); $sugar_smarty->assign('currentLanguage', $GLOBALS['current_language']); $sugar_smarty->assign('serverUniqueKey', $GLOBALS['server_unique_key']); $sugar_smarty->assign('imagePath', $GLOBALS['image_path']); $sugar_smarty->assign('lblLnkHelp', $GLOBALS['app_strings']['LNK_HELP']); $sugar_smarty->assign('mod', return_module_language($current_language, 'Home')); $sugar_smarty->assign('app', $GLOBALS['app_strings']); $sugar_smarty->assign('maxCount', empty($sugar_config['max_dashboards']) ? 15 : $sugar_config['max_dashboards']); $sugar_smarty->assign('dashletCount', $count); $sugar_smarty->assign('columns', $display); $sugar_smarty->assign('selectedPage', $selectedPage); $sugar_smarty->assign('numCols', $numCols); if (!empty($sugar_config['lock_homepage']) && $sugar_config['lock_homepage'] == true) { $sugar_smarty->assign('lock_homepage', true); } $htmlOutput = $sugar_smarty->fetch('include/MySugar/tpls/retrievePage.tpl'); $json = getJSONobj(); $scriptResponse = array(); $scriptResponse['dashletScript'] = $dashletScript; $scriptResponse['newDashletsToReg'] = $dashletIds; $scriptResponse['numCols'] = sizeof($pages[$selectedPage]['columns']); //custom chart code $scriptResponse['chartsArray'] = $chartsArray; $scriptResponse['trackerScript'] = $trackerScript . (strpos($trackerScriptArray, ',') ? substr($trackerScriptArray, 0, strlen($trackerScriptArray) - 1) . ']; </script>' : $trackerScriptArray . ']; </script>'); $scriptResponse['toggleHeaderToolsetScript'] = "<script>" . $toggleHeaderToolsetScript . "</script>"; $scriptOutput = 'var scriptResponse = ' . $json->encode($scriptResponse); return $json->encode(array('html' => $htmlOutput, 'script' => $scriptOutput)); }