From b69ebbf7dfe56db4832925ac6681818f4c71f418 Mon Sep 17 00:00:00 2001 From: Sven Slootweg Date: Mon, 25 Feb 2013 11:54:16 +0100 Subject: [PATCH] Implement payment method creation --- public_html/classes/paymentmethod.php | 23 +++++- public_html/modules/campaign/addmethod.php | 73 ++++++++++++++++++++ public_html/modules/campaign/dashboard.php | 5 +- public_html/rewrite.php | 47 +++++++------ public_html/static/css/style.css | 36 +++++++++- public_html/static/script/script.js | 26 +++++++ public_html/templates/campaign/addmethod.tpl | 42 +++++++++++ public_html/templates/campaign/dashboard.tpl | 38 +++++++--- 8 files changed, 257 insertions(+), 33 deletions(-) create mode 100644 public_html/modules/campaign/addmethod.php create mode 100644 public_html/templates/campaign/addmethod.tpl diff --git a/public_html/classes/paymentmethod.php b/public_html/classes/paymentmethod.php index dd063db..f50105c 100644 --- a/public_html/classes/paymentmethod.php +++ b/public_html/classes/paymentmethod.php @@ -21,7 +21,8 @@ class PaymentMethod extends CPHPDatabaseRecordClass public $prototype = array( 'string' => array( - 'Address' => "Address" + 'Address' => "Address", + 'CustomName' => "CustomName" ), 'numeric' => array( 'Type' => "Type", @@ -46,8 +47,28 @@ class PaymentMethod extends CPHPDatabaseRecordClass return array("image" => "/static/images/bitcoin.png", "text" => "Bitcoin"); case PaymentMethod::IBAN: return array("text" => "IBAN"); + case 0: + return array("text" => $this->sCustomName); default: return array("text" => "Unknown"); } } + + public static function ValidateAddress($type, $address) + { + switch($type) + { + case PaymentMethod::PAYPAL: + return filter_var($address, FILTER_VALIDATE_EMAIL); + case PaymentMethod::BITCOIN: + return (preg_match("/^[a-zA-Z1-9]{27,35}$/", $address) == true); + default: + return true; + } + } + + public static function CheckIfValidMethod($type) + { + return in_array($type, array(0, PaymentMethod::PAYPAL, PaymentMethod::BITCOIN)); + } } diff --git a/public_html/modules/campaign/addmethod.php b/public_html/modules/campaign/addmethod.php new file mode 100644 index 0000000..31916f4 --- /dev/null +++ b/public_html/modules/campaign/addmethod.php @@ -0,0 +1,73 @@ + $router->uParameters[1]), 30, true); + +} +catch (NotFoundException $e) +{ + throw new RouterException("Campaign does not exist."); +} + +if(!empty($_POST['submit'])) +{ + if(empty($_POST['address'])) + { + flash_error("You did not enter a valid address or account ID."); + } + + if(!isset($_POST['method']) || $_POST['method'] == "") + { + flash_error("You did not select a valid payment method."); + } + elseif($_POST['method'] == "0" && empty($_POST['customname'])) + { + flash_error("You did not enter a valid name for the payment method."); + } + elseif(PaymentMethod::CheckIfValidMethod($_POST['method']) === false) + { + flash_error("You did not select a valid payment method."); + } + elseif(PaymentMethod::ValidateAddress($_POST['method'], $_POST['address']) === false) + { + flash_error("The address you entered is invalid."); + } + + if(count(get_errors(false)) == 0) + { + $sPaymentMethod = new PaymentMethod(0); + $sPaymentMethod->uType = $_POST['method']; + $sPaymentMethod->uAddress = $_POST['address']; + $sPaymentMethod->uCampaignId = $sCampaign->sId; + + if($_POST['method'] == 0) + { + $sPaymentMethod->uCustomName = $_POST['customname']; + } + + $sPaymentMethod->InsertIntoDatabase(); + + flash_notice("The payment method was successfully added."); + redirect("/dashboard/{$sCampaign->uUrlName}"); + } +} + +$sPageTitle = "Add payment method"; +$sPageContents = NewTemplater::Render("campaign/addmethod", $locale->strings, array( + "name" => $sCampaign->sName, + "urlname" => $sCampaign->sUrlName +)); diff --git a/public_html/modules/campaign/dashboard.php b/public_html/modules/campaign/dashboard.php index 1be24f4..587238b 100644 --- a/public_html/modules/campaign/dashboard.php +++ b/public_html/modules/campaign/dashboard.php @@ -30,7 +30,10 @@ try foreach(PaymentMethod::CreateFromQuery("SELECT * FROM payment_methods WHERE `CampaignId` = :CampaignId", array(":CampaignId" => $sCampaign->sId)) as $sPaymentMethod) { - $sPaymentMethods[] = $sPaymentMethod->GetLogo(); + $sNewMethod = $sPaymentMethod->GetLogo(); + $sNewMethod['address'] = $sPaymentMethod->sAddress; + $sNewMethod['id'] = $sPaymentMethod->sId; + $sPaymentMethods[] = $sNewMethod; } } catch (NotFoundException $e) diff --git a/public_html/rewrite.php b/public_html/rewrite.php index 566a88d..b4063b6 100644 --- a/public_html/rewrite.php +++ b/public_html/rewrite.php @@ -24,27 +24,32 @@ $router->ignore_query = true; $router->routes = array( 0 => array( - "^/$" => array( - 'target' => "modules/index.php", - '_padded' => false - ), - "^/sign-up$" => "modules/signup.php", - "^/login$" => "modules/login.php", - "^/about$" => "modules/about.php", - "^/logout/([a-zA-Z0-9]+)$" => "modules/logout.php", - "^/confirm/(.+)/([a-zA-Z0-9]+)$" => "modules/confirm.php", - "^/dashboard$" => array( - 'target' => "modules/dashboard.php", - 'authenticator' => "authenticators/user.php", - 'auth_error' => "modules/error/guest.php" - ), - "^/dashboard/([a-zA-Z0-9-]+)$" => array( - 'target' => "modules/campaign/dashboard.php", - 'authenticator' => "authenticators/user.php", - 'auth_error' => "modules/error/guest.php" - ), - "^/campaign/([a-zA-Z0-9-]+)$" => "modules/landing.php", - "^/campaign/([a-zA-Z0-9-]+)/subscribe$" => "modules/subscribe.php" + "^/$" => array( + 'target' => "modules/index.php", + '_padded' => false + ), + "^/sign-up$" => "modules/signup.php", + "^/login$" => "modules/login.php", + "^/about$" => "modules/about.php", + "^/logout/([a-zA-Z0-9]+)$" => "modules/logout.php", + "^/confirm/(.+)/([a-zA-Z0-9]+)$" => "modules/confirm.php", + "^/dashboard$" => array( + 'target' => "modules/dashboard.php", + 'authenticator' => "authenticators/user.php", + 'auth_error' => "modules/error/guest.php" + ), + "^/dashboard/([a-zA-Z0-9-]+)$" => array( + 'target' => "modules/campaign/dashboard.php", + 'authenticator' => "authenticators/user.php", + 'auth_error' => "modules/error/guest.php" + ), + "^/dashboard/([a-zA-Z0-9-]+)/add-payment-method$" => array( + 'target' => "modules/campaign/addmethod.php", + 'authenticator' => "authenticators/user.php", + 'auth_error' => "modules/error/guest.php" + ), + "^/campaign/([a-zA-Z0-9-]+)$" => "modules/landing.php", + "^/campaign/([a-zA-Z0-9-]+)/subscribe$" => "modules/subscribe.php" ) ); diff --git a/public_html/static/css/style.css b/public_html/static/css/style.css index e17f680..8046f9e 100644 --- a/public_html/static/css/style.css +++ b/public_html/static/css/style.css @@ -99,6 +99,11 @@ pre.debug margin-bottom: 12px; } +.main h3.spaced +{ + margin-bottom: 18px; +} + /************************************** * FOOTER * **************************************/ @@ -196,11 +201,12 @@ pre.debug float: left; } -.formfield input +.formfield input, .formfield select { font-size: 17px; padding: 4px; width: 270px; + box-sizing: content-box; border: 1px solid #6CA825; border-radius: 1px; background-color: #F4FDE4; @@ -429,7 +435,7 @@ div.logo font-style: italic; color: #1F2E0B; display: inline-block; - font-size: 39px; + font-size: 35px; } div.logo.thumb @@ -451,6 +457,32 @@ td.payment-methods margin-top: 18px; } +table.payment-methods td.logo +{ + width: 250px; + padding: 16px; + text-align: center; +} + +table.payment-methods td.address +{ + padding: 18px; + font-size: 19px; +} + +table.payment-methods td.remove +{ + padding-top: 20px; + text-align: center; + width: 110px; +} + +table.payment-methods td.remove button +{ + padding: 9px 10px; + font-size: 15px; +} + /************************************** * BAR GRAPH * **************************************/ diff --git a/public_html/static/script/script.js b/public_html/static/script/script.js index 28d7207..d548dee 100644 --- a/public_html/static/script/script.js +++ b/public_html/static/script/script.js @@ -27,4 +27,30 @@ $(function(){ } } }); + + $('.conditional').each(function(element){ + var affected = $(this); + var target = $("#" + affected.data("conditional-element")); + var desired = $(this).data("conditional-value"); + + target.change(function(){ + if($(this).val() == desired) + { + affected.show(); + } + else + { + affected.hide(); + } + }); + + if(target.val() == desired) + { + affected.show(); + } + else + { + affected.hide(); + } + }); }); diff --git a/public_html/templates/campaign/addmethod.tpl b/public_html/templates/campaign/addmethod.tpl new file mode 100644 index 0000000..0c792c3 --- /dev/null +++ b/public_html/templates/campaign/addmethod.tpl @@ -0,0 +1,42 @@ +
+

Add payment method for {%?name}

+ + {%if isempty|errors == false} +
+ One or more errors occurred: +
    + {%foreach error in errors} +
  • {%?error}
  • + {%/foreach} +
+
+ {%/if} + +
+
+ + {%select name="method" id="field_method"} + {%option value="1" text="PayPal"} + {%option value="2" text="Bitcoin"} + {%option value="0" text="Other..."} + {%/select} +
+
+ +
+ + {%input type="text" name="customname"} +
+
+ +
+ + {%input type="text" name="address"} +
+
+ +
+ +
+
+
diff --git a/public_html/templates/campaign/dashboard.tpl b/public_html/templates/campaign/dashboard.tpl index bc69783..fbe92b9 100644 --- a/public_html/templates/campaign/dashboard.tpl +++ b/public_html/templates/campaign/dashboard.tpl @@ -1,5 +1,13 @@

Dashboard > {%?name}

+{%if isempty|notices == false} + {%foreach notice in notices} +
+ {%?notice} +
+ {%/foreach} +{%/if} +

Past month

@@ -38,16 +46,30 @@
-

Payment methods

+

Payment methods

Add method
- {%foreach method in payment-methods} - {%if isempty|method[image] == false} - - {%else} - - {%/if} - {%/foreach} + + {%foreach method in payment-methods} + + + + + + {%/foreach} +
+ {%?method[address]} + +
+ +
+