Example #1
0
function checkReports()
{
    $savedReportBean = new SavedReport();
    $savedReportQuery = "select * from saved_reports where deleted=0";
    $result = $savedReportBean->db->query($savedReportQuery, true, "");
    $row = $savedReportBean->db->fetchByAssoc($result);
    while ($row != null) {
        $saved_report_seed = new SavedReport();
        $saved_report_seed->retrieve($row['id'], false);
        $report = new Report($saved_report_seed->content);
        $display_columns = $report->report_def['display_columns'];
        $filters_def = $report->report_def['filters_def'];
        $group_defs = $report->report_def['group_defs'];
        if (!empty($report->report_def['order_by'])) {
            $order_by = $report->report_def['order_by'];
        } else {
            $order_by = array();
        }
        $summary_columns = $report->report_def['summary_columns'];
        $full_table_list = $report->report_def['full_table_list'];
        $owner_user = new User();
        $owner_user->retrieve($row['assigned_user_id']);
        checkEachColInArr($display_columns, $full_table_list, $row['id'], $row['name'], $owner_user->name);
        checkEachColInArr($group_defs, $full_table_list, $row['id'], $row['name'], $owner_user->name);
        checkEachColInArr($order_by, $full_table_list, $row['id'], $row['name'], $owner_user->name);
        checkEachColInArr($summary_columns, $full_table_list, $row['id'], $row['name'], $owner_user->name);
        foreach ($filters_def as $filters_def_row) {
            checkEachColInArr($filters_def_row, $full_table_list, $row['id'], $row['name'], $owner_user->name);
        }
        $row = $savedReportBean->db->fetchByAssoc($result);
    }
}
Example #2
0
 /**
  * @param $partialName
  * @param $pageSize
  * @param null|string $moduleClassName
  * @param null|string $type
  * @return Array of SavedReport models
  */
 public static function getReportsByPartialName($partialName, $pageSize, $moduleClassName = null, $type = null)
 {
     assert('is_string($partialName)');
     assert('is_int($pageSize)');
     assert('is_string($moduleClassName) || $moduleClassName == null');
     assert('is_string($type) || $type == null');
     $searchAttributeData = array();
     $searchAttributeData['clauses'] = array(1 => array('attributeName' => 'name', 'operatorType' => 'contains', 'value' => $partialName));
     $clauseCount = 2;
     if ($moduleClassName != null) {
         $searchAttributeData['clauses'][$clauseCount] = array('attributeName' => 'moduleClassName', 'operatorType' => 'equals', 'value' => $moduleClassName);
         $clauseCount++;
     }
     if ($type != null) {
         $searchAttributeData['clauses'][$clauseCount] = array('attributeName' => 'type', 'operatorType' => 'equals', 'value' => $type);
     }
     if ($clauseCount == 1) {
         $searchAttributeData['structure'] = '(1)';
     } elseif ($clauseCount == 2) {
         $searchAttributeData['structure'] = '(1 and 2)';
     } else {
         $searchAttributeData['structure'] = '(1 and 2 and 3)';
     }
     $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter('SavedReport');
     $where = RedBeanModelDataProvider::makeWhere('SavedReport', $searchAttributeData, $joinTablesAdapter);
     return SavedReport::getSubset($joinTablesAdapter, null, $pageSize, $where, 'name');
 }
 public function testGetReportsByPartialName()
 {
     $this->assertEquals(2, SavedReport::getCount());
     $this->assertEquals(2, count(ReportSearch::getReportsByPartialName('a', 5)));
     $this->assertEquals(0, count(ReportSearch::getReportsByPartialName('a', 5, 'AccountsModule')));
     $this->assertEquals(1, count(ReportSearch::getReportsByPartialName('a', 5, 'ReportsTestModule')));
     $this->assertEquals(1, count(ReportSearch::getReportsByPartialName('a', 5, 'ReportsTestModule', Report::TYPE_SUMMATION)));
     $this->assertEquals(0, count(ReportSearch::getReportsByPartialName('a', 5, 'ContactsModule', Report::TYPE_SUMMATION)));
 }
 public function actionDetails($id, $runReport = false)
 {
     $savedReport = SavedReport::getById((int) $id);
     ControllerSecurityUtil::resolveCanCurrentUserAccessModule($savedReport->moduleClassName);
     ControllerSecurityUtil::resolveAccessCanCurrentUserReadModel($savedReport, true);
     $report = SavedReportToReportAdapter::makeReportBySavedReport($savedReport);
     $portlet = Portlet::getById(intval($_GET['portletId']));
     $portlet->params = array('controllerId' => 'default', 'relationModuleId' => $this->getModule()->getId(), 'relationModel' => $report, 'redirectUrl' => Yii::app()->request->getRequestUri(), 'dataProvider' => $this->getDataProvider($report, $report->getId(), (bool) $runReport));
     $portletView = $portlet->getView();
     if (!RightsUtil::canUserAccessModule($portletView::getModuleClassName(), Yii::app()->user->userModel)) {
         $messageView = new AccessFailureView();
         $view = new AccessFailurePageView($messageView);
         echo $view->render();
         Yii::app()->end(0, false);
     }
     $view = new AjaxPageView($portletView);
     echo $view->render();
 }
