Subscription management

master
Sven Slootweg 11 years ago
parent 94c1047805
commit 1fb10f6c44

@ -0,0 +1,25 @@
<?php
/*
* ReDonate is more free software. It is licensed under the WTFPL, which
* allows you to do pretty much anything with it, without having to
* ask permission. Commercial use is allowed, and no attribution is
* required. We do politely request that you share your modifications
* to benefit other developers, but you are under no enforced
* obligation to do so :)
*
* Please read the accompanying LICENSE document for the full WTFPL
* licensing text.
*/
if(!isset($_APP)) { die("Unauthorized."); }
try
{
$sSubscription = Subscription::FindByEmail($router->uParameters[1], $router->uParameters[2]);
}
catch (NotFoundException $e)
{
throw new RouterException("No such subscription was found.");
}
$sRouterAuthenticated = true;

@ -36,15 +36,24 @@ class Subscription extends CPHPDatabaseRecordClass
'LastEmailDate' => "LastEmail"
),
'boolean' => array(
'IsConfirmed' => "Confirmed"
'IsConfirmed' => "Confirmed",
'IsActive' => "Active"
),
'campaign' => array(
'Campaign' => "CampaignId"
)
);
public static function FindByEmail($email)
public static function FindByEmail($email, $key = "", $expiry = 0)
{
return self::CreateFromQuery("SELECT * FROM subscriptions WHERE `EmailAddress` = :EmailAddress", array(':EmailAddress' => $email), 0);
if(empty($key))
{
return self::CreateFromQuery("SELECT * FROM subscriptions WHERE `EmailAddress` = :EmailAddress", array(':EmailAddress' => $email), $expiry);
}
else
{
return self::CreateFromQuery("SELECT * FROM subscriptions WHERE `EmailAddress` = :EmailAddress AND `SettingsKey` = :SettingsKey",
array(':EmailAddress' => $email, ':SettingsKey' => $key), $expiry, true);
}
}
}

@ -0,0 +1,16 @@
<?php
/*
* ReDonate is more free software. It is licensed under the WTFPL, which
* allows you to do pretty much anything with it, without having to
* ask permission. Commercial use is allowed, and no attribution is
* required. We do politely request that you share your modifications
* to benefit other developers, but you are under no enforced
* obligation to do so :)
*
* Please read the accompanying LICENSE document for the full WTFPL
* licensing text.
*/
if(!isset($_APP)) { die("Unauthorized."); }
throw new NotFoundException("No such subscription was found.");

