diff --git a/database.mwb b/database.mwb index a54c587..d585347 100644 Binary files a/database.mwb and b/database.mwb differ diff --git a/lib/requiredpublic.php b/lib/requiredpublic.php index e0b8db6..9817887 100644 --- a/lib/requiredpublic.php +++ b/lib/requiredpublic.php @@ -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'); diff --git a/public/actions/submitmembership.php b/public/actions/submitmembership.php index c37e5ce..fffa2c4 100644 --- a/public/actions/submitmembership.php +++ b/public/actions/submitmembership.php @@ -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']; diff --git a/public/parts/signup.php b/public/parts/signup.php index 4b02c96..903167d 100644 --- a/public/parts/signup.php +++ b/public/parts/signup.php @@ -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']; +} ?>
@@ -13,7 +41,13 @@
HACHE: Helena Area Christian Home Educators
-

Membership Application

+ Membership Renewal"; + } else { + echo "

Membership Application

"; + } + ?>
@@ -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="" + value="" + required /> @@ -195,7 +241,11 @@ required> $label) { - echo ""; + $selected = ""; + if (!empty($item['value']) && $value == $item['value']) { + $selected = " selected"; + } + echo "\n"; } ?> @@ -241,7 +291,13 @@
0) { + foreach ($children as $childid) { + include __DIR__ . "/template_child_entry.php"; + } + } else { + include __DIR__ . "/template_child_entry.php"; + } ?>
diff --git a/public/parts/template_child_entry.php b/public/parts/template_child_entry.php index 7dc7ef5..b63f76d 100644 --- a/public/parts/template_child_entry.php +++ b/public/parts/template_child_entry.php @@ -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])); +} ?>
@@ -19,7 +33,7 @@ $randomid = mt_rand(0, 9999999999);
- +
@@ -31,19 +45,16 @@ $randomid = mt_rand(0, 9999999999);
- + " . date("F", mktime(0, 0, 0, $i, 2)) . "\n"; + } + ?> @@ -56,17 +67,21 @@ $randomid = mt_rand(0, 9999999999);
- +
- +
- - + > +
diff --git a/public/parts/thanks.php b/public/parts/thanks.php index 0d2d341..0f01d91 100644 --- a/public/parts/thanks.php +++ b/public/parts/thanks.php @@ -14,10 +14,21 @@

Thank You!

- Checkmark + Checkmark -

Your membership has been submitted and paid for. We'll be in touch soon!

+ Your membership has been renewed."; + } else { + echo "

Your membership has been submitted and paid for. We'll be in touch soon!

"; + } + ?> +

You may now close this page.

- \ No newline at end of file + + + \ No newline at end of file