Exemplo 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();
 }
Exemplo n.º 2
0
 function index()
 {
     Piwik::checkUserIsNotAnonymous();
     $view = Piwik_View::factory('Settings');
     $view->isSuperUser = Piwik::isUserIsSuperUser();
     $mobileMessagingAPI = Piwik_MobileMessaging_API::getInstance();
     $view->delegatedManagement = $mobileMessagingAPI->getDelegatedManagement();
     $view->credentialSupplied = $mobileMessagingAPI->areSMSAPICredentialProvided();
     $view->accountManagedByCurrentUser = $view->isSuperUser || $view->delegatedManagement;
     $view->strHelpAddPhone = Piwik_Translate('MobileMessaging_Settings_PhoneNumbers_HelpAdd', array(Piwik_Translate('UserSettings_SubmenuSettings'), Piwik_Translate('MobileMessaging_SettingsMenu')));
     if ($view->credentialSupplied && $view->accountManagedByCurrentUser) {
         $view->provider = $mobileMessagingAPI->getSMSProvider();
         $view->creditLeft = $mobileMessagingAPI->getCreditLeft();
     }
     $view->smsProviders = Piwik_MobileMessaging_SMSProvider::$availableSMSProviders;
     // construct the list of countries from the lang files
     $countries = array();
     foreach (Piwik_Common::getCountriesList() as $countryCode => $continentCode) {
         if (isset(Piwik_MobileMessaging_CountryCallingCodes::$countryCallingCodes[$countryCode])) {
             $countries[$countryCode] = array('countryName' => Piwik_CountryTranslate($countryCode), 'countryCallingCode' => Piwik_MobileMessaging_CountryCallingCodes::$countryCallingCodes[$countryCode]);
         }
     }
     $view->countries = $countries;
     $view->defaultCountry = Piwik_Common::getCountry(Piwik_LanguagesManager::getLanguageCodeForCurrentUser(), true, Piwik_IP::getIpFromHeader());
     $view->phoneNumbers = $mobileMessagingAPI->getPhoneNumbers();
     $this->setBasicVariablesView($view);
     $view->menu = Piwik_GetAdminMenu();
     echo $view->render();
 }
Exemplo n.º 3
0
 /**
  * Creates a new PDF report and schedules it. 
  * 
  * @param int $idSite 
  * @param string $description Report description
  * @param string $period Schedule frequency: day, week or month 
  * @param bool $sendToMe
  * @param string $additionalEmails Comma separated list of emails
  * @param string $reports Comma separated list of reports
  * @return int idReport generated
  */
 public function addReport($idSite, $description, $period, $reports, $emailMe = true, $additionalEmails = false)
 {
     Piwik::checkUserIsNotAnonymous();
     Piwik::checkUserHasViewAccess($idSite);
     $this->checkPeriod($period);
     $description = $this->checkDescription($description);
     $emailMe = (bool) $emailMe;
     $additionalEmails = $this->checkAdditionalEmails($additionalEmails);
     $reports = $this->checkAvailableReports($idSite, $reports);
     $db = Zend_Registry::get('db');
     $idReport = $db->fetchOne("SELECT max(idreport) + 1 \n\t\t\t\t\t\t\t\tFROM " . Piwik_Common::prefixTable('pdf'));
     if ($idReport == false) {
         $idReport = 1;
     }
     $db->insert(Piwik_Common::prefixTable('pdf'), array('idreport' => $idReport, 'idsite' => $idSite, 'login' => Piwik::getCurrentUserLogin(), 'description' => $description, 'period' => $period, 'email_me' => $emailMe, 'additional_emails' => $additionalEmails, 'reports' => $reports, 'ts_created' => Piwik_Date::now()->getDatetime(), 'deleted' => 0));
     return $idReport;
 }
Exemplo n.º 4
0
 public function sendReport($idReport, $period = false, $date = false)
 {
     Piwik::checkUserIsNotAnonymous();
     $reports = $this->getReports($idSite = false, 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();
     }
     $language = Piwik_LanguagesManager_API::getInstance()->getLanguageForUser($report['login']);
     // generate report
     list($outputFilename, $prettyDate, $websiteName, $additionalFiles) = $this->generateReport($idReport, $date, $language, self::OUTPUT_SAVE_ON_DISK, $report['period']);
     if (!file_exists($outputFilename)) {
         throw new Exception("The report file wasn't found in {$outputFilename}");
     }
     $filename = basename($outputFilename);
     $handle = fopen($outputFilename, "r");
     $contents = fread($handle, filesize($outputFilename));
     fclose($handle);
     $notificationObject = null;
     Piwik_PostEvent(self::SEND_REPORT_EVENT, $notificationObject, $notificationInfo = array(self::REPORT_TYPE_INFO_KEY => $report['type'], self::REPORT_KEY => $report, self::REPORT_CONTENT_KEY => $contents, self::FILENAME_KEY => $filename, self::PRETTY_DATE_KEY => $prettyDate, self::WEBSITE_NAME_KEY => $websiteName, self::ADDITIONAL_FILES_KEY => $additionalFiles));
     // Update flag in DB
     Zend_Registry::get('db')->update(Piwik_Common::prefixTable('report'), array('ts_last_sent' => Piwik_Date::now()->getDatetime()), "idreport = " . $report['idreport']);
     // If running from piwik.php with debug, do not delete the PDF after sending the email
     if (!isset($GLOBALS['PIWIK_TRACKER_DEBUG']) || !$GLOBALS['PIWIK_TRACKER_DEBUG']) {
         @chmod($outputFilename, 0600);
     }
 }
Exemplo n.º 5
0
 /**
  * Returns true if user with given email (userEmail) is known in the database
  *
  * @return bool true if the user is known
  */
 public function userEmailExists($userEmail)
 {
     Piwik::checkUserIsNotAnonymous();
     $count = Piwik_FetchOne("SELECT count(*) \n\t\t\t\t\t\t\t\tFROM " . Piwik_Common::prefixTable("user") . " \n\t\t\t\t\t\t\t\tWHERE email = ?", $userEmail);
     return $count != 0;
 }
Exemplo n.º 6
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);
 }
Exemplo n.º 7
0
	public function setIgnoreCookie()
	{
		Piwik::checkUserHasSomeViewAccess();
		Piwik::checkUserIsNotAnonymous();
		$this->checkTokenInUrl();
		Piwik_Tracker_IgnoreCookie::setIgnoreCookie();
		Piwik::redirectToModule('UsersManager', 'userSettings');
	}
Exemplo n.º 8
0
 /**
  * Determine if normal users can manage their own SMS API credential
  *
  * @return bool false if SMS API credential only manageable by super admin, true otherwise
  */
 public function getDelegatedManagement()
 {
     Piwik::checkUserIsNotAnonymous();
     return Piwik_GetOption(Piwik_MobileMessaging::DELEGATED_MANAGEMENT_OPTION) == 'true';
 }
Exemplo n.º 9
0
 /**
  * Returns true if user with given email (userEmail) is known in the database, or the super user
  *
  * @return bool true if the user is known
  */
 public function userEmailExists($userEmail)
 {
     Piwik::checkUserIsNotAnonymous();
     $count = Piwik_FetchOne("SELECT count(*) \n\t\t\t\t\t\t\t\tFROM " . Piwik_Common::prefixTable("user") . " \n\t\t\t\t\t\t\t\tWHERE email = ?", $userEmail);
     return $count != 0 || Piwik_Config::getInstance()->superuser['email'] == $userEmail;
 }