Esempio n. 1
0
 public function index()
 {
     Piwik::checkUserIsNotAnonymous();
     $view = Piwik_View::factory('index');
     $this->setGeneralVariablesView($view);
     $view->currentUserEmail = Piwik::getCurrentUserEmail();
     $availableReports = Piwik_API_API::getInstance()->getReportMetadata($this->idSite);
     $reportsByCategory = array();
     foreach ($availableReports as $report) {
         $reportsByCategory[$report['category']][] = $report;
     }
     unset($reportsByCategory['API']);
     $reports = Piwik_PDFReports_API::getInstance()->getReports($this->idSite, $period = false, $idReport = false, $ifSuperUserReturnOnlySuperUserReports = true);
     $reportsById = array();
     foreach ($reports as &$report) {
         $report['additional_emails'] = str_replace(',', "\n", $report['additional_emails']);
         $report['reports'] = explode(',', str_replace('.', '_', $report['reports']));
         $reportsById[$report['idreport']] = $report;
     }
     $view->downloadOutputType = Piwik_PDFReports_API::OUTPUT_DOWNLOAD;
     $columnsCount = 2;
     $view->newColumnAfter = ceil(count($reportsByCategory) / $columnsCount);
     $view->reportsByCategory = $reportsByCategory;
     $view->reportsJSON = Piwik_Common::json_encode($reportsById);
     $view->periods = array_merge(array('never' => Piwik_Translate('General_Never')), Piwik_PDFReports_API::getPeriodToFrequency());
     $view->defaultFormat = Piwik_PDFReports::DEFAULT_FORMAT;
     $view->formats = Piwik_ReportRenderer::$availableReportRenderers;
     $view->aggregateReportsFormats = Piwik_PDFReports_API::getAggregateReportsFormats();
     $view->reports = $reports;
     $view->language = Piwik_LanguagesManager::getLanguageCodeForCurrentUser();
     echo $view->render();
 }
Esempio n. 2
0
 public function sendEmailReport($idReport, $idSite, $period = false, $date = false)
 {
     Piwik::checkUserIsNotAnonymous();
     $reports = $this->getReports($idSite, false, $idReport);
     $report = reset($reports);
     if ($report['period'] == 'never') {
         $report['period'] = 'day';
     }
     if (!empty($period)) {
         $report['period'] = $period;
     }
     if (empty($date)) {
         $date = Piwik_Date::now()->subPeriod(1, $report['period'])->toString();
     }
     // Get user emails and languages
     $emails = self::getEmailsFromString($report['additional_emails']);
     if ($report['email_me'] == 1) {
         if (Piwik::getCurrentUserLogin() == $report['login']) {
             $emails[] = Piwik::getCurrentUserEmail();
         } elseif ($report['login'] == Piwik_Config::getInstance()->superuser['login']) {
             $emails[] = Piwik::getSuperUserEmail();
         } else {
             try {
                 $user = Piwik_UsersManager_API::getInstance()->getUser($report['login']);
             } catch (Exception $e) {
                 return;
             }
             $emails[] = $user['email'];
         }
     }
     $language = Piwik_LanguagesManager_API::getInstance()->getLanguageForUser($report['login']);
     list($outputFilename, $prettyDate, $websiteName, $reportFormat, $additionalFiles) = $this->generateReport($idReport, $date, $idSite, $language, self::OUTPUT_SAVE_ON_DISK, $report['period']);
     $this->sendReportEmail($emails, $outputFilename, $prettyDate, $websiteName, $report, $reportFormat, $additionalFiles);
 }
Esempio n. 3
0
 /**
  * @param Piwik_Event_Notification $notification notification object
  */
 public static function template_reportParametersPDFReports($notification)
 {
     $out =& $notification->getNotificationObject();
     $view = Piwik_View::factory('report_parameters');
     $view->currentUserEmail = Piwik::getCurrentUserEmail();
     $view->displayFormats = self::getDisplayFormats();
     $view->reportType = self::EMAIL_TYPE;
     $view->defaultDisplayFormat = self::DEFAULT_DISPLAY_FORMAT;
     $view->defaultEmailMe = self::EMAIL_ME_PARAMETER_DEFAULT_VALUE;
     $out .= $view->render();
 }
Esempio n. 4
0
 public function sendEmailReport($idReport, $idSite)
 {
     $reports = $this->getReports($idSite, $period = false, $idReport);
     $report = reset($reports);
     if ($report['period'] == 'never') {
         $report['period'] = 'day';
     }
     // Get user emails and languages
     $emails = self::getEmailsFromString($report['additional_emails']);
     if ($report['email_me'] == 1) {
         if (Piwik::getCurrentUserLogin() == $report['login']) {
             $emails[] = Piwik::getCurrentUserEmail();
         } elseif ($report['login'] == Zend_Registry::get('config')->superuser->login) {
             $emails[] = Zend_Registry::get('config')->superuser->email;
         } else {
             try {
                 $user = Piwik_UsersManager_API::getInstance()->getUser($report['login']);
             } catch (Exception $e) {
                 return;
             }
             $emails[] = $user['email'];
         }
     }
     $language = Piwik_LanguagesManager_API::getInstance()->getLanguageForUser($report['login']);
     list($outputFilename, $prettyDate, $websiteName) = $this->generateReport($idReport, Piwik_Date::now()->subPeriod(1, $report['period'])->toString(), $idSite, $language, $outputType = Piwik_PDFReports_API::OUTPUT_PDF_SAVE_ON_DISK);
     $this->sendReportEmailPdfAttached($emails, $outputFilename, $prettyDate, $websiteName, $report);
 }