Example #5
0
 public function testSetAndGetModel()
 {
     $savedReport = new SavedReport();
     $savedReport->name = 'some report';
     $savedReport->description = 'description';
     $savedReport->moduleClassName = 'moduleClassName';
     $savedReport->type = 'some type';
     $savedReport->serializedData = serialize(array('something'));
     $saved = $savedReport->save();
     $this->assertTrue($saved);
     $savedReportId = $savedReport->id;
     $savedReport->forget();
     $savedReport = SavedReport::getById($savedReportId);
     $this->assertEquals('some report', $savedReport->name);
     $this->assertEquals('description', $savedReport->description);
     $this->assertEquals('moduleClassName', $savedReport->moduleClassName);
     $this->assertEquals('some type', $savedReport->type);
     $this->assertEquals(serialize(array('something')), $savedReport->serializedData);
 }
Example #6
0
function save_from_report($report_id, $parent_id, $module_name, $relationship_attr_name)
{
    global $beanFiles;
    global $beanList;
    $GLOBALS['log']->debug("Save2: Linking with report output");
    $GLOBALS['log']->debug("Save2:Report ID=" . $report_id);
    $GLOBALS['log']->debug("Save2:Parent ID=" . $parent_id);
    $GLOBALS['log']->debug("Save2:Module Name=" . $module_name);
    $GLOBALS['log']->debug("Save2:Relationship Attribute Name=" . $relationship_attr_name);
    $bean_name = $beanList[$module_name];
    $GLOBALS['log']->debug("Save2:Bean Name=" . $bean_name);
    require_once $beanFiles[$bean_name];
    $focus = new $bean_name();
    $focus->retrieve($parent_id);
    $focus->load_relationship($relationship_attr_name);
    //fetch report definition.
    global $current_language, $report_modules, $modules_report;
    $mod_strings = return_module_language($current_language, "Reports");
    $saved = new SavedReport();
    $saved->disable_row_level_security = true;
    $saved->retrieve($report_id, false);
    //initiailize reports engine with the report definition.
    require_once 'modules/Reports/SubpanelFromReports.php';
    $report = new SubpanelFromReports($saved);
    $report->run_query();
    $sql = $report->query_list[0];
    $GLOBALS['log']->debug("Save2:Report Query=" . $sql);
    $result = $report->db->query($sql);
    while ($row = $report->db->fetchByAssoc($result)) {
        $focus->{$relationship_attr_name}->add($row['primaryid']);
    }
}
 public static function makeReportDataProviderAndResolveAttributeName($id, $pageSize, &$attributeName)
 {
     assert('is_int($pageSize)');
     $savedReport = SavedReport::getById($id);
     $report = SavedReportToReportAdapter::makeReportBySavedReport($savedReport);
     foreach ($report->getDisplayAttributes() as $key => $displayAttribute) {
         if ($displayAttribute->getAttributeIndexOrDerivedType() == 'id') {
             $attributeName = ReportResultsRowData::resolveAttributeNameByKey($key);
             break;
         }
     }
     if ($attributeName == null) {
         $moduleClassName = $report->getModuleClassName();
         $modelClassName = $moduleClassName::getPrimaryModelName();
         $displayAttribute = new DisplayAttributeForReportForm($moduleClassName, $modelClassName, $report->getType());
         $displayAttribute->attributeIndexOrDerivedType = 'id';
         $report->addDisplayAttribute($displayAttribute);
         $attributeName = ReportResultsRowData::resolveAttributeNameByKey($key + 1);
     }
     return ReportDataProviderFactory::makeByReport($report, $pageSize);
 }
 /**
  * @depends testAutoComplete
  */
 public function testDelete()
 {
     $savedReports = SavedReport::getAll();
     $this->assertEquals(3, count($savedReports));
     $this->setGetArray(array('id' => $savedReports[0]->id));
     $this->runControllerWithRedirectExceptionAndGetContent('reports/default/delete');
     $savedReports = SavedReport::getAll();
     $this->assertEquals(2, count($savedReports));
 }
 /**
  * @depends testMakeReportDataProviderAndResolveAttributeName
  */
 public function testGetContactIdsByReportDataProviderAndAttributeName()
 {
     $contactReports = SavedReport::getAll();
     $contactReport = $contactReports[0];
     $contacts = Contact::getAll();
     $attributeName = null;
     $reportDataProvider = MarketingListMembersUtil::makeReportDataProviderAndResolveAttributeName($contactReport->id, 1, $attributeName);
     $contactIds = MarketingListMembersUtil::getContactIdsByReportDataProviderAndAttributeName($reportDataProvider, $attributeName);
     $this->assertCount(1, $contactIds);
     $attributeName = null;
     $reportDataProvider = MarketingListMembersUtil::makeReportDataProviderAndResolveAttributeName($contactReport->id, 2, $attributeName);
     $contactIds = MarketingListMembersUtil::getContactIdsByReportDataProviderAndAttributeName($reportDataProvider, $attributeName);
     $this->assertCount(2, $contactIds);
     $this->assertContains($contacts[0]->id, $contactIds);
     $this->assertContains($contacts[1]->id, $contactIds);
 }
 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
 }
 protected function resolveSavedReportAndReportByPostData(array $postData, &$savedReport, &$report, $type, $id = null, $isBeingCopied = false)
 {
     if ($id == null) {
         $this->resolveCanCurrentUserAccessReports();
         $savedReport = new SavedReport();
         $report = new Report();
         $report->setType($type);
     } elseif ($isBeingCopied) {
         $savedReport = new SavedReport();
         $oldReport = SavedReport::getById(intval($id));
         ControllerSecurityUtil::resolveAccessCanCurrentUserReadModel($oldReport);
         SavedReportCopyModelUtil::copy($oldReport, $savedReport);
         $report = SavedReportToReportAdapter::makeReportBySavedReport($savedReport);
     } else {
         $savedReport = SavedReport::getById(intval($id));
         ControllerSecurityUtil::resolveAccessCanCurrentUserWriteModel($savedReport);
         $report = SavedReportToReportAdapter::makeReportBySavedReport($savedReport);
     }
     DataToReportUtil::resolveReportByWizardPostData($report, $postData, ReportToWizardFormAdapter::getFormClassNameByType($type));
 }
