diff --git a/public_html/authenticators/subscription.php b/public_html/authenticators/subscription.php new file mode 100644 index 0000000..705d69c --- /dev/null +++ b/public_html/authenticators/subscription.php @@ -0,0 +1,25 @@ +uParameters[1], $router->uParameters[2]); +} +catch (NotFoundException $e) +{ + throw new RouterException("No such subscription was found."); +} + +$sRouterAuthenticated = true; diff --git a/public_html/classes/subscription.php b/public_html/classes/subscription.php index 2ab545d..cf29e59 100644 --- a/public_html/classes/subscription.php +++ b/public_html/classes/subscription.php @@ -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); + } } } diff --git a/public_html/modules/error/nosuchsubscription.php b/public_html/modules/error/nosuchsubscription.php new file mode 100644 index 0000000..b3903ef --- /dev/null +++ b/public_html/modules/error/nosuchsubscription.php @@ -0,0 +1,16 @@ +sCampaignId == $sCampaign->sId) + if($sSubscription->sCampaignId == $sCampaign->sId && $sSubscription->sIsActive == true) { $exists = true; } diff --git a/public_html/modules/subscription/change_amount.php b/public_html/modules/subscription/change_amount.php new file mode 100644 index 0000000..365cd56 --- /dev/null +++ b/public_html/modules/subscription/change_amount.php @@ -0,0 +1,43 @@ +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 +)); diff --git a/public_html/modules/subscription/manage.php b/public_html/modules/subscription/manage.php index 81b9be5..a847d9e 100644 --- a/public_html/modules/subscription/manage.php +++ b/public_html/modules/subscription/manage.php @@ -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 +)); diff --git a/public_html/modules/subscription/unsubscribe.php b/public_html/modules/subscription/unsubscribe.php new file mode 100644 index 0000000..3b47b5e --- /dev/null +++ b/public_html/modules/subscription/unsubscribe.php @@ -0,0 +1,39 @@ +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 +)); diff --git a/public_html/rewrite.php b/public_html/rewrite.php index ecfd09a..063b342 100644 --- a/public_html/rewrite.php +++ b/public_html/rewrite.php @@ -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" diff --git a/public_html/static/css/style.css b/public_html/static/css/style.css index 6edc403..7cbf876 100644 --- a/public_html/static/css/style.css +++ b/public_html/static/css/style.css @@ -409,6 +409,12 @@ td.meta font-style: italic; } +a.no-style +{ + color: inherit; + text-decoration: inherit; +} + /************************************** * NOTIFICATIONS * **************************************/ diff --git a/public_html/templates/subscription/change_amount.tpl b/public_html/templates/subscription/change_amount.tpl new file mode 100644 index 0000000..ae64107 --- /dev/null +++ b/public_html/templates/subscription/change_amount.tpl @@ -0,0 +1,30 @@ +
+

Change pledge amount

+ + {%if isempty|errors == false} + {%foreach error in errors} +
+ {%?error} +
+ {%/foreach} + {%/if} + +
+
+ + {%select name="currency"} + {%option value="usd" text="US Dollar"} + {%option value="eur" text="Euro"} + {%option value="btc" text="Bitcoin"} + {%/select} +
+
+ + {%input type="text" name="amount"} +
+
+
+ +
+
+
diff --git a/public_html/templates/subscription/manage.tpl b/public_html/templates/subscription/manage.tpl index b8f7cfa..405a58c 100644 --- a/public_html/templates/subscription/manage.tpl +++ b/public_html/templates/subscription/manage.tpl @@ -1,3 +1,5 @@ +

Manage your subscriptions

+ {%if isempty|notices == false} {%foreach notice in notices}
@@ -6,4 +8,37 @@ {%/foreach} {%/if} -Lorem ipsum indeed. +

This subscription

+ + + +{%if status == "Active"} +
+ Change monthly amount + + Unsubscribe +
+
+{%/if} + +

Other subscriptions for this address

+ + + + + + + + {%foreach subscription in other} + + + + + + {%/foreach} +
CampaignAmount (p/ month)Status
{%?subscription[name]}{%?subscription[amount]}{%?subscription[status]}
diff --git a/public_html/templates/subscription/unsubscribe.tpl b/public_html/templates/subscription/unsubscribe.tpl new file mode 100644 index 0000000..d5ab770 --- /dev/null +++ b/public_html/templates/subscription/unsubscribe.tpl @@ -0,0 +1,23 @@ +
+

Unsubscribe

+ + {%if isempty|errors == false} + {%foreach error in errors} +
+ {%?error} +
+ {%/foreach} + {%/if} + +
+
+

+ Are you sure you want to unsubscribe from your pledge to {%?name}? + You will no longer be reminded every month. +

+
+
+ +
+
+