require "modules/landing.php"; return; } if (empty($_POST['currency'])) { flash_error("Please pick a valid currency."); require "modules/landing.php"; return; } if (empty($_POST['amount']) || preg_match("([0-9]*[.,][0-9]+|[0-9]+)", $_POST['amount']) == false) { flash_error("Please enter a valid amount."); require "modules/landing.php"; return; } try { $exists = false; Subscription::CreateFromQuery("SELECT * FROM subscriptions WHERE `EmailAddress` = :EmailAddress AND `Confirmed` = 0", array(":EmailAddress" => $_POST['email'])); $exists = true; } catch (NotFoundException $e) { $exists = false; } if ($exists) { flash_error("That e-mail address has subscribed before and is currently awaiting confirmation."); require "modules/landing.php"; return; } try { $exists = false; foreach (Subscription::FindByEmail($_POST['email']) as $sSubscription) { if ($sSubscription->sCampaignId == $sCampaign->sId && $sSubscription->sIsActive == true) { $exists = true; $sExistingSubscription = $sSubscription;
public function UpdateStatistics() { global $database, $cphp_config; if (!empty($cphp_config->debugmode) || $this->sLastStatisticsUpdate < time() - 60 * 5) { /* Update subscriber count */ if ($result = $database->CachedQuery("SELECT COUNT(*) FROM subscriptions WHERE `CampaignId` = :CampaignId AND `Confirmed` = 1 AND `Active` = 1", array(":CampaignId" => $this->sId))) { $this->uSubscriberCount = $result->data[0]["COUNT(*)"]; } /* Update total monthly donations */ try { $sSubscriptions = Subscription::CreateFromQuery("SELECT * FROM subscriptions WHERE `CampaignId` = :CampaignId AND `Confirmed` = 1 AND `Active` = 1", array(":CampaignId" => $this->sId)); $sTotalDonations = 0; foreach ($sSubscriptions as $sSubscription) { $sTotalDonations += Currency::Convert("usd", $sSubscription->sCurrency, $sSubscription->sAmount); } $this->uMonthlyTotal = $sTotalDonations; } catch (NotFoundException $e) { $this->uMonthlyTotal = 0; } /* Update donation rate */ try { $sDonationsAsked = LogEntry::CreateFromQuery("SELECT * FROM log_entries WHERE `CampaignId` = :CampaignId AND `Type` = :Type AND `Date` > DATE_SUB(NOW(), INTERVAL 1 MONTH)", array(":CampaignId" => $this->sId, ":Type" => LogEntry::DONATION_ASKED)); $have_data = true; } catch (NotFoundException $e) { /* We don't have any data to work from yet. */ $sDonationsAsked = array(); $have_data = false; } if ($have_data) { try { $sDonationsMade = LogEntry::CreateFromQuery("SELECT * FROM log_entries WHERE `CampaignId` = :CampaignId AND `Type` = :Type AND `Date` > DATE_SUB(NOW(), INTERVAL 1 MONTH)", array(":CampaignId" => $this->sId, ":Type" => LogEntry::DONATION_MADE)); $this->uDonationRate = count($sDonationsMade) / count($sDonationsAsked) * 100; $this->uHaveData = true; } catch (NotFoundException $e) { $sDonationsMade = array(); $this->uDonationRate = 0; $this->uHaveData = false; } } else { $sDonationsMade = array(); $this->uDonationRate = 100; $this->uHaveData = false; } /* Update projected monthly donations */ $this->uMonthlyProjection = $this->uMonthlyTotal * ($this->uDonationRate / 100); /* Update past-month subscription count */ if ($result = $database->CachedQuery("SELECT COUNT(*) FROM log_entries WHERE `CampaignId` = :CampaignId AND `Type` = :Type AND `Date` > DATE_SUB(NOW(), INTERVAL 1 MONTH)", array(":CampaignId" => $this->sId, ":Type" => LogEntry::SUBSCRIPTION_CONFIRMED), 0)) { $this->uPastMonthSubscriptions = $result->data[0]["COUNT(*)"]; } /* Update past-month unsubscription count */ if ($result = $database->CachedQuery("SELECT COUNT(*) FROM log_entries WHERE `CampaignId` = :CampaignId AND `Type` = :Type AND `Date` > DATE_SUB(NOW(), INTERVAL 1 MONTH)", array(":CampaignId" => $this->sId, ":Type" => LogEntry::UNSUBSCRIPTION), 0)) { $this->uPastMonthUnsubscriptions = $result->data[0]["COUNT(*)"]; } /* Update past month donation count */ $this->uPastMonthDonations = count($sDonationsMade); /* Update past month non-donation count */ $this->uPastMonthNonDonations = count($sDonationsAsked) - count($sDonationsMade); $this->uLastStatisticsUpdate = time(); $this->InsertIntoDatabase(); } }
$_APP = true; require "includes/base.php"; if (php_sapi_name() !== "cli") { http_status_code(403); die; } /* This cronjob will send out donation reminder e-mails for every user * that hasn't received an e-mail in the past month. It will also * re-generate statistics for every campaign, and store them in the * historical statistics logs. */ /* First, we will update the exchange rates. */ Currency::UpdateRates(); /* Then, we'll start out sending reminder e-mails. */ try { $sSubscriptions = Subscription::CreateFromQuery("SELECT * FROM subscriptions WHERE `Confirmed` = 1 AND `Active` = 1 AND (`LastEmail` IS NULL OR `LastEmail` < DATE_SUB(NOW(), INTERVAL 1 MONTH))"); } catch (NotFoundException $e) { $sSubscriptions = array(); } foreach ($sSubscriptions as $sSubscription) { $sSubscription->SendPaymentRequest(); } /* Now, we'll log a historical statistics snapshot for every campaign. */ try { $sCampaigns = Campaign::CreateFromQuery("SELECT * FROM campaigns"); $found = true; } catch (NotFoundException $e) { /* No campaigns are in the database yet. */ $found = false; } if ($found) {