Example #12
0
 /**
  * Displays the javascript for the dashlet
  * 
  * @return string javascript to use with this dashlet
  */
 function displayScript()
 {
     require_once "modules/Reports/Report.php";
     $chartReport = new SavedReport();
     $chartExists = $chartReport->retrieve($this->report_id, false);
     if (!is_null($chartExists)) {
         $this->title = $chartReport->name;
         require_once "modules/Reports/templates/templates_chart.php";
         $reporter = new Report($chartReport->content);
         $reporter->is_saved_report = true;
         $reporter->saved_report_id = $chartReport->id;
         $xmlFile = get_cache_file_name($reporter);
         $ss = new Sugar_Smarty();
         $ss->assign('chartName', $this->id);
         $ss->assign('chartXMLFile', $xmlFile);
         $ss->assign('chartStyleCSS', SugarThemeRegistry::current()->getCSSURL('chart.css'));
         $ss->assign('chartColorsXML', SugarThemeRegistry::current()->getImageURL('sugarColors.xml'));
         $ss->assign('chartLangFile', $GLOBALS['sugar_config']['tmp_dir'] . 'chart_strings.' . $GLOBALS['current_language'] . '.lang.xml');
         $str = $ss->fetch('modules/Home/Dashlets/ChartsDashlet/ChartsDashletScript.tpl');
         return $str;
     }
 }
 public function testRegularUserControllerActionsWithElevationToEdit()
 {
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     $nobody = User::getByUsername('nobody');
     $group1 = Group::getByName('Group1');
     $nobody->setRight('AccountsModule', AccountsModule::RIGHT_ACCESS_ACCOUNTS);
     $nobody->setRight('AccountsModule', AccountsModule::RIGHT_CREATE_ACCOUNTS);
     $nobody->setRight('ReportsModule', ReportsModule::RIGHT_ACCESS_REPORTS);
     $nobody->setRight('ReportsModule', ReportsModule::RIGHT_CREATE_REPORTS);
     $nobody->setRight('ReportsModule', ReportsModule::RIGHT_DELETE_REPORTS);
     assert($nobody->save());
     // Not Coding Standard
     $savedReports = SavedReport::getAll();
     $this->assertEquals(0, count($savedReports));
     $nobody = $this->logoutCurrentUserLoginNewUserAndGetByUsername('nobody');
     $content = $this->runControllerWithExitExceptionAndGetContent('reports/default/create');
     $this->assertContains('Rows and Columns Report', $content);
     $this->assertContains('Summation Report', $content);
     $this->assertContains('Matrix Report', $content);
     $this->setGetArray(array('type' => 'RowsAndColumns'));
     $this->resetPostArray();
     $content = $this->runControllerWithNoExceptionsAndGetContent('reports/default/create');
     $this->assertContains('Accounts', $content);
     $this->setGetArray(array('type' => 'RowsAndColumns'));
     $postData = static::makeRowsAndColumnsReportPostData();
     $postData['save'] = 'save';
     $postData['ajax'] = 'edit-form';
     $this->setPostArray($postData);
     $content = $this->runControllerWithExitExceptionAndGetContent('reports/default/save');
     $this->assertEquals('[]', $content);
     $postData = static::makeRowsAndColumnsReportPostData();
     $postData['save'] = 'save';
     $this->setPostArray($postData);
     $this->runControllerWithExitExceptionAndGetContent('reports/default/save');
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     $savedReports = SavedReport::getAll();
     $this->assertEquals(1, count($savedReports));
     $nobody = $this->logoutCurrentUserLoginNewUserAndGetByUsername('nobody');
     $savedReports = SavedReport::getAll();
     $this->assertEquals(1, count($savedReports));
     $this->setGetArray(array('id' => $savedReports[0]->id));
     $this->resetPostArray();
     $this->runControllerWithNoExceptionsAndGetContent('reports/default/details');
     $this->setGetArray(array('id' => $savedReports[0]->id));
     $this->resetPostArray();
     $this->runControllerWithNoExceptionsAndGetContent('reports/default/edit');
     //Save an existing report
     $this->setGetArray(array('type' => 'RowsAndColumns', 'id' => $savedReports[0]->id));
     $postData = static::makeRowsAndColumnsReportPostData();
     $postData['save'] = 'save';
     $this->setPostArray($postData);
     $this->runControllerWithExitExceptionAndGetContent('reports/default/save');
     $this->assertEquals(1, count($savedReports));
     //Clone existing report
     $this->setGetArray(array('type' => 'RowsAndColumns', 'id' => $savedReports[0]->id, 'isBeingCopied' => '1'));
     $postData = static::makeRowsAndColumnsReportPostData();
     $postData['save'] = 'save';
     $this->setPostArray($postData);
     $this->runControllerWithExitExceptionAndGetContent('reports/default/save');
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     $savedReports = SavedReport::getAll();
     $this->assertEquals(2, count($savedReports));
 }
 public function testCloneSetsRightPermissions()
 {
     // create users and groups.
     $everyoneGroup = Group::getByName(Group::EVERYONE_GROUP_NAME);
     $everyoneGroup->setRight('ReportsModule', ReportsModule::getAccessRight());
     $everyoneGroup->setRight('AccountsModule', AccountsModule::RIGHT_ACCESS_ACCOUNTS);
     $this->assertTrue($everyoneGroup->save());
     $everyoneGroup->forgetAll();
     $jim = UserTestHelper::createBasicUser('jim');
     $john = UserTestHelper::createBasicUser('john');
     $johnGroup = new Group();
     $johnGroup->name = 'John Group';
     $johnGroup->users->add($john);
     $this->assertTrue($johnGroup->save());
     $john->forgetAll();
     $johnGroup->forgetAll();
     $john = User::getByUsername('john');
     $johnGroup = Group::getByName('John Group');
     $basePostData = static::makeRowsAndColumnsReportPostDataForAccounts();
     $basePostData['save'] = 'save';
     $description = StringUtil::generateRandomString(40);
     // create a report with everyone group permission, ensure everyone can access it.
     // clone it, ensure everyone group can still access it.
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     SavedReport::deleteAll();
     $modelSpecificPostData = array('RowsAndColumnsReportWizardForm' => array('name' => 'Everyone Report 01', 'description' => $description, 'ownerId' => $super->id, 'ownerName' => strval($super), 'explicitReadWriteModelPermissions' => array('type' => ExplicitReadWriteModelPermissionsUtil::MIXED_TYPE_EVERYONE_GROUP, 'nonEveryoneGroup' => null)));
     $postData = CMap::mergeArray($basePostData, $modelSpecificPostData);
     $this->setGetArray(array('type' => 'RowsAndColumns'));
     $this->setPostArray($postData);
     $this->runControllerWithExitExceptionAndGetContent('/reports/default/save');
     ForgetAllCacheUtil::forgetAllCaches();
     $savedReports = SavedReport::getAll();
     $this->assertCount(1, $savedReports);
     $this->assertEquals(Permission::ALL, $savedReports[0]->getEffectivePermissions($super));
     $this->assertEquals(Permission::READ_WRITE_CHANGE_PERMISSIONS_CHANGE_OWNER, $savedReports[0]->getEffectivePermissions($everyoneGroup));
     $this->assertEquals(Permission::READ_WRITE_CHANGE_PERMISSIONS_CHANGE_OWNER, $savedReports[0]->getEffectivePermissions($jim));
     // ensure jim can access it.
     $this->logoutCurrentUserLoginNewUserAndGetByUsername('jim');
     $this->resetPostArray();
     $this->resetGetArray();
     $content = $this->runControllerWithNoExceptionsAndGetContent('/reports/default/list');
     $this->assertContains($postData['RowsAndColumnsReportWizardForm']['name'], $content);
     $this->assertEquals(substr_count($content, $postData['RowsAndColumnsReportWizardForm']['name']), 1);
     $this->setGetArray(array('id' => $savedReports[0]->id));
     $content = $this->runControllerWithNoExceptionsAndGetContent('/reports/default/details');
     $this->assertContains($postData['RowsAndColumnsReportWizardForm']['name'], $content);
     $this->assertEquals(substr_count($content, $postData['RowsAndColumnsReportWizardForm']['name']), 3);
     // clone the report.
     $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     $this->setGetArray(array('type' => 'RowsAndColumns', 'id' => $savedReports[0]->id, 'isBeingCopied' => '1'));
     $postData['RowsAndColumnsReportWizardForm']['name'] = 'Cloned ' . $postData['RowsAndColumnsReportWizardForm']['name'];
     $this->setPostArray($postData);
     $this->runControllerWithExitExceptionAndGetContent('/reports/default/save');
     ForgetAllCacheUtil::forgetAllCaches();
     $savedReports = SavedReport::getAll();
     $this->assertCount(2, $savedReports);
     $sourcePermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem($savedReports[0]);
     $clonePermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem($savedReports[1]);
     $this->assertEquals($sourcePermissions, $clonePermissions);
     $this->assertEquals(Permission::ALL, $savedReports[1]->getEffectivePermissions($super));
     $this->assertEquals(Permission::READ_WRITE_CHANGE_PERMISSIONS_CHANGE_OWNER, $savedReports[1]->getEffectivePermissions($everyoneGroup));
     $this->assertEquals(Permission::READ_WRITE_CHANGE_PERMISSIONS_CHANGE_OWNER, $savedReports[1]->getEffectivePermissions($jim));
     // ensure jim can access it.
     $this->logoutCurrentUserLoginNewUserAndGetByUsername('jim');
     $this->resetPostArray();
     $this->resetGetArray();
     $content = $this->runControllerWithNoExceptionsAndGetContent('/reports/default/list');
     $this->assertContains($postData['RowsAndColumnsReportWizardForm']['name'], $content);
     $this->assertEquals(substr_count($content, $postData['RowsAndColumnsReportWizardForm']['name']), 1);
     $this->setGetArray(array('id' => $savedReports[1]->id));
     $content = $this->runControllerWithNoExceptionsAndGetContent('/reports/default/details');
     $this->assertContains($postData['RowsAndColumnsReportWizardForm']['name'], $content);
     $this->assertEquals(substr_count($content, $postData['RowsAndColumnsReportWizardForm']['name']), 3);
     // create a report with specific group permissions, ensure only members of that group can access it.
     // clone it, ensure only that specific group members can access it.
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     SavedReport::deleteAll();
     $modelSpecificPostData = array('RowsAndColumnsReportWizardForm' => array('name' => 'Group Specific Report 01', 'description' => $description, 'ownerId' => $super->id, 'ownerName' => strval($super), 'explicitReadWriteModelPermissions' => array('type' => ExplicitReadWriteModelPermissionsUtil::MIXED_TYPE_NONEVERYONE_GROUP, 'nonEveryoneGroup' => $johnGroup->id)));
     $postData = CMap::mergeArray($basePostData, $modelSpecificPostData);
     $this->setGetArray(array('type' => 'RowsAndColumns'));
     $this->setPostArray($postData);
     $this->runControllerWithExitExceptionAndGetContent('/reports/default/save');
     ForgetAllCacheUtil::forgetAllCaches();
     $savedReports = SavedReport::getAll();
     $this->assertCount(1, $savedReports);
     $this->assertEquals(Permission::ALL, $savedReports[0]->getEffectivePermissions($super));
     $this->assertEquals(Permission::NONE, $savedReports[0]->getEffectivePermissions($everyoneGroup));
     $this->assertEquals(Permission::NONE, $savedReports[0]->getEffectivePermissions($jim));
     $this->assertEquals(Permission::READ_WRITE_CHANGE_PERMISSIONS_CHANGE_OWNER, $savedReports[0]->getEffectivePermissions($johnGroup));
     $this->assertEquals(Permission::READ_WRITE_CHANGE_PERMISSIONS_CHANGE_OWNER, $savedReports[0]->getEffectivePermissions($john));
     // ensure john can access it.
     $this->logoutCurrentUserLoginNewUserAndGetByUsername('john');
     $this->resetPostArray();
     $this->resetGetArray();
     $content = $this->runControllerWithNoExceptionsAndGetContent('/reports/default/list');
     $this->assertContains($postData['RowsAndColumnsReportWizardForm']['name'], $content);
     $this->assertEquals(substr_count($content, $postData['RowsAndColumnsReportWizardForm']['name']), 1);
     $this->setGetArray(array('id' => $savedReports[0]->id));
     $content = $this->runControllerWithNoExceptionsAndGetContent('/reports/default/details');
     $this->assertContains($postData['RowsAndColumnsReportWizardForm']['name'], $content);
     $this->assertEquals(substr_count($content, $postData['RowsAndColumnsReportWizardForm']['name']), 3);
     // ensure jim can not access it.
     $this->logoutCurrentUserLoginNewUserAndGetByUsername('jim');
     $this->resetGetArray();
     $content = $this->runControllerWithNoExceptionsAndGetContent('/reports/default/list');
     $this->assertNotContains($postData['RowsAndColumnsReportWizardForm']['name'], $content);
     $this->setGetArray(array('id' => $savedReports[0]->id));
     $this->runControllerWithAccessDeniedSecurityExceptionAndGetContent('/reports/default/details');
     // clone the report.
     $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     $this->setGetArray(array('type' => 'RowsAndColumns', 'id' => $savedReports[0]->id, 'isBeingCopied' => '1'));
     $postData['RowsAndColumnsReportWizardForm']['name'] = 'Cloned ' . $postData['RowsAndColumnsReportWizardForm']['name'];
     $this->setPostArray($postData);
     $this->runControllerWithExitExceptionAndGetContent('/reports/default/save');
     ForgetAllCacheUtil::forgetAllCaches();
     $savedReports = SavedReport::getAll();
     $this->assertCount(2, $savedReports);
     $sourcePermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem($savedReports[0]);
     $clonePermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem($savedReports[1]);
     $this->assertEquals($sourcePermissions, $clonePermissions);
     $this->assertEquals(Permission::ALL, $savedReports[1]->getEffectivePermissions($super));
     $this->assertEquals(Permission::NONE, $savedReports[1]->getEffectivePermissions($everyoneGroup));
     $this->assertEquals(Permission::NONE, $savedReports[1]->getEffectivePermissions($jim));
     $this->assertEquals(Permission::READ_WRITE_CHANGE_PERMISSIONS_CHANGE_OWNER, $savedReports[1]->getEffectivePermissions($johnGroup));
     $this->assertEquals(Permission::READ_WRITE_CHANGE_PERMISSIONS_CHANGE_OWNER, $savedReports[1]->getEffectivePermissions($john));
     // ensure john can access it.
     $this->logoutCurrentUserLoginNewUserAndGetByUsername('john');
     $this->resetPostArray();
     $this->resetGetArray();
     $content = $this->runControllerWithNoExceptionsAndGetContent('/reports/default/list');
     $this->assertContains($postData['RowsAndColumnsReportWizardForm']['name'], $content);
     $this->assertEquals(substr_count($content, $postData['RowsAndColumnsReportWizardForm']['name']), 1);
     $this->setGetArray(array('id' => $savedReports[1]->id));
     $content = $this->runControllerWithNoExceptionsAndGetContent('/reports/default/details');
     $this->assertContains($postData['RowsAndColumnsReportWizardForm']['name'], $content);
     $this->assertEquals(substr_count($content, $postData['RowsAndColumnsReportWizardForm']['name']), 3);
     // ensure jim can not access it.
     $this->logoutCurrentUserLoginNewUserAndGetByUsername('jim');
     $this->resetGetArray();
     $content = $this->runControllerWithNoExceptionsAndGetContent('/reports/default/list');
     $this->assertNotContains($postData['RowsAndColumnsReportWizardForm']['name'], $content);
     $this->setGetArray(array('id' => $savedReports[0]->id));
     $this->runControllerWithAccessDeniedSecurityExceptionAndGetContent('/reports/default/details');
 }
 /**
  * @depends testResolveReportToSavedReport
  */
 public function testMakeReportBySavedReport()
 {
     $billy = User::getByUsername('billy');
     $savedReports = SavedReport::getAll();
     $this->assertEquals(1, count($savedReports));
     $savedReport = $savedReports[0];
     $report = SavedReportToReportAdapter::makeReportBySavedReport($savedReport);
     $filters = $report->getFilters();
     $groupBys = $report->getGroupBys();
     $orderBys = $report->getOrderBys();
     $displayAttributes = $report->getDisplayAttributes();
     $drillDownDisplayAttributes = $report->getDrillDownDisplayAttributes();
     $this->assertEquals('ReportsTestModule', $report->getModuleClassName());
     $this->assertEquals('myFirstReport', $report->getName());
     $this->assertEquals('aDescription', $report->getDescription());
     $this->assertEquals(Report::TYPE_ROWS_AND_COLUMNS, $report->getType());
     $this->assertEquals('1 and 2 or 3', $report->getFiltersStructure());
     $this->assertTrue($report->getOwner()->isSame($billy));
     $this->assertCount(4, $filters);
     $this->assertCount(1, $groupBys);
     $this->assertCount(1, $orderBys);
     $this->assertCount(1, $displayAttributes);
     $this->assertCount(1, $drillDownDisplayAttributes);
     $this->assertEquals(true, $filters[0]->availableAtRunTime);
     $this->assertEquals('aValue', $filters[0]->value);
     $this->assertEquals('string', $filters[0]->attributeIndexOrDerivedType);
     $this->assertNull($filters[0]->currencyIdForValue);
     $this->assertNull($filters[0]->secondValue);
     $this->assertNull($filters[0]->stringifiedModelForValue);
     $this->assertNull($filters[0]->valueType);
     $this->assertEquals('equals', $filters[0]->operator);
     $this->assertEquals(true, $filters[1]->availableAtRunTime);
     $this->assertEquals('aValue', $filters[1]->value);
     $this->assertEquals('currencyValue', $filters[1]->attributeIndexOrDerivedType);
     $this->assertEquals(4, $filters[1]->currencyIdForValue);
     $this->assertEquals('bValue', $filters[1]->secondValue);
     $this->assertNull($filters[1]->stringifiedModelForValue);
     $this->assertNull($filters[1]->valueType);
     $this->assertEquals('between', $filters[1]->operator);
     $this->assertEquals(false, $filters[2]->availableAtRunTime);
     $this->assertEquals('aValue', $filters[2]->value);
     $this->assertEquals('owner__User', $filters[2]->attributeIndexOrDerivedType);
     $this->assertNull($filters[2]->currencyIdForValue);
     $this->assertNull($filters[2]->secondValue);
     $this->assertEquals('someName', $filters[2]->stringifiedModelForValue);
     $this->assertNull($filters[2]->valueType);
     $this->assertNull($filters[2]->operator);
     $this->assertEquals(true, $filters[3]->availableAtRunTime);
     $this->assertEquals('aValue', $filters[3]->value);
     $this->assertEquals('createdDateTime', $filters[3]->attributeIndexOrDerivedType);
     $this->assertNull($filters[3]->currencyIdForValue);
     $this->assertEquals('bValue', $filters[3]->secondValue);
     $this->assertNull($filters[3]->stringifiedModelForValue);
     $this->assertNull($filters[3]->operator);
     $this->assertEquals('Between', $filters[3]->valueType);
     $this->assertEquals('url', $orderBys[0]->attributeIndexOrDerivedType);
     $this->assertEquals('desc', $orderBys[0]->order);
     $this->assertEquals('lastName', $groupBys[0]->attributeIndexOrDerivedType);
     $this->assertEquals('y', $groupBys[0]->axis);
     $this->assertEquals('phone', $displayAttributes[0]->attributeIndexOrDerivedType);
     $this->assertEquals('someNewLabel', $displayAttributes[0]->label);
     $this->assertEquals('firstName', $drillDownDisplayAttributes[0]->attributeIndexOrDerivedType);
     $this->assertEquals('someNewLabel', $drillDownDisplayAttributes[0]->label);
 }