@ -50,7 +50,7 @@ try
foreach(Subscription::FindByEmail($_POST['email']) as $sSubscription)
{
if($sSubscription->sCampaignId == $sCampaign->sId)
if($sSubscription->sCampaignId == $sCampaign->sId && $sSubscription->sIsActive == true)
{
$exists = true;
}

@ -0,0 +1,43 @@
<?php
/*
* ReDonate is more free software. It is licensed under the WTFPL, which
* allows you to do pretty much anything with it, without having to
* ask permission. Commercial use is allowed, and no attribution is
* required. We do politely request that you share your modifications
* to benefit other developers, but you are under no enforced
* obligation to do so :)
*
* Please read the accompanying LICENSE document for the full WTFPL
* licensing text.
*/
if(!isset($_APP)) { die("Unauthorized."); }
if(!empty($_POST['submit']))
{
if(empty($_POST['currency']))
{
flash_error("Please select a valid currency.");
}
if(empty($_POST['amount']) || preg_match("([0-9]*[.,][0-9]+|[0-9]+)", $_POST['amount']) == false)
{
flash_error("Please enter a valid amount.");
}
if(count(get_errors(false)) == 0)
{
$sSubscription->uAmount = str_replace(",", ".", $_POST['amount']);
$sSubscription->uCurrency = $_POST['currency'];
$sSubscription->InsertIntoDatabase();
flash_notice("The monthly pledge amount for this subscription was successfully updated.");
redirect("/manage/{$sSubscription->sEmailAddress}/{$sSubscription->sSettingsKey}");
}
}
$sPageTitle = "Change pledge amount";
$sPageContents = NewTemplater::Render("subscription/change_amount", $locale->strings, array(
"email" => $sSubscription->sEmailAddress,
"key" => $sSubscription->sSettingsKey
));

@ -13,7 +13,55 @@
if(!isset($_APP)) { die("Unauthorized."); }
$sNotice = empty($sNotice) ? "" : $sNotice;
$sOtherSubscriptions = array();
foreach(Subscription::FindByEmail($sSubscription->sEmailAddress) as $sOtherSubscription)
{
/* We don't want to add the currently visible subscription to the
* list of other subscriptions. */
if($sOtherSubscription->sId != $sSubscription->sId)
{
if($sOtherSubscription->sIsConfirmed == false)
{
$sStatus = "Awaiting confirmation";
}
elseif($sOtherSubscription->sIsActive == true)
{
$sStatus = "Active";
}
else
{
$sStatus = "Cancelled";
}
$sOtherSubscriptions[] = array(
"name" => $sOtherSubscription->sCampaign->sName,
"amount" => Currency::Format($sOtherSubscription->sCurrency, $sOtherSubscription->sAmount),
"key" => $sOtherSubscription->sSettingsKey,
"status" => $sStatus
);
}
}
if($sSubscription->sIsConfirmed == false)
{
$sStatus = "Awaiting confirmation";
}
elseif($sSubscription->sIsActive == true)
{
$sStatus = "Active";
}
else
{
$sStatus = "Cancelled";
}
$sPageTitle = "Manage your subscriptions";
$sPageContents = NewTemplater::Render("subscription/manage", $locale->strings, array("notice" => $sNotice));
$sPageContents = NewTemplater::Render("subscription/manage", $locale->strings, array(
"name" => $sSubscription->sCampaign->sName,
"amount" => Currency::Format($sSubscription->sCurrency, $sSubscription->sAmount),
"email" => $sSubscription->sEmailAddress,
"key" => $sSubscription->sSettingsKey,
"status" => $sStatus,
"other" => $sOtherSubscriptions
));

@ -0,0 +1,39 @@
<?php
/*
* ReDonate is more free software. It is licensed under the WTFPL, which
* allows you to do pretty much anything with it, without having to
* ask permission. Commercial use is allowed, and no attribution is
* required. We do politely request that you share your modifications
* to benefit other developers, but you are under no enforced
* obligation to do so :)
*
* Please read the accompanying LICENSE document for the full WTFPL
* licensing text.
*/
if(!isset($_APP)) { die("Unauthorized."); }
if(!empty($_POST['submit']))
{
$sSubscription->uIsActive = false;
$sSubscription->InsertIntoDatabase();
$sLogEntry = new LogEntry(0);
$sLogEntry->uType = LogEntry::UNSUBSCRIPTION;
$sLogEntry->uIp = $_SERVER['REMOTE_ADDR'];
$sLogEntry->uData = json_encode(array("email" => $sSubscription->sEmailAddress));
$sLogEntry->uCampaignId = $sCampaign->sId;
$sLogEntry->uDate = time();
$sLogEntry->uSessionId = session_id();
$sLogEntry->InsertIntoDatabase();
flash_notice("We've unsubscribed you.");
redirect("/manage/{$sSubscription->sEmailAddress}/{$sSubscription->sSettingsKey}");
}
$sPageTitle = "Change pledge amount";
$sPageContents = NewTemplater::Render("subscription/unsubscribe", $locale->strings, array(
"email" => $sSubscription->sEmailAddress,
"key" => $sSubscription->sSettingsKey,
"name" => $sSubscription->sCampaign->sName
));

@ -78,6 +78,21 @@ $router->routes = array(
'authenticator' => "authenticators/payment.php",
'auth_error' => "modules/error/nosuchpayment.php"
),
"^/manage/(.+?)/([a-zA-Z0-9]+)/change-amount$" => array(
'target' => "modules/subscription/change_amount.php",
'authenticator' => "authenticators/subscription.php",
'auth_error' => "modules/error/nosuchsubscription.php"
),
"^/manage/(.+?)/([a-zA-Z0-9]+)/unsubscribe$" => array(
'target' => "modules/subscription/unsubscribe.php",
'authenticator' => "authenticators/subscription.php",
'auth_error' => "modules/error/nosuchsubscription.php"
),
"^/manage/(.+?)/([a-zA-Z0-9]+)[.]?$" => array(
'target' => "modules/subscription/manage.php",
'authenticator' => "authenticators/subscription.php",
'auth_error' => "modules/error/nosuchsubscription.php"
),
"^/campaign/([a-zA-Z0-9-]+)$" => "modules/landing.php",
"^/campaign/([a-zA-Z0-9-]+)/subscribe$" => "modules/subscribe.php",
"^/test$" => "modules/test.php"

@ -409,6 +409,12 @@ td.meta
font-style: italic;
}
a.no-style
{
color: inherit;
text-decoration: inherit;
}
/**************************************
* NOTIFICATIONS *
**************************************/

