Add camp coupons, add submission code
This commit is contained in:
parent
9af6bc7d15
commit
3eaa9f0ed9
BIN
database.mwb
BIN
database.mwb
Binary file not shown.
@ -10,193 +10,186 @@ require_once __DIR__ . "/../../lib/requiredpublic.php";
|
|||||||
|
|
||||||
require_once __DIR__ . "/../../lib/Email.lib.php";
|
require_once __DIR__ . "/../../lib/Email.lib.php";
|
||||||
|
|
||||||
var_export($_POST);
|
|
||||||
die();
|
|
||||||
|
|
||||||
function errorBack(string $errormsg) {
|
function errorBack(string $errormsg) {
|
||||||
|
global $familyid;
|
||||||
header("Location: ../?page=signup&error=" . htmlentities($errormsg));
|
header("Location: ../?page=signup&error=" . htmlentities($errormsg));
|
||||||
|
$database->delete("families", ["familyid" => $familyid]);
|
||||||
die($errormsg);
|
die($errormsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($_SESSION['familyid']) && $database->has("families", ['familyid' => $_SESSION['familyid']])) {
|
|
||||||
$family = $_SESSION['familyid'];
|
|
||||||
$renewal = true;
|
|
||||||
} else if (!empty($_POST['renewing'])) {
|
|
||||||
// Session expired, but we're renewing, so kick them back to verification
|
|
||||||
header("Location: ../?page=renew&msg=sessionexpired");
|
|
||||||
die("You took too long and were automatically logged out. Please try again.");
|
|
||||||
}
|
|
||||||
|
|
||||||
$database->action(function($database) {
|
$database->action(function($database) {
|
||||||
global $family, $renewal, $SETTINGS;
|
global $SETTINGS;
|
||||||
|
|
||||||
|
$database->insert("families", []);
|
||||||
|
$familyid = $database->id();
|
||||||
|
|
||||||
|
$dueusd = 0.0;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$lastname = $_POST['familyname'];
|
|
||||||
$father = $_POST['fathername'];
|
|
||||||
$mother = $_POST['mothername'];
|
|
||||||
|
|
||||||
if (empty($lastname)) {
|
$people = $_POST['people'];
|
||||||
errorBack("Enter a last name.");
|
|
||||||
}
|
|
||||||
if (empty($father)) {
|
|
||||||
errorBack("Enter a father name.");
|
|
||||||
}
|
|
||||||
if (empty($mother)) {
|
|
||||||
errorBack("Enter a mother name.");
|
|
||||||
}
|
|
||||||
|
|
||||||
$family->setName($lastname);
|
$requiredfields = [
|
||||||
$family->setFather($father);
|
"firstname" => ".+",
|
||||||
$family->setMother($mother);
|
"lastname" => ".+",
|
||||||
|
"address" => ".+",
|
||||||
|
"zip" => "[0-9]{5}(-?[0-9]{4})?",
|
||||||
|
"phone1" => "[0-9]{10}",
|
||||||
|
"email" => "_EMAIL_",
|
||||||
|
"shirt" => ["YS", "YM", "YL", "AS", "AM", "AL", "AX", "A2"],
|
||||||
|
"sex" => ["M", "F"]
|
||||||
|
];
|
||||||
|
|
||||||
$family->setPhone($_POST['phone']);
|
foreach ($people['ids'] as $pid) {
|
||||||
$family->setEmail($_POST['email']);
|
switch ($people["type"][$pid]) {
|
||||||
|
case "camper":
|
||||||
if ($renewal) {
|
$checkfields = array_merge($requiredfields, [
|
||||||
if ($database->has("families", ["AND" => ["email" => $family->getEmail(), "familyid[!]" => $family->getID()]])) {
|
"parentname" => ".+",
|
||||||
errorBack("That email address is already in use with another family.");
|
"unit" => "[0-9]{3,4}",
|
||||||
}
|
"rank" => ["Tiger", "Wolf", "Bear", "Webelos", "Arrow of Light"]
|
||||||
} else {
|
]);
|
||||||
if ($database->has("families", ["email" => $family->getEmail()])) {
|
|
||||||
errorBack("That email address is already in use with another family.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$address = $_POST['streetaddress'];
|
|
||||||
$city = $_POST['city'];
|
|
||||||
$state = strtoupper($_POST['state']);
|
|
||||||
$zip = $_POST['zip'];
|
|
||||||
if (empty($address)) {
|
|
||||||
errorBack("Enter a street address.");
|
|
||||||
}
|
|
||||||
if (empty($city)) {
|
|
||||||
errorBack("Enter a city.");
|
|
||||||
}
|
|
||||||
$family->setAddress($address);
|
|
||||||
$family->setCity($city);
|
|
||||||
$family->setState($state);
|
|
||||||
$family->setZip($zip);
|
|
||||||
|
|
||||||
|
|
||||||
$newsletter = $_POST['newsletter_method'];
|
|
||||||
$membership_cost = 2500;
|
|
||||||
if (empty($newsletter)) {
|
|
||||||
errorBack("Select a newsletter preference.");
|
|
||||||
}
|
|
||||||
$family->setNewsletter($newsletter);
|
|
||||||
switch ($newsletter) {
|
|
||||||
case 1: // Email only
|
|
||||||
$membership_cost = 2500;
|
|
||||||
break;
|
break;
|
||||||
case 2: // Print only
|
case "adult":
|
||||||
$membership_cost = 3500;
|
$checkfields = array_merge($requiredfields, [
|
||||||
|
"position" => [
|
||||||
|
"None",
|
||||||
|
"Den Walker",
|
||||||
|
"Station Leader",
|
||||||
|
"Tot Lot",
|
||||||
|
"First Aid",
|
||||||
|
"Floater"
|
||||||
|
]
|
||||||
|
]);
|
||||||
break;
|
break;
|
||||||
case 3: // Email and print
|
case "youth":
|
||||||
$membership_cost = 3500;
|
$checkfields = array_merge($requiredfields, [
|
||||||
|
"position" => [
|
||||||
|
"None",
|
||||||
|
"Den Chief",
|
||||||
|
"Station",
|
||||||
|
"Tot Lot",
|
||||||
|
"Floater"
|
||||||
|
]
|
||||||
|
]);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
errorBack("Select a valid newsletter preference.");
|
errorBack("Invalid person type.");
|
||||||
}
|
}
|
||||||
|
foreach ($checkfields as $name => $regex) {
|
||||||
|
$validatefunction = function ($str) use ($regex) {
|
||||||
|
return preg_match("/$regex/", $str);
|
||||||
|
};
|
||||||
|
|
||||||
$photopermission = $_POST['photo_permission'];
|
if (is_array($regex)) {
|
||||||
if (!empty($photopermission) && $photopermission == "1") {
|
// Array of options
|
||||||
$photopermission = true;
|
$validatefunction = function ($str) use ($regex) {
|
||||||
} else {
|
return in_array($str, $regex);
|
||||||
$photopermission = false;
|
};
|
||||||
}
|
} else if (strpos($regex, "_") === 0) {
|
||||||
$family->setPhotoPermission($photopermission);
|
// Special cases
|
||||||
|
switch ($regex) {
|
||||||
if ($renewal) {
|
case "_EMAIL_":
|
||||||
// If membership lapsed, add a whole year, otherwise just extend it
|
$validatefunction = function ($str) {
|
||||||
if ($family->getExpires() < time()) {
|
return filter_var($str, FILTER_VALIDATE_EMAIL);
|
||||||
$family->setExpires(strtotime("+1 year"));
|
};
|
||||||
} else {
|
break;
|
||||||
$family->setExpires(strtotime("+1 year", $family->getExpires()));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$family->setExpires(strtotime("+1 year"));
|
|
||||||
}
|
|
||||||
|
|
||||||
$family->save();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Children
|
|
||||||
//
|
|
||||||
$children = $_POST['child'];
|
|
||||||
|
|
||||||
$childObjects = $family->getChildren();
|
|
||||||
|
|
||||||
foreach ($children['ids'] as $cid) {
|
|
||||||
if (empty($children['name'][$cid])) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!preg_match("/^([1-9]|1[012])$/", $children['month'][$cid])) {
|
|
||||||
errorBack("Invalid birth month chosen for " . htmlentities($children['name'][$cid]) . ".");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!is_numeric($children['year'][$cid])) {
|
|
||||||
errorBack("Invalid birth year chosen for " . htmlentities($children['name'][$cid]) . ".");
|
|
||||||
}
|
|
||||||
$children['year'][$cid] = $children['year'][$cid] * 1;
|
|
||||||
if ($children['year'][$cid] < 1980 || $children['year'][$cid] > date("Y")) {
|
|
||||||
errorBack("Invalid birth year chosen for " . htmlentities($children['name'][$cid]) . ".");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Child::exists($cid, $family->getID())) {
|
|
||||||
// iterate over existing children to find the correct one
|
|
||||||
for ($i = 0; $i < count($childObjects); $i++) {
|
|
||||||
if ($childObjects[$i]->getID() == $cid) {
|
|
||||||
$childObjects[$i]->setName($children['name'][$cid]);
|
|
||||||
$childObjects[$i]->setBirthday(null, $children['year'][$cid] . "-" . $children['month'][$cid] . "-00");
|
|
||||||
$childObjects[$i]->setGraduated(empty($children['graduate'][$cid]) ? false : true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$child = new Child();
|
|
||||||
$child->setName($children['name'][$cid]);
|
|
||||||
$child->setBirthday(null, $children['year'][$cid] . "-" . $children['month'][$cid] . "-00");
|
|
||||||
$child->setGraduated(empty($children['graduate'][$cid]) ? false : true);
|
|
||||||
$child->setFamilyID($family->getID());
|
|
||||||
$childObjects[] = $child;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($childObjects as $child) {
|
// Validate
|
||||||
$child->save();
|
if (!$validatefunction($people[$name][$pid])) {
|
||||||
|
errorBack("Please check your input and try again ($name).");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$days = "";
|
||||||
|
if (is_array($people["days"][$pid])) {
|
||||||
|
$validdays = ["Tu", "We", "Th", "Fr"];
|
||||||
|
$days = "";
|
||||||
|
foreach ($people["days"][$pid] as $day) {
|
||||||
|
if (in_array($day, $validdays)) {
|
||||||
|
$days .= $day;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
switch ($people["type"][$pid]) {
|
||||||
|
case "camper":
|
||||||
|
$dueusd += 50.0;
|
||||||
|
echo "\nAdding $50 to the total for a camper, dueusd is $dueusd\n";
|
||||||
|
$database->insert("campers", [
|
||||||
|
"parentname" => $people["parentname"][$pid],
|
||||||
|
"rank" => $people["rank"][$pid]
|
||||||
|
]);
|
||||||
|
$camperid = $database->id();
|
||||||
|
break;
|
||||||
|
case "adult":
|
||||||
|
$discount = 10.0 * (strlen($days) / 2);
|
||||||
|
$dueusd -= $discount;
|
||||||
|
echo "\Subtracting $$discount from the total for an adult volunteer, dueusd is $dueusd\n";
|
||||||
|
$database->insert("adults", [
|
||||||
|
"position" => $people["position"][$pid],
|
||||||
|
"days" => $days
|
||||||
|
]);
|
||||||
|
$adultid = $database->id();
|
||||||
|
break;
|
||||||
|
case "youth":
|
||||||
|
$database->insert("youth", [
|
||||||
|
"position" => $people["position"][$pid],
|
||||||
|
"days" => $days
|
||||||
|
]);
|
||||||
|
$youthid = $database->id();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$database->insert("people", [
|
||||||
|
"familyid" => $familyid,
|
||||||
|
"camperid" => $camperid,
|
||||||
|
"adultid" => $adultid,
|
||||||
|
"youthid" => $youthid,
|
||||||
|
"firstname" => $people["firstname"][$pid],
|
||||||
|
"lastname" => $people["lastname"][$pid],
|
||||||
|
"address" => $people["address"][$pid],
|
||||||
|
"zip" => $people["zip"][$pid],
|
||||||
|
"phone1" => empty($people["phone1"][$pid] ? "" : $people["phone1"][$pid]),
|
||||||
|
"phone2" => empty($people["phone2"][$pid] ? "" : $people["phone2"][$pid]),
|
||||||
|
"email" => empty($people["email"][$pid] ? "" : $people["email"][$pid]),
|
||||||
|
"unit" => $people["unit"][$pid],
|
||||||
|
"shirt" => $people["shirt"][$pid],
|
||||||
|
"sex" => $people["sex"][$pid]
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
} catch (Exception $ex) {
|
} catch (Exception $ex) {
|
||||||
errorBack($ex->getMessage());
|
errorBack($ex->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
|
||||||
// Interests
|
|
||||||
//
|
|
||||||
$database->delete('interests', ['familyid' => $family->getID()]);
|
|
||||||
if (!empty($_POST['events']) && is_array($_POST['events'])) {
|
|
||||||
$interests = [];
|
|
||||||
foreach ($_POST['events'] as $evt) {
|
|
||||||
if ($database->has("events", ['eventid' => $evt])) {
|
|
||||||
$interests[] = ["familyid" => $family->getID(), "eventid" => $evt];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$database->insert("interests", $interests);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Payment
|
// Payment
|
||||||
//
|
//
|
||||||
|
|
||||||
|
$campcoupons = (!empty($_POST['campcoupons']) && preg_match("/[0-9]+/", $_POST['campcoupons'])) ? $_POST['campcoupons'] * 1 : 0;
|
||||||
|
|
||||||
|
$duecard = $dueusd - $campcoupons;
|
||||||
|
|
||||||
|
echo "\nCost $dueusd total: $duecard to Stripe, $campcoupons as coupons\n";
|
||||||
|
|
||||||
|
if ($_POST['totalcharge'] != $dueusd) {
|
||||||
|
errorBack("There was a discrepency between the total you saw and the total the server calculated. The transaction has been cancelled and you were not charged.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($duecard > 0) {
|
||||||
try {
|
try {
|
||||||
\Stripe\Stripe::setApiKey($SETTINGS["stripe"]["seckey"]);
|
\Stripe\Stripe::setApiKey($SETTINGS["stripe"]["seckey"]);
|
||||||
|
|
||||||
$charge = \Stripe\Charge::create([
|
$charge = \Stripe\Charge::create([
|
||||||
'amount' => $membership_cost,
|
'amount' => $duecard * 100.0,
|
||||||
'currency' => 'usd',
|
'currency' => 'usd',
|
||||||
'description' => 'HACHE Membership',
|
'description' => 'Day Camp',
|
||||||
'source' => $_POST['stripeToken'],
|
'source' => $_POST['stripeToken'],
|
||||||
'statement_descriptor' => 'HACHE Membership 1yr',
|
'statement_descriptor' => 'PPD Day Camp',
|
||||||
]);
|
]);
|
||||||
} catch (\Stripe\Error\Card $e) {
|
} catch (\Stripe\Error\Card $e) {
|
||||||
$body = $e->getJsonBody();
|
$body = $e->getJsonBody();
|
||||||
@ -215,53 +208,17 @@ $database->action(function($database) {
|
|||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
errorBack("An unknown error occurred. Please try again later.");
|
errorBack("An unknown error occurred. Please try again later.");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$database->insert("payments", [
|
$database->insert("payments", [
|
||||||
"familyid" => $family->getID(),
|
"familyid" => $familyid,
|
||||||
"amount" => ($membership_cost / 100.0),
|
"amount" => ($dueusd),
|
||||||
"paid" => 1,
|
"amountpaid" => ($duecard),
|
||||||
"date" => date("Y-m-d H:i:s"),
|
"date" => date("Y-m-d H:i:s"),
|
||||||
"type" => "Online"
|
"type" => "Online"
|
||||||
]);
|
]);
|
||||||
|
|
||||||
try {
|
|
||||||
$confirmation = new Email();
|
|
||||||
$confirmation->addTo($family->getEmail());
|
|
||||||
$confirmation->setFrom($SETTINGS["smtp"]["fromaddress"], $SETTINGS["smtp"]["fromname"]);
|
|
||||||
$confirmation->setSMTP($SETTINGS["smtp"]["host"], $SETTINGS["smtp"]["port"], $SETTINGS["smtp"]["auth"], $SETTINGS["smtp"]["user"], $SETTINGS["smtp"]["password"], $SETTINGS["smtp"]["secure"]);
|
|
||||||
if ($renewal) {
|
|
||||||
$confirmation->setSubject("HACHE renewal confirmation");
|
|
||||||
$confirmation->setBody("Your membership renewal has been processed.\r\n"
|
|
||||||
. "Your membership will expire on" . date("F j Y", $family->getExpires()) . ".\r\n"
|
|
||||||
. "Thanks for being a HACHE member!");
|
|
||||||
} else {
|
|
||||||
$confirmation->setSubject("HACHE membership confirmation");
|
|
||||||
$confirmation->setBody("Your membership and payment have been recorded.\r\n"
|
|
||||||
. "A HACHE member will be in touch in the next few days.\r\n"
|
|
||||||
. "Thanks again and welcome to HACHE!");
|
|
||||||
}
|
|
||||||
$confirmation->send();
|
|
||||||
} catch (Exception $e) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
$notification = new Email();
|
|
||||||
$notification->addTo($SETTINGS["smtp"]["notification_to"]);
|
|
||||||
$notification->setFrom($SETTINGS["smtp"]["fromaddress"], $SETTINGS["smtp"]["fromname"]);
|
|
||||||
$notification->setSMTP($SETTINGS["smtp"]["host"], $SETTINGS["smtp"]["port"], $SETTINGS["smtp"]["auth"], $SETTINGS["smtp"]["user"], $SETTINGS["smtp"]["password"], $SETTINGS["smtp"]["secure"]);
|
|
||||||
if ($renewal) {
|
|
||||||
$notification->setSubject("HACHE renewal notification");
|
|
||||||
$notification->setBody("The " . $family->getName() . " family has renewed their HACHE membership.");
|
|
||||||
} else {
|
|
||||||
$notification->setSubject("HACHE membership notification");
|
|
||||||
$notification->setBody("The " . $family->getName() . " family has registered for a HACHE membership.");
|
|
||||||
}
|
|
||||||
$notification->send();
|
|
||||||
} catch (Exception $e) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
header("Location: ../?page=thanks");
|
header("Location: ../?page=thanks");
|
||||||
|
var_dump($_POST);
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
@ -133,29 +133,48 @@ if (isset($_SESSION['familyid']) && $database->has('families', ['familyid' => $_
|
|||||||
</div>
|
</div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<h4>Total: $<span id="total">0</span></h4>
|
<h4>Total: $<span id="total">0</span></h4>
|
||||||
<!-- Hi, don't bother tampering with this, the math is checked on the server before charging the card. -->
|
|
||||||
<input type="hidden" name="totalcharge" value="0" />
|
<div class="row" id="payment-methods" style="display: none;">
|
||||||
|
<div class="col-12 col-md-8">
|
||||||
<noscript>
|
<noscript>
|
||||||
<div class="card-text text-danger mb-1">
|
<div class="card-text text-danger mb-1">
|
||||||
<i class="fas fa-code"></i> JavaScript is required to complete your payment.
|
<i class="fas fa-code"></i> JavaScript is required to complete your payment.
|
||||||
</div>
|
</div>
|
||||||
</noscript>
|
</noscript>
|
||||||
<div class="card-text text-success mb-1">
|
|
||||||
<i class="fas fa-lock"></i> We can't see your card info; it's sent directly and securely from your computer to our payment processor.
|
|
||||||
</div>
|
|
||||||
<label for="card-element">
|
<label for="card-element">
|
||||||
Credit or debit card
|
Credit or debit card:
|
||||||
</label>
|
</label>
|
||||||
<div id="card-element" class="form-control">
|
<div id="card-element" class="form-control">
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div id="card-errors" class="alert alert-danger d-none"></div>
|
<div id="card-errors" class="alert alert-danger d-none"></div>
|
||||||
<input type="hidden" name="stripeToken" id="stripe-token" required />
|
<input type="hidden" name="stripeToken" id="stripe-token" required />
|
||||||
|
<div class="card-text text-success mb-1">
|
||||||
|
<i class="fas fa-lock"></i> We can't see your card info; it's sent directly and securely from your computer to our payment processor.
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-12 col-md-4">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="campcoupons">Camp Coupons or Scout Bucks:</label>
|
||||||
|
<div class="input-group">
|
||||||
|
<div class="input-group-prepend">
|
||||||
|
<div class="input-group-text">
|
||||||
|
<i class="fas fa-dollar-sign"></i>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<input type="number" step="1" name="campcoupons" class="form-control" value="0" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Hi, don't bother tampering with this, the math is checked on the server. -->
|
||||||
|
<input type="hidden" name="totalcharge" value="0" />
|
||||||
</div>
|
</div>
|
||||||
<div class="card-footer">
|
<div class="card-footer">
|
||||||
<button type="submit" class="btn btn-teal" id="savebutton">
|
<button type="submit" class="btn btn-teal" id="savebutton">
|
||||||
<span id="savebutton-text">
|
<span id="savebutton-text">
|
||||||
<i class="fas fa-arrow-right"></i> Submit<span class="d-none d-sm-inline"> Registration and Payment</span>
|
<i class="fas fa-arrow-right"></i> Submit<span class="d-none d-sm-inline"> Registration</span>
|
||||||
</span>
|
</span>
|
||||||
<span id="savebutton-wait" class="d-none">
|
<span id="savebutton-wait" class="d-none">
|
||||||
<i class="fas fa-spinner fa-spin"></i> Working...
|
<i class="fas fa-spinner fa-spin"></i> Working...
|
||||||
|
@ -51,7 +51,7 @@ if (isset($personid) && $database->has('people', ['personid' => $personid])) {
|
|||||||
|
|
||||||
<div class="list-group-item person-list-item" data-persontype="<?php echo $type; ?>">
|
<div class="list-group-item person-list-item" data-persontype="<?php echo $type; ?>">
|
||||||
<input type="hidden" name="people[ids][]" value="<?php echo $personid; ?>" />
|
<input type="hidden" name="people[ids][]" value="<?php echo $personid; ?>" />
|
||||||
<input type="hidden" name="persontype" value="<?php echo $type; ?>" />
|
<input type="hidden" name="people[type][<?php echo $personid; ?>]" value="<?php echo $type; ?>" />
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
@ -259,7 +259,8 @@ if (isset($personid) && $database->has('people', ['personid' => $personid])) {
|
|||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
<?php if (empty($item['type']) || ($item['type'] != "select" && $item['type'] != "checkboxes")) { ?>
|
<?php if (empty($item['type']) || ($item['type'] != "select" && $item['type'] != "checkboxes")) { ?>
|
||||||
<input type="<?php echo (empty($item['type']) ? "text" : $item['type']); ?>"
|
<input type="<?php echo (empty($item['type']) ? "text" : $item['type']); ?>"
|
||||||
name="<?php echo $item['name']; ?>"
|
name="people[<?php echo $item['name']; ?>][<?php echo $personid; ?>]"
|
||||||
|
data-name="<?php echo $item['name']; ?>"
|
||||||
class="form-control"
|
class="form-control"
|
||||||
placeholder=""
|
placeholder=""
|
||||||
aria-label="<?php echo $item['label']; ?>"
|
aria-label="<?php echo $item['label']; ?>"
|
||||||
@ -283,7 +284,8 @@ if (isset($personid) && $database->has('people', ['personid' => $personid])) {
|
|||||||
?> />
|
?> />
|
||||||
<?php } else if ($item['type'] == "select") { ?>
|
<?php } else if ($item['type'] == "select") { ?>
|
||||||
<select class="form-control"
|
<select class="form-control"
|
||||||
name="<?php echo $item['name']; ?>"
|
name="people[<?php echo $item['name']; ?>][<?php echo $personid; ?>]"
|
||||||
|
data-name="<?php echo $item['name']; ?>"
|
||||||
aria-label="<?php echo $item['label']; ?>"
|
aria-label="<?php echo $item['label']; ?>"
|
||||||
<?php
|
<?php
|
||||||
if (empty($item['optional'])) {
|
if (empty($item['optional'])) {
|
||||||
@ -308,7 +310,7 @@ if (isset($personid) && $database->has('people', ['personid' => $personid])) {
|
|||||||
foreach ($item['options'] as $value => $label) {
|
foreach ($item['options'] as $value => $label) {
|
||||||
?>
|
?>
|
||||||
<div class="form-check m-1">
|
<div class="form-check m-1">
|
||||||
<input class="form-check-input" type="checkbox" name="<?php echo $item['name']; ?>" value="<?php echo $value; ?>">
|
<input class="form-check-input" type="checkbox" data-name="<?php echo $item['name']; ?>" name="people[<?php echo $item['name']; ?>][<?php echo $personid; ?>][]" value="<?php echo $value; ?>">
|
||||||
<label class="form-check-label">
|
<label class="form-check-label">
|
||||||
<?php echo $label; ?>
|
<?php echo $label; ?>
|
||||||
</label>
|
</label>
|
||||||
|
@ -8,14 +8,14 @@ $("#add_camper").click(function () {
|
|||||||
var copyfrom = $("#camper_list .person-list-item").first();
|
var copyfrom = $("#camper_list .person-list-item").first();
|
||||||
$.get("parts/template_person.php", {
|
$.get("parts/template_person.php", {
|
||||||
type: "camper",
|
type: "camper",
|
||||||
lastname: $("input[name=lastname]", copyfrom).val(),
|
lastname: $("input[data-name=lastname]", copyfrom).val(),
|
||||||
parentname: $("input[name=parentname]", copyfrom).val(),
|
parentname: $("input[data-name=parentname]", copyfrom).val(),
|
||||||
address: $("input[name=address]", copyfrom).val(),
|
address: $("input[data-name=address]", copyfrom).val(),
|
||||||
zip: $("input[name=zip]", copyfrom).val(),
|
zip: $("input[data-name=zip]", copyfrom).val(),
|
||||||
phone1: $("input[name=phone1]", copyfrom).val(),
|
phone1: $("input[data-name=phone1]", copyfrom).val(),
|
||||||
phone2: $("input[name=phone2]", copyfrom).val(),
|
phone2: $("input[data-name=phone2]", copyfrom).val(),
|
||||||
email: $("input[name=email]", copyfrom).val(),
|
email: $("input[data-name=email]", copyfrom).val(),
|
||||||
unit: $("input[name=unit]", copyfrom).val()
|
unit: $("input[data-name=unit]", copyfrom).val()
|
||||||
}, function (resp) {
|
}, function (resp) {
|
||||||
$("#camper_list").append(resp);
|
$("#camper_list").append(resp);
|
||||||
updateTotal();
|
updateTotal();
|
||||||
@ -26,12 +26,12 @@ $("#add_adult").click(function () {
|
|||||||
var copyfrom = $("#adult_list .person-list-item").first();
|
var copyfrom = $("#adult_list .person-list-item").first();
|
||||||
$.get("parts/template_person.php", {
|
$.get("parts/template_person.php", {
|
||||||
type: "adult",
|
type: "adult",
|
||||||
lastname: $("input[name=lastname]", copyfrom).val(),
|
lastname: $("input[data-name=lastname]", copyfrom).val(),
|
||||||
address: $("input[name=address]", copyfrom).val(),
|
address: $("input[data-name=address]", copyfrom).val(),
|
||||||
zip: $("input[name=zip]", copyfrom).val(),
|
zip: $("input[data-name=zip]", copyfrom).val(),
|
||||||
phone1: $("input[name=phone1]", copyfrom).val(),
|
phone1: $("input[data-name=phone1]", copyfrom).val(),
|
||||||
phone2: $("input[name=phone2]", copyfrom).val(),
|
phone2: $("input[data-name=phone2]", copyfrom).val(),
|
||||||
email: $("input[name=email]", copyfrom).val()
|
email: $("input[data-name=email]", copyfrom).val()
|
||||||
}, function (resp) {
|
}, function (resp) {
|
||||||
$("#adult_list").append(resp);
|
$("#adult_list").append(resp);
|
||||||
updateTotal();
|
updateTotal();
|
||||||
@ -42,32 +42,31 @@ $("#add_youth").click(function () {
|
|||||||
var copyfrom = $("#youth_list .person-list-item").first();
|
var copyfrom = $("#youth_list .person-list-item").first();
|
||||||
$.get("parts/template_person.php", {
|
$.get("parts/template_person.php", {
|
||||||
type: "youth",
|
type: "youth",
|
||||||
lastname: $("input[name=lastname]", copyfrom).val(),
|
lastname: $("input[data-name=lastname]", copyfrom).val(),
|
||||||
address: $("input[name=address]", copyfrom).val(),
|
address: $("input[data-name=address]", copyfrom).val(),
|
||||||
zip: $("input[name=zip]", copyfrom).val(),
|
zip: $("input[data-name=zip]", copyfrom).val(),
|
||||||
parentname: $("input[name=parentname]", copyfrom).val(),
|
parentname: $("input[data-name=parentname]", copyfrom).val(),
|
||||||
phone2: $("input[name=phone2]", copyfrom).val(),
|
phone2: $("input[data-name=phone2]", copyfrom).val(),
|
||||||
email: $("input[name=email]", copyfrom).val()
|
email: $("input[data-name=email]", copyfrom).val()
|
||||||
}, function (resp) {
|
}, function (resp) {
|
||||||
$("#youth_list").append(resp);
|
$("#youth_list").append(resp);
|
||||||
updateTotal();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#camper_list").on("change", "input[name=firstname]", function () {
|
$("#camper_list").on("change", "input[data-name=firstname]", function () {
|
||||||
updateTotal();
|
updateTotal();
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#adult_list").on("change", "input[name=days]", function () {
|
$("#adult_list").on("change", "input[data-name=days]", function () {
|
||||||
updateTotal();
|
updateTotal();
|
||||||
});
|
});
|
||||||
|
|
||||||
function updateTotal() {
|
function updateTotal() {
|
||||||
totalcharge = $(".person-list-item[data-persontype=camper] input[name=firstname]").filter(function () {
|
totalcharge = $(".person-list-item[data-persontype=camper] input[data-name=firstname]").filter(function () {
|
||||||
return $(this).val() != '';
|
return $(this).val() != '';
|
||||||
}).length * 50.0;
|
}).length * 50.0;
|
||||||
|
|
||||||
totalcharge = totalcharge - $(".person-list-item[data-persontype=adult] input[name=days]:checked").filter(function () {
|
totalcharge = totalcharge - $(".person-list-item[data-persontype=adult] input[data-name=days]:checked").filter(function () {
|
||||||
return $(this).val() != '';
|
return $(this).val() != '';
|
||||||
}).length * 10.0;
|
}).length * 10.0;
|
||||||
|
|
||||||
@ -77,6 +76,11 @@ function updateTotal() {
|
|||||||
// the backend-calculated amount, don't bother being a haxxor
|
// the backend-calculated amount, don't bother being a haxxor
|
||||||
$("#total").text(totalcharge);
|
$("#total").text(totalcharge);
|
||||||
$("input[name=totalcharge]").val(totalcharge);
|
$("input[name=totalcharge]").val(totalcharge);
|
||||||
|
if (totalcharge <= 0) {
|
||||||
|
$("#payment-methods").css("display", "none");
|
||||||
|
} else {
|
||||||
|
$("#payment-methods").css("display", "");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a Stripe client.
|
// Create a Stripe client.
|
||||||
@ -117,11 +121,13 @@ $("#savebutton").click(function (event) {
|
|||||||
$("#registrationform").on("submit", function (event) {
|
$("#registrationform").on("submit", function (event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
|
|
||||||
// prevent multiple clicks since Stripe can take a few seconds
|
// prevent multiple clicks since Stripe can take a few seconds
|
||||||
$("#savebutton").prop("disabled", true);
|
$("#savebutton").prop("disabled", true);
|
||||||
$("#savebutton-text").addClass("d-none");
|
$("#savebutton-text").addClass("d-none");
|
||||||
$("#savebutton-wait").removeClass("d-none");
|
$("#savebutton-wait").removeClass("d-none");
|
||||||
|
|
||||||
|
// If we have any charge left after subtracting camp coupons/scout bucks
|
||||||
|
if ($("input[name=totalcharge]").val() - $("input[name=campcoupons]").val() > 0) {
|
||||||
stripe.createToken(card).then(function (result) {
|
stripe.createToken(card).then(function (result) {
|
||||||
if (result.error) {
|
if (result.error) {
|
||||||
// Inform the customer that there was an error.
|
// Inform the customer that there was an error.
|
||||||
@ -133,7 +139,9 @@ $("#registrationform").on("submit", function (event) {
|
|||||||
} else {
|
} else {
|
||||||
$("#stripe-token").val(result.token.id);
|
$("#stripe-token").val(result.token.id);
|
||||||
console.log(result.token);
|
console.log(result.token);
|
||||||
document.getElementById('membershipform').submit();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
document.getElementById('registrationform').submit();
|
||||||
|
}
|
||||||
});
|
});
|
Loading…
x
Reference in New Issue
Block a user