Example #16
0
 /**
  * @static
  * @param SavedReport $report
  * @return string
  */
 public static function Serialize(SavedReport $report)
 {
     $template = 'usage=%s;selection=%s;groupby=%s;range=%s;range_start=%s;range_end=%s;resourceid=%s;scheduleid=%s;userid=%s;groupid=%s;accessoryid=%s;participantid=%s';
     return sprintf($template, $report->Usage(), $report->Selection(), $report->GroupBy(), $report->Range(), $report->RangeStart()->ToDatabase(), $report->RangeEnd()->ToDatabase(), $report->ResourceId(), $report->ScheduleId(), $report->UserId(), $report->GroupId(), $report->AccessoryId(), $report->ParticipantId());
 }
 private function resolveSavedReportAndWarningData()
 {
     try {
         $savedReport = SavedReport::getById((int) $this->getSavedReportId());
         if (!ControllerSecurityUtil::doesCurrentUserHavePermissionOnSecurableItem($savedReport, Permission::READ)) {
             $this->warningMessage = Zurmo::t('ReportsModule', 'You have tried to access a report you do not have access to');
         } else {
             $report = SavedReportToReportAdapter::makeReportBySavedReport($savedReport);
             if ($report->getChart()->type == null) {
                 $this->warningMessage = Zurmo::t('ReportsModule', 'This report does not have a chart to display');
             } else {
                 $this->savedReport = $savedReport;
             }
         }
     } catch (NotFoundException $e) {
         $this->warningMessage = Zurmo::t('ReportsModule', 'You have tried to access a report that is no longer available');
     } catch (AccessDeniedSecurityException $e) {
         $this->warningMessage = Zurmo::t('ReportsModule', 'You have tried to access a report you do not have access to');
     }
     $this->savedReportHasBeenResolved = true;
 }
