Add renewal ability to signup form

master
Skylar Ittner 6 years ago
parent 6af2fb753a
commit 144685b31f

Binary file not shown.

@ -18,6 +18,8 @@ if (!DEBUG) {
ini_set('display_errors', 'On');
}
session_start();
// Unicode, solves almost all stupid encoding problems
header('Content-Type: text/html; charset=utf-8');

@ -17,7 +17,12 @@ if (empty($_POST['agree_terms'])) {
errorBack("You must agree to HACHE's policy.");
}
if (!empty($_SESSION['familyid']) && $database->has("families", ['familyid' => $_SESSION['familyid']])) {
$familyid = $_SESSION['familyid'];
}
$database->action(function($database) {
global $familyid;
$lastname = $_POST['familyname'];
$father = $_POST['fathername'];
$mother = $_POST['mothername'];
@ -89,21 +94,39 @@ $database->action(function($database) {
$photopermission = false;
}
$database->insert("families", [
"familyname" => $lastname,
"father_name" => $father,
"mother_name" => $mother,
"phone" => $phone,
"email" => $email,
"newsletter_method" => $newsletter,
"address" => $address,
"city" => $city,
"state" => $state,
"zip" => $zip,
"photo_permission" => $photopermission
]);
if (isset($familyid)) {
$database->update("families", [
"familyname" => $lastname,
"father_name" => $father,
"mother_name" => $mother,
"phone" => $phone,
"email" => $email,
"newsletter_method" => $newsletter,
"address" => $address,
"city" => $city,
"state" => $state,
"zip" => $zip,
"photo_permission" => $photopermission
], [
'familyid' => $familyid
]);
} else {
$database->insert("families", [
"familyname" => $lastname,
"father_name" => $father,
"mother_name" => $mother,
"phone" => $phone,
"email" => $email,
"newsletter_method" => $newsletter,
"address" => $address,
"city" => $city,
"state" => $state,
"zip" => $zip,
"photo_permission" => $photopermission
]);
$familyid = $database->id();
$familyid = $database->id();
}
$children = $_POST['child'];
@ -124,14 +147,26 @@ $database->action(function($database) {
errorBack("Invalid birth year chosen for " . htmlentities($children['name'][$cid]) . ".");
}
$database->insert("people", [
"familyid" => $familyid,
"name" => $children['name'][$cid],
"birthday" => $children['year'][$cid] . "-" . $children['month'][$cid] . "-00",
"graduated" => empty($children['graduate'][$cid]) ? 0 : 1
]);
if ($database->has('people', ["AND" => [
'familyid' => $familyid,
'personid' => $cid
]])) {
$database->update('people', [
"name" => $children['name'][$cid],
"birthday" => $children['year'][$cid] . "-" . $children['month'][$cid] . "-00",
"graduated" => empty($children['graduate'][$cid]) ? 0 : 1
], ['personid' => $cid]);
} else {
$database->insert("people", [
"familyid" => $familyid,
"name" => $children['name'][$cid],
"birthday" => $children['year'][$cid] . "-" . $children['month'][$cid] . "-00",
"graduated" => empty($children['graduate'][$cid]) ? 0 : 1
]);
}
}
$database->delete('interests', ['familyid' => $familyid]);
$interests = [];
foreach ($_POST['events'] as $evt) {
if ($database->has("events", ['eventid' => $evt])) {
@ -143,7 +178,7 @@ $database->action(function($database) {
try {
\Stripe\Stripe::setApiKey(STRIPE_SECKEY);
$charge = \Stripe\Charge::create([
'amount' => $membership_cost,
'currency' => 'usd',
@ -151,7 +186,6 @@ $database->action(function($database) {
'source' => $_POST['stripeToken'],
'statement_descriptor' => 'HACHE Membership 1yr',
]);
} catch (\Stripe\Error\Card $e) {
$body = $e->getJsonBody();
$err = $body['error'];

@ -4,6 +4,34 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
$familyname = "";
$fathername = "";
$mothername = "";
$streetaddress = "";
$city = "";
$state = "";
$zip = "";
$phone = "";
$email = "";
$newsletter_method = "";
$children = [];
if (isset($_SESSION['familyid']) && $database->has('families', ['familyid' => $_SESSION['familyid']])) {
$familyinfo = $database->get("families", ['familyname', 'phone', 'email', 'address', 'city', 'state', 'zip', 'father_name (fathername)', 'mother_name (mothername)', 'newsletter_method'], ['familyid' => $_SESSION['familyid']]);
$children = $database->select("people", 'personid', ['familyid' => $_SESSION['familyid']]);
$familyname = $familyinfo['familyname'];
$fathername = $familyinfo['fathername'];
$mothername = $familyinfo['mothername'];
$streetaddress = $familyinfo['address'];
$city = $familyinfo['city'];
$state = $familyinfo['state'];
$zip = $familyinfo['zip'];
$phone = $familyinfo['phone'];
$email = $familyinfo['email'];
$newsletter_method = $familyinfo['newsletter_method'];
}
?>
<div class="container mt-4">
<form action="actions/submitmembership.php" method="post" id="membershipform">
@ -13,7 +41,13 @@
<div class="d-flex flex-wrap justify-content-around">
<img class="img-fluid" style="max-height: 100px; min-width: 100px;" src="static/hachelogo.svg" alt="HACHE: Helena Area Christian Home Educators"/>
<div class="ml-auto mr-auto pl-4 align-self-center text-center">
<h1>Membership Application</h1>
<?php
if (isset($_SESSION['familyid'])) {
echo "<h1>Membership Renewal</h1>";
} else {
echo "<h1>Membership Application</h1>";
}
?>
</div>
</div>
</div>
@ -45,38 +79,44 @@
"label" => "Family Name (Last Name)",
"icon" => "fas fa-users",
"name" => "familyname",
"maxlength" => 100
"maxlength" => 100,
"value" => $familyname
],
[
"label" => "Father's Name",
"icon" => "fas fa-male",
"name" => "fathername",
"maxlength" => 255
"maxlength" => 255,
"value" => $fathername
],
[
"label" => "Mother's Name",
"icon" => "fas fa-female",
"name" => "mothername",
"maxlength" => 255
"maxlength" => 255,
"value" => $mothername
],
[
"label" => "Street Address",
"icon" => "fas fa-home",
"name" => "streetaddress",
"maxlength" => 500
"maxlength" => 500,
"value" => $streetaddress
],
[
"label" => "City",
"icon" => "fas fa-city",
"name" => "city",
"maxlength" => 255,
"width" => 3
"width" => 3,
"value" => $city
],
[
"label" => "State",
"icon" => "fas fa-flag",
"name" => "state",
"type" => "select",
"value" => $state,
"options" => [
'MT' => 'Montana',
'AL' => 'Alabama',
@ -138,13 +178,15 @@
"icon" => "fas fa-mail-bulk",
"name" => "zip",
"maxlength" => 10,
"width" => 3
"width" => 3,
"value" => $zip
],
[
"label" => "Phone Number",
"icon" => "fas fa-phone",
"name" => "phone",
"maxlength" => 20
"maxlength" => 20,
"value" => $phone
],
[
"label" => "Email",
@ -152,12 +194,14 @@
"name" => "email",
"maxlength" => 255,
"type" => "email",
"value" => $email
],
[
"label" => "Newsletter Preference",
"icon" => "fas fa-newspaper",
"name" => "newsletter_method",
"type" => "select",
"value" => $newsletter_method,
"options" => [
"1" => "Email ($25)",
"2" => "Paper ($35)",
@ -185,7 +229,9 @@
maxlength="<?php echo $item['maxlength']; ?>"
<?php
if (!empty($item['value'])) {
echo "value=\"$item[value]\" ";
?>
value="<?php echo htmlspecialchars($item['value']); ?>"
<?php
}
?>required />
<?php } else if ($item['type'] == "select") { ?>
@ -195,7 +241,11 @@
required>
<?php
foreach ($item['options'] as $value => $label) {
echo "<option value=\"$value\">$label</option>";
$selected = "";
if (!empty($item['value']) && $value == $item['value']) {
$selected = " selected";
}
echo "<option value=\"$value\"$selected>$label</option>\n";
}
?>
</select>
@ -241,7 +291,13 @@
<div class="list-group" id="child_list">
<?php
include __DIR__ . "/template_child_entry.php";
if (count($children) > 0) {
foreach ($children as $childid) {
include __DIR__ . "/template_child_entry.php";
}
} else {
include __DIR__ . "/template_child_entry.php";
}
?>
</div>

@ -5,8 +5,22 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
// Use a random ID for each child, so we can tell 100% which inputs go together
$randomid = mt_rand(0, 9999999999);
require_once __DIR__ . "/../../lib/requiredpublic.php";
$childinfo = ['name' => '', 'month' => 1, 'year' => date('Y', strtotime('now - 10 years')), 'graduated' => false];
if (isset($childid) && $database->has('people', ['personid' => $childid])) {
$randomid = $childid;
$chinfo = $database->get('people', ['name', 'birthday', 'graduated'], ['personid' => $childid]);
$childinfo['name'] = $chinfo['name'];
$childinfo['graduated'] = $chinfo['graduated'] == true;
$childinfo['month'] = date('m', strtotime($chinfo['birthday']));
$childinfo['year'] = date('Y', strtotime($chinfo['birthday']));
} else {
do {
$randomid = mt_rand(0, 9999999999);
} while ($database->has('people', ['personid' => $randomid]));
}
?>
<div class="list-group-item">
@ -19,7 +33,7 @@ $randomid = mt_rand(0, 9999999999);
<div class="input-group-prepend">
<span class="input-group-text"><i class="fas fa-user-graduate"></i></span>
</div>
<input type="text" name="child[name][<?php echo $randomid; ?>]" class="form-control" />
<input type="text" name="child[name][<?php echo $randomid; ?>]" class="form-control" value="<?php echo htmlspecialchars($childinfo['name']); ?>" />
</div>
</div>
</div>
@ -31,19 +45,16 @@ $randomid = mt_rand(0, 9999999999);
<div class="input-group-prepend">
<span class="input-group-text"><i class="fas fa-calendar"></i></span>
</div>
<select name="child[month][<?php echo $randomid; ?>]" class="form-control">
<option value=1>January</option>
<option value=2>February</option>
<option value=3>March</option>
<option value=4>April</option>
<option value=5>May</option>
<option value=6>June</option>
<option value=7>July</option>
<option value=8>August</option>
<option value=9>September</option>
<option value=10>October</option>
<option value=11>November</option>
<option value=12>December</option>
<select name="child[month][<?php echo $randomid; ?>]" class="form-control" value="<?php echo $childinfo['month']; ?>" >
<?php
for ($i = 1; $i <= 12; $i++) {
$selected = "";
if ($childinfo['month'] == $i) {
$selected = " selected";
}
echo "<option value=$i$selected>" . date("F", mktime(0, 0, 0, $i, 2)) . "</option>\n";
}
?>
</select>
</div>
</div>
@ -56,17 +67,21 @@ $randomid = mt_rand(0, 9999999999);
<div class="input-group-prepend">
<span class="input-group-text"><i class="fas fa-calendar-alt"></i></span>
</div>
<input type="number" name="child[year][<?php echo $randomid; ?>]" class="form-control" min="1980" max="<?php echo date('Y'); ?>" value="<?php echo date('Y', strtotime('now - 10 years')); ?>"/>
<input type="number" name="child[year][<?php echo $randomid; ?>]" class="form-control" min="1980" max="<?php echo date('Y'); ?>" value="<?php echo $childinfo['year']; ?>"/>
</div>
</div>
</div>
<div class="col-12 col-sm-2">
<div class="form-group">
<label>Graduated?</label>
<label>&nbsp;</label>
<div class="form-check">
<input class="form-check-input" type="checkbox" value="1" name="child[graduate][<?php echo $randomid; ?>]">
<label class="form-check-label mt-1">Yes</label>
<input class="form-check-input" type="checkbox" value="1" name="child[graduate][<?php echo $randomid; ?>]"<?php
if ($childinfo['graduated']) {
echo " checked";
}
?>>
<label class="form-check-label mt-1">Graduated</label>
</div>
</div>
</div>

@ -14,10 +14,21 @@
<h1>Thank You!</h1>
<img class="img-fluid mb-4" style="max-height: 150px;" src="static/bigcheck.svg" alt="Checkmark"/>
<img class="img-fluid mb-4 mt-2" style="max-height: 150px;" src="static/bigcheck.svg" alt="Checkmark"/>
<h4>Your membership has been submitted and paid for. We'll be in touch soon!</h4>
<?php
if (isset($_SESSION['familyid'])) {
echo "<h2 class=\"h3\">Your membership has been renewed.</h2>";
} else {
echo "<h2 class=\"h3\">Your membership has been submitted and paid for. We'll be in touch soon!</h2>";
}
?>
<h3 class="h5 mt-4">You may now close this page.</h3>
</div>
</div>
</div>
</div>
</div>
<?php
$_SESSION['familyid'] = null;
?>
Loading…
Cancel
Save