@ -0,0 +1,30 @@
<div class="formwrapper">
<h2 class="spaced">Change pledge amount</h2>
{%if isempty|errors == false}
{%foreach error in errors}
<div class="errors">
{%?error}
</div>
{%/foreach}
{%/if}
<form method="post" action="/manage/{%?email}/{%?key}/change-amount">
<div class="formfield">
<label>Currency</label>
{%select name="currency"}
{%option value="usd" text="US Dollar"}
{%option value="eur" text="Euro"}
{%option value="btc" text="Bitcoin"}
{%/select}
</div>
<div class="formfield">
<label>Amount per month</label>
{%input type="text" name="amount"}
<div class="clear"></div>
</div>
<div class="formfield submit">
<button type="submit" name="submit" value="submit">Save changes</button>
</div>
</form>
</div>

@ -1,3 +1,5 @@
<h2 class="spaced">Manage your subscriptions</h2>
{%if isempty|notices == false}
{%foreach notice in notices}
<div class="notices">
@ -6,4 +8,37 @@
{%/foreach}
{%/if}
Lorem ipsum indeed.
<h3>This subscription</h3>
<ul>
<li><strong>Campaign:</strong> {%?name}</li>
<li><strong>E-mail address:</strong> {%?email}</li>
<li><strong>Amount:</strong> {%?amount} per month</li>
<li><strong>Status:</strong> {%?status}</li>
</ul>
{%if status == "Active"}
<div class="toolbar">
<a href="/manage/{%?email}/{%?key}/change-amount" class="button">Change monthly amount</a>
<!-- <a href="/manage/{%?email}/{%?key}/change-email" class="button">Change e-mail address</a> -->
<a href="/manage/{%?email}/{%?key}/unsubscribe" class="button">Unsubscribe</a>
<div class="clear"></div>
</div>
{%/if}
<h3 class="spaced">Other subscriptions for this address</h3>
<table>
<tr>
<th>Campaign</th>
<th>Amount (p/ month)</th>
<th>Status</th>
</tr>
{%foreach subscription in other}
<tr class="clickable" data-url="/manage/{%?email}/{%?subscription[key]}">
<td><a class="no-style" href="/manage/{%?email}/{%?subscription[key]}">{%?subscription[name]}</a></td>
<td>{%?subscription[amount]}</td>
<td>{%?subscription[status]}</td>
</tr>
{%/foreach}
</table>

@ -0,0 +1,23 @@
<div class="formwrapper">
<h2 class="spaced">Unsubscribe</h2>
{%if isempty|errors == false}
{%foreach error in errors}
<div class="errors">
{%?error}
</div>
{%/foreach}
{%/if}
<form method="post" action="/manage/{%?email}/{%?key}/unsubscribe">
<div class="formfield">
<p>
Are you sure you want to unsubscribe from your pledge to {%?name}?
You will no longer be reminded every month.
</p>
</div>
<div class="formfield" style="text-align: center;">
<button type="submit" name="submit" value="submit">Yes, unsubscribe me</button>
</div>
</form>
</div>
Loading…
Cancel
Save