Example #18
0
 public function __construct()
 {
     parent::__construct('fake', 1, new Report_Usage(Report_Usage::ACCESSORIES), new Report_ResultSelection(Report_ResultSelection::COUNT), new Report_GroupBy(Report_GroupBy::NONE), new Report_Range(Report_Range::ALL_TIME, Date::Now(), Date::Now()), new Report_Filter(null, null, null, null, null, null));
 }
Example #19
0
 /**
  * @param int $reportId
  * @param int $userId
  * @return SavedReport
  */
 public function LoadSavedReportForUser($reportId, $userId)
 {
     $reader = ServiceLocator::GetDatabase()->Query(new GetSavedReportForUserCommand($reportId, $userId));
     if ($row = $reader->GetRow()) {
         return SavedReport::FromDatabase($row[ColumnNames::REPORT_NAME], $row[ColumnNames::USER_ID], Date::FromDatabase($row[ColumnNames::DATE_CREATED]), $row[ColumnNames::REPORT_DETAILS], $row[ColumnNames::REPORT_ID]);
     } else {
         return null;
     }
 }
Example #20
0
 /**
  * Displays the javascript for the dashlet
  * 
  * @return string javascript to use with this dashlet
  */
 function displayScript()
 {
     require_once "modules/Reports/Report.php";
     $chartReport = new SavedReport();
     $chartExists = $chartReport->retrieve($this->report_id, false);
     if (!is_null($chartExists)) {
         $this->title = $chartReport->name;
         require_once "modules/Reports/templates/templates_chart.php";
         require_once 'include/SugarCharts/SugarChartFactory.php';
         $sugarChart = SugarChartFactory::getInstance();
         $reporter = new Report($chartReport->content);
         $reporter->is_saved_report = true;
         $reporter->saved_report_id = $chartReport->id;
         $xmlFile = get_cache_file_name($reporter);
         $str = $sugarChart->getDashletScript($this->id, $xmlFile);
         return $str;
     }
 }
 public function testLoadsSingleReportForUser()
 {
     $userId = 100;
     $reportId = 1;
     $reportName = 'report2';
     $date = Date::Now();
     $expectedReport1 = new SavedReport($reportName, $userId, new Report_Usage(Report_Usage::ACCESSORIES), new Report_ResultSelection(Report_ResultSelection::COUNT), new Report_GroupBy(Report_GroupBy::GROUP), new Report_Range(Report_Range::DATE_RANGE, Date::Now()->ToUtc(), Date::Now()->ToUtc()), new Report_Filter(12, 11, 896, 123, 45234, 111));
     $expectedReport1->WithDateCreated($date->ToUtc());
     $expectedReport1->WithId($reportId);
     $serialized1 = ReportSerializer::Serialize($expectedReport1);
     $rows = new SavedReportRow();
     $rows->With($userId, $reportName, $date->ToDatabase(), $serialized1, $reportId);
     $this->db->SetRows($rows->Rows());
     $report = $this->repository->LoadSavedReportForUser($reportId, $userId);
     $expectedCommand = new GetSavedReportForUserCommand($reportId, $userId);
     $this->assertEquals($expectedCommand, $this->db->_LastCommand);
     $this->assertEquals($expectedReport1, $report);
 }