diff --git a/public_html/classes/campaign.php b/public_html/classes/campaign.php index 964685a..c5f4472 100644 --- a/public_html/classes/campaign.php +++ b/public_html/classes/campaign.php @@ -22,7 +22,8 @@ class Campaign extends CPHPDatabaseRecordClass public $prototype = array( 'string' => array( 'Name' => "Name", - 'UrlName' => "UrlName" + 'UrlName' => "UrlName", + 'DefaultCurrency' => "DefaultCurrency" ), 'numeric' => array( 'OwnerId' => "OwnerId", @@ -35,7 +36,8 @@ class Campaign extends CPHPDatabaseRecordClass 'PastMonthAmount' => "PastMonthAmount", 'PastMonthNonAmount' => "PastMonthNonAmount", 'PastMonthSubscriptions' => "PastMonthSubscriptions", - 'PastMonthUnsubscriptions' => "PastMonthUnsubscriptions" + 'PastMonthUnsubscriptions' => "PastMonthUnsubscriptions", + 'DefaultAmount' => "DefaultAmount" ), 'boolean' => array( 'AllowOneTime' => "AllowOneTime", diff --git a/public_html/modules/campaign/changesettings.php b/public_html/modules/campaign/changesettings.php new file mode 100644 index 0000000..6ec3ccc --- /dev/null +++ b/public_html/modules/campaign/changesettings.php @@ -0,0 +1,55 @@ + $router->uParameters[1]), 30, true); + +} +catch (NotFoundException $e) +{ + throw new RouterException("Campaign does not exist."); +} + +if($sCampaign->VerifyAdministratorAccess($_SESSION['user_id']) === false) +{ + throw new RouterException("Not authorized to administrate this campaign."); +} + +if(!empty($_POST['default_currency']) && in_array($_POST['default_currency'], array("usd", "eur", "btc"))) /* TODO: Allow other currencies */ +{ + $sCampaign->uDefaultCurrency = $_POST['default_currency']; +} + +if(isset($_POST['default_amount'])) +{ + if(preg_match("/^([0-9]*[.,][0-9]+|[0-9]+)$/", $_POST['default_amount']) == false) + { + flash_error("You did not enter a valid default amount."); + } + else + { + $sCampaign->uDefaultAmount = $_POST['default_amount']; + } +} + +if(count(get_errors(false)) == 0) +{ + $sCampaign->InsertIntoDatabase(); + flash_notice("Settings successfully changed."); +} + +redirect("/dashboard/{$sCampaign->sUrlName}"); + diff --git a/public_html/modules/campaign/dashboard.php b/public_html/modules/campaign/dashboard.php index 85cfc9b..d7e86d2 100644 --- a/public_html/modules/campaign/dashboard.php +++ b/public_html/modules/campaign/dashboard.php @@ -82,5 +82,8 @@ $sPageContents = NewTemplater::Render("campaign/dashboard", $locale->strings, ar "nondonations-amount" => $sCampaign->sPastMonthNonDonations, "nondonations-percentage" => $sNonDonationPercentage, "statistics-available" => $sStatisticsAvailable +), array( + "default_currency" => $sCampaign->sDefaultCurrency, + "default_amount" => $sCampaign->sDefaultAmount )); diff --git a/public_html/rewrite.php b/public_html/rewrite.php index 42536aa..75c7e3a 100644 --- a/public_html/rewrite.php +++ b/public_html/rewrite.php @@ -58,6 +58,11 @@ $router->routes = array( 'authenticator' => "authenticators/user.php", 'auth_error' => "modules/error/guest.php" ), + "^/dashboard/([a-zA-Z0-9-]+)/change-settings$" => array( + 'target' => "modules/campaign/changesettings.php", + 'authenticator' => "authenticators/user.php", + 'auth_error' => "modules/error/guest.php" + ), "^/pay/(.+)/([0-9]+)/([a-zA-Z0-9]+)/(.+)/done$" => array( 'target' => "modules/payment/notify_done.php", 'authenticator' => "authenticators/payment.php", diff --git a/public_html/templates/campaign/dashboard.tpl b/public_html/templates/campaign/dashboard.tpl index 20c8dfc..03c77f0 100644 --- a/public_html/templates/campaign/dashboard.tpl +++ b/public_html/templates/campaign/dashboard.tpl @@ -8,6 +8,18 @@ {%/foreach} {%/if} +{%if isempty|errors == false} +
+ One or more problems occurred: + + Please correct these issues and submit the form again. +
+{%/if} +

Your public campaign page URL

@@ -85,3 +97,30 @@

No payment methods have been added yet.

{%/if}
+ +
+

Settings

+ +
+
+ + {%select name="default_currency"} + {%option value="usd" text="$ (United States Dollar)"} + {%option value="eur" text="€ (Euro)"} + {%option value="btc" text="BTC (Bitcoin)"} + {%/select} +
+
+ +
+ + {%input name="default_amount"} +
+
+ +
+ + +
+
+
diff --git a/sql_updates/2013-06-12-defaults.sql b/sql_updates/2013-06-12-defaults.sql new file mode 100644 index 0000000..42dd289 --- /dev/null +++ b/sql_updates/2013-06-12-defaults.sql @@ -0,0 +1,2 @@ +ALTER TABLE `campaigns` ADD `DefaultCurrency` VARCHAR( 6 ) NOT NULL DEFAULT 'usd', +ADD `DefaultAmount` DECIMAL( 12, 2 ) NOT NULL DEFAULT '5';